diff --git a/lib/Hoymiles/src/commands/CommandAbstract.cpp b/lib/Hoymiles/src/commands/CommandAbstract.cpp index e7fb4ab5..78d8d07d 100644 --- a/lib/Hoymiles/src/commands/CommandAbstract.cpp +++ b/lib/Hoymiles/src/commands/CommandAbstract.cpp @@ -100,4 +100,14 @@ void CommandAbstract::convertSerialToPacketId(uint8_t buffer[], uint64_t serial) void CommandAbstract::gotTimeout(InverterAbstract* inverter) { -} \ No newline at end of file +} + +uint8_t CommandAbstract::getMaxResendCount() +{ + return MAX_RESEND_COUNT; +} + +uint8_t CommandAbstract::getMaxRetransmitCount() +{ + return MAX_RETRANSMIT_COUNT; +} diff --git a/lib/Hoymiles/src/commands/CommandAbstract.h b/lib/Hoymiles/src/commands/CommandAbstract.h index 3baa348e..8029ac87 100644 --- a/lib/Hoymiles/src/commands/CommandAbstract.h +++ b/lib/Hoymiles/src/commands/CommandAbstract.h @@ -6,6 +6,8 @@ #include #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; @@ -39,6 +41,12 @@ public: 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; diff --git a/lib/Hoymiles/src/inverters/InverterAbstract.cpp b/lib/Hoymiles/src/inverters/InverterAbstract.cpp index 25b35e5d..3833aac6 100644 --- a/lib/Hoymiles/src/inverters/InverterAbstract.cpp +++ b/lib/Hoymiles/src/inverters/InverterAbstract.cpp @@ -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); @@ -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); @@ -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); diff --git a/lib/Hoymiles/src/inverters/InverterAbstract.h b/lib/Hoymiles/src/inverters/InverterAbstract.h index 7663bbbe..755414f2 100644 --- a/lib/Hoymiles/src/inverters/InverterAbstract.h +++ b/lib/Hoymiles/src/inverters/InverterAbstract.h @@ -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;