Skip to content

Commit 213d2b6

Browse files
authored
Merge pull request #6059 from hasnainvirk/pr_branch
Enabling LoRaWAN technology in Mbed-OS 5.8
2 parents 5e8d8e1 + d7c22a6 commit 213d2b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+9629
-18703
lines changed

features/netsocket/LoRaRadio.h renamed to features/lorawan/LoRaRadio.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#ifndef LORARADIO_H_
1919
#define LORARADIO_H_
2020

21+
#include "platform/Callback.h"
22+
#include "PinNames.h"
23+
2124
/**
2225
* Structure to hold RF controls for LoRa Radio.
2326
* SX1276 have an extra control for the crystal (used in DOSCO-L072CZ)
@@ -131,17 +134,18 @@ typedef struct radio_settings {
131134
*
132135
*/
133136
typedef struct radio_events {
134-
/* Tx Done callback prototype.
135-
*
137+
/**
138+
* Callback when Transmission is done
136139
*/
137-
void (*tx_done) (void);
140+
mbed::Callback<void()> tx_done;
138141

139-
/* Tx Timeout callback prototype.
140-
*
142+
/**
143+
* Callback when Transmission is timed out
141144
*/
142-
void (*tx_timeout) (void);
145+
mbed::Callback<void()> tx_timeout;
143146

144-
/* Rx Done callback prototype.
147+
/**
148+
* Rx Done callback prototype.
145149
*
146150
* @param payload Received buffer pointer.
147151
* @param size Received buffer size.
@@ -150,29 +154,31 @@ typedef struct radio_events {
150154
* FSK : N/A (set to 0)
151155
* LoRa: SNR value in dB
152156
*/
153-
void (*rx_done) (uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
157+
mbed::Callback<void(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)> rx_done;
154158

155-
/* Rx Timeout callback prototype.
156-
*
159+
/**
160+
* Callback when Reception is timed out
157161
*/
158-
void (*rx_timeout) (void);
162+
mbed::Callback<void()> rx_timeout;
159163

160-
/* Rx Error callback prototype.
161-
*
164+
/**
165+
* Callback when Reception ends up in error
162166
*/
163-
void (*rx_error) (void);
167+
mbed::Callback<void()> rx_error;
164168

165-
/* FHSS Change Channel callback prototype.
166-
*
167-
* @param current_channel The index number of the current channel.
168-
*/
169-
void (*fhss_change_channel) (uint8_t current_channel);
169+
/**
170+
* FHSS Change Channel callback prototype.
171+
*
172+
* @param current_channel The index number of the current channel.
173+
*/
174+
mbed::Callback<void(uint8_t current_channel)> fhss_change_channel;
170175

171-
/* CAD Done callback prototype.
176+
/**
177+
* CAD Done callback prototype.
172178
*
173-
* @param channel_activity_detected Channel activity detected during the CAD.
179+
* @param channel_busy True, if Channel activity detected.
174180
*/
175-
void (*cad_done) (bool channel_activity_detected);
181+
mbed::Callback<void(bool channel_busy)> cad_done;
176182
} radio_events_t;
177183

178184
/**

features/netsocket/LoRaWANBase.h renamed to features/lorawan/LoRaWANBase.h

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ class LoRaWANBase {
3131
*
3232
* @param queue A pointer to EventQueue provided by the application.
3333
*
34-
* @return LORA_MAC_STATUS_OK on success, a negative error code on
34+
* @return LORAWAN_STATUS_OK on success, a negative error code on
3535
* failure.
3636
*/
37-
virtual lora_mac_status_t initialize(events::EventQueue *queue) = 0;
37+
virtual lorawan_status_t initialize(events::EventQueue *queue) = 0;
3838

3939
/** Connect OTAA or ABP by setup.
4040
*
4141
* Connect by Over The Air Activation or Activation By Personalization.
4242
* The connection type is selected at the setup.
4343
*
44-
* @return LORA_MAC_STATUS_OK on success, a negative error code on
44+
* @return LORAWAN_STATUS_OK on success, a negative error code on
4545
* failure.
4646
*/
47-
virtual lora_mac_status_t connect() = 0;
47+
virtual lorawan_status_t connect() = 0;
4848

4949
/** Connect OTAA or ABP by parameters
5050
*
@@ -53,46 +53,78 @@ class LoRaWANBase {
5353
* You need to define the parameters in the main application.
5454
*
5555
* @param connect Options how end-device will connect to gateway
56-
* @return LORA_MAC_STATUS_OK on success, negative error code
56+
* @return LORAWAN_STATUS_OK on success, negative error code
5757
* on failure
5858
*/
59-
virtual lora_mac_status_t connect(const lorawan_connect_t &connect) = 0;
59+
virtual lorawan_status_t connect(const lorawan_connect_t &connect) = 0;
6060

6161
/** Disconnects the current session.
6262
*
63-
* @return LORA_MAC_STATUS_OK on success, a negative error code on failure.
63+
* @return LORAWAN_STATUS_OK on success, a negative error code on failure.
6464
*/
65-
virtual lora_mac_status_t disconnect() = 0;
65+
virtual lorawan_status_t disconnect() = 0;
66+
67+
/** Validate the connectivity with the network.
68+
*
69+
* Application may use this API to submit a request to the stack for
70+
* validation of its connectivity to a Network Server. Under the hood, this
71+
* API schedules a Link Check Request command (LinkCheckReq) for the network
72+
* server and once the response, i.e., LinkCheckAns MAC command is received
73+
* from the Network Server, user provided method is called.
74+
*
75+
* This API is usable only when the link check response is callback set by
76+
* the application. See add_lora_app_callbacks API. If the above mentioned
77+
* callback is not set, a LORAWAN_STATUS_PARAMETER_INVALID error is thrown.
78+
*
79+
* First parameter to callback function is the demodulation margin and
80+
* the second parameter is the number of gateways that successfully received
81+
* the last request.
82+
*
83+
* A 'Link Check Request' MAC command remains set for every subsequent
84+
* transmission, until/unless application explicitly turns it off using
85+
* remove_link_check_request() API.
86+
*
87+
* @return LORAWAN_STATUS_OK on successfully queuing a request, or
88+
* a negative error code on failure.
89+
*
90+
*/
91+
virtual lorawan_status_t add_link_check_request() = 0;
92+
93+
/** Detaches Link Request MAC command.
94+
*
95+
* Removes sticky MAC command for link check request.
96+
*/
97+
virtual void remove_link_check_request() = 0;
6698

6799
/** Sets up a particular data rate of choice
68100
*
69101
* @param data_rate Intended data rate e.g., DR_0, DR_1 etc.
70102
* Caution is advised as the macro DR_* can mean different
71103
* things while being in a different region.
72-
* @return LORA_MAC_STATUS_OK if everything goes well, otherwise
104+
* @return LORAWAN_STATUS_OK if everything goes well, otherwise
73105
* a negative error code.
74106
*/
75-
virtual lora_mac_status_t set_datarate(uint8_t data_rate) = 0;
107+
virtual lorawan_status_t set_datarate(uint8_t data_rate) = 0;
76108

77109
/** Enables adaptive data rate (ADR)
78110
*
79111
* Underlying LoRaPHY and LoRaMac layers handle the data rate automatically
80112
* for the user based upon radio conditions (network congestion).
81113
*
82-
* @return LORA_MAC_STATUS_OK on success, negative error code
114+
* @return LORAWAN_STATUS_OK on success, negative error code
83115
* on failure.
84116
*/
85-
virtual lora_mac_status_t enable_adaptive_datarate() = 0;
117+
virtual lorawan_status_t enable_adaptive_datarate() = 0;
86118

87119
/** Disables adaptive data rate
88120
*
89121
* When adaptive data rate (ADR) is disabled, user can either set a certain
90122
* data rate or the Mac layer will choose a default value.
91123
*
92-
* @return LORA_MAC_STATUS_OK on success, negative error code
124+
* @return LORAWAN_STATUS_OK on success, negative error code
93125
* on failure.
94126
*/
95-
virtual lora_mac_status_t disable_adaptive_datarate() = 0;
127+
virtual lorawan_status_t disable_adaptive_datarate() = 0;
96128

97129
/** Sets up retry counter for confirmed messages
98130
*
@@ -108,36 +140,36 @@ class LoRaWANBase {
108140
*
109141
* @param count number of retries for confirmed messages
110142
*
111-
* @return LORA_MAC_STATUS_OK or a negative error code
143+
* @return LORAWAN_STATUS_OK or a negative error code
112144
*/
113-
virtual lora_mac_status_t set_confirmed_msg_retries(uint8_t count) = 0;
145+
virtual lorawan_status_t set_confirmed_msg_retries(uint8_t count) = 0;
114146

115147
/** Sets channel plan
116148
*
117149
* @param channel_plan The defined channel plans to be set.
118150
* @return 0 on success, a negative error code on failure.
119151
*/
120-
virtual lora_mac_status_t set_channel_plan(const lora_channelplan_t &channel_plan) = 0;
152+
virtual lorawan_status_t set_channel_plan(const lorawan_channelplan_t &channel_plan) = 0;
121153

122154
/** Gets the current channel plan.
123155
*
124156
* @param channel_plan The current channel information.
125157
*
126-
* @return LORA_MAC_STATUS_OK on success, a negative error
158+
* @return LORAWAN_STATUS_OK on success, a negative error
127159
* code on failure.
128160
*/
129-
virtual lora_mac_status_t get_channel_plan(lora_channelplan_t &channel_plan) = 0;
161+
virtual lorawan_status_t get_channel_plan(lorawan_channelplan_t &channel_plan) = 0;
130162

131163
/** Removes currently active channel plan
132164
*
133165
* Default channels (channels where Base Stations are listening) are not
134166
* allowed to be removed. So when a plan is abolished, only non-default
135167
* channels are removed.
136168
*
137-
* @return LORA_MAC_STATUS_OK on success, negative error
169+
* @return LORAWAN_STATUS_OK on success, negative error
138170
* code on failure
139171
*/
140-
virtual lora_mac_status_t remove_channel_plan() = 0;
172+
virtual lorawan_status_t remove_channel_plan() = 0;
141173

142174
/** Removes a given single channel
143175
*
@@ -146,10 +178,10 @@ class LoRaWANBase {
146178
*
147179
* @param index The channel index
148180
*
149-
* @return LORA_MAC_STATUS_OK on success, negative error
181+
* @return LORAWAN_STATUS_OK on success, negative error
150182
* code on failure
151183
*/
152-
virtual lora_mac_status_t remove_channel(uint8_t index) = 0;
184+
virtual lorawan_status_t remove_channel(uint8_t index) = 0;
153185

154186
/** Send message to gateway
155187
*
@@ -182,7 +214,7 @@ class LoRaWANBase {
182214
*
183215
*
184216
* @return The number of bytes sent, or
185-
* LORA_MAC_STATUS_WOULD_BLOCK if another TX is
217+
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
186218
* ongoing, or a negative error code on failure.
187219
*/
188220
virtual int16_t send(uint8_t port, const uint8_t* data,
@@ -223,7 +255,7 @@ class LoRaWANBase {
223255
* @return It could be one of these:
224256
* i) 0 if there is nothing else to read.
225257
* ii) Number of bytes written to user buffer.
226-
* iii) LORA_MAC_STATUS_WOULD_BLOCK if there is
258+
* iii) LORAWAN_STATUS_WOULD_BLOCK if there is
227259
* nothing available to read at the moment.
228260
* iv) A negative error code on failure.
229261
*/
@@ -298,7 +330,7 @@ class LoRaWANBase {
298330
* @param callbacks A pointer to the structure containing application
299331
* callbacks.
300332
*/
301-
virtual lora_mac_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks) = 0;
333+
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks) = 0;
302334
};
303335

304336
#endif /* LORAWAN_BASE_H_ */

0 commit comments

Comments
 (0)