diff --git a/Software/MainBoard/rust/src/main.rs b/Software/MainBoard/rust/src/main.rs index 33e45dc..d86bb12 100644 --- a/Software/MainBoard/rust/src/main.rs +++ b/Software/MainBoard/rust/src/main.rs @@ -1327,12 +1327,17 @@ async fn get_version( let hash = &env!("VERGEN_GIT_SHA")[0..8]; let board = board.board_hal.get_esp(); + let heap = esp_alloc::HEAP.stats(); VersionInfo { git_hash: branch + "@" + hash, build_time: env!("VERGEN_BUILD_TIMESTAMP").to_owned(), current: format!("{:?}", board.current), slot0_state: format!("{:?}", board.slot0_state), slot1_state: format!("{:?}", board.slot1_state), + heap_total: heap.size, + heap_used: heap.current_usage, + heap_free: heap.size.saturating_sub(heap.current_usage), + heap_max_used: heap.max_usage, } } @@ -1343,4 +1348,8 @@ struct VersionInfo { current: String, slot0_state: String, slot1_state: String, + heap_total: usize, + heap_used: usize, + heap_free: usize, + heap_max_used: usize, } diff --git a/Software/MainBoard/rust/src/webserver/get_json.rs b/Software/MainBoard/rust/src/webserver/get_json.rs index d07c44f..e565a36 100644 --- a/Software/MainBoard/rust/src/webserver/get_json.rs +++ b/Software/MainBoard/rust/src/webserver/get_json.rs @@ -109,7 +109,7 @@ pub(crate) async fn get_solar_state( Ok(Some(serde_json::to_string(&state)?)) } -pub(crate) async fn get_version_web( +pub(crate) async fn get_firmware_info_web( _request: &mut Connection<'_, T, N>, ) -> FatResult> { let mut board = BOARD_ACCESS.get().await.lock().await; diff --git a/Software/MainBoard/rust/src/webserver/mod.rs b/Software/MainBoard/rust/src/webserver/mod.rs index 5bb31e2..2faa6bb 100644 --- a/Software/MainBoard/rust/src/webserver/mod.rs +++ b/Software/MainBoard/rust/src/webserver/mod.rs @@ -11,7 +11,7 @@ use crate::fat_error::{FatError, FatResult}; use crate::webserver::backup_manager::{backup_config, backup_info, get_backup_config}; use crate::webserver::get_json::{ delete_save, get_battery_state, get_config, get_live_moisture, get_log_localization_config, - get_solar_state, get_time, get_timezones, get_version_web, list_saves, tank_info, + get_firmware_info_web, get_solar_state, get_time, get_timezones, list_saves, tank_info, }; use crate::webserver::get_log::{get_live_log, get_log}; use crate::webserver::get_static::{serve_bundle, serve_favicon, serve_index}; @@ -73,7 +73,7 @@ impl Handler for HTTPRequestRouter { "/get_backup_config" => get_backup_config(conn).await?, &_ => { let json = match path { - "/version" => Some(get_version_web(conn).await), + "/firmware_info" => Some(get_firmware_info_web(conn).await), "/time" => Some(get_time(conn).await), "/battery" => Some(get_battery_state(conn).await), "/solar" => Some(get_solar_state(conn).await), diff --git a/Software/MainBoard/rust/src_webpack/src/api.ts b/Software/MainBoard/rust/src_webpack/src/api.ts index dbe8601..a080cbf 100644 --- a/Software/MainBoard/rust/src_webpack/src/api.ts +++ b/Software/MainBoard/rust/src_webpack/src/api.ts @@ -183,6 +183,10 @@ export interface VersionInfo { current: string, slot0_state: string, slot1_state: string, + heap_total: number, + heap_used: number, + heap_free: number, + heap_max_used: number, } export interface BatteryState { diff --git a/Software/MainBoard/rust/src_webpack/src/main.ts b/Software/MainBoard/rust/src_webpack/src/main.ts index 79dcf0c..388e639 100644 --- a/Software/MainBoard/rust/src_webpack/src/main.ts +++ b/Software/MainBoard/rust/src_webpack/src/main.ts @@ -194,7 +194,7 @@ export class Controller { async version(): Promise { controller.progressview.addIndeterminate("version", "Getting buildVersion") - const response = await fetch(PUBLIC_URL + "/version"); + const response = await fetch(PUBLIC_URL + "/firmware_info"); const json = await response.json(); const versionInfo = json as VersionInfo; controller.progressview.removeProgress("version"); @@ -499,7 +499,7 @@ export class Controller { waitForReboot() { console.log("Check if controller online again") - fetch(PUBLIC_URL + "/version", { + fetch(PUBLIC_URL + "/firmware_info", { method: "GET", signal: AbortSignal.timeout(5000) }).then(response => { diff --git a/Software/MainBoard/rust/src_webpack/src/ota.html b/Software/MainBoard/rust/src_webpack/src/ota.html index 0d18370..9c95f8e 100644 --- a/Software/MainBoard/rust/src_webpack/src/ota.html +++ b/Software/MainBoard/rust/src_webpack/src/ota.html @@ -21,6 +21,7 @@
Current Firmware
+
Buildtime: @@ -42,12 +43,35 @@ State1:
-

+
+
+ Heap Memory +
+
+
+
+ Free: + +
+
+ Used: + +
+
+ Total: + +
+
+ Peak used: + +
+ +
\ No newline at end of file diff --git a/Software/MainBoard/rust/src_webpack/src/ota.ts b/Software/MainBoard/rust/src_webpack/src/ota.ts index c407932..b7c6f69 100644 --- a/Software/MainBoard/rust/src_webpack/src/ota.ts +++ b/Software/MainBoard/rust/src_webpack/src/ota.ts @@ -1,6 +1,10 @@ import {Controller} from "./main"; import {VersionInfo} from "./api"; +function fmtBytes(n: number): string { + return `${n} B (${(n / 1024).toFixed(1)} KiB)`; +} + export class OTAView { readonly file1Upload: HTMLInputElement; readonly firmware_buildtime: HTMLDivElement; @@ -8,19 +12,26 @@ export class OTAView { readonly firmware_partition: HTMLDivElement; readonly firmware_state0: HTMLDivElement; readonly firmware_state1: HTMLDivElement; + readonly heap_free: HTMLDivElement; + readonly heap_used: HTMLDivElement; + readonly heap_total: HTMLDivElement; + readonly heap_max_used: HTMLDivElement; constructor(controller: Controller) { (document.getElementById("firmwareview") as HTMLElement).innerHTML = require("./ota.html") let test = document.getElementById("test") as HTMLButtonElement; + let refresh = document.getElementById("refresh_firmware_info") as HTMLButtonElement; this.firmware_buildtime = document.getElementById("firmware_buildtime") as HTMLDivElement; this.firmware_githash = document.getElementById("firmware_githash") as HTMLDivElement; this.firmware_partition = document.getElementById("firmware_partition") as HTMLDivElement; - this.firmware_state0 = document.getElementById("firmware_state0") as HTMLDivElement; this.firmware_state1 = document.getElementById("firmware_state1") as HTMLDivElement; - + this.heap_free = document.getElementById("heap_free") as HTMLDivElement; + this.heap_used = document.getElementById("heap_used") as HTMLDivElement; + this.heap_total = document.getElementById("heap_total") as HTMLDivElement; + this.heap_max_used = document.getElementById("heap_max_used") as HTMLDivElement; const file = document.getElementById("firmware_file") as HTMLInputElement; this.file1Upload = file @@ -36,6 +47,10 @@ export class OTAView { test.onclick = () => { controller.selfTest(); } + + refresh.onclick = () => { + controller.version(); + } } setVersion(versionInfo: VersionInfo) { @@ -44,5 +59,9 @@ export class OTAView { this.firmware_partition.innerText = versionInfo.current; this.firmware_state0.innerText = versionInfo.slot0_state; this.firmware_state1.innerText = versionInfo.slot1_state; + this.heap_free.innerText = fmtBytes(versionInfo.heap_free); + this.heap_used.innerText = fmtBytes(versionInfo.heap_used); + this.heap_total.innerText = fmtBytes(versionInfo.heap_total); + this.heap_max_used.innerText = fmtBytes(versionInfo.heap_max_used); } } \ No newline at end of file