From b02d36d042152100607e8b29fe02ecf86101edd1 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 6 Oct 2022 18:34:31 +0200 Subject: [PATCH] Added IDs to identifiy inverters to DevInfoParser --- lib/Hoymiles/src/parser/DevInfoParser.cpp | 47 +++++++++++++++++++++++ lib/Hoymiles/src/parser/DevInfoParser.h | 4 ++ 2 files changed, 51 insertions(+) diff --git a/lib/Hoymiles/src/parser/DevInfoParser.cpp b/lib/Hoymiles/src/parser/DevInfoParser.cpp index ce32bfc..7d9251c 100644 --- a/lib/Hoymiles/src/parser/DevInfoParser.cpp +++ b/lib/Hoymiles/src/parser/DevInfoParser.cpp @@ -1,6 +1,22 @@ #include "DevInfoParser.h" #include +typedef struct { + uint8_t hwPart[3]; + uint16_t maxPower; + const char* modelName; +} devInfo_t; + +const devInfo_t devInfo[] = { + { { 0x10, 0x10, 0x10 }, 300, "HM-300" }, + { { 0x10, 0x10, 0x40 }, 400, "HM-400" }, + { { 0x10, 0x11, 0x10 }, 600, "HM-600" }, + { { 0x10, 0x11, 0x20 }, 700, "HM-700" }, + { { 0x10, 0x11, 0x40 }, 800, "HM-800" }, + { { 0x10, 0x12, 0x10 }, 1200, "HM-1200" }, + { { 0x10, 0x12, 0x30 }, 1500, "HM-1500" } +}; + void DevInfoParser::clearBufferAll() { memset(_payloadDevInfoAll, 0, DEV_INFO_SIZE); @@ -97,6 +113,37 @@ String DevInfoParser::getHwVersion() return String(buf); } +uint16_t DevInfoParser::getMaxPower() +{ + uint8_t idx = getDevIdx(); + if (idx == 0xff) { + return 0; + } + return devInfo[idx].maxPower; +} + +String DevInfoParser::getHwModelName() +{ + uint8_t idx = getDevIdx(); + if (idx == 0xff) { + return ""; + } + return devInfo[idx].modelName; +} + +uint8_t DevInfoParser::getDevIdx() +{ + uint8_t pos; + for (pos = 0; pos < sizeof(devInfo) / sizeof(devInfo_t); pos++) { + if (devInfo[pos].hwPart[0] == _payloadDevInfoSimple[2] + && devInfo[pos].hwPart[1] == _payloadDevInfoSimple[3] + && devInfo[pos].hwPart[2] == _payloadDevInfoSimple[4]) { + return pos; + } + } + return 0xff; +} + /* struct tm to seconds since Unix epoch */ time_t DevInfoParser::timegm(struct tm* t) { diff --git a/lib/Hoymiles/src/parser/DevInfoParser.h b/lib/Hoymiles/src/parser/DevInfoParser.h index 4606586..a4ce10e 100644 --- a/lib/Hoymiles/src/parser/DevInfoParser.h +++ b/lib/Hoymiles/src/parser/DevInfoParser.h @@ -25,8 +25,12 @@ public: uint32_t getHwPartNumber(); String getHwVersion(); + uint16_t getMaxPower(); + String getHwModelName(); + private: time_t timegm(struct tm* tm); + uint8_t getDevIdx(); uint32_t _lastUpdateAll = 0; uint32_t _lastUpdateSimple = 0;