Skip to content

Commit

Permalink
Feature: webapp: show hardware UART allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Dec 7, 2024
1 parent 7f62362 commit dbb3421
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/SerialPortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <array>
#include <optional>
#include <string>
#include <vector>
#include <utility>
#include <set>

class SerialPortManagerClass {
public:
Expand All @@ -12,10 +15,14 @@ class SerialPortManagerClass {
std::optional<uint8_t> allocatePort(std::string const& owner);
void freePort(std::string const& owner);

using allocations_t = std::vector<std::pair<int8_t, std::string>>;
allocations_t getAllocations() const;

private:
// the amount of hardare UARTs available on supported ESP32 chips
static size_t constexpr _num_controllers = 3;
std::array<std::string, _num_controllers> _ports = { "" };
std::set<std::string> _rejects;
};

extern SerialPortManagerClass SerialPortManager;
13 changes: 13 additions & 0 deletions src/SerialPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ std::optional<uint8_t> 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;
}

Expand All @@ -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;
}
8 changes: 8 additions & 0 deletions src/WebApi_sysstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Configuration.h"
#include "NetworkSettings.h"
#include "PinMapping.h"
#include "SerialPortManager.h"
#include "WebApi.h"
#include "__compiled_constants.h"
#include <AsyncJson.h>
Expand Down Expand Up @@ -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<JsonArray>();
for (auto const& allocation : SerialPortManager.getAllocations()) {
JsonObject uart = uarts.add<JsonObject>();
uart["port"] = allocation.first;
uart["owner"] = allocation.second;
}

WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}
45 changes: 45 additions & 0 deletions webapp/src/components/UartAllocations.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<CardElement :text="$t('uartallocations.Allocations')" textVariant="text-bg-primary" table>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>{{ $t('uartallocations.Owner') }}</th>
<th>{{ $t('uartallocations.Port') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(allocation, idx) in allocations" :key="idx">
<td>
<template v-if="allocation.owner.length === 0">{{ $t('uartallocations.Free') }}</template>
<template v-else>{{ allocation.owner }}</template>
</td>
<td>
<span v-if="allocation.port >= 0" class="badge text-bg-success">
UART {{ allocation.port }}
</span>
<span v-else class="badge text-bg-danger">
{{ $t('uartallocations.Rejected') }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
</CardElement>
</template>

<script lang="ts">
import CardElement from '@/components/CardElement.vue';
import type { UartAllocation } from '@/types/SystemStatus';
import { defineComponent, type PropType } from 'vue';
export default defineComponent({
components: {
CardElement,
},
props: {
allocations: { type: Object as PropType<UartAllocation[]>, required: true },
},
});
</script>
7 changes: 7 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/types/SystemStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export interface TaskDetail {
priority: number;
}

export interface UartAllocation {
port: number;
owner: string;
}

export interface SystemStatus {
// HardwareInfo
chipmodel: string;
Expand Down Expand Up @@ -47,4 +52,6 @@ export interface SystemStatus {
nrf_pvariant: boolean;
cmt_configured: boolean;
cmt_connected: boolean;
// UARTs
uarts: UartAllocation[];
}
3 changes: 3 additions & 0 deletions webapp/src/views/SystemInfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="mt-5"></div>
<RadioInfo :systemStatus="systemDataList" />
<div class="mt-5"></div>
<UartAllocations :allocations="systemDataList.uarts" />
</BasePage>
</template>

Expand All @@ -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';
Expand All @@ -36,6 +38,7 @@ export default defineComponent({
HeapDetails,
TaskDetails,
RadioInfo,
UartAllocations,
},
data() {
return {
Expand Down

0 comments on commit dbb3421

Please sign in to comment.