minor state improvements

This commit is contained in:
Pawel Spychalski
2018-05-17 11:24:14 +02:00
parent 16a90adbc0
commit e915f30f1f
5 changed files with 25 additions and 40 deletions

View File

@@ -54,7 +54,6 @@ RadioNode radioNode;
volatile int16_t TxInput::channels[TX_INPUT_CHANNEL_COUNT]; volatile int16_t TxInput::channels[TX_INPUT_CHANNEL_COUNT];
#include "txbuzzer.h" #include "txbuzzer.h"
BuzzerState_t buzzer; BuzzerState_t buzzer;
@@ -91,7 +90,8 @@ void onQspSuccess(QspConfiguration_t *qsp, TxDeviceState_t *txDeviceState, RxDev
//If recide received a valid frame, that means it can start to talk //If recide received a valid frame, that means it can start to talk
radioNode.lastReceivedChannel = receivedChannel; radioNode.lastReceivedChannel = receivedChannel;
qsp->canTransmit = true; //RX can start transmitting only when an least one frame has been receiveds
radioNode.canTransmit = true;
radioNode.readRssi(); radioNode.readRssi();
radioNode.readSnr(); radioNode.readSnr();
@@ -193,7 +193,7 @@ void setup(void)
/* /*
* TX should start talking imediately after power up * TX should start talking imediately after power up
*/ */
qsp.canTransmit = true; radioNode.canTransmit = true;
pinMode(TX_BUZZER_PIN, OUTPUT); pinMode(TX_BUZZER_PIN, OUTPUT);
@@ -215,13 +215,6 @@ void setup(void)
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
#ifdef DEBUG_SERIAL
qsp.debugConfig |= DEBUG_FLAG_SERIAL;
#endif
#ifdef DEBUG_LED
qsp.debugConfig |= DEBUG_FLAG_LED;
#endif
/* /*
* Setup salt bind key * Setup salt bind key
*/ */
@@ -458,10 +451,9 @@ void loop(void)
#endif #endif
if (qsp.canTransmit && transmitPayload) if (transmitPayload)
{ {
radioNode.handleTx(&qsp); radioNode.handleTx(&qsp);
transmitPayload = false;
} }
#ifdef DEVICE_MODE_TX #ifdef DEVICE_MODE_TX

View File

@@ -1,6 +1,18 @@
#include "radio_node.h" #include "radio_node.h"
#include "lora.h" #include "lora.h"
uint32_t getFrequencyForChannel(uint8_t channel) {
return RADIO_FREQUENCY_MIN + (RADIO_CHANNEL_WIDTH * channel);
}
uint8_t getNextChannel(uint8_t channel) {
return (channel + RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
}
uint8_t getPrevChannel(uint8_t channel) {
return (RADIO_CHANNEL_COUNT + channel - RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
}
RadioNode::RadioNode(void) { RadioNode::RadioNode(void) {
} }
@@ -50,18 +62,6 @@ uint32_t RadioNode::getChannelEntryMillis(void) {
return _channelEntryMillis; return _channelEntryMillis;
} }
uint32_t RadioNode::getFrequencyForChannel(uint8_t channel) {
return RADIO_FREQUENCY_MIN + (RADIO_CHANNEL_WIDTH * channel);
}
uint8_t RadioNode::getNextChannel(uint8_t channel) {
return (channel + RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
}
uint8_t RadioNode::getPrevChannel(uint8_t channel) {
return (RADIO_CHANNEL_COUNT + channel - RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT;
}
void RadioNode::readAndDecode( void RadioNode::readAndDecode(
QspConfiguration_t *qsp, QspConfiguration_t *qsp,
RxDeviceState_t *rxDeviceState, RxDeviceState_t *rxDeviceState,
@@ -91,15 +91,15 @@ void RadioNode::hopFrequency(bool forward, uint8_t fromChannel, uint32_t timesta
_channelEntryMillis = timestamp; _channelEntryMillis = timestamp;
if (forward) { if (forward) {
_channel = RadioNode::getNextChannel(fromChannel); _channel = getNextChannel(fromChannel);
} else { } else {
_channel = RadioNode::getPrevChannel(fromChannel); _channel = getPrevChannel(fromChannel);
} }
// And set hardware // And set hardware
LoRa.sleep(); LoRa.sleep();
LoRa.setFrequency( LoRa.setFrequency(
RadioNode::getFrequencyForChannel(_channel) getFrequencyForChannel(_channel)
); );
LoRa.idle(); LoRa.idle();
} }
@@ -142,6 +142,11 @@ void RadioNode::handleTxDoneState(bool hop) {
} }
void RadioNode::handleTx(QspConfiguration_t *qsp) { void RadioNode::handleTx(QspConfiguration_t *qsp) {
if (!canTransmit) {
return;
}
uint8_t size; uint8_t size;
uint8_t tmpBuffer[MAX_PACKET_SIZE]; uint8_t tmpBuffer[MAX_PACKET_SIZE];

View File

@@ -21,9 +21,6 @@ class RadioNode {
void init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int)); void init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int));
void readRssi(void); void readRssi(void);
void readSnr(void); void readSnr(void);
uint32_t getFrequencyForChannel(uint8_t channel);
uint8_t getNextChannel(uint8_t channel);
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(
QspConfiguration_t *qsp, QspConfiguration_t *qsp,
@@ -45,6 +42,7 @@ class RadioNode {
uint8_t loraSpreadingFactor = 7; uint8_t loraSpreadingFactor = 7;
uint8_t loraCodingRate = 6; uint8_t loraCodingRate = 6;
uint8_t loraTxPower = 17; // Defines output power of TX, defined in dBm range from 2-17 uint8_t loraTxPower = 17; // Defines output power of TX, defined in dBm range from 2-17
bool canTransmit = false;
private: private:
uint8_t _channel = 0; uint8_t _channel = 0;
uint32_t _channelEntryMillis = 0; uint32_t _channelEntryMillis = 0;

View File

@@ -143,9 +143,6 @@ void SbusInput::sbusRead() {
static byte buffer[25]; static byte buffer[25];
static byte buffer_index = 0; static byte buffer_index = 0;
static uint32_t _decoderErrorFrames;
static uint32_t _goodFrames;
while (_serial.available()) { while (_serial.available()) {
byte rx = _serial.read(); byte rx = _serial.read();

View File

@@ -66,11 +66,6 @@ enum deviceStates {
DEVICE_STATE_UNDETERMINED DEVICE_STATE_UNDETERMINED
}; };
enum debugConfigFlags {
DEBUG_FLAG_SERIAL = 0b00000001,
DEBUG_FLAG_LED = 0b00000010
};
#define PPM_INPUT_PIN 0 // Has to be one of Interrupt pins #define PPM_INPUT_PIN 0 // Has to be one of Interrupt pins
#define PPM_INPUT_CHANNEL_COUNT 10 #define PPM_INPUT_CHANNEL_COUNT 10
@@ -121,9 +116,7 @@ struct QspConfiguration_t {
uint8_t deviceState = DEVICE_STATE_UNDETERMINED; uint8_t deviceState = DEVICE_STATE_UNDETERMINED;
void (* onSuccessCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*, uint8_t receivedChannel); void (* onSuccessCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*, uint8_t receivedChannel);
void (* onFailureCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*); void (* onFailureCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*);
bool canTransmit = false;
bool forcePongFrame = false; bool forcePongFrame = false;
uint8_t debugConfig = 0;
uint32_t frameDecodingStartedAt = 0; uint32_t frameDecodingStartedAt = 0;
uint32_t lastTxSlotTimestamp = 0; uint32_t lastTxSlotTimestamp = 0;
bool transmitWindowOpen = false; bool transmitWindowOpen = false;