-
Notifications
You must be signed in to change notification settings - Fork 1
/
csf_linux.c
3006 lines (2525 loc) · 84.4 KB
/
csf_linux.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 csf_linux.c [Linux version of csf.c]
@brief Collector Specific Functions
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
/******************************************************************************
Includes
*****************************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "nvintf.h"
#include "nv_linux.h"
#include "log.h"
#include "mutex.h"
#include "ti_semaphore.h"
#include "timer.h"
#include "appsrv.h"
#include "time.h"
#include "mac_util.h"
#include "ti_154stack_config.h"
#include "api_mac.h"
#include "api_mac_linux.h"
#include "collector.h"
#include "cllc.h"
#include "csf.h"
#if defined(MT_CSF)
#include "mt_csf.h"
#endif
/* additional linux information */
#include "csf_linux.h"
/******************************************************************************
Constants and definitions
*****************************************************************************/
/* Initial timeout value for the tracking clock */
#define TRACKING_INIT_TIMEOUT_VALUE 100
/* NV Item ID - the device's network information */
#define CSF_NV_NETWORK_INFO_ID 0x0001
/* NV Item ID - the number of device list entries */
#define CSF_NV_DEVICELIST_ENTRIES_ID 0x0004
/* NV Item ID - the device list, use sub ID for each record in the list */
#define CSF_NV_DEVICELIST_ID 0x0005
/* NV Item ID - this devices frame counter */
#define CSF_NV_FRAMECOUNTER_ID 0x0006
/* NV Item ID - reset reason */
#define CSF_NV_RESET_REASON_ID 0x0007
/* Maximum number of device list entries */
#define CSF_MAX_DEVICELIST_ENTRIES CONFIG_MAX_DEVICES
/*
Maximum sub ID for a device list item, this is failsafe. This is
not the maximum number of items in the list
*/
#define CSF_MAX_DEVICELIST_IDS (2*CONFIG_MAX_DEVICES)
/* timeout value for trickle timer initialization */
#define TRICKLE_TIMEOUT_VALUE 20
/* timeout value for join timer */
#define JOIN_TIMEOUT_VALUE 20
/* timeout value for config request delay */
#define CONFIG_TIMEOUT_VALUE 1000
/* timeout value for config request delay */
#define IDENTIFY_TIMEOUT_VALUE 10
/* Timeout value in ms for sending the next OAD request request if not received */
#define OAD_RESET_REQ_RETRY_TIMEOUT_VALUE 12000
/* Amount of times the collector will sent a reset reqest if not received */
#define OAD_RESET_REQ_MAX_RETRIES 3
/*
The increment value needed to save a frame counter. Example, setting this
constant to 100, means that the frame counter will be saved when the new
frame counter is 100 more than the last saved frame counter. Also, when
the get frame counter function reads the value from NV it will add this value
to the read value.
*/
#define FRAME_COUNTER_SAVE_WINDOW 25
/* Value returned from findDeviceListIndex() when not found */
#define DEVICE_INDEX_NOT_FOUND -1
/*! NV driver item ID for reset reason */
#define NVID_RESET {NVINTF_SYSID_APP, CSF_NV_RESET_REASON_ID, 0}
/* DeviceType_ID_XYZ values */
#define DeviceType_ID_GENERIC 0
#define DeviceType_ID_CC1310 1
#define DeviceType_ID_CC1350 2
#define DeviceType_ID_CC2640R2 3
#define DeviceType_ID_CC1312R1 4
#define DeviceType_ID_CC1352R1 5
#define DeviceType_ID_CC1352P1 6
#define DeviceType_ID_CC1352P_2 7
#define DeviceType_ID_CC1352P_4 8
#define DeviceType_ID_CC2642R1 9
#define DeviceType_ID_CC2652R1 10
#define DeviceType_ID_CC2652RB 11
#define board_led_type_LED1 0
#define board_led_type_LED2 0
#define board_led_state_ON 0
#define Board_Led_toggle(led)(void)led;
#define Board_Led_control(led, action) \
(void)led; \
(void)action;
#define Board_Lcd_printf(line, ...) \
/*move curser to line*/ \
fprintf(stderr,"\033[%d;0H", line+1); \
/*clear line */ \
fprintf(stderr,"\033[2K"); \
fprintf(stderr,__VA_ARGS__); \
fprintf(stderr,"\n");
#define Board_LCD_open() \
fprintf(stderr,"\033[2J");
#include <termios.h>
/* Alternatively, board type */
#define KEY_DEVICE_TYPE 'b'
#define KEY_DISASSOCIATE_DEVICE 'd'
#define KEY_GET_OAD_FILE 'f'
#define KEY_LIST_DEVICES 'l'
#define KEY_PERMIT_JOIN 'o'
#define KEY_SELECT_DEVICE 's'
#define KEY_TOGGLE_REQ 't'
#define KEY_FW_UPDATE_REQ_OFFCHIP 'u'
#define KEY_FW_VER_REQ 'v'
#define KEY_FW_UPDATE_REQ_ONCHIP 'w'
#define DEFAULT_OAD_FILE "../../firmware/oad/cc13x0/sensor_oad_cc13x0lp_app.bin"
#define MAX_FILENAME_LENGTH 256
#define SEC_PER_MIN 60
/******************************************************************************
External variables
*****************************************************************************/
/* handle for tracking timeout */
static intptr_t trackingClkHandle;
/* handle for PA trickle timeout */
static intptr_t tricklePAClkHandle;
/* handle for PC timeout */
static intptr_t tricklePCClkHandle;
/* handle for join permit timeout */
static intptr_t joinClkHandle;
/* handle for config request delay */
static intptr_t configClkHandle;
/* handle for broadcast interval */
static intptr_t broadcastClkHandle;
#ifndef IS_HEADLESS
/* Handle for OAD reset request retries timeout */
static intptr_t oadResetReqRetryClkHandle;
#endif
extern intptr_t semaphore0;
/* Non-volatile function pointers */
NVINTF_nvFuncts_t nvFps;
/******************************************************************************
Local variables
*****************************************************************************/
static intptr_t collectorSem;
#define Semaphore_post(S) SEMAPHORE_put(S)
/* NV Function Pointers */
static NVINTF_nvFuncts_t *pNV = NULL;
/* Permit join setting */
static bool permitJoining = false;
static bool started = false;
/* The last saved coordinator frame counter */
static uint32_t lastSavedCoordinatorFrameCounter = 0;
#if defined(MT_CSF)
/*! NV driver item ID for reset reason */
static const NVINTF_itemID_t nvResetId = NVID_RESET;
#endif
#ifndef IS_HEADLESS
enum {
DisplayLine_product = 0,
DisplayLine_nwk,
DisplayLine_sensorStart,
DisplayLine_sensorEnd = 6,
DisplayLine_info,
DisplayLine_cmd,
} DisplayLine;
#else
#endif //IS_HEADLESS
static uint32_t selected_oad_file_id = 0;
/* variables to control offchip and onchip oad flow */
static volatile uint8_t ResetRspNeeded = 0;
static volatile uint8_t ResetRspRcvd = 0;
static volatile uint8_t ResetReqSent = 0;
#ifndef IS_HEADLESS
static uint8_t ResetRetryCount = 0;
static uint8_t ResetReqSendRetry = 0;
static char UpdateKeySim[] = {KEY_FW_UPDATE_REQ_ONCHIP};
#endif
/******************************************************************************
Global variables
*****************************************************************************/
/* Key press parameters */
uint8_t Csf_keys;
/* pending Csf_events */
uint16_t Csf_events = 0;
/* Saved CLLC state */
Cllc_states_t savedCllcState = Cllc_states_initWaiting;
/* OAD Duration Timer */
double oadDurationTimer = 0;
/******************************************************************************
Local function prototypes
*****************************************************************************/
static void processTrackingTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
static void processPATrickleTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
static void processPCTrickleTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
static void processJoinTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
static void processConfigTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
static void processBroadcastTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
#ifndef IS_HEADLESS
static void processOadResetReqRetryTimeoutCallback_WRAPPER(intptr_t thandle, intptr_t cookie);
#endif
#ifndef IS_HEADLESS
char* getConsoleCmd(void);
void initConsoleCmd(void);
#endif //!IS_HEADLESS
static void processTrackingTimeoutCallback(UArg a0);
static void processBroadcastTimeoutCallback(UArg a0);
static void processKeyChangeCallback(uint8_t keysPressed);
static void processPATrickleTimeoutCallback(UArg a0);
static void processPCTrickleTimeoutCallback(UArg a0);
static void processJoinTimeoutCallback(UArg a0);
static void processConfigTimeoutCallback(UArg a0);
#ifndef IS_HEADLESS
static void processOadResetReqRetryTimeoutCallback(UArg a0);
#endif
static bool addDeviceListItem(Llc_deviceListItem_t *pItem, bool *pNewDevice);
static void updateDeviceListItem(Llc_deviceListItem_t *pItem);
static int findDeviceListIndex(ApiMac_sAddrExt_t *pAddr);
static int findUnusedDeviceListIndex(void);
static void saveNumDeviceListEntries(uint16_t numEntries);
#ifndef IS_HEADLESS
static bool removeDevice(ApiMac_sAddr_t addr);
#endif
#if defined(TEST_REMOVE_DEVICE)
static void removeTheFirstDevice(void);
#endif
static double getUnixTime(void);
#ifndef IS_HEADLESS
static void startOADResetReqRetryTimer(void);
static void stopOADResetReqRetryTimer(void);
#endif
/******************************************************************************
Public Functions
*****************************************************************************/
/*!
The application calls this function during initialization
Public function defined in csf.h
*/
void Csf_init(void *sem)
{
char default_oad_file[256] = DEFAULT_OAD_FILE;
/* Set default FW image */
selected_oad_file_id = Collector_updateFwList(default_oad_file);
/* Initialize the LCD */
Board_LCD_open();
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_product, "TI Collector");
#if !defined(AUTO_START)
Board_Lcd_printf(DisplayLine_nwk, "Nwk: Starting");
#endif /* AUTO_START */
#endif //!IS_HEADLESS
LOG_printf(LOG_APPSRV_MSG_CONTENT, "TI Collector");
#if !defined(AUTO_START)
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Nwk: Starting\n");
#endif /* AUTO_START */
#ifndef IS_HEADLESS
initConsoleCmd();
#endif //!HEADLESS
/* Save off the semaphore */
collectorSem = (intptr_t)sem;
/* save the application semaphore here */
/* load the NV function pointers */
// printf(" >> Initialize the NV Function pointers \n");
NVOCMP_loadApiPtrs(&nvFps);
/* Suyash - the code is using pNV var. Using that for now. */
/* config nv pointer will be read from the mac_config_t... */
pNV = &nvFps;
/* Init NV */
nvFps.initNV(NULL);
}
/*!
The application must call this function periodically to
process any Csf_events that this module needs to process.
Public function defined in csf.h
*/
void Csf_processEvents(void)
{
#if !defined(IS_HEADLESS)
char *cmdBuff;
static uint16_t selected_device = 0;
cmdBuff = getConsoleCmd();
if(1 == ResetRspNeeded) //Onchip case
{
/* simulate the key stoke for fw update */
if((!cmdBuff) && (((1 == ResetRspRcvd) && (1 == ResetReqSent)) || 1 == ResetReqSendRetry))
{
cmdBuff = UpdateKeySim;
}
}
if(cmdBuff)
{
Csf_keys = cmdBuff[0];
if(Csf_keys == KEY_DEVICE_TYPE)
{
ApiMac_sAddr_t sAddr;
Collector_status_t status;
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x device type req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x device type req\n", selected_device);
sAddr.addr.shortAddr = selected_device;
sAddr.addrMode = ApiMac_addrType_short;
status = Collector_sendDeviceTypeRequest(&sAddr);
if(status == Collector_status_deviceNotFound)
{
Board_Lcd_printf(DisplayLine_info, "Info: Device 0x%04x not found", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Device 0x%04x not found\n", selected_device);
}
else if(status != Collector_status_success)
{
Board_Lcd_printf(DisplayLine_info, "Info: Device type req failed");
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Device type req failed\n");
}
}
if(Csf_keys == KEY_PERMIT_JOIN)
{
/* Toggle the permit joining */
if (permitJoining == true)
{
Csf_closeNwk();
}
else
{
Csf_openNwk();
}
}
if(Csf_keys == KEY_SELECT_DEVICE)
{
if(sscanf(cmdBuff, "s0x%hx", &selected_device) < 1)
{
sscanf(cmdBuff, "s%hd", &selected_device);
}
Board_Lcd_printf(DisplayLine_info, "Info: Selected device 0x%04x", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Selected device 0x%04x\n", selected_device);
}
if(Csf_keys == KEY_FW_VER_REQ)
{
ApiMac_sAddr_t sAddr;
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x FW version req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x FW version req\n", selected_device);
sAddr.addr.shortAddr = selected_device;
sAddr.addrMode = ApiMac_addrType_short;
Collector_sendFwVersionRequest(&sAddr);
}
if((Csf_keys == KEY_FW_UPDATE_REQ_OFFCHIP) || (Csf_keys == KEY_FW_UPDATE_REQ_ONCHIP))
{
ApiMac_sAddr_t sAddr;
Collector_status_t status;
sAddr.addr.shortAddr = selected_device;
sAddr.addrMode = ApiMac_addrType_short;
if(Csf_keys == KEY_FW_UPDATE_REQ_ONCHIP)
{
ResetRspNeeded = 1;
} //onchip_case
else //offchip_case
{
ResetRspNeeded = 0;
}
/* for onchip OAD case: we need Reset Rsp to proceed further */
if((1 == ResetRspNeeded) && (0 == ResetRspRcvd))
{
if(ResetReqSent == 1)
{
ResetRetryCount++;
Board_Lcd_printf(DisplayLine_info, "Info: Retrying 0x%04x Target Reset - Attempt %i", selected_device, ResetRetryCount);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Retrying 0x%04x Target Reset - Attempt %i\n", selected_device, ResetRetryCount);
}
else
{
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x Target Reset Req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x Target Reset Req\n", selected_device);
}
status = Collector_sendResetReq(&sAddr);
if(status != Collector_status_success || ResetRetryCount >= OAD_RESET_REQ_MAX_RETRIES)
{
ResetReqSent = 0;
ResetRetryCount = 0;
ResetReqSendRetry = 0;
stopOADResetReqRetryTimer();
if(status != Collector_status_success)
{
Board_Lcd_printf(DisplayLine_info, "Info: Sending Target Reset Req failed");
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending Target Reset Req failed\n");
}
else
{
Board_Lcd_printf(DisplayLine_info, "Info: OAD Failed");
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: OAD Failed\n");
}
}
else if(ResetReqSent == 0)
{
ResetReqSent = 1;
startOADResetReqRetryTimer();
}
else //ResetReqSent == 1
{
ResetReqSendRetry = 0;
}
}
if((!ResetRspNeeded) || ((ResetRspNeeded)&&(1 == ResetRspRcvd)))
{
/* clear the Reset Req sent and Reset Rsp Received flag to facilate next OAD */
/* No harm in doing it for offchip oad case as well*/
ResetRspRcvd = 0;
ResetReqSent = 0;
ResetRetryCount = 0;
ResetReqSendRetry = 0;
stopOADResetReqRetryTimer();
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x FW Update Req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x FW Update Req\n", selected_device);
oadDurationTimer = getUnixTime();
status = Collector_startFwUpdate(&sAddr, selected_oad_file_id);
if(status == Collector_status_invalid_file)
{
Board_Lcd_printf(DisplayLine_info, "Info: Update req file not found ID:%d", selected_oad_file_id);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Update req file not found ID:%d\n", selected_oad_file_id);
}
else if(status != Collector_status_success)
{
Board_Lcd_printf(DisplayLine_info, "Info: Update req failed");
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Update req failed\n");
}
}
}
if(Csf_keys == KEY_GET_OAD_FILE)
{
static char new_oad_file[256] = DEFAULT_OAD_FILE;
char temp_oad_file[256] = "";
sscanf(cmdBuff, "f %s", temp_oad_file);
if(strlen(temp_oad_file) > 0)
{
// Verify file exists and we have read permissions
if(access(temp_oad_file, F_OK | R_OK) != -1)
{
// If file exists, then copy to the static filename and call updateFwList
strncpy(new_oad_file, temp_oad_file, strlen(temp_oad_file) + 1);
selected_oad_file_id = Collector_updateFwList(new_oad_file);
Board_Lcd_printf(DisplayLine_info, "Info: OAD file %s", new_oad_file);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: OAD file %s\n", new_oad_file);
}
else
{
Board_Lcd_printf(DisplayLine_info, "Info: Can not read file %s", temp_oad_file);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Can not read file %s\n", temp_oad_file);
}
}
else
{
// User is asking what the current file is
Board_Lcd_printf(DisplayLine_info, "Info: OAD file %s", new_oad_file);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: OAD file %s\n", new_oad_file);
}
}
if(Csf_keys == KEY_TOGGLE_REQ)
{
ApiMac_sAddr_t sAddr;
Collector_status_t status;
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x LED toggle req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x LED toggle req\n", selected_device);
sAddr.addr.shortAddr = selected_device;
sAddr.addrMode = ApiMac_addrType_short;
status = Csf_sendToggleLedRequest(&sAddr);
if(status == Collector_status_deviceNotFound)
{
Board_Lcd_printf(DisplayLine_info, "Info: Toggle Req device 0x%04x not found", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Toggle Req device 0x%04x not found\n", selected_device);
}
else if(status != Collector_status_success)
{
Board_Lcd_printf(DisplayLine_info, "Info: Update Req failed");
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Update Req failed\n");
}
}
if(Csf_keys == KEY_LIST_DEVICES)
{
ApiMac_sAddr_t sAddr;
uint16_t devIdx;
ApiMac_sAddrExt_t pExtAddr;
for(devIdx = 1; devIdx < CONFIG_MAX_DEVICES; devIdx++)
{
sAddr.addr.shortAddr = devIdx;
sAddr.addrMode = ApiMac_addrType_short;
if(Collector_findDevice(&sAddr) == Collector_status_success)
{
if(Csf_getDeviceExtended(devIdx, &pExtAddr)) {
Board_Lcd_printf(DisplayLine_info,
"Short: 0x%04x Extended: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
devIdx,
pExtAddr[7],
pExtAddr[6],
pExtAddr[5],
pExtAddr[4],
pExtAddr[3],
pExtAddr[2],
pExtAddr[1],
pExtAddr[0]);
LOG_printf(LOG_DBG_COLLECTOR,"Short: 0x%04x Extended: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
devIdx,
pExtAddr[7],
pExtAddr[6],
pExtAddr[5],
pExtAddr[4],
pExtAddr[3],
pExtAddr[2],
pExtAddr[1],
pExtAddr[0]);
}
}
}
}
if(Csf_keys == KEY_DISASSOCIATE_DEVICE)
{
ApiMac_sAddr_t sAddr;
Board_Lcd_printf(DisplayLine_info, "Info: Sending 0x%04x disassociation req", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Sending 0x%04x disassociation req\n", selected_device);
sAddr.addr.shortAddr = selected_device;
sAddr.addrMode = ApiMac_addrType_short;
if(!removeDevice(sAddr))
{
Board_Lcd_printf(DisplayLine_info, "Info: disassociation req device 0x%04x not found", selected_device);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: disassociation req device 0x%04x not found\n", selected_device);
}
}
/* Clear the key press indication */
Csf_keys = 0;
}
/* Clear the event */
Util_clearEvent(&Csf_events, CSF_KEY_EVENT);
#endif /* !defined(IS_HEADLESS) */
#if defined(MT_CSF)
MTCSF_displayStatistics();
#endif
}
#if !defined(IS_HEADLESS)
void initConsoleCmd(void)
{
struct termios term_attr;
/* set the terminal to raw mode */
tcgetattr(fileno(stdin), &term_attr);
term_attr.c_lflag &= ~(ECHO|ICANON);
term_attr.c_cc[VTIME] = 0;
term_attr.c_cc[VMIN] = 0;
tcsetattr(fileno(stdin), TCSANOW, &term_attr);
}
char* getConsoleCmd(void)
{
static bool cmdComplete = false;
static char cmd[256] = {0};
static int ch;
static uint8_t cmdIdx = 0;
if(cmdComplete)
{
memset(cmd, 0, 256);
cmdIdx = 0;
cmdComplete = false;
}
/* read a character from the stdin stream without blocking */
/* returns EOF (-1) if no character is available */
ch = getchar();
if(ch != -1)
{
/* Discard non-ascii characters except new lines */
if(ch == 0xa || (ch >= 0x20 && ch < 0x7F))
{
cmd[cmdIdx] = ch;
}
Board_Lcd_printf(DisplayLine_cmd, "cmd: %s", cmd);
/* cmdIdx will wrap around for the 256Byte buffer */
if(cmd[cmdIdx] == 0xa)
{
cmdComplete = true;
}
else
{
cmdIdx++;
}
}
if(cmdComplete)
{
Board_Lcd_printf(DisplayLine_cmd, "CMD: %s", cmd);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "CMD: %s\n", cmd);
return cmd;
}
else
{
return 0;
}
}
#endif // !defined(HEADLESS)
/*!
The application calls this function to retrieve the stored
network information.
Public function defined in csf.h
*/
bool Csf_getNetworkInformation(Llc_netInfo_t *pInfo)
{
if((pNV != NULL) && (pNV->readItem != NULL) && (pInfo != NULL))
{
NVINTF_itemID_t id;
/* Setup NV ID */
id.systemID = NVINTF_SYSID_APP;
id.itemID = CSF_NV_NETWORK_INFO_ID;
id.subID = 0;
/* Read Network Information from NV */
if(pNV->readItem(id, 0, sizeof(Llc_netInfo_t), pInfo) == NVINTF_SUCCESS)
{
return(true);
}
}
return(false);
}
/*!
The application calls this function to indicate that it has
started or restored the device in a network
Public function defined in csf.h
*/
void Csf_networkUpdate(bool restored, Llc_netInfo_t *pNetworkInfo)
{
/* check for valid structure ponter, ignore if not */
if(pNetworkInfo != NULL)
{
if((pNV != NULL) && (pNV->writeItem != NULL))
{
NVINTF_itemID_t id;
/* Setup NV ID */
id.systemID = NVINTF_SYSID_APP;
id.itemID = CSF_NV_NETWORK_INFO_ID;
id.subID = 0;
/* Write the NV item */
pNV->writeItem(id, sizeof(Llc_netInfo_t), pNetworkInfo);
}
/* Send info to appClient */
if(pNetworkInfo != NULL)
{
appsrv_networkUpdate(restored, pNetworkInfo);
}
started = true;
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_nwk, "Nwk: Started");
#endif //IS_HEADLESS
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Nwk: Started");
if(pNetworkInfo->fh == false)
{
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Channel %d", pNetworkInfo->channel);
#endif //IS_HEADLESS
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Channel %d", pNetworkInfo->channel);
}
else
{
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Freq. Hopping");
#endif //IS_HEADLESS
LOG_printf(LOG_APPSRV_MSG_CONTENT, "Info: Freq. Hopping");
}
Board_Led_control(board_led_type_LED1, board_led_state_ON);
#if defined(MT_CSF)
MTCSF_networkUpdateIndCB();
#endif
}
}
/*!
The application calls this function to indicate that a device
has joined the network.
Public function defined in csf.h
*/
ApiMac_assocStatus_t Csf_deviceUpdate(ApiMac_deviceDescriptor_t *pDevInfo,
ApiMac_capabilityInfo_t *pCapInfo)
{
ApiMac_assocStatus_t status = ApiMac_assocStatus_success;
ApiMac_sAddr_t extAddr;
/* flag which will be updated based on if the device joining is
a new device or already existing one */
bool newDevice;
extAddr.addrMode = ApiMac_addrType_extended;
memcpy(&extAddr.addr.extAddr, &pDevInfo->extAddress, APIMAC_SADDR_EXT_LEN);
/* Save the device information */
Llc_deviceListItem_t dev;
memcpy(&dev.devInfo, pDevInfo, sizeof(ApiMac_deviceDescriptor_t));
memcpy(&dev.capInfo, pCapInfo, sizeof(ApiMac_capabilityInfo_t));
dev.rxFrameCounter = 0;
if(addDeviceListItem(&dev, &newDevice) == false)
{
#ifdef NV_RESTORE
status = ApiMac_assocStatus_panAtCapacity;
LOG_printf(LOG_ERROR,"Failed: 0x%04x\n", pDevInfo->shortAddress);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Join Failed 0x%04x", pDevInfo->shortAddress);
#endif //!IS_HEADLESS
#else /* NV_RESTORE */
status = ApiMac_assocStatus_success;
LOG_printf(LOG_DBG_COLLECTOR_RAW, "Joined: Short: 0x%04x Extended: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
pDevInfo->shortAddress,
extAddr.addr.extAddr[7],
extAddr.addr.extAddr[6],
extAddr.addr.extAddr[5],
extAddr.addr.extAddr[4],
extAddr.addr.extAddr[3],
extAddr.addr.extAddr[2],
extAddr.addr.extAddr[1],
extAddr.addr.extAddr[0]);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Joined 0x%04x", pDevInfo->shortAddress);
#endif //!IS_HEADLESS
#endif /* NV_RESTORE */
}
else //addDeviceListItem() returned true
{
if(true == newDevice)
{
/* Send update to the appClient */
LOG_printf(LOG_APPSRV_MSG_CONTENT,
"sending device update info to appsrv\n");
appsrv_deviceUpdate(&dev);
LOG_printf(LOG_DBG_COLLECTOR_RAW, "Joined: Short: 0x%04x Extended: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
pDevInfo->shortAddress,
extAddr.addr.extAddr[7],
extAddr.addr.extAddr[6],
extAddr.addr.extAddr[5],
extAddr.addr.extAddr[4],
extAddr.addr.extAddr[3],
extAddr.addr.extAddr[2],
extAddr.addr.extAddr[1],
extAddr.addr.extAddr[0]);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Joined 0x%04x", pDevInfo->shortAddress);
#endif //!IS_HEADLESS
} //end of if newDevice == true
else // not a new device : device is rejoining
{
/* Send update to the appClient */
LOG_printf(LOG_APPSRV_MSG_CONTENT,
"sending device update info to appsrv\n");
appsrv_deviceUpdate(&dev);
LOG_printf(LOG_DBG_COLLECTOR_RAW, "Re-Joined: Short: 0x%04x Extended: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
pDevInfo->shortAddress,
extAddr.addr.extAddr[7],
extAddr.addr.extAddr[6],
extAddr.addr.extAddr[5],
extAddr.addr.extAddr[4],
extAddr.addr.extAddr[3],
extAddr.addr.extAddr[2],
extAddr.addr.extAddr[1],
extAddr.addr.extAddr[0]);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: Re-Joined 0x%04x", pDevInfo->shortAddress);
#endif //!IS_HEADLESS
}//end of not a new device
}//end of addDeviceListItem() returned true
#if defined(MT_CSF)
MTCSF_deviceUpdateIndCB(pDevInfo, pCapInfo);
#endif
/* Return the status of the joining device */
return (status);
}
/*!
The application calls this function to indicate that a device
is no longer active in the network.
Public function defined in csf.h
*/
void Csf_deviceNotActiveUpdate(ApiMac_deviceDescriptor_t *pDevInfo,
bool timeout)
{
/* send update to the appClient */
LOG_printf(LOG_APPSRV_MSG_CONTENT,
"!Responding: 0x%04x\n",
pDevInfo->shortAddress);
appsrv_deviceNotActiveUpdate(pDevInfo, timeout);
LOG_printf(LOG_DBG_COLLECTOR,
"inactive: pan: 0x%04x short: 0x%04x ext: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
pDevInfo->panID,
pDevInfo->shortAddress,
pDevInfo->extAddress[0],
pDevInfo->extAddress[1],
pDevInfo->extAddress[2],
pDevInfo->extAddress[3],
pDevInfo->extAddress[4],
pDevInfo->extAddress[5],
pDevInfo->extAddress[6],
pDevInfo->extAddress[7]);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: No response 0x%04x", pDevInfo->shortAddress);
#endif //IS_HEADLESS
#if defined(MT_CSF)
MTCSF_deviceNotActiveIndCB(pDevInfo, timeout);
#endif
}
/*!
The application calls this function to indicate that a device
has responded to a Config Request.
Public function defined in csf.h
*/
void Csf_deviceConfigUpdate(ApiMac_sAddr_t *pSrcAddr, int8_t rssi,
Smsgs_configRspMsg_t *pMsg)
{
/* send update to the appClient */
appsrv_deviceConfigUpdate(pSrcAddr,rssi,pMsg);
LOG_printf(LOG_APPSRV_MSG_CONTENT, "ConfigRsp: 0x%04x\n", pSrcAddr->addr.shortAddr);
#ifndef IS_HEADLESS
Board_Lcd_printf(DisplayLine_info, "Info: ConfigRsp 0x%04x", pSrcAddr->addr.shortAddr);
#endif //IS_HEADLESS
#if defined(MT_CSF)
MTCSF_configResponseIndCB(pSrcAddr, rssi, pMsg);
#endif
}
/*!