add first attempt of state handler

This commit is contained in:
DJ2LS 2023-11-11 20:46:49 +01:00
parent 78b545dff0
commit 87f2cbff2a
3 changed files with 17 additions and 36 deletions

View file

@ -19,14 +19,7 @@ const stateStore = useStateStore(pinia);
import { useSettingsStore } from "../store/settingsStore.js"; import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia); const settings = useSettingsStore(pinia);
export function eventDispatcher(data) { export function stateDispatcher(data) {
data = JSON.parse(data);
// get ptt state as a first test
// Todo we might use a switch function for data dispatching
stateStore.ptt_state = data.ptt;
// copied directly from sock.js We need to implement these variables step by step
if (data["command"] == "modem_state") { if (data["command"] == "modem_state") {
//console.log(data) //console.log(data)
@ -116,34 +109,14 @@ export function eventDispatcher(data) {
if (data["speed_list"].length > 0) { if (data["speed_list"].length > 0) {
prepareStatsDataForStore(data["speed_list"]); prepareStatsDataForStore(data["speed_list"]);
} }
// TODO: Remove ported objects
/*
let Data = {
mycallsign: data["mycallsign"],
mygrid: data["mygrid"],
//channel_state: data['CHANNEL_STATE'],
info: data["info"],
rx_msg_buffer_length: data["rx_msg_buffer_length"],
tx_n_max_retries: data["tx_n_max_retries"],
arq_tx_n_frames_per_burst: data["arq_tx_n_frames_per_burst"],
arq_tx_n_bursts: data["arq_tx_n_bursts"],
arq_tx_n_current_arq_frame: data["arq_tx_n_current_arq_frame"],
arq_tx_n_total_arq_frames: data["arq_tx_n_total_arq_frames"],
arq_rx_frame_n_bursts: data["arq_rx_frame_n_bursts"],
arq_rx_n_current_arq_frame: data["arq_rx_n_current_arq_frame"],
arq_n_arq_frames_per_data_frame:
data["arq_n_arq_frames_per_data_frame"],
arq_bytes_per_minute: data["arq_bytes_per_minute"],
arq_compression_factor: data["arq_compression_factor"],
routing_table: data["routing_table"],
mesh_signalling_table: data["mesh_signalling_table"],
listen: data["listen"],
//speed_table: [{"bpm" : 5200, "snr": -3, "timestamp":1673555399},{"bpm" : 2315, "snr": 12, "timestamp":1673555500}],
};
*/
} }
}
export function eventDispatcher(data) {
data = JSON.parse(data);
// get ptt state as a first test
stateStore.ptt_state = data.ptt;
var message = ""; var message = "";
if (data["freedata"] == "modem-message") { if (data["freedata"] == "modem-message") {

View file

@ -1,4 +1,4 @@
import { eventDispatcher } from "../js/eventHandler.js"; import { eventDispatcher, stateDispatcher } from "../js/eventHandler.js";
import { addDataToWaterfall } from "../js/waterfallHandler.js"; import { addDataToWaterfall } from "../js/waterfallHandler.js";
function connect(endpoint, dispatcher) { function connect(endpoint, dispatcher) {
@ -34,5 +34,6 @@ function connect(endpoint, dispatcher) {
} }
// Initial connection attempts to endpoints // Initial connection attempts to endpoints
connect("states", stateDispatcher);
connect("events", eventDispatcher); connect("events", eventDispatcher);
connect("fft", addDataToWaterfall); connect("fft", addDataToWaterfall);

View file

@ -192,6 +192,13 @@ def sock_fft(sock):
fft = app.modem_fft.get() fft = app.modem_fft.get()
transmit_sock_data(fft) transmit_sock_data(fft)
@sock.route('/states')
def sock_states(sock):
# it seems we have to keep the logics inside a loop, otherwise connection will be terminated
client_list.add(sock)
while True:
state = app.states.get()
transmit_sock_data(state)
# @app.route('/modem/listen', methods=['POST']) # not needed if we are restarting modem on changing settings # @app.route('/modem/listen', methods=['POST']) # not needed if we are restarting modem on changing settings