mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Integrate the modem event queue in other modules
This commit is contained in:
parent
08f35903af
commit
bf866a73e6
5 changed files with 16 additions and 11 deletions
|
@ -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:
|
||||
|
|
|
@ -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 """
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue