Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

446 lines
12 KiB

  1. /*!
  2. * \file RegionRU864.h
  3. *
  4. * \brief Region definition for RU864
  5. *
  6. * \copyright Revised BSD License, see section \ref LICENSE.
  7. *
  8. * \code
  9. * ______ _
  10. * / _____) _ | |
  11. * ( (____ _____ ____ _| |_ _____ ____| |__
  12. * \____ \| ___ | (_ _) ___ |/ ___) _ \
  13. * _____) ) ____| | | || |_| ____( (___| | | |
  14. * (______/|_____)_|_|_| \__)_____)\____)_| |_|
  15. * (C)2013-2017 Semtech
  16. *
  17. * ___ _____ _ ___ _ _____ ___ ___ ___ ___
  18. * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
  19. * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
  20. * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
  21. * embedded.connectivity.solutions===============
  22. *
  23. * \endcode
  24. *
  25. * \author Miguel Luis ( Semtech )
  26. *
  27. * \author Gregory Cristian ( Semtech )
  28. *
  29. * \author Daniel Jaeckle ( STACKFORCE )
  30. *
  31. * \defgroup REGIONRU864 Region RU864
  32. * Implementation according to LoRaWAN Specification v1.0.2.
  33. * \{
  34. */
  35. #ifndef __REGION_RU864_H__
  36. #define __REGION_RU864_H__
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. #include "region/Region.h"
  42. /*!
  43. * LoRaMac maximum number of channels
  44. */
  45. #define RU864_MAX_NB_CHANNELS 8
  46. /*!
  47. * Number of default channels
  48. */
  49. #define RU864_NUMB_DEFAULT_CHANNELS 2
  50. /*!
  51. * Number of channels to apply for the CF list
  52. */
  53. #define RU864_NUMB_CHANNELS_CF_LIST 5
  54. /*!
  55. * Minimal datarate that can be used by the node
  56. */
  57. #define RU864_TX_MIN_DATARATE DR_0
  58. /*!
  59. * Maximal datarate that can be used by the node
  60. */
  61. #define RU864_TX_MAX_DATARATE DR_7
  62. /*!
  63. * Minimal datarate that can be used by the node
  64. */
  65. #define RU864_RX_MIN_DATARATE DR_0
  66. /*!
  67. * Maximal datarate that can be used by the node
  68. */
  69. #define RU864_RX_MAX_DATARATE DR_7
  70. /*!
  71. * Default datarate used by the node
  72. */
  73. #define RU864_DEFAULT_DATARATE DR_0
  74. /*!
  75. * Minimal Rx1 receive datarate offset
  76. */
  77. #define RU864_MIN_RX1_DR_OFFSET 0
  78. /*!
  79. * Maximal Rx1 receive datarate offset
  80. */
  81. #define RU864_MAX_RX1_DR_OFFSET 5
  82. /*!
  83. * Minimal Tx output power that can be used by the node
  84. */
  85. #define RU864_MIN_TX_POWER TX_POWER_7
  86. /*!
  87. * Maximal Tx output power that can be used by the node
  88. */
  89. #define RU864_MAX_TX_POWER TX_POWER_0
  90. /*!
  91. * Default Tx output power used by the node
  92. */
  93. #define RU864_DEFAULT_TX_POWER TX_POWER_0
  94. /*!
  95. * Default Max EIRP
  96. */
  97. #define RU864_DEFAULT_MAX_EIRP 16.0f
  98. /*!
  99. * Default antenna gain
  100. */
  101. #define RU864_DEFAULT_ANTENNA_GAIN 2.15f
  102. /*!
  103. * Enabled or disabled the duty cycle
  104. */
  105. #define RU864_DUTY_CYCLE_ENABLED 1
  106. /*!
  107. * Maximum RX window duration
  108. */
  109. #define RU864_MAX_RX_WINDOW 3000 //TODO
  110. #if ( RU864_DEFAULT_DATARATE > DR_5 )
  111. #error "A default DR higher than DR_5 may lead to connectivity loss."
  112. #endif
  113. /*!
  114. * Second reception window channel frequency definition.
  115. */
  116. #define RU864_RX_WND_2_FREQ 869100000
  117. /*!
  118. * Second reception window channel datarate definition.
  119. */
  120. #define RU864_RX_WND_2_DR DR_0
  121. /*!
  122. * Default uplink dwell time configuration
  123. */
  124. #define RU864_DEFAULT_UPLINK_DWELL_TIME 0
  125. /*
  126. * CLASS B
  127. */
  128. /*!
  129. * Beacon frequency
  130. */
  131. #define RU864_BEACON_CHANNEL_FREQ 869100000
  132. /*!
  133. * Ping slot channel frequency
  134. */
  135. #define RU864_PING_SLOT_CHANNEL_FREQ 868900000
  136. /*!
  137. * Payload size of a beacon frame
  138. */
  139. #define RU864_BEACON_SIZE 17
  140. /*!
  141. * Size of RFU 1 field
  142. */
  143. #define RU864_RFU1_SIZE 1
  144. /*!
  145. * Size of RFU 2 field
  146. */
  147. #define RU864_RFU2_SIZE 0
  148. /*!
  149. * Datarate of the beacon channel
  150. */
  151. #define RU864_BEACON_CHANNEL_DR DR_3
  152. /*!
  153. * Bandwith of the beacon channel (Index of BandwidthsRU864[])
  154. */
  155. #define RU864_BEACON_CHANNEL_BW 0
  156. /*!
  157. * Datarate of the ping slot channel
  158. */
  159. #define RU864_PING_SLOT_CHANNEL_DR DR_3
  160. /*!
  161. * Ping slot channel datarate
  162. */
  163. #define RU864_PING_SLOT_CHANNEL_DR DR_3
  164. /*!
  165. * Maximum number of bands
  166. */
  167. #define RU864_MAX_NB_BANDS 1
  168. /*!
  169. * Band 0 definition
  170. * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission }
  171. */
  172. #define RU864_BAND0 { 100 , RU864_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 1.0 %
  173. /*!
  174. * LoRaMac default channel 1
  175. * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
  176. */
  177. #define RU864_LC1 { 868900000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
  178. /*!
  179. * LoRaMac default channel 2
  180. * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
  181. */
  182. #define RU864_LC2 { 869100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
  183. /*!
  184. * LoRaMac channels which are allowed for the join procedure
  185. */
  186. #define RU864_JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) )
  187. /*!
  188. * Data rates table definition
  189. */
  190. static const uint8_t DataratesRU864[] = { 12, 11, 10, 9, 8, 7, 7, 50 };
  191. /*!
  192. * Bandwidths table definition in Hz
  193. */
  194. static const uint32_t BandwidthsRU864[] = { 125000, 125000, 125000, 125000, 125000, 125000, 250000, 0 };
  195. /*!
  196. * Maximum payload with respect to the datarate index.
  197. */
  198. static const uint8_t MaxPayloadOfDatarateRU864[] = { 51, 51, 51, 115, 242, 242, 242, 242 };
  199. /*!
  200. * \brief The function gets a value of a specific phy attribute.
  201. *
  202. * \param [IN] getPhy Pointer to the function parameters.
  203. *
  204. * \retval Returns a structure containing the PHY parameter.
  205. */
  206. PhyParam_t RegionRU864GetPhyParam( GetPhyParams_t* getPhy );
  207. /*!
  208. * \brief Updates the last TX done parameters of the current channel.
  209. *
  210. * \param [IN] txDone Pointer to the function parameters.
  211. */
  212. void RegionRU864SetBandTxDone( SetBandTxDoneParams_t* txDone );
  213. /*!
  214. * \brief Initializes the channels masks and the channels.
  215. *
  216. * \param [IN] type Sets the initialization type.
  217. */
  218. void RegionRU864InitDefaults( InitDefaultsParams_t* params );
  219. /*!
  220. * \brief Verifies a parameter.
  221. *
  222. * \param [IN] verify Pointer to the function parameters.
  223. *
  224. * \param [IN] type Sets the initialization type.
  225. *
  226. * \retval Returns true, if the parameter is valid.
  227. */
  228. bool RegionRU864Verify( VerifyParams_t* verify, PhyAttribute_t phyAttribute );
  229. /*!
  230. * \brief The function parses the input buffer and sets up the channels of the
  231. * CF list.
  232. *
  233. * \param [IN] applyCFList Pointer to the function parameters.
  234. */
  235. void RegionRU864ApplyCFList( ApplyCFListParams_t* applyCFList );
  236. /*!
  237. * \brief Sets a channels mask.
  238. *
  239. * \param [IN] chanMaskSet Pointer to the function parameters.
  240. *
  241. * \retval Returns true, if the channels mask could be set.
  242. */
  243. bool RegionRU864ChanMaskSet( ChanMaskSetParams_t* chanMaskSet );
  244. /*!
  245. * Computes the Rx window timeout and offset.
  246. *
  247. * \param [IN] datarate Rx window datarate index to be used
  248. *
  249. * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame.
  250. *
  251. * \param [IN] rxError System maximum timing error of the receiver. In milliseconds
  252. * The receiver will turn on in a [-rxError : +rxError] ms
  253. * interval around RxOffset
  254. *
  255. * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields.
  256. */
  257. void RegionRU864ComputeRxWindowParameters( int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams );
  258. /*!
  259. * \brief Configuration of the RX windows.
  260. *
  261. * \param [IN] rxConfig Pointer to the function parameters.
  262. *
  263. * \param [OUT] datarate The datarate index which was set.
  264. *
  265. * \retval Returns true, if the configuration was applied successfully.
  266. */
  267. bool RegionRU864RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate );
  268. /*!
  269. * \brief TX configuration.
  270. *
  271. * \param [IN] txConfig Pointer to the function parameters.
  272. *
  273. * \param [OUT] txPower The tx power index which was set.
  274. *
  275. * \param [OUT] txTimeOnAir The time-on-air of the frame.
  276. *
  277. * \retval Returns true, if the configuration was applied successfully.
  278. */
  279. bool RegionRU864TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir );
  280. /*!
  281. * \brief The function processes a Link ADR Request.
  282. *
  283. * \param [IN] linkAdrReq Pointer to the function parameters.
  284. *
  285. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  286. */
  287. uint8_t RegionRU864LinkAdrReq( LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed );
  288. /*!
  289. * \brief The function processes a RX Parameter Setup Request.
  290. *
  291. * \param [IN] rxParamSetupReq Pointer to the function parameters.
  292. *
  293. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  294. */
  295. uint8_t RegionRU864RxParamSetupReq( RxParamSetupReqParams_t* rxParamSetupReq );
  296. /*!
  297. * \brief The function processes a Channel Request.
  298. *
  299. * \param [IN] newChannelReq Pointer to the function parameters.
  300. *
  301. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  302. */
  303. int8_t RegionRU864NewChannelReq( NewChannelReqParams_t* newChannelReq );
  304. /*!
  305. * \brief The function processes a TX ParamSetup Request.
  306. *
  307. * \param [IN] txParamSetupReq Pointer to the function parameters.
  308. *
  309. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  310. * Returns -1, if the functionality is not implemented. In this case, the end node
  311. * shall not process the command.
  312. */
  313. int8_t RegionRU864TxParamSetupReq( TxParamSetupReqParams_t* txParamSetupReq );
  314. /*!
  315. * \brief The function processes a DlChannel Request.
  316. *
  317. * \param [IN] dlChannelReq Pointer to the function parameters.
  318. *
  319. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  320. */
  321. int8_t RegionRU864DlChannelReq( DlChannelReqParams_t* dlChannelReq );
  322. /*!
  323. * \brief Alternates the datarate of the channel for the join request.
  324. *
  325. * \param [IN] currentDr Current datarate.
  326. *
  327. * \retval Datarate to apply.
  328. */
  329. int8_t RegionRU864AlternateDr( int8_t currentDr, AlternateDrType_t type );
  330. /*!
  331. * \brief Searches and set the next random available channel
  332. *
  333. * \param [OUT] channel Next channel to use for TX.
  334. *
  335. * \param [OUT] time Time to wait for the next transmission according to the duty
  336. * cycle.
  337. *
  338. * \param [OUT] aggregatedTimeOff Updates the aggregated time off.
  339. *
  340. * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate]
  341. */
  342. LoRaMacStatus_t RegionRU864NextChannel( NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff );
  343. /*!
  344. * \brief Adds a channel.
  345. *
  346. * \param [IN] channelAdd Pointer to the function parameters.
  347. *
  348. * \retval Status of the operation.
  349. */
  350. LoRaMacStatus_t RegionRU864ChannelAdd( ChannelAddParams_t* channelAdd );
  351. /*!
  352. * \brief Removes a channel.
  353. *
  354. * \param [IN] channelRemove Pointer to the function parameters.
  355. *
  356. * \retval Returns true, if the channel was removed successfully.
  357. */
  358. bool RegionRU864ChannelsRemove( ChannelRemoveParams_t* channelRemove );
  359. /*!
  360. * \brief Computes new datarate according to the given offset
  361. *
  362. * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms
  363. *
  364. * \param [IN] dr Current datarate
  365. *
  366. * \param [IN] drOffset Offset to be applied
  367. *
  368. * \retval newDr Computed datarate.
  369. */
  370. uint8_t RegionRU864ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
  371. /*!
  372. * \brief Sets the radio into beacon reception mode
  373. *
  374. * \param [IN] rxBeaconSetup Pointer to the function parameters
  375. */
  376. void RegionRU864RxBeaconSetup( RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr );
  377. /*! \} defgroup REGIONRU864 */
  378. #ifdef __cplusplus
  379. }
  380. #endif
  381. #endif // __REGION_RU864_H__