Branch data Line data Source code
1 : : /************************************************************************
2 : : * NASA Docket No. GSC-18,919-1, and identified as “Core Flight
3 : : * System (cFS) Housekeeping (HK) Application version 2.5.1”
4 : : *
5 : : * Copyright (c) 2021 United States Government as represented by the
6 : : * Administrator of the National Aeronautics and Space Administration.
7 : : * All Rights Reserved.
8 : : *
9 : : * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 : : * not use this file except in compliance with the License. You may obtain
11 : : * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
12 : : *
13 : : * Unless required by applicable law or agreed to in writing, software
14 : : * distributed under the License is distributed on an "AS IS" BASIS,
15 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : : * See the License for the specific language governing permissions and
17 : : * limitations under the License.
18 : : ************************************************************************/
19 : :
20 : : /**
21 : : * @file
22 : : * The CFS Housekeeping (HK) Application file containing the functions
23 : : * used combine the input messages into output messages.
24 : : */
25 : :
26 : : /************************************************************************
27 : : ** Includes
28 : : *************************************************************************/
29 : :
30 : : #include "cfe.h"
31 : : #include "hk_utils.h"
32 : : #include "hk_app.h"
33 : : #include "hk_events.h"
34 : : #include <string.h>
35 : :
36 : : /*************************************************************************
37 : : ** Function definitions
38 : : **************************************************************************/
39 : :
40 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 : : /* */
42 : : /* HK process incoming housekeeping data */
43 : : /* */
44 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 : 4 : void HK_ProcessIncomingHkData(const CFE_SB_Buffer_t *BufPtr)
46 : : {
47 : 4 : hk_copy_table_entry_t * StartOfCopyTable = HK_AppData.CopyTablePtr;
48 : 4 : hk_copy_table_entry_t * CpyTblEntry = NULL;
49 : 4 : hk_runtime_tbl_entry_t *StartOfRtTable = HK_AppData.RuntimeTablePtr;
50 : 4 : hk_runtime_tbl_entry_t *RtTblEntry = NULL;
51 : 4 : uint16 Loop = 0;
52 : 4 : CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
53 : 4 : uint8 * DestPtr = NULL;
54 : 4 : uint8 * SrcPtr = NULL;
55 : 4 : size_t MessageLength = 0;
56 : 4 : int32 MessageErrors = 0;
57 : : int32 LastByteAccessed;
58 : :
59 : 4 : CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID);
60 : :
61 : : /* Spin thru the entire table looking for matches */
62 [ + + ]: 516 : for (Loop = 0; Loop < HK_COPY_TABLE_ENTRIES; Loop++)
63 : : {
64 : 512 : CpyTblEntry = &StartOfCopyTable[Loop];
65 : 512 : RtTblEntry = &StartOfRtTable[Loop];
66 : :
67 : : /* Does the inputMID for this table entry match what we're looking for */
68 [ + + ]: 512 : if (CFE_SB_MsgId_Equal(MessageID, CpyTblEntry->InputMid))
69 : : {
70 : : /* Ensure that we don't reference past the end of the input packet */
71 : 3 : CFE_MSG_GetSize(&BufPtr->Msg, &MessageLength);
72 : 3 : LastByteAccessed = CpyTblEntry->InputOffset + CpyTblEntry->NumBytes;
73 [ + + ]: 3 : if (MessageLength >= LastByteAccessed)
74 : : {
75 : : /* We have a match. Build the Source and Destination addresses
76 : : and move the data */
77 : 2 : DestPtr = ((uint8 *)RtTblEntry->OutputPktAddr) + CpyTblEntry->OutputOffset;
78 : 2 : SrcPtr = ((uint8 *)BufPtr) + CpyTblEntry->InputOffset;
79 : :
80 : 2 : memcpy(DestPtr, SrcPtr, CpyTblEntry->NumBytes);
81 : :
82 : : /* Set the data present field to indicate the data is there */
83 : 2 : RtTblEntry->DataPresent = HK_DATA_PRESENT;
84 : : }
85 : : else
86 : : {
87 : : /* Error: copy data is past the end of the input packet */
88 : 1 : MessageErrors++;
89 : : }
90 : : }
91 : : }
92 : :
93 : : /* Send, at most, one error event per input packet */
94 [ + + ]: 4 : if (MessageErrors != 0)
95 : : {
96 : 1 : CFE_EVS_SendEvent(HK_ACCESSING_PAST_PACKET_END_EID, CFE_EVS_EventType_ERROR,
97 : : "HK table definition exceeds packet length. MID:0x%08lX, Length:%d, Count:%d",
98 : 1 : (unsigned long)CFE_SB_MsgIdToValue(MessageID), (int)MessageLength, (int)MessageErrors);
99 : : }
100 : 4 : }
101 : :
102 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
103 : : /* */
104 : : /* HK validate the copy table contents */
105 : : /* */
106 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
107 : 1 : int32 HK_ValidateHkCopyTable(void *TblPtr)
108 : : {
109 : 1 : return HK_SUCCESS;
110 : : }
111 : :
112 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
113 : : /* */
114 : : /* HK process new copy table */
115 : : /* */
116 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
117 : 11 : CFE_Status_t HK_ProcessNewCopyTable(hk_copy_table_entry_t *CpyTblPtr, hk_runtime_tbl_entry_t *RtTblPtr)
118 : : {
119 : 11 : hk_copy_table_entry_t * StartOfCopyTable = NULL;
120 : 11 : hk_copy_table_entry_t * OuterCpyEntry = NULL;
121 : 11 : hk_copy_table_entry_t * InnerDefEntry = NULL;
122 : 11 : hk_runtime_tbl_entry_t *StartOfRtTable = NULL;
123 : 11 : hk_runtime_tbl_entry_t *OuterRtEntry = NULL;
124 : 11 : hk_runtime_tbl_entry_t *InnerRtEntry = NULL;
125 : 11 : int32 Loop1 = 0;
126 : : int32 Loop2;
127 : : CFE_SB_MsgId_t MidOfThisPacket;
128 : : int32 SizeOfThisPacket;
129 : : int32 FurthestByteFromThisEntry;
130 : : CFE_SB_Buffer_t * NewPacketAddr;
131 : : CFE_Status_t Result;
132 : :
133 : : /* Ensure that the input arguments are valid */
134 [ + + + + ]: 11 : if (((void *)CpyTblPtr == NULL) || ((void *)RtTblPtr == NULL))
135 : : {
136 : 3 : CFE_EVS_SendEvent(HK_NULL_POINTER_NEWCPY_ERR_EID, CFE_EVS_EventType_ERROR,
137 : : "Null pointer detected in new copy tbl processing: CpyTbl = %p, RtTbl = %p",
138 : : (void *)CpyTblPtr, (void *)RtTblPtr);
139 : 3 : return HK_NULL_POINTER_DETECTED;
140 : : }
141 : :
142 : 8 : StartOfCopyTable = CpyTblPtr;
143 : 8 : StartOfRtTable = RtTblPtr;
144 : :
145 : : /* Loop thru the RunTime table initializing the fields */
146 [ + + ]: 1032 : for (Loop1 = 0; Loop1 < HK_COPY_TABLE_ENTRIES; Loop1++)
147 : : {
148 : 1024 : OuterRtEntry = &StartOfRtTable[Loop1];
149 : :
150 : 1024 : OuterRtEntry->OutputPktAddr = NULL;
151 : 1024 : OuterRtEntry->InputMidSubscribed = HK_INPUTMID_NOT_SUBSCRIBED;
152 : 1024 : OuterRtEntry->DataPresent = HK_DATA_NOT_PRESENT;
153 : : }
154 : :
155 : : /* Loop thru the table looking for all of the SB packets that need to be built */
156 [ + + ]: 1032 : for (Loop1 = 0; Loop1 < HK_COPY_TABLE_ENTRIES; Loop1++)
157 : : {
158 : 1024 : OuterCpyEntry = &StartOfCopyTable[Loop1];
159 : 1024 : OuterRtEntry = &StartOfRtTable[Loop1];
160 : :
161 : : /* If the both MIDs exists but the Packet Address has yet to be assigned,
162 : : we need to build an SB packet, so compute the size */
163 [ + + + + ]: 1024 : if (CFE_SB_IsValidMsgId(OuterCpyEntry->OutputMid) && CFE_SB_IsValidMsgId(OuterCpyEntry->InputMid) &&
164 [ + + ]: 34 : (OuterRtEntry->OutputPktAddr == NULL))
165 : : {
166 : : /* We have a table entry that needs a SB message to be built */
167 : 15 : MidOfThisPacket = OuterCpyEntry->OutputMid;
168 : 15 : SizeOfThisPacket = 0;
169 : :
170 : : /* Spin thru entire table looking for duplicate OutputMid's. This will let
171 : : us find the byte offset furthest from the beginning of the packet */
172 [ + + ]: 1935 : for (Loop2 = 0; Loop2 < HK_COPY_TABLE_ENTRIES; Loop2++)
173 : : {
174 : 1920 : InnerDefEntry = &StartOfCopyTable[Loop2];
175 : :
176 : : /* If this entry's MID matches the one we're looking for */
177 [ + + ]: 1920 : if (CFE_SB_MsgId_Equal(InnerDefEntry->OutputMid, MidOfThisPacket))
178 : : {
179 : : /* The byte furthest away from the section described by this entry */
180 : 75 : FurthestByteFromThisEntry = InnerDefEntry->OutputOffset + InnerDefEntry->NumBytes;
181 : :
182 : : /* Save the byte offset of the byte furthest from the packet start */
183 [ + + ]: 75 : if (FurthestByteFromThisEntry > SizeOfThisPacket)
184 : : {
185 : 49 : SizeOfThisPacket = FurthestByteFromThisEntry;
186 : : }
187 : : }
188 : : }
189 : :
190 : : /* Build the packet with the size computed above */
191 : 15 : NewPacketAddr = NULL;
192 [ + + ]: 15 : if (SizeOfThisPacket > 0)
193 : : {
194 : 10 : Result = CFE_ES_GetPoolBuf((void **)&NewPacketAddr, HK_AppData.MemPoolHandle, SizeOfThisPacket);
195 : :
196 [ + + ]: 10 : if (Result >= CFE_SUCCESS)
197 : : {
198 : : /* Spin thru entire table (again) looking for duplicate OutputMid's.
199 : : This will let us assign the packet created above to all
200 : : of the table entries that need to use it */
201 [ + + ]: 645 : for (Loop2 = 0; Loop2 < HK_COPY_TABLE_ENTRIES; Loop2++)
202 : : {
203 : 640 : InnerDefEntry = &StartOfCopyTable[Loop2];
204 : 640 : InnerRtEntry = &StartOfRtTable[Loop2];
205 : :
206 : : /* If this entry's MID matches the one we're looking for */
207 [ + + ]: 640 : if (CFE_SB_MsgId_Equal(InnerDefEntry->OutputMid, MidOfThisPacket))
208 : : {
209 : 25 : InnerRtEntry->OutputPktAddr = NewPacketAddr;
210 : : }
211 : : }
212 : :
213 : : /* Init the SB Packet only once regardless of how many times its in the table */
214 : 5 : CFE_MSG_Init(&NewPacketAddr->Msg, MidOfThisPacket, SizeOfThisPacket);
215 : : }
216 : : else
217 : : {
218 : 5 : CFE_EVS_SendEvent(HK_MEM_POOL_MALLOC_FAILED_EID, CFE_EVS_EventType_ERROR,
219 : : "HK Processing New Table: ES_GetPoolBuf for size %d returned 0x%04X",
220 : : (int)SizeOfThisPacket, (unsigned int)Result);
221 : : }
222 : : }
223 : : }
224 : :
225 : : /* If HK needs to subscribe to this Input packet... */
226 [ + + + + ]: 2042 : if ((OuterRtEntry->InputMidSubscribed == HK_INPUTMID_NOT_SUBSCRIBED) &&
227 : 1018 : CFE_SB_IsValidMsgId(OuterCpyEntry->InputMid))
228 : : {
229 : 28 : Result = CFE_SB_Subscribe(OuterCpyEntry->InputMid, HK_AppData.CmdPipe);
230 : :
231 [ + + ]: 28 : if (Result == CFE_SUCCESS)
232 : : {
233 : : /* Spin thru entire table (again) looking for duplicate InputMid's.
234 : : This will let us mark each duplicate as already having been subscribed */
235 [ + + ]: 2967 : for (Loop2 = 0; Loop2 < HK_COPY_TABLE_ENTRIES; Loop2++)
236 : : {
237 : 2944 : InnerDefEntry = &StartOfCopyTable[Loop2];
238 : 2944 : InnerRtEntry = &StartOfRtTable[Loop2];
239 : :
240 : : /* If this entry's MID matches the one we're looking for */
241 [ + + ]: 2944 : if (CFE_SB_MsgId_Equal(OuterCpyEntry->InputMid, InnerDefEntry->InputMid))
242 : : {
243 : 29 : InnerRtEntry->InputMidSubscribed = HK_INPUTMID_SUBSCRIBED;
244 : : }
245 : : }
246 : : }
247 : : else
248 : : {
249 : 5 : CFE_EVS_SendEvent(HK_CANT_SUBSCRIBE_TO_SB_PKT_EID, CFE_EVS_EventType_ERROR,
250 : : "HK Processing New Table:SB_Subscribe for Mid 0x%08lX returned 0x%04X",
251 : 5 : (unsigned long)CFE_SB_MsgIdToValue(OuterCpyEntry->InputMid), (unsigned int)Result);
252 : : }
253 : : }
254 : : }
255 : :
256 : 8 : return CFE_SUCCESS;
257 : : }
258 : :
259 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
260 : : /* */
261 : : /* HK Tear down old copy table */
262 : : /* */
263 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
264 : 11 : CFE_Status_t HK_TearDownOldCopyTable(hk_copy_table_entry_t *CpyTblPtr, hk_runtime_tbl_entry_t *RtTblPtr)
265 : : {
266 : 11 : hk_copy_table_entry_t * StartOfCopyTable = NULL;
267 : 11 : hk_copy_table_entry_t * OuterCpyEntry = NULL;
268 : 11 : hk_copy_table_entry_t * InnerDefEntry = NULL;
269 : 11 : hk_runtime_tbl_entry_t *StartOfRtTable = NULL;
270 : 11 : hk_runtime_tbl_entry_t *OuterRtEntry = NULL;
271 : 11 : hk_runtime_tbl_entry_t *InnerRtEntry = NULL;
272 : 11 : int32 Loop1 = 0;
273 : : int32 Loop2;
274 : : CFE_SB_MsgId_t MidOfThisPacket;
275 : 11 : void * OutputPktAddr = NULL;
276 : 11 : void * SavedPktAddr = NULL;
277 : : CFE_Status_t Result;
278 : :
279 : : /* Ensure that the input arguments are valid */
280 [ + + + + ]: 11 : if (((void *)CpyTblPtr == NULL) || ((void *)RtTblPtr == NULL))
281 : : {
282 : 6 : CFE_EVS_SendEvent(HK_NULL_POINTER_TEARCPY_ERR_EID, CFE_EVS_EventType_ERROR,
283 : : "Null pointer detected in copy tbl tear down: CpyTbl = %p, RtTbl = %p", (void *)CpyTblPtr,
284 : : (void *)RtTblPtr);
285 : 6 : return HK_NULL_POINTER_DETECTED;
286 : : }
287 : :
288 : 5 : StartOfCopyTable = CpyTblPtr;
289 : 5 : StartOfRtTable = RtTblPtr;
290 : :
291 : : /* Loop thru the table looking for all of the SB packets that need to be freed */
292 [ + + ]: 645 : for (Loop1 = 0; Loop1 < HK_COPY_TABLE_ENTRIES; Loop1++)
293 : : {
294 : 640 : OuterCpyEntry = &StartOfCopyTable[Loop1];
295 : 640 : OuterRtEntry = &StartOfRtTable[Loop1];
296 : :
297 : : /* If a Packet Address has been assigned, it needs to get deleted */
298 [ + + ]: 640 : if (OuterRtEntry->OutputPktAddr != NULL)
299 : : {
300 : 9 : OutputPktAddr = OuterRtEntry->OutputPktAddr;
301 : 9 : MidOfThisPacket = OuterCpyEntry->OutputMid;
302 : :
303 : 9 : SavedPktAddr = OutputPktAddr;
304 : 9 : Result = CFE_ES_PutPoolBuf(HK_AppData.MemPoolHandle, (uint32 *)OutputPktAddr);
305 [ + + ]: 9 : if (Result >= CFE_SUCCESS)
306 : : {
307 : : /* Spin thru the entire table looking for entries that used the same SB packets */
308 [ + + ]: 516 : for (Loop2 = 0; Loop2 < HK_COPY_TABLE_ENTRIES; Loop2++)
309 : : {
310 : 512 : InnerDefEntry = &StartOfCopyTable[Loop2];
311 : 512 : InnerRtEntry = &StartOfRtTable[Loop2];
312 : :
313 [ + + ]: 512 : if (CFE_SB_MsgId_Equal(InnerDefEntry->OutputMid, MidOfThisPacket) &&
314 [ + + ]: 20 : (InnerRtEntry->OutputPktAddr == SavedPktAddr))
315 : : {
316 : : /* NULL out the table entry whose packet was freed above */
317 : 15 : InnerRtEntry->OutputPktAddr = (CFE_SB_Buffer_t *)NULL;
318 : : }
319 : : }
320 : : }
321 : : else
322 : : {
323 : 5 : CFE_EVS_SendEvent(HK_MEM_POOL_FREE_FAILED_EID, CFE_EVS_EventType_ERROR,
324 : : "HK TearDown: ES_putPoolBuf Err pkt:0x%08lX ret 0x%04X, hdl 0x%08lx",
325 : : (unsigned long)SavedPktAddr, (unsigned int)Result,
326 : : CFE_RESOURCEID_TO_ULONG(HK_AppData.MemPoolHandle));
327 : : }
328 : : }
329 : :
330 : : /* If the InputMid for this Table Entry has been subscribed, it needs to
331 : : get Unsubscribed as do any other identical InputMids throughout the table.
332 : : We don't have to worry about leaving any Mid's subscribed since the entire table
333 : : is getting clobbered. */
334 [ + + ]: 640 : if (OuterRtEntry->InputMidSubscribed == HK_INPUTMID_SUBSCRIBED)
335 : : {
336 : 16 : CFE_SB_Unsubscribe(OuterCpyEntry->InputMid, HK_AppData.CmdPipe);
337 : :
338 : : /* Spin thru the entire table looking for entries that used the same SB packets */
339 [ + + ]: 2064 : for (Loop2 = 0; Loop2 < HK_COPY_TABLE_ENTRIES; Loop2++)
340 : : {
341 : 2048 : InnerDefEntry = &StartOfCopyTable[Loop2];
342 : 2048 : InnerRtEntry = &StartOfRtTable[Loop2];
343 : :
344 [ + + ]: 2048 : if (CFE_SB_MsgId_Equal(InnerDefEntry->InputMid, OuterCpyEntry->InputMid))
345 : : {
346 : 20 : InnerRtEntry->InputMidSubscribed = HK_INPUTMID_NOT_SUBSCRIBED;
347 : : }
348 : : }
349 : : }
350 : : }
351 : :
352 : 5 : return CFE_SUCCESS;
353 : : }
354 : :
355 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
356 : : /* */
357 : : /* HK Send combined output message */
358 : : /* */
359 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
360 : 4 : void HK_SendCombinedHkPacket(CFE_SB_MsgId_t WhichMidToSend)
361 : : {
362 : 4 : bool PacketFound = false;
363 : 4 : hk_runtime_tbl_entry_t *StartOfRtTable = HK_AppData.RuntimeTablePtr;
364 : 4 : hk_runtime_tbl_entry_t *RtTblEntry = NULL;
365 : 4 : int32 Loop = 0;
366 : 4 : CFE_SB_MsgId_t ThisEntrysOutMid = CFE_SB_INVALID_MSG_ID;
367 : 4 : CFE_SB_MsgId_t InputMidMissing = CFE_SB_INVALID_MSG_ID;
368 : 4 : CFE_SB_Buffer_t * OutBuffer = NULL;
369 : :
370 : : /* Look thru each item in this Table, but only send this packet once, at most */
371 [ + + + + ]: 262 : for (Loop = 0; ((Loop < HK_COPY_TABLE_ENTRIES) && (PacketFound == false)); Loop++)
372 : : {
373 : 258 : RtTblEntry = &StartOfRtTable[Loop];
374 : :
375 : : /* Empty table entries are defined by NULL's in this field */
376 [ + + ]: 258 : if (RtTblEntry->OutputPktAddr != NULL)
377 : : {
378 : 3 : OutBuffer = (CFE_SB_Buffer_t *)RtTblEntry->OutputPktAddr;
379 : 3 : CFE_MSG_GetMsgId(&OutBuffer->Msg, &ThisEntrysOutMid);
380 : :
381 [ + + ]: 3 : if (CFE_SB_MsgId_Equal(ThisEntrysOutMid, WhichMidToSend))
382 : : {
383 [ + + ]: 2 : if (HK_CheckForMissingData(ThisEntrysOutMid, &InputMidMissing) == HK_MISSING_DATA_DETECTED)
384 : : {
385 : 1 : HK_AppData.MissingDataCtr++;
386 : :
387 : 1 : CFE_EVS_SendEvent(HK_OUTPKT_MISSING_DATA_EID, CFE_EVS_EventType_DEBUG,
388 : : "Combined Packet 0x%08lX missing data from Input Pkt 0x%08lX",
389 : 1 : (unsigned long)CFE_SB_MsgIdToValue(ThisEntrysOutMid),
390 : 1 : (unsigned long)CFE_SB_MsgIdToValue(InputMidMissing));
391 : : }
392 : : #if HK_DISCARD_INCOMPLETE_COMBO == 1
393 : : else /* This clause is only exclusive if discarding incomplete packets */
394 : : #endif
395 : : {
396 : : /* Send the combined housekeeping telemetry packet... */
397 : 2 : CFE_SB_TimeStampMsg(&OutBuffer->Msg);
398 : 2 : CFE_SB_TransmitMsg(&OutBuffer->Msg, true);
399 : :
400 : 2 : HK_AppData.CombinedPacketsSent++;
401 : : }
402 : :
403 : 2 : HK_SetFlagsToNotPresent(ThisEntrysOutMid);
404 : :
405 : 2 : PacketFound = true;
406 : : }
407 : : }
408 : : }
409 : :
410 [ + + ]: 4 : if (PacketFound == false)
411 : : {
412 : 2 : CFE_EVS_SendEvent(HK_UNKNOWN_COMBINED_PACKET_EID, CFE_EVS_EventType_INFORMATION,
413 : : "Combined HK Packet 0x%08lX is not found in current HK Copy Table",
414 : 2 : (unsigned long)CFE_SB_MsgIdToValue(WhichMidToSend));
415 : : }
416 : 4 : }
417 : :
418 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
419 : : /* */
420 : : /* Check the status of HK tables and perform any necessary action. */
421 : : /* */
422 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
423 : 3 : int32 HK_CheckStatusOfTables(void)
424 : : {
425 : : int32 HKStatus;
426 : :
427 : 3 : HKStatus = HK_CheckStatusOfCopyTable();
428 : :
429 : : /* Only check the Dump Table if there were no problems with the Copy Table */
430 [ + + ]: 3 : if (HKStatus == HK_SUCCESS)
431 : : {
432 : 2 : HKStatus = HK_CheckStatusOfDumpTable();
433 : : }
434 : :
435 : 3 : return HKStatus;
436 : : }
437 : :
438 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
439 : : /* */
440 : : /* Check the status of HK Copy table and perform any necessary action. */
441 : : /* */
442 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
443 : 12 : int32 HK_CheckStatusOfCopyTable(void)
444 : : {
445 : : int32 Status;
446 : 12 : int32 HKStatus = HK_ERROR; /* Assume failure */
447 : :
448 : : /* Determine if the copy table has a validation or update that needs to be performed */
449 : 12 : Status = CFE_TBL_GetStatus(HK_AppData.CopyTableHandle);
450 : :
451 [ + + ]: 12 : if (Status == CFE_TBL_INFO_VALIDATION_PENDING)
452 : : {
453 : : /* Validate the specified Table */
454 : 2 : Status = CFE_TBL_Validate(HK_AppData.CopyTableHandle);
455 : :
456 [ + + ]: 2 : if (Status != CFE_SUCCESS)
457 : : {
458 : 1 : CFE_EVS_SendEvent(HK_UNEXPECTED_TBLVLD_RET_EID, CFE_EVS_EventType_ERROR,
459 : : "Unexpected CFE_TBL_Validate return (0x%08X) for Copy Table", (unsigned int)Status);
460 : : }
461 : 2 : HKStatus = HK_SUCCESS; /* This could just be a bad table, so no reason to abort the app */
462 : : }
463 [ + + ]: 10 : else if (Status == CFE_TBL_INFO_UPDATE_PENDING)
464 : : {
465 : : /* Unsubscribe to input msgs and free out pkt buffers */
466 : : /* If the copy table pointer is bad, that's okay here because it will be re-allocated later.
467 : : If the runtime table pointer is bad, the process new copy table call later on will
468 : : flag the error. So we can ignore the return status at this point.
469 : : */
470 : 5 : HK_TearDownOldCopyTable(HK_AppData.CopyTablePtr, HK_AppData.RuntimeTablePtr);
471 : :
472 : : /* release address must be called for update to take. */
473 : 5 : Status = CFE_TBL_ReleaseAddress(HK_AppData.CopyTableHandle);
474 : :
475 : : /* Releasing the address should only return CFE_SUCCESS at this point since we
476 : : already had an update-pending response earlier */
477 [ + + ]: 5 : if (Status == CFE_SUCCESS)
478 : : {
479 : : /* Update the copy table */
480 : 4 : Status = CFE_TBL_Update(HK_AppData.CopyTableHandle);
481 : :
482 [ + + ]: 4 : if (Status == CFE_SUCCESS)
483 : : {
484 : : /* Get address of the newly updated copy table. */
485 : 3 : Status = CFE_TBL_GetAddress((void *)(&HK_AppData.CopyTablePtr), HK_AppData.CopyTableHandle);
486 : :
487 : : /* Status should only be CFE_TBL_INFO_UPDATED because we updated it above */
488 [ + + ]: 3 : if (Status == CFE_TBL_INFO_UPDATED)
489 : : {
490 : 2 : Status = HK_ProcessNewCopyTable(HK_AppData.CopyTablePtr, HK_AppData.RuntimeTablePtr);
491 : :
492 [ + + ]: 2 : if (Status == CFE_SUCCESS)
493 : : {
494 : 1 : HKStatus = HK_SUCCESS;
495 : : }
496 : : else
497 : : {
498 : : /* If status was not success, then the copy table function received a NULL pointer argument */
499 : 1 : CFE_EVS_SendEvent(HK_NEWCPYTBL_HK_FAILED_EID, CFE_EVS_EventType_CRITICAL,
500 : : "Process New Copy Table Failed, status = 0x%08X", (unsigned int)Status);
501 : : }
502 : : }
503 : : else
504 : : {
505 : 1 : CFE_EVS_SendEvent(HK_UNEXPECTED_GETADDR_RET_EID, CFE_EVS_EventType_CRITICAL,
506 : : "Unexpected CFE_TBL_GetAddress return (0x%08X) for Copy Table",
507 : : (unsigned int)Status);
508 : : }
509 : : }
510 : : else
511 : : {
512 : 1 : CFE_EVS_SendEvent(HK_UNEXPECTED_TBLUPD_RET_EID, CFE_EVS_EventType_CRITICAL,
513 : : "Unexpected CFE_TBL_Update return (0x%08X) for Copy Table", (unsigned int)Status);
514 : : }
515 : : }
516 : : else
517 : : {
518 : 1 : CFE_EVS_SendEvent(HK_UNEXPECTED_RELADDR_RET_EID, CFE_EVS_EventType_CRITICAL,
519 : : "Unexpected CFE_TBL_ReleaseAddress return (0x%08X) for Copy Table", (unsigned int)Status);
520 : : }
521 : : }
522 [ + + ]: 5 : else if (Status != CFE_SUCCESS)
523 : : {
524 : 2 : CFE_EVS_SendEvent(HK_UNEXPECTED_GETSTAT_RET_EID, CFE_EVS_EventType_CRITICAL,
525 : : "Unexpected CFE_TBL_GetStatus return (0x%08X) for Copy Table", (unsigned int)Status);
526 : : }
527 : : else
528 : : {
529 : : /* Only way to get here is if Status == CFE_SUCCESS */
530 : 3 : HKStatus = HK_SUCCESS;
531 : : }
532 : :
533 : 12 : return HKStatus;
534 : : }
535 : :
536 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
537 : : /* */
538 : : /* Check the status of HK Dump table and perform any necessary action. */
539 : : /* */
540 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
541 : 6 : int32 HK_CheckStatusOfDumpTable(void)
542 : : {
543 : : int32 Status;
544 : 6 : int32 HKStatus = HK_ERROR; /* Assume failure */
545 : :
546 : : /* Determine if the runtime table has a dump pending */
547 : 6 : Status = CFE_TBL_GetStatus(HK_AppData.RuntimeTableHandle);
548 : :
549 [ + + ]: 6 : if (Status == CFE_TBL_INFO_DUMP_PENDING)
550 : : {
551 : : /* Dump the specified Table, cfe tbl manager makes copy */
552 : 2 : Status = CFE_TBL_DumpToBuffer(HK_AppData.RuntimeTableHandle);
553 : :
554 [ + + ]: 2 : if (Status != CFE_SUCCESS)
555 : : {
556 : 1 : CFE_EVS_SendEvent(HK_UNEXPECTED_DUMPTOBUFFER_RET_EID, CFE_EVS_EventType_CRITICAL,
557 : : "Unexpected CFE_TBL_DumpToBuffer return (0x%08X) for Runtime Table",
558 : : (unsigned int)Status);
559 : : }
560 : : else
561 : : {
562 : 1 : HKStatus = HK_SUCCESS;
563 : : }
564 : : }
565 [ + + ]: 4 : else if (Status != CFE_SUCCESS)
566 : : {
567 : 2 : CFE_EVS_SendEvent(HK_UNEXPECTED_GETSTAT2_RET_EID, CFE_EVS_EventType_CRITICAL,
568 : : "Unexpected CFE_TBL_GetStatus return (0x%08X) for Runtime Table", (unsigned int)Status);
569 : : }
570 : : else
571 : : {
572 : : /* Only way to get here is if Status == CFE_SUCCESS */
573 : 2 : HKStatus = HK_SUCCESS;
574 : : }
575 : :
576 : 6 : return HKStatus;
577 : : }
578 : :
579 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
580 : : /* */
581 : : /* HK Check for missing combined output message data */
582 : : /* */
583 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
584 : 6 : int32 HK_CheckForMissingData(CFE_SB_MsgId_t OutPktToCheck, CFE_SB_MsgId_t *MissingInputMid)
585 : : {
586 : 6 : int32 Loop = 0;
587 : 6 : int32 Status = HK_NO_MISSING_DATA;
588 : 6 : hk_copy_table_entry_t * StartOfCopyTable = HK_AppData.CopyTablePtr;
589 : 6 : hk_copy_table_entry_t * CpyTblEntry = NULL;
590 : 6 : hk_runtime_tbl_entry_t *StartOfRtTable = HK_AppData.RuntimeTablePtr;
591 : 6 : hk_runtime_tbl_entry_t *RtTblEntry = NULL;
592 : :
593 : : /* Loop thru each item in the runtime table until end is reached or
594 : : * data-not-present detected */
595 : : do
596 : : {
597 : 514 : CpyTblEntry = &StartOfCopyTable[Loop];
598 : 514 : RtTblEntry = &StartOfRtTable[Loop];
599 : :
600 : : /* Empty table entries are defined by NULL's in this field */
601 [ + + + + ]: 514 : if ((RtTblEntry->OutputPktAddr != NULL) && CFE_SB_MsgId_Equal(CpyTblEntry->OutputMid, OutPktToCheck) &&
602 [ + + ]: 12 : (RtTblEntry->DataPresent == HK_DATA_NOT_PRESENT))
603 : : {
604 : 2 : *MissingInputMid = CpyTblEntry->InputMid;
605 : 2 : Status = HK_MISSING_DATA_DETECTED;
606 : : }
607 : :
608 : 514 : Loop++;
609 : :
610 [ + + + + ]: 514 : } while ((Loop < HK_COPY_TABLE_ENTRIES) && (Status == HK_NO_MISSING_DATA));
611 : :
612 : 6 : return Status;
613 : : }
614 : :
615 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
616 : : /* */
617 : : /* HK Set data present flags to 'data-not-present' */
618 : : /* */
619 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
620 : 3 : void HK_SetFlagsToNotPresent(CFE_SB_MsgId_t OutPkt)
621 : : {
622 : 3 : int32 Loop = 0;
623 : 3 : hk_copy_table_entry_t * StartOfCopyTable = HK_AppData.CopyTablePtr;
624 : 3 : hk_copy_table_entry_t * CpyTblEntry = NULL;
625 : 3 : hk_runtime_tbl_entry_t *StartOfRtTable = HK_AppData.RuntimeTablePtr;
626 : 3 : hk_runtime_tbl_entry_t *RtTblEntry = NULL;
627 : :
628 : : /* Look thru each item in the runtime table until end is reached */
629 [ + + ]: 387 : for (Loop = 0; Loop < HK_COPY_TABLE_ENTRIES; Loop++)
630 : : {
631 : 384 : CpyTblEntry = &StartOfCopyTable[Loop];
632 : 384 : RtTblEntry = &StartOfRtTable[Loop];
633 : :
634 : : /* Empty table entries are defined by NULL's in this field */
635 [ + + + + ]: 384 : if ((RtTblEntry->OutputPktAddr != NULL) && CFE_SB_MsgId_Equal(CpyTblEntry->OutputMid, OutPkt))
636 : : {
637 : 137 : RtTblEntry->DataPresent = HK_DATA_NOT_PRESENT;
638 : : }
639 : : }
640 : 3 : }
641 : :
642 : : /************************/
643 : : /* End of File Comment */
644 : : /************************/
|