diff --git a/.vscode/settings.json b/.vscode/settings.json index 36dbd1d..96b3b58 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,12 @@ "__locale": "c", "string": "c", "ios": "cpp", - "locale": "cpp" + "locale": "cpp", + "functional": "cpp", + "numeric": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "set": "cpp" }, "files.exclude": { "**/build": true diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index a8b49f9..4109ff0 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -102,9 +102,12 @@ void onQspSuccess(QspConfiguration_t *qsp, TxDeviceState_t *txDeviceState, RxDev * RX module hops to next channel after frame has been received */ #ifdef DEVICE_MODE_RX - radioNode.hopFrequency(true, radioNode.lastReceivedChannel, millis()); - radioNode.failedDwellsCount = 0; // We received a frame, so we can just reset this counter - LoRa.receive(); //Put radio back into receive mode + if (!platformNode.isBindMode) { + //We do not hop frequency in bind mode! + radioNode.hopFrequency(true, radioNode.lastReceivedChannel, millis()); + radioNode.failedDwellsCount = 0; // We received a frame, so we can just reset this counter + LoRa.receive(); //Put radio back into receive mode + } #endif //Store the last timestamp when frame was received @@ -269,8 +272,11 @@ void loop(void) #ifdef DEVICE_MODE_RX /* * This routine handles resync of TX/RX while hoppping frequencies + * When not in bind mode. Bind mode is single frequency operation */ - radioNode.handleChannelDwell(); + if (!plaformNode.isBindMode) { + radioNode.handleChannelDwell(); + } /* * Detect the moment when radio module stopped transmittig and put it @@ -302,7 +308,7 @@ void loop(void) serialRestartMillis = currentMillis; } - radioNode.handleTxDoneState(true); + radioNode.handleTxDoneState(!platformNode.isBindMode); #endif radioNode.readAndDecode( diff --git a/crossbow/platform_node.cpp b/crossbow/platform_node.cpp index d822fdd..90762c1 100644 --- a/crossbow/platform_node.cpp +++ b/crossbow/platform_node.cpp @@ -18,4 +18,21 @@ void PlatformNode::setRcChannel(uint8_t channel, int value, int offset) { if (channel < PLATFORM_TOTAL_CHANNEL_COUNT) { _channels[channel] = value + offset; } +} + +void PlatformNode::enterBindMode(void) { + isBindMode = true; + + // radioNode.set( + // 0, // Minimum power + // 125000, // 125kHz bandwidth + // 6, // low spreading factor, we do not need high RX sensitivity + // 5, // same for coding rate + // 868000000 //Fixed frequency while binding + // ); + +} + +void PlatformNode::leaveBindMode(void) { + isBindMode = false; } \ No newline at end of file diff --git a/crossbow/platform_node.h b/crossbow/platform_node.h index 6ac2737..0e8f5b4 100644 --- a/crossbow/platform_node.h +++ b/crossbow/platform_node.h @@ -21,9 +21,12 @@ class PlatformNode { PlatformNode(void); int getRcChannel(uint8_t channel); void setRcChannel(uint8_t channel, int value, int offset); + void enterBindMode(void); + void leaveBindMode(void); uint8_t bindKey[4]; uint32_t nextLedUpdate = 0; uint8_t platformState = DEVICE_STATE_UNDETERMINED; + bool isBindMode = false; private: volatile int _channels[PLATFORM_TOTAL_CHANNEL_COUNT]; }; diff --git a/crossbow/radio_node.cpp b/crossbow/radio_node.cpp index e6f0af5..df2dfbf 100644 --- a/crossbow/radio_node.cpp +++ b/crossbow/radio_node.cpp @@ -31,11 +31,14 @@ void RadioNode::init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int)) while (true); } - //Configure LoRa module - LoRa.setSignalBandwidth(loraBandwidth); - LoRa.setSpreadingFactor(loraSpreadingFactor); - LoRa.setCodingRate4(loraCodingRate); - LoRa.setTxPower(loraTxPower); + set( + loraTxPower, + loraBandwidth, + loraSpreadingFactor, + loraCodingRate, + getFrequencyForChannel(getChannel()) + ); + LoRa.enableCrc(); //Setup ISR callback and start receiving @@ -159,4 +162,21 @@ void RadioNode::handleTx(QspConfiguration_t *qsp) { //Set state to be able to detect the moment when TX is done radioState = RADIO_STATE_TX; +} + +void RadioNode::set( + uint8_t power, + long bandwidth, + uint8_t spreadingFactor, + uint8_t codingRate, + long frequency +) { + LoRa.sleep(); + + LoRa.setTxPower(power); + LoRa.setSignalBandwidth(bandwidth); + LoRa.setCodingRate4(codingRate); + LoRa.setFrequency(frequency); + + LoRa.idle(); } \ No newline at end of file diff --git a/crossbow/radio_node.h b/crossbow/radio_node.h index 6d3eca1..14b5f01 100644 --- a/crossbow/radio_node.h +++ b/crossbow/radio_node.h @@ -1,8 +1,5 @@ #pragma once -#include "Arduino.h" -#include "qsp.h" - #define RADIO_FREQUENCY_MIN 868000000 #define RADIO_FREQUENCY_MAX 870000000 #define RADIO_FREQUENCY_RANGE (RADIO_FREQUENCY_MAX-RADIO_FREQUENCY_MIN) @@ -13,6 +10,8 @@ #ifndef RADIO_NODE_H #define RADIO_NODE_H +#include "Arduino.h" +#include "qsp.h" #include "variables.h" class RadioNode { @@ -32,6 +31,13 @@ class RadioNode { void handleChannelDwell(void); void handleTxDoneState(bool hop); void handleTx(QspConfiguration_t *qsp); + void set( + uint8_t power, + long bandwidth, + uint8_t spreadingFactor, + uint8_t codingRate, + long frequency + ); volatile int8_t bytesToRead = -1; volatile uint8_t radioState = RADIO_STATE_RX; uint8_t rssi = 0;