LoRaMAC  4.5.2
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_RETRANSMIT_TIMEOUT 2000
85 
90 #define REGION_COMMON_DEFAULT_RETRANSMIT_TIMEOUT_RND 1000
91 
95 #define REGION_COMMON_DEFAULT_RX1_DR_OFFSET 0
96 
100 #define REGION_COMMON_DEFAULT_DOWNLINK_DWELL_TIME 0
101 
108 #define REGION_COMMON_DEFAULT_PING_SLOT_PERIODICITY 7
109 
117 #define REGION_COMMON_CLASS_B_C_RESP_TIMEOUT 8000
118 
119 
120 typedef struct sRegionCommonLinkAdrParams
121 {
125  uint8_t NbRep;
129  int8_t Datarate;
133  int8_t TxPower;
137  uint8_t ChMaskCtrl;
141  uint16_t ChMask;
143 
144 typedef struct sRegionCommonLinkAdrReqVerifyParams
145 {
149  Version_t Version;
153  uint8_t Status;
161  int8_t Datarate;
165  int8_t TxPower;
169  uint8_t NbRep;
181  int8_t CurrentNbRep;
185  uint8_t NbChannels;
189  uint16_t* ChannelsMask;
193  int8_t MinDatarate;
197  int8_t MaxDatarate;
205  int8_t MinTxPower;
209  int8_t MaxTxPower;
211 
212 typedef struct sRegionCommonRxBeaconSetupParams
213 {
217  const uint8_t* Datarates;
221  uint32_t Frequency;
225  uint8_t BeaconSize;
229  uint8_t BeaconDatarate;
237  uint32_t RxTime;
241  uint16_t SymbolTimeout;
243 
244 typedef struct sRegionCommonCountNbOfEnabledChannelsParams
245 {
249  bool Joined;
253  uint8_t Datarate;
257  uint16_t* ChannelsMask;
269  uint16_t MaxNbChannels;
275  uint16_t* JoinChannels;
277 
278 typedef struct sRegionCommonIdentifyChannelsParam
279 {
283  TimerTime_t AggrTimeOff;
287  TimerTime_t LastAggrTx;
295  uint8_t MaxBands;
307  TimerTime_t ExpectedTimeOnAir;
313 
314 typedef struct sRegionCommonSetDutyCycleParams
315 {
319  TimerTime_t DutyCycleTimePeriod;
323  uint8_t MaxBands;
329 
330 typedef struct sRegionCommonGetNextLowerTxDrParams
331 {
332  int8_t CurrentDr;
333  int8_t MaxDr;
334  int8_t MinDr;
335  uint8_t NbChannels;
336  uint16_t* ChannelsMask;
337  ChannelParams_t* Channels;
339 
352 uint8_t RegionCommonValueInRange( int8_t value, int8_t min, int8_t max );
353 
372 bool RegionCommonChanVerifyDr( uint8_t nbChannels, uint16_t* channelsMask, int8_t dr,
373  int8_t minDr, int8_t maxDr, ChannelParams_t* channels );
374 
387 bool RegionCommonChanDisable( uint16_t* channelsMask, uint8_t id, uint8_t maxChannels );
388 
401 uint8_t RegionCommonCountChannels( uint16_t* channelsMask, uint8_t startIdx, uint8_t stopIdx );
402 
413 void RegionCommonChanMaskCopy( uint16_t* channelsMaskDest, uint16_t* channelsMaskSrc, uint8_t len );
414 
427 void RegionCommonSetBandTxDone( Band_t* band, TimerTime_t lastTxAirTime, bool joined, SysTime_t elapsedTimeSinceStartup );
428 
449 TimerTime_t RegionCommonUpdateBandTimeOff( bool joined, Band_t* bands,
450  uint8_t nbBands, bool dutyCycleEnabled,
451  bool lastTxIsJoinRequest, SysTime_t elapsedTimeSinceStartup,
452  TimerTime_t expectedTimeOnAir );
453 
466 uint8_t RegionCommonParseLinkAdrReq( uint8_t* payload, RegionCommonLinkAdrParams_t* parseLinkAdr );
467 
482 uint8_t RegionCommonLinkAdrReqVerifyParams( RegionCommonLinkAdrReqVerifyParams_t* verifyParams, int8_t* dr, int8_t* txPow, uint8_t* nbRep );
483 
493 uint32_t RegionCommonComputeSymbolTimeLoRa( uint8_t phyDr, uint32_t bandwidthInHz );
494 
502 uint32_t RegionCommonComputeSymbolTimeFsk( uint8_t phyDrInKbps );
503 
520 void RegionCommonComputeRxWindowParameters( uint32_t tSymbolInUs, uint8_t minRxSymbols, uint32_t rxErrorInMs, uint32_t wakeUpTimeInMs, uint32_t* windowTimeoutInSymbols, int32_t* windowOffsetInMs );
521 
537 int8_t RegionCommonComputeTxPower( int8_t txPowerIndex, float maxEirp, float antennaGain );
538 
545 
560  uint8_t* enabledChannels, uint8_t* nbEnabledChannels, uint8_t* nbRestrictedChannels );
561 
584  TimerTime_t* aggregatedTimeOff, uint8_t* enabledChannels,
585  uint8_t* nbEnabledChannels, uint8_t* nbRestrictedChannels,
586  TimerTime_t* nextTxDelay );
587 
596 
606 int8_t RegionCommonLimitTxPower( int8_t txPower, int8_t maxBandTxPower );
607 
617 uint32_t RegionCommonGetBandwidth( uint32_t drIndex, const uint32_t* bandwidths );
618 
621 #ifdef __cplusplus
622 }
623 #endif
624 
625 #endif // __REGIONCOMMON_H__
RegionCommonLinkAdrReqVerifyParams_t::ChannelsMask
uint16_t * ChannelsMask
Definition: RegionCommon.h:189
RegionCommonIdentifyChannelsParam_t::DutyCycleEnabled
bool DutyCycleEnabled
Definition: RegionCommon.h:291
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:133
RegionCommonLinkAdrReqVerifyParams_t::MaxDatarate
int8_t MaxDatarate
Definition: RegionCommon.h:197
RegionCommonLinkAdrReqVerifyParams_t::CurrentNbRep
int8_t CurrentNbRep
Definition: RegionCommon.h:181
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:303
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:2269
RegionCommonLinkAdrReqVerifyParams_t::CurrentDatarate
int8_t CurrentDatarate
Definition: RegionCommon.h:173
RegionCommonRxBeaconSetupParams_t::BeaconSize
uint8_t BeaconSize
Definition: RegionCommon.h:225
RegionCommonLinkAdrReqVerifyParams_t::Status
uint8_t Status
Definition: RegionCommon.h:153
RegionCommonLimitTxPower
int8_t RegionCommonLimitTxPower(int8_t txPower, int8_t maxBandTxPower)
Limits the TX power.
RegionCommonLinkAdrParams_t::ChMaskCtrl
uint8_t ChMaskCtrl
Definition: RegionCommon.h:137
RegionCommonLinkAdrParams_t::Datarate
int8_t Datarate
Definition: RegionCommon.h:129
LoRaMacTypes.h
LoRa MAC layer internal types definition. Please do not include in application sources.
RegionCommonIdentifyChannelsParam_t::MaxBands
uint8_t MaxBands
Definition: RegionCommon.h:295
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:125
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:209
Band_t
Definition: LoRaMacTypes.h:1097
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:141
RegionCommonIdentifyChannelsParam_t::CountNbOfEnabledChannelsParam
RegionCommonCountNbOfEnabledChannelsParams_t * CountNbOfEnabledChannelsParam
Definition: RegionCommon.h:311
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:149
RegionCommonRxBeaconSetupParams_t::SymbolTimeout
uint16_t SymbolTimeout
Definition: RegionCommon.h:241
RegionCommonRxBeaconSetupParams_t::RxTime
uint32_t RxTime
Definition: RegionCommon.h:237
ChannelParams_t
Definition: LoRaMacTypes.h:1169
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:157
RegionCommonCountNbOfEnabledChannelsParams_t::Bands
Band_t * Bands
Definition: RegionCommon.h:265
RegionCommonRxBeaconSetupParams_t::BeaconChannelBW
uint8_t BeaconChannelBW
Definition: RegionCommon.h:233
RegionCommonCountNbOfEnabledChannelsParams_t
Definition: RegionCommon.h:244
RegionCommonLinkAdrReqVerifyParams_t::Channels
ChannelParams_t * Channels
Definition: RegionCommon.h:201
RegionCommonCountNbOfEnabledChannelsParams_t::JoinChannels
uint16_t * JoinChannels
Definition: RegionCommon.h:275
RegionCommonIdentifyChannelsParam_t::LastAggrTx
TimerTime_t LastAggrTx
Definition: RegionCommon.h:287
RegionCommonLinkAdrReqVerifyParams_t::NbChannels
uint8_t NbChannels
Definition: RegionCommon.h:185
RegionCommonRxBeaconSetupParams_t::Datarates
const uint8_t * Datarates
Definition: RegionCommon.h:217
RegionCommonGetNextLowerTxDrParams_t
Definition: RegionCommon.h:330
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:193
RegionCommonSetDutyCycleParams_t::DutyCycleTimePeriod
TimerTime_t DutyCycleTimePeriod
Definition: RegionCommon.h:319
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:221
RegionCommonCountNbOfEnabledChannelsParams_t::Joined
bool Joined
Definition: RegionCommon.h:249
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:229
RegionCommonIdentifyChannelsParam_t::ExpectedTimeOnAir
TimerTime_t ExpectedTimeOnAir
Definition: RegionCommon.h:307
RegionCommonGetBandwidth
uint32_t RegionCommonGetBandwidth(uint32_t drIndex, const uint32_t *bandwidths)
Gets the bandwidth.
RegionCommonIdentifyChannelsParam_t::ElapsedTimeSinceStartUp
SysTime_t ElapsedTimeSinceStartUp
Definition: RegionCommon.h:299
RegionCommonRxBeaconSetupParams_t
Definition: RegionCommon.h:212
RegionCommonCountNbOfEnabledChannelsParams_t::Datarate
uint8_t Datarate
Definition: RegionCommon.h:253
RegionCommonGetNextLowerTxDr
int8_t RegionCommonGetNextLowerTxDr(RegionCommonGetNextLowerTxDrParams_t *params)
Selects the next lower datarate.
RegionCommonCountNbOfEnabledChannelsParams_t::MaxNbChannels
uint16_t MaxNbChannels
Definition: RegionCommon.h:269
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:177
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:283
RegionCommonIdentifyChannelsParam_t
Definition: RegionCommon.h:278
RegionCommonLinkAdrReqVerifyParams_t::MinTxPower
int8_t MinTxPower
Definition: RegionCommon.h:205
RegionCommonSetDutyCycleParams_t
Definition: RegionCommon.h:314