From 2c331ecaa4ba5bce28a3197773a11a32460fb934 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sat, 13 Apr 2024 10:56:11 +0200 Subject: [PATCH] beacon away from key flag on server layer --- gui/src/assets/waterfall/spectrum.js | 6 ++++ .../grid/grid_active_broadcasts_vert.vue | 31 +++++++++++++++++-- gui/src/js/api.js | 4 +-- gui/src/js/eventHandler.js | 10 ++++-- gui/src/store/stateStore.js | 1 + modem/data_frame_factory.py | 26 ++++++++++++++-- modem/server.py | 7 +++-- modem/state_manager.py | 2 ++ 8 files changed, 75 insertions(+), 12 deletions(-) diff --git a/gui/src/assets/waterfall/spectrum.js b/gui/src/assets/waterfall/spectrum.js index 1e75e548..11aadd24 100644 --- a/gui/src/assets/waterfall/spectrum.js +++ b/gui/src/assets/waterfall/spectrum.js @@ -105,6 +105,8 @@ Spectrum.prototype.drawSpectrum = function () { var linePositionHigh = 178.4; //150 + bandwidth/20 var linePositionLow2 = 65; //150 - bandwith/20 var linePositionHigh2 = 235; //150 + bandwith/20 + var linePositionLow3 = 28.1; //150 - bandwith/20 + var linePositionHigh3 = 271.9; //150 + bandwith/20 this.ctx_wf.beginPath(); this.ctx_wf.moveTo(linePositionLow, 0); this.ctx_wf.lineTo(linePositionLow, height); @@ -114,6 +116,10 @@ Spectrum.prototype.drawSpectrum = function () { this.ctx_wf.lineTo(linePositionLow2, height); this.ctx_wf.moveTo(linePositionHigh2, 0); this.ctx_wf.lineTo(linePositionHigh2, height); + this.ctx_wf.moveTo(linePositionLow3, 0); + this.ctx_wf.lineTo(linePositionLow3, height); + this.ctx_wf.moveTo(linePositionHigh3, 0); + this.ctx_wf.lineTo(linePositionHigh3, height); this.ctx_wf.lineWidth = 1; this.ctx_wf.strokeStyle = "#C3C3C3"; this.ctx_wf.stroke(); diff --git a/gui/src/components/grid/grid_active_broadcasts_vert.vue b/gui/src/components/grid/grid_active_broadcasts_vert.vue index f1290fdc..754ded2c 100644 --- a/gui/src/components/grid/grid_active_broadcasts_vert.vue +++ b/gui/src/components/grid/grid_active_broadcasts_vert.vue @@ -15,11 +15,22 @@ function transmitPing() { function startStopBeacon() { if (state.beacon_state === true) { - setModemBeacon(false); + setModemBeacon(false, state.away_from_key); } else { - setModemBeacon(true); + setModemBeacon(true, state.away_from_key); } } + +function setAwayFromKey(){ + if (state.away_from_key === true) { + setModemBeacon(state.beacon_state, false); + } else { + setModemBeacon(state.beacon_state, true); + } + +} + + var dxcallPing = ref(""); window.addEventListener( "stationSelected", @@ -84,6 +95,22 @@ window.addEventListener( > + +
+
+ + +
+
diff --git a/gui/src/js/api.js b/gui/src/js/api.js index 2cd05108..7e469fac 100644 --- a/gui/src/js/api.js +++ b/gui/src/js/api.js @@ -92,8 +92,8 @@ export async function getSerialDevices() { return await apiGet("/devices/serial"); } -export async function setModemBeacon(enabled = false) { - return await apiPost("/modem/beacon", { enabled: enabled }); +export async function setModemBeacon(enabled = false, afk = false) { + return await apiPost("/modem/beacon", { enabled: enabled, afk: afk}); } export async function sendModemCQ() { diff --git a/gui/src/js/eventHandler.js b/gui/src/js/eventHandler.js index dd95a156..0fa5db26 100644 --- a/gui/src/js/eventHandler.js +++ b/gui/src/js/eventHandler.js @@ -30,8 +30,11 @@ import { getRemote, } from "../store/settingsStore.js"; -export function loadAllData() { - getModemState(); +export async function loadAllData() { + // TODO: Make this working + let stateData = await getModemState(); + console.log(stateData) + getRemote(); getOverallHealth(); audioStore.loadAudioDevices(); @@ -67,7 +70,10 @@ export function stateDispatcher(data) { ); stateStore.channel_busy_slot = data["channel_busy_slot"]; + stateStore.beacon_state = data["is_beacon_running"]; + stateStore.is_away_from_key = data["is_away_from_key"]; + stateStore.radio_status = data["radio_status"]; stateStore.frequency = data["radio_frequency"]; stateStore.mode = data["radio_mode"]; diff --git a/gui/src/store/stateStore.js b/gui/src/store/stateStore.js index e65a331c..c17af8b9 100644 --- a/gui/src/store/stateStore.js +++ b/gui/src/store/stateStore.js @@ -38,6 +38,7 @@ export const useStateStore = defineStore("stateStore", () => { var arq_session_state = ref(""); var arq_state = ref(""); var beacon_state = ref(false); + var away_from_key = ref(false); var audio_recording = ref(false); diff --git a/modem/data_frame_factory.py b/modem/data_frame_factory.py index adddddf4..af6b3efa 100644 --- a/modem/data_frame_factory.py +++ b/modem/data_frame_factory.py @@ -18,6 +18,10 @@ class DataFrameFactory: 'CHECKSUM': 2, # Bit-position for indicating the CHECKSUM is correct or not } + BEACON_FLAGS = { + 'AWAY_FROM_KEY': 0, # Bit-position for indicating the AWAY FROM KEY state + } + def __init__(self, config): self.myfullcall = f"{config['STATION']['mycall']}-{config['STATION']['myssid']}" @@ -51,7 +55,8 @@ class DataFrameFactory: self.template_list[FR_TYPE.BEACON.value] = { "frame_length": self.LENGTH_SIG0_FRAME, "origin": 6, - "gridsquare": 4 + "gridsquare": 4, + "flag": 1 } def _load_ping_templates(self): @@ -287,6 +292,15 @@ class DataFrameFactory: # Update extracted_data with the status of each flag # get_flag returns True or False based on the bit value at the flag's position extracted_data[key][flag] = helpers.get_flag(data, flag, flag_dict) + + if frametype in [FR_TYPE.BEACON]: + flag_dict = self.BEACON_FLAGS + for flag in flag_dict: + # Update extracted_data with the status of each flag + # get_flag returns True or False based on the bit value at the flag's position + extracted_data[key][flag] = helpers.get_flag(data, flag, flag_dict) + + else: extracted_data[key] = data @@ -342,10 +356,16 @@ class DataFrameFactory: } return self.construct(FR_TYPE.QRV, payload) - def build_beacon(self): + def build_beacon(self, flag_away_from_key = False): + flag = 0b00000000 + if flag_away_from_key: + flag = helpers.set_flag(flag, 'AWAY_FROM_KEY', True, self.BEACON_FLAGS) + payload = { "origin": helpers.callsign_to_bytes(self.myfullcall), - "gridsquare": helpers.encode_grid(self.mygrid) + "gridsquare": helpers.encode_grid(self.mygrid), + "flag": flag.to_bytes(1, 'big'), + } return self.construct(FR_TYPE.BEACON, payload) diff --git a/modem/server.py b/modem/server.py index c723d3b6..409b4de2 100644 --- a/modem/server.py +++ b/modem/server.py @@ -33,7 +33,7 @@ from schedule_manager import ScheduleManager app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}) sock = Sock(app) -MODEM_VERSION = "0.15.1-alpha" +MODEM_VERSION = "0.15.2-alpha" # set config file to use def set_config(): @@ -146,14 +146,15 @@ def post_cqcqcq(): def post_beacon(): if request.method not in ['POST']: return api_response({"info": "endpoint for controlling BEACON STATE via POST"}) - - if not isinstance(request.json['enabled'], bool): + if not isinstance(request.json['enabled'], bool) or not isinstance(request.json['afk'], bool): api_abort(f"Incorrect value for 'enabled'. Shoud be bool.") if not app.state_manager.is_modem_running: api_abort('Modem not running', 503) if not app.state_manager.is_beacon_running: app.state_manager.set('is_beacon_running', request.json['enabled']) + app.state_manager.set('is_away_from_key', request.json['afk']) + if not app.state_manager.getARQ(): enqueue_tx_command(command_beacon.BeaconCommand, request.json) else: diff --git a/modem/state_manager.py b/modem/state_manager.py index ca65e4fb..a3464370 100644 --- a/modem/state_manager.py +++ b/modem/state_manager.py @@ -23,6 +23,7 @@ class StateManager: self.setARQ(False) self.is_beacon_running = False + self.is_away_from_key = False # If true, any wait() call is blocking self.transmitting_event = threading.Event() @@ -84,6 +85,7 @@ class StateManager: "type": msgtype, "is_modem_running": self.is_modem_running, "is_beacon_running": self.is_beacon_running, + "is_away_from_key": self.is_away_from_key, "radio_status": self.radio_status, "radio_frequency": self.radio_frequency, "radio_mode": self.radio_mode,