2023-12-05 17:50:39 +00:00
|
|
|
import queue, threading
|
2023-12-06 10:59:35 +00:00
|
|
|
import codec2
|
2023-12-05 17:50:39 +00:00
|
|
|
import data_frame_factory
|
2023-12-05 18:12:21 +00:00
|
|
|
import structlog
|
2023-12-05 17:50:39 +00:00
|
|
|
|
|
|
|
class ARQSession():
|
|
|
|
|
|
|
|
MODE_BY_SPEED = [
|
2023-12-13 10:51:54 +00:00
|
|
|
codec2.FREEDV_MODE.datac4,
|
|
|
|
codec2.FREEDV_MODE.datac3,
|
|
|
|
codec2.FREEDV_MODE.datac1,
|
2023-12-06 10:32:59 +00:00
|
|
|
]
|
|
|
|
|
2023-12-05 17:50:39 +00:00
|
|
|
def __init__(self, config: dict, tx_frame_queue: queue.Queue, dxcall: str):
|
2023-12-05 18:12:21 +00:00
|
|
|
self.logger = structlog.get_logger(type(self).__name__)
|
2023-12-05 17:50:39 +00:00
|
|
|
self.config = config
|
|
|
|
|
|
|
|
self.dxcall = dxcall
|
|
|
|
|
|
|
|
self.tx_frame_queue = tx_frame_queue
|
|
|
|
self.speed_level = 0
|
|
|
|
|
|
|
|
self.frame_factory = data_frame_factory.DataFrameFactory(self.config)
|
|
|
|
|
|
|
|
self.id = None
|
|
|
|
|
2023-12-11 18:02:50 +00:00
|
|
|
def log(self, message, isWarning = False):
|
|
|
|
msg = f"[{type(self).__name__}]: {message}"
|
|
|
|
logger = self.logger.warn if isWarning else self.logger.info
|
|
|
|
logger(msg)
|
2023-12-10 08:59:02 +00:00
|
|
|
|
2023-12-05 17:50:39 +00:00
|
|
|
def get_mode_by_speed_level(self, speed_level):
|
|
|
|
return self.MODE_BY_SPEED[speed_level]
|
|
|
|
|
2023-12-05 18:01:48 +00:00
|
|
|
def transmit_frame(self, frame: bytearray):
|
2023-12-11 18:02:50 +00:00
|
|
|
self.log("Transmitting frame")
|
2023-12-05 18:01:48 +00:00
|
|
|
modem_queue_item = {
|
|
|
|
'mode': self.get_mode_by_speed_level(self.speed_level),
|
|
|
|
'repeat': 1,
|
|
|
|
'repeat_delay': 1,
|
|
|
|
'frame': frame,
|
|
|
|
}
|
|
|
|
self.tx_frame_queue.put(modem_queue_item)
|
|
|
|
|
2023-12-13 13:33:09 +00:00
|
|
|
def set_state(self, state):
|
|
|
|
self.log(f"{type(self).__name__} state change from {self.state} to {state}")
|
2023-12-05 18:12:21 +00:00
|
|
|
self.state = state
|
2023-12-06 10:59:35 +00:00
|
|
|
|
|
|
|
def get_payload_size(self, speed_level):
|
|
|
|
mode = self.MODE_BY_SPEED[speed_level]
|
2023-12-13 10:51:54 +00:00
|
|
|
return codec2.get_bytes_per_frame(mode.value)
|
2023-12-12 21:33:17 +00:00
|
|
|
|
|
|
|
def set_details(self, snr, frequency_offset):
|
|
|
|
self.snr = snr
|
|
|
|
self.frequency_offset = frequency_offset
|