[feat](trx-server): handle decoder toggle and reset commands
Process decoder commands as early returns in rig_task (no CAT needed). Check aprs_decode_enabled/cw_decode_enabled flags in decoder tasks alongside mode. Track reset_seq to trigger decoder.reset() on clear. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -283,12 +283,22 @@ pub async fn run_aprs_decoder(
|
|||||||
info!("APRS decoder started ({}Hz, {} ch)", sample_rate, channels);
|
info!("APRS decoder started ({}Hz, {} ch)", sample_rate, channels);
|
||||||
let mut decoder = decode::aprs::AprsDecoder::new(sample_rate);
|
let mut decoder = decode::aprs::AprsDecoder::new(sample_rate);
|
||||||
let mut was_active = false;
|
let mut was_active = false;
|
||||||
|
let mut last_reset_seq: u64 = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match pcm_rx.recv().await {
|
match pcm_rx.recv().await {
|
||||||
Ok(frame) => {
|
Ok(frame) => {
|
||||||
let mode = &state_rx.borrow().status.mode;
|
let state = state_rx.borrow().clone();
|
||||||
let active = matches!(mode, RigMode::PKT);
|
let mode = &state.status.mode;
|
||||||
|
let enabled = state.aprs_decode_enabled;
|
||||||
|
let active = enabled && matches!(mode, RigMode::PKT);
|
||||||
|
|
||||||
|
// Check for reset request
|
||||||
|
if state.aprs_decode_reset_seq != last_reset_seq {
|
||||||
|
last_reset_seq = state.aprs_decode_reset_seq;
|
||||||
|
decoder.reset();
|
||||||
|
info!("APRS decoder reset (seq={})", last_reset_seq);
|
||||||
|
}
|
||||||
|
|
||||||
if !active {
|
if !active {
|
||||||
if was_active {
|
if was_active {
|
||||||
@@ -334,12 +344,22 @@ pub async fn run_cw_decoder(
|
|||||||
info!("CW decoder started ({}Hz, {} ch)", sample_rate, channels);
|
info!("CW decoder started ({}Hz, {} ch)", sample_rate, channels);
|
||||||
let mut decoder = decode::cw::CwDecoder::new(sample_rate);
|
let mut decoder = decode::cw::CwDecoder::new(sample_rate);
|
||||||
let mut was_active = false;
|
let mut was_active = false;
|
||||||
|
let mut last_reset_seq: u64 = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match pcm_rx.recv().await {
|
match pcm_rx.recv().await {
|
||||||
Ok(frame) => {
|
Ok(frame) => {
|
||||||
let mode = &state_rx.borrow().status.mode;
|
let state = state_rx.borrow().clone();
|
||||||
let active = matches!(mode, RigMode::CW | RigMode::CWR);
|
let mode = &state.status.mode;
|
||||||
|
let enabled = state.cw_decode_enabled;
|
||||||
|
let active = enabled && matches!(mode, RigMode::CW | RigMode::CWR);
|
||||||
|
|
||||||
|
// Check for reset request
|
||||||
|
if state.cw_decode_reset_seq != last_reset_seq {
|
||||||
|
last_reset_seq = state.cw_decode_reset_seq;
|
||||||
|
decoder.reset();
|
||||||
|
info!("CW decoder reset (seq={})", last_reset_seq);
|
||||||
|
}
|
||||||
|
|
||||||
if !active {
|
if !active {
|
||||||
if was_active {
|
if was_active {
|
||||||
|
|||||||
@@ -188,6 +188,10 @@ fn map_command(cmd: ClientCommand) -> RigCommand {
|
|||||||
ClientCommand::Unlock => RigCommand::Unlock,
|
ClientCommand::Unlock => RigCommand::Unlock,
|
||||||
ClientCommand::GetTxLimit => RigCommand::GetTxLimit,
|
ClientCommand::GetTxLimit => RigCommand::GetTxLimit,
|
||||||
ClientCommand::SetTxLimit { limit } => RigCommand::SetTxLimit(limit),
|
ClientCommand::SetTxLimit { limit } => RigCommand::SetTxLimit(limit),
|
||||||
|
ClientCommand::SetAprsDecodeEnabled { enabled } => RigCommand::SetAprsDecodeEnabled(enabled),
|
||||||
|
ClientCommand::SetCwDecodeEnabled { enabled } => RigCommand::SetCwDecodeEnabled(enabled),
|
||||||
|
ClientCommand::ResetAprsDecoder => RigCommand::ResetAprsDecoder,
|
||||||
|
ClientCommand::ResetCwDecoder => RigCommand::ResetCwDecoder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,6 +222,10 @@ fn build_initial_state(cfg: &ServerConfig, resolved: &ResolvedConfig) -> RigStat
|
|||||||
server_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
server_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||||
server_latitude: resolved.latitude,
|
server_latitude: resolved.latitude,
|
||||||
server_longitude: resolved.longitude,
|
server_longitude: resolved.longitude,
|
||||||
|
aprs_decode_enabled: false,
|
||||||
|
cw_decode_enabled: false,
|
||||||
|
aprs_decode_reset_seq: 0,
|
||||||
|
cw_decode_reset_seq: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,10 @@ pub async fn run_rig_task(
|
|||||||
server_version,
|
server_version,
|
||||||
server_latitude,
|
server_latitude,
|
||||||
server_longitude,
|
server_longitude,
|
||||||
|
aprs_decode_enabled: false,
|
||||||
|
cw_decode_enabled: false,
|
||||||
|
aprs_decode_reset_seq: 0,
|
||||||
|
cw_decode_reset_seq: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Polling configuration
|
// Polling configuration
|
||||||
@@ -343,6 +347,31 @@ async fn process_command(
|
|||||||
cmd: RigCommand,
|
cmd: RigCommand,
|
||||||
ctx: &mut CommandExecContext<'_>,
|
ctx: &mut CommandExecContext<'_>,
|
||||||
) -> RigResult<RigSnapshot> {
|
) -> RigResult<RigSnapshot> {
|
||||||
|
// Handle decoder commands early — they don't touch the rig CAT.
|
||||||
|
match cmd {
|
||||||
|
RigCommand::SetAprsDecodeEnabled(en) => {
|
||||||
|
ctx.state.aprs_decode_enabled = en;
|
||||||
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
|
return snapshot_from(ctx.state);
|
||||||
|
}
|
||||||
|
RigCommand::SetCwDecodeEnabled(en) => {
|
||||||
|
ctx.state.cw_decode_enabled = en;
|
||||||
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
|
return snapshot_from(ctx.state);
|
||||||
|
}
|
||||||
|
RigCommand::ResetAprsDecoder => {
|
||||||
|
ctx.state.aprs_decode_reset_seq += 1;
|
||||||
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
|
return snapshot_from(ctx.state);
|
||||||
|
}
|
||||||
|
RigCommand::ResetCwDecoder => {
|
||||||
|
ctx.state.cw_decode_reset_seq += 1;
|
||||||
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
|
return snapshot_from(ctx.state);
|
||||||
|
}
|
||||||
|
_ => {} // fall through to normal rig handler
|
||||||
|
}
|
||||||
|
|
||||||
sync_machine_state(ctx.machine, ctx.state);
|
sync_machine_state(ctx.machine, ctx.state);
|
||||||
|
|
||||||
// Check if rig is ready for commands
|
// Check if rig is ready for commands
|
||||||
|
|||||||
Reference in New Issue
Block a user