mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
show popup when modem restarting
This commit is contained in:
parent
aef44b1536
commit
b76726c4a5
3 changed files with 82 additions and 26 deletions
|
@ -121,17 +121,43 @@ export function stateDispatcher(data) {
|
||||||
export function eventDispatcher(data) {
|
export function eventDispatcher(data) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
||||||
// get ptt state as a first test
|
|
||||||
stateStore.ptt_state = data.ptt;
|
|
||||||
|
|
||||||
var message = "";
|
|
||||||
if (data["freedata"] == "modem-message") {
|
|
||||||
// break early if we received a dummy callsign
|
// break early if we received a dummy callsign
|
||||||
// thats a kind of hotfix, as long as the modem isnt handling this better
|
// thats a kind of hotfix, as long as the modem isnt handling this better
|
||||||
if (data["dxcallsign"] == "AA0AA-0" || data["dxcallsign"] == "ZZ9YY-0") {
|
if (data["dxcallsign"] == "AA0AA-0" || data["dxcallsign"] == "ZZ9YY-0") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get ptt state as a first test
|
||||||
|
stateStore.ptt_state = data.ptt;
|
||||||
|
|
||||||
|
// catch modem related events
|
||||||
|
if (data["freedata"] == "modem-event") {
|
||||||
|
|
||||||
|
switch (data["event"]) {
|
||||||
|
case "start":
|
||||||
|
displayToast("success", "bi-arrow-left-right", "Modem started", 5000);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "stop":
|
||||||
|
displayToast("success", "bi-arrow-left-right", "Modem stopped", 5000);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "restart":
|
||||||
|
displayToast("secondary", "bi-bootstrap-reboot", "Modem restarted", 5000);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "failed":
|
||||||
|
displayToast("danger", "bi-bootstrap-reboot", "Modem startup failed | bad config?", 5000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
var message = "";
|
||||||
|
if (data["freedata"] == "modem-message") {
|
||||||
|
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
switch (data["fec"]) {
|
switch (data["fec"]) {
|
||||||
|
@ -341,4 +367,5 @@ export function eventDispatcher(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,9 +70,8 @@ def index():
|
||||||
@app.route('/config', methods=['GET', 'POST'])
|
@app.route('/config', methods=['GET', 'POST'])
|
||||||
def config():
|
def config():
|
||||||
if request.method in ['POST']:
|
if request.method in ['POST']:
|
||||||
app.modem_service.put("stop")
|
|
||||||
set_config = app.config_manager.write(request.json)
|
set_config = app.config_manager.write(request.json)
|
||||||
app.modem_service.put("start")
|
app.modem_service.put("restart")
|
||||||
if not set_config:
|
if not set_config:
|
||||||
response = api_response(None, 'error writing config')
|
response = api_response(None, 'error writing config')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,6 +3,8 @@ import data_handler
|
||||||
import modem
|
import modem
|
||||||
import structlog
|
import structlog
|
||||||
import audio
|
import audio
|
||||||
|
import ujson as json
|
||||||
|
|
||||||
|
|
||||||
class SM:
|
class SM:
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
|
@ -26,21 +28,44 @@ class SM:
|
||||||
while True:
|
while True:
|
||||||
cmd = self.modem_service.get()
|
cmd = self.modem_service.get()
|
||||||
if cmd in ['start'] and not self.modem:
|
if cmd in ['start'] and not self.modem:
|
||||||
audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'], self.config['AUDIO']['output_device'])
|
self.log.info("------------------ FreeDATA ------------------")
|
||||||
print(audio_test)
|
self.log.info("------------------ MODEM ------------------")
|
||||||
|
self.start_modem()
|
||||||
|
elif cmd in ['stop'] and self.modem:
|
||||||
|
self.stop_modem()
|
||||||
|
# we need to wait a bit for avoiding a portaudio crash
|
||||||
|
threading.Event().wait(0.5)
|
||||||
|
|
||||||
|
elif cmd in ['restart']:
|
||||||
|
self.stop_modem()
|
||||||
|
# we need to wait a bit for avoiding a portaudio crash
|
||||||
|
threading.Event().wait(0.5)
|
||||||
|
if self.start_modem():
|
||||||
|
self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "restart"}))
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.log.warning("[SVC] modem command processing failed", cmd=cmd, state=self.states.is_modem_running)
|
||||||
|
|
||||||
|
|
||||||
|
def start_modem(self):
|
||||||
|
audio_test = self.test_audio()
|
||||||
if False not in audio_test and None not in audio_test and not self.states.is_modem_running:
|
if False not in audio_test and None not in audio_test and not self.states.is_modem_running:
|
||||||
self.log.info("starting modem....")
|
self.log.info("starting modem....")
|
||||||
self.modem = modem.RF(self.config, self.modem_events, self.modem_fft, self.modem_service, self.states)
|
self.modem = modem.RF(self.config, self.modem_events, self.modem_fft, self.modem_service, self.states)
|
||||||
self.data_handler = data_handler.DATA(self.config, self.modem_events)
|
self.data_handler = data_handler.DATA(self.config, self.modem_events)
|
||||||
self.states.set("is_modem_running", True)
|
self.states.set("is_modem_running", True)
|
||||||
|
return True
|
||||||
|
elif self.states.is_modem_running:
|
||||||
|
self.log.warning("modem already running")
|
||||||
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.log.warning("starting modem failed", input_test=audio_test[0], output_test=audio_test[1])
|
self.log.warning("starting modem failed", input_test=audio_test[0], output_test=audio_test[1])
|
||||||
self.states.set("is_modem_running", False)
|
self.states.set("is_modem_running", False)
|
||||||
|
self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "failed"}))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def stop_modem(self):
|
||||||
else:
|
|
||||||
print("--------------------------------------")
|
|
||||||
self.log.info("stopping modem....")
|
self.log.info("stopping modem....")
|
||||||
del self.modem
|
del self.modem
|
||||||
del self.data_handler
|
del self.data_handler
|
||||||
|
@ -48,4 +73,9 @@ class SM:
|
||||||
self.data_handler = False
|
self.data_handler = False
|
||||||
self.states.set("is_modem_running", False)
|
self.states.set("is_modem_running", False)
|
||||||
|
|
||||||
threading.Event().wait(0.5)
|
def test_audio(self):
|
||||||
|
audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'],
|
||||||
|
self.config['AUDIO']['output_device'])
|
||||||
|
self.log.info("tested audio devices", result=audio_test)
|
||||||
|
|
||||||
|
return audio_test
|
Loading…
Reference in a new issue