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

No negative altitudes #1

Open
VictorMarinus opened this issue Feb 5, 2021 · 0 comments
Open

No negative altitudes #1

VictorMarinus opened this issue Feb 5, 2021 · 0 comments

Comments

@VictorMarinus
Copy link

Apparently the code can not handle negative altitudes. Those living in the low-lands will get weird results. going from 0 m to 65535m between two measurements.
The altitude hex code from the LOCUS dump is "two's complement" so it has to be treated like that.
I added the twos_complement function and changed the parseInt function and now the results match the NMEA parsed results.

`def parseInt(bytes):
if len(bytes) != 2:
print >> sys.stderr, "WARNING: expecting 2 bytes got %s" % bytes
number = ((0xFF & bytes[1]) << 8) | (0xFF & bytes[0])
number = twos_complement(number, 16)
return number

def twos_complement(n, w):
if n & (1 << (w - 1)): n = n - (1 << w)
return n`

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