Init moved to RadioNode
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
* DEVICE_MODE_TX
|
||||
* DEVICE_MODE_RX
|
||||
*/
|
||||
// #define DEVICE_MODE_TX
|
||||
#define DEVICE_MODE_RX
|
||||
#define DEVICE_MODE_TX
|
||||
// #define DEVICE_MODE_RX
|
||||
|
||||
#define FEATURE_TX_OLED
|
||||
// #define FORCE_TX_WITHOUT_INPUT
|
||||
|
||||
@@ -87,8 +87,6 @@ QspConfiguration_t qsp = {};
|
||||
RxDeviceState_t rxDeviceState = {};
|
||||
TxDeviceState_t txDeviceState = {};
|
||||
|
||||
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
||||
|
||||
void onQspSuccess(QspConfiguration_t *qsp, TxDeviceState_t *txDeviceState, RxDeviceState_t *rxDeviceState, uint8_t receivedChannel) {
|
||||
//If recide received a valid frame, that means it can start to talk
|
||||
radioNode.lastReceivedChannel = receivedChannel;
|
||||
@@ -162,30 +160,7 @@ void setup(void)
|
||||
qsp.deviceState = DEVICE_STATE_OK;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Setup hardware
|
||||
*/
|
||||
LoRa.setPins(
|
||||
LORA_SS_PIN,
|
||||
LORA_RST_PIN,
|
||||
LORA_DI0_PIN
|
||||
);
|
||||
|
||||
if (!LoRa.begin(radioNode.getFrequencyForChannel(radioNode.getChannel()))) {
|
||||
while (true);
|
||||
}
|
||||
|
||||
//Configure LoRa module
|
||||
LoRa.setSignalBandwidth(radioNode.loraBandwidth);
|
||||
LoRa.setSpreadingFactor(radioNode.loraSpreadingFactor);
|
||||
LoRa.setCodingRate4(radioNode.loraCodingRate);
|
||||
LoRa.setTxPower(radioNode.loraTxPower);
|
||||
LoRa.enableCrc();
|
||||
|
||||
//Setup ISR callback and start receiving
|
||||
LoRa.onReceive(onReceive);
|
||||
LoRa.receive();
|
||||
radioNode.deviceState = RADIO_STATE_RX;
|
||||
radioNode.init(LORA_SS_PIN, LORA_RST_PIN, LORA_DI0_PIN, onReceive);
|
||||
|
||||
#ifdef DEVICE_MODE_RX
|
||||
//initiallize default ppm values
|
||||
@@ -485,17 +460,7 @@ void loop(void)
|
||||
|
||||
if (qsp.canTransmit && transmitPayload)
|
||||
{
|
||||
uint8_t size;
|
||||
LoRa.beginPacket();
|
||||
//Prepare packet
|
||||
qspEncodeFrame(&qsp, tmpBuffer, &size, radioNode.getChannel());
|
||||
//Sent it to radio in one SPI transaction
|
||||
LoRa.write(tmpBuffer, size);
|
||||
LoRa.endPacketAsync();
|
||||
|
||||
//Set state to be able to detect the moment when TX is done
|
||||
radioNode.deviceState = RADIO_STATE_TX;
|
||||
|
||||
radioNode.handleTx(&qsp);
|
||||
transmitPayload = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,33 @@ RadioNode::RadioNode(void) {
|
||||
|
||||
}
|
||||
|
||||
void RadioNode::init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int)) {
|
||||
/*
|
||||
* Setup hardware
|
||||
*/
|
||||
LoRa.setPins(
|
||||
ss,
|
||||
rst,
|
||||
di0
|
||||
);
|
||||
|
||||
if (!LoRa.begin(getFrequencyForChannel(getChannel()))) {
|
||||
while (true);
|
||||
}
|
||||
|
||||
//Configure LoRa module
|
||||
LoRa.setSignalBandwidth(loraBandwidth);
|
||||
LoRa.setSpreadingFactor(loraSpreadingFactor);
|
||||
LoRa.setCodingRate4(loraCodingRate);
|
||||
LoRa.setTxPower(loraTxPower);
|
||||
LoRa.enableCrc();
|
||||
|
||||
//Setup ISR callback and start receiving
|
||||
LoRa.onReceive(callback);
|
||||
LoRa.receive();
|
||||
deviceState = RADIO_STATE_RX;
|
||||
}
|
||||
|
||||
void RadioNode::readRssi(void)
|
||||
{
|
||||
rssi = 164 - constrain(LoRa.packetRssi() * -1, 0, 164);
|
||||
@@ -112,3 +139,18 @@ void RadioNode::handleTxDoneState(void) {
|
||||
nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
||||
}
|
||||
}
|
||||
|
||||
void RadioNode::handleTx(QspConfiguration_t *qsp) {
|
||||
uint8_t size;
|
||||
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
||||
|
||||
LoRa.beginPacket();
|
||||
//Prepare packet
|
||||
qspEncodeFrame(qsp, tmpBuffer, &size, getChannel());
|
||||
//Sent it to radio in one SPI transaction
|
||||
LoRa.write(tmpBuffer, size);
|
||||
LoRa.endPacketAsync();
|
||||
|
||||
//Set state to be able to detect the moment when TX is done
|
||||
deviceState = RADIO_STATE_TX;
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
class RadioNode {
|
||||
public:
|
||||
RadioNode(void);
|
||||
void init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int));
|
||||
void readRssi(void);
|
||||
void readSnr(void);
|
||||
static uint32_t getFrequencyForChannel(uint8_t channel);
|
||||
@@ -33,6 +34,7 @@ class RadioNode {
|
||||
uint32_t getChannelEntryMillis(void);
|
||||
void handleChannelDwell(void);
|
||||
void handleTxDoneState();
|
||||
void handleTx(QspConfiguration_t *qsp);
|
||||
int8_t bytesToRead = -1;
|
||||
uint8_t deviceState = RADIO_STATE_RX;
|
||||
uint8_t rssi = 0;
|
||||
|
||||
Reference in New Issue
Block a user