Skip to content

Commit

Permalink
Makes type 27 messages lat and lon signed
Browse files Browse the repository at this point in the history
  • Loading branch information
M0r13n committed Apr 24, 2022
1 parent 57b1f8f commit 476e6c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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 476e6c2

Please sign in to comment.