pub const BASELINE_WARMUP_S: u32 = 10;
pub const BASELINE_CAPTURE_S: u32 = 20;
pub const CELL_WARMUP_S: u32 = 15;
pub const CELL_CAPTURE_S: u32 = 40;
pub const RATES_HZ: [u32; 5] = [10, 50, 100, 250, 500];
pub const PAYLOADS_B: [u32; 3] = [32, 128, 512];
pub const REPS: u32 = 2;
pub const BOOT_DELAY_S: u32 = 10;
pub const TEST_CHANNEL: u8 = 11;
#[allow(dead_code)]
pub const BASELINE_MAX_SAMPLES: usize = 32;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PhaseKind {
BaselineWarmup,
BaselineCapture,
CellWarmup,
CellCapture,
}
impl PhaseKind {
pub fn as_str(self) -> &'static str {
match self {
PhaseKind::BaselineWarmup => "baseline_warmup",
PhaseKind::BaselineCapture => "baseline_capture",
PhaseKind::CellWarmup => "cell_warmup",
PhaseKind::CellCapture => "cell_capture",
}
}
}
#[derive(Clone, Copy)]
pub struct Phase {
pub kind: PhaseKind,
pub rate_hz: u32,
pub payload_b: u32,
pub rep: u32,
pub duration_s: u32,
}
pub const fn total_phases() -> usize {
2 + (RATES_HZ.len() * PAYLOADS_B.len() * REPS as usize) * 2
}
pub struct PhaseIter {
pos: usize,
}
impl Iterator for PhaseIter {
type Item = (usize, Phase);
fn next(&mut self) -> Option<Self::Item> {
let total = total_phases();
if self.pos >= total {
return None;
}
let idx = self.pos;
let phase = if self.pos == 0 {
Phase {
kind: PhaseKind::BaselineWarmup,
rate_hz: 0,
payload_b: 0,
rep: 0,
duration_s: BASELINE_WARMUP_S,
}
} else if self.pos == 1 {
Phase {
kind: PhaseKind::BaselineCapture,
rate_hz: 0,
payload_b: 0,
rep: 0,
duration_s: BASELINE_CAPTURE_S,
}
} else {
let cell_idx = (self.pos - 2) / 2;
let is_capture = (self.pos - 2) % 2 == 1;
let rep = (cell_idx as u32) % REPS;
let pi = (cell_idx / REPS as usize) % PAYLOADS_B.len();
let ri = (cell_idx / (REPS as usize * PAYLOADS_B.len())) % RATES_HZ.len();
let rate = RATES_HZ[ri];
let payload = PAYLOADS_B[pi];
let (kind, duration_s) = if is_capture {
(PhaseKind::CellCapture, CELL_CAPTURE_S)
} else {
(PhaseKind::CellWarmup, CELL_WARMUP_S)
};
Phase {
kind,
rate_hz: rate,
payload_b: payload,
rep,
duration_s,
}
};
self.pos += 1;
Some((idx, phase))
}
}
pub fn phases_iter() -> PhaseIter {
PhaseIter { pos: 0 }
}