mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Add DataFrameFactory with the different frame types
This commit is contained in:
parent
1cf6d5914a
commit
5c34ef40da
1 changed files with 67 additions and 0 deletions
67
modem/data_frame_factory.py
Normal file
67
modem/data_frame_factory.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
from modem_frametypes import FRAME_TYPE as FR_TYPE
|
||||||
|
import helpers
|
||||||
|
|
||||||
|
class DataFrameFactory:
|
||||||
|
|
||||||
|
def __init__(self, modem_config, modem_state, **data):
|
||||||
|
self.modem_config = modem_config
|
||||||
|
self.modem_state = modem_state
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
self.myfullcall = f"{modem_config['STATION']['mycall']}-{modem_config['STATION']['myssid']}"
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
build_method = getattr(self, self.type.name)
|
||||||
|
return build_method()
|
||||||
|
|
||||||
|
def build_ping(self):
|
||||||
|
ping_frame = bytearray(self.length_sig0_frame)
|
||||||
|
ping_frame[:1] = bytes(self.type.value)
|
||||||
|
ping_frame[1:4] = helpers.get_crc_24(self.data['dxcallsign'])
|
||||||
|
ping_frame[4:7] = helpers.get_crc_24(self.myfullcall)
|
||||||
|
ping_frame[7:13] = helpers.callsign_to_bytes(self.myfullcall)
|
||||||
|
return ping_frame
|
||||||
|
|
||||||
|
def build_cq(self):
|
||||||
|
cq_frame = bytearray(self.length_sig0_frame)
|
||||||
|
cq_frame[:1] = bytes([FR_TYPE.CQ.value])
|
||||||
|
cq_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
cq_frame[7:11] = helpers.encode_grid(self.mygrid)
|
||||||
|
return cq_frame
|
||||||
|
|
||||||
|
def build_fec_is_writing(self):
|
||||||
|
fec_frame = bytearray(14)
|
||||||
|
fec_frame[:1] = bytes([FR_TYPE.IS_WRITING.value])
|
||||||
|
fec_frame[1:7] = helpers.callsign_to_bytes(mycallsign)
|
||||||
|
return fec_frame
|
||||||
|
|
||||||
|
def build_qrv(self):
|
||||||
|
qrv_frame = bytearray(self.length_sig0_frame)
|
||||||
|
qrv_frame[:1] = bytes([FR_TYPE.QRV.value])
|
||||||
|
qrv_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
qrv_frame[7:11] = helpers.encode_grid(self.mygrid)
|
||||||
|
qrv_frame[11:12] = helpers.snr_to_bytes(snr)
|
||||||
|
return qrv_frame
|
||||||
|
|
||||||
|
def build_beacon(self):
|
||||||
|
beacon_frame = bytearray(self.length_sig0_frame)
|
||||||
|
beacon_frame[:1] = bytes([FR_TYPE.BEACON.value])
|
||||||
|
beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
beacon_frame[7:11] = helpers.encode_grid(self.mygrid)
|
||||||
|
return beacon_frame
|
||||||
|
|
||||||
|
def build_fec_wakeup(self):
|
||||||
|
mode_int_wakeup = codec2.freedv_get_mode_value_by_name("sig0")
|
||||||
|
payload_per_wakeup_frame = modem.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(mycallsign)
|
||||||
|
fec_wakeup_frame[7:8] = bytes([mode_int])
|
||||||
|
fec_wakeup_frame[8:9] = bytes([1]) # n payload bursts
|
||||||
|
return fec_wakeup_frame
|
||||||
|
|
||||||
|
def build_fec(self):
|
||||||
|
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])
|
||||||
|
return fec_frame
|
Loading…
Reference in a new issue