eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 616d58d4adb0a51c9b3a9f710501c9a7a2dee3a2
parent 35e0aeb88b7de4ed258927b4a71742236e99454c
Author: filipton <filipton12@gmail.com>
Date:   Thu,  4 Jul 2024 21:39:47 +0200

feat: print progress in %

Diffstat:
Mexamples/src/main.rs | 16+++++++++-------
Msimple-ota-server/firmware.bin | 0
Msimple-ota-server/src/main.rs | 2+-
Msrc/lib.rs | 8++++----
4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/examples/src/main.rs b/examples/src/main.rs @@ -5,7 +5,7 @@ use core::str::FromStr; use embassy_executor::Spawner; use embassy_net::{tcp::TcpSocket, Config, Stack, StackResources}; -use embassy_time::{Duration, Instant, Timer}; +use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, peripherals::Peripherals, prelude::*, system::SystemControl, @@ -39,7 +39,7 @@ async fn main(spawner: Spawner) { esp_println::logger::init_logger_from_env(); log::set_max_level(log::LevelFilter::Info); - let mut rng = esp_hal::rng::Rng::new(peripherals.RNG); + let rng = esp_hal::rng::Rng::new(peripherals.RNG); let timer = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks, None); let init = esp_wifi::initialize( esp_wifi::EspWifiInitFor::Wifi, @@ -92,7 +92,7 @@ async fn main(spawner: Spawner) { let ip = embassy_net::IpEndpoint::from_str(OTA_SERVER_IP).expect("Wrong ip addr"); socket.connect(ip).await.expect("Cannot connect!"); - let mut ota_buff = [0; 4096]; + let mut ota_buff = [0; 4096 * 2]; socket .read(&mut ota_buff[..4]) .await @@ -103,19 +103,20 @@ async fn main(spawner: Spawner) { let mut ota = Ota::new(FlashStorage::new()).with_next_partition_offset(); ota.set_flash_size(flash_size); + let mut bytes_read = 0; loop { let res = socket.read(&mut ota_buff).await; if let Ok(n) = res { + bytes_read += n; if n == 0 { break; } - let start = Instant::now(); let res = ota.ota_write_chunk(&ota_buff[..n]); - log::info!("ota_write_res: {:?}", res); - log::info!("Elapsed: {}", start.elapsed().as_micros()); + if bytes_read % 4096 * 2 == 0 { + _ = socket.write(&[0]).await; + } - _ = socket.write(&[0]).await; if res == Ok(true) { _ = ota.ota_flush(); break; @@ -123,6 +124,7 @@ async fn main(spawner: Spawner) { } Timer::after_millis(10).await; + log::info!("Progress: {}%", (ota.get_ota_progress() * 100.0) as u8); } loop { diff --git a/simple-ota-server/firmware.bin b/simple-ota-server/firmware.bin Binary files differ. diff --git a/simple-ota-server/src/main.rs b/simple-ota-server/src/main.rs @@ -15,7 +15,7 @@ fn main() { let buf = (BINARY.len() as u32).to_le_bytes(); _ = stream.write_all(&buf); - let chunks = BINARY.chunks(1024); + let chunks = BINARY.chunks(4096 * 2); let mut buf = [0; 1]; for chunk in chunks { println!("Writing: {}", chunk.len()); diff --git a/src/lib.rs b/src/lib.rs @@ -72,7 +72,7 @@ where /// Writes next firmware chunk pub fn ota_write_chunk(&mut self, chunk: &[u8]) -> Result<bool, ()> { if self.flash_size == 0 { - log::error!("Cant write chunk without set_flash_size()"); + log::error!("[OTA] Cant write chunk without set_flash_size()"); return Err(()); } @@ -88,8 +88,8 @@ where .write(*ota_offset, &chunk[..write_size]) .map_err(|_| ())?; - log::info!( - "Wrote {} bytes to ota partition at 0x{:x}", + log::debug!( + "[OTA] Wrote {} bytes to ota partition at 0x{:x}", write_size, ota_offset ); @@ -104,7 +104,7 @@ where if let Some(target_partition) = self.target_partition { self.set_target_ota_boot_partition(target_partition); } - + Ok(()) }