Fix several errors to get server to start again.

This commit is contained in:
Pedro 2023-11-26 12:45:51 +01:00
parent 9872b52741
commit e0bd7c5e09
9 changed files with 42 additions and 44 deletions

View file

@ -9,7 +9,7 @@ class TxCommand():
self.config = config
self.logger = logger
self.set_params_from_api(apiParams)
self.frame_factory = DataFrameFactory()
self.frame_factory = DataFrameFactory(config)
def set_params_from_api(self, apiParams):
pass
@ -27,12 +27,12 @@ class TxCommand():
pass
def get_tx_mode(self):
c2_mode = FREEDV_MODE.fsk_ldpc_0.value if self.config.enable_fsk else FREEDV_MODE.sig0.value
c2_mode = FREEDV_MODE.fsk_ldpc_0.value if self.config['MODEM']['enable_fsk'] else FREEDV_MODE.sig0.value
return c2_mode
def make_modem_queue_item(self, mode, repeat, repeat_delay, frame):
item = {
'mode': self.get_c2_mode(),
'mode': self.get_tx_mode(),
'repeat': 1,
'repeat_delay': 0,
'frame': frame

View file

@ -21,8 +21,11 @@ decoded_frame: {'frame_type': 'CQ', 'mycallsign': b'DJ2LS-9', 'gridsquare': 'JN4
class DataFrameFactory:
def __init__(self):
self.myfullcall = f"{self.modem_config['STATION']['mycall']}-{self.modem_config['STATION']['myssid']}"
LENGTH_SIG0_FRAME = 14
def __init__(self, config):
self.myfullcall = f"{config['STATION']['mycall']}-{config['STATION']['myssid']}"
self.mygrid = config['STATION']['mygrid']
# table for holding our frame templates
self.template_list = {}
@ -34,14 +37,14 @@ class DataFrameFactory:
def _load_broadcast_templates(self):
# cq frame
self.template_list[FR_TYPE.CQ.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"mycallsign": 6,
"gridsquare": 4
}
# qrv frame
self.template_list[FR_TYPE.QRV.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"mycallsign": 6,
"gridsquare": 4,
"snr": 1
@ -49,7 +52,7 @@ class DataFrameFactory:
# beacon frame
self.template_list[FR_TYPE.BEACON.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"mycallsign": 6,
"gridsquare": 4
}
@ -57,7 +60,7 @@ class DataFrameFactory:
def _load_ping_templates(self):
# ping frame
self.template_list[FR_TYPE.PING.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"dxcallsign_crc": 3,
"mycallsign_crc": 3,
"mycallsign": 6
@ -66,7 +69,7 @@ class DataFrameFactory:
def _load_fec_templates(self):
# fec wakeup frame
self.template_list[FR_TYPE.FEC_WAKEUP.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"mycallsign": 6,
"mode": 1,
"n_bursts": 1,
@ -74,13 +77,13 @@ class DataFrameFactory:
# fec frame
self.template_list[FR_TYPE.FEC.value] = {
"frame_length": self.length_sig0_frame,
"data": self.length_sig0_frame - 1
"frame_length": self.LENGTH_SIG0_FRAME,
"data": self.LENGTH_SIG0_FRAME - 1
}
# fec is writing frame
self.template_list[FR_TYPE.IS_WRITING.value] = {
"frame_length": self.length_sig0_frame,
"frame_length": self.LENGTH_SIG0_FRAME,
"mycallsign": 6
}

View file

@ -10,20 +10,13 @@ class EventManager:
q.put(data)
def send_ptt_change(self, on:bool = False):
jsondata = {"ptt": str(on)}
data_out = json.dumps(jsondata)
self.broadcast(data_out)
self.broadcast({"ptt": str(on)})
def send_scatter_change(self, data):
jsondata = {"scatter": str(data)}
data_out = json.dumps(jsondata)
self.broadcast(data_out)
self.broadcast({"scatter": str(data)})
def send_buffer_overflow(self, data):
jsondata = {"buffer-overflow": str(data)}
data_out = json.dumps(jsondata)
self.broadcast(data_out)
self.broadcast({"buffer-overflow": str(data)})
def send_custom_event(self, **jsondata):
data_out = json.dumps(jsondata)
self.broadcast(data_out)
def send_custom_event(self, **event_data):
self.broadcast(event_data)

View file

@ -25,7 +25,7 @@ from protocol_arq_session import SESSION
class DISPATCHER():
def __init__(self, config, event_queue, states):
print("loading frame dispatcher.....")
print("loading frame dispatcher.....\n")
self.config = config
self.event_queue = event_queue
self.states = states
@ -37,8 +37,7 @@ class DISPATCHER():
def _initialize_handlers(self, config, event_queue, states):
"""Initializes various data handlers."""
self.frame_factory = DataFrameFactory()
self.frame_factory = DataFrameFactory(config)
self.broadcasts = BROADCAST(config, event_queue, states)
self.data_broadcasts = DATABROADCAST(config, event_queue, states)
@ -119,7 +118,7 @@ class DISPATCHER():
"""Dispatch incoming UI instructions for transmitting operations"""
while True:
command = self.data_queue_transmit.get()
command.execute(self.event_queue, MODEM_TRANSMIT_QUEUE)
command.run(self.event_queue, MODEM_TRANSMIT_QUEUE)
def worker_receive(self) -> None:
"""Queue received data for processing"""

View file

@ -1147,10 +1147,11 @@ class RF:
self.log.debug("[MDM] self.modem_transmit_queue", qsize=queuesize)
tx = self.modem_transmit_queue.get()
# TODO Why we is this taking an array instead of a single frame?
if tx['mode'] in ["morse"]:
self.transmit_morse(tx['repeat'], tx['repeat_delay'], tx['frame'])
self.transmit_morse(tx['repeat'], tx['repeat_delay'], [tx['frame']])
else:
self.transmit(tx['mode'], tx['repeat'], tx['repeat_delay'], tx['frame'])
self.transmit(tx['mode'], tx['repeat'], tx['repeat_delay'], [tx['frame']])
# self.modem_transmit_queue.task_done()
def worker_received(self) -> None:

View file

@ -14,7 +14,6 @@ from data_handler import DATA
TESTMODE = False
class ARQ:
def __init__(self, config, event_queue, states):
super().__init__(config, event_queue, states)
self.log = structlog.get_logger("DHARQ")
self.event_queue = event_queue

View file

@ -67,6 +67,9 @@ def api_abort(message, code):
jsonError = json.dumps({'error': message})
abort(Response(jsonError, code))
def api_ok(message = "ok"):
return api_response({'message': message})
# validates a parameter
def validate(req, param, validator, isRequired = True):
if param not in req:
@ -79,7 +82,7 @@ def validate(req, param, validator, isRequired = True):
# Takes a transmit command and puts it in the transmit command queue
def enqueue_tx_command(cmd_class, params = {}):
command = cmd_class(app.config, app.logger, params)
command = cmd_class(app.config_manager.read(), app.logger, params)
tx_cmd_queue.put(command)
app.logger.info(f"Command {command.get_name()} enqueued.")
@ -130,7 +133,7 @@ def post_cqcqcq():
if not app.state_manager.is_modem_running:
api_abort('Modem not running', 503)
enqueue_tx_command(command_cq.CQCommand)
return "ok"
return api_ok()
@app.route('/modem/beacon', methods=['POST'])
def post_beacon():
@ -151,7 +154,7 @@ def post_ping():
api_abort('Modem not running', 503)
validate(request.json, 'dxcall', validations.validate_freedata_callsign)
enqueue_tx_command(command_ping.PingCommand, request.json)
return 'ok'
return api_ok()
@app.route('/modem/send_test_frame', methods=['POST'])
def post_send_test_frame():
@ -160,7 +163,7 @@ def post_send_test_frame():
if not app.state_manager.is_modem_running:
api_abort('Modem not running', 503)
enqueue_tx_command(command_test.TestCommand)
return "ok"
return api_ok()
@app.route('/modem/fec_transmit', methods=['POST'])
def post_send_fec_frame():
@ -169,7 +172,7 @@ def post_send_fec_frame():
if not app.state_manager.is_modem_running:
api_abort('Modem not running', 503)
enqueue_tx_command(command_feq.FecCommand, request.json)
return "ok"
return api_ok()
@app.route('/modem/fec_is_writing', methods=['POST'])
def post_send_fec_is_writing():
@ -195,7 +198,7 @@ def post_modem_stop():
print("stop received...")
app.modem_service.put("stop")
return api_response(request.json)
return api_ok()
@app.route('/version', methods=['GET'])
def get_modem_version():

View file

@ -55,7 +55,7 @@ class StateManager:
def sendState (self):
currentState = self.getAsJSON(False)
currentState = self.get_state_event(False)
self.statequeue.put(currentState)
return currentState
@ -66,17 +66,17 @@ class StateManager:
setattr(self, key, value)
#print(f"State ==> Setting {key} to value {value}")
# only process data if changed
new_state = self.getAsJSON(True)
new_state = self.get_state_event(True)
if new_state != self.newstate:
self.newstate = new_state
self.sendStateUpdate()
def getAsJSON(self, isChangedState):
def get_state_event(self, isChangedState):
msgtype = "state-change"
if (not isChangedState):
msgtype = "state"
return json.dumps({
return {
"freedata-message": msgtype,
"channel_busy": self.channel_busy,
"is_codec2_traffic": self.is_codec2_traffic,
@ -84,7 +84,7 @@ class StateManager:
"is_beacon_running": self.is_beacon_running,
"radio_status": self.radio_status,
"radio_frequency": self.radio_frequency,
})
}
# .wait() blocks until the event is set
def isTransmitting(self):

View file

@ -8,7 +8,7 @@ fft_client_list = set()
states_client_list = set()
def handle_connection(sock, client_list, event_queue):
event_queue.put(json.dumps({"freedata-message": "hello-client"}))
event_queue.put({"freedata-message": "hello-client"})
client_list.add(sock)
while True: