Implemented resend of whole requests

This commit is contained in:
Thomas Basler 2022-06-20 20:47:21 +02:00
parent 9542cd9be3
commit 8d2b71cd04
3 changed files with 42 additions and 13 deletions

View File

@ -86,9 +86,13 @@ void HoymilesRadio::loop()
if (nullptr != inv) {
uint8_t verifyResult = inv->verifyAllFragments();
if (verifyResult == 255) {
Serial.println(F("Should Retransmit whole thing"));
// todo: irgendwas tun wenn garnichts ankam....
if (currentTransaction.sendCount < MAX_RESEND_COUNT) {
Serial.println(F("Nothing received, resend whole request"));
sendEsbPacket(currentTransaction.target, currentTransaction.mainCmd, currentTransaction.subCmd, currentTransaction.payload, currentTransaction.len, currentTransaction.timeout, true);
} else {
Serial.println(F("Nothing received, resend count exeeded"));
_busyFlag = false;
}
} else if (verifyResult == 254) {
Serial.println(F("Retransmit timeout"));
@ -208,6 +212,11 @@ void HoymilesRadio::sendEsbPacket(serial_u target, uint8_t mainCmd, uint8_t subC
static uint8_t txBuffer[MAX_RF_PAYLOAD_SIZE];
if (!resend) {
currentTransaction.sendCount = 0;
} else {
currentTransaction.sendCount++;
}
memset(txBuffer, 0, MAX_RF_PAYLOAD_SIZE);
txBuffer[0] = mainCmd;
@ -217,7 +226,13 @@ void HoymilesRadio::sendEsbPacket(serial_u target, uint8_t mainCmd, uint8_t subC
memcpy(&txBuffer[10], payload, len);
txBuffer[10 + len] = crc8(txBuffer, 10 + len);
}
currentTransaction.mainCmd = mainCmd;
currentTransaction.target = target;
currentTransaction.subCmd = subCmd;
memcpy(currentTransaction.payload, payload, len);
currentTransaction.len = len;
currentTransaction.timeout = timeout;
_radio->stopListening();
_radio->setChannel(getTxNxtChannel());

View File

@ -11,6 +11,8 @@
// number of fragments hold in buffer
#define FRAGMENT_BUFFER_SIZE 30
#define MAX_RESEND_COUNT 3
class HoymilesRadio {
public:
void init();
@ -55,4 +57,6 @@ private:
serial_u _activeSerial;
bool _busyFlag = false;
inverter_transaction_t currentTransaction;
};

View File

@ -14,3 +14,13 @@ typedef struct {
uint8_t fragment[MAX_RF_PAYLOAD_SIZE];
uint8_t len;
} fragment_t;
typedef struct {
serial_u target;
uint8_t mainCmd;
uint8_t subCmd;
uint8_t payload[MAX_RF_PAYLOAD_SIZE];
uint8_t len;
uint32_t timeout;
uint8_t sendCount;
} inverter_transaction_t;