Comments (5)
I found the bug. I was importing from the wrong place. I changed:
from typing imort OrderedDict
to
from collections import OrderedDict
This should fix your issue. Please tell me, if it works for you now!
Greetings
from pyais.
Thank you so much for the explanation. The header of the line helps the parser. Now, the code works! The last field could be a checksum.
https://en.wikipedia.org/wiki/Automatic_identification_system#Message_format
from pyais.
Thank you for this issue. I will dig into it at the weekend!
Greetings,
Leon
from pyais.
Hello @M0r13n, thank you for your fast reply. I tried to run script again. The error has changed.
ValueError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pyais/stream.py in _assemble_messages(self)
34 msg: NMEAMessage = NMEAMessage(line)
35 except Exception as e:
---> 36 raise ValueError(f'Failed to parse line "{line}"') from e
37
38 # Be gentle and just skip invalid messages
ValueError: Failed to parse line "b'!SAVDM,1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68,1602757282\n'"
I think the problem is in the header of the line. "!SVADM," is adding an extrafield and, now, there are eight fields. I tried to avoid this error running the following code:
from pyais.messages import NMEAMessage
line = '!SAVDM,1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68,1602757282\n'
NMEAMessage(line[7:])
However I get a new error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-37-9cb3f40e5084> in <module>()
----> 1 NMEAMessage(line[7:])
/usr/local/lib/python3.6/dist-packages/pyais/messages.py in __init__(self, raw)
34
35 # An AIS NMEA message consists of seven, comma separated parts
---> 36 # values = raw.split(b",")
37 values = raw.split(',')
38
TypeError: must be str or None, not bytes
I cannot understand where is the problem. Thank you by your kindly attention.
from pyais.
Hey,
you are correct. The lib only supports seven, comma separated values. You spotted the problem, but your approach was slightly off. If you do the following, it works:
msg = NMEAMessage(b"!SAVDM,1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68")
assert msg.decode()
it works. You didn't split the string correctly:
>>> line = '!SAVDM,1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68,1602757282\n'
# The following print the full line starting at the 7th character:
>>> line[7:]
'1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68,1602757282\n'
# Instead you first need to split the message into it's comma separated parts and after that reassemble it - without the last part:
>>> ','.join(line.split(',')[:-1])
'!SAVDM,1,1,0,A,H52M2B4TB1I0000<925BDI200300,0*68'
from pyais.
Related Issues (20)
- [docs] messages.rst content duplicated. HOT 1
- 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 4
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.