-
Notifications
You must be signed in to change notification settings - Fork 202
/
cfe_sb_task.c
1446 lines (1210 loc) · 51.4 KB
/
cfe_sb_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_sb_task.c
**
** Purpose:
** This file contains the source code for the SB task.
**
** Author: R.McGraw/SSI
**
******************************************************************************/
/* Include Files */
#include "cfe_sb_module_all.h"
#include "cfe_version.h"
#include "cfe_es_msg.h" /* needed for local use of CFE_ES_RestartCmd_t */
#include <string.h>
/* Task Globals */
CFE_SB_Global_t CFE_SB_Global;
/* Local structure for file writing callbacks */
typedef struct
{
const char *Filename; /* File name for error reporting */
osal_id_t Fd; /* File id for writing */
uint32 FileSize; /* File size for reporting */
uint32 EntryCount; /* Entry count for reporting */
int32 Status; /* File write status */
} CFE_SB_FileWriteCallback_t;
/******************************************************************************
** Function: CFE_SB_TaskMain()
**
** Purpose:
** Main loop for Software Bus task, used to process SB commands.
**
** Arguments:
** none
**
** Return:
** none
*/
void CFE_SB_TaskMain(void)
{
int32 Status;
CFE_SB_Buffer_t *SBBufPtr;
CFE_ES_PerfLogEntry(CFE_MISSION_SB_MAIN_PERF_ID);
Status = CFE_SB_AppInit();
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Application Init Failed,RC=0x%08X\n", (unsigned int)Status);
CFE_ES_PerfLogExit(CFE_MISSION_SB_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_SB_MAIN_PERF_ID);
/* Pend on receipt of packet */
Status = CFE_SB_ReceiveBuffer(&SBBufPtr, CFE_SB_Global.CmdPipe, CFE_SB_PEND_FOREVER);
CFE_ES_PerfLogEntry(CFE_MISSION_SB_MAIN_PERF_ID);
if (Status == CFE_SUCCESS)
{
/* Process cmd pipe msg */
CFE_SB_ProcessCmdPipePkt(SBBufPtr);
}
else
{
CFE_ES_WriteToSysLog("SB: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_SB_TaskMain */
/******************************************************************************
** Function: CFE_SB_AppInit()
**
** Purpose:
** Initialization routine for SB application. This routine is executed when
** the SB application is started by Executive Services.
**
** Arguments:
** none
**
** Return:
** CFE_SUCCESS if no errors, otherwise this function returns the error code
** that was received from the function that detected the error.
**
*/
int32 CFE_SB_AppInit(void)
{
uint32 CfgFileEventsToFilter = 0;
CFE_ES_MemPoolBuf_t TmpPtr;
int32 Status;
/* Get the assigned Application ID for the SB Task */
CFE_ES_GetAppID(&CFE_SB_Global.AppId);
/* Process the platform cfg file events to be filtered */
if (CFE_PLATFORM_SB_FILTERED_EVENT1 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT1;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK1;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT2 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT2;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK2;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT3 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT3;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK3;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT4 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT4;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK4;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT5 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT5;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK5;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT6 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT6;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK6;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT7 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT7;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK7;
CfgFileEventsToFilter++;
} /* end if */
if (CFE_PLATFORM_SB_FILTERED_EVENT8 != 0)
{
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].EventID = CFE_PLATFORM_SB_FILTERED_EVENT8;
CFE_SB_Global.EventFilters[CfgFileEventsToFilter].Mask = CFE_PLATFORM_SB_FILTER_MASK8;
CfgFileEventsToFilter++;
} /* end if */
/* Be sure the number of events to register for filtering
** does not exceed CFE_PLATFORM_EVS_MAX_EVENT_FILTERS */
if (CFE_PLATFORM_EVS_MAX_EVENT_FILTERS < CfgFileEventsToFilter)
{
CfgFileEventsToFilter = CFE_PLATFORM_EVS_MAX_EVENT_FILTERS;
} /* end if */
/* Register event filter table... */
Status = CFE_EVS_Register(CFE_SB_Global.EventFilters, CfgFileEventsToFilter, CFE_EVS_EventFilter_BINARY);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Call to CFE_EVS_Register Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
CFE_ES_WriteToSysLog("SB:Registered %d events for filtering\n", (int)CfgFileEventsToFilter);
CFE_MSG_Init(&CFE_SB_Global.HKTlmMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_HK_TLM_MID),
sizeof(CFE_SB_Global.HKTlmMsg));
CFE_MSG_Init(&CFE_SB_Global.PrevSubMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_ALLSUBS_TLM_MID),
sizeof(CFE_SB_Global.PrevSubMsg));
/* Populate the fixed fields in the HK Tlm Msg */
CFE_SB_Global.HKTlmMsg.Payload.MemPoolHandle = CFE_SB_Global.Mem.PoolHdl;
/* Populate the fixed fields in the Stat Tlm Msg */
CFE_SB_Global.StatTlmMsg.Payload.MaxMsgIdsAllowed = CFE_PLATFORM_SB_MAX_MSG_IDS;
CFE_SB_Global.StatTlmMsg.Payload.MaxPipesAllowed = CFE_PLATFORM_SB_MAX_PIPES;
CFE_SB_Global.StatTlmMsg.Payload.MaxMemAllowed = CFE_PLATFORM_SB_BUF_MEMORY_BYTES;
CFE_SB_Global.StatTlmMsg.Payload.MaxPipeDepthAllowed = OS_QUEUE_MAX_DEPTH;
CFE_SB_Global.StatTlmMsg.Payload.MaxSubscriptionsAllowed =
((CFE_PLATFORM_SB_MAX_MSG_IDS) * (CFE_PLATFORM_SB_MAX_DEST_PER_PKT));
Status = CFE_SB_CreatePipe(&CFE_SB_Global.CmdPipe, CFE_SB_CMD_PIPE_DEPTH, CFE_SB_CMD_PIPE_NAME);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Call to CFE_SB_CreatePipe Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_SB_CMD_MID), CFE_SB_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Subscribe to Cmds Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_SB_SEND_HK_MID), CFE_SB_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Subscribe to HK Request Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID), CFE_SB_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Subscribe to Subscription Report Request Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
/* Ensure a ground commanded reset does not get blocked if SB mem pool */
/* becomes fully configured (DCR6772) */
Status = CFE_ES_GetPoolBuf(&TmpPtr, CFE_SB_Global.Mem.PoolHdl, sizeof(CFE_ES_RestartCmd_t));
if (Status < 0)
{
CFE_ES_WriteToSysLog("SB:Init error, GetPool Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
/* Return mem block used on previous call,the actual memory is not needed.*/
/* The SB mem pool is now configured with a block size for the reset cmd. */
Status = CFE_ES_PutPoolBuf(CFE_SB_Global.Mem.PoolHdl, TmpPtr);
if (Status < 0)
{
CFE_ES_WriteToSysLog("SB:Init error, PutPool Failed:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_EVS_SendEvent(CFE_SB_INIT_EID, CFE_EVS_EventType_INFORMATION, "cFE SB Initialized");
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SB:Error sending init event:RC=0x%08X\n", (unsigned int)Status);
return Status;
} /* end if */
return CFE_SUCCESS;
} /* end CFE_SB_AppInit */
/******************************************************************************
** Function: CFE_SB_VerifyCmdLength()
**
** Purpose:
** Function to verify the length of incoming SB command packets
**
** Arguments:
** Message pointer and expected length
**
** Return:
** true if length is acceptable
*/
bool CFE_SB_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);
CFE_EVS_SendEvent(CFE_SB_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;
++CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter;
}
return (result);
} /* End of CFE_SB_VerifyCmdLength() */
/******************************************************************************
** Function: CFE_SB_ProcessCmdPipePkt()
**
** Purpose:
** Function to control actions when an SB command is received.
**
** Arguments:
** Software bus buffer pointer
**
** Return:
** none
*/
void CFE_SB_ProcessCmdPipePkt(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
{
case CFE_SB_SEND_HK_MID:
/* Note: Command counter not incremented for this command */
CFE_SB_SendHKTlmCmd((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;
case CFE_SB_SUB_RPT_CTRL_MID:
/* Note: Command counter not incremented for this command */
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode);
switch (FcnCode)
{
case CFE_SB_SEND_PREV_SUBS_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendPrevSubsCmd_t)))
{
CFE_SB_SendPrevSubsCmd((CFE_SB_SendPrevSubsCmd_t *)SBBufPtr);
}
break;
case CFE_SB_ENABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableSubReportingCmd_t)))
{
CFE_SB_EnableSubReportingCmd((CFE_SB_EnableSubReportingCmd_t *)SBBufPtr);
}
break;
case CFE_SB_DISABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableSubReportingCmd_t)))
{
CFE_SB_DisableSubReportingCmd((CFE_SB_DisableSubReportingCmd_t *)SBBufPtr);
}
break;
default:
CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR,
"Invalid Cmd, Unexpected Command Code %u", (unsigned int)FcnCode);
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
break;
} /* end switch on cmd code */
break;
case CFE_SB_CMD_MID:
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode);
switch (FcnCode)
{
case CFE_SB_NOOP_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_NoopCmd_t)))
{
CFE_SB_NoopCmd((CFE_SB_NoopCmd_t *)SBBufPtr);
}
break;
case CFE_SB_RESET_COUNTERS_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_ResetCountersCmd_t)))
{
/* Note: Command counter not incremented for this command */
CFE_SB_ResetCountersCmd((CFE_SB_ResetCountersCmd_t *)SBBufPtr);
}
break;
case CFE_SB_SEND_SB_STATS_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendSbStatsCmd_t)))
{
CFE_SB_SendStatsCmd((CFE_SB_SendSbStatsCmd_t *)SBBufPtr);
}
break;
case CFE_SB_WRITE_ROUTING_INFO_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteRoutingInfoCmd_t)))
{
CFE_SB_WriteRoutingInfoCmd((CFE_SB_WriteRoutingInfoCmd_t *)SBBufPtr);
}
break;
case CFE_SB_ENABLE_ROUTE_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableRouteCmd_t)))
{
CFE_SB_EnableRouteCmd((CFE_SB_EnableRouteCmd_t *)SBBufPtr);
}
break;
case CFE_SB_DISABLE_ROUTE_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableRouteCmd_t)))
{
CFE_SB_DisableRouteCmd((CFE_SB_DisableRouteCmd_t *)SBBufPtr);
}
break;
case CFE_SB_WRITE_PIPE_INFO_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WritePipeInfoCmd_t)))
{
CFE_SB_WritePipeInfoCmd((CFE_SB_WritePipeInfoCmd_t *)SBBufPtr);
}
break;
case CFE_SB_WRITE_MAP_INFO_CC:
if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteMapInfoCmd_t)))
{
CFE_SB_WriteMapInfoCmd((CFE_SB_WriteMapInfoCmd_t *)SBBufPtr);
}
break;
default:
CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR,
"Invalid Cmd, Unexpected Command Code %u", FcnCode);
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
break;
} /* end switch on cmd code */
break;
default:
CFE_EVS_SendEvent(CFE_SB_BAD_MSGID_EID, CFE_EVS_EventType_ERROR, "Invalid Cmd, Unexpected Msg Id: 0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MessageID));
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
break;
} /* end switch on MsgId */
} /* end CFE_SB_ProcessCmdPipePkt */
/******************************************************************************
** Function: CFE_SB_NoopCmd()
**
** Purpose:
** Handler function the SB command
**
*/
int32 CFE_SB_NoopCmd(const CFE_SB_NoopCmd_t *data)
{
CFE_EVS_SendEvent(CFE_SB_CMD0_RCVD_EID, CFE_EVS_EventType_INFORMATION, "No-op Cmd Rcvd. %s", CFE_VERSION_STRING);
CFE_SB_Global.HKTlmMsg.Payload.CommandCounter++;
return CFE_SUCCESS;
}
/******************************************************************************
** Function: CFE_SB_ResetCountersCmd()
**
** Purpose:
** Handler function the SB command
**
*/
int32 CFE_SB_ResetCountersCmd(const CFE_SB_ResetCountersCmd_t *data)
{
CFE_EVS_SendEvent(CFE_SB_CMD1_RCVD_EID, CFE_EVS_EventType_DEBUG, "Reset Counters Cmd Rcvd");
CFE_SB_ResetCounters();
return CFE_SUCCESS;
}
/******************************************************************************
** Function: CFE_SB_EnableSubReportingCmd()
**
** Purpose:
** Handler function the SB command
**
*/
int32 CFE_SB_EnableSubReportingCmd(const CFE_SB_EnableSubReportingCmd_t *data)
{
CFE_SB_SetSubscriptionReporting(CFE_SB_ENABLE);
return CFE_SUCCESS;
}
/******************************************************************************
** Function: CFE_SB_DisableSubReportingCmd()
**
** Purpose:
** Handler function the SB command
**
*/
int32 CFE_SB_DisableSubReportingCmd(const CFE_SB_DisableSubReportingCmd_t *data)
{
CFE_SB_SetSubscriptionReporting(CFE_SB_DISABLE);
return CFE_SUCCESS;
}
/******************************************************************************
** Function: CFE_SB_SendHKTlmCmd()
**
** Purpose:
** Function to send the SB housekeeping packet.
**
** Arguments:
** none
**
** Notes:
** Command counter not incremented for this command
**
** Return:
** none
*/
int32 CFE_SB_SendHKTlmCmd(const CFE_MSG_CommandHeader_t *data)
{
CFE_SB_LockSharedData(__FILE__, __LINE__);
CFE_SB_Global.HKTlmMsg.Payload.MemInUse = CFE_SB_Global.StatTlmMsg.Payload.MemInUse;
CFE_SB_Global.HKTlmMsg.Payload.UnmarkedMem =
CFE_PLATFORM_SB_BUF_MEMORY_BYTES - CFE_SB_Global.StatTlmMsg.Payload.PeakMemInUse;
CFE_SB_UnlockSharedData(__FILE__, __LINE__);
CFE_SB_TimeStampMsg(&CFE_SB_Global.HKTlmMsg.Hdr.Msg);
CFE_SB_TransmitMsg(&CFE_SB_Global.HKTlmMsg.Hdr.Msg, true);
return CFE_SUCCESS;
} /* end CFE_SB_SendHKTlmCmd */
/******************************************************************************
** Function: CFE_SB_ResetCounters()
**
** Purpose:
** Function to reset the SB housekeeping counters.
**
** Arguments:
** none
**
** Notes:
** Command counter not incremented for this command
**
** Return:
** none
*/
void CFE_SB_ResetCounters(void)
{
CFE_SB_Global.HKTlmMsg.Payload.CommandCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.NoSubscribersCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.DuplicateSubscriptionsCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.MsgSendErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.MsgReceiveErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.InternalErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.CreatePipeErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.SubscribeErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.PipeOverflowErrorCounter = 0;
CFE_SB_Global.HKTlmMsg.Payload.MsgLimitErrorCounter = 0;
} /* end CFE_SB_ResetCounters */
/******************************************************************************
** Function: CFE_SB_EnableRouteCmd()
**
** Purpose:
** SB internal function to enable a specific route. A route is defined as a
** MsgId/PipeId combination.
**
** Arguments:
** MsgPtr : pointer to the message
**
** Return:
** None
*/
int32 CFE_SB_EnableRouteCmd(const CFE_SB_EnableRouteCmd_t *data)
{
CFE_SB_MsgId_t MsgId;
CFE_SB_PipeD_t * PipeDscPtr;
CFE_SB_DestinationD_t * DestPtr;
const CFE_SB_RouteCmd_Payload_t *CmdPtr;
uint16 PendingEventID;
PendingEventID = 0;
CmdPtr = &data->Payload;
MsgId = CmdPtr->MsgId;
CFE_SB_LockSharedData(__func__, __LINE__);
/* check cmd parameters */
PipeDscPtr = CFE_SB_LocatePipeDescByID(CmdPtr->Pipe);
if (!CFE_SB_IsValidMsgId(MsgId) || !CFE_SB_PipeDescIsMatch(PipeDscPtr, CmdPtr->Pipe))
{
PendingEventID = CFE_SB_ENBL_RTE3_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
}
else
{
DestPtr = CFE_SB_GetDestPtr(CFE_SBR_GetRouteId(MsgId), CmdPtr->Pipe);
if (DestPtr == NULL)
{
PendingEventID = CFE_SB_ENBL_RTE1_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
}
else
{
DestPtr->Active = CFE_SB_ACTIVE;
PendingEventID = CFE_SB_ENBL_RTE2_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandCounter++;
}
} /* end if */
CFE_SB_UnlockSharedData(__func__, __LINE__);
switch (PendingEventID)
{
case CFE_SB_ENBL_RTE1_EID:
CFE_EVS_SendEvent(CFE_SB_ENBL_RTE1_EID, CFE_EVS_EventType_ERROR,
"Enbl Route Cmd:Route does not exist.Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
case CFE_SB_ENBL_RTE3_EID:
CFE_EVS_SendEvent(CFE_SB_ENBL_RTE3_EID, CFE_EVS_EventType_ERROR,
"Enbl Route Cmd:Invalid Param.Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
case CFE_SB_ENBL_RTE2_EID:
CFE_EVS_SendEvent(CFE_SB_ENBL_RTE2_EID, CFE_EVS_EventType_DEBUG, "Enabling Route,Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
}
return CFE_SUCCESS;
} /* end CFE_SB_EnableRouteCmd */
/******************************************************************************
** Function: CFE_SB_DisableRouteCmd()
**
** Purpose:
** SB internal function to disable a specific route. A route is defined as a
** MsgId/PipeId combination.
**
** Arguments:
** MsgPtr : pointer to the message
**
** Return:
** None
*/
int32 CFE_SB_DisableRouteCmd(const CFE_SB_DisableRouteCmd_t *data)
{
CFE_SB_MsgId_t MsgId;
CFE_SB_PipeD_t * PipeDscPtr;
CFE_SB_DestinationD_t * DestPtr;
const CFE_SB_RouteCmd_Payload_t *CmdPtr;
uint16 PendingEventID;
PendingEventID = 0;
CmdPtr = &data->Payload;
MsgId = CmdPtr->MsgId;
CFE_SB_LockSharedData(__func__, __LINE__);
/* check cmd parameters */
PipeDscPtr = CFE_SB_LocatePipeDescByID(CmdPtr->Pipe);
if (!CFE_SB_IsValidMsgId(MsgId) || !CFE_SB_PipeDescIsMatch(PipeDscPtr, CmdPtr->Pipe))
{
PendingEventID = CFE_SB_DSBL_RTE3_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
}
else
{
DestPtr = CFE_SB_GetDestPtr(CFE_SBR_GetRouteId(MsgId), CmdPtr->Pipe);
if (DestPtr == NULL)
{
PendingEventID = CFE_SB_DSBL_RTE1_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++;
}
else
{
DestPtr->Active = CFE_SB_INACTIVE;
PendingEventID = CFE_SB_DSBL_RTE2_EID;
CFE_SB_Global.HKTlmMsg.Payload.CommandCounter++;
}
} /* end if */
CFE_SB_UnlockSharedData(__func__, __LINE__);
switch (PendingEventID)
{
case CFE_SB_DSBL_RTE1_EID:
CFE_EVS_SendEvent(CFE_SB_DSBL_RTE1_EID, CFE_EVS_EventType_ERROR,
"Disable Route Cmd:Route does not exist,Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
case CFE_SB_DSBL_RTE3_EID:
CFE_EVS_SendEvent(CFE_SB_DSBL_RTE3_EID, CFE_EVS_EventType_ERROR,
"Disable Route Cmd:Invalid Param.Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
case CFE_SB_DSBL_RTE2_EID:
CFE_EVS_SendEvent(CFE_SB_DSBL_RTE2_EID, CFE_EVS_EventType_DEBUG, "Route Disabled,Msg 0x%x,Pipe %lu",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(CmdPtr->Pipe));
break;
}
return CFE_SUCCESS;
} /* end CFE_SB_DisableRouteCmd */
/******************************************************************************
** Function: CFE_SB_SendStatsCmd()
**
** Purpose:
** SB internal function to send a Software Bus statistics packet
**
** Arguments:
** None
**
** Return:
** None
*/
int32 CFE_SB_SendStatsCmd(const CFE_SB_SendSbStatsCmd_t *data)
{
uint32 PipeDscCount;
uint32 PipeStatCount;
CFE_SB_PipeD_t * PipeDscPtr;
CFE_SB_PipeDepthStats_t *PipeStatPtr;
CFE_SB_LockSharedData(__FILE__, __LINE__);
/* Collect data on pipes */
PipeDscCount = CFE_PLATFORM_SB_MAX_PIPES;
PipeStatCount = CFE_MISSION_SB_MAX_PIPES;
PipeDscPtr = CFE_SB_Global.PipeTbl;
PipeStatPtr = CFE_SB_Global.StatTlmMsg.Payload.PipeDepthStats;
while (PipeDscCount > 0 && PipeStatCount > 0)
{
if (CFE_SB_PipeDescIsUsed(PipeDscPtr))
{
PipeStatPtr->PipeId = PipeDscPtr->PipeId;
/* Copy depth info */
PipeStatPtr->CurrentQueueDepth = PipeDscPtr->CurrentQueueDepth;
PipeStatPtr->PeakQueueDepth = PipeDscPtr->PeakQueueDepth;
PipeStatPtr->MaxQueueDepth = PipeDscPtr->MaxQueueDepth;
++PipeStatPtr;
--PipeStatCount;
}
--PipeDscCount;
++PipeDscPtr;
}
CFE_SB_UnlockSharedData(__FILE__, __LINE__);
while (PipeStatCount > 0)
{
memset(PipeStatPtr, 0, sizeof(*PipeStatPtr));
++PipeStatPtr;
--PipeStatCount;
}
CFE_SB_TimeStampMsg(&CFE_SB_Global.StatTlmMsg.Hdr.Msg);
CFE_SB_TransmitMsg(&CFE_SB_Global.StatTlmMsg.Hdr.Msg, true);
CFE_EVS_SendEvent(CFE_SB_SND_STATS_EID, CFE_EVS_EventType_DEBUG, "Software Bus Statistics packet sent");
CFE_SB_Global.HKTlmMsg.Payload.CommandCounter++;
return CFE_SUCCESS;
} /* CFE_SB_SendStatsCmd */
/******************************************************************************
* Local callback helper for writing routing info to a file
*/
void CFE_SB_CollectRouteInfo(CFE_SBR_RouteId_t RouteId, void *ArgPtr)
{
CFE_SB_DestinationD_t * DestPtr;
CFE_SB_PipeD_t * PipeDscPtr;
CFE_SB_MsgId_t RouteMsgId;
CFE_SB_BackgroundRouteInfoBuffer_t *RouteBufferPtr;
CFE_SB_RoutingFileEntry_t * FileEntryPtr;
CFE_ES_AppId_t DestAppId[CFE_PLATFORM_SB_MAX_DEST_PER_PKT];
uint32 i;
/* Cast arguments for local use */
RouteBufferPtr = (CFE_SB_BackgroundRouteInfoBuffer_t *)ArgPtr;
/* Extract data from runtime info, write into the temporary buffer */
/* Data must be locked to snapshot the route info */
CFE_SB_LockSharedData(__FILE__, __LINE__);
RouteMsgId = CFE_SBR_GetMsgId(RouteId);
RouteBufferPtr->NumDestinations = 0;
/* If this is a valid route, get the destinations */
if (CFE_SB_IsValidMsgId(RouteMsgId))
{
DestPtr = CFE_SBR_GetDestListHeadPtr(RouteId);
/* copy relevant data from the destination list into the temp buffer */
while (DestPtr != NULL && RouteBufferPtr->NumDestinations < CFE_PLATFORM_SB_MAX_DEST_PER_PKT)
{
PipeDscPtr = CFE_SB_LocatePipeDescByID(DestPtr->PipeId);
/* If invalid id, continue on to next entry */
if (CFE_SB_PipeDescIsMatch(PipeDscPtr, DestPtr->PipeId))
{
FileEntryPtr = &RouteBufferPtr->DestEntries[RouteBufferPtr->NumDestinations];
/* clear all fields in the temp buffer before re-use */
memset(FileEntryPtr, 0, sizeof(*FileEntryPtr));
FileEntryPtr->PipeId = DestPtr->PipeId;
FileEntryPtr->State = DestPtr->Active;
FileEntryPtr->MsgCnt = DestPtr->DestCnt;
/* Stash the Pipe Owner AppId - App Name is looked up later (comes from ES) */
DestAppId[RouteBufferPtr->NumDestinations] = PipeDscPtr->AppId;
++RouteBufferPtr->NumDestinations;
}
DestPtr = DestPtr->Next;
}
}
CFE_SB_UnlockSharedData(__FILE__, __LINE__);
/* Go through the temp buffer and fill in the remaining info for each dest */
FileEntryPtr = RouteBufferPtr->DestEntries;
for (i = 0; i < RouteBufferPtr->NumDestinations; ++i)
{
/* All dest entries refer to the same MsgId (based on the route) */
FileEntryPtr->MsgId = RouteMsgId;
/*
* NOTE: as long as CFE_ES_GetAppName() is given a nonzero-length
* output buffer, it guarantees null termination of the output, even
* if the AppID is invalid - in which case it returns an empty string.
*/
CFE_ES_GetAppName(FileEntryPtr->AppName, DestAppId[i], sizeof(FileEntryPtr->AppName));
CFE_SB_GetPipeName(FileEntryPtr->PipeName, sizeof(FileEntryPtr->PipeName), FileEntryPtr->PipeId);
++FileEntryPtr;
}
}
/******************************************************************************
** Function: CFE_SB_SendSubscriptionReport()
**
** Purpose:
** SB internal function to generate the "ONESUB_TLM" message after a subscription.
** No-op when subscription reporting is disabled.
**
** Arguments:
** Payload of notification message - MsgId, PipeId, QOS
**
** Return:
** CFE_SUCCESS or error code
*/
int32 CFE_SB_SendSubscriptionReport(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId, CFE_SB_Qos_t Quality)
{
CFE_SB_SingleSubscriptionTlm_t SubRptMsg;
int32 Status;
Status = CFE_SUCCESS;
if (CFE_SB_Global.SubscriptionReporting == CFE_SB_ENABLE)
{
CFE_MSG_Init(&SubRptMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_ONESUB_TLM_MID), sizeof(SubRptMsg));
SubRptMsg.Payload.MsgId = MsgId;
SubRptMsg.Payload.Pipe = PipeId;
SubRptMsg.Payload.Qos = Quality;
SubRptMsg.Payload.SubType = CFE_SB_SUBSCRIPTION;
Status = CFE_SB_TransmitMsg(&SubRptMsg.Hdr.Msg, true);
CFE_EVS_SendEventWithAppID(CFE_SB_SUBSCRIPTION_RPT_EID, CFE_EVS_EventType_DEBUG, CFE_SB_Global.AppId,
"Sending Subscription Report Msg=0x%x,Pipe=%lu,Stat=0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(PipeId),
(unsigned int)Status);
}
return Status;
}
bool CFE_SB_WriteRouteInfoDataGetter(void *Meta, uint32 RecordNum, void **Buffer, size_t *BufSize)
{
CFE_SB_BackgroundFileStateInfo_t *BgFilePtr;
CFE_SBR_Throttle_t Throttle;
/* Cast arguments for local use */
BgFilePtr = (CFE_SB_BackgroundFileStateInfo_t *)Meta;
Throttle.StartIndex = RecordNum;
Throttle.MaxLoop = 1;
Throttle.NextIndex = 0;
/* Reset NumDestinations to 0, just in case the CFE_SBR_ForEachRouteId() is a no-op */
BgFilePtr->Buffer.RouteInfo.NumDestinations = 0;
/* Collect info on the next route (limited to one per cycle via throttle) */
CFE_SBR_ForEachRouteId(CFE_SB_CollectRouteInfo, &BgFilePtr->Buffer.RouteInfo, &Throttle);
/* Pass the output of CFE_SB_CollectRouteInfo() back to be written */
*Buffer = &BgFilePtr->Buffer.RouteInfo.DestEntries;
*BufSize = sizeof(CFE_SB_RoutingFileEntry_t) * BgFilePtr->Buffer.RouteInfo.NumDestinations;
/* Check for EOF (last entry) - NextIndex is nonzero if more records left, zero at the end of the route table */
return (Throttle.NextIndex == 0);
}
void CFE_SB_BackgroundFileEventHandler(void *Meta, CFE_FS_FileWriteEvent_t Event, int32 Status, uint32 RecordNum,
size_t BlockSize, size_t Position)
{
CFE_SB_BackgroundFileStateInfo_t *BgFilePtr;
BgFilePtr = (CFE_SB_BackgroundFileStateInfo_t *)Meta;
/*
* Note that this runs in the context of ES background task (file writer background job)
* It does NOT run in the context of the CFE_TBL app task.
*
* Events should use CFE_EVS_SendEventWithAppID() rather than CFE_EVS_SendEvent()
* to get proper association with TBL task.
*/
switch (Event)
{
case CFE_FS_FileWriteEvent_COMPLETE:
CFE_EVS_SendEventWithAppID(CFE_SB_SND_RTG_EID, CFE_EVS_EventType_DEBUG, CFE_SB_Global.AppId,
"%s written:Size=%d,Entries=%d", BgFilePtr->FileWrite.FileName, (int)Position,
(int)RecordNum);
break;
case CFE_FS_FileWriteEvent_HEADER_WRITE_ERROR:
case CFE_FS_FileWriteEvent_RECORD_WRITE_ERROR:
CFE_EVS_SendEventWithAppID(CFE_SB_FILEWRITE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId,
"File write,byte cnt err,file %s,request=%d,actual=%d",
BgFilePtr->FileWrite.FileName, (int)BlockSize, (int)Status);
break;
case CFE_FS_FileWriteEvent_CREATE_ERROR:
CFE_EVS_SendEventWithAppID(CFE_SB_SND_RTG_ERR1_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId,
"Error creating file %s, stat=0x%x", BgFilePtr->FileWrite.FileName, (int)Status);
break;
default:
/* unhandled event - ignore */
break;
}
}
/******************************************************************************
* \brief SB internal function to handle processing of 'Write Routing Info' Cmd
*
* \param[in] data Pointer to command structure
*
* \return Execution status, see \ref CFEReturnCodes