From c8255005488736b35630d1a111138ea90d3c09c0 Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 14 May 2024 08:17:32 +1200 Subject: [PATCH] write correct wav bytes --- src/device_config.rs | 20 -------------------- src/main.rs | 12 ++---------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/device_config.rs b/src/device_config.rs index 891f128..fc44b7d 100644 --- a/src/device_config.rs +++ b/src/device_config.rs @@ -479,7 +479,6 @@ pub struct DeviceConfig { #[serde(rename = "thermal-recorder", default)] recording_settings: ThermalRecordingSettings, location: Option, - last_offload:Option, } impl DeviceConfig { @@ -564,23 +563,6 @@ impl DeviceConfig { self.recording_settings.use_low_power_mode } - pub fn update_last_offload(&mut self, timestamp:i64) ->Result<(), std::io::Error> { - self.last_offload = Some(timestamp); - fs::write("/etc/cacophony/.offload_time",×tamp.to_le_bytes()) - } - - pub fn load_last_offload(&mut self) { - let offload_fs = - fs::read("/etc/cacophony/.offload_time"); - let last_offload = match offload_fs{ - Ok(file_data) => Some(LittleEndian::read_i64(&file_data[0..8])), - _ => { - info!("Couldn't read offload info /etc/cacophony/.offload_time"); - None - } - }; - self.last_offload = last_offload; - } pub fn load_from_fs() -> Result { let config_toml = fs::read("/etc/cacophony/config.toml").map_err(|_| "Error reading file from disk")?; @@ -611,7 +593,6 @@ impl DeviceConfig { device_config.print_next_recording_window(&Utc::now().naive_utc()); } } - device_config.load_last_offload(); Ok(device_config) } Err(msg) => { @@ -872,7 +853,6 @@ impl DeviceConfig { - buf.write_i64::(self.last_offload.unwrap_or_default()).unwrap(); } } diff --git a/src/main.rs b/src/main.rs index 71239a3..cadaa21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,7 +171,7 @@ fn wav_header(audio_bytes: &Vec) -> [u8;44]{ cursor+=1; } - let file_size = audio_bytes.len() + 36; + let file_size = audio_bytes.len()-12 + 36; for b in file_size.to_le_bytes(){ header[cursor] =b; cursor+=1; @@ -218,7 +218,7 @@ fn wav_header(audio_bytes: &Vec) -> [u8;44]{ header[cursor] =b; cursor+=1; } - for b in audio_bytes.len().to_le_bytes(){ + for b in (audio_bytes.len()-12).to_le_bytes(){ header[cursor] =b; cursor+=1; } @@ -808,14 +808,6 @@ fn main() { if transfer_type == CAMERA_CONNECT_INFO { info!("Got camera connect info {:?}", chunk); - let last_offload = LittleEndian::read_i64(&chunk[12..20]); - if last_offload !=0 { - info!("Updating last offload {}",last_offload); - let update_off = device_config.update_last_offload(last_offload); - if update_off.is_err(){ - warn!("Couldn't write last offload {}",update_off.err().unwrap()); - } - } // Write all the info we need about the device: device_config.write_to_slice(&mut return_payload_buf[8..]); info!("Sending camera device config to rp2040");