TX module is no longer using interrupts to read from LoRa. This fixes jumpy PPM readouts
This commit is contained in:
34
crossbow.ino
34
crossbow.ino
@@ -1,11 +1,11 @@
|
||||
#define LORA_HARDWARE_SPI
|
||||
|
||||
#define DEVICE_MODE_TX
|
||||
// #define DEVICE_MODE_RX
|
||||
// #define DEVICE_MODE_TX
|
||||
#define DEVICE_MODE_RX
|
||||
|
||||
#define FEATURE_TX_OLED
|
||||
|
||||
// #define DEBUG_SERIAL
|
||||
#define DEBUG_SERIAL
|
||||
// #define DEBUG_PING_PONG
|
||||
// #define DEBUG_LED
|
||||
// #define WAIT_FOR_SERIAL
|
||||
@@ -20,7 +20,7 @@
|
||||
#define LORA32U4_RST_PIN 4
|
||||
#define LORA32U4_DI0_PIN 7
|
||||
|
||||
int ppm[16] = {0};
|
||||
volatile int ppm[16] = {0};
|
||||
|
||||
/*
|
||||
* Main defines for device working in TX mode
|
||||
@@ -52,8 +52,8 @@ uint32_t lastOledTaskTime = 0;
|
||||
/*
|
||||
* Start of QSP protocol implementation
|
||||
*/
|
||||
QspConfiguration_t qsp = {};
|
||||
RxDeviceState_t rxDeviceState = {};
|
||||
volatile QspConfiguration_t qsp = {};
|
||||
volatile RxDeviceState_t rxDeviceState = {};
|
||||
|
||||
#ifdef LORA_HARDWARE_SPI
|
||||
|
||||
@@ -134,7 +134,13 @@ void setup(void)
|
||||
LoRa.setSpreadingFactor(7);
|
||||
LoRa.setCodingRate4(5);
|
||||
|
||||
/*
|
||||
* Use interrupt driven approach only on RX side
|
||||
* TX interrupts breaks PPM readout
|
||||
*/
|
||||
#ifdef DEVICE_MODE_RX
|
||||
LoRa.onReceive(onReceive);
|
||||
#endif
|
||||
LoRa.receive();
|
||||
#endif
|
||||
|
||||
@@ -270,9 +276,23 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
#ifdef DEVICE_MODE_TX
|
||||
if (LoRa.available()) {
|
||||
qspDecodeIncomingFrame(&qsp, LoRa.read(), ppm, &rxDeviceState);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t currentMillis = millis();
|
||||
bool transmitPayload = false;
|
||||
|
||||
#ifdef DEBUG_SERIAL
|
||||
static uint32_t r = 0;
|
||||
if (currentMillis - r > 1000) {
|
||||
Serial.println(currentMillis / 1000);
|
||||
r = currentMillis;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Watchdog for frame decoding stuck somewhere in the middle of a process
|
||||
*/
|
||||
@@ -432,7 +452,6 @@ void loop(void)
|
||||
|
||||
}
|
||||
|
||||
#ifdef LORA_HARDWARE_SPI
|
||||
void onReceive(int packetSize)
|
||||
{
|
||||
if (packetSize == 0)
|
||||
@@ -443,4 +462,3 @@ void onReceive(int packetSize)
|
||||
qspDecodeIncomingFrame(&qsp, LoRa.read(), ppm, &rxDeviceState);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
5
qsp.cpp
5
qsp.cpp
@@ -142,7 +142,6 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
|
||||
if (qsp->protocolState == QSP_STATE_IDLE && incomingByte == QSP_PREAMBLE)
|
||||
{
|
||||
//FIXME there should be a way to go back to IDLE if frame did not finished decoding in reasonable time
|
||||
//If in IDLE and correct preamble comes, start to decode frame
|
||||
qsp->protocolState = QSP_STATE_PREAMBLE_RECEIVED;
|
||||
qsp->crc = 0 ^ incomingByte;
|
||||
@@ -177,6 +176,9 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
}
|
||||
else if (qsp->protocolState == QSP_STATE_FRAME_TYPE_RECEIVED)
|
||||
{
|
||||
if (receivedPayload >= QSP_PAYLOAD_LENGTH) {
|
||||
qsp->protocolState = QSP_STATE_IDLE;
|
||||
}
|
||||
|
||||
//Now it's time for payload
|
||||
qsp->crc ^= incomingByte;
|
||||
@@ -192,7 +194,6 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
}
|
||||
else if (qsp->protocolState == QSP_STATE_PAYLOAD_RECEIVED)
|
||||
{
|
||||
|
||||
if (qsp->crc == incomingByte) {
|
||||
//CRC is correct
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#define QSP_PREAMBLE 0x51
|
||||
#define QSP_PAYLOAD_LENGTH 32
|
||||
|
||||
#define QSP_MAX_FRAME_DECODE_TIME 50 //max time that frame can be decoded in ms
|
||||
#define QSP_MAX_FRAME_DECODE_TIME 10 //max time that frame can be decoded in ms
|
||||
|
||||
#define QSP_FRAME_RC_DATA 0x0
|
||||
#define QSP_FRAME_RX_HEALTH 0x1
|
||||
@@ -83,8 +83,8 @@ struct QspConfiguration_t {
|
||||
};
|
||||
|
||||
struct RxDeviceState_t {
|
||||
int rssi = 0;
|
||||
float snr = 0;
|
||||
uint8_t rssi = 0;
|
||||
uint8_t snr = 0;
|
||||
uint8_t rxVoltage = 0;
|
||||
uint8_t a1Voltage = 0;
|
||||
uint8_t a2Voltage = 0;
|
||||
|
||||
Reference in New Issue
Block a user