void sx127x::writeRegister(uint8_t address, uint8_t value) { singleTransfer(address | 0x80, value); }
void sx127x::standby() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_STDBY_7X); }
void sx127x::sleep() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_SLEEP_7X); }
-uint8_t sx127x::modemStatus() { return readRegister(REG_MODEM_STAT_7X); }
void sx127x::setSyncWord(uint8_t sw) { writeRegister(REG_SYNC_WORD_7X, sw); }
void sx127x::enableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) | 0x04); }
void sx127x::disableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) & 0xfb); }
return 1;
}
+bool sx127x::dcd() {
+ bool carrier_detected = false;
+ uint8_t status = readRegister(REG_MODEM_STAT_7X);
+ if ((status & SIG_DETECT) == SIG_DETECT) { carrier_detected = true; }
+ if ((status & SIG_SYNCED) == SIG_SYNCED) { carrier_detected = true; }
+ return carrier_detected;
+}
+
uint8_t sx127x::currentRssiRaw() {
uint8_t rssi = readRegister(REG_RSSI_VALUE_7X);
return rssi;
else { return 1; }
}
-uint8_t sx128x::modemStatus() {
- // Imitate the register status from the sx1276 / 78
- uint8_t buf[2] = {0};
- executeOpcodeRead(OP_GET_IRQ_STATUS_8X, buf, 2);
- uint8_t clearbuf[2] = {0};
- uint8_t byte = 0x00;
-
- if ((buf[0] & IRQ_PREAMBLE_DET_MASK_8X) != 0) {
- byte = byte | 0x01 | 0x04;
- // Clear register after reading
- clearbuf[0] = IRQ_PREAMBLE_DET_MASK_8X;
+unsigned long preamble_detected_at = 0;
+unsigned long header_detected_at = 0;
+extern long lora_preamble_time_ms;
+extern long lora_header_time_ms;
+bool sx128x::dcd() {
+ bool carrier_detected = false;
+ uint8_t buf[2] = {0}; executeOpcodeRead(OP_GET_IRQ_STATUS_8X, buf, 2);
+
+ if ((buf[1] & IRQ_PREAMBLE_DET_MASK_8X) != 0) {
+ carrier_detected = true;
+ if (preamble_detected_at == 0) preamble_detected_at = millis();
+ if (millis() - preamble_detected_at > lora_preamble_time_ms + lora_header_time_ms) {
+ preamble_detected_at = 0;
+ uint8_t clearbuf[2] = {0};
+ clearbuf[1] = IRQ_PREAMBLE_DET_MASK_8X;
+ executeOpcode(OP_CLEAR_IRQ_STATUS_8X, clearbuf, 2);
}
+ }
- if ((buf[1] & IRQ_HEADER_DET_MASK_8X) != 0) { byte = byte | 0x02 | 0x04; }
- executeOpcode(OP_CLEAR_IRQ_STATUS_8X, clearbuf, 2);
+ if ((buf[1] & IRQ_HEADER_DET_MASK_8X) != 0) {
+ carrier_detected = true;
+ header_detected_at = millis();
+ }
- return byte;
+ return carrier_detected;
}