Skip to content

Commit

Permalink
Resend and Retransmit count is now implementable per command
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Apr 15, 2023
1 parent e2aa29f commit ac7b5db
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
12 changes: 11 additions & 1 deletion lib/Hoymiles/src/commands/CommandAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ void CommandAbstract::convertSerialToPacketId(uint8_t buffer[], uint64_t serial)

void CommandAbstract::gotTimeout(InverterAbstract* inverter)
{
}
}

uint8_t CommandAbstract::getMaxResendCount()
{
return MAX_RESEND_COUNT;
}

uint8_t CommandAbstract::getMaxRetransmitCount()
{
return MAX_RETRANSMIT_COUNT;
}
8 changes: 8 additions & 0 deletions lib/Hoymiles/src/commands/CommandAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <cstdint>

#define RF_LEN 32
#define MAX_RESEND_COUNT 4 // Used if all packages are missing
#define MAX_RETRANSMIT_COUNT 5 // Used to send the retransmit package

class InverterAbstract;

Expand Down Expand Up @@ -39,6 +41,12 @@ class CommandAbstract {
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) = 0;
virtual void gotTimeout(InverterAbstract* inverter);

// Sets the amount how often the specific command is resent if all fragments where missing
virtual uint8_t getMaxResendCount();

// Sets the amount how often a missing fragment is re-requested if it was not available
virtual uint8_t getMaxRetransmitCount();

protected:
uint8_t _payload[RF_LEN];
uint8_t _payload_size;
Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/inverters/InverterAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract* cmd)
// All missing
if (_rxFragmentLastPacketId == 0) {
Hoymiles.getMessageOutput()->println("All missing");
if (cmd->getSendCount() <= MAX_RESEND_COUNT) {
if (cmd->getSendCount() <= cmd->getMaxResendCount()) {
return FRAGMENT_ALL_MISSING_RESEND;
} else {
cmd->gotTimeout(this);
Expand All @@ -192,7 +192,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract* cmd)
// Last fragment is missing (the one with 0x80)
if (_rxFragmentMaxPacketId == 0) {
Hoymiles.getMessageOutput()->println("Last missing");
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
if (_rxFragmentRetransmitCnt++ < cmd->getMaxRetransmitCount()) {
return _rxFragmentLastPacketId + 1;
} else {
cmd->gotTimeout(this);
Expand All @@ -204,7 +204,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract* cmd)
for (uint8_t i = 0; i < _rxFragmentMaxPacketId - 1; i++) {
if (!_rxFragmentBuffer[i].wasReceived) {
Hoymiles.getMessageOutput()->println("Middle missing");
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
if (_rxFragmentRetransmitCnt++ < cmd->getMaxRetransmitCount()) {
return i + 1;
} else {
cmd->gotTimeout(this);
Expand Down
2 changes: 0 additions & 2 deletions lib/Hoymiles/src/inverters/InverterAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ enum {
};

#define MAX_RF_FRAGMENT_COUNT 13
#define MAX_RETRANSMIT_COUNT 5 // Used to send the retransmit package
#define MAX_RESEND_COUNT 4 // Used if all packages are missing
#define MAX_ONLINE_FAILURE_COUNT 2

class CommandAbstract;
Expand Down

0 comments on commit ac7b5db

Please sign in to comment.