Browse Source

Merge pull request #2490 from tuzzmaniandevil/dev

Enhance KissModem frame processing and timeout handling
pull/2510/head
Liam Cottle 4 weeks ago
committed by GitHub
parent
commit
56d4671c2c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 24
      examples/kiss_modem/KissModem.cpp
  2. 2
      examples/kiss_modem/KissModem.h

24
examples/kiss_modem/KissModem.cpp

@ -129,6 +129,8 @@ void KissModem::processFrame() {
memcpy(_pending_tx, data, data_len); memcpy(_pending_tx, data, data_len);
_pending_tx_len = data_len; _pending_tx_len = data_len;
_has_pending_tx = true; _has_pending_tx = true;
} else if (_has_pending_tx) {
writeHardwareError(HW_ERR_TX_BUSY);
} }
break; break;
@ -257,6 +259,7 @@ void KissModem::processTx() {
_tx_timer = millis(); _tx_timer = millis();
_tx_state = TX_DELAY; _tx_state = TX_DELAY;
} else { } else {
_tx_timer = millis();
_tx_state = TX_WAIT_CLEAR; _tx_state = TX_WAIT_CLEAR;
} }
} }
@ -273,19 +276,30 @@ void KissModem::processTx() {
_tx_timer = millis(); _tx_timer = millis();
_tx_state = TX_SLOT_WAIT; _tx_state = TX_SLOT_WAIT;
} }
} else if (millis() - _tx_timer >= _radio.getEstAirtimeFor(KISS_MAX_PACKET_SIZE) * KISS_TX_TIMEOUT_FACTOR) {
_tx_timer = millis();
_tx_state = TX_DELAY;
} }
break; break;
case TX_SLOT_WAIT: case TX_SLOT_WAIT:
if (millis() - _tx_timer >= (uint32_t)_slottime * 10) { if (millis() - _tx_timer >= (uint32_t)_slottime * 10) {
_tx_timer = millis();
_tx_state = TX_WAIT_CLEAR; _tx_state = TX_WAIT_CLEAR;
} }
break; break;
case TX_DELAY: case TX_DELAY:
if (millis() - _tx_timer >= (uint32_t)_txdelay * 10) { if (millis() - _tx_timer >= (uint32_t)_txdelay * 10) {
_radio.startSendRaw(_pending_tx, _pending_tx_len); if (_radio.startSendRaw(_pending_tx, _pending_tx_len)) {
_tx_state = TX_SENDING; _tx_timer = millis();
_tx_state = TX_SENDING;
} else {
uint8_t result = 0x00;
writeHardwareFrame(HW_RESP_TX_DONE, &result, 1);
_has_pending_tx = false;
_tx_state = TX_IDLE;
}
} }
break; break;
@ -296,6 +310,12 @@ void KissModem::processTx() {
writeHardwareFrame(HW_RESP_TX_DONE, &result, 1); writeHardwareFrame(HW_RESP_TX_DONE, &result, 1);
_has_pending_tx = false; _has_pending_tx = false;
_tx_state = TX_IDLE; _tx_state = TX_IDLE;
} else if (millis() - _tx_timer >= _radio.getEstAirtimeFor(_pending_tx_len) * KISS_TX_TIMEOUT_FACTOR) {
_radio.onSendFinished();
uint8_t result = 0x00;
writeHardwareFrame(HW_RESP_TX_DONE, &result, 1);
_has_pending_tx = false;
_tx_state = TX_IDLE;
} }
break; break;
} }

2
examples/kiss_modem/KissModem.h

@ -26,6 +26,7 @@
#define KISS_DEFAULT_TXDELAY 50 #define KISS_DEFAULT_TXDELAY 50
#define KISS_DEFAULT_PERSISTENCE 63 #define KISS_DEFAULT_PERSISTENCE 63
#define KISS_DEFAULT_SLOTTIME 10 #define KISS_DEFAULT_SLOTTIME 10
#define KISS_TX_TIMEOUT_FACTOR 3/2 // 1.5x estimated airtime
#define HW_CMD_GET_IDENTITY 0x01 #define HW_CMD_GET_IDENTITY 0x01
#define HW_CMD_GET_RANDOM 0x02 #define HW_CMD_GET_RANDOM 0x02
@ -71,6 +72,7 @@
#define HW_ERR_MAC_FAILED 0x04 #define HW_ERR_MAC_FAILED 0x04
#define HW_ERR_UNKNOWN_CMD 0x05 #define HW_ERR_UNKNOWN_CMD 0x05
#define HW_ERR_ENCRYPT_FAILED 0x06 #define HW_ERR_ENCRYPT_FAILED 0x06
#define HW_ERR_TX_BUSY 0x07
#define KISS_FIRMWARE_VERSION 1 #define KISS_FIRMWARE_VERSION 1

Loading…
Cancel
Save