RadioState removed

This commit is contained in:
Pawel Spychalski
2018-05-16 13:36:22 +02:00
parent 0079264128
commit 948cc7915b
9 changed files with 49 additions and 64 deletions

View File

@@ -86,7 +86,6 @@ Tactile button1(BUTTON_1_PIN);
QspConfiguration_t qsp = {};
RxDeviceState_t rxDeviceState = {};
TxDeviceState_t txDeviceState = {};
volatile RadioState_t radioState = {};
uint8_t tmpBuffer[MAX_PACKET_SIZE];
@@ -177,10 +176,10 @@ void setup(void)
}
//Configure LoRa module
LoRa.setSignalBandwidth(radioState.loraBandwidth);
LoRa.setSpreadingFactor(radioState.loraSpreadingFactor);
LoRa.setCodingRate4(radioState.loraCodingRate);
LoRa.setTxPower(radioState.loraTxPower);
LoRa.setSignalBandwidth(radioNode.loraBandwidth);
LoRa.setSpreadingFactor(radioNode.loraSpreadingFactor);
LoRa.setCodingRate4(radioNode.loraCodingRate);
LoRa.setTxPower(radioNode.loraTxPower);
LoRa.enableCrc();
//Setup ISR callback and start receiving
@@ -210,7 +209,6 @@ void setup(void)
#ifdef FEATURE_TX_OLED
oled.init();
oled.page(
&radioState,
&rxDeviceState,
&txDeviceState,
TX_PAGE_INIT
@@ -320,7 +318,6 @@ void loop(void)
#ifdef FEATURE_TX_OLED
oled.loop(
&radioState,
&rxDeviceState,
&txDeviceState,
&button0,
@@ -355,26 +352,9 @@ void loop(void)
* Detect the moment when radio module stopped transmittig and put it
* back in to receive state
*/
if (
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.handleTxDoneState();
radioNode.readAndDecode(
&radioState,
&qsp,
&rxDeviceState,
&txDeviceState
@@ -508,7 +488,7 @@ void loop(void)
uint8_t size;
LoRa.beginPacket();
//Prepare packet
qspEncodeFrame(&qsp, &radioState, tmpBuffer, &size, radioNode.getChannel());
qspEncodeFrame(&qsp, tmpBuffer, &size, radioNode.getChannel());
//Sent it to radio in one SPI transaction
LoRa.write(tmpBuffer, size);
LoRa.endPacketAsync();

View File

@@ -222,7 +222,7 @@ void qspDecodeIncomingFrame(
/**
* 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
qspInitCrc(qsp);

View File

@@ -17,6 +17,6 @@ void qspDecodeIncomingFrame(
TxDeviceState_t *txDeviceState
);
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);

View File

@@ -36,7 +36,6 @@ static uint8_t RadioNode::getPrevChannel(uint8_t channel) {
}
void RadioNode::readAndDecode(
volatile RadioState_t *radioState,
QspConfiguration_t *qsp,
RxDeviceState_t *rxDeviceState,
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
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
}
}

View File

@@ -25,7 +25,6 @@ class RadioNode {
static uint8_t getPrevChannel(uint8_t channel);
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
@@ -33,15 +32,21 @@ class RadioNode {
uint8_t getChannel(void);
uint32_t getChannelEntryMillis(void);
void handleChannelDwell(void);
void handleTxDoneState();
int8_t bytesToRead = -1;
uint8_t deviceState = RADIO_STATE_RX;
uint8_t rssi = 0;
uint8_t snr = 0;
uint8_t lastReceivedChannel = 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:
uint8_t _channel = 0;
uint32_t _channelEntryMillis = 0;
uint32_t nextTxCheckMillis = 0;
};
#endif

View File

@@ -13,7 +13,6 @@ void TxOled::init() {
}
void TxOled::loop(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState,
Tactile *button0,
@@ -48,7 +47,6 @@ void TxOled::loop(
if (update) {
page(
radioState,
rxDeviceState,
txDeviceState,
pageSequence[_mainPageSequenceIndex]
@@ -58,26 +56,25 @@ void TxOled::loop(
}
void TxOled::page(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState,
int page
) {
switch (page) {
case TX_PAGE_INIT:
renderPageInit(radioState, rxDeviceState, txDeviceState);
renderPageInit(rxDeviceState, txDeviceState);
break;
case TX_PAGE_STATS:
renderPageStats(radioState, rxDeviceState, txDeviceState);
renderPageStats(rxDeviceState, txDeviceState);
break;
case TX_PAGE_PWR:
renderPagePwr(radioState, rxDeviceState, txDeviceState);
renderPagePwr(rxDeviceState, txDeviceState);
break;
case TX_PAGE_BIND:
renderPageBind(radioState, rxDeviceState, txDeviceState);
renderPageBind(rxDeviceState, txDeviceState);
break;
case TX_PAGE_MODE:
renderPageMode(radioState, rxDeviceState, txDeviceState);
renderPageMode(rxDeviceState, txDeviceState);
break;
}
@@ -85,7 +82,6 @@ void TxOled::page(
}
void TxOled::renderPagePwr(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
@@ -99,14 +95,13 @@ void TxOled::renderPagePwr(
//TODO content
_display.setCursor(0, 25);
_display.setTextSize(3);
_display.print(radioState->loraTxPower);
_display.print(radioNode.loraTxPower);
_display.print("dBm");
_display.display();
}
void TxOled::renderPageBind(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
@@ -123,7 +118,6 @@ void TxOled::renderPageBind(
}
void TxOled::renderPageMode(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
@@ -142,7 +136,6 @@ void TxOled::renderPageMode(
}
void TxOled::renderPageStats(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
@@ -173,7 +166,6 @@ void TxOled::renderPageStats(
}
void TxOled::renderPageInit(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
@@ -183,22 +175,22 @@ void TxOled::renderPageInit(
_display.setCursor(0, 0);
_display.print("Rdy ");
_display.print(radioState->loraTxPower);
_display.print(radioNode.loraTxPower);
_display.print("dBm");
_display.setTextSize(1);
_display.setCursor(0, 32);
_display.print("Bandwitdh: ");
_display.print(radioState->loraBandwidth / 1000);
_display.print(radioNode.loraBandwidth / 1000);
_display.print("kHz");
_display.setCursor(0, 42);
_display.print("SF: ");
_display.print(radioState->loraSpreadingFactor);
_display.print(radioNode.loraSpreadingFactor);
_display.setCursor(64, 42);
_display.print("CR: ");
_display.print(radioState->loraCodingRate);
_display.print(radioNode.loraCodingRate);
_display.setCursor(0, 52);
_display.print("Rate: ");

View File

@@ -35,14 +35,12 @@ class TxOled {
TxOled(void);
void init();
void loop(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState,
Tactile *button0,
Tactile *button1
);
void page(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState,
int page
@@ -50,27 +48,22 @@ class TxOled {
private:
Adafruit_SSD1306 _display;
void renderPageInit(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
);
void renderPageStats(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
);
void renderPagePwr(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
);
void renderPageBind(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
);
void renderPageMode(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
);

View File

@@ -90,14 +90,6 @@ enum debugConfigFlags {
#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 {
uint8_t flags = 0;
uint32_t roundtrip = 0;