-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
at.c
1232 lines (1024 loc) · 28.1 KB
/
at.c
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
/*******************************************************************************
* @file at.c
* @author MCD Application Team
* @version V1.1.2
* @date 08-September-2017
* @brief at command API
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution 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 STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "at.h"
#include "lora.h"
#include "Commissioning.h"
#include "utilities.h"
#include "LoRaMac.h"
#include "LoRaMacTest.h"
#include "radio.h"
#include "vcom.h"
#include "tiny_sscanf.h"
#include "version.h"
#include "hw_msp.h"
#include "test_rf.h"
/* External variables --------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/**
* @brief Max size of the data that can be received
*/
#define MAX_RECEIVED_DATA 255
/* Private macro -------------------------------------------------------------*/
/**
* @brief Macro to return when an error occurs
*/
#define CHECK_STATUS(status) do { \
ATEerror_t at_status = translate_status(status); \
if (at_status != AT_OK) { return at_status; } \
} while (0)
/* Private variables ---------------------------------------------------------*/
/**
* @brief Buffer that contains the last received data
*/
static char ReceivedData[MAX_RECEIVED_DATA];
/**
* @brief Size if the buffer that contains the last received data
*/
static unsigned ReceivedDataSize = 0;
/**
* @brief Application port the last received data were on
*/
static uint8_t ReceivedDataPort;
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Translate a LoRaMacStatus_t into an ATEerror_t
* @param the LoRaMacStatus_t status
* @retval the corresponding ATEerror_t code
*/
static ATEerror_t translate_status(LoRaMacStatus_t status);
/**
* @brief Get 16 bytes values in hexa
* @param The string containing the 16 bytes, something like ab:cd:01:...
* @param The buffer that will contain the bytes read
* @retval The number of bytes read
*/
static int sscanf_16_hhx(const char *from, uint8_t *pt);
/**
* @brief Print 16 bytes as %02x
* @param the pointer containing the 16 bytes to print
* @retval None
*/
static void print_16_02x(uint8_t *pt);
/**
* @brief Get 4 bytes values in hexa
* @param The string containing the 16 bytes, something like ab:cd:01:21
* @param The buffer that will contain the bytes read
* @retval The number of bytes read
*/
static int sscanf_uint32_as_hhx(const char *from, uint32_t *value);
/**
* @brief Print 4 bytes as %02x
* @param the value containing the 4 bytes to print
* @retval None
*/
static void print_uint32_as_02x(uint32_t value);
/**
* @brief Print 8 bytes as %02x
* @param the pointer containing the 8 bytes to print
* @retval None
*/
static void print_8_02x(uint8_t *pt);
/**
* @brief Print an int
* @param the value to print
* @retval None
*/
static void print_d(int value);
/**
* @brief Print an unsigned int
* @param the value to print
* @retval None
*/
static void print_u(unsigned int value);
/* Exported functions ------------------------------------------------------- */
void set_at_receive(uint8_t AppPort, uint8_t* Buff, uint8_t BuffSize)
{
if (MAX_RECEIVED_DATA <= BuffSize)
BuffSize = MAX_RECEIVED_DATA;
memcpy1((uint8_t *)ReceivedData, Buff, BuffSize);
ReceivedDataSize = BuffSize;
ReceivedDataPort = AppPort;
}
ATEerror_t at_return_ok(const char *param)
{
return AT_OK;
}
ATEerror_t at_return_error(const char *param)
{
return AT_ERROR;
}
ATEerror_t at_reset(const char *param)
{
NVIC_SystemReset();
return AT_OK;
}
ATEerror_t at_DevEUI_get(const char *param)
{
AT_PRINTF("+OK=");
print_8_02x(lora_config_deveui_get());
return AT_OK;
}
ATEerror_t at_AppEUI_get(const char *param)
{
AT_PRINTF("+OK=");
print_8_02x(lora_config_appeui_get());
return AT_OK;
}
ATEerror_t at_AppEUI_set(const char *param)
{
uint8_t AppEui[8];
if (tiny_sscanf(param, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
&AppEui[0], &AppEui[1], &AppEui[2], &AppEui[3],
&AppEui[4], &AppEui[5], &AppEui[6], &AppEui[7]) != 8)
{
return AT_PARAM_ERROR;
}
lora_config_appeui_set(AppEui);
return AT_OK;
}
ATEerror_t at_DevAddr_set(const char *param)
{
uint32_t DevAddr;
sscanf_uint32_as_hhx(param, &DevAddr);
lora_config_devaddr_set(DevAddr);
return AT_OK;
}
ATEerror_t at_DevAddr_get(const char *param)
{
AT_PRINTF("+OK=");
print_uint32_as_02x(lora_config_devaddr_get());
return AT_OK;
}
ATEerror_t at_NetworkID_get(const char *param)
{
AT_PRINTF("+OK=");
print_uint32_as_02x(lora_config_networkid_get());
return AT_OK;
}
ATEerror_t at_NetworkID_set(const char *param)
{
uint32_t NetworkID;
sscanf_uint32_as_hhx(param, &NetworkID);
lora_config_networkid_set(NetworkID);
return AT_OK;
}
ATEerror_t at_AppKey_get(const char *param)
{
AT_PRINTF("+OK=");
print_16_02x(lora_config_appkey_get());
return AT_OK;
}
ATEerror_t at_AppKey_set(const char *param)
{
uint8_t AppKey[16];
int ret = sscanf_16_hhx(param, AppKey);
if (ret != 16)
{
return AT_PARAM_ERROR;
}
lora_config_appkey_set(AppKey);
return AT_OK;
}
extern LoRaMacRegion_t globalRegion;
ATEerror_t at_Band_get(const char *param)
{
AT_PRINTF("+OK=");
print_d(globalRegion);
return AT_OK;
}
ATEerror_t at_Band_set(const char *param)
{
LoRaMacRegion_t region;
if (tiny_sscanf(param, "%hhu", ®ion) != 1)
{
return AT_PARAM_ERROR;
}
if (region != globalRegion) {
globalRegion = region;
TriggerReinit();
}
return AT_OK;
}
ATEerror_t at_NwkSKey_get(const char *param)
{
AT_PRINTF("+OK=");
print_16_02x(lora_config_nwkskey_get());
return AT_OK;
}
ATEerror_t at_NwkSKey_set(const char *param)
{
uint8_t NwkSkey[16];
int ret = sscanf_16_hhx(param, NwkSkey);
if (ret != 16)
{
return AT_PARAM_ERROR;
}
lora_config_nwkskey_set(NwkSkey);
return AT_OK;
}
ATEerror_t at_AppSKey_get(const char *param)
{
AT_PRINTF("+OK=");
print_16_02x(lora_config_appskey_get());
return AT_OK;
}
ATEerror_t at_AppSKey_set(const char *param)
{
uint8_t AppSKey[16];
int ret = sscanf_16_hhx(param, AppSKey);
if (ret != 16)
{
return AT_PARAM_ERROR;
}
lora_config_appskey_set(AppSKey);
return AT_OK;
}
ATEerror_t at_Certif( const char *param )
{
lora_wan_certif( );
return AT_OK;
}
ATEerror_t at_ChannelMask_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_CHANNELS_MASK;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
AT_PRINTF("%04x%04x%04x%04x%04x%04x\r",
mib.Param.ChannelsMask[0], mib.Param.ChannelsMask[1], mib.Param.ChannelsMask[2], mib.Param.ChannelsMask[3],
mib.Param.ChannelsMask[4], mib.Param.ChannelsMask[5]);
return AT_OK;
}
ATEerror_t at_ChannelMask_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
uint16_t channelsMask[6];
mib.Type = MIB_CHANNELS_MASK;
mib.Param.ChannelsMask = channelsMask;
if (tiny_sscanf(param, "%04hx%04hx%04hx%04hx%04hx%04hx",
&channelsMask[0], &channelsMask[1], &channelsMask[2], &channelsMask[3],
&channelsMask[4], &channelsMask[5]) != 6)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_ChannelDefaultMask_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_CHANNELS_DEFAULT_MASK;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
AT_PRINTF("%04x%04x%04x%04x%04x%04x\r",
mib.Param.ChannelsDefaultMask[0], mib.Param.ChannelsDefaultMask[1], mib.Param.ChannelsDefaultMask[2], mib.Param.ChannelsDefaultMask[3],
mib.Param.ChannelsDefaultMask[4], mib.Param.ChannelsDefaultMask[5]);
return AT_OK;
}
ATEerror_t at_ChannelDefaultMask_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
uint16_t channelDefaultMask[6];
mib.Type = MIB_CHANNELS_DEFAULT_MASK;
mib.Param.ChannelsDefaultMask = channelDefaultMask;
if (tiny_sscanf(param, "%04hx%04hx%04hx%04hx%04hx%04hx",
&channelDefaultMask[0], &channelDefaultMask[1], &channelDefaultMask[2], &channelDefaultMask[3],
&channelDefaultMask[4], &channelDefaultMask[5]) != 6)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_ADR_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_ADR;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.AdrEnable);
return AT_OK;
}
ATEerror_t at_ADR_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_ADR;
switch (param[0])
{
case '0':
case '1':
mib.Param.AdrEnable = param[0] - '0';
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
break;
default:
return AT_PARAM_ERROR;
}
return AT_OK;
}
ATEerror_t at_TransmitPower_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_CHANNELS_TX_POWER;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.ChannelsTxPower);
return AT_OK;
}
ATEerror_t at_TransmitPower_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
uint8_t ignored;
mib.Type = MIB_CHANNELS_TX_POWER;
if (tiny_sscanf(param, "%hhu,%hhu", &ignored, &mib.Param.ChannelsTxPower) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_DataRate_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_CHANNELS_DATARATE;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.ChannelsDatarate);
return AT_OK;
}
ATEerror_t at_DataRate_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_CHANNELS_DATARATE;
if (tiny_sscanf(param, "%hhu", &mib.Param.ChannelsDatarate) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_DutyCycle_set(const char *param)
{
switch (param[0])
{
case '0':
lora_config_duty_cycle_set(DISABLE);
break;
case '1':
lora_config_duty_cycle_set(ENABLE);
break;
default:
return AT_PARAM_ERROR;
}
return AT_OK;
}
ATEerror_t at_DutyCycle_get(const char *param)
{
AT_PRINTF("+OK=");
if (lora_config_duty_cycle_get() == ENABLE)
AT_PRINTF("1\r");
else
AT_PRINTF("0\r");
return AT_OK;
}
ATEerror_t at_PublicNetwork_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_PUBLIC_NETWORK;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.EnablePublicNetwork);
return AT_OK;
}
ATEerror_t at_PublicNetwork_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_PUBLIC_NETWORK;
switch (param[0])
{
case '0':
case '1':
mib.Param.EnablePublicNetwork = param[0] - '0';
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
break;
default:
return AT_PARAM_ERROR;
}
return AT_OK;
}
ATEerror_t at_Rx2Frequency_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RX2_CHANNEL;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.Rx2Channel.Frequency);
return AT_OK;
}
ATEerror_t at_Rx2Frequency_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RX2_CHANNEL;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
if (tiny_sscanf(param, "%lu", &mib.Param.Rx2Channel.Frequency) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_Rx2DataRate_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RX2_CHANNEL;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_d(mib.Param.Rx2Channel.Datarate);
return AT_OK;
}
ATEerror_t at_Rx2DataRate_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RX2_CHANNEL;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
if (tiny_sscanf(param, "%hhu", &mib.Param.Rx2Channel.Datarate) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_Rx1Delay_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RECEIVE_DELAY_1;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_u(mib.Param.ReceiveDelay1);
return AT_OK;
}
ATEerror_t at_Rx1Delay_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RECEIVE_DELAY_1;
if (tiny_sscanf(param, "%lu", &mib.Param.ReceiveDelay1) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_Rx2Delay_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RECEIVE_DELAY_2;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
print_u(mib.Param.ReceiveDelay2);
return AT_OK;
}
ATEerror_t at_Rx2Delay_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_RECEIVE_DELAY_2;
if (tiny_sscanf(param, "%lu", &mib.Param.ReceiveDelay2) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_JoinAcceptDelay1_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_JOIN_ACCEPT_DELAY_1;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_u(mib.Param.JoinAcceptDelay1);
return AT_OK;
}
ATEerror_t at_JoinAcceptDelay1_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_JOIN_ACCEPT_DELAY_1;
if (tiny_sscanf(param, "%lu", &mib.Param.JoinAcceptDelay1) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_JoinAcceptDelay2_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_JOIN_ACCEPT_DELAY_2;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_u(mib.Param.JoinAcceptDelay2);
return AT_OK;
}
ATEerror_t at_JoinAcceptDelay2_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_JOIN_ACCEPT_DELAY_2;
if (tiny_sscanf(param, "%lu", &mib.Param.JoinAcceptDelay2) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_NetworkJoinMode_get(const char *param)
{
AT_PRINTF("+OK=");
print_d((lora_config_otaa_get() == ENABLE ? 1 : 0));
return AT_OK;
}
ATEerror_t at_NetworkJoinMode_set(const char *param)
{
FunctionalState status;
switch (param[0])
{
case '0':
status = DISABLE;
break;
case '1':
status = ENABLE;
break;
default:
return AT_PARAM_ERROR;
}
lora_config_otaa_set(status);
return AT_OK;
}
ATEerror_t at_UplinkCounter_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_UPLINK_COUNTER;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_u(mib.Param.UpLinkCounter);
return AT_OK;
}
ATEerror_t at_UplinkCounter_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_UPLINK_COUNTER;
if (tiny_sscanf(param, "%lu", &mib.Param.UpLinkCounter) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_DownlinkCounter_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_DOWNLINK_COUNTER;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=");
print_u(mib.Param.DownLinkCounter);
return AT_OK;
}
ATEerror_t at_DownlinkCounter_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_DOWNLINK_COUNTER;
if (tiny_sscanf(param, "%lu", &mib.Param.DownLinkCounter) != 1)
{
return AT_PARAM_ERROR;
}
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_DeviceClass_get(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_DEVICE_CLASS;
status = LoRaMacMibGetRequestConfirm(&mib);
CHECK_STATUS(status);
AT_PRINTF("+OK=%c\r", 'A' + mib.Param.Class);
return AT_OK;
}
ATEerror_t at_DeviceClass_set(const char *param)
{
MibRequestConfirm_t mib;
LoRaMacStatus_t status;
mib.Type = MIB_DEVICE_CLASS;
switch (param[0])
{
case 'A':
case 'B':
case 'C':
/* assume CLASS_A == 0, CLASS_B == 1, etc, which is the case for now */
mib.Param.Class = (DeviceClass_t)(param[0] - 'A');
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
break;
default:
return AT_PARAM_ERROR;
}
return AT_OK;
}
ATEerror_t at_Join(const char *param)
{
LoRaMacStatus_t status;
status = lora_join();
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_NetworkJoinStatus(const char *param)
{
MibRequestConfirm_t mibReq;
LoRaMacStatus_t status;
mibReq.Type = MIB_NETWORK_JOINED;
status = LoRaMacMibGetRequestConfirm(&mibReq);
if (status == LORAMAC_STATUS_OK)
{
AT_PRINTF("+OK=");
print_d(mibReq.Param.IsNetworkJoined ? 1 : 0);
return AT_OK;
}
return AT_ERROR;
}
ATEerror_t at_SendBinary(const char *param)
{
LoRaMacStatus_t status;
status = lora_send(param, strlen(param), 1, 0);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_Send(const char *param)
{
LoRaMacStatus_t status;
status = lora_send(param, strlen(param), 0, 0);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_ReceiveBinary(const char *param)
{
unsigned i;
AT_PRINTF("+RECV=");
AT_PRINTF("%d,%d\r\n\n", ReceivedDataPort, ReceivedDataSize);
for (i = 0; i < ReceivedDataSize; i++)
{
AT_PRINTF("%02x", ReceivedData[i]);
}
AT_PRINTF("\r");
ReceivedDataSize = 0;
return AT_OK;
}
// Defaults to binary
#define USE_BINARY 1
#define USE_HEX 0
static uint8_t format_send_v2 = USE_HEX;
ATEerror_t at_Receive(const char *param)
{
AT_PRINTF("+RECV=");
if (format_send_v2==0)
{
AT_PRINTF("%d,%d\r\n\n", ReceivedDataPort, ReceivedDataSize);
for (unsigned i = 0; i < ReceivedDataSize; i++)
{
AT_PRINTF("%c", ReceivedData[i]);
}
}
else
{
AT_PRINTF("%d,%d\r\n\n", ReceivedDataPort, ReceivedDataSize*2);
for (unsigned i = 0; i < ReceivedDataSize; i++)
{
AT_PRINTF("%02x", ReceivedData[i]);
}
}
ReceivedDataSize = 0;
AT_PRINTF("\r");
return AT_OK;
}
ATEerror_t at_SendV2(const char *param)
{
LoRaMacStatus_t status;
at_ack_set("0");
size_t length = 0;
if (tiny_sscanf(param, "%hhu", &length) != 1)
{
return AT_PARAM_ERROR;
}
uint8_t data[64];
int i = 0;
// grab other #len bytes from the serial buffer
while (i<length) {
if (IsNewCharReceived() == SET) {
data[i] = GetNewChar();
i++;
}
}
status = lora_send(data, length, format_send_v2, 1);
CHECK_STATUS(status);
return AT_OK;
}
ATEerror_t at_SendV2Confirmation(const char *param)
{
LoRaMacStatus_t status;
at_ack_set("1");