Skip to content

Commit

Permalink
Fix: calc expected statistics packet length per parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jstammi committed Jun 28, 2023
1 parent 66636fe commit 143054d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract* inverter, fragment
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.
if (getTotalFragmentSize(fragment, max_fragment_id) < inverter->Statistics()->getExpectedByteCount()) {
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d min. expected size: %d\r\n",
getCommandName().c_str(),
getTotalFragmentSize(fragment, max_fragment_id),
inverter->Statistics()->getExpectedByteCount());

return false;
}

// Move all fragments into target buffer
uint8_t offs = 0;
inverter->Statistics()->clearBuffer();
Expand All @@ -40,4 +52,4 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract* inverter, fragment
void RealTimeRunDataCommand::gotTimeout(InverterAbstract* inverter)
{
inverter->Statistics()->incrementRxFailureCount();
}
}
12 changes: 12 additions & 0 deletions lib/Hoymiles/src/parser/StatisticsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ void StatisticsParser::setByteAssignment(const byteAssign_t* byteAssignment, uin
{
_byteAssignment = byteAssignment;
_byteAssignmentSize = size;

for (uint8_t i = 0; i < _byteAssignmentSize; i++) {
if (_byteAssignment[i].div == CMD_CALC) {
continue;
}
_expectedByteCount = max<uint8_t>(_expectedByteCount, _byteAssignment[i].start + _byteAssignment[i].num);
}
}

uint8_t StatisticsParser::getExpectedByteCount()
{
return _expectedByteCount;
}

void StatisticsParser::clearBuffer()
Expand Down
6 changes: 5 additions & 1 deletion lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class StatisticsParser : public Parser {

void setByteAssignment(const byteAssign_t* byteAssignment, uint8_t size);

// Returns 1 based amount of expected bytes of statistic data
uint8_t getExpectedByteCount();

const byteAssign_t* getAssignmentByChannelField(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
fieldSettings_t* getSettingByChannelField(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);

Expand Down Expand Up @@ -139,7 +142,8 @@ class StatisticsParser : public Parser {

const byteAssign_t* _byteAssignment;
uint8_t _byteAssignmentSize;
uint8_t _expectedByteCount;
std::list<fieldSettings_t> _fieldSettings;

uint32_t _rxFailureCount = 0;
};
};

0 comments on commit 143054d

Please sign in to comment.