backup info and read
This commit is contained in:
@@ -216,16 +216,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
|
||||
//check if we know the time current > 2020
|
||||
if cur.year() < 2020 {
|
||||
println!("Running time estimation super fallback");
|
||||
if board.is_day() {
|
||||
//assume TZ safe times ;)
|
||||
|
||||
println!("Is day -> 15:00");
|
||||
cur = *cur.with_hour(15).get_or_insert(cur);
|
||||
} else {
|
||||
println!("Is night -> 3:00");
|
||||
cur = *cur.with_hour(3).get_or_insert(cur);
|
||||
}
|
||||
to_config = true;
|
||||
}
|
||||
|
||||
println!("cur is {}", cur);
|
||||
|
@@ -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,
|
||||
|
@@ -51,6 +51,12 @@ pub struct TestPump {
|
||||
pump: usize,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
pub struct WebBackupHeader{
|
||||
timestamp: std::string::String,
|
||||
size: usize
|
||||
}
|
||||
|
||||
fn write_time(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -159,6 +165,26 @@ fn get_backup_config(
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
|
||||
fn backup_info(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let header = board.get_backup_info();
|
||||
let json = match header {
|
||||
Ok(h) => {
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap();
|
||||
let wbh = WebBackupHeader{
|
||||
timestamp: timestamp.to_rfc3339(),
|
||||
size: h.size,
|
||||
};
|
||||
serde_json::to_string(&wbh)?
|
||||
},
|
||||
Err(_) => "{\"error\":\"Header could not be parsed\"".to_owned()
|
||||
};
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
fn set_config(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -392,6 +418,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
handle_error_to500(request, backup_config)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/backup_info", Method::Get, move |request| {
|
||||
handle_error_to500(request, backup_info)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/files", Method::Get, move |request| {
|
||||
handle_error_to500(request, list_files)
|
||||
|
Reference in New Issue
Block a user