Skip to content

Commit

Permalink
Feature: Added basic Grid Profile parser which shows the used profile…
Browse files Browse the repository at this point in the history
… and version

Other values are still outstanding.
  • Loading branch information
tbnobody committed Dec 9, 2023
1 parent c9508d2 commit 00bc631
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Hoymiles/src/parser/GridProfileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#include "../Hoymiles.h"
#include <cstring>

const std::array<const ProfileType_t, PROFILE_TYPE_COUNT> GridProfileParser::_profileTypes = { {
{ 0x02, 0x00, "no data (yet)" },
{ 0x03, 0x00, "Germany - DE_VDE4105_2018" },
{ 0x0a, 0x00, "European - EN 50549-1:2019" },
{ 0x0c, 0x00, "AT Tor - EU_EN50438" },
{ 0x0d, 0x04, "France" },
{ 0x12, 0x00, "Poland" },
{ 0x37, 0x00, "Swiss - CH_NA EEA-NE7-CH2020" },
} };

GridProfileParser::GridProfileParser()
: Parser()
{
Expand All @@ -28,6 +38,23 @@ void GridProfileParser::appendFragment(uint8_t offset, uint8_t* payload, uint8_t
_gridProfileLength += len;
}

String GridProfileParser::getProfileName()
{
for (auto& ptype : _profileTypes) {
if (ptype.lIdx == _payloadGridProfile[0] && ptype.hIdx == _payloadGridProfile[1]) {
return ptype.Name;
}
}
return "Unknown";
}

String GridProfileParser::getProfileVersion()
{
char buffer[10];
snprintf(buffer, sizeof(buffer), "%d.%d.%d", (_payloadGridProfile[2] >> 4) & 0x0f, _payloadGridProfile[2] & 0x0f, _payloadGridProfile[3]);
return buffer;
}

std::vector<uint8_t> GridProfileParser::getRawData()
{
std::vector<uint8_t> ret;
Expand Down
12 changes: 12 additions & 0 deletions lib/Hoymiles/src/parser/GridProfileParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
#include "Parser.h"

#define GRID_PROFILE_SIZE 141
#define PROFILE_TYPE_COUNT 7

typedef struct {
uint8_t lIdx;
uint8_t hIdx;
const char* Name;
} ProfileType_t;

class GridProfileParser : public Parser {
public:
GridProfileParser();
void clearBuffer();
void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len);

String getProfileName();
String getProfileVersion();

std::vector<uint8_t> getRawData();

private:
uint8_t _payloadGridProfile[GRID_PROFILE_SIZE] = {};
uint8_t _gridProfileLength = 0;

static const std::array<const ProfileType_t, PROFILE_TYPE_COUNT> _profileTypes;
};
3 changes: 3 additions & 0 deletions src/WebApi_gridprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void WebApiGridProfileClass::onGridProfileStatus(AsyncWebServerRequest* request)
auto data = inv->GridProfile()->getRawData();

copyArray(&data[0], data.size(), raw);

root["name"] = inv->GridProfile()->getProfileName();
root["version"] = inv->GridProfile()->getProfileVersion();
}

response->setLength();
Expand Down
13 changes: 13 additions & 0 deletions webapp/src/components/GridProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
</BootstrapAlert>

<template v-if="hasValidData">
<table class="table table-hover">
<tbody>
<tr>
<td>{{ $t('gridprofile.Name') }}</td>
<td>{{ gridProfileList.name }}</td>
</tr>
<tr>
<td>{{ $t('gridprofile.Version') }}</td>
<td>{{ gridProfileList.version }}</td>
</tr>
</tbody>
</table>

<BootstrapAlert :show="true" variant="danger">
<h4 class="info-heading">
<BIconInfoSquare class="fs-2" />&nbsp;{{ $t('gridprofile.GridprofileSupport') }}
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"gridprofile": {
"NoInfo": "@:devinfo.NoInfo",
"NoInfoLong": "@:devinfo.NoInfoLong",
"Name": "Name",
"Version": "Version",
"GridprofileSupport": "Unterstütze die Entwicklung",
"GridprofileSupportLong": "Weitere Informationen sind <a href=\"https://github.com/tbnobody/OpenDTU/wiki/Grid-Profile-Parser\" target=\"_blank\">hier</a> zu finden."
},
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"gridprofile": {
"NoInfo": "@:devinfo.NoInfo",
"NoInfoLong": "@:devinfo.NoInfoLong",
"Name": "Name",
"Version": "Version",
"GridprofileSupport": "Support the development",
"GridprofileSupportLong": "Please see <a href=\"https://github.com/tbnobody/OpenDTU/wiki/Grid-Profile-Parser\" target=\"_blank\">here</a> for further information."
},
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"gridprofile": {
"NoInfo": "@:devinfo.NoInfo",
"NoInfoLong": "@:devinfo.NoInfoLong",
"Name": "Name",
"Version": "Version",
"GridprofileSupport": "Support the development",
"GridprofileSupportLong": "Please see <a href=\"https://github.com/tbnobody/OpenDTU/wiki/Grid-Profile-Parser\" target=\"_blank\">here</a> for further information."
},
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/types/GridProfileStatus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export interface GridProfileStatus {
raw: Array<number>;
name: String;
version: String;
}

0 comments on commit 00bc631

Please sign in to comment.