-
Notifications
You must be signed in to change notification settings - Fork 204
/
cfe_evs_task.c
1847 lines (1559 loc) · 61.9 KB
/
cfe_evs_task.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
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/*
** File: cfe_evs_task.c
**
** Title: Event Service API Management Control Interfaces
**
** Purpose: This module defines the top level functions of the
** cFE Event Service task defining the control, command,
** and telemetry interfaces
**
*/
/* Include Files */
#include "cfe_evs_task.h" /* EVS internal definitions */
#include "cfe_evs_log.h" /* EVS log file definitions */
#include "cfe_evs_utils.h" /* EVS utility function definitions */
#include "cfe_evs.h" /* EVS API definitions */
#include <string.h>
#include "cfe_version.h" /* cFE version definitions */
#include "cfe_error.h" /* cFE error code definitions */
#include "cfe_es.h" /* Executive Service definitions */
#include "cfe_fs.h" /* File Service definitions */
#include "cfe_psp.h" /* cFE Platform Support Package definitions */
#include "osapi.h" /* OS API file system definitions */
#include "private/cfe_es_resetdata_typedef.h" /* Definition of CFE_ES_ResetData_t */
/* Global Data */
CFE_EVS_GlobalData_t CFE_EVS_GlobalData;
/*
** Local function prototypes.
*/
void CFE_EVS_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId);
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);
/* Function Definitions */
/*
** Function Prologue
**
** Function Name: CFE_EVS_EarlyInit
**
** Purpose: This routine provides initialization for the EVS API.
**
** Assumptions and Notes: This routine must be called before the EVS
** application is started. CFE_EVS_EarlyInit performs initialization
** necessary to support EVS API calls that might occur before
** the EVS application has completed its startup initialization.
*/
int32 CFE_EVS_EarlyInit ( void )
{
#ifdef CFE_PLATFORM_EVS_LOG_ON
int32 Status;
uint32 resetAreaSize = 0;
cpuaddr resetAreaAddr;
CFE_ES_ResetData_t *CFE_EVS_ResetDataPtr = (CFE_ES_ResetData_t *) NULL;
#endif
memset(&CFE_EVS_GlobalData, 0, sizeof(CFE_EVS_GlobalData_t));
/* Initialize housekeeping packet */
CFE_MSG_Init(&CFE_EVS_GlobalData.EVS_TlmPkt.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_EVS_HK_TLM_MID),
sizeof(CFE_EVS_GlobalData.EVS_TlmPkt));
/* Elements stored in the hk packet that have non-zero default values */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageFormatMode = CFE_PLATFORM_EVS_DEFAULT_MSG_FORMAT_MODE;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort = CFE_PLATFORM_EVS_PORT_DEFAULT;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogFullFlag = false;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogMode = CFE_PLATFORM_EVS_DEFAULT_LOG_MODE;
#ifdef CFE_PLATFORM_EVS_LOG_ON
/* Get a pointer to the CFE reset area from the BSP */
Status = CFE_PSP_GetResetArea(&resetAreaAddr, &resetAreaSize);
if (Status != CFE_PSP_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS call to CFE_PSP_GetResetArea failed, RC=0x%08x\n", (unsigned int)Status);
}
else if (resetAreaSize < sizeof(CFE_ES_ResetData_t))
{
/* Got the pointer but the size is wrong */
Status = CFE_EVS_RESET_AREA_POINTER;
CFE_ES_WriteToSysLog("Unexpected size from CFE_PSP_GetResetArea: expected = 0x%08lX, actual = 0x%08lX\n",
(unsigned long)sizeof(CFE_ES_ResetData_t), (unsigned long)resetAreaSize);
}
else
{
CFE_EVS_ResetDataPtr = (CFE_ES_ResetData_t *)resetAreaAddr;
/* Save pointer to the EVS portion of the CFE reset area */
CFE_EVS_GlobalData.EVS_LogPtr = &CFE_EVS_ResetDataPtr->EVS_Log;
/* Create semaphore to serialize access to event log */
Status = OS_MutSemCreate(&CFE_EVS_GlobalData.EVS_SharedDataMutexID, "CFE_EVS_DataMutex", 0);
if (Status != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS call to OS_MutSemCreate failed, RC=0x%08x\n", (unsigned int)Status);
}
else
{
/* Enable access to the EVS event log */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled = true;
/* Clear event log if power-on reset or bad contents */
if (CFE_ES_GetResetType(NULL) == CFE_PSP_RST_TYPE_POWERON)
{
CFE_ES_WriteToSysLog("Event Log cleared following power-on reset\n");
EVS_ClearLog();
CFE_EVS_GlobalData.EVS_LogPtr->LogMode = CFE_PLATFORM_EVS_DEFAULT_LOG_MODE;
}
else if (((CFE_EVS_GlobalData.EVS_LogPtr->LogMode != CFE_EVS_LogMode_OVERWRITE) &&
(CFE_EVS_GlobalData.EVS_LogPtr->LogMode != CFE_EVS_LogMode_DISCARD)) ||
((CFE_EVS_GlobalData.EVS_LogPtr->LogFullFlag != false) &&
(CFE_EVS_GlobalData.EVS_LogPtr->LogFullFlag != true)) ||
(CFE_EVS_GlobalData.EVS_LogPtr->Next >= CFE_PLATFORM_EVS_LOG_MAX))
{
CFE_ES_WriteToSysLog("Event Log cleared, n=%d, c=%d, f=%d, m=%d, o=%d\n",
(int)CFE_EVS_GlobalData.EVS_LogPtr->Next,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogCount,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogFullFlag,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogMode,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogOverflowCounter);
EVS_ClearLog();
CFE_EVS_GlobalData.EVS_LogPtr->LogMode = CFE_PLATFORM_EVS_DEFAULT_LOG_MODE;
}
else
{
CFE_ES_WriteToSysLog("Event Log restored, n=%d, c=%d, f=%d, m=%d, o=%d\n",
(int)CFE_EVS_GlobalData.EVS_LogPtr->Next,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogCount,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogFullFlag,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogMode,
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogOverflowCounter);
}
}
}
#endif
return(CFE_SUCCESS);
} /* End CFE_EVS_EarlyInit */
/*
** Function Prologue
**
** Function Name: CFE_EVS_CleanUpApp
**
** Purpose: ES calls this routine when an app is being terminated.
**
** Assumptions and Notes:
*/
int32 CFE_EVS_CleanUpApp(CFE_ES_ResourceID_t AppID)
{
int32 Status = CFE_SUCCESS;
EVS_AppData_t *AppDataPtr;
/* Query and verify the caller's AppID */
AppDataPtr = EVS_GetAppDataByID(AppID);
if (AppDataPtr == NULL)
{
Status = CFE_EVS_APP_ILLEGAL_APP_ID;
}
else if (EVS_AppDataIsMatch(AppDataPtr, AppID))
{
/* Same cleanup as CFE_EVS_Unregister() */
EVS_AppDataSetFree(AppDataPtr);
}
return(Status);
}
/*
** Function Prologue
**
** Function Name: EVS_TaskMain
**
** Purpose: This is the main EVS task process loop.
**
** Assumptions and Notes:
**
*/
void CFE_EVS_TaskMain(void)
{
int32 Status;
CFE_SB_Buffer_t *SBBufPtr;
CFE_ES_PerfLogEntry(CFE_MISSION_EVS_MAIN_PERF_ID);
Status = CFE_EVS_TaskInit();
if(Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Application Init Failed,RC=0x%08X\n", (unsigned int)Status);
CFE_ES_PerfLogExit(CFE_MISSION_EVS_MAIN_PERF_ID);
/* Note: CFE_ES_ExitApp will not return */
CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_INIT_ERROR);
}/* end if */
/*
* Wait for other apps to start.
* It is important that the core apps are present before this starts receiving
* messages from the command pipe, as some of those handlers might depend on
* the other core apps.
*/
CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, CFE_PLATFORM_CORE_MAX_STARTUP_MSEC);
/* Main loop */
while (Status == CFE_SUCCESS)
{
/* Increment the Main task Execution Counter */
CFE_ES_IncrementTaskCounter();
CFE_ES_PerfLogExit(CFE_MISSION_EVS_MAIN_PERF_ID);
/* Pend on receipt of packet */
Status = CFE_SB_ReceiveBuffer(&SBBufPtr,
CFE_EVS_GlobalData.EVS_CommandPipe,
CFE_SB_PEND_FOREVER);
CFE_ES_PerfLogEntry(CFE_MISSION_EVS_MAIN_PERF_ID);
if (Status == CFE_SUCCESS)
{
/* Process cmd pipe msg */
CFE_EVS_ProcessCommandPacket(SBBufPtr);
}else{
CFE_ES_WriteToSysLog("EVS:Error reading cmd pipe,RC=0x%08X\n",(unsigned int)Status);
}/* end if */
}/* end while */
/* while loop exits only if CFE_SB_ReceiveBuffer returns error */
CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR);
} /* end CFE_EVS_TaskMain */
/*
** Function Prologue
**
** Function Name: CFE_EVS_TaskInit
**
** Purpose: This function performs any necessary EVS task initialization.
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_TaskInit ( void )
{
int32 Status;
CFE_ES_ResourceID_t AppID;
/* Register EVS application */
Status = CFE_ES_RegisterApp();
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Call to CFE_ES_RegisterApp Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
/* Query and verify the AppID */
Status = CFE_ES_GetAppID(&AppID);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Call to CFE_ES_GetAppID Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
/* Register EVS task for event services */
Status = CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Call to CFE_EVS_Register Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
/* Create software bus command pipe */
Status = CFE_SB_CreatePipe(&CFE_EVS_GlobalData.EVS_CommandPipe,
CFE_EVS_PIPE_DEPTH, CFE_EVS_PIPE_NAME);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Call to CFE_SB_CreatePipe Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
/* Subscribe to command and telemetry requests coming in on the command pipe */
Status = CFE_SB_SubscribeEx(CFE_SB_ValueToMsgId(CFE_EVS_CMD_MID), CFE_EVS_GlobalData.EVS_CommandPipe,
CFE_SB_Default_Qos, CFE_EVS_MSG_LIMIT);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Subscribing to Cmds Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
Status = CFE_SB_SubscribeEx(CFE_SB_ValueToMsgId(CFE_EVS_SEND_HK_MID), CFE_EVS_GlobalData.EVS_CommandPipe,
CFE_SB_Default_Qos, CFE_EVS_MSG_LIMIT);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("EVS:Subscribing to HK Request Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}
/* Write the AppID to the global location, now that the rest of initialization is done */
CFE_EVS_GlobalData.EVS_AppID = AppID;
EVS_SendEvent(CFE_EVS_STARTUP_EID, CFE_EVS_EventType_INFORMATION, "cFE EVS Initialized.%s", CFE_VERSION_STRING);
return CFE_SUCCESS;
} /* End CFE_EVS_TaskInit */
/*
** Function Prologue
**
** Function Name: CFE_EVS_ProcessCommandPacket
**
** Purpose: This function processes packets received on the EVS command pipe.
**
** Assumptions and Notes:
**
*/
void CFE_EVS_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID);
/* Process all SB messages */
switch (CFE_SB_MsgIdToValue(MessageID))
{
case CFE_EVS_CMD_MID:
/* EVS task specific command */
CFE_EVS_ProcessGroundCommand(SBBufPtr, MessageID);
break;
case CFE_EVS_SEND_HK_MID:
/* Housekeeping request */
CFE_EVS_ReportHousekeepingCmd((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;
default:
/* Unknown command -- should never occur */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.CommandErrorCounter++;
EVS_SendEvent(CFE_EVS_ERR_MSGID_EID, CFE_EVS_EventType_ERROR,
"Invalid command packet, Message ID = 0x%08X",
(unsigned int)CFE_SB_MsgIdToValue(MessageID));
break;
}
return;
} /* End CFE_EVS_ProcessCommandPacket */
/*
** Function Prologue
**
** Function Name: CFE_EVS_ProcessGroundCommand
**
** Purpose: This function processes a command, verifying that it is valid and of
** proper length.
**
** Assumptions and Notes:
**
*/
void CFE_EVS_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId)
{
/* status will get reset if it passes length check */
int32 Status = CFE_STATUS_WRONG_MSG_LENGTH;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode);
/* Process "known" EVS task ground commands */
switch (FcnCode)
{
case CFE_EVS_NOOP_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_NoopCmd_t)))
{
Status = CFE_EVS_NoopCmd((CFE_EVS_NoopCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_RESET_COUNTERS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetCountersCmd_t)))
{
Status = CFE_EVS_ResetCountersCmd((CFE_EVS_ResetCountersCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_ENABLE_EVENT_TYPE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableEventTypeCmd_t)))
{
Status = CFE_EVS_EnableEventTypeCmd((CFE_EVS_EnableEventTypeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_DISABLE_EVENT_TYPE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableEventTypeCmd_t)))
{
Status = CFE_EVS_DisableEventTypeCmd((CFE_EVS_DisableEventTypeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_SET_EVENT_FORMAT_MODE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetEventFormatModeCmd_t)))
{
Status = CFE_EVS_SetEventFormatModeCmd((CFE_EVS_SetEventFormatModeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_ENABLE_APP_EVENT_TYPE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventTypeCmd_t)))
{
Status = CFE_EVS_EnableAppEventTypeCmd((CFE_EVS_EnableAppEventTypeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_DISABLE_APP_EVENT_TYPE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventTypeCmd_t)))
{
Status = CFE_EVS_DisableAppEventTypeCmd((CFE_EVS_DisableAppEventTypeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_ENABLE_APP_EVENTS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventsCmd_t)))
{
Status = CFE_EVS_EnableAppEventsCmd((CFE_EVS_EnableAppEventsCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_DISABLE_APP_EVENTS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventsCmd_t)))
{
Status = CFE_EVS_DisableAppEventsCmd((CFE_EVS_DisableAppEventsCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_RESET_APP_COUNTER_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAppCounterCmd_t)))
{
Status = CFE_EVS_ResetAppCounterCmd((CFE_EVS_ResetAppCounterCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_SET_FILTER_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetFilterCmd_t)))
{
Status = CFE_EVS_SetFilterCmd((CFE_EVS_SetFilterCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_ENABLE_PORTS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnablePortsCmd_t)))
{
Status = CFE_EVS_EnablePortsCmd((CFE_EVS_EnablePortsCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_DISABLE_PORTS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisablePortsCmd_t)))
{
Status = CFE_EVS_DisablePortsCmd((CFE_EVS_DisablePortsCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_RESET_FILTER_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetFilterCmd_t)))
{
Status = CFE_EVS_ResetFilterCmd((CFE_EVS_ResetFilterCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_RESET_ALL_FILTERS_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAllFiltersCmd_t)))
{
Status = CFE_EVS_ResetAllFiltersCmd((CFE_EVS_ResetAllFiltersCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_ADD_EVENT_FILTER_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_AddEventFilterCmd_t)))
{
Status = CFE_EVS_AddEventFilterCmd((CFE_EVS_AddEventFilterCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_DELETE_EVENT_FILTER_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DeleteEventFilterCmd_t)))
{
Status = CFE_EVS_DeleteEventFilterCmd((CFE_EVS_DeleteEventFilterCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_WRITE_APP_DATA_FILE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteAppDataFileCmd_t)))
{
Status = CFE_EVS_WriteAppDataFileCmd((CFE_EVS_WriteAppDataFileCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_SET_LOG_MODE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetLogModeCmd_t)))
{
Status = CFE_EVS_SetLogModeCmd((CFE_EVS_SetLogModeCmd_t*)SBBufPtr);
}
break;
case CFE_EVS_CLEAR_LOG_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ClearLogCmd_t)))
{
Status = CFE_EVS_ClearLogCmd((CFE_EVS_ClearLogCmd_t *)SBBufPtr);
}
break;
case CFE_EVS_WRITE_LOG_DATA_FILE_CC:
if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteLogDataFileCmd_t)))
{
Status = CFE_EVS_WriteLogDataFileCmd((CFE_EVS_WriteLogDataFileCmd_t*)SBBufPtr);
}
break;
/* default is a bad command code as it was not found above */
default:
EVS_SendEvent(CFE_EVS_ERR_CC_EID, CFE_EVS_EventType_ERROR,
"Invalid command code -- ID = 0x%08x, CC = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId),
(unsigned int)FcnCode);
Status = CFE_STATUS_BAD_COMMAND_CODE;
break;
}
if (Status == CFE_SUCCESS)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.CommandCounter++;
}
else if (Status < 0) /* Negative values indicate errors */
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.CommandErrorCounter++;
}
return;
} /* End of EVS_ProcessGroundCommand() */
/*
** Function Prologue
**
** Function Name: CFE_EVS_VerifyCmdLength
**
** Purpose: This function validates the length of incoming commands.
**
** Assumptions and Notes:
**
*/
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_GetSize(MsgPtr, &ActualLength);
/*
** Verify the command packet length
*/
if (ExpectedLength != ActualLength)
{
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);
EVS_SendEvent(CFE_EVS_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode,
(unsigned int)ActualLength, (unsigned int)ExpectedLength);
result = false;
}
return(result);
} /* End of CFE_EVS_VerifyCmdLength() */
/*
** Function Prologue
**
** Function Name: CFE_EVS_NoopCmd
**
** Purpose: This function processes "no-op" commands received on the EVS command pipe.
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_NoopCmd(const CFE_EVS_NoopCmd_t *data)
{
EVS_SendEvent(CFE_EVS_NOOP_EID, CFE_EVS_EventType_INFORMATION,"No-op command. %s",
CFE_VERSION_STRING);
return CFE_SUCCESS;
}
/*
** Function Prologue
**
** Function Name: CFE_EVS_ClearLogCmd
**
** Purpose: This function processes "clear log" commands received on the EVS command pipe.
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_ClearLogCmd(const CFE_EVS_ClearLogCmd_t *data)
{
int32 Status;
if (CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled == true)
{
EVS_ClearLog();
Status = CFE_SUCCESS;
}
else
{
EVS_SendEvent(CFE_EVS_NO_LOGCLR_EID, CFE_EVS_EventType_ERROR,
"Clear Log Command: Event Log is Disabled");
Status = CFE_EVS_FUNCTION_DISABLED;
}
return Status;
}
/*
** Function Prologue
**
** Function Name: CFE_EVS_ReportHousekeepingCmd
**
** Purpose: Request for housekeeping status telemetry packet.
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_ReportHousekeepingCmd (const CFE_MSG_CommandHeader_t *data)
{
uint32 i, j;
EVS_AppData_t *AppDataPtr;
CFE_EVS_AppTlmData_t *AppTlmDataPtr;
if (CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled == true)
{
/* Copy hk variables that are maintained in the event log */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogFullFlag = CFE_EVS_GlobalData.EVS_LogPtr->LogFullFlag;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogMode = CFE_EVS_GlobalData.EVS_LogPtr->LogMode;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogOverflowCounter = CFE_EVS_GlobalData.EVS_LogPtr->LogOverflowCounter;
}
/* Write event state data for registered apps to telemetry packet */
AppDataPtr = CFE_EVS_GlobalData.AppData;
AppTlmDataPtr = CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData;
for (i = 0, j = 0; j < CFE_MISSION_ES_MAX_APPLICATIONS && i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++)
{
if ( EVS_AppDataIsUsed(AppDataPtr) )
{
AppTlmDataPtr->AppID = EVS_AppDataGetID(AppDataPtr);
AppTlmDataPtr->AppEnableStatus = AppDataPtr->ActiveFlag;
AppTlmDataPtr->AppMessageSentCounter = AppDataPtr->EventCount;
++j;
++AppTlmDataPtr;
}
++AppDataPtr;
}
/* Clear unused portion of event state data in telemetry packet */
for (i = j; i < CFE_MISSION_ES_MAX_APPLICATIONS; i++)
{
AppTlmDataPtr->AppID = CFE_ES_RESOURCEID_UNDEFINED;
AppTlmDataPtr->AppEnableStatus = false;
AppTlmDataPtr->AppMessageSentCounter = 0;
}
CFE_SB_TimeStampMsg(&CFE_EVS_GlobalData.EVS_TlmPkt.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_EVS_GlobalData.EVS_TlmPkt.TlmHeader.Msg, true);
return CFE_STATUS_NO_COUNTER_INCREMENT;
} /* End of CFE_EVS_ReportHousekeepingCmd() */
/*
** Function Prologue
**
** Function Name: CFE_EVS_ResetCountersCmd
**
** Purpose: This function resets all the global counter variables that are
** part of the task telemetry.
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_ResetCountersCmd(const CFE_EVS_ResetCountersCmd_t *data)
{
/* Status of commands processed by EVS task */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.CommandCounter = 0;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.CommandErrorCounter = 0;
/* EVS telemetry counters */
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageSendCounter = 0;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageTruncCounter = 0;
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.UnregisteredAppCounter = 0;
EVS_SendEvent(CFE_EVS_RSTCNT_EID, CFE_EVS_EventType_DEBUG, "Reset Counters Command Received");
/* NOTE: Historically the reset counters command does _NOT_ increment the command counter */
return CFE_STATUS_NO_COUNTER_INCREMENT;
} /* End of CFE_EVS_ResetCountersCmd() */
/*
** Function Prologue
**
** Function Name: CFE_EVS_SetEventFilterMaskCmd
**
** Purpose: This routine sets the filter mask for the given event_id in the
** calling task's filter array
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilterCmd_t *data)
{
const CFE_EVS_AppNameEventIDMaskCmd_Payload_t *CmdPtr = &data->Payload;
EVS_BinFilter_t *FilterPtr;
int32 Status;
EVS_AppData_t *AppDataPtr;
char LocalName[OS_MAX_API_NAME];
/*
* Althgouh EVS_GetApplicationInfo() does not require a null terminated argument,
* the value is passed to EVS_SendEvent which does require termination (normal C string)
*/
CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL,
sizeof(LocalName), sizeof(CmdPtr->AppName));
/* Retreive application data */
Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName);
if (Status == CFE_SUCCESS)
{
FilterPtr = EVS_FindEventID(CmdPtr->EventID, AppDataPtr->BinFilters);
if(FilterPtr != NULL)
{
/* Set application filter mask */
FilterPtr->Mask = CmdPtr->Mask;
EVS_SendEvent(CFE_EVS_SETFILTERMSK_EID, CFE_EVS_EventType_DEBUG,
"Set Filter Mask Command Received with AppName=%s, EventID=0x%08x, Mask=0x%04x",
LocalName, (unsigned int)CmdPtr->EventID, (unsigned int)CmdPtr->Mask);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_EVTIDNOREGS_EID, CFE_EVS_EventType_ERROR,
"%s Event ID %d not registered for filtering: CC = %lu ",
LocalName, (int)CmdPtr->EventID, (long unsigned int)CFE_EVS_SET_FILTER_CC);
Status = CFE_EVS_EVT_NOT_REGISTERED;
}
}
else if(Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR,
"%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC);
}
else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC);
}
return Status;
} /* End CFE_EVS_SetFilterMaskCmd */
/*
** Function Prologue
**
** Function Name: CFE_EVS_EnablePortsCmd
**
** Purpose: This routine sets the command given ports to an enabled state
**
** Assumptions and Notes:
** Shifting is done so the value not masked off is placed in the ones spot:
** necessary for comparing with true.
*/
int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
{
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu",
(unsigned int)CmdPtr->BitMask, (long unsigned int)CFE_EVS_ENABLE_PORTS_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
{
/* Process command data */
if(((CmdPtr->BitMask & CFE_EVS_PORT1_BIT) >> 0) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort |= CFE_EVS_PORT1_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT2_BIT) >>1) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort |= CFE_EVS_PORT2_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT3_BIT) >> 2) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort |= CFE_EVS_PORT3_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT4_BIT) >>3) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort |= CFE_EVS_PORT4_BIT;
}
EVS_SendEvent(CFE_EVS_ENAPORT_EID, CFE_EVS_EventType_DEBUG,
"Enable Ports Command Received with Port Bit Mask = 0x%02x",
(unsigned int)CmdPtr->BitMask);
ReturnCode = CFE_SUCCESS;
}
return ReturnCode;
} /* End CFE_EVS_EnablePortsCmd */
/*
** Function Prologue
**
** Function Name: CFE_EVS_DisablePortsCmd
**
** Purpose: This routine sets the command given ports to a disabled state
**
** Assumptions and Notes:
** Shifting is done so the value not masked off is placed in the ones spot:
** necessary for comparing with true.
*/
int32 CFE_EVS_DisablePortsCmd(const CFE_EVS_DisablePortsCmd_t *data)
{
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu",
(unsigned int)CmdPtr->BitMask, (long unsigned int)CFE_EVS_DISABLE_PORTS_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
{
/* Process command data */
if(((CmdPtr->BitMask & CFE_EVS_PORT1_BIT) >>0) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort &= ~CFE_EVS_PORT1_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT2_BIT) >> 1) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort &= ~CFE_EVS_PORT2_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT3_BIT) >> 2) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort &= ~CFE_EVS_PORT3_BIT;
}
if(((CmdPtr->BitMask & CFE_EVS_PORT4_BIT) >>3) == true)
{
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.OutputPort &= ~CFE_EVS_PORT4_BIT;
}
EVS_SendEvent(CFE_EVS_DISPORT_EID, CFE_EVS_EventType_DEBUG,
"Disable Ports Command Received with Port Bit Mask = 0x%02x",
(unsigned int)CmdPtr->BitMask);
ReturnCode = CFE_SUCCESS;
}
return ReturnCode;
} /* End CFE_EVS_DisablePortsCmd */
/*
** Function Prologue
**
** Function Name: CFE_EVS_EnableEventTypesCmd
**
** Purpose: This routine sets the given event types to an enabled state across all
** registered applications
**
** Assumptions and Notes:
**
*/
int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventTypeCmd_t *data)
{
uint32 i;
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
EVS_AppData_t *AppDataPtr;
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu",
(unsigned int)CmdPtr->BitMask, (long unsigned int)CFE_EVS_ENABLE_EVENT_TYPE_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
{
AppDataPtr = CFE_EVS_GlobalData.AppData;
for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++)
{
/* Make sure application is registered for event services */
if ( EVS_AppDataIsUsed(AppDataPtr) )
{
EVS_EnableTypes(AppDataPtr, CmdPtr->BitMask);
}
++AppDataPtr;