Code Monkey home page Code Monkey logo

Comments (5)

M0r13n avatar M0r13n commented on July 25, 2024 2

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.

asuagar avatar asuagar commented on July 25, 2024 1

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.

M0r13n avatar M0r13n commented on July 25, 2024

Thank you for this issue. I will dig into it at the weekend!

Greetings,
Leon

from pyais.

asuagar avatar asuagar commented on July 25, 2024

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.

M0r13n avatar M0r13n commented on July 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.