-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathrn2xx3.h
690 lines (618 loc) · 24.4 KB
/
rn2xx3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/*
* Copyright (C) 2017 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_rn2xx3 RN2483/RN2903 LoRa module driver
* @ingroup drivers_netdev
* @brief High-level driver for the RN2483/RN2903 LoRa modules
* @{
*
* @file
* @brief High-level driver for the RN2483/RN2903 LoRa modules
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/
#ifndef RN2XX3_H
#define RN2XX3_H
#include <stdint.h>
#include "xtimer.h"
#include "periph/uart.h"
#include "periph/gpio.h"
#include "net/netdev.h"
#include "net/loramac.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Maximum length of an exchanged messages with commands
*/
#define RN2XX3_MAX_BUF (40U)
/**
* @brief Maximum length of an RX message
*
* LoRaMAC payload can be up to 250 bytes.
*/
#define RN2XX3_RX_MAX_BUF (250U)
/**
* @brief Maximum delay in second to receive a reply from server.
*/
#define RN2XX3_REPLY_DELAY_TIMEOUT (60U)
/**
* @brief Minimum sleep duration (in ms)
*/
#define RN2XX3_SLEEP_MIN (100U)
/**
* @brief Default sleep duration (in ms)
*/
#ifndef RN2XX3_DEFAULT_SLEEP
#define RN2XX3_DEFAULT_SLEEP (5000U)
#endif
#if defined(MODULE_RN2903)
#define RN2XX3_FREQ_BAND (915U)
#elif defined(MODULE_RN2483)
#define RN2XX3_FREQ_BAND (868U)
#else
#error "Unsupported module type, use either RN2483 or RN2903"
#endif
/**
* @brief Command responses and server replies status codes
*/
enum {
RN2XX3_OK, /**< Command is valid */
RN2XX3_DATA, /**< Command returned data */
RN2XX3_TIMEOUT, /**< Command timeout */
/* all other error codes */
RN2XX3_ERR_MAC_INIT, /**< Device mac initialization failed */
RN2XX3_ERR_INVALID_PARAM, /**< Wrong command given */
RN2XX3_ERR_NOT_JOINED, /**< Network is not joined */
RN2XX3_ERR_NO_FREE_CH, /**< All channels are busy */
RN2XX3_ERR_SILENT, /**< Device is in Silent Immediately state */
RN2XX3_ERR_FR_CNT_REJOIN_NEEDED, /**< Frame counter rolled over */
RN2XX3_ERR_BUSY, /**< MAC is not in Idle state */
RN2XX3_ERR_MAC_PAUSED, /**< MAC was paused */
RN2XX3_ERR_INVALID_DATA_LENGTH, /**< Wrong payload given */
RN2XX3_ERR_KEYS_NOT_INIT, /**< Keys not configured ("mac join" command) */
RN2XX3_ERR_SLEEP_MODE, /**< Failure because device is in sleep mode */
/* all other reply codes */
RN2XX3_REPLY_TX_MAC_OK, /**< MAC transmission successful */
RN2XX3_REPLY_TX_MAC_ERR, /**< MAC transmission failed */
RN2XX3_REPLY_TX_INVALID_DATA_LEN, /**< Application payload too large */
RN2XX3_REPLY_TX_MAC_RX, /**< Data received from server */
RN2XX3_REPLY_JOIN_ACCEPTED, /**< Join procedure successful */
RN2XX3_REPLY_JOIN_DENIED, /**< Join procedure failed */
RN2XX3_REPLY_TIMEOUT, /**< No MAC reply received from server */
RN2XX3_REPLY_OTHER, /**< Unknown reply */
};
/**
* @brief Internal states of the device
*/
enum {
RN2XX3_INT_STATE_RESET, /**< the device is being reset or initialized */
RN2XX3_INT_STATE_CMD, /**< waiting command response */
RN2XX3_INT_STATE_IDLE, /**< waiting for incoming commands */
RN2XX3_INT_STATE_SLEEP, /**< sleep mode */
RN2XX3_INT_STATE_MAC_JOIN, /**< waiting for mac join procedure reply */
RN2XX3_INT_STATE_MAC_TX, /**< waiting for mac tx reply */
RN2XX3_INT_STATE_MAC_RX_PORT, /**< waiting for mac rx port */
RN2XX3_INT_STATE_MAC_RX_MESSAGE, /**< waiting for mac rx message */
};
/**
* @brief LoRaMAC communication settings
*/
typedef struct {
uint32_t rx2_freq; /**< Center frequency used for second receive window */
loramac_dr_idx_t rx2_dr; /**< Datarate used for second receive window */
uint8_t tx_port; /**< Application TX port (between 1 and 223) */
loramac_tx_mode_t tx_mode; /**< TX mode, either confirmable of unconfirmable */
uint8_t rx_port; /**< RX port (between 1 and 223) */
} loramac_settings_t;
/**
* @brief Configuration parameters for RN2483/RN2903 devices
*/
typedef struct {
uart_t uart; /**< UART interfaced the device is connected to */
uint32_t baudrate; /**< baudrate to use */
gpio_t pin_reset; /**< GPIO pin that is connected to the STATUS pin
set to GPIO_UNDEF if not used */
} rn2xx3_params_t;
/**
* @brief RN2483/RN2903 device descriptor
*/
typedef struct {
netdev_t netdev; /**< Netdev parent struct */
/* device driver specific fields */
rn2xx3_params_t p; /**< configuration parameters */
loramac_settings_t loramac; /**< loramac communication settings */
/* values for the UART TX state machine */
char cmd_buf[RN2XX3_MAX_BUF]; /**< command to send data buffer */
mutex_t cmd_lock; /**< mutex to allow only one
* command at a time */
uint8_t int_state; /**< current state of the device */
/* buffer and synchronization for command responses */
mutex_t resp_lock; /**< mutex for waiting for command
* response */
char resp_buf[RN2XX3_MAX_BUF]; /**< command response data buffer */
uint16_t resp_size; /**< counter for received char in response */
uint8_t resp_done; /**< check if response has completed */
/* buffer for RX messages */
char rx_tmp_buf[2]; /**< Temporary RX buffer used to convert
* 2 hex characters in one byte on the
* fly. */
uint8_t rx_buf[RN2XX3_RX_MAX_BUF]; /**< RX data buffer */
uint16_t rx_size; /**< counter for received char in RX */
/* timers */
xtimer_t sleep_timer; /**< Timer used to count module sleep time */
uint32_t sleep; /**< module sleep duration */
} rn2xx3_t;
/**
* @brief Prepares the given RN2XX3 device
*
* @param[out] dev RN2XX3 device to initialize
* @param[in] params parameters for device initialization
*/
void rn2xx3_setup(rn2xx3_t *dev, const rn2xx3_params_t *params);
/**
* @brief Initializes the RN2XX3 device
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return -ENXIO if UART initialization failed
* @return RN2XX3_TIMEOUT if UART communication failed
*/
int rn2xx3_init(rn2xx3_t *dev);
/**
* @brief Restarts the RN2XX2 device
*
* After calling this function, dev->resp_buf contains the module
* name and version string.
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if UART communication failed
*/
int rn2xx3_sys_reset(rn2xx3_t *dev);
/**
* @brief Performs a factory reset of the module
*
* The configuration data and user EEPPROM are reinitialized to factory default
* values and the module reboots
*
* After calling this function, dev->resp_buf contains the module name and
* version string.
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if UART communication failed
*/
int rn2xx3_sys_factory_reset(rn2xx3_t *dev);
/**
* @brief Puts the RN2XX2 device in sleep mode
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if UART communication failed
*/
int rn2xx3_sys_sleep(rn2xx3_t *dev);
/**
* @brief Initializes the RN2XX3 device MAC layer
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if UART communication failed
*/
int rn2xx3_mac_init(rn2xx3_t *dev);
/**
* @brief Writes a command to the RN2XX3 device
*
* The module will immediately reply with a meaningful message if the command
* is valid or not.
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if no response is received from the module
* @return RN2XX3_ERR_INVALID_PARAM if command is invalid
* @return RN2XX3_ERR_NOT_JOINED if network is not joined
* @return RN2XX3_ERR_NO_FREE_CH if no free channel
* @return RN2XX3_ERR_SILENT if device is in Silent state
* @return RN2XX3_ERR_FR_CNT_REJOIN_NEEDED if frame counter rolled over
* @return RN2XX3_ERR_BUSY if MAC is not in Idle state
* @return RN2XX3_ERR_INVALID_DATA_LENGTH if payload is too large
* @return RN2XX3_ERR_KEYS_NOT_INIT if keys are not configured
*/
int rn2xx3_write_cmd(rn2xx3_t *dev);
/**
* @brief Writes a command to the RN2XX3 device but don't wait for timeout
*
* The module will immediately reply with a meaningful message if the command
* is valid or not.
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_ERR_INVALID_PARAM if command is invalid
* @return RN2XX3_ERR_NOT_JOINED if network is not joined
* @return RN2XX3_ERR_NO_FREE_CH if no free channel
* @return RN2XX3_ERR_SILENT if device is in Silent state
* @return RN2XX3_ERR_FR_CNT_REJOIN_NEEDED if frame counter rolled over
* @return RN2XX3_ERR_BUSY if MAC is not in Idle state
* @return RN2XX3_ERR_INVALID_DATA_LENGTH if payload is too large
* @return RN2XX3_ERR_KEYS_NOT_INIT if keys are not configured
*/
int rn2xx3_write_cmd_no_wait(rn2xx3_t *dev);
/**
* @brief Waits for a response to a command from the device
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK on success
* @return RN2XX3_TIMEOUT if no response is received from the module
* @return RN2XX3_ERR_INVALID_PARAM if command is invalid
* @return RN2XX3_ERR_NOT_JOINED if network is not joined
* @return RN2XX3_ERR_NO_FREE_CH if no free channel
* @return RN2XX3_ERR_SILENT if device is in Silent state
* @return RN2XX3_ERR_FR_CNT_REJOIN_NEEDED if frame counter rolled over
* @return RN2XX3_ERR_BUSY if MAC is not in Idle state
* @return RN2XX3_ERR_INVALID_DATA_LENGTH if payload is too large
* @return RN2XX3_ERR_KEYS_NOT_INIT if keys are not configured
*/
int rn2xx3_wait_response(rn2xx3_t *dev);
/**
* @brief Waits for a reply from the LoRaWAN network
*
* @param[in] dev LoRaBee device descriptor
* @param[in] timeout Reply wait timeout in seconds
*
* @return RN2XX3_REPLY_TIMEOUT when no MAC reply is received from server
* @return RN2XX3_REPLY_TX_MAC_OK when MAC transmission succeeded
* @return RN2XX3_REPLY_TX_MAC_ERR when MAC transmission failed
* @return RN2XX3_REPLY_TX_MAC_RX when received downlink data from server
* @return RN2XX3_REPLY_TX_INVALID_DATA_LEN when Application payload is too large
* @return RN2XX3_REPLY_JOIN_ACCEPTED when the join procedure succeded
* @return RN2XX3_REPLY_JOIN_DENIED when the join procedure failed
* @return RN2XX3_REPLY_OTHER when an unknown reply is received
*/
int rn2xx3_wait_reply(rn2xx3_t *dev, uint8_t timeout);
/**
* @brief Sends data to LoRaWAN server
*
* @param[in] dev RN2XX3 device descriptor
* @param[in] payload Payload to transmit
* @param[in] payload_len Payload length to transmit
*
* @return RN2XX3_ERR_KEYS_NOT_INIT if the loramac params are not configured
* @return RN2XX3_ERR_NO_FREE_CH if channels are busy
* @return RN2XX3_ERR_SILENT if device is in Silent state
* @return RN2XX3_ERR_BUSY if MAC layer is in idle state
* @return RN2XX3_ERR_MAC_PAUSED if MAC layed is paused
* @return RN2XX3_REPLY_TX_INVALID_DATA_LEN if payload is too large
* @return RN2XX3_REPLY_TX_MAC_ERR when MAC transmission failed
* @return RN2XX3_REPLY_TX_MAC_RX when received downlink data from server
* @return RN2XX3_REPLY_TX_MAC_OK when MAC transmission succeeded
*/
int rn2xx3_mac_tx(rn2xx3_t *dev, uint8_t *payload, uint8_t payload_len);
/**
* @brief Starts network activation procedure
*
* @param[in] dev RN2XX3 device descriptor
* @param[in] mode Activation procedure type
*
* @return RN2XX3_ERR_KEYS_NOT_INIT if the loramac params are not configured
* @return RN2XX3_ERR_NO_FREE_CH if channels are busy
* @return RN2XX3_ERR_SILENT if device is in Silent state
* @return RN2XX3_ERR_BUSY if MAC layer is in idle state
* @return RN2XX3_ERR_MAC_PAUSED if MAC layed is paused
* @return RN2XX3_REPLY_JOIN_ACCEPTED when the join procedure succeded
* @return RN2XX3_REPLY_JOIN_DENIED when the join procedure failed
*/
int rn2xx3_mac_join_network(rn2xx3_t *dev, loramac_join_mode_t mode);
/**
* @brief Saves current LoRaMAC configuration to internal EEPROM
*
* The configuration parameters saved are: frequency band, end device EUI,
* application EUI, application key, network session key, application session
* key, end device EUI and all channel parameters.
*
* @param[in] dev RN2XX3 device descriptor
*
* @return RN2XX3_OK if all is ok
* @return RN2XX3_TIMEOUT if the device didn't reply
*/
int rn2xx3_mac_save(rn2xx3_t *dev);
/* Get/Set functions definitions */
/**
* @brief Gets the rn2xx3 LoRaMAC device EUI
*
* The device EUI is an array of 8 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[out] eui The device EUI
*/
void rn2xx3_mac_get_deveui(rn2xx3_t *dev, uint8_t *eui);
/**
* @brief Sets the rn2xx3 LoRaMAC device EUI
*
* The device EUI is an array of 8 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] eui The device EUI
*/
void rn2xx3_mac_set_deveui(rn2xx3_t *dev, const uint8_t *eui);
/**
* @brief Gets the rn2xx3 LoRaMAC application EUI
*
* The application EUI is an array of 8 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[out] eui The application EUI
*/
void rn2xx3_mac_get_appeui(rn2xx3_t *dev, uint8_t *eui);
/**
* @brief Sets the rn2xx3 LoRaMAC application EUI
*
* The application key is an array of 8 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] eui The application EUI
*/
void rn2xx3_mac_set_appeui(rn2xx3_t *dev, const uint8_t *eui);
/**
* @brief Sets the rn2xx3 LoRaMAC application key
*
* The application key is an array of 16 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] key The application key
*/
void rn2xx3_mac_set_appkey(rn2xx3_t *dev, const uint8_t *key);
/**
* @brief Sets the rn2xx3 LoRaMAC application session key
*
* The application session key is an array of 16 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] key The application session key
*/
void rn2xx3_mac_set_appskey(rn2xx3_t *dev, const uint8_t *key);
/**
* @brief Sets the rn2xx3 LoRaMAC network session key
*
* The network session key is an array of 16 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] key The network session key
*/
void rn2xx3_mac_set_nwkskey(rn2xx3_t *dev, const uint8_t *key);
/**
* @brief Gets the rn2xx3 LoRaMAC device address
*
* The device address is an array of 4 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[out] addr The device address
*/
void rn2xx3_mac_get_devaddr(rn2xx3_t *dev, uint8_t *addr);
/**
* @brief Sets the rn2xx3 LoRaMAC device address
*
* The device address is an array of 4 bytes.
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] addr The device address
*/
void rn2xx3_mac_set_devaddr(rn2xx3_t *dev, const uint8_t *addr);
/**
* @brief Gets the rn2xx3 LoRaMAC TX radio power index
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The radio power index
*/
loramac_tx_pwr_idx_t rn2xx3_mac_get_tx_power(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC transmission power index
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] power The TX power index
*/
void rn2xx3_mac_set_tx_power(rn2xx3_t *dev, loramac_tx_pwr_idx_t power);
/**
* @brief Gets the rn2xx3 LoRaMAC datarate
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The datarate
*/
loramac_dr_idx_t rn2xx3_mac_get_dr(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC datarate
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] dr The datarate
*/
void rn2xx3_mac_set_dr(rn2xx3_t *dev, loramac_dr_idx_t dr);
/**
* @brief Gets the rn2xx3 LoRaMAC frequency band in operation
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The frequency band
*/
uint16_t rn2xx3_mac_get_band(rn2xx3_t *dev);
/**
* @brief Checks if the rn2xx3 LoRaMAC adaptive datarate is enabled/disabled
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return true if adaptive datarate is set,
* false otherwise
*/
bool rn2xx3_mac_get_adr(rn2xx3_t *dev);
/**
* @brief Enables/disables the rn2xx3 LoRaMAC adaptive datarate
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] adr The adaptive datarate mode
*/
void rn2xx3_mac_set_adr(rn2xx3_t *dev, bool adr);
/**
* @brief Sets the rn2xx3 battery level measured by the end device
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] battery The battery level:
* - 0 means external power,
* - 1 means low level,
* - 254 high level,
* - 255 means the battery level couldn't be
* measured by the device.
*/
void rn2xx3_mac_set_battery(rn2xx3_t *dev, uint8_t battery);
/**
* @brief Gets the rn2xx3 LoRaMAC uplink retransmission retries number
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The number of uplink retransmission retries
*/
uint8_t rn2xx3_mac_get_retx(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC uplink retransmission retries number
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] retx The number of uplink retransmission retries
*/
void rn2xx3_mac_set_retx(rn2xx3_t *dev, uint8_t retx);
/**
* @brief Sets the rn2xx3 LoRaMAC link check interval (in seconds)
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] linkchk The link check interval in seconds
*/
void rn2xx3_mac_set_linkchk_interval(rn2xx3_t *dev, uint16_t linkchk);
/**
* @brief Gets the rn2xx3 LoRaMAC interval delay before the first reception window (in ms)
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The delay in ms
*/
uint16_t rn2xx3_mac_get_rx1_delay(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC interval delay before the first reception window (in ms)
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] rx1 The delay in ms
*/
void rn2xx3_mac_set_rx1_delay(rn2xx3_t *dev, uint16_t rx1);
/**
* @brief Gets the rn2xx3 LoRaMAC interval delay before the second reception window (in ms)
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The delay in ms
*/
uint16_t rn2xx3_mac_get_rx2_delay(rn2xx3_t *dev);
/**
* @brief Checks the rn2xx3 LoRaMAC automatic reply state
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The automatic reply state
*/
bool rn2xx3_mac_get_ar(rn2xx3_t *dev);
/**
* @brief Enables/disables LoRaMAC rn2xx3 MAC automatic reply state
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] ar The automatic reply state
*/
void rn2xx3_mac_set_ar(rn2xx3_t *dev, bool ar);
/**
* @brief Gets the rn2xx3 LoRaMAC datarate used for second receive window
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The datarate during second receive window
*/
loramac_dr_idx_t rn2xx3_mac_get_rx2_dr(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC datarate used for second receive window
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] dr The datarate during second receive window
*/
void rn2xx3_mac_set_rx2_dr(rn2xx3_t *dev, loramac_dr_idx_t dr);
/**
* @brief Gets the rn2xx3 LoRaMAC frequency used during second receive window (in Hz)
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The frequency during second receive window
*/
uint32_t rn2xx3_mac_get_rx2_freq(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC frequency used during second receive window (in Hz)
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] freq The frequency during second receive window
*/
void rn2xx3_mac_set_rx2_freq(rn2xx3_t *dev, uint32_t freq);
/**
* @brief Gets the rn2xx3 LoRaMAC TX port
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The TX port
*/
uint8_t rn2xx3_mac_get_tx_port(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC TX port
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] port The TX port (from 1 to 223)
*/
void rn2xx3_mac_set_tx_port(rn2xx3_t *dev, uint8_t port);
/**
* @brief Gets the rn2xx3 LoRaMAC TX mode
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The TX mode, either confirmable or unconfirmable
*/
loramac_tx_mode_t rn2xx3_mac_get_tx_mode(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 LoRaMAC TX mode
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] mode The TX mode, either confirmable or unconfirmable
*/
void rn2xx3_mac_set_tx_mode(rn2xx3_t *dev, loramac_tx_mode_t mode);
/**
* @brief Parses the response buffer to get the LoRaWAN RX port
*
* @param[in] dev The rn2xx3 device descriptor
*
* @return The RX port (between 1 and 223)
*/
uint8_t rn2xx3_mac_get_rx_port(rn2xx3_t *dev);
/**
* @brief Sets the rn2xx3 sleep mode duration (in ms)
*
* @param[in] dev The rn2xx3 device descriptor
* @param[in] sleep The sleep mode duration (ms)
*/
void rn2xx3_sys_set_sleep_duration(rn2xx3_t *dev, uint32_t sleep);
#ifdef __cplusplus
}
#endif
#endif /* RN2XX3_H */
/** @} */