2023-11-23 15:59:53 +00:00
|
|
|
from data_frame_factory import DataFrameFactory
|
2023-11-25 17:21:41 +00:00
|
|
|
import queue
|
|
|
|
from codec2 import FREEDV_MODE
|
2023-11-23 15:59:53 +00:00
|
|
|
|
|
|
|
class TxCommand():
|
|
|
|
|
2023-11-26 14:23:20 +00:00
|
|
|
def __init__(self, config, logger, apiParams = {}):
|
2023-11-25 17:21:41 +00:00
|
|
|
self.config = config
|
|
|
|
self.logger = logger
|
|
|
|
self.set_params_from_api(apiParams)
|
2023-11-26 11:45:51 +00:00
|
|
|
self.frame_factory = DataFrameFactory(config)
|
2023-11-23 15:59:53 +00:00
|
|
|
|
2023-11-25 17:21:41 +00:00
|
|
|
def set_params_from_api(self, apiParams):
|
2023-11-23 15:59:53 +00:00
|
|
|
pass
|
|
|
|
|
2023-11-25 17:21:41 +00:00
|
|
|
def get_name(self):
|
2023-11-24 09:46:51 +00:00
|
|
|
return type(self).__name__
|
|
|
|
|
2023-11-25 22:14:49 +00:00
|
|
|
def emit_event(self, event_queue):
|
2023-11-23 15:59:53 +00:00
|
|
|
pass
|
|
|
|
|
2023-11-25 17:21:41 +00:00
|
|
|
def log_message(self):
|
2023-11-26 12:11:45 +00:00
|
|
|
message = f"Running {self.get_name()}"
|
|
|
|
return message
|
2023-11-25 17:21:41 +00:00
|
|
|
|
|
|
|
def build_frame(self):
|
|
|
|
pass
|
2023-11-23 15:59:53 +00:00
|
|
|
|
2023-11-25 23:11:39 +00:00
|
|
|
def get_tx_mode(self):
|
2023-11-26 11:45:51 +00:00
|
|
|
c2_mode = FREEDV_MODE.fsk_ldpc_0.value if self.config['MODEM']['enable_fsk'] else FREEDV_MODE.sig0.value
|
2023-11-25 22:14:49 +00:00
|
|
|
return c2_mode
|
2023-11-25 23:11:39 +00:00
|
|
|
|
|
|
|
def make_modem_queue_item(self, mode, repeat, repeat_delay, frame):
|
|
|
|
item = {
|
2023-11-26 11:45:51 +00:00
|
|
|
'mode': self.get_tx_mode(),
|
2023-11-25 22:39:35 +00:00
|
|
|
'repeat': 1,
|
|
|
|
'repeat_delay': 0,
|
|
|
|
'frame': frame
|
|
|
|
}
|
2023-11-25 23:11:39 +00:00
|
|
|
return item
|
|
|
|
|
|
|
|
def transmit(self, tx_frame_queue):
|
|
|
|
frame = self.build_frame()
|
|
|
|
tx_queue_item = self.make_modem_queue_item(self.get_tx_mode(), 1, 0, frame)
|
2023-11-25 17:21:41 +00:00
|
|
|
tx_frame_queue.put(tx_queue_item)
|
2023-11-23 15:59:53 +00:00
|
|
|
|
2023-11-25 22:14:49 +00:00
|
|
|
def run(self, event_queue: queue.Queue, tx_frame_queue: queue.Queue):
|
|
|
|
self.emit_event(event_queue)
|
2023-11-26 12:11:45 +00:00
|
|
|
self.logger.info(self.log_message())
|
2023-11-25 17:21:41 +00:00
|
|
|
self.transmit(tx_frame_queue)
|
|
|
|
pass
|