Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
DJ2LS 2023-11-08 20:18:48 +01:00
commit 282dc84364
5 changed files with 44 additions and 11 deletions

View file

@ -8,13 +8,12 @@ from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibPar
import sock import sock
import ujson as json import ujson as json
class broadcastHandler: class broadcastHandler:
"""Terminal Node Controller for FreeDATA""" """Terminal Node Controller for FreeDATA"""
log = structlog.get_logger("BROADCAST") log = structlog.get_logger("BROADCAST")
def __init__(self) -> None: def __init__(self, event_queue) -> None:
self.fec_wakeup_callsign = bytes() self.fec_wakeup_callsign = bytes()
self.longest_duration = 6 self.longest_duration = 6
self.wakeup_received = False self.wakeup_received = False
@ -24,6 +23,7 @@ class broadcastHandler:
target=self.watchdog, name="watchdog thread", daemon=True target=self.watchdog, name="watchdog thread", daemon=True
) )
self.broadcast_watchdog.start() self.broadcast_watchdog.start()
self.event_queue = event_queue
def received_fec_wakeup(self, data_in: bytes): def received_fec_wakeup(self, data_in: bytes):
self.fec_wakeup_callsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) 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) self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out)
# finally push data to our network queue # finally push data to our network queue
sock.SOCKET_QUEUE.put(json_data_out) sock.SOCKET_QUEUE.put(json_data_out)
self.event_queue.put(json_data_out)
def watchdog(self): def watchdog(self):
while 1: while 1:

View file

@ -41,10 +41,12 @@ class DATA:
log = structlog.get_logger("DATA") log = structlog.get_logger("DATA")
def __init__(self, config) -> None: def __init__(self, config, event_queue) -> None:
self.stats = stats.stats() self.stats = stats.stats()
self.event_queue = event_queue
self.mycallsign = config['STATION']['mycall'] self.mycallsign = config['STATION']['mycall']
self.dxcallsign = Station.dxcallsign self.dxcallsign = Station.dxcallsign
@ -109,7 +111,7 @@ class DATA:
self.rx_n_frames_per_burst = 0 self.rx_n_frames_per_burst = 0
self.max_n_frames_per_burst = 1 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 # Flag to indicate if we received a low bandwidth mode channel opener
self.received_LOW_BANDWIDTH_MODE = False 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) self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out)
# finally push data to our network queue # finally push data to our network queue
sock.SOCKET_QUEUE.put(json_data_out) sock.SOCKET_QUEUE.put(json_data_out)
self.event_queue.put(json_data_out)
def send_ident_frame(self, transmit) -> None: def send_ident_frame(self, transmit) -> None:
"""Build and send IDENT frame """ """Build and send IDENT frame """

View file

@ -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 AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE
import audio import audio
import event_manager import event_manager
import queue
TESTMODE = False TESTMODE = False
RXCHANNEL = "" RXCHANNEL = ""
@ -64,7 +63,7 @@ class RF:
log = structlog.get_logger("RF") log = structlog.get_logger("RF")
def __init__(self, config) -> None: def __init__(self, config, event_queue) -> None:
self.config = config self.config = config
self.sampler_avg = 0 self.sampler_avg = 0
@ -113,9 +112,8 @@ class RF:
# Define fft_data buffer # Define fft_data buffer
self.fft_data = bytes() self.fft_data = bytes()
self.modem_events = queue.Queue()
self.event_manager = event_manager.EventManager([ self.event_manager = event_manager.EventManager([
self.modem_events, event_queue,
sock.SOCKET_QUEUE]) sock.SOCKET_QUEUE])
self.init_codec2() self.init_codec2()

View file

@ -7,6 +7,7 @@ from config import CONFIG
import audio import audio
import data_handler import data_handler
import modem import modem
import queue
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
@ -39,8 +40,9 @@ def api_response(data, status = 'ok'):
set_config() set_config()
# start modem # start modem
data_handler.DATA(app.config_manager.config) app.modem_events = queue.Queue()
app.modem = modem.RF(app.config_manager.config) app.modem = modem.RF(app.config_manager.config, app.modem_events)
data_handler.DATA(app.config_manager.config, app.modem_events)
## REST API ## REST API
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
@ -76,8 +78,36 @@ def get_serial_devices():
devices = serial_ports.get_ports() devices = serial_ports.get_ports()
return api_response(devices) return api_response(devices)
# @app.route('/modem/listen', methods=['POST'])
# @app.route('/modem/record_audio', methods=['POST'])
# @app.route('/modem/responde_to_call', methods=['POST'])
# @app.route('/modem/responde_to_cq', methods=['POST'])
# @app.route('/modem/audio_levels', methods=['POST']) # tx and rx
# @app.route('/modem/send_test_frame', methods=['POST'])
# @app.route('/modem/fec_transmit', methods=['POST'])
# @app.route('/modem/fec_is_writing', methods=['POST'])
# @app.route('/modem/cqcqcq', methods=['POST'])
# @app.route('/modem/beacon', methods=['POST']) # on/off
# @app.route('/modem/mesh_ping', methods=['POST'])
# @app.route('/modem/ping_ping', methods=['POST'])
# @app.route('/modem/arc_connect', methods=['POST'])
# @app.route('/modem/arc_disconnect', methods=['POST'])
# @app.route('/modem/send_raw', methods=['POST'])
# @app.route('/modem/stop_transmission', methods=['POST'])
# @app.route('/mesh/routing_table', methods=['GET'])
# @app.route('/modem/get_rx_buffer', methods=['GET'])
# @app.route('/modem/del_rx_buffer', methods=['POST'])
# @app.route('/modem/start', methods=['POST'])
# @app.route('/modem/stop', methods=['POST'])
# @app.route('/rig/status', methods=['GET'])
# @app.route('/rig/mode', methods=['POST'])
# @app.route('/rig/frequency', methods=['POST'])
# @app.route('/rig/test_hamlib', methods=['POST'])
# Event websocket # Event websocket
@sock.route('/events') @sock.route('/events')
def echo(sock): def echo(sock):
ev = app.modem.modem_events.get() ev = app.modem_events.get()
sock.send(ev) sock.send(ev)

View file

@ -114,6 +114,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
# self.request.sendall(sock_data) # self.request.sendall(sock_data)
threading.Event().wait(0.15) threading.Event().wait(0.15)
# This will disapear because commands will come from the REST API
def receive_from_client(self): def receive_from_client(self):
""" """
function which is called by the socket handler function which is called by the socket handler