diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index 4b53ad0..4cb0d94 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -54,7 +54,6 @@ RadioNode radioNode; volatile int16_t TxInput::channels[TX_INPUT_CHANNEL_COUNT]; - #include "txbuzzer.h" 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 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.readSnr(); @@ -193,7 +193,7 @@ void setup(void) /* * TX should start talking imediately after power up */ - qsp.canTransmit = true; + radioNode.canTransmit = true; pinMode(TX_BUZZER_PIN, OUTPUT); @@ -215,13 +215,6 @@ void setup(void) 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 */ @@ -458,10 +451,9 @@ void loop(void) #endif - if (qsp.canTransmit && transmitPayload) + if (transmitPayload) { radioNode.handleTx(&qsp); - transmitPayload = false; } #ifdef DEVICE_MODE_TX diff --git a/crossbow/radio_node.cpp b/crossbow/radio_node.cpp index 772dec8..fb9c09f 100644 --- a/crossbow/radio_node.cpp +++ b/crossbow/radio_node.cpp @@ -1,6 +1,18 @@ #include "radio_node.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) { } @@ -50,18 +62,6 @@ uint32_t RadioNode::getChannelEntryMillis(void) { 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( QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceState, @@ -91,15 +91,15 @@ void RadioNode::hopFrequency(bool forward, uint8_t fromChannel, uint32_t timesta _channelEntryMillis = timestamp; if (forward) { - _channel = RadioNode::getNextChannel(fromChannel); + _channel = getNextChannel(fromChannel); } else { - _channel = RadioNode::getPrevChannel(fromChannel); + _channel = getPrevChannel(fromChannel); } // And set hardware LoRa.sleep(); LoRa.setFrequency( - RadioNode::getFrequencyForChannel(_channel) + getFrequencyForChannel(_channel) ); LoRa.idle(); } @@ -142,6 +142,11 @@ void RadioNode::handleTxDoneState(bool hop) { } void RadioNode::handleTx(QspConfiguration_t *qsp) { + + if (!canTransmit) { + return; + } + uint8_t size; uint8_t tmpBuffer[MAX_PACKET_SIZE]; diff --git a/crossbow/radio_node.h b/crossbow/radio_node.h index e720c5c..b5670f7 100644 --- a/crossbow/radio_node.h +++ b/crossbow/radio_node.h @@ -21,9 +21,6 @@ class RadioNode { void init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int)); void readRssi(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 readAndDecode( QspConfiguration_t *qsp, @@ -45,6 +42,7 @@ class RadioNode { uint8_t loraSpreadingFactor = 7; uint8_t loraCodingRate = 6; uint8_t loraTxPower = 17; // Defines output power of TX, defined in dBm range from 2-17 + bool canTransmit = false; private: uint8_t _channel = 0; uint32_t _channelEntryMillis = 0; diff --git a/crossbow/sbus.cpp b/crossbow/sbus.cpp index 7eb0ef8..dac4fe0 100644 --- a/crossbow/sbus.cpp +++ b/crossbow/sbus.cpp @@ -143,9 +143,6 @@ void SbusInput::sbusRead() { static byte buffer[25]; static byte buffer_index = 0; - static uint32_t _decoderErrorFrames; - static uint32_t _goodFrames; - while (_serial.available()) { byte rx = _serial.read(); diff --git a/crossbow/variables.h b/crossbow/variables.h index 38570d5..e71dc4a 100644 --- a/crossbow/variables.h +++ b/crossbow/variables.h @@ -66,11 +66,6 @@ enum deviceStates { 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_CHANNEL_COUNT 10 @@ -121,9 +116,7 @@ struct QspConfiguration_t { uint8_t deviceState = DEVICE_STATE_UNDETERMINED; void (* onSuccessCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*, uint8_t receivedChannel); void (* onFailureCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*); - bool canTransmit = false; bool forcePongFrame = false; - uint8_t debugConfig = 0; uint32_t frameDecodingStartedAt = 0; uint32_t lastTxSlotTimestamp = 0; bool transmitWindowOpen = false;