blackbox: Store state for all blocks

This lets us validate the model from blackbox dumps.

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2023-10-23 02:38:43 +09:00
parent 7fbb53df51
commit 368be9d7df

View file

@ -84,14 +84,22 @@ impl Blackbox {
t_ambient: self.globals.t_ambient,
t_safe_max: self.globals.t_safe_max,
t_hysteresis: self.globals.t_hysteresis,
state: null
blocks: null
};
let mut state = json::JsonValue::new_array();
let mut blocks = json::JsonValue::new_array();
for block in self.blocks.iter() {
let mut info = object! {
sample_rate: block.sample_rate,
sample_count: block.data.len() / self.globals.channels,
speakers: null,
};
let mut speakers = json::JsonValue::new_array();
for group in self.blocks[0].state.iter() {
for speaker in group.iter() {
let _ = state.push(object! {
let _ = speakers.push(object! {
t_coil: speaker.t_coil,
t_magnet: speaker.t_magnet,
t_coil_hyst: speaker.t_coil_hyst,
@ -101,8 +109,11 @@ impl Blackbox {
});
}
}
info["speakers"] = speakers;
let _ = blocks.push(info);
}
meta["state"] = state;
meta["blocks"] = blocks;
metafd.write_all(meta.dump().as_bytes())?;