mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
make beacon a service
This commit is contained in:
parent
bfc0c88154
commit
e91cf49f21
|
@ -6,13 +6,13 @@ class Beacon:
|
|||
|
||||
BEACON_LOOP_INTERVAL = 1
|
||||
|
||||
def __init__(self, config, states, event_queue, logger, modem_tx_queue):
|
||||
def __init__(self, config, states, event_queue, logger, modem):
|
||||
|
||||
self.modem_config = config
|
||||
self.states = states
|
||||
self.event_queue = event_queue
|
||||
self.log = logger
|
||||
self.tx_frame_queue = modem_tx_queue
|
||||
self.modem = modem
|
||||
|
||||
self.loop_running = True
|
||||
self.paused = False
|
||||
|
@ -39,8 +39,8 @@ class Beacon:
|
|||
True):
|
||||
#not self.states.channel_busy):
|
||||
|
||||
cmd = command_beacon.BeaconCommand(self.modem_config, self.log)
|
||||
cmd.run(self.event_queue, self.tx_frame_queue)
|
||||
cmd = command_beacon.BeaconCommand(self.modem_config, self.states, self.event_queue)
|
||||
cmd.run(self.event_queue, self.modem)
|
||||
self.event.wait(self.modem_config['MODEM']['beacon_interval'])
|
||||
|
||||
self.event.wait(self.BEACON_LOOP_INTERVAL)
|
||||
|
|
|
@ -5,8 +5,9 @@ class BeaconCommand(TxCommand):
|
|||
def build_frame(self):
|
||||
return self.frame_factory.build_beacon()
|
||||
|
||||
def transmit(self, modem):
|
||||
super().transmit(modem)
|
||||
if self.config['MODEM']['enable_morse_identifier']:
|
||||
mycall = f"{self.config['STATION']['mycall']}-{self.config['STATION']['myssid']}"
|
||||
modem.transmit_morse("morse", 1, 0, mycall)
|
||||
|
||||
#def transmit(self, modem):
|
||||
# super().transmit(modem)
|
||||
# if self.config['MODEM']['enable_morse_identifier']:
|
||||
# mycall = f"{self.config['STATION']['mycall']}-{self.config['STATION']['myssid']}"
|
||||
# modem.transmit_morse("morse", 1, 0, mycall)
|
||||
|
|
|
@ -23,7 +23,6 @@ import cw
|
|||
from queues import RIGCTLD_COMMAND_QUEUE
|
||||
import audio
|
||||
import event_manager
|
||||
import beacon
|
||||
import demodulator
|
||||
|
||||
TESTMODE = False
|
||||
|
@ -101,8 +100,7 @@ class RF:
|
|||
self.fft_queue
|
||||
)
|
||||
|
||||
self.beacon = beacon.Beacon(self.config, self.states, event_queue,
|
||||
self.log, self.modem_transmit_queue)
|
||||
|
||||
|
||||
def tci_tx_callback(self, audio_48k) -> None:
|
||||
self.radio.set_ptt(True)
|
||||
|
@ -134,8 +132,6 @@ class RF:
|
|||
if not TESTMODE:
|
||||
atexit.register(self.sd_input_stream.stop)
|
||||
|
||||
# init beacon
|
||||
self.beacon.start()
|
||||
else:
|
||||
return False
|
||||
|
||||
|
|
|
@ -143,7 +143,14 @@ def post_beacon():
|
|||
api_abort(f"Incorrect value for 'enabled'. Shoud be bool.")
|
||||
if not app.state_manager.is_modem_running:
|
||||
api_abort('Modem not running', 503)
|
||||
app.state_manager.set('is_beacon_running', request.json['enabled'])
|
||||
|
||||
if not app.state_manager.is_beacon_running:
|
||||
app.state_manager.set('is_beacon_running', request.json['enabled'])
|
||||
app.modem_service.put("start_beacon")
|
||||
else:
|
||||
app.state_manager.set('is_beacon_running', request.json['enabled'])
|
||||
app.modem_service.put("stop_beacon")
|
||||
|
||||
return api_response(request.json)
|
||||
|
||||
@app.route('/modem/ping_ping', methods=['POST'])
|
||||
|
|
|
@ -5,6 +5,7 @@ import structlog
|
|||
import audio
|
||||
import ujson as json
|
||||
import explorer
|
||||
import beacon
|
||||
|
||||
|
||||
class SM:
|
||||
|
@ -12,6 +13,7 @@ class SM:
|
|||
self.log = structlog.get_logger("service")
|
||||
|
||||
self.modem = False
|
||||
self.beacon = False
|
||||
self.data_handler = False
|
||||
self.app = app
|
||||
self.config = self.app.config_manager.read()
|
||||
|
@ -48,6 +50,14 @@ class SM:
|
|||
threading.Event().wait(0.5)
|
||||
if self.start_modem():
|
||||
self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "restart"}))
|
||||
elif cmd in ['start_beacon']:
|
||||
self.start_beacon()
|
||||
|
||||
elif cmd in ['stop_beacon']:
|
||||
self.stop_beacon()
|
||||
|
||||
|
||||
|
||||
else:
|
||||
self.log.warning("[SVC] modem command processing failed", cmd=cmd, state=self.states.is_modem_running)
|
||||
|
||||
|
@ -97,4 +107,11 @@ class SM:
|
|||
self.log.info("tested audio devices", result=audio_test)
|
||||
|
||||
return audio_test
|
||||
|
||||
|
||||
|
||||
def start_beacon(self):
|
||||
self.beacon = beacon.Beacon(self.config, self.states, self.modem_events, self.log, self.modem)
|
||||
self.beacon.start()
|
||||
|
||||
def stop_beacon(self):
|
||||
del self.beacon
|
||||
|
|
Loading…
Reference in a new issue