Skip to content
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

ais.decode() doesn't take a raw ais NMEA sentence but it's unclear how to break up #204

Open
caileighf opened this issue Jul 31, 2020 · 1 comment

Comments

@caileighf
Copy link

Hi there -- this could my fault, but I'm not totally clear on how to consistently break apart the raw AIS NMEA sentence for the ais.decode method.

When I do this:
decoded = ais.decode('!AIVDM,1,1,,A,18UG;P0012G?Uq4EdHa=c;7@051@,0*53',0)
I get this error:
DecodeError: ais.decode: unknown message - !

But when I remove everything except the body and add the fillbits:
decoded = ais.decode('18UG;P0012G?Uq4EdHa=c;7@051@',0)
I get this
{'id': 1, 'repeat_indicator': 0, 'mmsi': 576048000, 'nav_status': 0, 'rot_over_range': False, 'rot': 0.0, 'sog': 6.599999904632568, 'position_accuracy': 0, 'x': -122.42298333333333, 'y': 37.912166666666664, 'cog': 350.0, 'true_heading': 355, 'timestamp': 40, 'special_manoeuvre': 0, 'spare': 0, 'raim': False, 'sync_state': 0, 'slot_timeout': 1, 'utc_hour': 8, 'utc_min': 20, 'utc_spare': 0}

I am hoping there is a way to pass the AIS NMEA sentence to ais.decode since it seems like there is already logic to get the fill bit and body from ais.stream.decode.

If someone could point me to the source code for ais.decode that would be much appreciated! I did search for it and I wasn't able to find it (I haven't written python bindings for C++ so this could be more obvious to others).
Thanks,
Caileigh

@caileighf
Copy link
Author

caileighf commented Jul 31, 2020

I looked through the test module and stole some code that broke up the raw messages. Here's what I came up with:

def decode_ais(raw_nmea):
    if not isinstance(raw_nmea, list):
        raw_nmea = [raw_nmea]
    body = ''.join([line.split(',')[5] for line in raw_nmea])
    pad = int(raw_nmea[-1].split('*')[0][-1])
    msg = ais.decode(body, pad)
    return(msg)

It works for the cases I've tried so far but, I would prefer not to use this code for production if there is a native alternative. Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant