Revert "new ota logic"

This reverts commit c61a586595.
This commit is contained in:
2026-03-17 22:17:47 +01:00
parent ce981232f0
commit 66e1fe63e0
15 changed files with 401 additions and 314 deletions

View File

@@ -5,7 +5,7 @@ use crate::plant_state::{MoistureSensorState, PlantState};
use crate::tank::determine_tank_state;
use crate::{get_version, BOARD_ACCESS};
use alloc::format;
use alloc::string::String;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use chrono_tz::Tz;
use core::str::FromStr;
@@ -43,6 +43,7 @@ where
plant_state.push(PlantState::read_hardware_state(moistures, i, &mut board).await);
}
let a = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_a {
MoistureSensorState::Disabled => "disabled".to_string(),
MoistureSensorState::MoistureValue {
raw_hz,
moisture_percent,
@@ -52,6 +53,7 @@ where
MoistureSensorState::SensorError(err) => format!("{err:?}"),
}));
let b = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_b {
MoistureSensorState::Disabled => "disabled".to_string(),
MoistureSensorState::MoistureValue {
raw_hz,
moisture_percent,
@@ -126,7 +128,11 @@ pub(crate) async fn get_battery_state<T, const N: usize>(
_request: &mut Connection<'_, T, N>,
) -> FatResult<Option<String>> {
let mut board = BOARD_ACCESS.get().await.lock().await;
let battery_state = board.board_hal.get_battery_monitor().get_state().await?;
let battery_state = board
.board_hal
.get_battery_monitor()
.get_state()
.await?;
Ok(Some(serde_json::to_string(&battery_state)?))
}

View File

@@ -4,8 +4,7 @@ use crate::BOARD_ACCESS;
use edge_http::io::server::Connection;
use edge_http::Method;
use edge_nal::io::{Read, Write};
use esp_hal_ota::OtaError;
use log::{error, info};
use log::info;
pub(crate) async fn ota_operations<T, const N: usize>(
conn: &mut Connection<'_, T, { N }>,
@@ -29,45 +28,27 @@ where
Some(200)
}
Method::Post => {
let size = read_up_to_bytes_from_request(conn, Some(4)).await?;
let flash_size = u32::from_le_bytes(size[..4].try_into().unwrap());
info!("flash size: {flash_size}");
let crc32 = read_up_to_bytes_from_request(conn, Some(4)).await?;
let target_crc = u32::from_le_bytes(crc32[..4].try_into().unwrap());
info!("crc32: {target_crc}");
BOARD_ACCESS
.get()
.await
.lock()
.await
.board_hal
.get_esp()
.ota
.ota_begin(flash_size, target_crc)?;
let mut offset = 0_usize;
let mut chunk = 0;
loop {
let buf = read_up_to_bytes_from_request(conn, Some(4096)).await?;
if buf.is_empty() {
error!("Upload finished, but no enough data received.");
return Err(OtaError::WrongCRC)?;
info!("file request for ota finished");
let mut board = BOARD_ACCESS.get().await.lock().await;
board.board_hal.get_esp().finalize_ota().await?;
break;
} else {
let mut board = BOARD_ACCESS.get().await.lock().await;
board.board_hal.progress(chunk as u32).await;
// Erase next block if we are at a 4K boundary (including the first block at offset 0)
let finsihed = board.board_hal.get_esp().ota.ota_write_chunk(&buf)?;
if finsihed {
board.board_hal.get_esp().ota.ota_flush(true, true)?;
board.board_hal.get_esp().set_restart_to_conf(true);
break;
}
info!(
"Progress: {}%",
(board.board_hal.get_esp().ota.get_ota_progress() * 100.0) as u8
);
info!("erasing and writing block 0x{offset:x}");
board
.board_hal
.get_esp()
.write_ota(offset as u32, &buf)
.await?;
}
offset += buf.len();
chunk += 1;
}
BOARD_ACCESS

View File

@@ -1,6 +1,6 @@
use crate::config::PlantControllerConfig;
use crate::fat_error::FatResult;
use crate::hal::{esp_set_time, Detection};
use crate::hal::{esp_set_time, Detection, DetectionRequest};
use crate::webserver::read_up_to_bytes_from_request;
use crate::{do_secure_pump, BOARD_ACCESS};
use alloc::string::{String, ToString};
@@ -142,6 +142,9 @@ where
board.board_hal.can_power(can_power_request.state).await?;
let enable = can_power_request.state;
info!("set can power to {enable}");
info!(
"set can power to {enable}"
);
Ok(None)
}