[LoRaWAN] Added preliminary FSK support

This commit is contained in:
jgromes 2023-07-16 16:33:47 +02:00
parent 76ac7d3dad
commit d52c9e3183
2 changed files with 80 additions and 26 deletions

View file

@ -18,6 +18,7 @@ static void LoRaWANNodeOnDownlink(void) {
LoRaWANNode::LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band) { LoRaWANNode::LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band) {
this->phyLayer = phy; this->phyLayer = phy;
this->band = band; this->band = band;
this->FSK = false;
} }
void LoRaWANNode::wipe() { void LoRaWANNode::wipe() {
@ -83,9 +84,11 @@ int16_t LoRaWANNode::beginOTAA(uint64_t appEUI, uint64_t devEUI, uint8_t* nwkKey
// set the function that will be called when the reply is received // set the function that will be called when the reply is received
this->phyLayer->setPacketReceivedAction(LoRaWANNodeOnDownlink); this->phyLayer->setPacketReceivedAction(LoRaWANNodeOnDownlink);
// downlink messages are sent with interted IQ // downlink messages are sent with inverted IQ
state = this->phyLayer->invertIQ(true); if(!this->FSK) {
RADIOLIB_ASSERT(state); state = this->phyLayer->invertIQ(true);
RADIOLIB_ASSERT(state);
}
// start receiving // start receiving
uint32_t start = mod->hal->millis(); uint32_t start = mod->hal->millis();
@ -97,7 +100,9 @@ int16_t LoRaWANNode::beginOTAA(uint64_t appEUI, uint64_t devEUI, uint8_t* nwkKey
while(!downlinkReceived) { while(!downlinkReceived) {
if(mod->hal->millis() - start >= RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_2_MS + 2000) { if(mod->hal->millis() - start >= RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_2_MS + 2000) {
downlinkReceived = false; downlinkReceived = false;
this->phyLayer->invertIQ(false); if(!this->FSK) {
this->phyLayer->invertIQ(false);
}
return(RADIOLIB_ERR_RX_TIMEOUT); return(RADIOLIB_ERR_RX_TIMEOUT);
} }
} }
@ -105,8 +110,10 @@ int16_t LoRaWANNode::beginOTAA(uint64_t appEUI, uint64_t devEUI, uint8_t* nwkKey
// we have a message, reset the IQ inversion // we have a message, reset the IQ inversion
downlinkReceived = false; downlinkReceived = false;
this->phyLayer->clearPacketReceivedAction(); this->phyLayer->clearPacketReceivedAction();
state = this->phyLayer->invertIQ(false); if(!this->FSK) {
RADIOLIB_ASSERT(state); state = this->phyLayer->invertIQ(false);
RADIOLIB_ASSERT(state);
}
// build the buffer for the reply data // build the buffer for the reply data
uint8_t joinAcceptMsgEnc[RADIOLIB_LORAWAN_JOIN_ACCEPT_MAX_LEN]; uint8_t joinAcceptMsgEnc[RADIOLIB_LORAWAN_JOIN_ACCEPT_MAX_LEN];
@ -410,22 +417,30 @@ int16_t LoRaWANNode::configureChannel(uint8_t chan, uint8_t dr) {
RADIOLIB_DEBUG_PRINTLN("Data rate %02x", dataRateBand); RADIOLIB_DEBUG_PRINTLN("Data rate %02x", dataRateBand);
DataRate_t datr; DataRate_t datr;
uint8_t bw = dataRateBand & 0x03; if(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_FSK_50_K) {
switch(bw) { datr.fsk.bitRate = 50;
case(RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ): datr.fsk.freqDev = 25;
datr.lora.bandwidth = 125.0;
break; } else {
case(RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ): uint8_t bw = dataRateBand & 0x03;
datr.lora.bandwidth = 250.0; switch(bw) {
break; case(RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ):
case(RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ): datr.lora.bandwidth = 125.0;
datr.lora.bandwidth = 500.0; break;
break; case(RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ):
default: datr.lora.bandwidth = 250.0;
return(RADIOLIB_ERR_INVALID_BANDWIDTH); break;
case(RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ):
datr.lora.bandwidth = 500.0;
break;
default:
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
}
datr.lora.spreadingFactor = ((dataRateBand & 0x70) >> 4) + 6;
} }
datr.lora.spreadingFactor = ((dataRateBand & 0xF0) >> 4) + 6;
state = this->phyLayer->setDataRate(datr); state = this->phyLayer->setDataRate(datr);
return(state); return(state);
@ -465,17 +480,47 @@ int16_t LoRaWANNode::setPhyProperties() {
// TODO select channel span based on channel ID // TODO select channel span based on channel ID
// TODO select channel randomly // TODO select channel randomly
uint8_t channelId = 0; uint8_t channelId = 0;
int16_t state = this->configureChannel(channelId, this->band->defaultChannels[0].joinRequestDataRate); int16_t state = RADIOLIB_ERR_NONE;
if(this->FSK) {
state = this->phyLayer->setFrequency(this->band->fskFreq);
RADIOLIB_ASSERT(state);
DataRate_t dr;
dr.fsk.bitRate = 50;
dr.fsk.freqDev = 25;
state = this->phyLayer->setDataRate(dr);
RADIOLIB_ASSERT(state);
state = this->phyLayer->setDataShaping(RADIOLIB_SHAPING_1_0);
RADIOLIB_ASSERT(state);
state = this->phyLayer->setEncoding(RADIOLIB_ENCODING_WHITENING);
} else {
state = this->configureChannel(channelId, this->band->defaultChannels[0].joinRequestDataRate);
}
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
state = this->phyLayer->setOutputPower(this->band->powerMax); state = this->phyLayer->setOutputPower(this->band->powerMax);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
uint8_t syncWord = RADIOLIB_LORAWAN_LORA_SYNC_WORD; uint8_t syncWord[3] = { 0 };
state = this->phyLayer->setSyncWord(&syncWord, 1); uint8_t syncWordLen = 0;
size_t preLen = 0;
if(this->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;
} else {
preLen = RADIOLIB_LORAWAN_LORA_PREAMBLE_LEN;
syncWord[0] = RADIOLIB_LORAWAN_LORA_SYNC_WORD;
syncWordLen = 1;
}
state = this->phyLayer->setSyncWord(syncWord, syncWordLen);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
state = this->phyLayer->setPreambleLength(RADIOLIB_LORAWAN_LORA_PREAMBLE_LEN); state = this->phyLayer->setPreambleLength(preLen);
return(state); return(state);
} }

View file

@ -19,6 +19,7 @@ const LoRaWANBand_t EU868 = {
.powerMax = 16, .powerMax = 16,
.powerNumSteps = 7, .powerNumSteps = 7,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 868.8,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {
@ -85,6 +86,7 @@ const LoRaWANBand_t US915 = {
.powerMax = 30, .powerMax = 30,
.powerNumSteps = 10, .powerNumSteps = 10,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK,
.fskFreq = 0,
.numChannelSpans = 3, .numChannelSpans = 3,
.defaultChannels = { .defaultChannels = {
{ {
@ -197,6 +199,7 @@ const LoRaWANBand_t CN780 = {
.powerMax = 12, .powerMax = 12,
.powerNumSteps = 5, .powerNumSteps = 5,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 0,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {
@ -263,6 +266,7 @@ const LoRaWANBand_t EU433 = {
.powerMax = 12, .powerMax = 12,
.powerNumSteps = 5, .powerNumSteps = 5,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 0,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {
@ -329,6 +333,7 @@ const LoRaWANBand_t AU915 = {
.powerMax = 30, .powerMax = 30,
.powerNumSteps = 10, .powerNumSteps = 10,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK,
.fskFreq = 0,
.numChannelSpans = 3, .numChannelSpans = 3,
.defaultChannels = { .defaultChannels = {
{ {
@ -441,6 +446,7 @@ const LoRaWANBand_t CN500 = {
.powerMax = 19, .powerMax = 19,
.powerNumSteps = 7, .powerNumSteps = 7,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_MASK,
.fskFreq = 0,
.numChannelSpans = 2, .numChannelSpans = 2,
.defaultChannels = { .defaultChannels = {
{ {
@ -530,6 +536,7 @@ const LoRaWANBand_t AS923 = {
.powerMax = 16, .powerMax = 16,
.powerNumSteps = 7, .powerNumSteps = 7,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 921.8,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {
@ -596,6 +603,7 @@ const LoRaWANBand_t KR920 = {
.powerMax = 14, .powerMax = 14,
.powerNumSteps = 7, .powerNumSteps = 7,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 0,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {
@ -662,6 +670,7 @@ const LoRaWANBand_t IN865 = {
.powerMax = 30, .powerMax = 30,
.powerNumSteps = 10, .powerNumSteps = 10,
.cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES, .cfListType = RADIOLIB_LORAWAN_CFLIST_TYPE_FREQUENCIES,
.fskFreq = 0,
.numChannelSpans = 1, .numChannelSpans = 1,
.defaultChannels = { .defaultChannels = {
{ {