-
Notifications
You must be signed in to change notification settings - Fork 1
/
mDot.h
1937 lines (1639 loc) · 60.7 KB
/
mDot.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
* COPYRIGHT 2015 MULTI-TECH SYSTEMS, INC.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of MULTI-TECH SYSTEMS, INC. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#ifndef MDOT_H
#define MDOT_H
#include "mbed.h"
#include "rtos.h"
#include "Mote.h"
#include <vector>
#include <map>
#include <string>
#include "FlashRecordStore.h"
class mDotEvent;
class LoRaConfig;
mbed::BlockDevice * mdot_override_external_block_device();
class mDot {
friend class mDotEvent;
private:
mDot(lora::ChannelPlan* plan);
~mDot();
void initLora();
void setLastError(const std::string& str);
static bool validateBaudRate(const uint32_t& baud);
static bool validateFrequencySubBand(const uint8_t& band);
int32_t joinBase(const uint32_t& retries);
int32_t sendBase(const std::vector<uint8_t>& data, const bool& confirmed = false, const bool& blocking = true, const bool& highBw = false);
void waitForPacket();
void waitForLinkCheck();
mDot(const mDot&);
mDot& operator=(const mDot&);
void enterStopMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
void enterStandbyMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
static mDot* _instance;
lora::Mote* _mote;
LoRaConfig* _config;
lora::Settings _settings;
mDotEvent* _events;
std::string _last_error;
static const uint32_t _baud_rates[];
uint8_t _linkFailCount;
uint8_t _class;
InterruptIn* _wakeup;
PinName _wakeup_pin;
typedef enum {
OFF,
ON,
BLINK,
} state;
public:
uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
void RTC_DisableWakeupTimer();
void RTC_EnableWakeupTimer();
#if defined(TARGET_MTS_MDOT_F411RE)
typedef enum {
FM_APPEND = (1 << 0),
FM_TRUNC = (1 << 1),
FM_CREAT = (1 << 2),
FM_RDONLY = (1 << 3),
FM_WRONLY = (1 << 4),
FM_RDWR = (FM_RDONLY | FM_WRONLY),
FM_DIRECT = (1 << 5)
} FileMode;
#endif /* TARGET_MTS_MDOT_F411RE */
typedef enum {
MDOT_OK = 0,
MDOT_INVALID_PARAM = -1,
MDOT_TX_ERROR = -2,
MDOT_RX_ERROR = -3,
MDOT_JOIN_ERROR = -4,
MDOT_TIMEOUT = -5,
MDOT_NOT_JOINED = -6,
MDOT_ENCRYPTION_DISABLED = -7,
MDOT_NO_FREE_CHAN = -8,
MDOT_TEST_MODE = -9,
MDOT_NO_ENABLED_CHAN = -10,
MDOT_AGGREGATED_DUTY_CYCLE = -11,
MDOT_MAX_PAYLOAD_EXCEEDED = -12,
MDOT_LBT_CHANNEL_BUSY = -13,
MDOT_NOT_IDLE = -14,
MDOT_UNSUPPORTED = -15,
MDOT_ERROR = -1024,
} mdot_ret_code;
enum JoinMode {
MANUAL = 0,
OTA,
AUTO_OTA,
PEER_TO_PEER
};
enum Mode {
COMMAND_MODE,
SERIAL_MODE
};
enum RX_Output {
HEXADECIMAL,
BINARY,
EXTENDED,
EXTENDED_HEX
};
enum DataRates {
DR0,
DR1,
DR2,
DR3,
DR4,
DR5,
DR6,
DR7,
DR8,
DR9,
DR10,
DR11,
DR12,
DR13,
DR14,
DR15
};
enum FrequencySubBands {
FSB_ALL,
FSB_1,
FSB_2,
FSB_3,
FSB_4,
FSB_5,
FSB_6,
FSB_7,
FSB_8
};
enum wakeup_mode {
RTC_ALARM,
INTERRUPT,
RTC_ALARM_OR_INTERRUPT
};
enum wakeup_trigger {
WAKE_TRIGGER_ANY,
WAKE_TRIGGER_RISE,
WAKE_TRIGGER_FALL
};
enum UserBackupRegs {
UBR0,
UBR1,
UBR2,
UBR3,
UBR4,
UBR5,
UBR6,
UBR7,
UBR8,
UBR9
#if defined (TARGET_XDOT_L151CC)
,UBR10,
UBR11,
UBR12,
UBR13,
UBR14,
UBR15,
UBR16,
UBR17,
UBR18,
UBR19,
UBR20,
UBR21
#endif /* TARGET_XDOT_L151CC */
};
#if defined(TARGET_MTS_MDOT_F411RE)
typedef struct {
int16_t fd;
char name[33];
uint32_t size;
} mdot_file;
#endif /* TARGET_MTS_MDOT_F411RE */
typedef struct {
uint32_t Up;
uint32_t Down;
uint32_t Joins;
uint32_t JoinFails;
uint32_t MissedAcks;
uint32_t CRCErrors;
} mdot_stats;
typedef struct {
int16_t last;
int16_t min;
int16_t max;
int16_t avg;
} rssi_stats;
typedef struct {
int16_t last;
int16_t min;
int16_t max;
int16_t avg;
} snr_stats;
typedef struct {
bool status;
uint8_t dBm;
uint32_t gateways;
std::vector<uint8_t> payload;
} link_check;
typedef struct {
int32_t status;
int16_t rssi;
int16_t snr;
} ping_response;
static std::string JoinModeStr(uint8_t mode);
static std::string ModeStr(uint8_t mode);
static std::string RxOutputStr(uint8_t format);
static std::string DataRateStr(uint8_t rate);
static std::string FrequencyBandStr(uint8_t band);
static std::string FrequencySubBandStr(uint8_t band);
#if defined(TARGET_MTS_MDOT_F411RE)
uint32_t UserRegisters[10];
#else
uint32_t UserRegisters[22];
#endif /* TARGET_MTS_MDOT_F411RE */
/**
* Get a handle to the singleton object
* @param plan the channel plan to use
* @returns pointer to mDot object
*/
static mDot* getInstance(lora::ChannelPlan* plan);
/**
* Can only be used after a dot has
* configured with a plan
* @returns pointer to mDot object
*/
static mDot* getInstance();
void setEvents(mDotEvent* events);
/**
*
* Get library version information
* @returns string containing library version information
*/
std::string getId();
/**
* Get MTS LoRa version information
* @returns string containing MTS LoRa version information
*/
std::string getMtsLoraId();
/**
* MAC version
*
* @return string containing version information of supported LoRaWAN MAC Version
*/
const char* getMACVersion();
/**
* Perform a soft reset of the system
*/
void resetCpu();
/**
* Reset config to factory default
*/
void resetConfig();
/**
* Save config data to non volatile memory
* @returns true if success, false if failure
*/
bool saveConfig();
/**
* Set the log level for the library
* options are:
* NONE_LEVEL - logging is off at this level
* FATAL_LEVEL - only critical errors will be reported
* ERROR_LEVEL
* WARNING_LEVEL
* INFO_LEVEL
* DEBUG_LEVEL
* TRACE_LEVEL - every detail will be reported
* @param level the level to log at
* @returns MDOT_OK if success
*/
int32_t setLogLevel(const uint8_t& level);
/**
* Get the current log level for the library
* @returns current log level
*/
uint8_t getLogLevel();
/**
* Seed pseudo RNG in LoRaMac layer, uses random value from radio RSSI reading by default
* @param seed for RNG
*/
void seedRandom(uint32_t seed);
/**
* @returns true if MAC command answers are ready to be sent
*/
bool hasMacCommands();
uint8_t setChannelPlan(lora::ChannelPlan* plan);
lora::Settings* getSettings();
/**
* Returns boolean indicative of start-up from standby mode
* @returns true if dot woke from standby
*/
bool getStandbyFlag();
std::vector<uint16_t> getChannelMask();
int32_t setChannelMask(uint8_t offset, uint16_t mask);
/**
* Add a channel
* @param index - 0-15
* @param frequency - depends on selected channel plan
* @param datarateRange - min and max DR, range 0-F, set to one byte.
* Minimum DR is the low 4 bits
* Maximum DR is the high 4 bits
* @returns MDOT_OK
*/
int32_t addChannel(uint8_t index, uint32_t frequency, uint8_t datarateRange);
/**
* Add a downlink channel
* @param index - 0-15
* @param frequency - depends on selected channel plan
* @returns MDOT_OK
*/
int32_t addDownlinkChannel(uint8_t index, uint32_t frequency);
/**
* Get list of channel frequencies currently in use
* @returns vector of channels currently in use
*/
std::vector<uint32_t> getChannels();
/**
* Get list of downlink channel frequencies currently in use
* @returns vector of channels currently in use
*/
std::vector<uint32_t> getDownlinkChannels();
/**
* Get list of channel datarate ranges currently in use
* @returns vector of datarate ranges currently in use
*/
std::vector<uint8_t> getChannelRanges();
/**
* Get list of channel frequencies in config file to be used as session defaults
* @returns vector of channels in config file
*/
std::vector<uint32_t> getConfigChannels();
/**
* Get list of channel datarate ranges in config file to be used as session defaults
* @returns vector of datarate ranges in config file
*/
std::vector<uint8_t> getConfigChannelRanges();
/**
* Get default frequency band
* @returns frequency band the device was manufactured for
*/
uint8_t getDefaultFrequencyBand();
/**
* Set frequency sub band
* only applicable if frequency band is set for United States (FB_915)
* sub band 0 will allow the radio to use all 64 channels
* sub band 1 - 8 will allow the radio to use the 8 channels in that sub band
* for use with Conduit gateway and MTAC_LORA, use sub bands 1 - 8, not sub band 0
* @param band the sub band to use (0 - 8)
* @returns MDOT_OK if success
*/
int32_t setFrequencySubBand(const uint8_t& band);
/**
* Get frequency sub band
* @returns frequency sub band currently in use
*/
uint8_t getFrequencySubBand();
/**
* Get frequency band
* @returns frequency band (channel plan) currently in use
*/
uint8_t getFrequencyBand();
/**
* Get channel plan name
* @returns name of channel plan currently in use
*/
std::string getChannelPlanName();
/**
* Get the datarate currently in use within the MAC layer
* returns 0-15
*/
uint8_t getSessionDataRate();
/**
* Get the current max EIRP used in the channel plan
* May be changed by the network server
* returns 0-36
*/
uint8_t getSessionMaxEIRP();
/**
* Set the current max EIRP used in the channel plan
* May be changed by the network server
* accepts 0-36
*/
void setSessionMaxEIRP(uint8_t max);
/**
* Get the current downlink dwell time used in the channel plan
* May be changed by the network server
* returns 0-1
*/
uint8_t getSessionDownlinkDwelltime();
/**
* Set the current downlink dwell time used in the channel plan
* May be changed by the network server
* accepts 0-1
*/
void setSessionDownlinkDwelltime(uint8_t dwell);
/**
* Get the current uplink dwell time used in the channel plan
* May be changed by the network server
* returns 0-1
*/
uint8_t getSessionUplinkDwelltime();
/**
* Set the current uplink dwell time used in the channel plan
* May be changed by the network server
* accepts 0-1
*/
void setSessionUplinkDwelltime(uint8_t dwell);
/**
* Set the current downlink dwell time used in the channel plan
* May be changed by the network server
* accepts 0-1
*/
uint32_t getListenBeforeTalkTime(uint8_t ms);
/**
* Set the current downlink dwell time used in the channel plan
* May be changed by the network server
* accepts 0-1
*/
void setListenBeforeTalkTime(uint32_t ms);
/**
* Set public network mode
* 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
* PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band
* PUBLIC_LORAWAN - Sync Word 0x34
* PRIVATE_LORAWAN - Sync Word 0x12
*
* The default Join Delay is 5 seconds
* The default Join Delay for PRIVATE_MTS was 1 second in the previous release
* The Join Delay must be changed independently of Public Network setting
*
* @see lora::NetworkType
* @returns MDOT_OK if success
*/
int32_t setPublicNetwork(const uint8_t& val);
/**
* Get public network mode
*
* The default Join Delay is 5 seconds
* The default Join Delay for PRIVATE_MTS was 1 second in the previous release
* The Join Delay must be changed independently of Public Network setting
*
* @see lora:NetworkType
* @returns 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
*/
uint8_t getPublicNetwork();
/**
* Get the device ID
* @returns vector containing the device ID (size 8)
*/
std::vector<uint8_t> getDeviceId();
/**
* Get the device port to be used for lora application data (1-223)
* @returns port
*/
uint8_t getAppPort();
/**
* Set the device port to be used for lora application data (1-223)
* @returns MDOT_OK if success
*/
int32_t setAppPort(uint8_t port);
/**
* Set the device class A, B or C
* @returns MDOT_OK if success
*/
int32_t setClass(std::string newClass);
/**
* Set the device class A, B or C without changing configuration, revert class after reset
* @returns MDOT_OK if success
*/
int32_t setTempClass(std::string newClass);
/**
* Get the device class A, B or C
* @returns MDOT_OK if success
*/
std::string getClass();
/**
* Get the max packet length with current settings
* @returns max packet length
*/
uint8_t getMaxPacketLength();
/**
* Set network address
* for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
* @param addr a vector of 4 bytes
* @returns MDOT_OK if success
*/
int32_t setNetworkAddress(const std::vector<uint8_t>& addr);
/**
* Get network address
* @returns vector containing network address (size 4)
*/
std::vector<uint8_t> getNetworkAddress();
/**
* Set network session key
* for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
* @param key a vector of 16 bytes
* @returns MDOT_OK if success
*/
int32_t setNetworkSessionKey(const std::vector<uint8_t>& key);
/**
* Get network session key
* @returns vector containing network session key (size 16)
*/
std::vector<uint8_t> getNetworkSessionKey();
/**
* Set data session key
* for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
* @param key a vector of 16 bytes
* @returns MDOT_OK if success
*/
int32_t setDataSessionKey(const std::vector<uint8_t>& key);
/**
* Get data session key
* @returns vector containing data session key (size 16)
*/
std::vector<uint8_t> getDataSessionKey();
/**
* Set network name
* for use with OTA & AUTO_OTA network join modes
* generates network ID (crc64 of name) automatically
* @param name a string of of at least 8 bytes and no more than 128 bytes
* @return MDOT_OK if success
*/
int32_t setNetworkName(const std::string& name);
/**
* Get network name
* @return string containing network name (size 8 to 128)
*/
std::string getNetworkName();
/**
* Set network ID
* for use with OTA & AUTO_OTA network join modes
* setting network ID via this function sets network name to empty
* @param id a vector of 8 bytes
* @returns MDOT_OK if success
*/
int32_t setNetworkId(const std::vector<uint8_t>& id);
/**
* Get network ID
* @returns vector containing network ID (size 8)
*/
std::vector<uint8_t> getNetworkId();
/**
* Set network passphrase
* for use with OTA & AUTO_OTA network join modes
* generates network key (cmac of passphrase) automatically
* @param name a string of of at least 8 bytes and no more than 128 bytes
* @return MDOT_OK if success
*/
int32_t setNetworkPassphrase(const std::string& passphrase);
/**
* Get network passphrase
* @return string containing network passphrase (size 8 to 128)
*/
std::string getNetworkPassphrase();
/**
* Set network key
* for use with OTA & AUTO_OTA network join modes
* setting network key via this function sets network passphrase to empty
* @param id a vector of 16 bytes
* @returns MDOT_OK if success
*/
int32_t setNetworkKey(const std::vector<uint8_t>& id);
/**
* Get generic app key
* @returns a vector containing key (size 16)
*/
std::vector<uint8_t> getGenAppKey();
/**
* Set generic app key
* for use with Multicast key exchange
* @param id a vector of 16 bytes
* @returns MDOT_OK if success
*/
int32_t setGenAppKey(const std::vector<uint8_t>& id);
/**
* Get network key
* @returns a vector containing network key (size 16)
*/
std::vector<uint8_t> getNetworkKey();
/**
* Set lorawan application EUI
* equivalent to setNetworkId
* @param eui application EUI (size 8)
*/
int32_t setAppEUI(const uint8_t* eui);
/**
* Get lorawan application EUI
* equivalent to getNetworkId
* @returns vector containing application EUI (size 8)
*/
const uint8_t* getAppEUI();
/**
* Set lorawan application key
* equivalent to setNetworkKey
* @param eui application key (size 16)
*/
int32_t setAppKey(const uint8_t* key);
/**
* Set lorawan application key
* equivalent to getNetworkKey
* @returns eui application key (size 16)
*/
const uint8_t* getAppKey();
/**
* Set device nonce counter incremented with each Join Request
* @returns MDOT_OK if success
*/
int32_t setDevNonce(const uint16_t& nonce);
/**
* Get device nonce counter incremented with each Join Request
* @returns join nonce
*/
uint16_t getDevNonce();
/**
* Set app nonce counter incremented with each Join Accept
* @returns MDOT_OK if success
*/
int32_t setAppNonce(const uint32_t& nonce);
/**
* Get app nonce counter incremented with each Join Accept
* @returns app nonce
*/
uint32_t getAppNonce();
/**
* Enable/disable Join Nonce validation for App Nonce in Join Accept
* Default is enabled
*/
int32_t setJoinNonceValidation(bool enable);
bool getJoinNonceValidation();
/**
* Add a multicast session address and keys
* Downlink counter is set to 0
* Up to 8 MULTICAST_SESSIONS can be set
*/
int32_t setMulticastSession(uint8_t index, uint32_t addr, const uint8_t* nsk, const uint8_t* ask);
/**
* Set multicast session info
* Up to 8 MULTICAST_SESSIONS
*/
int32_t setMulticastAddress(uint8_t index, uint32_t addr);
int32_t setMulticastNetworkSessionKey(uint8_t index, const uint8_t* nsk);
int32_t setMulticastApplicationSessionKey(uint8_t index, const uint8_t* ask);
/**
* Set a multicast session counter
* Up to 8 MULTICAST_SESSIONS
*/
int32_t setMulticastDownlinkCounter(uint8_t index, uint32_t count);
int32_t setMulticastPeriodicity(uint8_t index, int8_t period);
int32_t setMulticastFrequency(uint8_t index, uint32_t freq);
int32_t setMulticastDatarate(uint8_t index, uint8_t dr);
/**
* Get multicast session info
* Up to 8 MULTICAST_SESSIONS
*/
uint32_t getMulticastAddress(uint8_t index);
int32_t getMulticastNetworkSessionKey(uint8_t index, uint8_t* nsk);
int32_t getMulticastApplicationSessionKey(uint8_t index, uint8_t* ask);
uint32_t getMulticastDownlinkCounter(uint8_t index);
int8_t getMulticastPeriodicity(uint8_t index);
uint32_t getMulticastFrequency(uint8_t index);
uint8_t getMulticastDatarate(uint8_t index);
/**
* Attempt to join network
* each attempt will be made with a random datarate up to the configured datarate
* JoinRequest backoff between tries is enforced to 1% for 1st hour, 0.1% for 1-10 hours and 0.01% after 10 hours
* Check getNextTxMs() for time until next join attempt can be made
* @returns MDOT_OK if success
*/
int32_t joinNetwork();
/**
* Attempts to join network once
* @returns MDOT_OK if success
*/
int32_t joinNetworkOnce();
/**
* Resets current network session, essentially disconnecting from the network
* has no effect for MANUAL network join mode
*/
void resetNetworkSession();
/**
* Restore saved network session from flash
* has no effect for MANUAL network join mode
*/
void restoreNetworkSession();
/**
* Save current network session to flash
* has no effect for MANUAL network join mode
*/
void saveNetworkSession();
/**
* Set number of times joining will retry each sub-band before changing
* to the next subband in US915 and AU915
* @param retries must be between 0 - 255
* @returns MDOT_OK if success
*/
int32_t setJoinRetries(const uint8_t& retries);
/**
* Get number of times joining will retry each sub-band
* @returns join retries (0 - 255)
*/
uint8_t getJoinRetries();
/**
* Set network join mode
* MANUAL: set network address and session keys manually
* OTA: User sets network name and passphrase, then attempts to join
* AUTO_OTA: same as OTA, but network sessions can be saved and restored
* @param mode MANUAL, OTA, or AUTO_OTA
* @returns MDOT_OK if success
*/
int32_t setJoinMode(const uint8_t& mode);
/**
* Get network join mode
* @returns MANUAL, OTA, or AUTO_OTA
*/
uint8_t getJoinMode();
/**
* Get network join status
* @returns true if currently joined to network
*/
bool getNetworkJoinStatus();
/**
* Do a network link check
* application data may be returned in response to a network link check command
* @returns link_check structure containing success, dBm above noise floor, gateways in range, and packet payload
*/
link_check networkLinkCheck();
/**
* Set network link check count to perform automatic link checks every count packets
* only applicable if ACKs are disabled
* @param count must be between 0 - 255
* @returns MDOT_OK if success
*/
int32_t setLinkCheckCount(const uint8_t& count);
/**
* Get network link check count
* @returns count (0 - 255)
*/
uint8_t getLinkCheckCount();
/**
* Set network link check threshold, number of link check failures or missed acks to tolerate
* before considering network connection lost
* @pararm count must be between 0 - 255
* @returns MDOT_OK if success
*/
int32_t setLinkCheckThreshold(const uint8_t& count);
/**
* Get network link check threshold
* @returns threshold (0 - 255)
*/
uint8_t getLinkCheckThreshold();
/**
* Get/set number of failed link checks in the current session
* @returns count (0 - 255)
*/
uint8_t getLinkFailCount();
int32_t setLinkFailCount(uint8_t count);
/**
* Set UpLinkCounter number of packets sent to the gateway during this network session (sequence number)
* @returns MDOT_OK
*/
int32_t setUpLinkCounter(uint32_t count);
/**
* Get UpLinkCounter
* @returns number of packets sent to the gateway during this network session (sequence number)
*/
uint32_t getUpLinkCounter();
/**
* Set UpLinkCounter number of packets sent by the gateway during this network session (sequence number)
* @returns MDOT_OK
*/
int32_t setDownLinkCounter(uint32_t count);
/**
* Get DownLinkCounter
* @returns number of packets sent by the gateway during this network session (sequence number)
*/
uint32_t getDownLinkCounter();
/**
* Get RSSI stats. All fields are invalid if last is invalid.
* @returns rssi_stats struct containing last, min, max, and avg RSSI in dB
* @see lora::INVALID_RSSI
*/
rssi_stats getRssiStats();
/**
* Get SNR stats. All fields are invalid if last is invalid.
* @returns snr_stats struct containing last, min, max, and avg SNR in cB
* @see lora::INVALID_SNR
*/
snr_stats getSnrStats();
/**
* Get ms until next free channel
* only applicable for European models, US models return 0
* @returns time (ms) until a channel is free to use for transmitting
*/
uint32_t getNextTxMs();
/**
* Get available bytes for payload
* @returns bytes
*/
uint8_t getNextTxMaxSize();
/**
* Get join delay in seconds
* Defaults to 5 seconds
* Must match join delay setting of the network server
*
* The default Join Delay is 5 seconds
* The default Join Delay for PRIVATE_MTS was 1 second in the previous release
*
* @returns number of seconds before join accept message is expected
*/
uint8_t getJoinDelay();
/**
* Set join delay in seconds
* Defaults to 5 seconds
* Must match join delay setting of the network server
*
* The default Join Delay is 5 seconds
* The default Join Delay for PRIVATE_MTS was 1 second in the previous release
*
* @param delay number of seconds before join accept message is expected
* @return MDOT_OK if success
*/
uint32_t setJoinDelay(uint8_t delay);
/**
* Get join Rx1 datarate offset
* defaults to 0
* @returns offset
*/
uint8_t getJoinRx1DataRateOffset();