diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp index ef28546..5e238a5 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2022 Thomas Basler and others */ #include "SystemConfigParaCommand.h" +#include "Hoymiles.h" #include "inverters/InverterAbstract.h" SystemConfigParaCommand::SystemConfigParaCommand(uint64_t target_address, uint64_t router_address, time_t time) @@ -25,6 +26,18 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract* inverter, fragmen return false; } + // Check if at least all required bytes are received + // In case of low power in the inverter it occours that some incomplete fragments + // with a valid CRC are received. + uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); + uint8_t expectedSize = inverter->SystemConfigPara()->getExpectedByteCount(); + if (fragmentsSize < expectedSize) { + Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n", + getCommandName().c_str(), fragmentsSize, expectedSize); + + return false; + } + // Move all fragments into target buffer uint8_t offs = 0; inverter->SystemConfigPara()->beginAppendFragment(); diff --git a/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp b/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp index d2d6365..d1ed30b 100644 --- a/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp +++ b/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp @@ -84,4 +84,9 @@ void SystemConfigParaParser::setLastUpdateRequest(uint32_t lastUpdate) { _lastUpdateRequest = lastUpdate; setLastUpdate(lastUpdate); -} \ No newline at end of file +} + +uint8_t SystemConfigParaParser::getExpectedByteCount() +{ + return SYSTEM_CONFIG_PARA_SIZE; +} diff --git a/lib/Hoymiles/src/parser/SystemConfigParaParser.h b/lib/Hoymiles/src/parser/SystemConfigParaParser.h index 37e2fa7..300a818 100644 --- a/lib/Hoymiles/src/parser/SystemConfigParaParser.h +++ b/lib/Hoymiles/src/parser/SystemConfigParaParser.h @@ -23,6 +23,9 @@ public: uint32_t getLastUpdateRequest(); void setLastUpdateRequest(uint32_t lastUpdate); + // Returns 1 based amount of expected bytes of data + uint8_t getExpectedByteCount(); + private: uint8_t _payload[SYSTEM_CONFIG_PARA_SIZE]; uint8_t _payloadLength;