From a5148d5a229e79fc18afb46c20f0ea5baf6b0726 Mon Sep 17 00:00:00 2001 From: Arne Date: Sun, 17 Mar 2024 17:03:21 +0100 Subject: [PATCH] #1 Moved WindAlarm to own file --- seatalk/__init__.py | 1 + seatalk/s66_wind_alarm.py | 43 +++++++++++++++++++++++++++++++++++++ seatalk/seatalk_datagram.py | 39 --------------------------------- 3 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 seatalk/s66_wind_alarm.py diff --git a/seatalk/__init__.py b/seatalk/__init__.py index cb4a828..7a6e70d 100644 --- a/seatalk/__init__.py +++ b/seatalk/__init__.py @@ -27,3 +27,4 @@ from seatalk.s59_countdown_timer import CountdownTimer from seatalk.s60_e80_initialization import E80Initialization from seatalk.s65_select_fathom import SelectFathom +from seatalk.s66_wind_alarm import WindAlarm diff --git a/seatalk/s66_wind_alarm.py b/seatalk/s66_wind_alarm.py new file mode 100644 index 0000000..d8afa6f --- /dev/null +++ b/seatalk/s66_wind_alarm.py @@ -0,0 +1,43 @@ +import enum + +from seatalk.seatalk_datagram import SeatalkDatagram + + +class WindAlarm(SeatalkDatagram): + """ + 66 00 XY Wind alarm as indicated by flags in XY: + X&8 = 8: Apparent Wind angle low + X&4 = 4: Apparent Wind angle high + X&2 = 2: Apparent Wind speed low + X&1 = 1: Apparent Wind speed high + Y&8 = 8: True Wind angle low + Y&4 = 4: True Wind angle high + Y&2 = 2: True Wind speed low + Y&1 = 1: True Wind speed high (causes Wind-High-Alarm on ST40 Wind Instrument) + XY =00: End of wind alarm (only sent once) + """ + seatalk_id = 0x66 + data_length = 0 + + class Alarm(enum.IntEnum): + AngleLow = 0x08 + AngleHigh = 0x04 + SpeedLow = 0x02 + SpeedHigh = 0x01 + NoAlarm = 0x00 + + def __init__(self, apparent_alarm: Alarm=None, true_alarm: Alarm=None): + SeatalkDatagram.__init__(self) + self.apparent_alarm = apparent_alarm + self.true_alarm = true_alarm + + def process_datagram(self, first_half_byte, data): + x_nibble = (data[0] & 0xF0) >> 4 + y_nibble = (data[0] & 0x0F) + self.apparent_alarm = self.Alarm(x_nibble) # TODO enum exception + self.true_alarm = self.Alarm(y_nibble) + + def get_seatalk_datagram(self): + x_nibble = self.apparent_alarm.value << 4 # TODO enum exception + y_nibble = self.true_alarm.value + return bytearray([self.seatalk_id, self.data_length, (x_nibble | y_nibble)]) diff --git a/seatalk/seatalk_datagram.py b/seatalk/seatalk_datagram.py index 7b82857..9300918 100644 --- a/seatalk/seatalk_datagram.py +++ b/seatalk/seatalk_datagram.py @@ -334,45 +334,6 @@ def get_seatalk_datagram(self): -class WindAlarm(SeatalkDatagram): - """ - 66 00 XY Wind alarm as indicated by flags in XY: - X&8 = 8: Apparent Wind angle low - X&4 = 4: Apparent Wind angle high - X&2 = 2: Apparent Wind speed low - X&1 = 1: Apparent Wind speed high - Y&8 = 8: True Wind angle low - Y&4 = 4: True Wind angle high - Y&2 = 2: True Wind speed low - Y&1 = 1: True Wind speed high (causes Wind-High-Alarm on ST40 Wind Instrument) - XY =00: End of wind alarm (only sent once) - """ - seatalk_id = 0x66 - data_length = 0 - - class Alarm(enum.IntEnum): - AngleLow = 0x08 - AngleHigh = 0x04 - SpeedLow = 0x02 - SpeedHigh = 0x01 - NoAlarm = 0x00 - - def __init__(self, apparent_alarm: Alarm=None, true_alarm: Alarm=None): - SeatalkDatagram.__init__(self) - self.apparent_alarm = apparent_alarm - self.true_alarm = true_alarm - - def process_datagram(self, first_half_byte, data): - x_nibble = (data[0] & 0xF0) >> 4 - y_nibble = (data[0] & 0x0F) - self.apparent_alarm = self.Alarm(x_nibble) # TODO enum exception - self.true_alarm = self.Alarm(y_nibble) - - def get_seatalk_datagram(self): - x_nibble = self.apparent_alarm.value << 4 # TODO enum exception - y_nibble = self.true_alarm.value - return bytearray([self.seatalk_id, self.data_length, (x_nibble | y_nibble)]) - class AlarmAcknowledgement(SeatalkDatagram): """