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

@@ -11,7 +11,7 @@ use crate::hal::{
};
use crate::log::{LogMessage, LOG_ACCESS};
use alloc::boxed::Box;
use alloc::string::ToString;
use alloc::string::{ToString};
use async_trait::async_trait;
use canapi::id::{classify, plant_id, MessageKind, IDENTIFY_CMD_OFFSET};
use canapi::SensorSlot;
@@ -23,6 +23,7 @@ use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig, Pull}
use esp_hal::i2c::master::I2c;
use esp_hal::twai::{EspTwaiError, EspTwaiFrame, StandardId, Twai, TwaiConfiguration, TwaiMode};
use esp_hal::{twai, Async, Blocking};
use esp_println::println;
use ina219::address::{Address, Pin};
use ina219::calibration::UnCalibrated;
use ina219::configuration::{Configuration, OperatingMode, Resolution};
@@ -132,9 +133,10 @@ pub struct V4<'a> {
extra1: Output<'a>,
extra2: Output<'a>,
twai_config: Option<TwaiConfiguration<'static, Blocking>>,
twai_config: Option<TwaiConfiguration<'static, Blocking>>
}
pub(crate) async fn create_v4(
peripherals: FreePeripherals<'static>,
esp: Esp<'static>,
@@ -261,11 +263,12 @@ pub(crate) async fn create_v4(
extra1,
extra2,
can_power,
twai_config,
twai_config
};
Ok(Box::new(v))
}
#[async_trait(?Send)]
impl<'a> BoardInteraction<'a> for V4<'a> {
fn get_tank_sensor(&mut self) -> Result<&mut TankSensor<'a>, FatError> {
@@ -392,18 +395,11 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
if !detect {
continue;
}
let target = StandardId::new(plant_id(
IDENTIFY_CMD_OFFSET,
sensor.into(),
(plant + 1) as u16,
))
.context(">> Could not create address for sensor! (plant: {}) <<")?;
let target =
StandardId::new(plant_id(IDENTIFY_CMD_OFFSET, sensor.into(), (plant +1) as u16))
.context(">> Could not create address for sensor! (plant: {}) <<")?;
let can_buffer = [0_u8; 0];
info!(
"Sending test message to plant {} sensor {sensor:?} with id {}",
plant + 1,
target.as_raw()
);
info!("Sending test message to plant {} sensor {sensor:?} with id {}", plant +1, target.as_raw());
if let Some(frame) = EspTwaiFrame::new(target, &can_buffer) {
// Try a few times; we intentionally ignore rx here and rely on stub logic
let resu = twai
@@ -411,12 +407,12 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
.with_timeout(Duration::from_millis(3000))
.await;
match resu {
Ok(_) => {}
Ok(_) => {
}
Err(err) => {
info!(
"Error sending test message to plant {} sensor {sensor:?}: {err:?}",
plant + 1
);
"Error sending test message to plant {} sensor {sensor:?}: {err:?}", plant +1
);
}
}
} else {
@@ -430,17 +426,20 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
.with_timeout(Duration::from_millis(3000))
.await;
let config = twai.stop().into_blocking();
self.twai_config.replace(config);
self.can_power.set_low();
let result = moistures.into();
info!("Autodetection result: {result:?}");
Ok(result)
}
async fn general_fault(&mut self, enable: bool) {
hold_disable(23);
self.general_fault.set_level(enable.into());
@@ -483,7 +482,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
LOG_ACCESS
.lock()
.await
.log(LogMessage::TestSensor, a, b, &(plant + 1).to_string(), "")
.log(LogMessage::TestSensor, a, b, &(plant+1).to_string(), "")
.await;
}
Timer::after_millis(10).await;
@@ -512,6 +511,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
}
}
async fn wait_for_can_measurements(
as_async: &mut Twai<'_, Async>,
moistures: &mut Moistures,
@@ -538,12 +538,10 @@ async fn wait_for_can_measurements(
let frequency = u32::from_be_bytes(bytes);
match sensor {
SensorSlot::A => {
moistures.sensor_a_hz[plant - 1] =
Some(frequency as f32);
moistures.sensor_a_hz[plant-1] = Some(frequency as f32);
}
SensorSlot::B => {
moistures.sensor_b_hz[plant - 1] =
Some(frequency as f32);
moistures.sensor_b_hz[plant-1] = Some(frequency as f32);
}
}
} else {