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

Encoding large (Type 5) messages causes NMEA max message length to exceed 82 characters. #81

Closed
bgercken opened this issue Sep 26, 2022 · 8 comments · Fixed by #84
Closed
Assignees
Labels
bug Something isn't working

Comments

@bgercken
Copy link

Was running into an issue in encode.py ais_to_nmea_0183 where it was causing messages to exceed the NMEA max size.

On line 54 (in encode.py) I changed max_len to 60, which seems to have resolved it.

Thanks.

@M0r13n M0r13n self-assigned this Sep 27, 2022
@M0r13n M0r13n added the bug Something isn't working label Sep 27, 2022
@M0r13n
Copy link
Owner

M0r13n commented Sep 27, 2022

@bgercken Thank you for bringing this up. I will look at this but as soon as time allows. But it might take a couple of days.

@bgercken
Copy link
Author

No hurry on my part. Thank you very much.

@M0r13n
Copy link
Owner

M0r13n commented Oct 1, 2022

@bgercken

Could you provide me some example that led to this issue? I am not able to reproduce the described behavior.

@bgercken
Copy link
Author

bgercken commented Oct 2, 2022

Below is output for encoding the following data.

data: {'type': 5, 'repeat': 0, 'mmsi': '538008122', 'ais_version': 1, 'imo': 9500091, 'callsign': 'V7GS3', 'shipname': 'CLIPPER BAROLO', 'shiptype': 70, 'to_bow': 166, 'to_stern': 30, 'to_port': 22, 'to_starboard': 10, 'epfd': 1, 'month': 5, 'day': 16, 'hour': 0, 'minute': 30, 'draught': 6.6, 'destination': 'BALTIMORE', 'dte': 0}

sentence: !AIVDO,2,1,0,A,5815J>T2@uKeKLM?<00<hU10E:0858tht0000000DhNF:5H0N@PPC52CClQ@0,0*28 (81)

sentence: !AIVDO,2,2,0,A,0000000000,2*16 (30)

UPDATE: actually 81 is too long. When you append the NMEA terminator it exceeds the max sentence length.

@bgercken bgercken closed this as completed Oct 2, 2022
@bgercken
Copy link
Author

bgercken commented Oct 2, 2022

I had closed this but it still appears to be an issue.

Updated test fails:

from pyais import encode_dict

data = {
    'type': 5, 'repeat': 0, 'mmsi': '259725000', 'ais_version': 1, 'imo': 9103128, 'callsign': 'LAXP4',
    'shipname': 'STAR HANSA', 'shiptype': 70, 'to_bow': 177, 'to_stern': 22, 'to_port': 17, 'to_starboard': 14,
    'epfd': 1, 'month': 5, 'day': 20, 'hour': 6, 'minute': 0, 'draught': 7.4, 'destination': 'US BAL', 'dte': 0
}


# Maximum sentence length, including the $ and <CR><LF> is 82 bytes.
NMEA_MAX_LEN = 82
NMEA_TERMINATOR = "\r\n"


def test_encode_type5():
    encoded = encode_dict(data)
    for i in range(len(encoded)):
        encoded[i] += NMEA_TERMINATOR
        assert len(encoded[i]) <= NMEA_MAX_LEN


if __name__ == "__main__":
    test_encode_type5()

@bgercken bgercken reopened this Oct 2, 2022
@M0r13n
Copy link
Owner

M0r13n commented Oct 2, 2022

Thank you. I am pretty sure that I forgot to include the final <LF> terminator when calculating the total length of a message. I will fix this tomorrow.

@M0r13n
Copy link
Owner

M0r13n commented Oct 3, 2022

@bgercken

You were right. The max payload length should be set to 60 and not 61. The docstring of the relevant method actually mentions this:

This method takes care of splitting large payloads (larger than 60 characters)
into multiple sentences. With a total of 80 maximum chars excluding end of line
per sentence, and 20 chars head + tail in the nmea 0183 carrier protocol, 60
chars remain for the actual payload.

But then the implementation sets max_len to 61 (see).

@M0r13n
Copy link
Owner

M0r13n commented Oct 3, 2022

Should be fixed with version 2.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants