mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-01-27 06:47:14 -05:00
False preamble detection on SX1262
This commit is contained in:
parent
4bdd30daac
commit
3ae8982e93
24
sx126x.cpp
24
sx126x.cpp
@ -390,29 +390,35 @@ int sx126x::endPacket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long preamble_detected_at = 0;
|
unsigned long preamble_detected_at = 0;
|
||||||
unsigned long header_detected_at = 0;
|
|
||||||
extern long lora_preamble_time_ms;
|
extern long lora_preamble_time_ms;
|
||||||
extern long lora_header_time_ms;
|
extern long lora_header_time_ms;
|
||||||
|
bool false_preamble_detected = false;
|
||||||
|
|
||||||
bool sx126x::dcd() {
|
bool sx126x::dcd() {
|
||||||
bool carrier_detected = false;
|
|
||||||
uint8_t buf[2] = {0}; executeOpcodeRead(OP_GET_IRQ_STATUS_6X, buf, 2);
|
uint8_t buf[2] = {0}; executeOpcodeRead(OP_GET_IRQ_STATUS_6X, buf, 2);
|
||||||
|
uint32_t now = millis();
|
||||||
|
|
||||||
|
bool header_detected = false;
|
||||||
|
bool carrier_detected = false;
|
||||||
|
|
||||||
|
if ((buf[1] & IRQ_HEADER_DET_MASK_6X) != 0) { header_detected = true; carrier_detected = true; }
|
||||||
|
else { header_detected = false; }
|
||||||
|
|
||||||
if ((buf[1] & IRQ_PREAMBLE_DET_MASK_6X) != 0) {
|
if ((buf[1] & IRQ_PREAMBLE_DET_MASK_6X) != 0) {
|
||||||
carrier_detected = true;
|
carrier_detected = true;
|
||||||
if (preamble_detected_at == 0) preamble_detected_at = millis();
|
if (preamble_detected_at == 0) { preamble_detected_at = now; }
|
||||||
if (millis() - preamble_detected_at > lora_preamble_time_ms + lora_header_time_ms) {
|
if (now - preamble_detected_at > lora_preamble_time_ms + lora_header_time_ms) {
|
||||||
preamble_detected_at = 0;
|
preamble_detected_at = 0;
|
||||||
|
if (!header_detected) { false_preamble_detected = true; }
|
||||||
uint8_t clearbuf[2] = {0};
|
uint8_t clearbuf[2] = {0};
|
||||||
clearbuf[1] = IRQ_PREAMBLE_DET_MASK_6X;
|
clearbuf[1] = IRQ_PREAMBLE_DET_MASK_6X;
|
||||||
executeOpcode(OP_CLEAR_IRQ_STATUS_6X, clearbuf, 2);
|
executeOpcode(OP_CLEAR_IRQ_STATUS_6X, clearbuf, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[1] & IRQ_HEADER_DET_MASK_6X) != 0) {
|
// TODO: Maybe there's a way of unlatching the RSSI
|
||||||
carrier_detected = true;
|
// status without re-activating receive mode?
|
||||||
header_detected_at = millis();
|
if (false_preamble_detected) { sx126x_modem.receive(); false_preamble_detected = false; }
|
||||||
}
|
|
||||||
|
|
||||||
return carrier_detected;
|
return carrier_detected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user