Skip to content

Commit

Permalink
#1 Moved EquipmentID1 to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegue committed Mar 17, 2024
1 parent 841a8d1 commit accc613
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
1 change: 1 addition & 0 deletions seatalk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from seatalk.seatalk import SeatalkDevice

from seatalk.s00_depth_datagram import DepthDatagram
from seatalk.s01_equipment_id import EquipmentID1
from seatalk.s36_cancel_mob import CancelMOB
from seatalk.s38_code_lock_data import CodeLockData
39 changes: 39 additions & 0 deletions seatalk/s01_equipment_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import enum

from common.helper import TwoWayDict
from seatalk.seatalk_datagram import _TwoWayDictDatagram


class EquipmentID1(_TwoWayDictDatagram):
"""
01 05 XX XX XX XX XX XX Equipment ID, sent at power on, reported examples:
01 05 00 00 00 60 01 00 Course Computer 400G
01 05 04 BA 20 28 01 00 ST60 Tridata
01 05 70 99 10 28 01 00 ST60 Log
01 05 F3 18 00 26 0F 06 ST80 Masterview
01 05 FA 03 00 30 07 03 ST80 Maxi Display
01 05 FF FF FF D0 00 00 Smart Controller Remote Control Handset
"""
seatalk_id = 0x01
data_length = 5

class Equipments(enum.IntEnum):
Course_Computer_400G = enum.auto()
ST60_Tridata = enum.auto()
ST60_Tridata_Plus = enum.auto()
ST60_Log = enum.auto()
ST80_Masterview = enum.auto()
ST80_Maxi_Display = enum.auto()
Smart_Controller_Remote_Control_Handset = enum.auto()

def __init__(self, set_key: Equipments = None):
equipment_map = TwoWayDict({
bytes([0x00, 0x00, 0x00, 0x60, 0x01, 0x00]): self.Equipments.Course_Computer_400G,
bytes([0x04, 0xBA, 0x20, 0x28, 0x01, 0x00]): self.Equipments.ST60_Tridata,
bytes([0x87, 0x72, 0x25, 0x28, 0x01, 0x00]): self.Equipments.ST60_Tridata_Plus,
bytes([0x70, 0x99, 0x10, 0x28, 0x01, 0x00]): self.Equipments.ST60_Log,
bytes([0xF3, 0x18, 0x00, 0x26, 0x0F, 0x06]): self.Equipments.ST80_Masterview,
bytes([0xFA, 0x03, 0x00, 0x30, 0x07, 0x03]): self.Equipments.ST80_Maxi_Display,
bytes([0xFF, 0xFF, 0xFF, 0xD0, 0x00, 0x00]): self.Equipments.Smart_Controller_Remote_Control_Handset,
})
_TwoWayDictDatagram.__init__(self, map=equipment_map, set_key=set_key)
36 changes: 0 additions & 36 deletions seatalk/seatalk_datagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,6 @@ def get_seatalk_datagram(self, first_half_byte=0):
first_byte = first_half_byte << 4 | self.data_length
return bytearray([self.seatalk_id, first_byte]) + map_bytes


class EquipmentIDDatagram1(_TwoWayDictDatagram):
"""
01 05 XX XX XX XX XX XX Equipment ID, sent at power on, reported examples:
01 05 00 00 00 60 01 00 Course Computer 400G
01 05 04 BA 20 28 01 00 ST60 Tridata
01 05 70 99 10 28 01 00 ST60 Log
01 05 F3 18 00 26 0F 06 ST80 Masterview
01 05 FA 03 00 30 07 03 ST80 Maxi Display
01 05 FF FF FF D0 00 00 Smart Controller Remote Control Handset
"""
seatalk_id = 0x01
data_length = 5

class Equipments(enum.IntEnum):
Course_Computer_400G = enum.auto()
ST60_Tridata = enum.auto()
ST60_Tridata_Plus = enum.auto()
ST60_Log = enum.auto()
ST80_Masterview = enum.auto()
ST80_Maxi_Display = enum.auto()
Smart_Controller_Remote_Control_Handset = enum.auto()

def __init__(self, set_key: Equipments=None):
equipment_map = TwoWayDict({
bytes([0x00, 0x00, 0x00, 0x60, 0x01, 0x00]): self.Equipments.Course_Computer_400G,
bytes([0x04, 0xBA, 0x20, 0x28, 0x01, 0x00]): self.Equipments.ST60_Tridata,
bytes([0x87, 0x72, 0x25, 0x28, 0x01, 0x00]): self.Equipments.ST60_Tridata_Plus,
bytes([0x70, 0x99, 0x10, 0x28, 0x01, 0x00]): self.Equipments.ST60_Log,
bytes([0xF3, 0x18, 0x00, 0x26, 0x0F, 0x06]): self.Equipments.ST80_Masterview,
bytes([0xFA, 0x03, 0x00, 0x30, 0x07, 0x03]): self.Equipments.ST80_Maxi_Display,
bytes([0xFF, 0xFF, 0xFF, 0xD0, 0x00, 0x00]): self.Equipments.Smart_Controller_Remote_Control_Handset,
})
_TwoWayDictDatagram.__init__(self, map=equipment_map, set_key=set_key)


class ApparentWindAngleDatagram(SeatalkDatagram): # TODO nmea mwv with ApparentWindSpeed
"""
10 01 XX YY Apparent Wind Angle: XXYY/2 degrees right of bow
Expand Down
4 changes: 2 additions & 2 deletions tests/test_seatalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def _read(self, length=1):
def get_parameters():
return ("seatalk_datagram", "byte_representation"), (
(DepthDatagram(depth_m=22.3), bytes([0x00, 0x02, 0x00, 0xDB, 0x02])),
(EquipmentIDDatagram1(EquipmentIDDatagram1.Equipments.ST60_Tridata), bytes([0x01, 0x05, 0x04, 0xBA, 0x20, 0x28, 0x01, 0x00])),
(EquipmentID1(EquipmentID1.Equipments.ST60_Tridata), bytes([0x01, 0x05, 0x04, 0xBA, 0x20, 0x28, 0x01, 0x00])),
(ApparentWindAngleDatagram(256.5), bytes([0x10, 0x01, 0x01, 0x02])),
(ApparentWindSpeedDatagram(18.3), bytes([0x11, 0x01, 0x12, 0x03])),
(SpeedDatagram(speed_knots=8.31), bytes([0x20, 0x01, 0x53, 0x00])),
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_check_datagram_to_seatalk(seatalk_datagram, byte_representation):


@pytest.mark.parametrize("seatalk_datagram_instance", (
EquipmentIDDatagram1(9),
EquipmentID1(9),
SetLampIntensity1(9)
))
def test_two_way_maps_validations(seatalk_datagram_instance):
Expand Down

0 comments on commit accc613

Please sign in to comment.