Data carrier detection
This commit is contained in:
parent
978800aaf9
commit
be98b0d7f7
25
Config.h
25
Config.h
|
@ -43,8 +43,10 @@
|
|||
#endif
|
||||
|
||||
// MCU independent configuration parameters
|
||||
const long serial_baudrate = 115200;
|
||||
const int rssi_offset = 164;
|
||||
const long serial_baudrate = 115200;
|
||||
const int rssi_offset = 164;
|
||||
|
||||
const int lora_rx_turnaround_ms = 5;
|
||||
|
||||
// Default LoRa settings
|
||||
int lora_sf = 0;
|
||||
|
@ -67,4 +69,23 @@
|
|||
uint32_t stat_rx = 0;
|
||||
uint32_t stat_tx = 0;
|
||||
|
||||
bool outbound_ready = false;
|
||||
|
||||
bool stat_signal_detected = false;
|
||||
bool stat_signal_synced = false;
|
||||
bool stat_rx_ongoing = false;
|
||||
bool dcd = false;
|
||||
bool dcd_led = false;
|
||||
bool dcd_waiting = false;
|
||||
uint16_t dcd_count = 0;
|
||||
uint16_t dcd_threshold = 15;
|
||||
|
||||
uint32_t status_interval_ms = 3;
|
||||
uint32_t last_status_update = 0;
|
||||
|
||||
// Status flags
|
||||
const uint8_t SIG_DETECT = 0x01;
|
||||
const uint8_t SIG_SYNCED = 0x02;
|
||||
const uint8_t RX_ONGOING = 0x04;
|
||||
|
||||
#endif
|
10
LoRa.cpp
10
LoRa.cpp
|
@ -1,5 +1,8 @@
|
|||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Modifications and additions copyright 2018 by Mark Qvist
|
||||
// Obviously still under the MIT license.
|
||||
|
||||
#include <LoRa.h>
|
||||
|
||||
|
@ -17,6 +20,7 @@
|
|||
#define REG_FIFO_RX_CURRENT_ADDR 0x10
|
||||
#define REG_IRQ_FLAGS 0x12
|
||||
#define REG_RX_NB_BYTES 0x13
|
||||
#define REG_MODEM_STAT 0x18
|
||||
#define REG_PKT_SNR_VALUE 0x19
|
||||
#define REG_PKT_RSSI_VALUE 0x1a
|
||||
#define REG_MODEM_CONFIG_1 0x1d
|
||||
|
@ -204,6 +208,10 @@ int LoRaClass::parsePacket(int size)
|
|||
return packetLength;
|
||||
}
|
||||
|
||||
uint8_t LoRaClass::modemStatus() {
|
||||
return readRegister(REG_MODEM_STAT);
|
||||
}
|
||||
|
||||
int LoRaClass::packetRssi()
|
||||
{
|
||||
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < 868E6 ? 164 : 157));
|
||||
|
|
1
LoRa.h
1
LoRa.h
|
@ -54,6 +54,7 @@ public:
|
|||
void setCodingRate4(int denominator);
|
||||
void setPreambleLength(long length);
|
||||
void setSyncWord(int sw);
|
||||
uint8_t modemStatus();
|
||||
void enableCrc();
|
||||
void disableCrc();
|
||||
|
||||
|
|
|
@ -81,8 +81,6 @@ void update_radio_lock() {
|
|||
}
|
||||
|
||||
void receiveCallback(int packet_size) {
|
||||
led_rx_on();
|
||||
|
||||
uint8_t header = LoRa.read(); packet_size--;
|
||||
uint8_t sequence = packetSequence(header);
|
||||
bool ready = false;
|
||||
|
@ -148,7 +146,6 @@ void receiveCallback(int packet_size) {
|
|||
Serial.write(FEND);
|
||||
read_len = 0;
|
||||
}
|
||||
led_rx_off();
|
||||
}
|
||||
|
||||
void transmit(size_t size) {
|
||||
|
@ -178,21 +175,22 @@ void transmit(size_t size) {
|
|||
|
||||
LoRa.endPacket();
|
||||
led_tx_off();
|
||||
LoRa.receive();
|
||||
|
||||
if (FLOW_CONTROL_ENABLED)
|
||||
kiss_indicate_ready();
|
||||
LoRa.receive();
|
||||
|
||||
} else {
|
||||
kiss_indicate_error(ERROR_TXFAILED);
|
||||
led_indicate_error(5);
|
||||
}
|
||||
|
||||
if (FLOW_CONTROL_ENABLED)
|
||||
kiss_indicate_ready();
|
||||
}
|
||||
|
||||
void serialCallback(uint8_t sbyte) {
|
||||
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
|
||||
IN_FRAME = false;
|
||||
transmit(frame_len);
|
||||
outbound_ready = true;
|
||||
} else if (sbyte == FEND) {
|
||||
IN_FRAME = true;
|
||||
command = CMD_UNKNOWN;
|
||||
|
@ -308,7 +306,61 @@ void serialCallback(uint8_t sbyte) {
|
|||
}
|
||||
}
|
||||
|
||||
void updateModemStatus() {
|
||||
uint8_t status = LoRa.modemStatus();
|
||||
last_status_update = millis();
|
||||
if (status & SIG_DETECT == 0x01) { stat_signal_detected = true; } else { stat_signal_detected = false; }
|
||||
if (status & SIG_SYNCED == 0x01) { stat_signal_synced = true; } else { stat_signal_synced = false; }
|
||||
if (status & RX_ONGOING == 0x01) { stat_rx_ongoing = true; } else { stat_rx_ongoing = false; }
|
||||
|
||||
if (stat_signal_detected || stat_signal_synced || stat_rx_ongoing) {
|
||||
if (dcd_count < dcd_threshold) {
|
||||
dcd_count++;
|
||||
dcd = true;
|
||||
} else {
|
||||
dcd = true;
|
||||
dcd_led = true;
|
||||
}
|
||||
} else {
|
||||
if (dcd_count > 0) {
|
||||
dcd_count--;
|
||||
} else {
|
||||
dcd_led = false;
|
||||
}
|
||||
dcd = false;
|
||||
}
|
||||
|
||||
if (dcd_led) {
|
||||
led_rx_on();
|
||||
} else {
|
||||
led_rx_off();
|
||||
}
|
||||
}
|
||||
|
||||
void checkModemStatus() {
|
||||
if (millis()-last_status_update >= status_interval_ms) {
|
||||
led_tx_on();
|
||||
updateModemStatus();
|
||||
led_tx_off();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (radio_online) {
|
||||
checkModemStatus();
|
||||
if (outbound_ready) {
|
||||
if (!dcd_waiting) updateModemStatus();
|
||||
if (!dcd && !dcd_led) {
|
||||
if (dcd_waiting) delay(lora_rx_turnaround_ms);
|
||||
outbound_ready = false;
|
||||
dcd_waiting = false;
|
||||
transmit(frame_len);
|
||||
} else {
|
||||
dcd_waiting = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Serial.available()) {
|
||||
char sbyte = Serial.read();
|
||||
serialCallback(sbyte);
|
||||
|
|
Loading…
Reference in New Issue