Implement fec and fec wake up frames

This commit is contained in:
Pedro 2023-11-25 23:22:31 +01:00
parent f96c566223
commit cf50e69e3a
2 changed files with 35 additions and 2 deletions

29
modem/command_feq.py Normal file
View file

@ -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)

View file

@ -58,8 +58,9 @@ class DataFrameFactory:
return beacon_frame return beacon_frame
def build_fec_wakeup(self, mode): 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") 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 = bytearray(payload_per_wakeup_frame)
fec_wakeup_frame[:1] = bytes([FR_TYPE.FEC_WAKEUP.value]) fec_wakeup_frame[:1] = bytes([FR_TYPE.FEC_WAKEUP.value])
fec_wakeup_frame[1:7] = helpers.callsign_to_bytes(self.myfullcall) 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 fec_wakeup_frame[8:9] = bytes([1]) # n payload bursts
return fec_wakeup_frame 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 = bytearray(payload_per_frame)
fec_frame[:1] = bytes([FR_TYPE.FEC.value]) fec_frame[:1] = bytes([FR_TYPE.FEC.value])
fec_frame[1:payload_per_frame] = bytes(payload[:fec_payload_length]) fec_frame[1:payload_per_frame] = bytes(payload[:fec_payload_length])