RadioState removed
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -5,7 +5,10 @@
|
|||||||
"algorithm": "cpp",
|
"algorithm": "cpp",
|
||||||
"random": "cpp",
|
"random": "cpp",
|
||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"iterator": "cpp"
|
"iterator": "cpp",
|
||||||
|
"rope": "c",
|
||||||
|
"__locale": "c",
|
||||||
|
"string": "c"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/build": true
|
"**/build": true
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ Tactile button1(BUTTON_1_PIN);
|
|||||||
QspConfiguration_t qsp = {};
|
QspConfiguration_t qsp = {};
|
||||||
RxDeviceState_t rxDeviceState = {};
|
RxDeviceState_t rxDeviceState = {};
|
||||||
TxDeviceState_t txDeviceState = {};
|
TxDeviceState_t txDeviceState = {};
|
||||||
volatile RadioState_t radioState = {};
|
|
||||||
|
|
||||||
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
@@ -177,10 +176,10 @@ void setup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Configure LoRa module
|
//Configure LoRa module
|
||||||
LoRa.setSignalBandwidth(radioState.loraBandwidth);
|
LoRa.setSignalBandwidth(radioNode.loraBandwidth);
|
||||||
LoRa.setSpreadingFactor(radioState.loraSpreadingFactor);
|
LoRa.setSpreadingFactor(radioNode.loraSpreadingFactor);
|
||||||
LoRa.setCodingRate4(radioState.loraCodingRate);
|
LoRa.setCodingRate4(radioNode.loraCodingRate);
|
||||||
LoRa.setTxPower(radioState.loraTxPower);
|
LoRa.setTxPower(radioNode.loraTxPower);
|
||||||
LoRa.enableCrc();
|
LoRa.enableCrc();
|
||||||
|
|
||||||
//Setup ISR callback and start receiving
|
//Setup ISR callback and start receiving
|
||||||
@@ -210,7 +209,6 @@ void setup(void)
|
|||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
oled.init();
|
oled.init();
|
||||||
oled.page(
|
oled.page(
|
||||||
&radioState,
|
|
||||||
&rxDeviceState,
|
&rxDeviceState,
|
||||||
&txDeviceState,
|
&txDeviceState,
|
||||||
TX_PAGE_INIT
|
TX_PAGE_INIT
|
||||||
@@ -320,7 +318,6 @@ void loop(void)
|
|||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
oled.loop(
|
oled.loop(
|
||||||
&radioState,
|
|
||||||
&rxDeviceState,
|
&rxDeviceState,
|
||||||
&txDeviceState,
|
&txDeviceState,
|
||||||
&button0,
|
&button0,
|
||||||
@@ -355,26 +352,9 @@ void loop(void)
|
|||||||
* Detect the moment when radio module stopped transmittig and put it
|
* Detect the moment when radio module stopped transmittig and put it
|
||||||
* back in to receive state
|
* back in to receive state
|
||||||
*/
|
*/
|
||||||
if (
|
radioNode.handleTxDoneState();
|
||||||
currentMillis > radioState.nextTxCheckMillis &&
|
|
||||||
radioNode.deviceState == RADIO_STATE_TX &&
|
|
||||||
!LoRa.isTransmitting()
|
|
||||||
) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* In case of TX module, hop right now
|
|
||||||
*/
|
|
||||||
#ifdef DEVICE_MODE_TX
|
|
||||||
radioNode.hopFrequency(true, radioNode.getChannel(), millis());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LoRa.receive();
|
|
||||||
radioNode.deviceState = RADIO_STATE_RX;
|
|
||||||
radioState.nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
|
||||||
}
|
|
||||||
|
|
||||||
radioNode.readAndDecode(
|
radioNode.readAndDecode(
|
||||||
&radioState,
|
|
||||||
&qsp,
|
&qsp,
|
||||||
&rxDeviceState,
|
&rxDeviceState,
|
||||||
&txDeviceState
|
&txDeviceState
|
||||||
@@ -508,7 +488,7 @@ void loop(void)
|
|||||||
uint8_t size;
|
uint8_t size;
|
||||||
LoRa.beginPacket();
|
LoRa.beginPacket();
|
||||||
//Prepare packet
|
//Prepare packet
|
||||||
qspEncodeFrame(&qsp, &radioState, tmpBuffer, &size, radioNode.getChannel());
|
qspEncodeFrame(&qsp, tmpBuffer, &size, radioNode.getChannel());
|
||||||
//Sent it to radio in one SPI transaction
|
//Sent it to radio in one SPI transaction
|
||||||
LoRa.write(tmpBuffer, size);
|
LoRa.write(tmpBuffer, size);
|
||||||
LoRa.endPacketAsync();
|
LoRa.endPacketAsync();
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ void qspDecodeIncomingFrame(
|
|||||||
/**
|
/**
|
||||||
* Encode frame is corrent format and write to hardware
|
* Encode frame is corrent format and write to hardware
|
||||||
*/
|
*/
|
||||||
void qspEncodeFrame(QspConfiguration_t *qsp, volatile RadioState_t *radioState, uint8_t buffer[], uint8_t *size, uint8_t radioChannel) {
|
void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size, uint8_t radioChannel) {
|
||||||
//Salt CRC with bind key
|
//Salt CRC with bind key
|
||||||
qspInitCrc(qsp);
|
qspInitCrc(qsp);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ void qspDecodeIncomingFrame(
|
|||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
void qspClearPayload(QspConfiguration_t *qsp);
|
void qspClearPayload(QspConfiguration_t *qsp);
|
||||||
void qspEncodeFrame(QspConfiguration_t *qsp, volatile RadioState_t *radioState, uint8_t buffer[], uint8_t *size, uint8_t radioChannel);
|
void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size, uint8_t radioChannel);
|
||||||
|
|
||||||
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros);
|
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros);
|
||||||
@@ -36,7 +36,6 @@ static uint8_t RadioNode::getPrevChannel(uint8_t channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RadioNode::readAndDecode(
|
void RadioNode::readAndDecode(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
QspConfiguration_t *qsp,
|
QspConfiguration_t *qsp,
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
@@ -91,4 +90,25 @@ void RadioNode::handleChannelDwell(void) {
|
|||||||
hopFrequency(false, getChannel(), getChannelEntryMillis() + RX_CHANNEL_DWELL_TIME); //Start jumping in opposite direction to resync
|
hopFrequency(false, getChannel(), getChannelEntryMillis() + RX_CHANNEL_DWELL_TIME); //Start jumping in opposite direction to resync
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RadioNode::handleTxDoneState(void) {
|
||||||
|
uint32_t currentMillis = millis();
|
||||||
|
if (
|
||||||
|
currentMillis > nextTxCheckMillis &&
|
||||||
|
deviceState == RADIO_STATE_TX &&
|
||||||
|
!LoRa.isTransmitting()
|
||||||
|
) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In case of TX module, hop right now
|
||||||
|
*/
|
||||||
|
#ifdef DEVICE_MODE_TX
|
||||||
|
hopFrequency(true, getChannel(), currentMillis);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LoRa.receive();
|
||||||
|
deviceState = RADIO_STATE_RX;
|
||||||
|
nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,6 @@ class RadioNode {
|
|||||||
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(
|
void readAndDecode(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
QspConfiguration_t *qsp,
|
QspConfiguration_t *qsp,
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
@@ -33,15 +32,21 @@ class RadioNode {
|
|||||||
uint8_t getChannel(void);
|
uint8_t getChannel(void);
|
||||||
uint32_t getChannelEntryMillis(void);
|
uint32_t getChannelEntryMillis(void);
|
||||||
void handleChannelDwell(void);
|
void handleChannelDwell(void);
|
||||||
|
void handleTxDoneState();
|
||||||
int8_t bytesToRead = -1;
|
int8_t bytesToRead = -1;
|
||||||
uint8_t deviceState = RADIO_STATE_RX;
|
uint8_t deviceState = RADIO_STATE_RX;
|
||||||
uint8_t rssi = 0;
|
uint8_t rssi = 0;
|
||||||
uint8_t snr = 0;
|
uint8_t snr = 0;
|
||||||
uint8_t lastReceivedChannel = 0;
|
uint8_t lastReceivedChannel = 0;
|
||||||
uint8_t failedDwellsCount = 0;
|
uint8_t failedDwellsCount = 0;
|
||||||
|
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
|
||||||
private:
|
private:
|
||||||
uint8_t _channel = 0;
|
uint8_t _channel = 0;
|
||||||
uint32_t _channelEntryMillis = 0;
|
uint32_t _channelEntryMillis = 0;
|
||||||
|
uint32_t nextTxCheckMillis = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -13,7 +13,6 @@ void TxOled::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::loop(
|
void TxOled::loop(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState,
|
TxDeviceState_t *txDeviceState,
|
||||||
Tactile *button0,
|
Tactile *button0,
|
||||||
@@ -48,7 +47,6 @@ void TxOled::loop(
|
|||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
page(
|
page(
|
||||||
radioState,
|
|
||||||
rxDeviceState,
|
rxDeviceState,
|
||||||
txDeviceState,
|
txDeviceState,
|
||||||
pageSequence[_mainPageSequenceIndex]
|
pageSequence[_mainPageSequenceIndex]
|
||||||
@@ -58,26 +56,25 @@ void TxOled::loop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::page(
|
void TxOled::page(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState,
|
TxDeviceState_t *txDeviceState,
|
||||||
int page
|
int page
|
||||||
) {
|
) {
|
||||||
switch (page) {
|
switch (page) {
|
||||||
case TX_PAGE_INIT:
|
case TX_PAGE_INIT:
|
||||||
renderPageInit(radioState, rxDeviceState, txDeviceState);
|
renderPageInit(rxDeviceState, txDeviceState);
|
||||||
break;
|
break;
|
||||||
case TX_PAGE_STATS:
|
case TX_PAGE_STATS:
|
||||||
renderPageStats(radioState, rxDeviceState, txDeviceState);
|
renderPageStats(rxDeviceState, txDeviceState);
|
||||||
break;
|
break;
|
||||||
case TX_PAGE_PWR:
|
case TX_PAGE_PWR:
|
||||||
renderPagePwr(radioState, rxDeviceState, txDeviceState);
|
renderPagePwr(rxDeviceState, txDeviceState);
|
||||||
break;
|
break;
|
||||||
case TX_PAGE_BIND:
|
case TX_PAGE_BIND:
|
||||||
renderPageBind(radioState, rxDeviceState, txDeviceState);
|
renderPageBind(rxDeviceState, txDeviceState);
|
||||||
break;
|
break;
|
||||||
case TX_PAGE_MODE:
|
case TX_PAGE_MODE:
|
||||||
renderPageMode(radioState, rxDeviceState, txDeviceState);
|
renderPageMode(rxDeviceState, txDeviceState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -85,7 +82,6 @@ void TxOled::page(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::renderPagePwr(
|
void TxOled::renderPagePwr(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
) {
|
) {
|
||||||
@@ -99,14 +95,13 @@ void TxOled::renderPagePwr(
|
|||||||
//TODO content
|
//TODO content
|
||||||
_display.setCursor(0, 25);
|
_display.setCursor(0, 25);
|
||||||
_display.setTextSize(3);
|
_display.setTextSize(3);
|
||||||
_display.print(radioState->loraTxPower);
|
_display.print(radioNode.loraTxPower);
|
||||||
_display.print("dBm");
|
_display.print("dBm");
|
||||||
|
|
||||||
_display.display();
|
_display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::renderPageBind(
|
void TxOled::renderPageBind(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
) {
|
) {
|
||||||
@@ -123,7 +118,6 @@ void TxOled::renderPageBind(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::renderPageMode(
|
void TxOled::renderPageMode(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
) {
|
) {
|
||||||
@@ -142,7 +136,6 @@ void TxOled::renderPageMode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::renderPageStats(
|
void TxOled::renderPageStats(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
) {
|
) {
|
||||||
@@ -173,7 +166,6 @@ void TxOled::renderPageStats(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxOled::renderPageInit(
|
void TxOled::renderPageInit(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
) {
|
) {
|
||||||
@@ -183,22 +175,22 @@ void TxOled::renderPageInit(
|
|||||||
|
|
||||||
_display.setCursor(0, 0);
|
_display.setCursor(0, 0);
|
||||||
_display.print("Rdy ");
|
_display.print("Rdy ");
|
||||||
_display.print(radioState->loraTxPower);
|
_display.print(radioNode.loraTxPower);
|
||||||
_display.print("dBm");
|
_display.print("dBm");
|
||||||
|
|
||||||
_display.setTextSize(1);
|
_display.setTextSize(1);
|
||||||
_display.setCursor(0, 32);
|
_display.setCursor(0, 32);
|
||||||
_display.print("Bandwitdh: ");
|
_display.print("Bandwitdh: ");
|
||||||
_display.print(radioState->loraBandwidth / 1000);
|
_display.print(radioNode.loraBandwidth / 1000);
|
||||||
_display.print("kHz");
|
_display.print("kHz");
|
||||||
|
|
||||||
_display.setCursor(0, 42);
|
_display.setCursor(0, 42);
|
||||||
_display.print("SF: ");
|
_display.print("SF: ");
|
||||||
_display.print(radioState->loraSpreadingFactor);
|
_display.print(radioNode.loraSpreadingFactor);
|
||||||
|
|
||||||
_display.setCursor(64, 42);
|
_display.setCursor(64, 42);
|
||||||
_display.print("CR: ");
|
_display.print("CR: ");
|
||||||
_display.print(radioState->loraCodingRate);
|
_display.print(radioNode.loraCodingRate);
|
||||||
|
|
||||||
_display.setCursor(0, 52);
|
_display.setCursor(0, 52);
|
||||||
_display.print("Rate: ");
|
_display.print("Rate: ");
|
||||||
|
|||||||
@@ -35,14 +35,12 @@ class TxOled {
|
|||||||
TxOled(void);
|
TxOled(void);
|
||||||
void init();
|
void init();
|
||||||
void loop(
|
void loop(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState,
|
TxDeviceState_t *txDeviceState,
|
||||||
Tactile *button0,
|
Tactile *button0,
|
||||||
Tactile *button1
|
Tactile *button1
|
||||||
);
|
);
|
||||||
void page(
|
void page(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState,
|
TxDeviceState_t *txDeviceState,
|
||||||
int page
|
int page
|
||||||
@@ -50,27 +48,22 @@ class TxOled {
|
|||||||
private:
|
private:
|
||||||
Adafruit_SSD1306 _display;
|
Adafruit_SSD1306 _display;
|
||||||
void renderPageInit(
|
void renderPageInit(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
void renderPageStats(
|
void renderPageStats(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
void renderPagePwr(
|
void renderPagePwr(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
void renderPageBind(
|
void renderPageBind(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
void renderPageMode(
|
void renderPageMode(
|
||||||
volatile RadioState_t *radioState,
|
|
||||||
RxDeviceState_t *rxDeviceState,
|
RxDeviceState_t *rxDeviceState,
|
||||||
TxDeviceState_t *txDeviceState
|
TxDeviceState_t *txDeviceState
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -90,14 +90,6 @@ 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
|
|
||||||
uint32_t nextTxCheckMillis = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TxDeviceState_t {
|
struct TxDeviceState_t {
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
uint32_t roundtrip = 0;
|
uint32_t roundtrip = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user