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 a510afe commit 4ae6a2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract* inverter, fragment
// 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()->getMaxByteCount()) {
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()->getMaxByteCount());
inverter->Statistics()->getExpectedByteCount());

return false;
}
Expand Down
17 changes: 5 additions & 12 deletions lib/Hoymiles/src/parser/StatisticsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,18 @@ void StatisticsParser::setByteAssignment(const byteAssign_t* byteAssignment, uin
{
_byteAssignment = byteAssignment;
_byteAssignmentSize = size;
}

uint8_t StatisticsParser::getMaxByteCount()
{
static uint8_t maxByteCount = 0;

// Use already calculated value
if (maxByteCount > 0) {
return maxByteCount;
}

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

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

void StatisticsParser::clearBuffer()
Expand Down
3 changes: 2 additions & 1 deletion lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ 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 getMaxByteCount();
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 @@ -142,6 +142,7 @@ class StatisticsParser : public Parser {

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

uint32_t _rxFailureCount = 0;
Expand Down

0 comments on commit 4ae6a2b

Please sign in to comment.