-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_table.c
1187 lines (1029 loc) · 40.5 KB
/
ds_table.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
/************************************************************************
* NASA Docket No. GSC-18,917-1, and identified as “CFS Data Storage
* (DS) application version 2.6.1”
*
* Copyright (c) 2021 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
* CFS Data Storage (DS) table management functions
*/
#include "cfe.h"
#include "ds_msgids.h"
#include "ds_platform_cfg.h"
#include "ds_verify.h"
#include "ds_appdefs.h"
#include "ds_app.h"
#include "ds_table.h"
#include "ds_msg.h"
#include "ds_events.h"
#define DS_CDS_NAME "DS_CDS"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* DS application table initialization */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 DS_TableInit(void)
{
int32 Result1 = CFE_SUCCESS;
int32 Result2 = CFE_SUCCESS;
bool NeedToLoadDestTable = false;
bool NeedToLoadFilterTable = false;
uint16 TableRegisterFlags = CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_LOAD_DUMP;
#if (DS_MAKE_TABLES_CRITICAL == 1)
TableRegisterFlags |= CFE_TBL_OPT_CRITICAL;
#endif
/*
** If registration fails for either table then the DS app will
** terminate immediately. Without valid table handles, the DS
** app will never be able to load table data.
**
** However, as long as both tables were successfully registered,
** it doesn't matter that one or both table loads fail. The
** DS app can still continue - or at least the DS app can limp
** along until an external influence (ground or RTS) can manage
** to get both tables loaded.
*/
Result1 = CFE_TBL_Register(&DS_AppData.DestFileTblHandle, DS_DESTINATION_TBL_NAME, sizeof(DS_DestFileTable_t),
TableRegisterFlags, (CFE_TBL_CallbackFuncPtr_t)DS_TableVerifyDestFile);
if (Result1 == CFE_TBL_INFO_RECOVERED_TBL)
{
/*
** cFE registered the table and restored the table data
*/
NeedToLoadDestTable = false;
CFE_EVS_SendEvent(DS_INIT_TBL_CDS_EID, CFE_EVS_EventType_DEBUG,
"Destination File Table data restored from CDS");
/*
** This is not an error so clear the result value for later tests
*/
Result1 = CFE_SUCCESS;
}
else if (Result1 == CFE_SUCCESS)
{
/*
** cFE registered the table - we need to load the table data
*/
NeedToLoadDestTable = true;
}
else
{
/*
** cFE did not register the table - we cannot continue
*/
CFE_EVS_SendEvent(DS_INIT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Unable to register Destination File Table: Error = 0x%08X", (unsigned int)Result1);
}
if (Result1 == CFE_SUCCESS)
{
Result1 = CFE_TBL_Register(&DS_AppData.FilterTblHandle, DS_FILTER_TBL_NAME, sizeof(DS_FilterTable_t),
TableRegisterFlags, (CFE_TBL_CallbackFuncPtr_t)DS_TableVerifyFilter);
if (Result1 == CFE_TBL_INFO_RECOVERED_TBL)
{
/*
** cFE registered the table and restored the table data
*/
NeedToLoadFilterTable = false;
CFE_EVS_SendEvent(DS_INIT_TBL_CDS_EID, CFE_EVS_EventType_DEBUG, "Filter Table data restored from CDS");
/*
** This is not an error so clear the result value for later tests
*/
Result1 = CFE_SUCCESS;
}
else if (Result1 == CFE_SUCCESS)
{
/*
** cFE registered the table - we need to load the table data
*/
NeedToLoadFilterTable = true;
}
else
{
/*
** cFE did not register the table - we cannot continue
*/
CFE_EVS_SendEvent(DS_INIT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Unable to register Filter Table: Error = 0x%08X", (unsigned int)Result1);
}
}
/*
** Now load the tables - but only if the registration succeeded
** and the table data has not already been restored from the
** Critical Data Store.
*/
if (Result1 == CFE_SUCCESS)
{
if (NeedToLoadDestTable)
{
Result2 = CFE_TBL_Load(DS_AppData.DestFileTblHandle, CFE_TBL_SRC_FILE, DS_DEF_DEST_FILENAME);
if (Result2 != CFE_SUCCESS)
{
CFE_EVS_SendEvent(DS_INIT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Unable to load default Destination File Table: Filename = '%s', Error = 0x%08X",
DS_DEF_DEST_FILENAME, (unsigned int)Result2);
}
}
if (NeedToLoadFilterTable)
{
Result2 = CFE_TBL_Load(DS_AppData.FilterTblHandle, CFE_TBL_SRC_FILE, DS_DEF_FILTER_FILENAME);
if (Result2 != CFE_SUCCESS)
{
CFE_EVS_SendEvent(DS_INIT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Unable to load default Filter Table: Filename = '%s', Error = 0x%08X",
DS_DEF_FILTER_FILENAME, (unsigned int)Result2);
}
}
/*
** Get initial table data pointers...
*/
DS_TableManageDestFile();
DS_TableManageFilter();
}
return Result1;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Manage table data updates */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void DS_TableManageDestFile(void)
{
int32 i = 0, Result = CFE_SUCCESS;
/*
** Pointer will be NULL until first successful table load...
*/
if (DS_AppData.DestFileTblPtr == (DS_DestFileTable_t *)NULL)
{
/*
** Still waiting for the first table load...
*/
CFE_TBL_ReleaseAddress(DS_AppData.DestFileTblHandle);
CFE_TBL_Manage(DS_AppData.DestFileTblHandle);
Result = CFE_TBL_GetAddress((void *)&DS_AppData.DestFileTblPtr, DS_AppData.DestFileTblHandle);
if (Result == CFE_TBL_INFO_UPDATED)
{
/*
** Got a pointer to initial table data...
*/
DS_AppData.DestTblLoadCounter++;
/*
** Keep local copies of table values that software will modify...
*/
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DS_AppData.FileStatus[i].FileState = DS_AppData.DestFileTblPtr->File[i].EnableState;
DS_AppData.FileStatus[i].FileCount = DS_AppData.DestFileTblPtr->File[i].SequenceCount;
}
/*
** Store local values in the Critical Data Store (CDS)...
*/
DS_TableUpdateCDS();
}
else if (Result == CFE_TBL_ERR_NEVER_LOADED)
{
/*
** Still waiting for the first table load...
*/
DS_AppData.DestTblErrCounter++;
/*
** Make sure we don't try to use the empty table buffer...
*/
DS_AppData.DestFileTblPtr = (DS_DestFileTable_t *)NULL;
}
}
else
{
/*
** Already have initial table data...
*/
Result = CFE_TBL_GetStatus(DS_AppData.DestFileTblHandle);
if (Result == CFE_TBL_INFO_DUMP_PENDING)
{
/*
** Dump the current table data...
*/
CFE_TBL_DumpToBuffer(DS_AppData.DestFileTblHandle);
}
else if (Result == CFE_TBL_INFO_VALIDATION_PENDING)
{
/*
** Validate the pending table data...
*/
CFE_TBL_Validate(DS_AppData.DestFileTblHandle);
}
else if (Result == CFE_TBL_INFO_UPDATE_PENDING)
{
/*
** Update the current table with new data...
*/
DS_AppData.DestTblLoadCounter++;
/*
** Allow cFE to update the table data...
*/
CFE_TBL_ReleaseAddress(DS_AppData.DestFileTblHandle);
CFE_TBL_Update(DS_AppData.DestFileTblHandle);
CFE_TBL_GetAddress((void *)&DS_AppData.DestFileTblPtr, DS_AppData.DestFileTblHandle);
/*
** Keep local copies of table values that software will modify...
*/
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DS_AppData.FileStatus[i].FileState = DS_AppData.DestFileTblPtr->File[i].EnableState;
DS_AppData.FileStatus[i].FileCount = DS_AppData.DestFileTblPtr->File[i].SequenceCount;
}
/*
** Store local values in the Critical Data Store (CDS)...
*/
DS_TableUpdateCDS();
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Manage table data updates */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void DS_TableManageFilter(void)
{
int32 Result = CFE_SUCCESS;
/*
** Pointer will be NULL until first successful filter table load...
*/
if (DS_AppData.FilterTblPtr == (DS_FilterTable_t *)NULL)
{
/*
** Still waiting for the first filter table load...
*/
CFE_TBL_ReleaseAddress(DS_AppData.FilterTblHandle);
CFE_TBL_Manage(DS_AppData.FilterTblHandle);
Result = CFE_TBL_GetAddress((void *)&DS_AppData.FilterTblPtr, DS_AppData.FilterTblHandle);
if (Result == CFE_TBL_INFO_UPDATED)
{
/*
** Got a pointer to initial filter table data...
*/
DS_AppData.FilterTblLoadCounter++;
/*
** Subscribe to the packets in the new filter table...
*/
DS_TableSubscribe();
/*
** Create hash table for messageID's in new filter table...
*/
DS_TableCreateHash();
}
else if (Result == CFE_TBL_ERR_NEVER_LOADED)
{
/*
** Still waiting for the first filter table load...
*/
DS_AppData.FilterTblErrCounter++;
/*
** Make sure we don't try to use the empty table buffer...
*/
DS_AppData.FilterTblPtr = (DS_FilterTable_t *)NULL;
}
}
else
{
/*
** Already have initial filter table data...
*/
Result = CFE_TBL_GetStatus(DS_AppData.FilterTblHandle);
if (Result == CFE_TBL_INFO_DUMP_PENDING)
{
/*
** Dump the current filter table data...
*/
CFE_TBL_DumpToBuffer(DS_AppData.FilterTblHandle);
}
else if (Result == CFE_TBL_INFO_VALIDATION_PENDING)
{
/*
** Validate the pending filter table data...
*/
CFE_TBL_Validate(DS_AppData.FilterTblHandle);
}
else if (Result == CFE_TBL_INFO_UPDATE_PENDING)
{
/*
** Update the current filter table with new data...
*/
DS_AppData.FilterTblLoadCounter++;
/*
** Un-subscribe to the packets in the old filter table...
*/
DS_TableUnsubscribe();
/*
** Allow cFE to update the filter table data...
*/
CFE_TBL_ReleaseAddress(DS_AppData.FilterTblHandle);
CFE_TBL_Update(DS_AppData.FilterTblHandle);
CFE_TBL_GetAddress((void *)&DS_AppData.FilterTblPtr, DS_AppData.FilterTblHandle);
/*
** Subscribe to the packets in the new filter table...
*/
DS_TableSubscribe();
/*
** Create hash table for messageID's in new filter table...
*/
DS_TableCreateHash();
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Validate table data */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 DS_TableVerifyDestFile(const void *TableData)
{
DS_DestFileTable_t *DestFileTable = (DS_DestFileTable_t *)TableData;
const char * DescResult = "OK";
int32 Result = CFE_SUCCESS;
int32 i = 0;
int32 CountGood = 0;
int32 CountBad = 0;
int32 CountUnused = 0;
/*
** Each entry in table will be unused, good or bad
*/
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
if (DS_TableEntryUnused(&DestFileTable->File[i], sizeof(DS_DestFileEntry_t)) == true)
{
CountUnused++;
}
else if (DS_TableVerifyDestFileEntry(&DestFileTable->File[i], (uint8)i, CountBad) == true)
{
CountGood++;
}
else
{
CountBad++;
Result = DS_TABLE_VERIFY_ERR;
}
}
/*
** Note that totals include each table entry plus the descriptor
*/
CFE_EVS_SendEvent(DS_FIL_TBL_EID, CFE_EVS_EventType_INFORMATION,
"Destination file table verify results: desc text = %s, good entries = %d, bad = %d, unused = %d",
DescResult, (int)CountGood, (int)CountBad, (int)CountUnused);
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify dest table entry */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyDestFileEntry(DS_DestFileEntry_t *DestFileEntry, uint8 TableIndex, int32 ErrorCount)
{
const char *CommonErrorText = "Destination file table verify err:";
bool Result = true;
/*
** Perform the following "per table entry" validation:
**
** FileNameType = DS_BY_COUNT or DS_BY_TIME
** EnableState = DS_ENABLED or DS_DISABLED
**
** MaxFileSize = cannot be less than DS_FILE_MIN_SIZE_LIMIT
** MaxFileAge = cannot be less than DS_FILE_MIN_AGE_LIMIT
** SequenceCount = may be zero, cannot exceed DS_MAX_SEQUENCE_COUNT
*/
if (DS_TableVerifyType(DestFileEntry->FileNameType) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FIL_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "%s index = %d, filename type = %d",
CommonErrorText, TableIndex, DestFileEntry->FileNameType);
}
Result = false;
}
else if (DS_TableVerifyState(DestFileEntry->EnableState) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FIL_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "%s index = %d, file enable state = %d",
CommonErrorText, TableIndex, DestFileEntry->EnableState);
}
Result = false;
}
else if (DS_TableVerifySize(DestFileEntry->MaxFileSize) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FIL_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "%s index = %d, max file size = %d",
CommonErrorText, (int)TableIndex, (int)DestFileEntry->MaxFileSize);
}
Result = false;
}
else if (DS_TableVerifyAge(DestFileEntry->MaxFileAge) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FIL_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "%s index = %d, max file age = %d",
CommonErrorText, (int)TableIndex, (int)DestFileEntry->MaxFileAge);
}
Result = false;
}
else if (DS_TableVerifyCount(DestFileEntry->SequenceCount) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FIL_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "%s index = %d, sequence count = %d",
CommonErrorText, (int)TableIndex, (int)DestFileEntry->SequenceCount);
}
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Validate table data */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 DS_TableVerifyFilter(const void *TableData)
{
DS_FilterTable_t *FilterTable = (DS_FilterTable_t *)TableData;
const char * DescResult = "OK";
int32 Result = CFE_SUCCESS;
int32 i = 0;
int32 CountGood = 0;
int32 CountBad = 0;
int32 CountUnused = 0;
/*
** Perform the following validation:
**
** MessageID = unlimited, zero means unused
*/
/*
** Each entry in table will be unused, good or bad
*/
for (i = 0; i < DS_PACKETS_IN_FILTER_TABLE; i++)
{
if (!CFE_SB_IsValidMsgId(FilterTable->Packet[i].MessageID))
{
CountUnused++;
}
else if (DS_TableVerifyFilterEntry(&FilterTable->Packet[i], (uint8)i, CountBad) == true)
{
CountGood++;
}
else
{
CountBad++;
Result = DS_TABLE_VERIFY_ERR;
}
}
/*
** Note that totals include each table entry plus the descriptor
*/
CFE_EVS_SendEvent(DS_FLT_TBL_EID, CFE_EVS_EventType_INFORMATION,
"Filter table verify results: desc text = %s, good entries = %d, bad = %d, unused = %d",
DescResult, (int)CountGood, (int)CountBad, (int)CountUnused);
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify filter table entry */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyFilterEntry(DS_PacketEntry_t *PacketEntry, int32 TableIndex, int32 ErrorCount)
{
const char * CommonErrorText = "Filter table verify err:";
DS_FilterParms_t *FilterParms;
bool Result = true;
int32 i = 0;
/*
** Each packet filter table entry has multiple filters per packet
**
** Perform the following validation (per filter):
**
** FileTableIndex = must be less than DS_DEST_FILE_CNT
** FilterType = must be DS_BY_COUNT or DS_BY_TIME
**
** Algorithm_N = cannot exceed Algorithm_X, zero means filter ALL
** Algorithm_X = unlimited
** Algorithm_O = must be less than Algorithm_X
**
** Note: unused filters (all zero's) are valid
*/
for (i = 0; (i < DS_FILTERS_PER_PACKET) && (Result == true); i++)
{
FilterParms = &PacketEntry->Filter[i];
if (DS_TableEntryUnused(FilterParms, sizeof(DS_FilterParms_t)) == false)
{
/*
** If any filter field is non-zero then all filter fields must be valid
*/
if (DS_TableVerifyFileIndex((uint32)FilterParms->FileTableIndex) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FLT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"%s MID = 0x%08lX, index = %d, filter = %d, file table index = %d",
CommonErrorText, (unsigned long)CFE_SB_MsgIdToValue(PacketEntry->MessageID),
(int)TableIndex, (int)i, FilterParms->FileTableIndex);
}
Result = false;
}
else if (DS_TableVerifyType((uint16)FilterParms->FilterType) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FLT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"%s MID = 0x%08lX, index = %d, filter = %d, filter type = %d", CommonErrorText,
(unsigned long)CFE_SB_MsgIdToValue(PacketEntry->MessageID), (int)TableIndex,
(int)i, FilterParms->FilterType);
}
Result = false;
}
else if (DS_TableVerifyParms(FilterParms->Algorithm_N, FilterParms->Algorithm_X,
FilterParms->Algorithm_O) == false)
{
if (ErrorCount == 0)
{
CFE_EVS_SendEvent(DS_FLT_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"%s MID = 0x%08lX, index = %d, filter = %d, filter parms N = %d, X = %d, O = %d",
CommonErrorText, (unsigned long)CFE_SB_MsgIdToValue(PacketEntry->MessageID),
(int)TableIndex, (int)i, FilterParms->Algorithm_N, FilterParms->Algorithm_X,
FilterParms->Algorithm_O);
}
Result = false;
}
}
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Find unused table entries */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableEntryUnused(const void *TableEntry, int32 BufferSize)
{
const char *Buffer = (char *)TableEntry;
bool Result = true;
int32 i = 0;
for (i = 0; i < BufferSize; i++)
{
if (Buffer[i] != DS_UNUSED)
{
Result = false;
break;
}
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify dest file index */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyFileIndex(uint16 FileTableIndex)
{
bool Result = true;
if (FileTableIndex >= DS_DEST_FILE_CNT)
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify algorithm parameters */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyParms(uint16 Algorithm_N, uint16 Algorithm_X, uint16 Algorithm_O)
{
bool Result = true;
/*
** Unused entries (all zero's) are valid
*/
if ((Algorithm_N != 0) || (Algorithm_X != 0) || (Algorithm_O != 0))
{
if (Algorithm_N > Algorithm_X)
{
/*
** "pass this many" cannot exceed "out of this many"
*/
Result = false;
}
else if (Algorithm_O >= Algorithm_X)
{
/*
** "at this offset" must be less than "out of this many"
*/
Result = false;
}
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify filter or filename type */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyType(uint16 TimeVsCount)
{
bool Result = true;
if ((TimeVsCount != DS_BY_COUNT) && (TimeVsCount != DS_BY_TIME))
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify file ena/dis state */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyState(uint16 EnableState)
{
bool Result = true;
if ((EnableState != DS_ENABLED) && (EnableState != DS_DISABLED))
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify file size limit */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifySize(uint32 MaxFileSize)
{
bool Result = true;
if (MaxFileSize < DS_FILE_MIN_SIZE_LIMIT)
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify file age limit */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyAge(uint32 MaxFileAge)
{
bool Result = true;
if (MaxFileAge < DS_FILE_MIN_AGE_LIMIT)
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify sequence count */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool DS_TableVerifyCount(uint32 SequenceCount)
{
bool Result = true;
if (SequenceCount > DS_MAX_SEQUENCE_COUNT)
{
Result = false;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process new filter table */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void DS_TableSubscribe(void)
{
DS_PacketEntry_t *FilterPackets = NULL;
CFE_SB_MsgId_t MessageID;
int32 i;
FilterPackets = DS_AppData.FilterTblPtr->Packet;
/*
** Check each entry in "new" packet filter table...
*/
for (i = 0; i < DS_PACKETS_IN_FILTER_TABLE; i++)
{
MessageID = FilterPackets[i].MessageID;
/*
** Already subscribe to DS command packets...
*/
if (CFE_SB_IsValidMsgId(MessageID) && (CFE_SB_MsgIdToValue(MessageID) != DS_CMD_MID) &&
(CFE_SB_MsgIdToValue(MessageID) != DS_SEND_HK_MID))
{
CFE_SB_SubscribeEx(MessageID, DS_AppData.InputPipe, CFE_SB_DEFAULT_QOS, DS_PER_PACKET_PIPE_LIMIT);
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process old filter table */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void DS_TableUnsubscribe(void)
{
DS_PacketEntry_t *FilterPackets = NULL;
CFE_SB_MsgId_t MessageID;
int32 i;
FilterPackets = DS_AppData.FilterTblPtr->Packet;
/*
** Check each entry in "old" packet filter table...
*/
for (i = 0; i < DS_PACKETS_IN_FILTER_TABLE; i++)
{
MessageID = FilterPackets[i].MessageID;
/*
** Do not un-subscribe to unused or DS command packets...
*/
if (CFE_SB_IsValidMsgId(MessageID) && (CFE_SB_MsgIdToValue(MessageID) != DS_CMD_MID) &&
(CFE_SB_MsgIdToValue(MessageID) != DS_SEND_HK_MID))
{
CFE_SB_Unsubscribe(MessageID, DS_AppData.InputPipe);
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Create DS storage area in CDS */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 DS_TableCreateCDS(void)
{
/* Store file sequence counts and task ena/dis state in CDS */
uint32 DataStoreBuffer[DS_DEST_FILE_CNT + 1] = {0};
int32 Result = CFE_SUCCESS;
int32 i = 0;
/*
** Request for CDS area from cFE Executive Services...
*/
Result = CFE_ES_RegisterCDS(&DS_AppData.DataStoreHandle, sizeof(DataStoreBuffer), DS_CDS_NAME);
if (Result == CFE_SUCCESS)
{
/*
** New CDS area - write to Critical Data Store...
*/
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DataStoreBuffer[i] = DS_AppData.FileStatus[i].FileCount;
}
DataStoreBuffer[DS_DEST_FILE_CNT] = DS_AppData.AppEnableState;
Result = CFE_ES_CopyToCDS(DS_AppData.DataStoreHandle, DataStoreBuffer);
}
else if (Result == CFE_ES_CDS_ALREADY_EXISTS)
{
/*
** Pre-existing CDS area - read from Critical Data Store...
*/
Result = CFE_ES_RestoreFromCDS(DataStoreBuffer, DS_AppData.DataStoreHandle);
if (Result == CFE_SUCCESS)
{
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DS_AppData.FileStatus[i].FileCount = DataStoreBuffer[i];
}
#if (DS_CDS_ENABLE_STATE == 1)
/* Only restore enable/disable state if configured */
DS_AppData.AppEnableState = (uint8)DataStoreBuffer[DS_DEST_FILE_CNT];
#endif
}
}
if (Result != CFE_SUCCESS)
{
/*
** CDS is broken - prevent further errors...
*/
DS_AppData.DataStoreHandle = CFE_ES_CDS_BAD_HANDLE;
CFE_EVS_SendEvent(DS_INIT_CDS_ERR_EID, CFE_EVS_EventType_ERROR, "Critical Data Store access error = 0x%08X",
(unsigned int)Result);
/*
** CDS errors are not fatal - DS can still run...
*/
Result = CFE_SUCCESS;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Update DS storage area in CDS */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void DS_TableUpdateCDS(void)
{
/* Store file sequence counts and task ena/dis state in CDS */
uint32 DataStoreBuffer[DS_DEST_FILE_CNT + 1] = {0};
int32 Result = CFE_SUCCESS;
int32 i = 0;
/*
** Handle is non-zero when CDS is active...
*/
if (!CFE_RESOURCEID_TEST_EQUAL(DS_AppData.DataStoreHandle, CFE_ES_CDS_BAD_HANDLE))
{
/*
** Copy file sequence counts values to the data array...
*/
for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DataStoreBuffer[i] = DS_AppData.FileStatus[i].FileCount;
}
/*
** Always save the DS enable/disable state in the CDS...
** (DS_CDS_ENABLE_STATE controls restoring the state)
*/
DataStoreBuffer[DS_DEST_FILE_CNT] = DS_AppData.AppEnableState;
/*
** Update DS portion of Critical Data Store...
*/
Result = CFE_ES_CopyToCDS(DS_AppData.DataStoreHandle, DataStoreBuffer);
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(DS_INIT_CDS_ERR_EID, CFE_EVS_EventType_ERROR, "Critical Data Store access error = 0x%08X",
(unsigned int)Result);
/*
** CDS is broken - prevent further errors...
*/
DS_AppData.DataStoreHandle = CFE_ES_CDS_BAD_HANDLE;
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Convert messageID to hash table index */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint32 DS_TableHashFunction(CFE_SB_MsgId_t MessageID)
{
/*
** The purpose of a hash function is to take the input value
** and convert it to an index into the hash table. Assume that
** the range of input values is much different (larger) than
** the number of entries in the hash table. Then multiple input
** values must resolve to the same output table index. This is ok