Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/compress.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! Delta encoding for archived downlink frames. Live frames stay raw.

/// Encode a channel as first sample plus deltas, quantised to `step`.
pub fn delta_encode(samples: &[f64], step: f64) -> Vec<i32> {
let mut out = Vec::with_capacity(samples.len());
let mut prev = 0.0;
for (i, &s) in samples.iter().enumerate() {
let q = (s / step).round();
out.push(if i == 0 { q as i32 } else { (q - prev) as i32 });
prev = q;
}
out
}

pub fn delta_decode(deltas: &[i32], step: f64) -> Vec<f64> {
let mut acc = 0i64;
deltas
.iter()
.map(|&d| {
acc += d as i64;
acc as f64 * step
})
.collect()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn round_trips_within_a_step() {
let samples = [4.01, 4.02, 4.05, 3.98];
let step = 0.01;
let decoded = delta_decode(&delta_encode(&samples, step), step);
for (a, b) in samples.iter().zip(decoded) {
assert!((a - b).abs() <= step / 2.0 + 1e-9);
}
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Kestrel launch sequencer: walks the terminal count, honours holds, and
//! hands off to the flight computer at T-0.

mod compress;
mod sequencer;
mod telemetry;

Expand Down
Loading