fix upload

# Conflicts:
#	rust/src/webserver/webserver.rs
This commit is contained in:
2024-08-12 21:17:16 +02:00
parent ca26f090fa
commit 7415e74643
4 changed files with 23 additions and 22 deletions

View File

@@ -1078,7 +1078,7 @@ impl CreatePlantHal<'_> for PlantHal {
let config = I2cConfig::new()
.scl_enable_pullup(true)
.sda_enable_pullup(true)
.baudrate(1_u32.kHz().into())
.baudrate(400_u32.kHz().into())
.timeout(APBTickType::from(Duration::from_millis(100)));
let scl = peripherals.pins.gpio19.downgrade();
let sda = peripherals.pins.gpio20.downgrade();

View File

@@ -295,7 +295,7 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
server
.fn_handler("/flashbattery", Method::Post, move |mut request| {
let mut board = BOARD_ACCESS.lock().unwrap();
let mut buffer: [u8; 32] = [0; 32];
let mut buffer: [u8; 128] = [0; 128];
let mut line_buffer: VecDeque<u8> = VecDeque::new();
let is_dry_run = !request.uri().ends_with("?flash=true");
@@ -307,7 +307,6 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
delay.delay_us(2);
let read = request.read(&mut buffer).unwrap();
total_read += read;
println!("received {read} bytes ota {total_read}");
if read == 0 {
if line_buffer.len() > 0 {
println!("No further body but no endline");
@@ -323,29 +322,28 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
break;
}
let to_write = &buffer[0..read];
line_buffer.write_all(to_write).unwrap();
println!("Write to deque new lenght is {}", line_buffer.len());
board.general_fault(toggle);
toggle = !toggle;
println!("Updated btn");
loop {
println!("Check for line");
let has_line = line_buffer.contains(&b'\n');
if has_line {
println!("Was no line no string read");
if !has_line {
break;
}
let mut line = std::string::String::new();
let line_size = line_buffer.read_line(&mut line)?;
println!("Processing line with size {} {}", line_size, line);
let validate = board.flash_bq34_z100(&line, is_dry_run);
line_buffer.read_line(&mut line)?;
let line2 = &line[0..line.len()-1];
println!("Processing dry:{} line {}", is_dry_run, line2);
let validate = board.flash_bq34_z100(&line2, is_dry_run);
delay.delay_us(2);
if validate.is_err() {
let mut response = request.into_status_response(400_u16).unwrap();
let err = validate.unwrap_err();
let err_str = err.to_string();
let err_msg = err_str.as_bytes();
println!("Error writing {}", err_str);
response
.write(err_msg)
.unwrap();

View File

@@ -33,6 +33,9 @@ ajax.addEventListener("abort", () => {
battery_flash_button.onclick = async function (){
ajax.open("POST", "/flashbattery");
//ajax.open("POST", "/flashbattery");
//ajax.send(battery_flash_file.files[0]);
ajax.open("POST", "/flashbattery?flash=true");
ajax.send(battery_flash_file.files[0]);
};