mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Add support for /modem/state rest
This commit is contained in:
parent
5cc05d26e7
commit
f2befd29f2
5 changed files with 25 additions and 7 deletions
|
@ -20,7 +20,7 @@ import { useStateStore } from "../store/stateStore.js";
|
|||
const state = useStateStore(pinia);
|
||||
|
||||
import { startModem, stopModem } from "../js/api";
|
||||
import { getModemConfig } from "../js/api";
|
||||
import { getModemConfig, getModemCurrentState } from "../js/api";
|
||||
|
||||
import { saveSettingsToFile } from "../js/settingsHandler";
|
||||
import { startRigctld, stopRigctld } from "../js/deprecated_daemon";
|
||||
|
@ -31,6 +31,7 @@ var updateAvailable = process.env.FDUpdateAvail;
|
|||
// start modemCheck modal once on startup
|
||||
onMounted(() => {
|
||||
getModemConfig();
|
||||
getModemCurrentState();
|
||||
getModemVersion();
|
||||
new Modal("#modemCheck", {}).show();
|
||||
});
|
||||
|
|
|
@ -33,3 +33,6 @@ export function stopModem() {
|
|||
export function getModemVersion() {
|
||||
getFromServer(settings.modem_host, settings.modem_port, "version", null);
|
||||
}
|
||||
export function getModemCurrentState() {
|
||||
getFromServer(settings.modem_host, settings.modem_port, "modem/state", null);
|
||||
}
|
|
@ -28,7 +28,7 @@ export function stateDispatcher(data) {
|
|||
|
||||
stateStore.modem_connection = "connected";
|
||||
|
||||
if (data["freedata-message"] == "state-change") {
|
||||
if (data["freedata-message"] == "state-change" || data["freedata-message"] == "state" ) {
|
||||
stateStore.channel_busy = data["channel_busy"];
|
||||
stateStore.is_codec2_traffic = data["is_codec2_traffic"];
|
||||
stateStore.is_modem_running = data["is_modem_running"];
|
||||
|
|
|
@ -92,6 +92,10 @@ def get_serial_devices():
|
|||
devices = serial_ports.get_ports()
|
||||
return api_response(devices)
|
||||
|
||||
@app.route('/modem/state', methods=['GET'])
|
||||
def get_modem_state():
|
||||
return api_response(app.states.sendState())
|
||||
|
||||
@app.route('/modem/cqcqcq', methods=['POST', 'GET'])
|
||||
def post_cqcqcq():
|
||||
if request.method not in ['POST']:
|
||||
|
@ -224,7 +228,7 @@ def sock_fft(sock):
|
|||
@sock.route('/states')
|
||||
def sock_states(sock):
|
||||
sock_watchdog(sock, states_client_list, app.state_queue)
|
||||
app.states.sendStateUpdate()
|
||||
|
||||
|
||||
# websocket multi client support for using with queued information.
|
||||
# our client set which contains all connected websocket clients
|
||||
|
|
|
@ -30,6 +30,11 @@ class STATES:
|
|||
self.radio_bandwidth = 0
|
||||
self.radio_rf_power = 0
|
||||
|
||||
def sendState (self):
|
||||
currentState = self.getAsJSON(False)
|
||||
self.statequeue.put(currentState)
|
||||
return currentState
|
||||
|
||||
def sendStateUpdate (self):
|
||||
self.statequeue.put(self.newstate)
|
||||
|
||||
|
@ -39,15 +44,20 @@ class STATES:
|
|||
# only process data if changed
|
||||
# but also send an update if more than a 'updateCadence' second(s) has lapsed
|
||||
# Otherwise GUI can't tell if modem is active due to lack of state messages on startup
|
||||
new_state = self.getAsJSON()
|
||||
new_state = self.getAsJSON(True)
|
||||
if new_state != self.newstate:
|
||||
self.newstate = new_state
|
||||
self.sendStateUpdate()
|
||||
|
||||
|
||||
def getAsJSON(self):
|
||||
def getAsJSON(self, isChangedState):
|
||||
|
||||
msgtype = "state-change"
|
||||
if (not isChangedState):
|
||||
msgtype = "state"
|
||||
|
||||
return json.dumps({
|
||||
"freedata-message": "state-change",
|
||||
"freedata-message": msgtype,
|
||||
"channel_busy": self.channel_busy,
|
||||
"is_codec2_traffic": self.is_codec2_traffic,
|
||||
"is_modem_running": self.is_modem_running,
|
||||
|
|
Loading…
Reference in a new issue