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

@@ -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(

View File

@@ -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;
}

View File

@@ -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];
};

View File

@@ -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();
}

View File

@@ -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;