[fix](trx-wefax): auto-save in-progress image on decoder reset
decoder.reset() now finalises and saves any partially-received image before returning to Idle. The server emits the completion event so the image appears in the frontend history and is persisted to disk. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -325,8 +325,15 @@ impl WefaxDecoder {
|
|||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reset the decoder, discarding any in-progress image.
|
/// Reset the decoder. Saves the in-progress image (if any) before
|
||||||
pub fn reset(&mut self) {
|
/// returning to Idle. Returns any completion events produced.
|
||||||
|
pub fn reset(&mut self) -> Vec<WefaxEvent> {
|
||||||
|
let events = match self.state {
|
||||||
|
State::Receiving { ioc, lpm } | State::Phasing { ioc, lpm } => {
|
||||||
|
self.finalize_image(ioc, lpm)
|
||||||
|
}
|
||||||
|
_ => Vec::new(),
|
||||||
|
};
|
||||||
let default_lpm = self.config.lpm.unwrap_or(120);
|
let default_lpm = self.config.lpm.unwrap_or(120);
|
||||||
self.state = State::Idle;
|
self.state = State::Idle;
|
||||||
self.resampler.reset();
|
self.resampler.reset();
|
||||||
@@ -341,6 +348,7 @@ impl WefaxDecoder {
|
|||||||
self.sent_idle_event = false;
|
self.sent_idle_event = false;
|
||||||
self.signal_detect_count = 0;
|
self.signal_detect_count = 0;
|
||||||
self.signal_detect_buf.clear();
|
self.signal_detect_buf.clear();
|
||||||
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the decoder is currently receiving an image.
|
/// Check if the decoder is currently receiving an image.
|
||||||
|
|||||||
@@ -2742,7 +2742,13 @@ pub async fn run_wefax_decoder(
|
|||||||
|
|
||||||
if reset_seq != last_reset_seq {
|
if reset_seq != last_reset_seq {
|
||||||
last_reset_seq = reset_seq;
|
last_reset_seq = reset_seq;
|
||||||
decoder.reset();
|
// Reset saves any in-progress image.
|
||||||
|
for evt in decoder.reset() {
|
||||||
|
if let WefaxEvent::Complete(msg) = evt {
|
||||||
|
histories.record_wefax_message(msg.clone());
|
||||||
|
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
||||||
pcm_rx = pcm_rx.resubscribe();
|
pcm_rx = pcm_rx.resubscribe();
|
||||||
continue;
|
continue;
|
||||||
@@ -2750,7 +2756,12 @@ pub async fn run_wefax_decoder(
|
|||||||
|
|
||||||
if !process_enabled {
|
if !process_enabled {
|
||||||
if was_active {
|
if was_active {
|
||||||
decoder.reset();
|
for evt in decoder.reset() {
|
||||||
|
if let WefaxEvent::Complete(msg) = evt {
|
||||||
|
histories.record_wefax_message(msg.clone());
|
||||||
|
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
was_active = false;
|
was_active = false;
|
||||||
}
|
}
|
||||||
active = false;
|
active = false;
|
||||||
@@ -2778,7 +2789,12 @@ pub async fn run_wefax_decoder(
|
|||||||
state_rx.borrow().reset_seqs.wefax_decode_reset_seq;
|
state_rx.borrow().reset_seqs.wefax_decode_reset_seq;
|
||||||
if latest_reset_seq != reset_seq {
|
if latest_reset_seq != reset_seq {
|
||||||
last_reset_seq = latest_reset_seq;
|
last_reset_seq = latest_reset_seq;
|
||||||
decoder.reset();
|
for evt in decoder.reset() {
|
||||||
|
if let WefaxEvent::Complete(msg) = evt {
|
||||||
|
histories.record_wefax_message(msg.clone());
|
||||||
|
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
||||||
pcm_rx = pcm_rx.resubscribe();
|
pcm_rx = pcm_rx.resubscribe();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user