Skip to content

Commit

Permalink
Merge pull request #64 from M0r13n/63-fix-inconsistencies
Browse files Browse the repository at this point in the history
Fix inconsistencies and add a 'rate_of_turn' property to typ 1,2,3 me…
  • Loading branch information
M0r13n authored Apr 14, 2022
2 parents b50fd4d + 72961ce commit 21da419
Show file tree
Hide file tree
Showing 12 changed files with 733 additions and 323 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
====================
pyais CHANGELOG
====================
-------------------------------------------------------------------------------
Version 2.1.0 14 Apr 2022
-------------------------------------------------------------------------------
* Closes https://github.com/M0r13n/pyais/issues/63#issuecomment-1099045541
* unifies naming of fields across all message types
* makes all single bit fields booleans
* replaces the raw turn value with the actual rate of turn: (turn/4.733)**2
* makes all data fields raw bytes instead of (large) integers for interoperability
* makes speed and course floats instead of ints
* enforces strict types and fixes typing inconsistencies

-------------------------------------------------------------------------------
Version 2.0.3 27 Mar 2022
-------------------------------------------------------------------------------
Expand Down
95 changes: 52 additions & 43 deletions docs/messages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Therefore ``pyais`` does not even try to decode the payload. Instead, you can ac

payload = msg.data

The data is stored as raw bytes to make it easy to post process such binary payload.
The lib also includes some handy helper functions to transform bytes to bits and vice versa::

from pyais.utils import bits2bytes, bytes2bits

bits2bytes('00100110') #=> b'&'
bytes2bits(b'&').to01() #=> '00100110'

NMEA messages
----------------

Expand Down Expand Up @@ -121,23 +129,23 @@ MessageType1
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -191,23 +199,23 @@ MessageType1
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -261,23 +269,23 @@ MessageType2
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -331,23 +339,23 @@ MessageType3
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -421,11 +429,11 @@ MessageType4
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `epfd`
Expand All @@ -437,7 +445,7 @@ MessageType4
* bit-width: 10
* default: 0
* `raim`
* type: <class 'int'>
* type: <class 'bool'>
* bit-width: 1
* default: 0
* `radio`
Expand Down Expand Up @@ -519,7 +527,7 @@ MessageType5
* bit-width: 6
* default: 0
* `draught`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 8
* default: 0
* `destination`
Expand All @@ -536,7 +544,7 @@ MessageType5
* default: 0
MessageType6
Binary Addresses Message
Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_6_binary_addressed_message
Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_4_base_station_report


Attributes:
Expand Down Expand Up @@ -699,15 +707,15 @@ MessageType9
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `second`
Expand All @@ -731,7 +739,7 @@ MessageType9
* bit-width: 1
* default: 0
* `raim`
* type: <class 'int'>
* type: <class 'bool'>
* bit-width: 1
* default: 0
* `radio`
Expand Down Expand Up @@ -815,11 +823,11 @@ MessageType11
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `epfd`
Expand All @@ -831,7 +839,7 @@ MessageType11
* bit-width: 10
* default: 0
* `raim`
* type: <class 'int'>
* type: <class 'bool'>
* bit-width: 1
* default: 0
* `radio`
Expand Down Expand Up @@ -1090,11 +1098,11 @@ MessageType17
* bit-width: 2
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 18
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 17
* default: 0
* `spare_2`
Expand Down Expand Up @@ -1128,23 +1136,23 @@ MessageType18
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -1214,23 +1222,23 @@ MessageType19
* bit-width: 8
* default: 0
* `speed`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 10
* default: 0
* `accuracy`
* type: <class 'int'>
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `course`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 12
* default: 0
* `heading`
Expand Down Expand Up @@ -1406,11 +1414,11 @@ MessageType21
* bit-width: 1
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 28
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 27
* default: 0
* `to_bow`
Expand Down Expand Up @@ -1554,19 +1562,19 @@ MessageType27
* bit-width: 1
* default: 0
* `raim`
* type: <class 'int'>
* type: <class 'bool'>
* bit-width: 1
* default: 0
* `status`
* type: <class 'int'>
* bit-width: 4
* default: 0
* `lon`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 18
* default: 0
* `lat`
* type: <class 'int'>
* type: <class 'float'>
* bit-width: 17
* default: 0
* `speed`
Expand All @@ -1585,3 +1593,4 @@ MessageType27
* type: <class 'int'>
* bit-width: 1
* default: 0

22 changes: 22 additions & 0 deletions examples/binary_payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import bitarray

from pyais import decode
from pyais.util import bits2bytes, bytes2bits

# This is a message of type 6 which contains binary payload
msg = decode(b"!AIVDM,1,1,,B,6B?n;be:cbapalgc;i6?Ow4,2*4A")

assert msg.msg_type == 6

# The payload is bytes by default
assert msg.data == b'\xeb/\x11\x8f\x7f\xf1'


# But using `bytes2bits` you can convert the bytes into a bitarray
assert bytes2bits(msg.data) == bitarray.bitarray('111010110010111100010001100011110111111111110001')

# Or to a bitstring using the bitarray to01() method
assert bytes2bits(msg.data).to01() == '111010110010111100010001100011110111111111110001'

# It is also possible to transform a set of bits back to bytes
assert bits2bytes('111010110010111100010001100011110111111111110001') == b'\xeb/\x11\x8f\x7f\xf1'
2 changes: 1 addition & 1 deletion pyais/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pyais.decode import decode

__license__ = 'MIT'
__version__ = '2.0.3'
__version__ = '2.1.0'
__author__ = 'Leon Morten Richter'

__all__ = (
Expand Down
Loading

0 comments on commit 21da419

Please sign in to comment.