LoRaMAC  4.4.5
Documentation of the API
RegionCommon.h
Go to the documentation of this file.
1 
37 #ifndef __REGIONCOMMON_H__
38 #define __REGIONCOMMON_H__
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
45 #include "LoRaMacTypes.h"
46 #include "LoRaMacHeaderTypes.h"
47 #include "region/Region.h"
48 
49 // Constants that are common to all the regions.
50 
54 #define REGION_COMMON_DEFAULT_RECEIVE_DELAY1 1000
55 
59 #define REGION_COMMON_DEFAULT_RECEIVE_DELAY2 ( REGION_COMMON_DEFAULT_RECEIVE_DELAY1 + 1000 )
60 
64 #define REGION_COMMON_DEFAULT_JOIN_ACCEPT_DELAY1 5000
65 
69 #define REGION_COMMON_DEFAULT_JOIN_ACCEPT_DELAY2 ( REGION_COMMON_DEFAULT_JOIN_ACCEPT_DELAY1 + 1000 )
70 
74 #define REGION_COMMON_DEFAULT_ADR_ACK_LIMIT 64
75 
79 #define REGION_COMMON_DEFAULT_ADR_ACK_DELAY 32
80 
84 #define REGION_COMMON_DEFAULT_MAX_FCNT_GAP 16384
85 
89 #define REGION_COMMON_DEFAULT_ACK_TIMEOUT 2000
90 
95 #define REGION_COMMON_DEFAULT_ACK_TIMEOUT_RND 1000
96 
100 #define REGION_COMMON_DEFAULT_RX1_DR_OFFSET 0
101 
105 #define REGION_COMMON_DEFAULT_DOWNLINK_DWELL_TIME 0
106 
113 #define REGION_COMMON_DEFAULT_PING_SLOT_PERIODICITY 7
114 
115 typedef struct sRegionCommonLinkAdrParams
116 {
120  uint8_t NbRep;
124  int8_t Datarate;
128  int8_t TxPower;
132  uint8_t ChMaskCtrl;
136  uint16_t ChMask;
138 
139 typedef struct sRegionCommonLinkAdrReqVerifyParams
140 {
144  Version_t Version;
148  uint8_t Status;
156  int8_t Datarate;
160  int8_t TxPower;
164  uint8_t NbRep;
176  int8_t CurrentNbRep;
180  uint8_t NbChannels;
184  uint16_t* ChannelsMask;
188  int8_t MinDatarate;
192  int8_t MaxDatarate;
200  int8_t MinTxPower;
204  int8_t MaxTxPower;
206 
207 typedef struct sRegionCommonRxBeaconSetupParams
208 {
212  const uint8_t* Datarates;
216  uint32_t Frequency;
220  uint8_t BeaconSize;
224  uint8_t BeaconDatarate;
232  uint32_t RxTime;
236  uint16_t SymbolTimeout;
238 
239 typedef struct sRegionCommonCountNbOfEnabledChannelsParams
240 {
244  bool Joined;
248  uint8_t Datarate;
252  uint16_t* ChannelsMask;
264  uint16_t MaxNbChannels;
270  uint16_t* JoinChannels;
272 
273 typedef struct sRegionCommonIdentifyChannelsParam
274 {
278  TimerTime_t AggrTimeOff;
282  TimerTime_t LastAggrTx;
290  uint8_t MaxBands;
302  TimerTime_t ExpectedTimeOnAir;
308 
309 typedef struct sRegionCommonSetDutyCycleParams
310 {
314  TimerTime_t DutyCycleTimePeriod;
318  uint8_t MaxBands;
324 
337 uint8_t RegionCommonValueInRange( int8_t value, int8_t min, int8_t max );
338 
357 bool RegionCommonChanVerifyDr( uint8_t nbChannels, uint16_t* channelsMask, int8_t dr,
358  int8_t minDr, int8_t maxDr, ChannelParams_t* channels );
359 
372 bool RegionCommonChanDisable( uint16_t* channelsMask, uint8_t id, uint8_t maxChannels );
373 
386 uint8_t RegionCommonCountChannels( uint16_t* channelsMask, uint8_t startIdx, uint8_t stopIdx );
387 
398 void RegionCommonChanMaskCopy( uint16_t* channelsMaskDest, uint16_t* channelsMaskSrc, uint8_t len );
399 
412 void RegionCommonSetBandTxDone( Band_t* band, TimerTime_t lastTxAirTime, bool joined, SysTime_t elapsedTimeSinceStartup );
413 
434 TimerTime_t RegionCommonUpdateBandTimeOff( bool joined, Band_t* bands,
435  uint8_t nbBands, bool dutyCycleEnabled,
436  bool lastTxIsJoinRequest, SysTime_t elapsedTimeSinceStartup,
437  TimerTime_t expectedTimeOnAir );
438 
451 uint8_t RegionCommonParseLinkAdrReq( uint8_t* payload, RegionCommonLinkAdrParams_t* parseLinkAdr );
452 
467 uint8_t RegionCommonLinkAdrReqVerifyParams( RegionCommonLinkAdrReqVerifyParams_t* verifyParams, int8_t* dr, int8_t* txPow, uint8_t* nbRep );
468 
478 uint32_t RegionCommonComputeSymbolTimeLoRa( uint8_t phyDr, uint32_t bandwidthInHz );
479 
487 uint32_t RegionCommonComputeSymbolTimeFsk( uint8_t phyDrInKbps );
488 
505 void RegionCommonComputeRxWindowParameters( uint32_t tSymbolInUs, uint8_t minRxSymbols, uint32_t rxErrorInMs, uint32_t wakeUpTimeInMs, uint32_t* windowTimeoutInSymbols, int32_t* windowOffsetInMs );
506 
522 int8_t RegionCommonComputeTxPower( int8_t txPowerIndex, float maxEirp, float antennaGain );
523 
530 
545  uint8_t* enabledChannels, uint8_t* nbEnabledChannels, uint8_t* nbRestrictedChannels );
546 
569  TimerTime_t* aggregatedTimeOff, uint8_t* enabledChannels,
570  uint8_t* nbEnabledChannels, uint8_t* nbRestrictedChannels,
571  TimerTime_t* nextTxDelay );
572 
582 int8_t RegionCommonGetNextLowerTxDr( int8_t dr, int8_t minDr );
583 
593 int8_t RegionCommonLimitTxPower( int8_t txPower, int8_t maxBandTxPower );
594 
604 uint32_t RegionCommonGetBandwidth( uint32_t drIndex, const uint32_t* bandwidths );
605 
608 #ifdef __cplusplus
609 }
610 #endif
611 
612 #endif // __REGIONCOMMON_H__
RegionCommonLinkAdrReqVerifyParams_t::ChannelsMask
uint16_t * ChannelsMask
Definition: RegionCommon.h:184
RegionCommonIdentifyChannelsParam_t::DutyCycleEnabled
bool DutyCycleEnabled
Definition: RegionCommon.h:286
Region.h
Region implementation.
RegionCommonCountChannels
uint8_t RegionCommonCountChannels(uint16_t *channelsMask, uint8_t startIdx, uint8_t stopIdx)
Counts the number of active channels in a given channels mask. This is a generic function and valid f...
RegionCommonLinkAdrParams_t::TxPower
int8_t TxPower
Definition: RegionCommon.h:128
RegionCommonLinkAdrReqVerifyParams_t::MaxDatarate
int8_t MaxDatarate
Definition: RegionCommon.h:192
RegionCommonLinkAdrReqVerifyParams_t::CurrentNbRep
int8_t CurrentNbRep
Definition: RegionCommon.h:176
RegionCommonComputeTxPower
int8_t RegionCommonComputeTxPower(int8_t txPowerIndex, float maxEirp, float antennaGain)
Computes the txPower, based on the max EIRP and the antenna gain.
LoRaMacHeaderTypes.h
LoRa MAC layer header type definitions.
RegionCommonIdentifyChannelsParam_t::LastTxIsJoinRequest
bool LastTxIsJoinRequest
Definition: RegionCommon.h:298
RegionCommonValueInRange
uint8_t RegionCommonValueInRange(int8_t value, int8_t min, int8_t max)
Verifies, if a value is in a given range. This is a generic function and valid for all regions.
LoRaMacStatus_t
LoRaMacStatus_t
Definition: LoRaMac.h:2153
RegionCommonLinkAdrReqVerifyParams_t::CurrentDatarate
int8_t CurrentDatarate
Definition: RegionCommon.h:168
RegionCommonRxBeaconSetupParams_t::BeaconSize
uint8_t BeaconSize
Definition: RegionCommon.h:220
RegionCommonLinkAdrReqVerifyParams_t::Status
uint8_t Status
Definition: RegionCommon.h:148
RegionCommonLimitTxPower
int8_t RegionCommonLimitTxPower(int8_t txPower, int8_t maxBandTxPower)
Limits the TX power.
RegionCommonLinkAdrParams_t::ChMaskCtrl
uint8_t ChMaskCtrl
Definition: RegionCommon.h:132
ChannelParams_t
Definition: LoRaMac.h:217
RegionCommonLinkAdrParams_t::Datarate
int8_t Datarate
Definition: RegionCommon.h:124
LoRaMacTypes.h
LoRa MAC layer internal types definition. Please do not include in application sources.
RegionCommonIdentifyChannelsParam_t::MaxBands
uint8_t MaxBands
Definition: RegionCommon.h:290
RegionCommonRxBeaconSetup
void RegionCommonRxBeaconSetup(RegionCommonRxBeaconSetupParams_t *rxBeaconSetupParams)
Sets up the radio into RX beacon mode.
RegionCommonUpdateBandTimeOff
TimerTime_t RegionCommonUpdateBandTimeOff(bool joined, Band_t *bands, uint8_t nbBands, bool dutyCycleEnabled, bool lastTxIsJoinRequest, SysTime_t elapsedTimeSinceStartup, TimerTime_t expectedTimeOnAir)
Updates the time-offs of the bands. This is a generic function and valid for all regions.
RegionCommonLinkAdrParams_t::NbRep
uint8_t NbRep
Definition: RegionCommon.h:120
RegionCommonCountNbOfEnabledChannels
void RegionCommonCountNbOfEnabledChannels(RegionCommonCountNbOfEnabledChannelsParams_t *countNbOfEnabledChannelsParams, uint8_t *enabledChannels, uint8_t *nbEnabledChannels, uint8_t *nbRestrictedChannels)
Counts the number of enabled channels.
RegionCommonLinkAdrReqVerifyParams_t::MaxTxPower
int8_t MaxTxPower
Definition: RegionCommon.h:204
Band_t
Definition: LoRaMacTypes.h:590
RegionCommonComputeRxWindowParameters
void RegionCommonComputeRxWindowParameters(uint32_t tSymbolInUs, uint8_t minRxSymbols, uint32_t rxErrorInMs, uint32_t wakeUpTimeInMs, uint32_t *windowTimeoutInSymbols, int32_t *windowOffsetInMs)
Computes the RX window timeout and the RX window offset.
RegionCommonLinkAdrParams_t::ChMask
uint16_t ChMask
Definition: RegionCommon.h:136
RegionCommonIdentifyChannelsParam_t::CountNbOfEnabledChannelsParam
RegionCommonCountNbOfEnabledChannelsParams_t * CountNbOfEnabledChannelsParam
Definition: RegionCommon.h:306
RegionCommonIdentifyChannels
LoRaMacStatus_t RegionCommonIdentifyChannels(RegionCommonIdentifyChannelsParam_t *identifyChannelsParam, TimerTime_t *aggregatedTimeOff, uint8_t *enabledChannels, uint8_t *nbEnabledChannels, uint8_t *nbRestrictedChannels, TimerTime_t *nextTxDelay)
Identifies all channels which are available currently.
RegionCommonSetBandTxDone
void RegionCommonSetBandTxDone(Band_t *band, TimerTime_t lastTxAirTime, bool joined, SysTime_t elapsedTimeSinceStartup)
Sets the last tx done property. This is a generic function and valid for all regions.
RegionCommonComputeSymbolTimeFsk
uint32_t RegionCommonComputeSymbolTimeFsk(uint8_t phyDrInKbps)
Computes the symbol time for FSK modulation.
RegionCommonLinkAdrReqVerifyParams_t::Version
Version_t Version
Definition: RegionCommon.h:144
RegionCommonRxBeaconSetupParams_t::SymbolTimeout
uint16_t SymbolTimeout
Definition: RegionCommon.h:236
RegionCommonRxBeaconSetupParams_t::RxTime
uint32_t RxTime
Definition: RegionCommon.h:232
RegionCommonChanMaskCopy
void RegionCommonChanMaskCopy(uint16_t *channelsMaskDest, uint16_t *channelsMaskSrc, uint8_t len)
Copy a channels mask. This is a generic function and valid for all regions.
RegionCommonLinkAdrReqVerifyParams_t::AdrEnabled
bool AdrEnabled
Definition: RegionCommon.h:152
RegionCommonCountNbOfEnabledChannelsParams_t::Bands
Band_t * Bands
Definition: RegionCommon.h:260
RegionCommonRxBeaconSetupParams_t::BeaconChannelBW
uint8_t BeaconChannelBW
Definition: RegionCommon.h:228
RegionCommonCountNbOfEnabledChannelsParams_t
Definition: RegionCommon.h:239
RegionCommonLinkAdrReqVerifyParams_t::Channels
ChannelParams_t * Channels
Definition: RegionCommon.h:196
RegionCommonCountNbOfEnabledChannelsParams_t::JoinChannels
uint16_t * JoinChannels
Definition: RegionCommon.h:270
RegionCommonIdentifyChannelsParam_t::LastAggrTx
TimerTime_t LastAggrTx
Definition: RegionCommon.h:282
RegionCommonLinkAdrReqVerifyParams_t::NbChannels
uint8_t NbChannels
Definition: RegionCommon.h:180
RegionCommonRxBeaconSetupParams_t::Datarates
const uint8_t * Datarates
Definition: RegionCommon.h:212
RegionCommonParseLinkAdrReq
uint8_t RegionCommonParseLinkAdrReq(uint8_t *payload, RegionCommonLinkAdrParams_t *parseLinkAdr)
Parses the parameter of an LinkAdrRequest. This is a generic function and valid for all regions.
RegionCommonLinkAdrReqVerifyParams_t::MinDatarate
int8_t MinDatarate
Definition: RegionCommon.h:188
RegionCommonSetDutyCycleParams_t::DutyCycleTimePeriod
TimerTime_t DutyCycleTimePeriod
Definition: RegionCommon.h:314
RegionCommonComputeSymbolTimeLoRa
uint32_t RegionCommonComputeSymbolTimeLoRa(uint8_t phyDr, uint32_t bandwidthInHz)
Computes the symbol time for LoRa modulation.
RegionCommonRxBeaconSetupParams_t::Frequency
uint32_t Frequency
Definition: RegionCommon.h:216
RegionCommonCountNbOfEnabledChannelsParams_t::Joined
bool Joined
Definition: RegionCommon.h:244
RegionCommonLinkAdrReqVerifyParams
uint8_t RegionCommonLinkAdrReqVerifyParams(RegionCommonLinkAdrReqVerifyParams_t *verifyParams, int8_t *dr, int8_t *txPow, uint8_t *nbRep)
Verifies and updates the datarate, the TX power and the number of repetitions of a LinkAdrRequest....
RegionCommonRxBeaconSetupParams_t::BeaconDatarate
uint8_t BeaconDatarate
Definition: RegionCommon.h:224
RegionCommonIdentifyChannelsParam_t::ExpectedTimeOnAir
TimerTime_t ExpectedTimeOnAir
Definition: RegionCommon.h:302
RegionCommonGetBandwidth
uint32_t RegionCommonGetBandwidth(uint32_t drIndex, const uint32_t *bandwidths)
Gets the bandwidth.
RegionCommonIdentifyChannelsParam_t::ElapsedTimeSinceStartUp
SysTime_t ElapsedTimeSinceStartUp
Definition: RegionCommon.h:294
RegionCommonRxBeaconSetupParams_t
Definition: RegionCommon.h:207
RegionCommonGetNextLowerTxDr
int8_t RegionCommonGetNextLowerTxDr(int8_t dr, int8_t minDr)
Selects the next lower datarate.
RegionCommonCountNbOfEnabledChannelsParams_t::Datarate
uint8_t Datarate
Definition: RegionCommon.h:248
RegionCommonCountNbOfEnabledChannelsParams_t::MaxNbChannels
uint16_t MaxNbChannels
Definition: RegionCommon.h:264
RegionCommonChanVerifyDr
bool RegionCommonChanVerifyDr(uint8_t nbChannels, uint16_t *channelsMask, int8_t dr, int8_t minDr, int8_t maxDr, ChannelParams_t *channels)
Verifies, if a datarate is available on an active channel. This is a generic function and valid for a...
RegionCommonLinkAdrReqVerifyParams_t::CurrentTxPower
int8_t CurrentTxPower
Definition: RegionCommon.h:172
RegionCommonChanDisable
bool RegionCommonChanDisable(uint16_t *channelsMask, uint8_t id, uint8_t maxChannels)
Disables a channel in a given channels mask. This is a generic function and valid for all regions.
RegionCommonIdentifyChannelsParam_t::AggrTimeOff
TimerTime_t AggrTimeOff
Definition: RegionCommon.h:278
RegionCommonIdentifyChannelsParam_t
Definition: RegionCommon.h:273
RegionCommonLinkAdrReqVerifyParams_t::MinTxPower
int8_t MinTxPower
Definition: RegionCommon.h:200
RegionCommonSetDutyCycleParams_t
Definition: RegionCommon.h:309