diff --git a/modem/broadcast.py b/modem/broadcast.py index 71dd2882..688e7372 100644 --- a/modem/broadcast.py +++ b/modem/broadcast.py @@ -8,13 +8,12 @@ from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibPar import sock import ujson as json - class broadcastHandler: """Terminal Node Controller for FreeDATA""" log = structlog.get_logger("BROADCAST") - def __init__(self) -> None: + def __init__(self, event_queue) -> None: self.fec_wakeup_callsign = bytes() self.longest_duration = 6 self.wakeup_received = False @@ -24,6 +23,7 @@ class broadcastHandler: target=self.watchdog, name="watchdog thread", daemon=True ) self.broadcast_watchdog.start() + self.event_queue = event_queue def received_fec_wakeup(self, data_in: bytes): self.fec_wakeup_callsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) @@ -95,6 +95,7 @@ class broadcastHandler: self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out) # finally push data to our network queue sock.SOCKET_QUEUE.put(json_data_out) + self.event_queue.put(json_data_out) def watchdog(self): while 1: diff --git a/modem/data_handler.py b/modem/data_handler.py index 8eb96168..6c66b566 100644 --- a/modem/data_handler.py +++ b/modem/data_handler.py @@ -41,10 +41,12 @@ class DATA: log = structlog.get_logger("DATA") - def __init__(self, config) -> None: + def __init__(self, config, event_queue) -> None: self.stats = stats.stats() + self.event_queue = event_queue + self.mycallsign = config['STATION']['mycall'] self.dxcallsign = Station.dxcallsign @@ -109,7 +111,7 @@ class DATA: self.rx_n_frames_per_burst = 0 self.max_n_frames_per_burst = 1 - self.broadcast = broadcast.broadcastHandler() + self.broadcast = broadcast.broadcastHandler(self.event_queue) # Flag to indicate if we received a low bandwidth mode channel opener self.received_LOW_BANDWIDTH_MODE = False @@ -529,6 +531,7 @@ class DATA: self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out) # finally push data to our network queue sock.SOCKET_QUEUE.put(json_data_out) + self.event_queue.put(json_data_out) def send_ident_frame(self, transmit) -> None: """Build and send IDENT frame """ diff --git a/modem/modem.py b/modem/modem.py index 63513ca0..d5661229 100644 --- a/modem/modem.py +++ b/modem/modem.py @@ -31,7 +31,6 @@ from queues import DATA_QUEUE_RECEIVED, MODEM_RECEIVED_QUEUE, MODEM_TRANSMIT_QUE AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE import audio import event_manager -import queue TESTMODE = False RXCHANNEL = "" @@ -64,7 +63,7 @@ class RF: log = structlog.get_logger("RF") - def __init__(self, config) -> None: + def __init__(self, config, event_queue) -> None: self.config = config self.sampler_avg = 0 @@ -113,9 +112,8 @@ class RF: # Define fft_data buffer self.fft_data = bytes() - self.modem_events = queue.Queue() self.event_manager = event_manager.EventManager([ - self.modem_events, + event_queue, sock.SOCKET_QUEUE]) self.init_codec2() diff --git a/modem/server.py b/modem/server.py index 45ca84fd..2a897357 100644 --- a/modem/server.py +++ b/modem/server.py @@ -7,6 +7,7 @@ from config import CONFIG import audio import data_handler import modem +import queue app = Flask(__name__) CORS(app) @@ -39,8 +40,9 @@ def api_response(data, status = 'ok'): set_config() # start modem -data_handler.DATA(app.config_manager.config) -app.modem = modem.RF(app.config_manager.config) +app.modem_events = queue.Queue() +app.modem = modem.RF(app.config_manager.config, app.modem_events) +data_handler.DATA(app.config_manager.config, app.modem_events) ## REST API @app.route('/', methods=['GET']) @@ -79,5 +81,5 @@ def get_serial_devices(): # Event websocket @sock.route('/events') def echo(sock): - ev = app.modem.modem_events.get() + ev = app.modem_events.get() sock.send(ev) diff --git a/modem/sock.py b/modem/sock.py index 17a56418..42e4b10d 100644 --- a/modem/sock.py +++ b/modem/sock.py @@ -114,6 +114,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # self.request.sendall(sock_data) threading.Event().wait(0.15) + # This will disapear because commands will come from the REST API def receive_from_client(self): """ function which is called by the socket handler