step 2
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"variables.h": "c",
|
"variables.h": "c",
|
||||||
"arduino.h": "c"
|
"arduino.h": "c",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"random": "cpp"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/build": true
|
"**/build": true
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ Copyright (c) 20xx, MPL Contributor1 contrib1@example.net
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "lora.h"
|
#include "lora.h"
|
||||||
|
#include "radio_node.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "main_variables.h"
|
#include "main_variables.h"
|
||||||
#include "qsp.h"
|
#include "qsp.h"
|
||||||
#include "sbus.h"
|
#include "sbus.h"
|
||||||
#include "radio_node.h"
|
|
||||||
|
|
||||||
#ifdef ARDUINO_AVR_FEATHER32U4
|
#ifdef ARDUINO_AVR_FEATHER32U4
|
||||||
#define LORA_SS_PIN 8
|
#define LORA_SS_PIN 8
|
||||||
@@ -184,7 +184,7 @@ void setup(void)
|
|||||||
//Setup ISR callback and start receiving
|
//Setup ISR callback and start receiving
|
||||||
LoRa.onReceive(onReceive);
|
LoRa.onReceive(onReceive);
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
radioState.deviceState = RADIO_STATE_RX;
|
radioNode.deviceState = RADIO_STATE_RX;
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
//initiallize default ppm values
|
//initiallize default ppm values
|
||||||
@@ -368,7 +368,7 @@ void loop(void)
|
|||||||
*/
|
*/
|
||||||
if (
|
if (
|
||||||
currentMillis > radioState.nextTxCheckMillis &&
|
currentMillis > radioState.nextTxCheckMillis &&
|
||||||
radioState.deviceState == RADIO_STATE_TX &&
|
radioNode.deviceState == RADIO_STATE_TX &&
|
||||||
!LoRa.isTransmitting()
|
!LoRa.isTransmitting()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -380,27 +380,16 @@ void loop(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
radioState.deviceState = RADIO_STATE_RX;
|
radioNode.deviceState = RADIO_STATE_RX;
|
||||||
radioState.nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
radioState.nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
radioNode.readAndDecode(
|
||||||
* There is data to be read from radio!
|
&radioState,
|
||||||
*/
|
&qsp,
|
||||||
if (radioState.bytesToRead != NO_DATA_TO_READ) {
|
&rxDeviceState,
|
||||||
LoRa.read(tmpBuffer, radioState.bytesToRead);
|
&txDeviceState
|
||||||
|
);
|
||||||
for (int i = 0; i < radioState.bytesToRead; i++) {
|
|
||||||
qspDecodeIncomingFrame(&qsp, tmpBuffer[i], &rxDeviceState, &txDeviceState, &radioState);
|
|
||||||
}
|
|
||||||
|
|
||||||
//After reading, flush radio buffer, we have no need for whatever might be over there
|
|
||||||
LoRa.sleep();
|
|
||||||
LoRa.receive();
|
|
||||||
radioState.deviceState = RADIO_STATE_RX;
|
|
||||||
|
|
||||||
radioState.bytesToRead = NO_DATA_TO_READ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool transmitPayload = false;
|
bool transmitPayload = false;
|
||||||
|
|
||||||
@@ -419,7 +408,7 @@ void loop(void)
|
|||||||
txInput.loop();
|
txInput.loop();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
radioState.deviceState == RADIO_STATE_RX &&
|
radioNode.deviceState == RADIO_STATE_RX &&
|
||||||
qsp.protocolState == QSP_STATE_IDLE &&
|
qsp.protocolState == QSP_STATE_IDLE &&
|
||||||
qsp.lastTxSlotTimestamp + TX_TRANSMIT_SLOT_RATE < currentMillis
|
qsp.lastTxSlotTimestamp + TX_TRANSMIT_SLOT_RATE < currentMillis
|
||||||
) {
|
) {
|
||||||
@@ -536,7 +525,7 @@ void loop(void)
|
|||||||
LoRa.endPacketAsync();
|
LoRa.endPacketAsync();
|
||||||
|
|
||||||
//Set state to be able to detect the moment when TX is done
|
//Set state to be able to detect the moment when TX is done
|
||||||
radioState.deviceState = RADIO_STATE_TX;
|
radioNode.deviceState = RADIO_STATE_TX;
|
||||||
|
|
||||||
transmitPayload = false;
|
transmitPayload = false;
|
||||||
}
|
}
|
||||||
@@ -615,18 +604,18 @@ void onReceive(int packetSize)
|
|||||||
* We can start reading only when radio is not reading.
|
* We can start reading only when radio is not reading.
|
||||||
* If not reading, then we might start
|
* If not reading, then we might start
|
||||||
*/
|
*/
|
||||||
if (radioState.bytesToRead == NO_DATA_TO_READ) {
|
if (radioNode.bytesToRead == NO_DATA_TO_READ) {
|
||||||
|
|
||||||
if (packetSize >= MIN_PACKET_SIZE && packetSize <= MAX_PACKET_SIZE) {
|
if (packetSize >= MIN_PACKET_SIZE && packetSize <= MAX_PACKET_SIZE) {
|
||||||
//We have a packet candidate that might contain a valid QSP packet
|
//We have a packet candidate that might contain a valid QSP packet
|
||||||
radioState.bytesToRead = packetSize;
|
radioNode.bytesToRead = packetSize;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
That packet was not very interesting, just flush it, we have no use
|
That packet was not very interesting, just flush it, we have no use
|
||||||
*/
|
*/
|
||||||
LoRa.sleep();
|
LoRa.sleep();
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
radioState.deviceState = RADIO_STATE_RX;
|
radioNode.deviceState = RADIO_STATE_RX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "variables.h"
|
||||||
|
|
||||||
void qspDecodeRcDataFrame(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceSate);
|
void qspDecodeRcDataFrame(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceSate);
|
||||||
void decodeRxHealthPayload(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceState);
|
void decodeRxHealthPayload(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceState);
|
||||||
|
|||||||
@@ -35,6 +35,32 @@ static uint8_t RadioNode::getPrevChannel(uint8_t channel) {
|
|||||||
return (RADIO_CHANNEL_COUNT + channel - RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
|
return (RADIO_CHANNEL_COUNT + channel - RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadioNode::readAndDecode(
|
||||||
|
volatile RadioState_t *radioState,
|
||||||
|
QspConfiguration_t *qsp,
|
||||||
|
RxDeviceState_t *rxDeviceState,
|
||||||
|
TxDeviceState_t *txDeviceState
|
||||||
|
) {
|
||||||
|
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
||||||
|
/*
|
||||||
|
* There is data to be read from radio!
|
||||||
|
*/
|
||||||
|
if (bytesToRead != NO_DATA_TO_READ) {
|
||||||
|
LoRa.read(tmpBuffer, bytesToRead);
|
||||||
|
|
||||||
|
for (int i = 0; i < bytesToRead; i++) {
|
||||||
|
qspDecodeIncomingFrame(qsp, tmpBuffer[i], rxDeviceState, txDeviceState, radioState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//After reading, flush radio buffer, we have no need for whatever might be over there
|
||||||
|
LoRa.sleep();
|
||||||
|
LoRa.receive();
|
||||||
|
|
||||||
|
deviceState = RADIO_STATE_RX;
|
||||||
|
bytesToRead = NO_DATA_TO_READ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RadioNode::hopFrequency(bool forward, uint8_t fromChannel, uint32_t timestamp) {
|
void RadioNode::hopFrequency(bool forward, uint8_t fromChannel, uint32_t timestamp) {
|
||||||
_channelEntryMillis = timestamp;
|
_channelEntryMillis = timestamp;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "qsp.h"
|
||||||
#ifndef RADIO_NODE_H
|
|
||||||
#define RADIO_NODE_H
|
|
||||||
|
|
||||||
#define RADIO_STATE_TX 1
|
|
||||||
#define RADIO_STATE_RX 2
|
|
||||||
|
|
||||||
#define TX_TRANSMIT_SLOT_RATE 67 //ms
|
|
||||||
#define RX_CHANNEL_DWELL_TIME (TX_TRANSMIT_SLOT_RATE + 10) //Dwell on a channel slightly longer
|
|
||||||
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
|
||||||
#define TX_FAILSAFE_DELAY (RX_FAILSAFE_DELAY * 4)
|
|
||||||
|
|
||||||
#define RADIO_FREQUENCY_MIN 868000000
|
#define RADIO_FREQUENCY_MIN 868000000
|
||||||
#define RADIO_FREQUENCY_MAX 870000000
|
#define RADIO_FREQUENCY_MAX 870000000
|
||||||
@@ -20,21 +10,10 @@
|
|||||||
#define RADIO_CHANNEL_COUNT 9 // 9 channels in 2MHz range (RADIO_FREQUENCY_RANGE/RADIO_CHANNEL_WIDTH) + 1
|
#define RADIO_CHANNEL_COUNT 9 // 9 channels in 2MHz range (RADIO_FREQUENCY_RANGE/RADIO_CHANNEL_WIDTH) + 1
|
||||||
#define RADIO_HOP_OFFSET 5
|
#define RADIO_HOP_OFFSET 5
|
||||||
|
|
||||||
struct RadioState_t {
|
#ifndef RADIO_NODE_H
|
||||||
uint32_t loraBandwidth = 250000;
|
#define RADIO_NODE_H
|
||||||
uint8_t loraSpreadingFactor = 7;
|
|
||||||
uint8_t loraCodingRate = 6;
|
|
||||||
uint8_t loraTxPower = 17; // Defines output power of TX, defined in dBm range from 2-17
|
|
||||||
int8_t bytesToRead = -1;
|
|
||||||
uint8_t rssi = 0;
|
|
||||||
uint8_t snr = 0;
|
|
||||||
uint8_t deviceState = RADIO_STATE_RX;
|
|
||||||
uint32_t nextTxCheckMillis = 0;
|
|
||||||
|
|
||||||
const uint32_t dwellTime = TX_TRANSMIT_SLOT_RATE * 2;
|
#include "variables.h"
|
||||||
uint8_t lastReceivedChannel = 0;
|
|
||||||
uint8_t failedDwellsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RadioNode {
|
class RadioNode {
|
||||||
public:
|
public:
|
||||||
@@ -45,8 +24,16 @@ class RadioNode {
|
|||||||
static uint8_t getNextChannel(uint8_t channel);
|
static uint8_t getNextChannel(uint8_t channel);
|
||||||
static uint8_t getPrevChannel(uint8_t channel);
|
static uint8_t getPrevChannel(uint8_t channel);
|
||||||
void hopFrequency(bool forward, uint8_t fromChannel, uint32_t timestamp);
|
void hopFrequency(bool forward, uint8_t fromChannel, uint32_t timestamp);
|
||||||
|
void readAndDecode(
|
||||||
|
volatile RadioState_t *radioState,
|
||||||
|
QspConfiguration_t *qsp,
|
||||||
|
RxDeviceState_t *rxDeviceState,
|
||||||
|
TxDeviceState_t *txDeviceState
|
||||||
|
);
|
||||||
uint8_t getChannel(void);
|
uint8_t getChannel(void);
|
||||||
uint32_t getChannelEntryMillis(void);
|
uint32_t getChannelEntryMillis(void);
|
||||||
|
int8_t bytesToRead = -1;
|
||||||
|
uint8_t deviceState = RADIO_STATE_RX;
|
||||||
private:
|
private:
|
||||||
uint8_t _channel = 0;
|
uint8_t _channel = 0;
|
||||||
uint32_t _channelEntryMillis = 0;
|
uint32_t _channelEntryMillis = 0;
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef VARIABLES_H
|
||||||
|
#define VARIABLES_H
|
||||||
|
|
||||||
|
#define RADIO_STATE_TX 1
|
||||||
|
#define RADIO_STATE_RX 2
|
||||||
|
|
||||||
|
#define TX_TRANSMIT_SLOT_RATE 67 //ms
|
||||||
|
#define RX_CHANNEL_DWELL_TIME (TX_TRANSMIT_SLOT_RATE + 10) //Dwell on a channel slightly longer
|
||||||
|
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
||||||
|
#define TX_FAILSAFE_DELAY (RX_FAILSAFE_DELAY * 4)
|
||||||
|
|
||||||
#define OLED_UPDATE_RATE 750
|
#define OLED_UPDATE_RATE 750
|
||||||
|
|
||||||
#define SBUS_UPDATE_RATE 15 //ms
|
#define SBUS_UPDATE_RATE 15 //ms
|
||||||
@@ -79,6 +90,20 @@ enum debugConfigFlags {
|
|||||||
|
|
||||||
#define NO_DATA_TO_READ -1
|
#define NO_DATA_TO_READ -1
|
||||||
|
|
||||||
|
struct RadioState_t {
|
||||||
|
uint32_t loraBandwidth = 250000;
|
||||||
|
uint8_t loraSpreadingFactor = 7;
|
||||||
|
uint8_t loraCodingRate = 6;
|
||||||
|
uint8_t loraTxPower = 17; // Defines output power of TX, defined in dBm range from 2-17
|
||||||
|
uint8_t rssi = 0;
|
||||||
|
uint8_t snr = 0;
|
||||||
|
uint32_t nextTxCheckMillis = 0;
|
||||||
|
|
||||||
|
const uint32_t dwellTime = TX_TRANSMIT_SLOT_RATE * 2;
|
||||||
|
uint8_t lastReceivedChannel = 0;
|
||||||
|
uint8_t failedDwellsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
struct TxDeviceState_t {
|
struct TxDeviceState_t {
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
uint32_t roundtrip = 0;
|
uint32_t roundtrip = 0;
|
||||||
@@ -117,3 +142,5 @@ struct QspConfiguration_t {
|
|||||||
uint32_t lastTxSlotTimestamp = 0;
|
uint32_t lastTxSlotTimestamp = 0;
|
||||||
bool transmitWindowOpen = false;
|
bool transmitWindowOpen = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user