Some work, stuck by dependencies

This commit is contained in:
Pawel Spychalski
2018-05-23 11:45:48 +02:00
parent e240fbc412
commit 917b1514fd
6 changed files with 71 additions and 14 deletions

View File

@@ -10,7 +10,12 @@
"__locale": "c", "__locale": "c",
"string": "c", "string": "c",
"ios": "cpp", "ios": "cpp",
"locale": "cpp" "locale": "cpp",
"functional": "cpp",
"numeric": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"set": "cpp"
}, },
"files.exclude": { "files.exclude": {
"**/build": true "**/build": true

View File

@@ -102,9 +102,12 @@ void onQspSuccess(QspConfiguration_t *qsp, TxDeviceState_t *txDeviceState, RxDev
* RX module hops to next channel after frame has been received * RX module hops to next channel after frame has been received
*/ */
#ifdef DEVICE_MODE_RX #ifdef DEVICE_MODE_RX
radioNode.hopFrequency(true, radioNode.lastReceivedChannel, millis()); if (!platformNode.isBindMode) {
radioNode.failedDwellsCount = 0; // We received a frame, so we can just reset this counter //We do not hop frequency in bind mode!
LoRa.receive(); //Put radio back into receive 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 #endif
//Store the last timestamp when frame was received //Store the last timestamp when frame was received
@@ -269,8 +272,11 @@ void loop(void)
#ifdef DEVICE_MODE_RX #ifdef DEVICE_MODE_RX
/* /*
* This routine handles resync of TX/RX while hoppping frequencies * 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 * Detect the moment when radio module stopped transmittig and put it
@@ -302,7 +308,7 @@ void loop(void)
serialRestartMillis = currentMillis; serialRestartMillis = currentMillis;
} }
radioNode.handleTxDoneState(true); radioNode.handleTxDoneState(!platformNode.isBindMode);
#endif #endif
radioNode.readAndDecode( radioNode.readAndDecode(

View File

@@ -18,4 +18,21 @@ void PlatformNode::setRcChannel(uint8_t channel, int value, int offset) {
if (channel < PLATFORM_TOTAL_CHANNEL_COUNT) { if (channel < PLATFORM_TOTAL_CHANNEL_COUNT) {
_channels[channel] = value + offset; _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;
} }

View File

@@ -21,9 +21,12 @@ class PlatformNode {
PlatformNode(void); PlatformNode(void);
int getRcChannel(uint8_t channel); int getRcChannel(uint8_t channel);
void setRcChannel(uint8_t channel, int value, int offset); void setRcChannel(uint8_t channel, int value, int offset);
void enterBindMode(void);
void leaveBindMode(void);
uint8_t bindKey[4]; uint8_t bindKey[4];
uint32_t nextLedUpdate = 0; uint32_t nextLedUpdate = 0;
uint8_t platformState = DEVICE_STATE_UNDETERMINED; uint8_t platformState = DEVICE_STATE_UNDETERMINED;
bool isBindMode = false;
private: private:
volatile int _channels[PLATFORM_TOTAL_CHANNEL_COUNT]; volatile int _channels[PLATFORM_TOTAL_CHANNEL_COUNT];
}; };

View File

@@ -31,11 +31,14 @@ void RadioNode::init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int))
while (true); while (true);
} }
//Configure LoRa module set(
LoRa.setSignalBandwidth(loraBandwidth); loraTxPower,
LoRa.setSpreadingFactor(loraSpreadingFactor); loraBandwidth,
LoRa.setCodingRate4(loraCodingRate); loraSpreadingFactor,
LoRa.setTxPower(loraTxPower); loraCodingRate,
getFrequencyForChannel(getChannel())
);
LoRa.enableCrc(); LoRa.enableCrc();
//Setup ISR callback and start receiving //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 //Set state to be able to detect the moment when TX is done
radioState = RADIO_STATE_TX; 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();
} }

View File

@@ -1,8 +1,5 @@
#pragma once #pragma once
#include "Arduino.h"
#include "qsp.h"
#define RADIO_FREQUENCY_MIN 868000000 #define RADIO_FREQUENCY_MIN 868000000
#define RADIO_FREQUENCY_MAX 870000000 #define RADIO_FREQUENCY_MAX 870000000
#define RADIO_FREQUENCY_RANGE (RADIO_FREQUENCY_MAX-RADIO_FREQUENCY_MIN) #define RADIO_FREQUENCY_RANGE (RADIO_FREQUENCY_MAX-RADIO_FREQUENCY_MIN)
@@ -13,6 +10,8 @@
#ifndef RADIO_NODE_H #ifndef RADIO_NODE_H
#define RADIO_NODE_H #define RADIO_NODE_H
#include "Arduino.h"
#include "qsp.h"
#include "variables.h" #include "variables.h"
class RadioNode { class RadioNode {
@@ -32,6 +31,13 @@ class RadioNode {
void handleChannelDwell(void); void handleChannelDwell(void);
void handleTxDoneState(bool hop); void handleTxDoneState(bool hop);
void handleTx(QspConfiguration_t *qsp); 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 int8_t bytesToRead = -1;
volatile uint8_t radioState = RADIO_STATE_RX; volatile uint8_t radioState = RADIO_STATE_RX;
uint8_t rssi = 0; uint8_t rssi = 0;