From 00bc631e87f16fb94bcf72d98b7f8e49eba83bbc Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sat, 9 Dec 2023 11:12:37 +0100 Subject: [PATCH] Feature: Added basic Grid Profile parser which shows the used profile and version Other values are still outstanding. --- lib/Hoymiles/src/parser/GridProfileParser.cpp | 27 +++++++++++++++++++ lib/Hoymiles/src/parser/GridProfileParser.h | 12 +++++++++ src/WebApi_gridprofile.cpp | 3 +++ webapp/src/components/GridProfile.vue | 13 +++++++++ webapp/src/locales/de.json | 2 ++ webapp/src/locales/en.json | 2 ++ webapp/src/locales/fr.json | 2 ++ webapp/src/types/GridProfileStatus.ts | 2 ++ 8 files changed, 63 insertions(+) diff --git a/lib/Hoymiles/src/parser/GridProfileParser.cpp b/lib/Hoymiles/src/parser/GridProfileParser.cpp index 35f7689d..aa456a8e 100644 --- a/lib/Hoymiles/src/parser/GridProfileParser.cpp +++ b/lib/Hoymiles/src/parser/GridProfileParser.cpp @@ -6,6 +6,16 @@ #include "../Hoymiles.h" #include +const std::array 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() { @@ -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 GridProfileParser::getRawData() { std::vector ret; diff --git a/lib/Hoymiles/src/parser/GridProfileParser.h b/lib/Hoymiles/src/parser/GridProfileParser.h index c2af52f8..30653716 100644 --- a/lib/Hoymiles/src/parser/GridProfileParser.h +++ b/lib/Hoymiles/src/parser/GridProfileParser.h @@ -3,6 +3,13 @@ #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: @@ -10,9 +17,14 @@ public: void clearBuffer(); void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len); + String getProfileName(); + String getProfileVersion(); + std::vector getRawData(); private: uint8_t _payloadGridProfile[GRID_PROFILE_SIZE] = {}; uint8_t _gridProfileLength = 0; + + static const std::array _profileTypes; }; \ No newline at end of file diff --git a/src/WebApi_gridprofile.cpp b/src/WebApi_gridprofile.cpp index c9d2adb8..599c54e4 100644 --- a/src/WebApi_gridprofile.cpp +++ b/src/WebApi_gridprofile.cpp @@ -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(); diff --git a/webapp/src/components/GridProfile.vue b/webapp/src/components/GridProfile.vue index 31a14133..840e897e 100644 --- a/webapp/src/components/GridProfile.vue +++ b/webapp/src/components/GridProfile.vue @@ -6,6 +6,19 @@