From 40447f6cc43b793e5efa65ec6b915563966588d6 Mon Sep 17 00:00:00 2001 From: KingfuChan-Mac Date: Mon, 20 Jan 2025 23:45:01 +0800 Subject: [PATCH 1/3] add callsign for kStationStateUpdate --- backend/include/sdk.hpp | 2 +- backend/src/main.cpp | 19 ++++++++++--------- backend/src/sdk.cpp | 2 +- backend/types/index.d.ts | 1 + src/main/index.ts | 2 ++ src/preload/bindings.ts | 2 ++ src/renderer/src/components/radio/radio.tsx | 6 ++++++ .../src/components/radio/unicom-guard.tsx | 4 ++++ 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/backend/include/sdk.hpp b/backend/include/sdk.hpp index 714fd86..d62ad85 100644 --- a/backend/include/sdk.hpp +++ b/backend/include/sdk.hpp @@ -31,7 +31,7 @@ enum class Event : std::uint8_t { kTxEnd, kFrequencyStateUpdate, kDisconnectFrequencyStateUpdate, - kStationStateUpdated, + kStationStateUpdate, kVoiceConnectedState, }; } diff --git a/backend/src/main.cpp b/backend/src/main.cpp index 1d8755b..108366d 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -237,19 +237,20 @@ Napi::Boolean SetFrequencyState(const Napi::CallbackInfo& info) { RadioState newState {}; - newState.frequency = info[0].As().Int32Value(); - newState.rx = info[1].As().Value(); - newState.tx = info[2].As().Value(); - newState.xc = info[3].As().Value(); + auto callsign = info[0].As().Utf8Value(); + newState.frequency = info[1].As().Int32Value(); + newState.rx = info[2].As().Value(); + newState.tx = info[3].As().Value(); + newState.xc = info[4].As().Value(); // Note the negation here, as the API uses the opposite of what is saved internally - newState.headset = !info[4].As().Value(); - newState.xca = info[5].As().Value(); // Not used - newState.isOutputMuted = info.Length() > 6 ? info[6].As().Value() : false; - newState.outputVolume = info.Length() > 7 ? info[7].As().FloatValue() : 100; + newState.headset = !info[5].As().Value(); + newState.xca = info[6].As().Value(); // Not used + newState.isOutputMuted = info.Length() > 7 ? info[7].As().Value() : false; + newState.outputVolume = info.Length() > 8 ? info[8].As().FloatValue() : 100; // SetGuardAndUnicomTransceivers(); - auto result = RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, ""); + auto result = RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, callsign); return Napi::Boolean::New(info.Env(), result); } diff --git a/backend/src/sdk.cpp b/backend/src/sdk.cpp index 4e38ed7..caafdb9 100644 --- a/backend/src/sdk.cpp +++ b/backend/src/sdk.cpp @@ -228,7 +228,7 @@ void SDK::handleAFVEventForWebsocket(sdk::types::Event event, return; } - if (event == sdk::types::Event::kStationStateUpdated) { + if (event == sdk::types::Event::kStationStateUpdate) { if (!frequencyHz.has_value()) { PLOG_ERROR << "kStationStateUpdated requires a frequencyHz"; return; diff --git a/backend/types/index.d.ts b/backend/types/index.d.ts index af96847..25d86b2 100644 --- a/backend/types/index.d.ts +++ b/backend/types/index.d.ts @@ -71,6 +71,7 @@ declare namespace TrackAudioAfv { export function RefreshStation(callsign: string): void; export function SetFrequencyState( + callsign: string, frequency: number, rx: boolean, tx: boolean, diff --git a/src/main/index.ts b/src/main/index.ts index 821817c..532e767 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -586,6 +586,7 @@ ipcMain.handle( 'audio-set-frequency-state', ( _, + callsign: string, frequency: number, rx: boolean, tx: boolean, @@ -596,6 +597,7 @@ ipcMain.handle( outputVolume?: number ) => { return TrackAudioAfv.SetFrequencyState( + callsign, frequency, rx, tx, diff --git a/src/preload/bindings.ts b/src/preload/bindings.ts index 4d4a2e6..406078b 100644 --- a/src/preload/bindings.ts +++ b/src/preload/bindings.ts @@ -67,6 +67,7 @@ export const api = { IsFrequencyActive: (frequency: number) => ipcRenderer.invoke('audio-is-frequency-active', frequency), setFrequencyState: ( + callsign: string, frequency: number, rx: boolean, tx: boolean, @@ -78,6 +79,7 @@ export const api = { ) => ipcRenderer.invoke( 'audio-set-frequency-state', + callsign, frequency, rx, tx, diff --git a/src/renderer/src/components/radio/radio.tsx b/src/renderer/src/components/radio/radio.tsx index 0b277b5..ae2f44a 100644 --- a/src/renderer/src/components/radio/radio.tsx +++ b/src/renderer/src/components/radio/radio.tsx @@ -136,6 +136,7 @@ const Radio: React.FC = ({ radio }) => { const newState = !radio.isOutputMuted; window.api .setFrequencyState( + radio.callsign, radio.frequency, radio.rx, radio.tx, @@ -195,6 +196,7 @@ const Radio: React.FC = ({ radio }) => { window.api .setFrequencyState( + radio.callsign, radio.frequency, newState, newState ? radio.tx : false, @@ -230,6 +232,7 @@ const Radio: React.FC = ({ radio }) => { window.api .setFrequencyState( + radio.callsign, radio.frequency, newState ? true : radio.rx, newState, @@ -263,6 +266,7 @@ const Radio: React.FC = ({ radio }) => { const newState = !radio.xc; window.api .setFrequencyState( + radio.callsign, radio.frequency, newState ? true : radio.rx, newState ? true : radio.tx, @@ -296,6 +300,7 @@ const Radio: React.FC = ({ radio }) => { const newState = !radio.crossCoupleAcross; window.api .setFrequencyState( + radio.callsign, radio.frequency, newState ? true : radio.rx, newState ? true : radio.tx, @@ -329,6 +334,7 @@ const Radio: React.FC = ({ radio }) => { const newState = !radio.onSpeaker; window.api .setFrequencyState( + radio.callsign, radio.frequency, radio.rx, radio.tx, diff --git a/src/renderer/src/components/radio/unicom-guard.tsx b/src/renderer/src/components/radio/unicom-guard.tsx index 7239514..113e41b 100644 --- a/src/renderer/src/components/radio/unicom-guard.tsx +++ b/src/renderer/src/components/radio/unicom-guard.tsx @@ -70,6 +70,7 @@ const UnicomGuardBar = () => { window.api .setFrequencyState( + radio.callsign, radio.frequency, newState, newState ? radio.tx : false, @@ -105,6 +106,7 @@ const UnicomGuardBar = () => { window.api .setFrequencyState( + radio.callsign, radio.frequency, newState ? true : radio.rx, // If tx is true, rx must be true newState, @@ -139,6 +141,7 @@ const UnicomGuardBar = () => { const newState = !radio.onSpeaker; window.api .setFrequencyState( + radio.callsign, radio.frequency, radio.rx, radio.tx, @@ -174,6 +177,7 @@ const UnicomGuardBar = () => { const newState = !radio.isOutputMuted; window.api .setFrequencyState( + radio.callsign, radio.frequency, radio.rx, radio.tx, From 7b64f1ab8d00d52fc1c539d8519ecce798074080 Mon Sep 17 00:00:00 2001 From: KingfuChan-Mac Date: Tue, 21 Jan 2025 00:46:41 +0800 Subject: [PATCH 2/3] add callsign for kStationStateUpdate (on RemoveFrequency) --- backend/src/main.cpp | 3 ++- backend/types/index.d.ts | 5 ++++- src/main/index.ts | 12 +++++++++--- src/preload/bindings.ts | 10 +++++++++- .../src/components/delete-multiple-radios.tsx | 2 +- src/renderer/src/components/radio/radio.tsx | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/src/main.cpp b/backend/src/main.cpp index 108366d..aa69e79 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -217,6 +217,7 @@ void RemoveFrequency(const Napi::CallbackInfo& info) RadioState newState {}; newState.frequency = info[0].As().Int32Value(); + auto callsign = info.Length() > 1 ? info[1].As().Utf8Value() : ""; newState.rx = false; newState.tx = false; newState.xc = false; @@ -225,7 +226,7 @@ void RemoveFrequency(const Napi::CallbackInfo& info) newState.isOutputMuted = false; newState.outputVolume = 100; - RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, "", false); + RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, callsign, false); mClient->RemoveFrequency(newState.frequency); MainThreadShared::mApiServer->publishFrequencyRemoved(newState.frequency); diff --git a/backend/types/index.d.ts b/backend/types/index.d.ts index 25d86b2..137d44d 100644 --- a/backend/types/index.d.ts +++ b/backend/types/index.d.ts @@ -64,7 +64,10 @@ declare namespace TrackAudioAfv { callign: string, outputVolume?: number, ): Promise; - export function RemoveFrequency(frequency: number): void; + export function RemoveFrequency( + frequency: number, + callsign?: string, + ): void; export function IsFrequencyActive(frequency: number): boolean; export function GetStation(callsign: string): void; diff --git a/src/main/index.ts b/src/main/index.ts index 532e767..1f0ba41 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -578,9 +578,15 @@ ipcMain.handle( } ); -ipcMain.handle('audio-remove-frequency', (_, frequency: number) => { - TrackAudioAfv.RemoveFrequency(frequency); -}); +ipcMain.handle( + 'audio-remove-frequency', + (_, frequency: number, callsign?: string) => { + if (callsign) { + TrackAudioAfv.RemoveFrequency(frequency, callsign); + } + TrackAudioAfv.RemoveFrequency(frequency); + } +); ipcMain.handle( 'audio-set-frequency-state', diff --git a/src/preload/bindings.ts b/src/preload/bindings.ts index 406078b..9719379 100644 --- a/src/preload/bindings.ts +++ b/src/preload/bindings.ts @@ -63,7 +63,15 @@ export const api = { addFrequency: (frequency: number, callsign: string, outputVolume?: number) => ipcRenderer.invoke('audio-add-frequency', frequency, callsign, outputVolume), - removeFrequency: (frequency: number) => ipcRenderer.invoke('audio-remove-frequency', frequency), + removeFrequency: ( + frequency: number, + callsign?: string + ) => + ipcRenderer.invoke( + 'audio-remove-frequency', + frequency, + callsign + ), IsFrequencyActive: (frequency: number) => ipcRenderer.invoke('audio-is-frequency-active', frequency), setFrequencyState: ( diff --git a/src/renderer/src/components/delete-multiple-radios.tsx b/src/renderer/src/components/delete-multiple-radios.tsx index fb5d0fa..0836d8f 100644 --- a/src/renderer/src/components/delete-multiple-radios.tsx +++ b/src/renderer/src/components/delete-multiple-radios.tsx @@ -42,7 +42,7 @@ const DeleteMultipleRadios: React.FC = () => { } if (!radio.currentlyRx && !radio.currentlyTx) { - void window.api.removeFrequency(radio.frequency); + void window.api.removeFrequency(radio.frequency, radio.callsign); removeRadio(radio.frequency); clearInterval(interval); } diff --git a/src/renderer/src/components/radio/radio.tsx b/src/renderer/src/components/radio/radio.tsx index ae2f44a..beeaaf8 100644 --- a/src/renderer/src/components/radio/radio.tsx +++ b/src/renderer/src/components/radio/radio.tsx @@ -376,7 +376,7 @@ const Radio: React.FC = ({ radio }) => { } if (!radio.currentlyRx && !radio.currentlyTx) { - void window.api.removeFrequency(radio.frequency); + void window.api.removeFrequency(radio.frequency, radio.callsign); removeRadio(radio.frequency); clearInterval(interval); } From 7bd2c423d10c148a6cd4a8e36697ff32c8bc36d0 Mon Sep 17 00:00:00 2001 From: KingfuChan-Mac Date: Tue, 21 Jan 2025 09:25:55 +0800 Subject: [PATCH 3/3] restore kStationStateUpdated event type --- backend/include/sdk.hpp | 2 +- backend/src/sdk.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/include/sdk.hpp b/backend/include/sdk.hpp index d62ad85..714fd86 100644 --- a/backend/include/sdk.hpp +++ b/backend/include/sdk.hpp @@ -31,7 +31,7 @@ enum class Event : std::uint8_t { kTxEnd, kFrequencyStateUpdate, kDisconnectFrequencyStateUpdate, - kStationStateUpdate, + kStationStateUpdated, kVoiceConnectedState, }; } diff --git a/backend/src/sdk.cpp b/backend/src/sdk.cpp index caafdb9..4e38ed7 100644 --- a/backend/src/sdk.cpp +++ b/backend/src/sdk.cpp @@ -228,7 +228,7 @@ void SDK::handleAFVEventForWebsocket(sdk::types::Event event, return; } - if (event == sdk::types::Event::kStationStateUpdate) { + if (event == sdk::types::Event::kStationStateUpdated) { if (!frequencyHz.has_value()) { PLOG_ERROR << "kStationStateUpdated requires a frequencyHz"; return;