From dbb3421270fbb052f07355fc57d494d690d06876 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 6 Dec 2024 16:11:53 +0100 Subject: [PATCH] Feature: webapp: show hardware UART allocations --- include/SerialPortManager.h | 7 ++++ src/SerialPortManager.cpp | 13 +++++++ src/WebApi_sysstatus.cpp | 8 ++++ webapp/src/components/UartAllocations.vue | 45 +++++++++++++++++++++++ webapp/src/locales/de.json | 7 ++++ webapp/src/locales/en.json | 7 ++++ webapp/src/locales/fr.json | 7 ++++ webapp/src/types/SystemStatus.ts | 7 ++++ webapp/src/views/SystemInfoView.vue | 3 ++ 9 files changed, 104 insertions(+) create mode 100644 webapp/src/components/UartAllocations.vue diff --git a/include/SerialPortManager.h b/include/SerialPortManager.h index 372b9c50f..444de133b 100644 --- a/include/SerialPortManager.h +++ b/include/SerialPortManager.h @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include class SerialPortManagerClass { public: @@ -12,10 +15,14 @@ class SerialPortManagerClass { std::optional allocatePort(std::string const& owner); void freePort(std::string const& owner); + using allocations_t = std::vector>; + allocations_t getAllocations() const; + private: // the amount of hardare UARTs available on supported ESP32 chips static size_t constexpr _num_controllers = 3; std::array _ports = { "" }; + std::set _rejects; }; extern SerialPortManagerClass SerialPortManager; diff --git a/src/SerialPortManager.cpp b/src/SerialPortManager.cpp index fbcc7f036..27a22912d 100644 --- a/src/SerialPortManager.cpp +++ b/src/SerialPortManager.cpp @@ -32,6 +32,7 @@ std::optional SerialPortManagerClass::allocatePort(std::string const& o MessageOutput.printf("[SerialPortManager] Cannot assign another HW " "UART port to '%s'\r\n", owner.c_str()); + _rejects.insert(owner); return std::nullopt; } @@ -45,3 +46,15 @@ void SerialPortManagerClass::freePort(std::string const& owner) _ports[i] = ""; } } + +SerialPortManagerClass::allocations_t SerialPortManagerClass::getAllocations() const +{ + allocations_t res; + for (int8_t i = 0; i < _ports.size(); ++i) { + res.push_back({i, _ports[i]}); + } + for (auto const& reject : _rejects) { + res.push_back({-1, reject}); + } + return res; +} diff --git a/src/WebApi_sysstatus.cpp b/src/WebApi_sysstatus.cpp index fcb8a5349..0266e37e6 100644 --- a/src/WebApi_sysstatus.cpp +++ b/src/WebApi_sysstatus.cpp @@ -6,6 +6,7 @@ #include "Configuration.h" #include "NetworkSettings.h" #include "PinMapping.h" +#include "SerialPortManager.h" #include "WebApi.h" #include "__compiled_constants.h" #include @@ -92,5 +93,12 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request) root["cmt_configured"] = PinMapping.isValidCmt2300Config(); root["cmt_connected"] = Hoymiles.getRadioCmt()->isConnected(); + JsonArray uarts = root["uarts"].to(); + for (auto const& allocation : SerialPortManager.getAllocations()) { + JsonObject uart = uarts.add(); + uart["port"] = allocation.first; + uart["owner"] = allocation.second; + } + WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); } diff --git a/webapp/src/components/UartAllocations.vue b/webapp/src/components/UartAllocations.vue new file mode 100644 index 000000000..877ff08c1 --- /dev/null +++ b/webapp/src/components/UartAllocations.vue @@ -0,0 +1,45 @@ + + + diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 817dfec61..e4cdfab97 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -326,6 +326,13 @@ "NotConfigured": "nicht konfiguriert", "Unknown": "unbekannt" }, + "uartallocations": { + "Allocations": "Zuteilung Serieller Hardwareschnittstellen", + "Owner": "Komponente", + "Port": "Zugeteilte Schnittstelle", + "Free": "(Noch Verfügbar)", + "Rejected": "Keine Schnittstelle verfügbar" + }, "networkinfo": { "NetworkInformation": "Netzwerkinformationen" }, diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 5abfb2fc0..a2d38d2e6 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -327,6 +327,13 @@ "NotConfigured": "not configured", "Unknown": "Unknown" }, + "uartallocations": { + "Allocations": "Serial Hardware Interface Allocations", + "Owner": "Component", + "Port": "Allocated Port", + "Free": "(Still Available)", + "Rejected": "No UART available" + }, "networkinfo": { "NetworkInformation": "Network Information" }, diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index 3d44a4c26..e2bf6dca5 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -343,6 +343,13 @@ "NotConfigured": "non configurée", "Unknown": "Inconnue" }, + "uartallocations": { + "Allocations": "Serial Hardware Interface Allocations", + "Owner": "Component", + "Port": "Allocated Port", + "Free": "(Still Available)", + "Rejected": "No UART available" + }, "networkinfo": { "NetworkInformation": "Informations sur le réseau" }, diff --git a/webapp/src/types/SystemStatus.ts b/webapp/src/types/SystemStatus.ts index 4262cb06d..52c90d4b8 100644 --- a/webapp/src/types/SystemStatus.ts +++ b/webapp/src/types/SystemStatus.ts @@ -4,6 +4,11 @@ export interface TaskDetail { priority: number; } +export interface UartAllocation { + port: number; + owner: string; +} + export interface SystemStatus { // HardwareInfo chipmodel: string; @@ -47,4 +52,6 @@ export interface SystemStatus { nrf_pvariant: boolean; cmt_configured: boolean; cmt_connected: boolean; + // UARTs + uarts: UartAllocation[]; } diff --git a/webapp/src/views/SystemInfoView.vue b/webapp/src/views/SystemInfoView.vue index 8742383a1..bea00d99a 100644 --- a/webapp/src/views/SystemInfoView.vue +++ b/webapp/src/views/SystemInfoView.vue @@ -12,6 +12,7 @@
+ @@ -23,6 +24,7 @@ import MemoryInfo from '@/components/MemoryInfo.vue'; import HeapDetails from '@/components/HeapDetails.vue'; import TaskDetails from '@/components/TaskDetails.vue'; import RadioInfo from '@/components/RadioInfo.vue'; +import UartAllocations from '@/components/UartAllocations.vue'; import type { SystemStatus } from '@/types/SystemStatus'; import { authHeader, handleResponse } from '@/utils/authentication'; import { defineComponent } from 'vue'; @@ -36,6 +38,7 @@ export default defineComponent({ HeapDetails, TaskDetails, RadioInfo, + UartAllocations, }, data() { return {