mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-10-31 02:51:58 +01:00
cad timeout y oled update
This commit is contained in:
1 parent
fc256de09c
commit
a472c307d3
2 files changed
+18
-1
No files matched your search
@@ -68,7 +68,7 @@ ___________________________________________________________________*/
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
String versionDate = "2026-09-28";
|
String versionDate = "2026-09-29";
|
||||||
String versionNumber = "4.0.1";
|
String versionNumber = "4.0.1";
|
||||||
Configuration Config;
|
Configuration Config;
|
||||||
WiFiClient aprsIsClient;
|
WiFiClient aprsIsClient;
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ bool transmitFlag = true;
|
|||||||
|
|
||||||
#define DIFS_SLOTS 2 // Number of secuential CAD slots to consider a free channel to Tx
|
#define DIFS_SLOTS 2 // Number of secuential CAD slots to consider a free channel to Tx
|
||||||
int backoffMax = 4; // Max Backoff value (number of CAD slots to wait before Tx)
|
int backoffMax = 4; // Max Backoff value (number of CAD slots to wait before Tx)
|
||||||
|
#define CAD_MAX_WAIT_MS 10000 // Max total time waiting for a free channel, then the packet is dropped
|
||||||
|
unsigned long cadStartTime = 0;
|
||||||
|
|
||||||
#ifdef HAS_SX1262
|
#ifdef HAS_SX1262
|
||||||
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||||
@@ -195,8 +197,13 @@ namespace LoRa_Utils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cadTimedOut() {
|
||||||
|
return millis() - cadStartTime > CAD_MAX_WAIT_MS;
|
||||||
|
}
|
||||||
|
|
||||||
void waitForDIFS() {
|
void waitForDIFS() {
|
||||||
while (!doDIFS()) {
|
while (!doDIFS()) {
|
||||||
|
if (cadTimedOut()) return;
|
||||||
Serial.println("CAD/DIFS failed, retry...");
|
Serial.println("CAD/DIFS failed, retry...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,6 +211,7 @@ namespace LoRa_Utils {
|
|||||||
void doBEB() {
|
void doBEB() {
|
||||||
int backoffCounter = random(1, backoffMax + 1);
|
int backoffCounter = random(1, backoffMax + 1);
|
||||||
while (backoffCounter > 0) {
|
while (backoffCounter > 0) {
|
||||||
|
if (cadTimedOut()) return;
|
||||||
if (doCAD()) {
|
if (doCAD()) {
|
||||||
waitForDIFS(); // busy channel: freeze backoff and restart DIFS
|
waitForDIFS(); // busy channel: freeze backoff and restart DIFS
|
||||||
} else {
|
} else {
|
||||||
@@ -225,11 +233,18 @@ namespace LoRa_Utils {
|
|||||||
if (Config.digi.ecoMode != 1) digitalWrite(INTERNAL_LED_PIN, HIGH); // disabled in Ultra Eco Mode
|
if (Config.digi.ecoMode != 1) digitalWrite(INTERNAL_LED_PIN, HIGH); // disabled in Ultra Eco Mode
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool cadDropped = false;
|
||||||
if (Config.loramodule.cadActive) {
|
if (Config.loramodule.cadActive) {
|
||||||
|
cadStartTime = millis();
|
||||||
waitForDIFS(); // DIFS (Distributed Inter-Frame Space)
|
waitForDIFS(); // DIFS (Distributed Inter-Frame Space)
|
||||||
doBEB(); // BEB (Binary Exponential Backoff)
|
doBEB(); // BEB (Binary Exponential Backoff)
|
||||||
|
if (cadTimedOut()) {
|
||||||
|
Utils::println("CAD timeout, packet dropped: " + newPacket);
|
||||||
|
cadDropped = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cadDropped) {
|
||||||
int state = radio.transmit("\x3c\xff\x01" + newPacket);
|
int state = radio.transmit("\x3c\xff\x01" + newPacket);
|
||||||
transmitFlag = true;
|
transmitFlag = true;
|
||||||
if (state == RADIOLIB_ERR_NONE) {
|
if (state == RADIOLIB_ERR_NONE) {
|
||||||
@@ -242,6 +257,7 @@ namespace LoRa_Utils {
|
|||||||
Utils::print(F("failed, code "));
|
Utils::print(F("failed, code "));
|
||||||
Utils::println(String(state));
|
Utils::println(String(state));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef INTERNAL_LED_PIN
|
#ifdef INTERNAL_LED_PIN
|
||||||
if (Config.digi.ecoMode != 1) digitalWrite(INTERNAL_LED_PIN, LOW); // disabled in Ultra Eco Mode
|
if (Config.digi.ecoMode != 1) digitalWrite(INTERNAL_LED_PIN, LOW); // disabled in Ultra Eco Mode
|
||||||
#endif
|
#endif
|
||||||
@@ -250,6 +266,7 @@ namespace LoRa_Utils {
|
|||||||
changeFreqRx();
|
changeFreqRx();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cadDropped) radio.startReceive(); // no Tx end IRQ will restart Rx
|
||||||
}
|
}
|
||||||
|
|
||||||
String receivePacketFromSleep() {
|
String receivePacketFromSleep() {
|
||||||
|
|||||||
Reference in new issue
Block a user