Implemented resend of whole requests
This commit is contained in:
parent
9542cd9be3
commit
8d2b71cd04
@ -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....
|
||||
_busyFlag = false;
|
||||
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,17 +212,28 @@ void HoymilesRadio::sendEsbPacket(serial_u target, uint8_t mainCmd, uint8_t subC
|
||||
static uint8_t txBuffer[MAX_RF_PAYLOAD_SIZE];
|
||||
|
||||
if (!resend) {
|
||||
memset(txBuffer, 0, MAX_RF_PAYLOAD_SIZE);
|
||||
|
||||
txBuffer[0] = mainCmd;
|
||||
convertSerialToPacketId(&txBuffer[1], target); // 4 byte long
|
||||
convertSerialToPacketId(&txBuffer[5], DtuSerial()); // 4 byte long
|
||||
txBuffer[9] = subCmd;
|
||||
|
||||
memcpy(&txBuffer[10], payload, len);
|
||||
txBuffer[10 + len] = crc8(txBuffer, 10 + len);
|
||||
currentTransaction.sendCount = 0;
|
||||
} else {
|
||||
currentTransaction.sendCount++;
|
||||
}
|
||||
|
||||
memset(txBuffer, 0, MAX_RF_PAYLOAD_SIZE);
|
||||
|
||||
txBuffer[0] = mainCmd;
|
||||
convertSerialToPacketId(&txBuffer[1], target); // 4 byte long
|
||||
convertSerialToPacketId(&txBuffer[5], DtuSerial()); // 4 byte long
|
||||
txBuffer[9] = subCmd;
|
||||
|
||||
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());
|
||||
openWritingPipe(target);
|
||||
|
||||
@ -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;
|
||||
};
|
||||
@ -13,4 +13,14 @@ union serial_u {
|
||||
typedef struct {
|
||||
uint8_t fragment[MAX_RF_PAYLOAD_SIZE];
|
||||
uint8_t len;
|
||||
} fragment_t;
|
||||
} 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;
|
||||
Loading…
Reference in New Issue
Block a user