Skip to content

Commit

Permalink
Fix: Ignore incomplete SystemConfigPara packages
Browse files Browse the repository at this point in the history
Some inverters seem to transmit too less and incomplete data. These packages will be ignored now.
  • Loading branch information
tbnobody committed Sep 7, 2023
1 parent 0260af9 commit 8023b66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion lib/Hoymiles/src/parser/SystemConfigParaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ void SystemConfigParaParser::setLastUpdateRequest(uint32_t lastUpdate)
{
_lastUpdateRequest = lastUpdate;
setLastUpdate(lastUpdate);
}
}

uint8_t SystemConfigParaParser::getExpectedByteCount()
{
return SYSTEM_CONFIG_PARA_SIZE;
}
3 changes: 3 additions & 0 deletions lib/Hoymiles/src/parser/SystemConfigParaParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class SystemConfigParaParser : public Parser {
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;
Expand Down

0 comments on commit 8023b66

Please sign in to comment.