SX126x-Arduino
LoRaMacHelper.h
Go to the documentation of this file.
1 /******************************************************************************
2  * @file LoRaMacHelper.h
3  * @author Insight SiP
4  * @version V1.0.0
5  * @date 06-november-2018
6  * @brief LoRaMacHelper declaration file.
7  *
8  * @attention
9  * THIS SOFTWARE IS PROVIDED BY INSIGHT SIP "AS IS" AND ANY EXPRESS
10  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
12  * DISCLAIMED. IN NO EVENT SHALL INSIGHT SIP OR CONTRIBUTORS BE
13  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
14  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
15  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
16  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
17  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
18  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19  *
20  *****************************************************************************/
21 
22 #ifndef __LORAMACHELPER_H__
23 #define __LORAMACHELPER_H__
24 
25 #include "stdint.h"
26 #include "mac/Commissioning.h"
27 #include "boards/mcu/board.h"
28 #include "mac/LoRaMac.h"
29 #include "mac/region/Region.h"
30 
31 extern "C"
32 {
33 
34 #define LORAWAN_CONFIRMED_MSG_ON 0
35 #define LORAWAN_CERTIF_PORT 224
36 #define LORAWAN_APP_PORT 2
37 #define LORAWAN_APP_DATA_MAX_SIZE 242
38 #define LORAWAN_DEFAULT_DATARATE DR_0
39 #define LORAWAN_DEFAULT_TX_POWER TX_POWER_0
41  typedef struct lmh_param_s
42  {
43  bool adr_enable;
44  int8_t tx_data_rate;
46  uint8_t nb_trials;
47  int8_t tx_power;
48  bool duty_cycle;
50 
51  typedef enum
52  {
53  LMH_RESET = 0,
56 
57  typedef enum
58  {
59  LMH_ERROR = -1,
60  LMH_SUCCESS = 0
62 
63  typedef enum
64  {
68 
71  typedef struct
72  {
73  uint8_t *buffer;
74  uint8_t buffsize;
75  uint8_t port;
76  int16_t rssi;
77  uint8_t snr;
79 
82  typedef struct lmh_callback_s
83  {
87  uint8_t (*BoardGetBatteryLevel)(void);
88 
92  void (*BoardGetUniqueId)(uint8_t *id);
93 
97  uint32_t (*BoardGetRandomSeed)(void);
98 
102  void (*lmh_RxData)(lmh_app_data_t *appdata);
103 
106  void (*lmh_has_joined)();
107 
112 
114 
118  {
119  bool running;
120  uint8_t state;
122  uint8_t app_port;
124  uint8_t data_buffer[64];
127  uint8_t demod_margin;
128  uint8_t nb_gateways;
130 
139  lmh_error_status lmh_init(lmh_callback_t *callbacks, lmh_param_t lora_param, bool otaa);
140 
148  lmh_error_status lmh_send(lmh_app_data_t *app_data, lmh_confirm is_txconfirmed);
149 
152  void lmh_join(void);
153 
159 
165  uint32_t lmh_getDevAddr(void);
166 
178 
183  void lmh_class_get(DeviceClass_t *currentClass);
184 
190  void lmh_datarate_set(uint8_t data_rate, uint8_t enable_adr);
191 
196  void lmh_tx_power_set(uint8_t tx_power);
197 
202  void lmh_setDevEui(uint8_t *userDevEui);
203 
208  void lmh_setAppEui(uint8_t *userAppEui);
209 
215  void lmh_setAppKey(uint8_t *userAppKey);
216 
222  void lmh_setNwkSKey(uint8_t *userNwkSKey);
223 
229  void lmh_setAppSKey(uint8_t *userAppSKey);
230 
235  void lmh_setDevAddr(uint32_t userDevAddr);
236 
241  bool lmh_setSubBandChannels(uint8_t subBand);
242 
253  void lmh_setSingleChannelGateway(uint8_t userSingleChannel, int8_t userDatarate);
254 };
255 #endif
lmh_setSingleChannelGateway
void lmh_setSingleChannelGateway(uint8_t userSingleChannel, int8_t userDatarate)
Disable channel hoping for connnection to single channel gateways Check the file CHANNELS....
Definition: LoRaMacHelper.cpp:131
LoraMacHelper_ComplianceTest_s::running
bool running
Definition: LoRaMacHelper.h:119
lmh_param_s::tx_power
int8_t tx_power
Definition: LoRaMacHelper.h:47
Region.h
Region implementation.
lmh_compliance_test_t
struct LoraMacHelper_ComplianceTest_s lmh_compliance_test_t
LoRaWAN compliance tests support data.
LoraMacHelper_ComplianceTest_s::data_buffer
uint8_t data_buffer[64]
Definition: LoRaMacHelper.h:124
lmh_send
lmh_error_status lmh_send(lmh_app_data_t *app_data, lmh_confirm is_txconfirmed)
Send data.
Definition: LoRaMacHelper.cpp:963
lmh_callback_s::lmh_RxData
void(* lmh_RxData)(lmh_app_data_t *appdata)
Process Rx Data received from Lora network.
Definition: LoRaMacHelper.h:102
lmh_app_data_t::buffer
uint8_t * buffer
Definition: LoRaMacHelper.h:73
lmh_join_status
lmh_join_status
Definition: LoRaMacHelper.h:52
lmh_callback_s::BoardGetRandomSeed
uint32_t(* BoardGetRandomSeed)(void)
Returns a pseudo random seed generated using the MCU Unique ID.
Definition: LoRaMacHelper.h:97
lmh_setDevEui
void lmh_setDevEui(uint8_t *userDevEui)
Set Device IEEE EUI (big endian)
LoraMacHelper_ComplianceTest_s::app_port
uint8_t app_port
Definition: LoRaMacHelper.h:122
lmh_param_s::nb_trials
uint8_t nb_trials
Definition: LoRaMacHelper.h:46
lmh_confirm
lmh_confirm
Definition: LoRaMacHelper.h:64
lmh_app_data_t
Application Data structure.
Definition: LoRaMacHelper.h:72
lmh_datarate_set
void lmh_datarate_set(uint8_t data_rate, uint8_t enable_adr)
Configure data rate.
Definition: LoRaMacHelper.cpp:888
Commissioning.h
lmh_callback_s::BoardGetBatteryLevel
uint8_t(* BoardGetBatteryLevel)(void)
Get the current battery level.
Definition: LoRaMacHelper.h:87
lmh_setNwkSKey
void lmh_setNwkSKey(uint8_t *userNwkSKey)
Set Network Session Key AES encryption/decryption cipher network session key.
Definition: LoRaMacHelper.cpp:116
LoraMacHelper_ComplianceTest_s::link_check
bool link_check
Definition: LoRaMacHelper.h:126
lmh_setSubBandChannels
bool lmh_setSubBandChannels(uint8_t subBand)
Set custom channel mask.
Definition: LoRaMacHelper.cpp:138
lmh_callback_s::lmh_has_joined
void(* lmh_has_joined)()
callback indicating EndNode has just joined
Definition: LoRaMacHelper.h:106
LMH_ERROR
@ LMH_ERROR
Definition: LoRaMacHelper.h:59
lmh_app_data_t::buffsize
uint8_t buffsize
Definition: LoRaMacHelper.h:74
lmh_callback_s
LoRaMac Helper Callbacks.
Definition: LoRaMacHelper.h:83
lmh_getDevAddr
uint32_t lmh_getDevAddr(void)
Returns the Device address set by the LoRaWan server after OTAA join success.
Definition: LoRaMacHelper.cpp:1106
lmh_app_data_t::snr
uint8_t snr
Definition: LoRaMacHelper.h:77
lmh_class_request
lmh_error_status lmh_class_request(DeviceClass_t newClass)
change Lora Class
Definition: LoRaMacHelper.cpp:1017
LMH_UNCONFIRMED_MSG
@ LMH_UNCONFIRMED_MSG
Definition: LoRaMacHelper.h:65
lmh_callback_t
struct lmh_callback_s lmh_callback_t
LoRaMac Helper Callbacks.
DeviceClass_t
enum eDeviceClass DeviceClass_t
lmh_param_s::adr_enable
bool adr_enable
Definition: LoRaMacHelper.h:43
lmh_tx_power_set
void lmh_tx_power_set(uint8_t tx_power)
Configure tx power.
Definition: LoRaMacHelper.cpp:898
lmh_callback_s::lmh_ConfirmClass
void(* lmh_ConfirmClass)(DeviceClass_t Class)
Confirms the class change.
Definition: LoRaMacHelper.h:111
LoraMacHelper_ComplianceTest_s::downlink_counter
uint16_t downlink_counter
Definition: LoRaMacHelper.h:125
lmh_join_status_get
lmh_join_status lmh_join_status_get(void)
Check whether the Device is joined to the network.
Definition: LoRaMacHelper.cpp:947
LMH_RESET
@ LMH_RESET
Definition: LoRaMacHelper.h:53
lmh_app_data_t::rssi
int16_t rssi
Definition: LoRaMacHelper.h:76
lmh_app_data_t::port
uint8_t port
Definition: LoRaMacHelper.h:75
LoraMacHelper_ComplianceTest_s::state
uint8_t state
Definition: LoRaMacHelper.h:120
lmh_init
lmh_error_status lmh_init(lmh_callback_t *callbacks, lmh_param_t lora_param, bool otaa)
Lora Initialisation.
Definition: LoRaMacHelper.cpp:738
lmh_param_s::duty_cycle
bool duty_cycle
Definition: LoRaMacHelper.h:48
lmh_callback_s::BoardGetUniqueId
void(* BoardGetUniqueId)(uint8_t *id)
Gets the board 64 bits unique ID.
Definition: LoRaMacHelper.h:92
LoRaMac.h
LoRa MAC layer implementation.
LMH_CONFIRMED_MSG
@ LMH_CONFIRMED_MSG
Definition: LoRaMacHelper.h:66
lmh_param_t
struct lmh_param_s lmh_param_t
LoraMacHelper_ComplianceTest_s::demod_margin
uint8_t demod_margin
Definition: LoRaMacHelper.h:127
LoraMacHelper_ComplianceTest_s::data_buffer_size
uint8_t data_buffer_size
Definition: LoRaMacHelper.h:123
board.h
lmh_param_s::tx_data_rate
int8_t tx_data_rate
Definition: LoRaMacHelper.h:44
lmh_join
void lmh_join(void)
Join a Lora Network in class A.
Definition: LoRaMacHelper.cpp:905
lmh_param_s
Definition: LoRaMacHelper.h:42
lmh_class_get
void lmh_class_get(DeviceClass_t *currentClass)
get the current Lora Class
Definition: LoRaMacHelper.cpp:1096
LMH_SET
@ LMH_SET
Definition: LoRaMacHelper.h:54
LoraMacHelper_ComplianceTest_s::nb_gateways
uint8_t nb_gateways
Definition: LoRaMacHelper.h:128
LoraMacHelper_ComplianceTest_s
LoRaWAN compliance tests support data.
Definition: LoRaMacHelper.h:118
LMH_SUCCESS
@ LMH_SUCCESS
Definition: LoRaMacHelper.h:60
lmh_setAppSKey
void lmh_setAppSKey(uint8_t *userAppSKey)
Set Application Session Key AES encryption/decryption cipher application session key.
Definition: LoRaMacHelper.cpp:121
LoraMacHelper_ComplianceTest_s::is_tx_confirmed
bool is_tx_confirmed
Definition: LoRaMacHelper.h:121
lmh_setDevAddr
void lmh_setDevAddr(uint32_t userDevAddr)
Set Device address on the network (big endian)
Definition: LoRaMacHelper.cpp:126
lmh_setAppEui
void lmh_setAppEui(uint8_t *userAppEui)
Set Application IEEE EUI.
Definition: LoRaMacHelper.cpp:106
lmh_setAppKey
void lmh_setAppKey(uint8_t *userAppKey)
Set Application Key AES encryption/decryption cipher application key.
Definition: LoRaMacHelper.cpp:111
lmh_param_s::enable_public_network
bool enable_public_network
Definition: LoRaMacHelper.h:45
lmh_error_status
lmh_error_status
Definition: LoRaMacHelper.h:58