From ec42c6f87079a8f1f43aef18aaf1b4cb2d61ca21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bo=CC=88hm?= Date: Sat, 7 Dec 2024 20:21:41 +0100 Subject: [PATCH] WIP --- include/SerialPortManager.h | 8 +++--- src/WebApi_sysstatus.cpp | 10 +++++++ webapp/src/components/SerialPortUsage.vue | 33 +++++++++++++++++++++++ webapp/src/types/SystemStatus.ts | 7 +++++ webapp/src/views/SystemInfoView.vue | 4 +++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 webapp/src/components/SerialPortUsage.vue diff --git a/include/SerialPortManager.h b/include/SerialPortManager.h index 372b9c50f..c43b7e39b 100644 --- a/include/SerialPortManager.h +++ b/include/SerialPortManager.h @@ -5,17 +5,19 @@ #include #include +// the amount of hardare UARTs available on supported ESP32 chips +#define NUM_CONTROLLERS 3 + class SerialPortManagerClass { public: void init(); std::optional allocatePort(std::string const& owner); void freePort(std::string const& owner); + std::array getPorts() const { return _ports; } private: - // the amount of hardare UARTs available on supported ESP32 chips - static size_t constexpr _num_controllers = 3; - std::array _ports = { "" }; + std::array _ports = { "" }; }; extern SerialPortManagerClass SerialPortManager; diff --git a/src/WebApi_sysstatus.cpp b/src/WebApi_sysstatus.cpp index fcb8a5349..da5b70dfa 100644 --- a/src/WebApi_sysstatus.cpp +++ b/src/WebApi_sysstatus.cpp @@ -8,6 +8,7 @@ #include "PinMapping.h" #include "WebApi.h" #include "__compiled_constants.h" +#include "SerialPortManager.h" #include #include #include @@ -92,5 +93,14 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request) root["cmt_configured"] = PinMapping.isValidCmt2300Config(); root["cmt_connected"] = Hoymiles.getRadioCmt()->isConnected(); + JsonArray serialPortUsage = root["serial_port_usage"].to(); + auto serialPorts = SerialPortManager.getPorts(); + + for (size_t i = 0; i < serialPorts.size(); ++i) { + JsonObject port = serialPortUsage.add(); + port["port"] = i; + port["owner"] = serialPorts[i]; //TODO(andreasboehm): This is always empty, why? + } + WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); } diff --git a/webapp/src/components/SerialPortUsage.vue b/webapp/src/components/SerialPortUsage.vue new file mode 100644 index 000000000..e00a8c82a --- /dev/null +++ b/webapp/src/components/SerialPortUsage.vue @@ -0,0 +1,33 @@ + + + diff --git a/webapp/src/types/SystemStatus.ts b/webapp/src/types/SystemStatus.ts index 4262cb06d..495267b95 100644 --- a/webapp/src/types/SystemStatus.ts +++ b/webapp/src/types/SystemStatus.ts @@ -4,6 +4,11 @@ export interface TaskDetail { priority: number; } +export interface SerialPortDetail { + 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; + // SerialPortUsage + serial_port_usage: SerialPortDetail[]; } diff --git a/webapp/src/views/SystemInfoView.vue b/webapp/src/views/SystemInfoView.vue index 8742383a1..a5aab0795 100644 --- a/webapp/src/views/SystemInfoView.vue +++ b/webapp/src/views/SystemInfoView.vue @@ -10,6 +10,8 @@
+ +
@@ -22,6 +24,7 @@ import HardwareInfo from '@/components/HardwareInfo.vue'; import MemoryInfo from '@/components/MemoryInfo.vue'; import HeapDetails from '@/components/HeapDetails.vue'; import TaskDetails from '@/components/TaskDetails.vue'; +import SerialPortUsage from '@/components/SerialPortUsage.vue'; import RadioInfo from '@/components/RadioInfo.vue'; import type { SystemStatus } from '@/types/SystemStatus'; import { authHeader, handleResponse } from '@/utils/authentication'; @@ -35,6 +38,7 @@ export default defineComponent({ MemoryInfo, HeapDetails, TaskDetails, + SerialPortUsage, RadioInfo, }, data() {