Skip to content

Commit

Permalink
Merge pull request #67 from M0r13n/type-27-messages-should-be-signed
Browse files Browse the repository at this point in the history
Makes type 27 messages lat and lon signed
  • Loading branch information
M0r13n authored Apr 24, 2022
2 parents 57b1f8f + 02efdee commit 5913c44
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
====================
pyais CHANGELOG
====================
-------------------------------------------------------------------------------
Version 2.1.1 24 Apr 2022
-------------------------------------------------------------------------------
* Closes https://github.com/M0r13n/pyais/issues/65
* makes lat and lon signed for type 27 messages
* drops nosetest as a development dependency


-------------------------------------------------------------------------------
Version 2.1.0 14 Apr 2022
-------------------------------------------------------------------------------
Expand Down
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.1.0'
__version__ = '2.1.1'
__author__ = 'Leon Morten Richter'

__all__ = (
Expand Down
4 changes: 2 additions & 2 deletions pyais/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ class MessageType27(Payload):
accuracy = bit_field(1, bool, default=0, signed=False)
raim = bit_field(1, bool, default=0, signed=False)
status = bit_field(4, int, default=0, from_converter=NavigationStatus, to_converter=NavigationStatus, signed=False)
lon = bit_field(18, float, from_converter=from_lat_lon_600, to_converter=to_lat_lon_600, default=0)
lat = bit_field(17, float, from_converter=from_lat_lon_600, to_converter=to_lat_lon_600, default=0)
lon = bit_field(18, float, from_converter=from_lat_lon_600, to_converter=to_lat_lon_600, default=0, signed=True)
lat = bit_field(17, float, from_converter=from_lat_lon_600, to_converter=to_lat_lon_600, default=0, signed=True)
speed = bit_field(6, float, default=0, signed=False)
course = bit_field(9, float, default=0, signed=False)
gnss = bit_field(1, bool, default=0, signed=False)
Expand Down
28 changes: 22 additions & 6 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@

from pyais import NMEAMessage, encode_dict
from pyais.ais_types import AISType
from pyais.constants import ManeuverIndicator, NavigationStatus, ShipType, NavAid, EpfdType, StationType, TransmitMode
from pyais.constants import (EpfdType, ManeuverIndicator, NavAid,
NavigationStatus, ShipType, StationType,
TransmitMode)
from pyais.decode import decode
from pyais.exceptions import UnknownMessageException
from pyais.messages import MessageType18, MessageType5, MessageType6, MSG_CLASS, MessageType24PartA, MessageType24PartB, \
MessageType25AddressedStructured, MessageType25BroadcastStructured, MessageType25AddressedUnstructured, \
MessageType25BroadcastUnstructured, MessageType26AddressedStructured, MessageType26BroadcastStructured, \
MessageType26BroadcastUnstructured, MessageType22Addressed, MessageType22Broadcast, to_turn, from_turn
from pyais.messages import (MSG_CLASS, MessageType5, MessageType6,
MessageType18, MessageType22Addressed,
MessageType22Broadcast, MessageType24PartA,
MessageType24PartB,
MessageType25AddressedStructured,
MessageType25AddressedUnstructured,
MessageType25BroadcastStructured,
MessageType25BroadcastUnstructured,
MessageType26AddressedStructured,
MessageType26BroadcastStructured,
MessageType26BroadcastUnstructured, from_turn,
to_turn)
from pyais.stream import ByteStream
from pyais.util import bytes2bits, bits2bytes, b64encode_str
from pyais.util import b64encode_str, bits2bytes, bytes2bits


def ensure_type_for_msg_dict(msg_dict: typing.Dict[str, typing.Any]) -> None:
Expand Down Expand Up @@ -679,6 +689,12 @@ def test_msg_type_27(self):

ensure_type_for_msg_dict(msg)

def test_msg_type_27_signed(self):
msg = decode('!AIVDO,1,1,,A,K01;FQh?PbtE3P00,0*75').asdict()
assert msg['mmsi'] == 1234567
assert msg['lon'] == -13.368333
assert msg['lat'] == -50.121667

def test_broken_messages(self):
# Undefined epfd
assert decode(b"!AIVDM,1,1,,B,4>O7m7Iu@<9qUfbtm`vSnwvH20S8,0*46").asdict()['epfd'] == EpfdType.Undefined
Expand Down

0 comments on commit 5913c44

Please sign in to comment.