Comments (11)
Thank you again for the messages. I will dig into it.
from pyais.
Hey,
I integrated a native UDPStream
in the newest release. It includes out-of-order message assembly. Usage is straight forward:
from pyais.stream import UDPStream
host = "127.0.0.1" # change this
port = 55555 # and change that
for msg in UDPStream(host, port):
msg.decode()
# do something
@void4main Would you like to check it out and give me some feedback on how it works for you?
Greetings
from pyais.
I had some time to test it with live AIS data and it worked perfectly fine for me.
Since I get broadcasted UDPs I had to set an emtpy host address:
host = "" port = 10110
It crashed once in the beginning but only inside the json conversion:
message = msg.decode().to_json()
and I couldn't reproduce the problem.
With the UDPStream I inserted ~300.000 entries to my mongodb by now.
I had one more crash adding data to the db:
b'!AIVDM,2,1,1,A,14S1fp00002E5k8A5Ejv1c>200Rfr>l00000000s1rA<<5kQ0ClmAFP0,0*78!AIVDM,2,2,1,A,000000000000000,2*25'
Traceback (most recent call last):
File "./get3.py", line 39, in <module>
result = posts.insert_one(message)
File "/usr/local/lib/python3.7/dist-packages/pymongo/collection.py", line 657, in insert_one
bypass_doc_val=bypass_document_validation),
File "/usr/local/lib/python3.7/dist-packages/pymongo/collection.py", line 562, in _insert
check_keys, manipulate, write_concern, op_id, bypass_doc_val)
File "/usr/local/lib/python3.7/dist-packages/pymongo/collection.py", line 551, in _insert_one
self.__write_response_codec_options)
File "/usr/local/lib/python3.7/dist-packages/pymongo/collection.py", line 480, in _legacy_write
rqst_id, msg, max_size = func(*args)
OverflowError: MongoDB can only handle up to 8-byte ints
but haven't looked into it and probably hasn't got anthing to do with your code.
Thank you for the implementation.
from pyais.
Hey,
thanks your issue. Could you provide the exact raw message that leads to this crash?
Thank you
from pyais.
Yes, I try to get these ...
from pyais.
I have two examples for now.
The decoding of part 1 is alwasy ok but part 2 leads to a crash:
1)
b'!AIVDM,2,1,1,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*07'
b'!AIVDM,2,2,1,A,F@V@00000000000,2*35'
Traceback (most recent call last):
File "./get2.py", line 34, in
ais_print = message.decode()
File "/usr/local/lib/python3.7/dist-packages/pyais/messages.py", line 139, in decode
return AISMessage(self)
File "/usr/local/lib/python3.7/dist-packages/pyais/messages.py", line 151, in init
self.content = decode(self.nmea)
File "/usr/local/lib/python3.7/dist-packages/pyais/decode.py", line 677, in decode
return DECODE_MSGmsg.ais_id
File "/usr/local/lib/python3.7/dist-packages/pyais/decode.py", line 451, in decode_msg_22
'addressed': bit_arr[139],
IndexError: bitarray index out of range
2)
b'!AIVDM,2,1,9,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*0F'
b'!AIVDM,2,2,9,A,F@V@00000000000,2*3D'
Traceback (most recent call last):
File "./get2.py", line 34, in
ais_print = message.decode()
File "/usr/local/lib/python3.7/dist-packages/pyais/messages.py", line 139, in decode
return AISMessage(self)
File "/usr/local/lib/python3.7/dist-packages/pyais/messages.py", line 151, in init
self.content = decode(self.nmea)
File "/usr/local/lib/python3.7/dist-packages/pyais/decode.py", line 677, in decode
return DECODE_MSGmsg.ais_id
File "/usr/local/lib/python3.7/dist-packages/pyais/decode.py", line 451, in decode_msg_22
'addressed': bit_arr[139],
IndexError: bitarray index out of range
Looks like a problem of multipart-messages?
from pyais.
So. I took a look at your issue. There wasn't actually a bug in the decoding itself. Instead, you slightly misused the interface.
When working with multi-line messages you need to assemble them before you can decode them.
So you either have to do it like this:
msg_1_part_0 = b'!AIVDM,2,1,1,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*07'
msg_1_part_1 = b'!AIVDM,2,2,1,A,F@V@00000000000,2*35'
NMEAMessage.assemble_from_iterable(
messages=[
NMEAMessage(msg_1_part_0),
NMEAMessage(msg_1_part_1)
]
).decode().to_json()
msg_2_part_0 = b'!AIVDM,2,1,9,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*0F'
msg_2_part_1 = b'!AIVDM,2,2,9,A,F@V@00000000000,2*3D'
NMEAMessage.assemble_from_iterable(
messages=[
NMEAMessage(msg_2_part_0),
NMEAMessage(msg_2_part_1)
]
).decode().to_json()
or with the newest release it is also possible to do soimething like this:
messages = [
b'!AIVDM,2,1,1,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*07',
b'!AIVDM,2,2,1,A,F@V@00000000000,2*35',
b'!AIVDM,2,1,9,A,538CQ>02A;h?D9QC800pu8@T>0P4l9E8L0000017Ah:;;5r50Ahm5;C0,0*0F',
b'!AIVDM,2,2,9,A,F@V@00000000000,2*3D',
]
for msg in ByteStream(messages):
decoded = msg.decode()
But depending on the source of your messages you might want to take a look at the FileReaderStream
o TCPStream
.
I hope this helps. If you have further questions, feel free to ask. But I mark this issue as resolved.
from pyais.
Thank you, it helps!
(I get the data via antenna and udp broadcast, so it might get tricky to assemble the messages in the correct order but let's see .. :)
from pyais.
Interesting. I thought about adding out-of-order message support. I might add this feature in a future release together with an UDPStream.
from pyais.
Hey, that's great. I'll test it asap ...
from pyais.
I am happy to hear, that it works for you! :-)
If you observe any new issues or if you need another feature, feel free to open a new issue.
from pyais.
Related Issues (20)
- PiPY out of date? HOT 1
- Stream from serial/COM port HOT 2
- lat lon converters float accuracy HOT 2
- AtoN codes do not match R0126 (A-126) Table 3 or M.1371-5 TABLE 74 HOT 1
- Provide decoding of communication status field in types 1, 2, 3, 4, 9, 11, 18 HOT 5
- pyais fails to decode type 5 messages HOT 6
- Message Type 26 Logic may be incorrect HOT 2
- MessageType24PartA : incorrect length? HOT 6
- EpfdType Enum Missing InternalGNSS = 15 HOT 2
- Navigational statuses 9, 10, 13 and Ship type 29 HOT 3
- NoneFilter broken HOT 1
- Get Country Code HOT 5
- TCPConnection stops receiving messages HOT 4
- Determination of the communication status field HOT 5
- Encoded NRZI data HOT 1
- Timestamp for message type 1 and others HOT 1
- spare_1 field in MessageType19 converted as bytes HOT 1
- how to apply a filter to a single message HOT 5
- Decode raw payload data HOT 5
- Stream NMEA message with metadata HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyais.