Update Radiolib version to 7.1.0

This commit is contained in:
lewisxhe
2024-12-20 10:30:28 +08:00
parent ec34aea9f7
commit 7f7f0022fe
185 changed files with 5193 additions and 2116 deletions
+18
View File
@@ -260,6 +260,12 @@ int16_t APRSClient::sendFrame(char* destCallsign, uint8_t destSSID, char* info)
RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
RADIOLIB_AX25_PID_NO_LAYER_3, const_cast<char*>(info));
// optionally set repeaters
if(this->repCalls && this->repSSIDs && this->numReps) {
int16_t state = frameUI.setRepeaters(this->repCalls, this->repSSIDs, this->numReps);
RADIOLIB_ASSERT(state);
}
return(axClient->sendFrame(&frameUI));
} else if(this->phyLayer != nullptr) {
@@ -276,4 +282,16 @@ int16_t APRSClient::sendFrame(char* destCallsign, uint8_t destSSID, char* info)
return(RADIOLIB_ERR_WRONG_MODEM);
}
void APRSClient::useRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs, uint8_t numRepeaters) {
this->repCalls = repeaterCallsigns;
this->repSSIDs = repeaterSSIDs;
this->numReps = numRepeaters;
}
void APRSClient::dropRepeaters() {
this->repCalls = NULL;
this->repSSIDs = NULL;
this->numReps = 0;
}
#endif
+20
View File
@@ -144,6 +144,21 @@ class APRSClient {
*/
int16_t sendFrame(char* destCallsign, uint8_t destSSID, char* info);
/*!
\brief Set the repeater callsigns and SSIDs to be used by the frames sent by sendPosition, sendMicE or sendFrame.
\param repeaterCallsigns Array of repeater callsigns in the form of null-terminated C-strings.
\param repeaterSSIDs Array of repeater SSIDs.
\param numRepeaters Number of repeaters, maximum is 8.
\returns \ref status_codes
*/
void useRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs, uint8_t numRepeaters);
/*!
\brief Stop using repeaters.
\returns \ref status_codes
*/
void dropRepeaters();
#if !RADIOLIB_GODMODE
private:
#endif
@@ -153,6 +168,11 @@ class APRSClient {
// default APRS symbol (car)
char symbol = '>';
char table = '/';
// repeaters
char** repCalls = NULL;
uint8_t* repSSIDs = NULL;
uint8_t numReps = 0;
// source callsign when using APRS over LoRa
char src[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = { 0 };
+13 -11
View File
@@ -1,5 +1,7 @@
#include "AX25.h"
#include <string.h>
#if !RADIOLIB_EXCLUDE_AX25
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control)
@@ -369,7 +371,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
// flip bit order
for(size_t i = 0; i < frameBuffLen; i++) {
frameBuff[i] = Module::reflect(frameBuff[i], 8);
frameBuff[i] = rlb_reflect(frameBuff[i], 8);
}
// calculate
@@ -402,7 +404,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
uint16_t stuffedFrameBuffPos = stuffedFrameBuffLenBits + 7 - 2*(stuffedFrameBuffLenBits%8);
if((frameBuff[i] >> shift) & 0x01) {
// copy 1 and increment counter
SET_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos);
SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos);
stuffedFrameBuffLenBits++;
count++;
@@ -412,14 +414,14 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
stuffedFrameBuffPos = stuffedFrameBuffLenBits + 7 - 2*(stuffedFrameBuffLenBits%8);
// insert 0 and reset counter
CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos);
CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos);
stuffedFrameBuffLenBits++;
count = 0;
}
} else {
// copy 0 and reset counter
CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos);
CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos);
stuffedFrameBuffLenBits++;
count = 0;
}
@@ -454,20 +456,20 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
for(size_t i = preambleLen + 1; i < stuffedFrameBuffLen*8; i++) {
size_t currBitPos = i + 7 - 2*(i%8);
size_t prevBitPos = (i - 1) + 7 - 2*((i - 1)%8);
if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos)) {
if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos)) {
// bit is 1, no change, copy previous bit
if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, prevBitPos)) {
SET_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos);
if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, prevBitPos)) {
SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos);
} else {
CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos);
CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos);
}
} else {
// bit is 0, transition, copy inversion of the previous bit
if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, prevBitPos)) {
CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos);
if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, prevBitPos)) {
CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos);
} else {
SET_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos);
SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos);
}
}
}
@@ -3,9 +3,6 @@
#include "../../TypeDef.h"
#include "../../Module.h"
#if defined(RADIOLIB_BUILD_ARDUINO)
#include "../../ArduinoHal.h"
#endif
#if !RADIOLIB_EXCLUDE_BELL
@@ -3,9 +3,6 @@
#include "../../TypeDef.h"
#include "../../Module.h"
#if defined(RADIOLIB_BUILD_ARDUINO)
#include "../../ArduinoHal.h"
#endif
#include "../PhysicalLayer/PhysicalLayer.h"
+123 -72
View File
@@ -183,11 +183,12 @@ int16_t LoRaWANNode::sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort, u
eventUp->nbTrans = trans;
}
#if !RADIOLIB_STATIC_ONLY
delete[] uplinkMsg;
#endif
// if a hardware error occurred, return
if(state < RADIOLIB_ERR_NONE) {
#if !RADIOLIB_STATIC_ONLY
delete[] uplinkMsg;
#endif
return(state);
}
@@ -440,11 +441,19 @@ uint8_t* LoRaWANNode::getBufferSession() {
LoRaWANNode::hton<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_ADR_FCNT], this->adrFCnt);
LoRaWANNode::hton<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_FCNT_UP], this->fCntUp);
// store the enabled channels
uint64_t chMaskGrp0123 = 0;
uint32_t chMaskGrp45 = 0;
this->getChannelPlanMask(&chMaskGrp0123, &chMaskGrp45);
LoRaWANNode::hton<uint64_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_LINK_ADR] + 1, chMaskGrp0123);
LoRaWANNode::hton<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_LINK_ADR] + 9, chMaskGrp45);
// store the available/unused channels
uint16_t chMask = 0x0000;
(void)this->getAvailableChannels(&chMask);
LoRaWANNode::hton<uint16_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_AVAILABLE_CHANNELS], chMask);
// save the current uplink MAC command queue
// store the current uplink MAC command queue
memcpy(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_MAC_QUEUE], this->fOptsUp, RADIOLIB_LORAWAN_FHDR_FOPTS_MAX_LEN);
memcpy(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_MAC_QUEUE_LEN], &this->fOptsUpLen, 1);
@@ -679,6 +688,8 @@ int16_t LoRaWANNode::processJoinAccept(LoRaWANJoinEvent_t *joinEvent) {
// we can ignore that error
if(state != RADIOLIB_ERR_LORA_HEADER_DAMAGED) {
RADIOLIB_ASSERT(state);
} else {
state = RADIOLIB_ERR_NONE;
}
// check reply message type
@@ -930,6 +941,9 @@ int16_t LoRaWANNode::activateOTAA(uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent)
this->devNonce += 1;
LoRaWANNode::hton<uint16_t>(&this->bufferNonces[RADIOLIB_LORAWAN_NONCES_DEV_NONCE], this->devNonce);
// set the Time on Air of the JoinRequest
this->lastToA = this->phyLayer->getTimeOnAir(RADIOLIB_LORAWAN_JOIN_REQUEST_LEN) / 1000;
// configure Rx1 and Rx2 delay for JoinAccept message - these are re-configured once a valid JoinAccept is received
this->rxDelays[1] = RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_1_MS;
this->rxDelays[2] = RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_2_MS;
@@ -1384,11 +1398,11 @@ int16_t LoRaWANNode::receiveCommon(uint8_t dir, const LoRaWANChannel_t* dlChanne
}
// get the maximum allowed Time-on-Air of a packet given the current datarate
uint8_t maxPayLen = this->band->payloadLenMax[this->channels[RADIOLIB_LORAWAN_UPLINK].dr];
uint8_t maxPayLen = this->band->payloadLenMax[dlChannels[window].dr];
if(this->TS011) {
maxPayLen = RADIOLIB_MIN(maxPayLen, 230); // payload length is limited to 230 if under repeater
maxPayLen = RADIOLIB_MIN(maxPayLen, 222); // payload length is limited to 222 if under repeater
}
RadioLibTime_t tMax = this->phyLayer->getTimeOnAir(maxPayLen + 13); // mandatory FHDR is 12/13 bytes
RadioLibTime_t tMax = this->phyLayer->getTimeOnAir(maxPayLen + 13) / 1000; // mandatory FHDR is 12/13 bytes
bool downlinkComplete = true;
// wait for the DIO to fire indicating a downlink is received
@@ -1473,7 +1487,8 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, LoRaWANEvent_t* e
// check the address
uint32_t addr = LoRaWANNode::ntoh<uint32_t>(&downlinkMsg[RADIOLIB_LORAWAN_FHDR_DEV_ADDR_POS]);
if(addr != this->devAddr) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Device address mismatch, expected 0x%08X, got 0x%08X", this->devAddr, addr);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Device address mismatch, expected 0x%08lX, got 0x%08lX",
(unsigned long)this->devAddr, (unsigned long)addr);
#if !RADIOLIB_STATIC_ONLY
delete[] downlinkMsg;
#endif
@@ -1792,6 +1807,7 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, LoRaWANEvent_t* e
event->dir = RADIOLIB_LORAWAN_DOWNLINK;
event->confirmed = isConfirmedDown;
event->confirming = isConfirmingUp;
event->frmPending = (downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCTRL_POS] & RADIOLIB_LORAWAN_FCTRL_FRAME_PENDING) != 0;
event->datarate = this->channels[RADIOLIB_LORAWAN_DOWNLINK].dr;
event->freq = channels[event->dir].freq / 10000.0;
event->power = this->txPowerMax - this->txPowerSteps * 2;
@@ -1962,7 +1978,7 @@ bool LoRaWANNode::execMacCommand(uint8_t cid, uint8_t* optIn, uint8_t lenIn, uin
optIn[13] = this->nbTrans;
}
memcpy(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_LINK_ADR], optIn, lenIn);
return(true);
} break;
@@ -2340,11 +2356,11 @@ void LoRaWANNode::preprocessMacLinkAdr(uint8_t* mPtr, uint8_t cLen, uint8_t* mAd
}
break;
case 6:
// for dynamic bands: all channels ON (currently defined)
// for dynamic bands: all channels ON (that are currently defined)
// for fixed bands: all 125kHz channels ON, channel mask similar to ChMask = 4
// except for CN500: all 125kHz channels ON
// for dynamic bands: retrieve all defined channels
// for dynamic bands: retrieve all currently defined channels
// for fixed bands: cannot store all defined channels, so select a random one from each bank
this->getChannelPlanMask(&chMaskGrp0123, &chMaskGrp45);
if(this->band->bandType == RADIOLIB_LORAWAN_BAND_FIXED && this->band->bandNum != BandCN500) {
@@ -2752,11 +2768,19 @@ int16_t LoRaWANNode::setPhyProperties(const LoRaWANChannel_t* chnl, uint8_t dir,
return(state);
}
// TODO implement PhysicalLayer::setModem()
// get the currently configured modem from the radio
ModemType_t modem;
state = this->phyLayer->getModem(&modem);
RADIOLIB_ASSERT(state);
// set modem-dependent functions
switch(this->band->dataRates[chnl->dr] & RADIOLIB_LORAWAN_DATA_RATE_MODEM) {
case(RADIOLIB_LORAWAN_DATA_RATE_LORA):
this->modulation = RADIOLIB_LORAWAN_MODULATION_LORA;
if(modem != ModemType_t::LoRa) {
state = this->phyLayer->setModem(ModemType_t::LoRa);
RADIOLIB_ASSERT(state);
}
modem = ModemType_t::LoRa;
// downlink messages are sent with inverted IQ
if(dir == RADIOLIB_LORAWAN_DOWNLINK) {
state = this->phyLayer->invertIQ(true);
@@ -2765,22 +2789,33 @@ int16_t LoRaWANNode::setPhyProperties(const LoRaWANChannel_t* chnl, uint8_t dir,
}
RADIOLIB_ASSERT(state);
break;
case(RADIOLIB_LORAWAN_DATA_RATE_FSK):
this->modulation = RADIOLIB_LORAWAN_MODULATION_GFSK;
if(modem != ModemType_t::FSK) {
state = this->phyLayer->setModem(ModemType_t::FSK);
RADIOLIB_ASSERT(state);
}
modem = ModemType_t::FSK;
state = this->phyLayer->setDataShaping(RADIOLIB_SHAPING_1_0);
RADIOLIB_ASSERT(state);
state = this->phyLayer->setEncoding(RADIOLIB_ENCODING_WHITENING);
RADIOLIB_ASSERT(state);
break;
case(RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS):
this->modulation = RADIOLIB_LORAWAN_MODULATION_LR_FHSS;
if(modem != ModemType_t::LRFHSS) {
state = this->phyLayer->setModem(ModemType_t::LRFHSS);
RADIOLIB_ASSERT(state);
}
modem = ModemType_t::LRFHSS;
break;
default:
return(RADIOLIB_ERR_UNSUPPORTED);
}
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("");
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("PHY: Frequency %cL = %7.3f MHz", dir ? 'D' : 'U', chnl->freq / 10000.0);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("PHY: Frequency = %7.3f MHz, TX = %d dBm", chnl->freq / 10000.0, pwr);
state = this->phyLayer->setFrequency(chnl->freq / 10000.0);
RADIOLIB_ASSERT(state);
@@ -2796,40 +2831,37 @@ int16_t LoRaWANNode::setPhyProperties(const LoRaWANChannel_t* chnl, uint8_t dir,
state = this->phyLayer->setDataRate(dr);
RADIOLIB_ASSERT(state);
if(this->modulation == RADIOLIB_LORAWAN_MODULATION_GFSK) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("FSK: BR = %4.1f, TX = %d dBm, FD = %4.1f kHz",
dr.fsk.bitRate, pwr, dr.fsk.freqDev);
}
if(this->modulation == RADIOLIB_LORAWAN_MODULATION_LORA) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("LoRa: SF = %d, TX = %d dBm, BW = %5.1f kHz, CR = 4/%d",
dr.lora.spreadingFactor, pwr, dr.lora.bandwidth, dr.lora.codingRate);
}
// this only needs to be done once-ish
uint8_t syncWord[4] = { 0 };
uint8_t syncWordLen = 0;
size_t preLen = 0;
switch(this->modulation) {
case(RADIOLIB_LORAWAN_MODULATION_GFSK): {
switch(modem) {
case(ModemType_t::FSK): {
preLen = 8*RADIOLIB_LORAWAN_GFSK_PREAMBLE_LEN;
syncWord[0] = (uint8_t)(RADIOLIB_LORAWAN_GFSK_SYNC_WORD >> 16);
syncWord[1] = (uint8_t)(RADIOLIB_LORAWAN_GFSK_SYNC_WORD >> 8);
syncWord[2] = (uint8_t)RADIOLIB_LORAWAN_GFSK_SYNC_WORD;
syncWordLen = 3;
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("FSK: BR = %4.1f, FD = %4.1f kHz",
dr.fsk.bitRate, dr.fsk.freqDev);
} break;
case(RADIOLIB_LORAWAN_MODULATION_LORA): {
case(ModemType_t::LoRa): {
preLen = RADIOLIB_LORAWAN_LORA_PREAMBLE_LEN;
syncWord[0] = RADIOLIB_LORAWAN_LORA_SYNC_WORD;
syncWordLen = 1;
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("LoRa: SF = %d, BW = %5.1f kHz, CR = 4/%d, IQ: %c",
dr.lora.spreadingFactor, dr.lora.bandwidth, dr.lora.codingRate, dir ? 'D' : 'U');
} break;
case(RADIOLIB_LORAWAN_MODULATION_LR_FHSS): {
case(ModemType_t::LRFHSS): {
syncWord[0] = (uint8_t)(RADIOLIB_LORAWAN_LR_FHSS_SYNC_WORD >> 24);
syncWord[1] = (uint8_t)(RADIOLIB_LORAWAN_LR_FHSS_SYNC_WORD >> 16);
syncWord[2] = (uint8_t)(RADIOLIB_LORAWAN_LR_FHSS_SYNC_WORD >> 8);
syncWord[3] = (uint8_t)RADIOLIB_LORAWAN_LR_FHSS_SYNC_WORD;
syncWordLen = 4;
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("LR-FHSS: BW = 0x%02x, CR = 0x%02x kHz, grid = %c",
dr.lrFhss.bw, dr.lrFhss.cr, dr.lrFhss.narrowGrid ? 'N' : 'W');
} break;
default:
@@ -2843,7 +2875,7 @@ int16_t LoRaWANNode::setPhyProperties(const LoRaWANChannel_t* chnl, uint8_t dir,
if(pre) {
preLen = pre;
}
if(this->modulation != RADIOLIB_LORAWAN_MODULATION_LR_FHSS) {
if(modem != ModemType_t::LRFHSS) {
state = this->phyLayer->setPreambleLength(preLen);
}
return(state);
@@ -2885,7 +2917,9 @@ void LoRaWANNode::getChannelPlanMask(uint64_t* chMaskGrp0123, uint32_t* chMaskGr
*chMaskGrp0123 = 0;
*chMaskGrp45 = 0;
if(this->band->bandType == RADIOLIB_LORAWAN_BAND_DYNAMIC) {
// if there are any channels selected, create the mask from those channels
// channels are always selected for dynamic bands and/or when a device is active
if(this->band->bandType == RADIOLIB_LORAWAN_BAND_DYNAMIC || this->isActivated()) {
for(int i = 0; i < RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS; i++) {
uint8_t idx = this->channelPlan[RADIOLIB_LORAWAN_UPLINK][i].idx;
if(idx != RADIOLIB_LORAWAN_CHANNEL_INDEX_NONE) {
@@ -2896,6 +2930,8 @@ void LoRaWANNode::getChannelPlanMask(uint64_t* chMaskGrp0123, uint32_t* chMaskGr
}
}
}
return;
} else { // bandType == RADIOLIB_LORAWAN_BAND_FIXED
// if a subband is set, we can set the channel indices straight from subband
if(this->subBand > 0 && this->subBand <= 8) {
@@ -2906,9 +2942,9 @@ void LoRaWANNode::getChannelPlanMask(uint64_t* chMaskGrp0123, uint32_t* chMaskGr
// CN500 only: for sub band 9-12, set bank of 8 125kHz channels
*chMaskGrp45 |= 0xFF << ((this->subBand - 9) * 8);
} else {
// if subband is set to 0, all 125kHz channels are enabled
// however, we can 'only' store 16 channels, so we do not actually store these
// therefore, we select a random channel from each bank of 8 channels
// if subband is set to 0, all 125kHz channels are enabled.
// however, we can 'only' store 16 channels, so we don't use all channels at once.
// instead, we select a random channel from each bank of 8 channels + 1 from second plan.
uint8_t num125kHz = this->band->txSpans[0].numChannels;
uint8_t numBanks = num125kHz / 8;
for(uint8_t bank = 0; bank < numBanks; bank++) {
@@ -2992,10 +3028,6 @@ void LoRaWANNode::selectChannelPlanFix() {
// make all enabled channels available for uplink selection
this->setAvailableChannels(0xFFFF);
#if RADIOLIB_DEBUG_PROTOCOL
this->printChannels();
#endif
}
uint8_t LoRaWANNode::getAvailableChannels(uint16_t* chMask) {
@@ -3092,7 +3124,6 @@ int16_t LoRaWANNode::selectChannels() {
}
bool LoRaWANNode::applyChannelMask(uint64_t chMaskGrp0123, uint32_t chMaskGrp45) {
int num = 0;
if(this->band->bandType == RADIOLIB_LORAWAN_BAND_DYNAMIC) {
for(int i = 0; i < RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS; i++) {
if(chMaskGrp0123 & ((uint64_t)1 << i)) {
@@ -3106,7 +3137,12 @@ bool LoRaWANNode::applyChannelMask(uint64_t chMaskGrp0123, uint32_t chMaskGrp45)
}
}
} else { // bandType == RADIOLIB_LORAWAN_BAND_FIXED
// full channel mask received, so clear all existing channels
LoRaWANChannel_t chnl = RADIOLIB_LORAWAN_CHANNEL_NONE;
for(size_t i = 0; i < RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS; i++) {
this->channelPlan[RADIOLIB_LORAWAN_UPLINK][i] = chnl;
}
int num = 0;
uint8_t spanNum = 0;
int chNum = 0;
int chOfs = 0;
@@ -3188,7 +3224,8 @@ bool LoRaWANNode::verifyMIC(uint8_t* msg, size_t len, uint8_t* key) {
// calculate the expected value and compare
uint32_t micCalculated = generateMIC(msg, len - sizeof(uint32_t), key);
if(micCalculated != micReceived) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("MIC mismatch, expected %08x, got %08x", micCalculated, micReceived);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("MIC mismatch, expected %08lx, got %08lx",
(unsigned long)micCalculated, (unsigned long)micReceived);
return(false);
}
@@ -3222,12 +3259,12 @@ uint8_t LoRaWANNode::getMaxPayloadLen() {
RADIOLIB_LORAWAN_UPLINK,
this->txPowerMax - 2*this->txPowerSteps);
// mandatory FHDR is 12/13, so add & subtract 13 from calculations where necessary
uint8_t minLen = 0;
uint8_t maxLen = this->band->payloadLenMax[this->channels[RADIOLIB_LORAWAN_UPLINK].dr] + 13;
uint8_t maxLen = this->band->payloadLenMax[this->channels[RADIOLIB_LORAWAN_UPLINK].dr];
if(this->TS011) {
maxLen = RADIOLIB_MIN(maxLen, 230 + 13); // payload length is limited to 230 if under repeater
maxLen = RADIOLIB_MIN(maxLen, 222); // payload length is limited to N=222 if under repeater
}
maxLen += 13; // mandatory FHDR is 12/13 bytes
// if not limited by dwell-time, just return maximum
if(!this->dwellTimeEnabledUp) {
@@ -3262,10 +3299,13 @@ int16_t LoRaWANNode::findDataRate(uint8_t dr, DataRate_t* dataRate) {
return(state);
}
ModemType_t modemNew;
uint8_t dataRateBand = this->band->dataRates[dr];
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_MODEM) {
case(RADIOLIB_LORAWAN_DATA_RATE_LORA):
modemNew = ModemType_t::LoRa;
dataRate->lora.spreadingFactor = ((dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_SF) >> 3) + 7;
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_BW) {
case(RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ):
@@ -3283,18 +3323,55 @@ int16_t LoRaWANNode::findDataRate(uint8_t dr, DataRate_t* dataRate) {
dataRate->lora.codingRate = 5;
break;
case(RADIOLIB_LORAWAN_DATA_RATE_FSK):
modemNew = ModemType_t::FSK;
dataRate->fsk.bitRate = 50;
dataRate->fsk.freqDev = 25;
break;
case(RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS):
// not yet supported by DataRate_t
return(RADIOLIB_ERR_UNSUPPORTED);
modemNew = ModemType_t::LRFHSS;
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_BW) {
case(RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ):
dataRate->lrFhss.bw = 0x02; // specific encoding
dataRate->lrFhss.narrowGrid = 1;
break;
case(RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ):
dataRate->lrFhss.bw = 0x04; // specific encoding
dataRate->lrFhss.narrowGrid = 1;
break;
case(RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ):
dataRate->lrFhss.bw = 0x08; // specific encoding
dataRate->lrFhss.narrowGrid = 0;
break;
default:
return(RADIOLIB_ERR_UNSUPPORTED);
}
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_CR) {
case(RADIOLIB_LORAWAN_DATA_RATE_CR_1_3):
dataRate->lrFhss.cr = 0x03;
break;
case(RADIOLIB_LORAWAN_DATA_RATE_CR_2_3):
dataRate->lrFhss.cr = 0x01;
break;
default:
return(RADIOLIB_ERR_UNSUPPORTED);
}
break;
default:
return(RADIOLIB_ERR_UNSUPPORTED);
}
state = this->phyLayer->checkDataRate(*dataRate);
// get the currently configured modem from the radio
ModemType_t modemCurrent;
state = this->phyLayer->getModem(&modemCurrent);
RADIOLIB_ASSERT(state);
// if the required modem is different than the current one, change over
if(modemNew != modemCurrent) {
state = this->phyLayer->setModem(modemNew);
RADIOLIB_ASSERT(state);
}
state = this->phyLayer->checkDataRate(*dataRate);
return(state);
}
@@ -3373,30 +3450,4 @@ uint16_t LoRaWANNode::checkSum16(const uint8_t *key, uint16_t keyLen) {
return(checkSum);
}
template<typename T>
T LoRaWANNode::ntoh(uint8_t* buff, size_t size) {
uint8_t* buffPtr = buff;
size_t targetSize = sizeof(T);
if(size != 0) {
targetSize = size;
}
T res = 0;
for(size_t i = 0; i < targetSize; i++) {
res |= (uint32_t)(*(buffPtr++)) << 8*i;
}
return(res);
}
template<typename T>
void LoRaWANNode::hton(uint8_t* buff, T val, size_t size) {
uint8_t* buffPtr = buff;
size_t targetSize = sizeof(T);
if(size != 0) {
targetSize = size;
}
for(size_t i = 0; i < targetSize; i++) {
*(buffPtr++) = val >> 8*i;
}
}
#endif
+34 -12
View File
@@ -15,11 +15,6 @@
#define RADIOLIB_LORAWAN_CLASS_B (0x0B)
#define RADIOLIB_LORAWAN_CLASS_C (0x0C)
// modulation type
#define RADIOLIB_LORAWAN_MODULATION_LORA (0)
#define RADIOLIB_LORAWAN_MODULATION_GFSK (1)
#define RADIOLIB_LORAWAN_MODULATION_LR_FHSS (2)
// preamble format
#define RADIOLIB_LORAWAN_LORA_SYNC_WORD (0x34)
#define RADIOLIB_LORAWAN_LORA_PREAMBLE_LEN (8)
@@ -65,13 +60,14 @@
#define RADIOLIB_LORAWAN_DATA_RATE_SF_9 (0x02 << 3) // 5 3 SF9
#define RADIOLIB_LORAWAN_DATA_RATE_SF_8 (0x01 << 3) // 5 3 SF8
#define RADIOLIB_LORAWAN_DATA_RATE_SF_7 (0x00 << 3) // 5 3 SF7
#define RADIOLIB_LORAWAN_DATA_RATE_BW (0x03 << 1) // 2 1 bandwith mask
#define RADIOLIB_LORAWAN_DATA_RATE_BW (0x03 << 1) // 2 1 bandwidth mask
#define RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ (0x00 << 1) // 2 1 125 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ (0x01 << 1) // 2 1 250 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ (0x02 << 1) // 2 1 LoRa bandwidth: 500 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ (0x00 << 1) // 2 1 137 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ (0x01 << 1) // 2 1 336 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ (0x02 << 1) // 2 1 LR-FHSS bandwidth: 1523 kHz
#define RADIOLIB_LORAWAN_DATA_RATE_CR (0x01 << 0) // 0 0 coding rate mask
#define RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 (0x00 << 0) // 0 0 LR-FHSS coding rate: 1/3
#define RADIOLIB_LORAWAN_DATA_RATE_CR_2_3 (0x01 << 0) // 0 0 2/3
#define RADIOLIB_LORAWAN_DATA_RATE_UNUSED (0xFF << 0) // 7 0 unused data rate
@@ -385,7 +381,7 @@ struct LoRaWANBand_t {
/*! \brief Maximum allowed frequency (coded in 100 Hz steps) */
uint32_t freqMax;
/*! \brief Array of allowed maximum payload lengths for each data rate (global maximum) */
/*! \brief Array of allowed maximum application payload lengths for each data rate (N-value) */
uint8_t payloadLenMax[RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES];
/*! \brief Maximum allowed output power in this band in dBm */
@@ -504,6 +500,9 @@ struct LoRaWANEvent_t {
(e.g., server downlink reply to confirmed uplink sent by user application)*/
bool confirming;
/*! \brief Whether further downlink messages are pending on the server side. */
bool frmPending;
/*! \brief Datarate */
uint8_t datarate;
@@ -605,7 +604,7 @@ class LoRaWANNode {
\param initialDr The datarate at which to send the first uplink and any subsequent uplinks (unless ADR is enabled).
\returns \ref status_codes
*/
int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
virtual int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
/*! \brief Whether there is an ongoing session active */
bool isActivated();
@@ -913,9 +912,6 @@ class LoRaWANNode {
uint32_t confFCntDown = RADIOLIB_LORAWAN_FCNT_NONE;
uint32_t adrFCnt = 0;
// modulation of the currently configured channel
uint8_t modulation = RADIOLIB_LORAWAN_MODULATION_LORA;
// ADR is enabled by default
bool adrEnabled = true;
@@ -1069,7 +1065,7 @@ class LoRaWANNode {
// perform a single CAD operation for the under SF/CH combination. Returns either busy or otherwise.
bool cadChannelClear();
// get or create a complete 80-bit channel mask for current configuration
// (dynamic bands:) get or (fixed bands:) create a complete 80-bit channel mask for current configuration
void getChannelPlanMask(uint64_t* chMaskGrp0123, uint32_t* chMaskGrp45);
// setup uplink/downlink channel data rates and frequencies
@@ -1127,4 +1123,30 @@ class LoRaWANNode {
static void hton(uint8_t* buff, T val, size_t size = 0);
};
template<typename T>
T LoRaWANNode::ntoh(uint8_t* buff, size_t size) {
uint8_t* buffPtr = buff;
size_t targetSize = sizeof(T);
if(size != 0) {
targetSize = size;
}
T res = 0;
for(size_t i = 0; i < targetSize; i++) {
res |= (uint32_t)(*(buffPtr++)) << 8*i;
}
return(res);
}
template<typename T>
void LoRaWANNode::hton(uint8_t* buff, T val, size_t size) {
uint8_t* buffPtr = buff;
size_t targetSize = sizeof(T);
if(size != 0) {
targetSize = size;
}
for(size_t i = 0; i < targetSize; i++) {
*(buffPtr++) = val >> 8*i;
}
}
#endif
@@ -22,7 +22,7 @@ const LoRaWANBand_t EU868 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 8630000,
.freqMax = 8700000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 250, 58, 123, 58, 123, 0, 0, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 242, 242, 50, 115, 50, 115, 0, 0, 0 },
.powerMax = 16,
.powerNumSteps = 7,
.dutyCycle = 36000,
@@ -95,7 +95,7 @@ const LoRaWANBand_t US915 = {
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
.freqMin = 9020000,
.freqMax = 9280000,
.payloadLenMax = { 19, 61, 133, 250, 250, 58, 133, 0, 61, 137, 250, 250, 250, 250, 0 },
.payloadLenMax = { 11, 53, 125, 242, 242, 50, 125, 0, 53, 129, 242, 242, 242, 242, 0 },
.powerMax = 30,
.powerNumSteps = 10,
.dutyCycle = 0,
@@ -189,7 +189,7 @@ const LoRaWANBand_t EU433 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 4330000,
.freqMax = 4340000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 12,
.powerNumSteps = 5,
.dutyCycle = 36000,
@@ -262,7 +262,7 @@ const LoRaWANBand_t AU915 = {
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
.freqMin = 9150000,
.freqMax = 9280000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 58, 61, 137, 250, 250, 250, 250, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 242, 50, 53, 129, 242, 242, 242, 242, 0 },
.powerMax = 30,
.powerNumSteps = 10,
.dutyCycle = 0,
@@ -356,7 +356,7 @@ const LoRaWANBand_t CN500 = {
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
.freqMin = 4700000,
.freqMax = 5100000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 19,
.powerNumSteps = 7,
.dutyCycle = 0,
@@ -443,7 +443,7 @@ const LoRaWANBand_t AS923 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 9150000,
.freqMax = 9280000,
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 115, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 16,
.powerNumSteps = 7,
.dutyCycle = 36000,
@@ -516,7 +516,7 @@ const LoRaWANBand_t AS923_2 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 9150000,
.freqMax = 9280000,
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 115, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 16,
.powerNumSteps = 7,
.dutyCycle = 36000,
@@ -589,7 +589,7 @@ const LoRaWANBand_t AS923_3 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 9150000,
.freqMax = 9280000,
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 115, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 16,
.powerNumSteps = 7,
.dutyCycle = 36000,
@@ -662,7 +662,7 @@ const LoRaWANBand_t AS923_4 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 9170000,
.freqMax = 9200000,
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 115, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 16,
.powerNumSteps = 7,
.dutyCycle = 36000,
@@ -735,7 +735,7 @@ const LoRaWANBand_t KR920 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 9209000,
.freqMax = 9233000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 14,
.powerNumSteps = 7,
.dutyCycle = 0,
@@ -808,7 +808,7 @@ const LoRaWANBand_t IN865 = {
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
.freqMin = 8650000,
.freqMax = 8670000,
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 250, 0, 0, 0, 0, 0, 0, 0 },
.payloadLenMax = { 51, 51, 51, 115, 242, 242, 0, 242, 0, 0, 0, 0, 0, 0, 0 },
.powerMax = 30,
.powerNumSteps = 10,
.dutyCycle = 0,
+8 -8
View File
@@ -1,6 +1,8 @@
#include "Pager.h"
#include <string.h>
#include <math.h>
#if defined(ESP_PLATFORM)
#include "esp_attr.h"
#endif
@@ -177,7 +179,7 @@ int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t
// first insert the remainder from previous code word (if any)
if(remBits > 0) {
// this doesn't apply to BCD messages, so no need to check that here
uint8_t prev = Module::reflect(data[dataPos - 1], 8);
uint8_t prev = rlb_reflect(data[dataPos - 1], 8);
prev >>= 1;
msg[blockPos] |= (uint32_t)prev << (RADIOLIB_PAGER_CODE_WORD_LEN - 1 - remBits);
}
@@ -191,7 +193,7 @@ int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t
if(encoding == RADIOLIB_PAGER_BCD) {
symbol = encodeBCD(symbol);
}
symbol = Module::reflect(symbol, 8);
symbol = rlb_reflect(symbol, 8);
symbol >>= (8 - symbolLength);
// insert the next message symbol
@@ -205,7 +207,7 @@ int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t
uint8_t numSteps = (symbolPos - RADIOLIB_PAGER_FUNC_BITS_POS + symbolLength)/symbolLength;
for(uint8_t j = 0; j < numSteps; j++) {
symbol = encodeBCD(' ');
symbol = Module::reflect(symbol, 8);
symbol = rlb_reflect(symbol, 8);
symbol >>= (8 - symbolLength);
msg[blockPos] |= (uint32_t)symbol << symbolPos;
symbolPos -= symbolLength;
@@ -314,9 +316,7 @@ int16_t PagerClient::readData(String& str, size_t len, uint32_t* addr) {
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
#else
uint8_t* data = new uint8_t[length + 1];
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
RADIOLIB_ASSERT_PTR(data);
#endif
// read the received data
@@ -428,7 +428,7 @@ int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) {
uint32_t symbol = prevSymbol << (symbolLength - ovfBits) | currSymbol;
// finally, we can flip the bits
symbol = Module::reflect((uint8_t)symbol, 8);
symbol = rlb_reflect((uint8_t)symbol, 8);
symbol >>= (8 - symbolLength);
// decode BCD and we're done
@@ -446,7 +446,7 @@ int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) {
while(bitPos >= RADIOLIB_PAGER_MESSAGE_END_POS) {
// get the message symbol from the code word and reverse bits
uint32_t symbol = (cw & (0x7FUL << bitPos)) >> bitPos;
symbol = Module::reflect((uint8_t)symbol, 8);
symbol = rlb_reflect((uint8_t)symbol, 8);
symbol >>= (8 - symbolLength);
// decode BCD if needed
@@ -1,4 +1,5 @@
#include "PhysicalLayer.h"
#include <string.h>
PhysicalLayer::PhysicalLayer(float step, size_t maxLen) {
@@ -77,9 +78,7 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
} else {
data = new uint8_t[length + 1];
}
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
RADIOLIB_ASSERT_PTR(data);
#endif
// attempt packet reception
@@ -179,9 +178,7 @@ int16_t PhysicalLayer::readData(String& str, size_t len) {
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
#else
uint8_t* data = new uint8_t[length + 1];
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
RADIOLIB_ASSERT_PTR(data);
#endif
// read the received data
@@ -481,7 +478,7 @@ void PhysicalLayer::updateDirectBuffer(uint8_t bit) {
// check complete byte
if(this->bufferBitPos == 8) {
this->buffer[this->bufferWritePos] = Module::reflect(this->buffer[this->bufferWritePos], 8);
this->buffer[this->bufferWritePos] = rlb_reflect(this->buffer[this->bufferWritePos], 8);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("R\t%X", this->buffer[this->bufferWritePos]);
this->bufferWritePos++;
@@ -530,6 +527,16 @@ void PhysicalLayer::clearChannelScanAction() {
}
int16_t PhysicalLayer::setModem(ModemType_t modem) {
(void)modem;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::getModem(ModemType_t* modem) {
(void)modem;
return(RADIOLIB_ERR_UNSUPPORTED);
}
#if RADIOLIB_INTERRUPT_TIMING
void PhysicalLayer::setInterruptSetup(void (*func)(uint32_t)) {
Module* mod = getMod();
@@ -62,6 +62,9 @@ struct LrFhssRate_t {
/*! \brief Coding rate */
uint8_t cr;
/*! \brief Grid spacing */
bool narrowGrid;
};
/*!
@@ -74,6 +77,9 @@ union DataRate_t {
/*! \brief Interpretation for FSK modems */
FSKRate_t fsk;
/*! \brief Interpretation for LR-FHSS modems */
LrFhssRate_t lrFhss;
};
/*!
@@ -124,6 +130,16 @@ union ChannelScanConfig_t {
RSSIScanConfig_t rssi;
};
/*!
\enum ModemType_t
\brief Type of modem, used by setModem.
*/
enum ModemType_t {
FSK = 0,
LoRa,
LRFHSS,
};
/*!
\class PhysicalLayer
@@ -638,6 +654,21 @@ class PhysicalLayer {
*/
virtual void clearChannelScanAction();
/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set. Not all modems are implemented by all radio modules!
\returns \ref status_codes
*/
virtual int16_t setModem(ModemType_t modem);
/*!
\brief Get modem currently in use by the radio.
\param modem Pointer to a variable to save the retrieved configuration into.
\returns \ref status_codes
*/
virtual int16_t getModem(ModemType_t* modem);
#if RADIOLIB_INTERRUPT_TIMING
/*!
@@ -696,6 +727,7 @@ class PhysicalLayer {
friend class BellClient;
friend class FT8Client;
friend class LoRaWANNode;
friend class M17Client;
};
#endif