=================================================================================================================== sendHEXPacket() - return the SEQ of the ACK received, or -1 if invalid ===================================================================================================================
| 494 | // sendHEXPacket() - return the SEQ of the ACK received, or -1 if invalid |
| 495 | //=================================================================================================================== |
| 496 | uint8_t sendHEXPacket(RFM69& radio, uint16_t targetID, uint8_t* sendBuf, uint8_t hexDataLen, uint16_t seq, uint16_t TIMEOUT, uint16_t ACKTIMEOUT, uint8_t DEBUG) |
| 497 | { |
| 498 | long now = millis(); |
| 499 | |
| 500 | while(1) { |
| 501 | if (DEBUG) { Serial.print(F("RFTX > ")); PrintHex83(sendBuf, hexDataLen); Serial.println(); } |
| 502 | if (radio.sendWithRetry(targetID, sendBuf, hexDataLen, 2, ACKTIMEOUT)) |
| 503 | { |
| 504 | uint8_t ackLen = radio.DATALEN; |
| 505 | |
| 506 | if (DEBUG) { Serial.print(F("RFACK > ")); Serial.print(ackLen); Serial.print(F(" > ")); PrintHex83((uint8_t*)radio.DATA, ackLen); Serial.println(); } |
| 507 | |
| 508 | if (ackLen >= 8 && radio.DATA[0]=='F' && radio.DATA[1]=='L' && radio.DATA[2]=='X' && |
| 509 | radio.DATA[3]==':' && radio.DATA[ackLen-3]==':' && |
| 510 | radio.DATA[ackLen-2]=='O' && radio.DATA[ackLen-1]=='K') |
| 511 | { |
| 512 | uint16_t tmp=0; |
| 513 | #if defined(__arm__) |
| 514 | // On the ARM platform, uint16_t = short unsigned int, so %hu formatting is needed: |
| 515 | sscanf((const char*)radio.DATA, "FLX:%hu:OK", &tmp); |
| 516 | #else |
| 517 | // On the AVR platform, uint16_t = unsigned int, so %u formatting is needed: |
| 518 | sscanf((const char*)radio.DATA, "FLX:%u:OK", &tmp); |
| 519 | #endif |
| 520 | return tmp == seq; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | if (millis()-now > TIMEOUT) |
| 525 | { |
| 526 | Serial.println(F("Timeout waiting for packet ACK, aborting FLASH operation ...")); |
| 527 | break; //abort FLASH sequence if no valid ACK was received for a long time |
| 528 | } |
| 529 | } |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | //=================================================================================================================== |
no test coverage detected