backup info and read

This commit is contained in:
2025-01-22 22:21:54 +01:00
parent 8cc967cf68
commit 88be5951a6
9 changed files with 131 additions and 29 deletions

View File

@@ -206,9 +206,9 @@ pub struct BatteryState {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct BackupHeader{
timestamp: i64,
pub timestamp: i64,
crc16: u16,
size: usize
pub size: usize
}
impl PlantCtrlBoard<'_> {
@@ -227,6 +227,25 @@ impl PlantCtrlBoard<'_> {
};
}
pub fn get_backup_info(&mut self) -> Result<BackupHeader> {
let dummy = BackupHeader{
timestamp: 0,
crc16: 0,
size: 0,
};
let store = bincode::serialize(&dummy)?.len();
let mut header_page_buffer = vec![0_u8; store];
match self.eeprom.read_data(0, &mut header_page_buffer) {
OkStd(_) => {},
Err(err) => bail!("Error reading eeprom header {:?}", err),
};
println!("Raw header is {:?} with size {}", header_page_buffer , store);
let header:BackupHeader = bincode::deserialize(&header_page_buffer)?;
Ok(header)
}
pub fn get_backup_config(&mut self) -> Result<Vec<u8>> {
let dummy = BackupHeader{
timestamp: 0,