This commit is contained in:
Pedro 2023-11-25 18:21:41 +01:00
parent 2d6af962b5
commit e8a2a5d12a
2 changed files with 29 additions and 17 deletions

View file

@ -1,27 +1,39 @@
from data_frame_factory import DataFrameFactory from data_frame_factory import DataFrameFactory
from modem.modem import RF from modem.modem import RF
import queue
from codec2 import FREEDV_MODE
class TxCommand(): class TxCommand():
def __init__(self, apiParams): def __init__(self, config, logger, apiParams):
self.setParamsFromApi(apiParams) self.config = config
self.frame_factory = DataFrameFactory(modem) self.logger = logger
self.set_params_from_api(apiParams)
self.frame_factory = DataFrameFactory()
def setParamsFromApi(self, apiParams): def set_params_from_api(self, apiParams):
pass pass
def getName(self): def get_name(self):
return type(self).__name__ return type(self).__name__
def getPayload(self): def emit_event(self):
pass pass
def execute(self, modem_state, tx_frame_queue): def log_message(self):
return f"TX Command {self.get_name()}"
def build_frame(self):
pass pass
def transmit(self, frame): def transmit(self, tx_frame_queue):
# MODEM_TRANSMIT_QUEUE.put([c2_mode, copies, repeat_delay, frame_to_tx]) frame = self.build_frame()
c2_mode = FREEDV_MODE.fsk_ldpc_0.value if self.config.enable_fsk else FREEDV_MODE.sig0.value
tx_queue_item = [c2_mode, 1, 0, frame]
tx_frame_queue.put(tx_queue_item)
self.modem.modem_transmit_queue.put( def run(self, tx_frame_queue: queue.Queue):
self.emit_event()
) self.logger.info(self.log_message)
self.transmit(tx_frame_queue)
pass

View file

@ -12,8 +12,8 @@ import state_manager
import ujson as json import ujson as json
import websocket_manager as wsm import websocket_manager as wsm
import api_validations as validations import api_validations as validations
from tx_command.tx_command import TxCommand from command import TxCommand
from tx_command.ping_command import PingCommand from command_ping import PingCommand
from queues import DATA_QUEUE_TRANSMIT as tx_cmd_queue from queues import DATA_QUEUE_TRANSMIT as tx_cmd_queue
app = Flask(__name__) app = Flask(__name__)
@ -77,9 +77,9 @@ def validate(req, param, validator, isRequired = True):
# Takes a transmit command and puts it in the transmit command queue # Takes a transmit command and puts it in the transmit command queue
def enqueue_tx_command(cmd_class, params = {}): def enqueue_tx_command(cmd_class, params = {}):
command = cmd_class(service_manager.modem, params) command = cmd_class(app.config, app.logger, params)
tx_cmd_queue.put(command) tx_cmd_queue.put(command)
app.logger.info(f"Command {type(command).__name__} enqueued.") app.logger.info(f"Command {command.get_name()} enqueued.")
## REST API ## REST API
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])