Fix ota, use MMU to determine running partition, use RMW wrapper for ota_data partition (littelfs handles this internally, so it was no problem prior)
This commit is contained in:
@@ -29,8 +29,8 @@ use ::log::{error, info, warn};
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::sync::Arc;
|
||||
use alloc::{format, vec};
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{format, vec};
|
||||
use chrono::{DateTime, Datelike, Timelike, Utc};
|
||||
use chrono_tz::Tz::{self, UTC};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -501,16 +501,17 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
|
||||
info!("state of charg");
|
||||
let is_day = board.board_hal.is_day();
|
||||
let battery_state = board.board_hal.get_battery_monitor().get_state().await.unwrap_or(BatteryState::Unknown);
|
||||
let battery_state = board
|
||||
.board_hal
|
||||
.get_battery_monitor()
|
||||
.get_state()
|
||||
.await
|
||||
.unwrap_or(BatteryState::Unknown);
|
||||
info!("Battery state is {battery_state:?}");
|
||||
|
||||
let state_of_charge = match &battery_state {
|
||||
BatteryState::Unknown => {
|
||||
0
|
||||
}
|
||||
BatteryState::Info(data) => {
|
||||
data.state_of_charge
|
||||
}
|
||||
BatteryState::Unknown => 0,
|
||||
BatteryState::Info(data) => data.state_of_charge,
|
||||
};
|
||||
|
||||
let mut light_state = LightState {
|
||||
@@ -529,22 +530,10 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
board.board_hal.get_config().night_lamp.night_lamp_hour_end,
|
||||
);
|
||||
|
||||
if state_of_charge
|
||||
< board
|
||||
.board_hal
|
||||
.get_config()
|
||||
.night_lamp
|
||||
.low_soc_cutoff
|
||||
{
|
||||
if state_of_charge < board.board_hal.get_config().night_lamp.low_soc_cutoff {
|
||||
board.board_hal.get_esp().set_low_voltage_in_cycle();
|
||||
info!("Set low voltage in cycle");
|
||||
} else if state_of_charge
|
||||
> board
|
||||
.board_hal
|
||||
.get_config()
|
||||
.night_lamp
|
||||
.low_soc_restore
|
||||
{
|
||||
} else if state_of_charge > board.board_hal.get_config().night_lamp.low_soc_restore {
|
||||
board.board_hal.get_esp().clear_low_voltage_in_cycle();
|
||||
info!("Clear low voltage in cycle");
|
||||
}
|
||||
@@ -793,7 +782,7 @@ pub async fn do_secure_pump(
|
||||
|
||||
async fn update_charge_indicator(
|
||||
board: &mut MutexGuard<'static, CriticalSectionRawMutex, HAL<'static>>,
|
||||
) -> FatResult<()>{
|
||||
) -> FatResult<()> {
|
||||
//FIXME add config and code to allow power supply mode, in this case this is a nop
|
||||
//we have mppt controller, ask it for charging current
|
||||
let current = board.board_hal.get_mptt_current().await?;
|
||||
@@ -801,10 +790,9 @@ async fn update_charge_indicator(
|
||||
.board_hal
|
||||
.set_charge_indicator(current.as_milliamperes() > 20_f64)
|
||||
.await?;
|
||||
Ok(())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
async fn publish_tank_state(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'static>>,
|
||||
tank_state: &TankState,
|
||||
@@ -984,11 +972,7 @@ async fn publish_mppt_state(
|
||||
async fn publish_battery_state(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'static>>,
|
||||
) -> () {
|
||||
let state = board
|
||||
.board_hal
|
||||
.get_battery_monitor()
|
||||
.get_state()
|
||||
.await;
|
||||
let state = board.board_hal.get_battery_monitor().get_state().await;
|
||||
let value = match state {
|
||||
Ok(state) => {
|
||||
let json = serde_json::to_string(&state).unwrap().to_owned();
|
||||
@@ -1021,7 +1005,7 @@ async fn wait_infinity(
|
||||
loop {
|
||||
{
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
match update_charge_indicator(&mut board).await{
|
||||
match update_charge_indicator(&mut board).await {
|
||||
Ok(_) => {}
|
||||
Err(error) => {
|
||||
if !suppress_further_mppt_error {
|
||||
@@ -1104,35 +1088,38 @@ async fn wait_infinity(
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_serial_config(board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'_>>, serial_config_receive: &AtomicBool, reboot_now: &AtomicBool) -> FatResult<()> {
|
||||
async fn handle_serial_config(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'_>>,
|
||||
serial_config_receive: &AtomicBool,
|
||||
reboot_now: &AtomicBool,
|
||||
) -> FatResult<()> {
|
||||
match board.board_hal.get_esp().read_serial_line().await {
|
||||
Ok(serial_line) => {
|
||||
match serial_line {
|
||||
None => {
|
||||
Ok(serial_line) => match serial_line {
|
||||
None => Ok(()),
|
||||
Some(line) => {
|
||||
if serial_config_receive.load(Ordering::Relaxed) {
|
||||
let ll = line.as_str();
|
||||
let config: PlantControllerConfig = serde_json::from_str(ll)?;
|
||||
board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.save_config(Vec::from(ll.as_bytes()))
|
||||
.await?;
|
||||
board.board_hal.set_config(config);
|
||||
serial_config_receive.store(false, Ordering::Relaxed);
|
||||
info!("Config received, rebooting");
|
||||
board.board_hal.get_esp().set_restart_to_conf(false);
|
||||
reboot_now.store(true, Ordering::Relaxed);
|
||||
Ok(())
|
||||
} else {
|
||||
if line == "automation:streamconfig" {
|
||||
serial_config_receive.store(true, Ordering::Relaxed);
|
||||
info!("streamconfig:recieving");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Some(line) => {
|
||||
if serial_config_receive.load(Ordering::Relaxed) {
|
||||
let ll = line.as_str();
|
||||
let config: PlantControllerConfig = serde_json::from_str(ll)?;
|
||||
board.board_hal.get_esp().save_config(Vec::from(ll.as_bytes())).await?;
|
||||
board.board_hal.set_config(config);
|
||||
serial_config_receive.store(false, Ordering::Relaxed);
|
||||
info!("Config received, rebooting");
|
||||
board.board_hal.get_esp().set_restart_to_conf(false);
|
||||
reboot_now.store(true, Ordering::Relaxed);
|
||||
Ok(())
|
||||
} else {
|
||||
if line == "automation:streamconfig" {
|
||||
serial_config_receive.store(true, Ordering::Relaxed);
|
||||
info!("streamconfig:recieving");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
error!("Error reading serial line");
|
||||
Ok(())
|
||||
@@ -1158,7 +1145,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
}
|
||||
}
|
||||
println!("Hal init done, starting logic");
|
||||
|
||||
panic!("test");
|
||||
match safe_main(spawner).await {
|
||||
// this should not get triggered, safe_main should not return but go into deep sleep or reboot
|
||||
Ok(_) => {
|
||||
|
||||
Reference in New Issue
Block a user