| SX126x-Arduino 2.0.1

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 #include "mac/region/RegionAS923.h"
31
32 extern "C"
33 {
34
35 #define LORAWAN_CONFIRMED_MSG_ON 0
36 #define LORAWAN_CERTIF_PORT 224
37 #define LORAWAN_APP_PORT 2
38 #define LORAWAN_APP_DATA_MAX_SIZE 242
39 #define LORAWAN_DEFAULT_DATARATE DR_0
40 #define LORAWAN_DEFAULT_TX_POWER TX_POWER_0
42 typedef struct lmh_param_s
43 {
44 bool adr_enable;
45 int8_t tx_data_rate;
46 bool enable_public_network;
47 uint8_t nb_trials;
48 int8_t tx_power;
49 bool duty_cycle;
50 } lmh_param_t;
51
52 typedef enum
53 {
54 LMH_RESET = 0,
55 LMH_SET,
56 LMH_ONGOING,
57 LMH_FAILED
58 } lmh_join_status;
59
60 typedef enum
61 {
62 LMH_ERROR = -1,
63 LMH_SUCCESS = 0
64 } lmh_error_status;
65
66 typedef enum
67 {
68 LMH_UNCONFIRMED_MSG = 0,
69 LMH_CONFIRMED_MSG = !LMH_UNCONFIRMED_MSG
70 } lmh_confirm;
71
74 typedef struct
75 {
76 uint8_t *buffer;
77 uint8_t buffsize;
78 uint8_t port;
79 int16_t rssi;
80 uint8_t snr;
81 } lmh_app_data_t;
82
85 typedef struct lmh_callback_s
86 {
90 uint8_t (*BoardGetBatteryLevel)(void);
91
95 void (*BoardGetUniqueId)(uint8_t *id);
96
100 uint32_t (*BoardGetRandomSeed)(void);
101
105 void (*lmh_RxData)(lmh_app_data_t *appdata);
106
109 void (*lmh_has_joined)();
110
114 void (*lmh_ConfirmClass)(DeviceClass_t Class);
115
118 void (*lmh_has_joined_failed)();
119
120 } lmh_callback_t;
121
124 typedef struct LoraMacHelper_ComplianceTest_s
125 {
126 bool running;
127 uint8_t state;
128 bool is_tx_confirmed;
129 uint8_t app_port;
130 uint8_t data_buffer_size;
131 uint8_t data_buffer[64];
132 uint16_t downlink_counter;
133 bool link_check;
134 uint8_t demod_margin;
135 uint8_t nb_gateways;
136 } lmh_compliance_test_t;
137
148 lmh_error_status lmh_init(lmh_callback_t *callbacks, lmh_param_t lora_param,
149 bool otaa, eDeviceClass nodeClass = CLASS_A, LoRaMacRegion_t region = LORAMAC_REGION_EU868);
150
158 lmh_error_status lmh_send(lmh_app_data_t *app_data, lmh_confirm is_txconfirmed);
159
167 lmh_error_status lmh_send_blocking(lmh_app_data_t *app_data, lmh_confirm is_tx_confirmed, uint32_t time_out);
168
171 void lmh_join(void);
172
177 lmh_join_status lmh_join_status_get(void);
178
184 uint32_t lmh_getDevAddr(void);
185
196 lmh_error_status lmh_class_request(DeviceClass_t newClass);
197
202 void lmh_class_get(DeviceClass_t *currentClass);
203
209 void lmh_datarate_set(uint8_t data_rate, uint8_t enable_adr);
210
215 void lmh_tx_power_set(uint8_t tx_power);
216
221 void lmh_setDevEui(uint8_t *userDevEui);
222
227 void lmh_setAppEui(uint8_t *userAppEui);
228
234 void lmh_setAppKey(uint8_t *userAppKey);
235
241 void lmh_setNwkSKey(uint8_t *userNwkSKey);
242
248 void lmh_setAppSKey(uint8_t *userAppSKey);
249
254 void lmh_setDevAddr(uint32_t userDevAddr);
255
260 bool lmh_setSubBandChannels(uint8_t subBand);
261
272 void lmh_setSingleChannelGateway(uint8_t userSingleChannel, int8_t userDatarate);
273
282 bool lmh_setAS923Version(uint8_t version);
283 };
284 #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:137
LoraMacHelper_ComplianceTest_s::running
bool running
Definition: LoRaMacHelper.h:126
lmh_param_s::tx_power
int8_t tx_power
Definition: LoRaMacHelper.h:48
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:131
lmh_send
lmh_error_status lmh_send(lmh_app_data_t *app_data, lmh_confirm is_txconfirmed)
Send data.
Definition: LoRaMacHelper.cpp:927
lmh_callback_s::lmh_RxData
void(* lmh_RxData)(lmh_app_data_t *appdata)
Process Rx Data received from Lora network.
Definition: LoRaMacHelper.h:105
lmh_app_data_t::buffer
uint8_t * buffer
Definition: LoRaMacHelper.h:76
lmh_join_status
lmh_join_status
Definition: LoRaMacHelper.h:53
RegionAS923.h
Region definition for AS923.
lmh_init
lmh_error_status lmh_init(lmh_callback_t *callbacks, lmh_param_t lora_param, bool otaa, eDeviceClass nodeClass=CLASS_A, LoRaMacRegion_t region=LORAMAC_REGION_EU868)
Lora Initialisation.
Definition: LoRaMacHelper.cpp:682
lmh_callback_s::BoardGetRandomSeed
uint32_t(* BoardGetRandomSeed)(void)
Returns a pseudo random seed generated using the MCU Unique ID.
Definition: LoRaMacHelper.h:100
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:129
lmh_param_s::nb_trials
uint8_t nb_trials
Definition: LoRaMacHelper.h:47
lmh_confirm
lmh_confirm
Definition: LoRaMacHelper.h:67
lmh_app_data_t
Application Data structure.
Definition: LoRaMacHelper.h:75
lmh_datarate_set
void lmh_datarate_set(uint8_t data_rate, uint8_t enable_adr)
Configure data rate.
Definition: LoRaMacHelper.cpp:850
Commissioning.h
lmh_callback_s::BoardGetBatteryLevel
uint8_t(* BoardGetBatteryLevel)(void)
Get the current battery level.
Definition: LoRaMacHelper.h:90
lmh_setNwkSKey
void lmh_setNwkSKey(uint8_t *userNwkSKey)
Set Network Session Key AES encryption/decryption cipher network session key.
Definition: LoRaMacHelper.cpp:122
LoraMacHelper_ComplianceTest_s::link_check
bool link_check
Definition: LoRaMacHelper.h:133
lmh_setSubBandChannels
bool lmh_setSubBandChannels(uint8_t subBand)
Set custom channel mask.
Definition: LoRaMacHelper.cpp:144
lmh_callback_s::lmh_has_joined
void(* lmh_has_joined)()
callback indicating EndNode has just joined
Definition: LoRaMacHelper.h:109
LMH_ERROR
@ LMH_ERROR
Definition: LoRaMacHelper.h:62
lmh_app_data_t::buffsize
uint8_t buffsize
Definition: LoRaMacHelper.h:77
lmh_callback_s
LoRaMac Helper Callbacks.
Definition: LoRaMacHelper.h:86
lmh_getDevAddr
uint32_t lmh_getDevAddr(void)
Returns the Device address set by the LoRaWan server after OTAA join success.
Definition: LoRaMacHelper.cpp:1097
lmh_app_data_t::snr
uint8_t snr
Definition: LoRaMacHelper.h:80
lmh_class_request
lmh_error_status lmh_class_request(DeviceClass_t newClass)
change Lora Class
Definition: LoRaMacHelper.cpp:1008
LMH_UNCONFIRMED_MSG
@ LMH_UNCONFIRMED_MSG
Definition: LoRaMacHelper.h:68
lmh_callback_t
struct lmh_callback_s lmh_callback_t
LoRaMac Helper Callbacks.
lmh_send_blocking
lmh_error_status lmh_send_blocking(lmh_app_data_t *app_data, lmh_confirm is_tx_confirmed, uint32_t time_out)
Send data and wait for RX2 window closed or timeout occurs.
Definition: LoRaMacHelper.cpp:988
DeviceClass_t
enum eDeviceClass DeviceClass_t
lmh_param_s::adr_enable
bool adr_enable
Definition: LoRaMacHelper.h:44
lmh_tx_power_set
void lmh_tx_power_set(uint8_t tx_power)
Configure tx power.
Definition: LoRaMacHelper.cpp:860
lmh_callback_s::lmh_ConfirmClass
void(* lmh_ConfirmClass)(DeviceClass_t Class)
Confirms the class change.
Definition: LoRaMacHelper.h:114
LoraMacHelper_ComplianceTest_s::downlink_counter
uint16_t downlink_counter
Definition: LoRaMacHelper.h:132
lmh_join_status_get
lmh_join_status lmh_join_status_get(void)
Check whether the Device is joined to the network.
Definition: LoRaMacHelper.cpp:909
lmh_callback_s::lmh_has_joined_failed
void(* lmh_has_joined_failed)()
callback indicating EndNode has just joined failed
Definition: LoRaMacHelper.h:118
LMH_RESET
@ LMH_RESET
Definition: LoRaMacHelper.h:54
lmh_app_data_t::rssi
int16_t rssi
Definition: LoRaMacHelper.h:79
CLASS_A
@ CLASS_A
Definition: LoRaMac.h:92
lmh_app_data_t::port
uint8_t port
Definition: LoRaMacHelper.h:78
eDeviceClass
eDeviceClass
Definition: LoRaMac.h:86
LORAMAC_REGION_EU868
@ LORAMAC_REGION_EU868
Definition: LoRaMac.h:1614
LoraMacHelper_ComplianceTest_s::state
uint8_t state
Definition: LoRaMacHelper.h:127
region
LoRaMacRegion_t region
Definition: LoRaMacHelper.cpp:37
LMH_ONGOING
@ LMH_ONGOING
Definition: LoRaMacHelper.h:56
lmh_param_s::duty_cycle
bool duty_cycle
Definition: LoRaMacHelper.h:49
lmh_setAS923Version
bool lmh_setAS923Version(uint8_t version)
Adjust frequency band to AS923-1, AS923-2, AS923-3.
Definition: LoRaMacHelper.cpp:1102
lmh_callback_s::BoardGetUniqueId
void(* BoardGetUniqueId)(uint8_t *id)
Gets the board 64 bits unique ID.
Definition: LoRaMacHelper.h:95
LoRaMac.h
LoRa MAC layer implementation.
LMH_CONFIRMED_MSG
@ LMH_CONFIRMED_MSG
Definition: LoRaMacHelper.h:69
lmh_param_t
struct lmh_param_s lmh_param_t
LoraMacHelper_ComplianceTest_s::demod_margin
uint8_t demod_margin
Definition: LoRaMacHelper.h:134
LoraMacHelper_ComplianceTest_s::data_buffer_size
uint8_t data_buffer_size
Definition: LoRaMacHelper.h:130
LMH_FAILED
@ LMH_FAILED
Definition: LoRaMacHelper.h:57
board.h
lmh_param_s::tx_data_rate
int8_t tx_data_rate
Definition: LoRaMacHelper.h:45
lmh_join
void lmh_join(void)
Join a Lora Network in class A.
Definition: LoRaMacHelper.cpp:867
lmh_param_s
Definition: LoRaMacHelper.h:43
lmh_class_get
void lmh_class_get(DeviceClass_t *currentClass)
get the current Lora Class
Definition: LoRaMacHelper.cpp:1087
LMH_SET
@ LMH_SET
Definition: LoRaMacHelper.h:55
LoraMacHelper_ComplianceTest_s::nb_gateways
uint8_t nb_gateways
Definition: LoRaMacHelper.h:135
LoraMacHelper_ComplianceTest_s
LoRaWAN compliance tests support data.
Definition: LoRaMacHelper.h:125
LMH_SUCCESS
@ LMH_SUCCESS
Definition: LoRaMacHelper.h:63
lmh_setAppSKey
void lmh_setAppSKey(uint8_t *userAppSKey)
Set Application Session Key AES encryption/decryption cipher application session key.
Definition: LoRaMacHelper.cpp:127
LoraMacHelper_ComplianceTest_s::is_tx_confirmed
bool is_tx_confirmed
Definition: LoRaMacHelper.h:128
lmh_setDevAddr
void lmh_setDevAddr(uint32_t userDevAddr)
Set Device address on the network (big endian)
Definition: LoRaMacHelper.cpp:132
lmh_setAppEui
void lmh_setAppEui(uint8_t *userAppEui)
Set Application IEEE EUI.
Definition: LoRaMacHelper.cpp:112
lmh_setAppKey
void lmh_setAppKey(uint8_t *userAppKey)
Set Application Key AES encryption/decryption cipher application key.
Definition: LoRaMacHelper.cpp:117
LoRaMacRegion_t
enum eLoRaMacRegion_t LoRaMacRegion_t
lmh_param_s::enable_public_network
bool enable_public_network
Definition: LoRaMacHelper.h:46
lmh_error_status
lmh_error_status
Definition: LoRaMacHelper.h:61