diff --git a/modem/command_feq.py b/modem/command_feq.py new file mode 100644 index 00000000..d2364365 --- /dev/null +++ b/modem/command_feq.py @@ -0,0 +1,29 @@ +from command import TxCommand +import base64 + +class FecCommand(TxCommand): + + def set_params_from_api(self, apiParams): + self.mode = apiParams['mode'] + self.wakeup = apiParams['wakeup'] + payload_b64 = apiParams['payload'] + + if len(payload_b64) % 4: + raise TypeError + self.payload = base64.b64decode(payload_b64) + + return super().set_params_from_api(apiParams) + + def build_wakeup_frame(self): + return self.frame_factory.build_fec_wakeup(self.mode) + + def build_frame(self): + return self.frame_factory.build_fec(self. mode, self.payload) + + def transmit(self, tx_frame_queue): + if self.wakeup: + tx_queue_item = [self.get_c2_mode(), 1, 0, self.build_wakeup_frame()] + tx_frame_queue.put(tx_queue_item) + + tx_queue_item = [self.get_c2_mode(), 1, 0, self.build_frame()] + tx_frame_queue.put(tx_queue_item) diff --git a/modem/data_frame_factory.py b/modem/data_frame_factory.py index 7c3e86e3..15e1d6c1 100644 --- a/modem/data_frame_factory.py +++ b/modem/data_frame_factory.py @@ -58,8 +58,9 @@ class DataFrameFactory: return beacon_frame def build_fec_wakeup(self, mode): + mode_int = codec2.freedv_get_mode_value_by_name(mode) mode_int_wakeup = codec2.freedv_get_mode_value_by_name("sig0") - payload_per_wakeup_frame = self.modem.get_bytes_per_frame(mode_int_wakeup) - 2 + payload_per_wakeup_frame = codec2.get_bytes_per_frame(mode_int_wakeup) - 2 fec_wakeup_frame = bytearray(payload_per_wakeup_frame) fec_wakeup_frame[:1] = bytes([FR_TYPE.FEC_WAKEUP.value]) fec_wakeup_frame[1:7] = helpers.callsign_to_bytes(self.myfullcall) @@ -67,7 +68,10 @@ class DataFrameFactory: fec_wakeup_frame[8:9] = bytes([1]) # n payload bursts return fec_wakeup_frame - def build_fec(self, payload): + def build_fec(self, mode, payload): + mode_int = codec2.freedv_get_mode_value_by_name(mode) + payload_per_frame = codec2.get_bytes_per_frame(mode_int) - 2 + fec_payload_length = payload_per_frame - 1 fec_frame = bytearray(payload_per_frame) fec_frame[:1] = bytes([FR_TYPE.FEC.value]) fec_frame[1:payload_per_frame] = bytes(payload[:fec_payload_length])