-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexError: bitarray index out of range #3
Comments
Hey, thanks your issue. Could you provide the exact raw message that leads to this crash? Thank you |
Yes, I try to get these ... |
I have two examples for now. 1)
Traceback (most recent call last): 2)
Traceback (most recent call last): Looks like a problem of multipart-messages? |
Thank you again for the messages. I will dig into it. |
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 I hope this helps. If you have further questions, feel free to ask. But I mark this issue as resolved. |
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 .. :) |
Interesting. I thought about adding out-of-order message support. I might add this feature in a future release together with an UDPStream. |
Hey, I integrated a native 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 |
Hey, that's great. I'll test it asap ... |
I had some time to test it with live AIS data and it worked perfectly fine for me. It crashed once in the beginning but only inside the json conversion: I had one more crash adding data to the db:
but haven't looked into it and probably hasn't got anthing to do with your code. |
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. |
Hi,
I have this message:
ais_print = message.decode()
and I get this:
{'type': 5, 'repeat': 0, 'mmsi': 248659000, 'ais_version': 1, 'imo': 9745500, 'callsign': '9HA4748', 'shipname': 'CMA CGM PREGOLIA', 'shiptype': <ShipType.Cargo_HazardousCategory_A: 71>, 'to_bow': 183, 'to_stern': 12, 'to_port': 30, 'to_starboard': 2, 'epfd': <EpfdType.GPS: 1>, 'month': 7, 'day': 20, 'hour': 22, 'minute': 30, 'draught': 10.5, 'destination': 'DEHAM', 'dte': False}
then
ais_content = message.decode().to_json()
and I get this:
{'nmea': {'ais_id': 5, 'raw': '!AIVDM,2,1,2,B,53e8t>42De5kTP7COCP<l60<Ln118DLthT400017Fp<N25rFNJA1B0CH,0*18', 'talker': 'AI', 'msg_type': 'VDM', 'count': 2, 'index': 1, 'seq_id': '2', 'channel': 'B', 'data': '53e8t>42De5kTP7COCP<l60<Ln118DLthT400017Fp<N25rFNJA1B0CH', 'checksum': 24, 'bit_array': '000101000011101101001000111100001110000100000010010100101101000101110011100100100000000111010011011111010011100000001100110100000110000000001100011100110110000001000001001000010100011100111100110000100100000100000000000000000000000001000111010110111000001100011110000010000101111010010110011110011010010001000001010010000000010011011000'}, 'decoded': {'type': 5, 'repeat': 0, 'mmsi': 248659000, 'ais_version': 1, 'imo': 9745500, 'callsign': '9HA4748', 'shipname': 'CMA CGM PREGOLIA', 'shiptype': 71, 'to_bow': 183, 'to_stern': 12, 'to_port': 30, 'to_starboard': 2, 'epfd': 1, 'month': 7, 'day': 20, 'hour': 22, 'minute': 30, 'draught': 10.5, 'destination': 'DEHAM', 'dte': False}, 'date': '2020-07-20 23:17:14.338438'}
The 'date' is added later on to the dict.
And with the next message pyais crushes, not sure if it is a coincident with the messages above:
Traceback (most recent call last):
File "./get2.py", line 31, 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 38, in decode_msg_1
'raim': bit_arr[148],
IndexError: bitarray index out of range
Not sure how to debug this, hope it helps?!
Best
Frank
The text was updated successfully, but these errors were encountered: