Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Dec 7, 2024
1 parent 7f62362 commit ec42c6f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/SerialPortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
#include <optional>
#include <string>

// the amount of hardare UARTs available on supported ESP32 chips
#define NUM_CONTROLLERS 3

class SerialPortManagerClass {
public:
void init();

std::optional<uint8_t> allocatePort(std::string const& owner);
void freePort(std::string const& owner);
std::array<std::string, NUM_CONTROLLERS> getPorts() const { return _ports; }

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::array<std::string, NUM_CONTROLLERS> _ports = { "" };
};

extern SerialPortManagerClass SerialPortManager;
10 changes: 10 additions & 0 deletions src/WebApi_sysstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "PinMapping.h"
#include "WebApi.h"
#include "__compiled_constants.h"
#include "SerialPortManager.h"
#include <AsyncJson.h>
#include <CpuTemperature.h>
#include <Hoymiles.h>
Expand Down Expand Up @@ -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<JsonArray>();
auto serialPorts = SerialPortManager.getPorts();

for (size_t i = 0; i < serialPorts.size(); ++i) {
JsonObject port = serialPortUsage.add<JsonObject>();
port["port"] = i;
port["owner"] = serialPorts[i]; //TODO(andreasboehm): This is always empty, why?
}

WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}
33 changes: 33 additions & 0 deletions webapp/src/components/SerialPortUsage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<CardElement :text="$t('serialPortUsage.SerialPortUsage')" textVariant="text-bg-primary" table>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tbody>
<tr>
<th>{{ $t('serialPortUsage.Number') }}</th>
<th>{{ $t('serialPortUsage.Owner') }}</th>
</tr>
<tr v-for="serialPort in serialPortDetails" v-bind:key="serialPort.port">
<td>{{ serialPort.port }}</td>
<td>{{ serialPort.owner !== '' ? serialPort.owner : $t('serialPortDetails.Available') }}</td>
</tr>
</tbody>
</table>
</div>
</CardElement>
</template>

<script lang="ts">
import CardElement from '@/components/CardElement.vue';
import type { SerialPortDetail } from '@/types/SystemStatus';
import { defineComponent, type PropType } from 'vue';
export default defineComponent({
components: {
CardElement,
},
props: {
serialPortDetails: { type: Array as PropType<SerialPortDetail[]>, required: true },
},
});
</script>
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 SerialPortDetail {
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;
// SerialPortUsage
serial_port_usage: SerialPortDetail[];
}
4 changes: 4 additions & 0 deletions webapp/src/views/SystemInfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<div class="mt-5"></div>
<TaskDetails :taskDetails="systemDataList.task_details" />
<div class="mt-5"></div>
<SerialPortUsage :serialPortDetails="systemDataList.serial_port_usage" />
<div class="mt-5"></div>
<RadioInfo :systemStatus="systemDataList" />
<div class="mt-5"></div>
</BasePage>
Expand All @@ -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';
Expand All @@ -35,6 +38,7 @@ export default defineComponent({
MemoryInfo,
HeapDetails,
TaskDetails,
SerialPortUsage,
RadioInfo,
},
data() {
Expand Down

0 comments on commit ec42c6f

Please sign in to comment.