diff --git a/docs/dox_src/cfs_hk.dox b/docs/dox_src/cfs_hk.dox
index 5a8c9a9..873d633 100644
--- a/docs/dox_src/cfs_hk.dox
+++ b/docs/dox_src/cfs_hk.dox
@@ -281,9 +281,10 @@
tables were chosen so that checksumming can be executed on the more-static copy
table.
- HK Copy Table Validation - The HK copy table currently has an empty validation
- call-back function that always returns success. At the time of development,
- a validation process that would apply to all projects was not perceived.
+ HK Copy Table Validation - The HK copy table currently has a validation
+ call-back function that returns success when the size of the resulting combined
+ packet is less than or equal to the platform/project defined maximum value. Otherwise,
+ this function returns error and sends and error event.
HK Copy Table Entries - Entries follow the concept of:
Copy A bytes from input message B, byte-offset C to output message Y,
diff --git a/docs/hk_FunctionalRequirements.csv b/docs/hk_FunctionalRequirements.csv
index 6fc1594..0867687 100644
--- a/docs/hk_FunctionalRequirements.csv
+++ b/docs/hk_FunctionalRequirements.csv
@@ -9,6 +9,7 @@ HK1002,HK1002,"For all HK commands, if the length contained in the message heade
HK1003,HK1003,"If HK accepts any command as valid, HK shall execute the command, increment the HK Valid Command Counter and issue an event message",Provides basic verification of each HK command (i.e. HK command parameters are acceptable)
HK1004,HK1004,"If HK rejects any command, HK shall abort the command execution, increment the HK Command Rejected Counter and issue an error event message",Provides indicator of erroneous command
HK2000,HK2000,HK shall collect flight software housekeeping data from table-specified input messages,Use of tables makes it easier to modify/maintain
+HK2000.1,HK2000.1,"If the HK Copy Table fails validation, HK shall issue an event message.",This is the case when the total memory stored in the combined copy packet is greater than the allowable size.
HK2001,HK2001,"HK shall output table-defined messages, at the scheduled rate, by combining input message data starting at the table-defined offset and table-defined number of bytes to the table-defined offset in the output message.",Useful to group telemetry from multiple apps into a single message
HK2001.1,HK2001.1,"Upon a table update, HK shall update the output message formats specified in the table during normal execution.",Supports the capability to adding and removing applications at runtime (or modifying messages)
HK2001.2,HK2001.2,"If the parameter Discard Combo Packets is set to NO and HK does not receive a message from an application, HK shall use all values associated with last received message for that application in the combined message for that telemetry collection period.",Zeroing data could have undesirable effects.
diff --git a/fsw/inc/hk_platform_cfg.h b/fsw/inc/hk_platform_cfg.h
index 44c4ae4..182b832 100644
--- a/fsw/inc/hk_platform_cfg.h
+++ b/fsw/inc/hk_platform_cfg.h
@@ -121,6 +121,18 @@
*/
#define HK_MISSION_REV 0
+/**
+ * \brief Maximum size allowed for HK combined packet
+ *
+ * \par Description:
+ * Defines the maximum allowed size (in bytes) of a combined packet.
+ *
+ * \par Limits:
+ * Must be defined as a numeric value that is greater than
+ * or equal to zero.
+ */
+#define HK_MAX_COMBINED_PACKET_SIZE 1500
+
/**\}*/
#endif
diff --git a/fsw/src/hk_utils.c b/fsw/src/hk_utils.c
index aa0cf85..9cff1d7 100644
--- a/fsw/src/hk_utils.c
+++ b/fsw/src/hk_utils.c
@@ -106,7 +106,31 @@ void HK_ProcessIncomingHkData(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 HK_ValidateHkCopyTable(void *TblPtr)
{
- return HK_SUCCESS;
+ int32 HKStatus;
+ int32 i = 0;
+ int32 sumBytes = 0;
+ hk_copy_table_entry_t *tbl = (hk_copy_table_entry_t *)TblPtr;
+
+ /* Loop thru the table and add up all the bytes copied for testing overflow scenario */
+ for (i = 0; i < HK_COPY_TABLE_ENTRIES; i++)
+ {
+ sumBytes += tbl[i].NumBytes;
+ }
+
+ /* Check if the accumulated bytes exceed the allowed packet size, indicating an overflow */
+ if (sumBytes > HK_MAX_COMBINED_PACKET_SIZE)
+ {
+ HKStatus = HK_ERROR;
+
+ CFE_EVS_SendEvent(HK_NEWCPYTBL_HK_FAILED_EID, CFE_EVS_EventType_ERROR,
+ "HK Validate: table contents has size %d > %d\n", sumBytes, HK_MAX_COMBINED_PACKET_SIZE);
+ }
+ else
+ {
+ HKStatus = HK_SUCCESS;
+ }
+
+ return HKStatus;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
diff --git a/fsw/src/hk_utils.h b/fsw/src/hk_utils.h
index d93ef02..518ee5f 100644
--- a/fsw/src/hk_utils.h
+++ b/fsw/src/hk_utils.h
@@ -81,6 +81,7 @@ void HK_ProcessIncomingHkData(const CFE_SB_Buffer_t *BufPtr);
*
* \return Table Validation Status
* \retval #HK_SUCCESS Valid table
+ * \retval #HK_ERROR \copydoc HK_ERROR
*
* \sa #HK_TableInit
*/
diff --git a/unit-test/hk_utils_tests.c b/unit-test/hk_utils_tests.c
index b2a982b..fe2483e 100644
--- a/unit-test/hk_utils_tests.c
+++ b/unit-test/hk_utils_tests.c
@@ -296,22 +296,44 @@ void Test_HK_ProcessIncomingHkData_MessageError(void)
* Function under test: HK_ValidateHkCopyTable
*
* Case: Tests that the HK_ValidateHkCopyTable returns HK_SUCCESS
- * (that is the only possible outcome - there are no branches in
- * the function).
*/
void Test_HK_ValidateHkCopyTable_Success(void)
{
/* Arrange */
+ hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];
+
+ HK_Test_InitGoodCopyTable(CopyTblPtr);
/* Act */
- int32 ReturnValue = HK_ValidateHkCopyTable(NULL);
+ int32 ReturnValue = HK_ValidateHkCopyTable(CopyTblPtr);
/* Assert */
UtAssert_True(ReturnValue == HK_SUCCESS, "HK_ValidateHkCopyTable returned %d, expected %d (HK_SUCCESS)",
ReturnValue, HK_SUCCESS);
}
+/*
+ * Function under test: HK_ValidateHkCopyTable
+ *
+ * Case: Tests that the HK_ValidateHkCopyTable returns HK_ERROR
+ */
+
+void Test_HK_ValidateHkCopyTable_Error(void)
+{
+ /* Arrange */
+ hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];
+
+ HK_Test_InitOverflowCopyTable(CopyTblPtr);
+
+ /* Act */
+ int32 ReturnValue = HK_ValidateHkCopyTable(CopyTblPtr);
+
+ /* Assert */
+ UtAssert_True(ReturnValue == HK_ERROR, "HK_ValidateHkCopyTable returned %d, expected %d (HK_ERROR)",
+ ReturnValue, HK_ERROR);
+}
+
/**********************************************************************/
/* */
/* Test functions for HK_ProcessNewCopyTable */
@@ -1933,6 +1955,8 @@ void UtTest_Setup(void)
/* Test functions for HK_VaidateHkCopyTable */
UtTest_Add(Test_HK_ValidateHkCopyTable_Success, HK_Test_Setup, HK_Test_TearDown,
"Test_HK_ValidateHkCopyTable_Success");
+ UtTest_Add(Test_HK_ValidateHkCopyTable_Error, HK_Test_Setup, HK_Test_TearDown,
+ "Test_HK_ValidateHkCopyTable_Error");
/* Test functions for HK_ProcessNewCopyTable */
UtTest_Add(Test_HK_ProcessNewCopyTable_EmptyTable, HK_Test_Setup, HK_Test_TearDown,
diff --git a/unit-test/utilities/hk_test_utils.c b/unit-test/utilities/hk_test_utils.c
index 9e719ff..a0c349b 100644
--- a/unit-test/utilities/hk_test_utils.c
+++ b/unit-test/utilities/hk_test_utils.c
@@ -118,6 +118,22 @@ void HK_Test_InitGoodCopyTable(hk_copy_table_entry_t *CpyTbl)
}
}
+void HK_Test_InitOverflowCopyTable(hk_copy_table_entry_t *CpyTbl)
+{
+ int32 i;
+ int32 overflowBytes = (HK_MAX_COMBINED_PACKET_SIZE / HK_COPY_TABLE_ENTRIES) + 1;
+
+ /* Set each table entry such that the combined size exceeds HK_MAX_COMBINED_PACKET_SIZE */
+ for (i = 0; i < HK_COPY_TABLE_ENTRIES; i++)
+ {
+ CpyTbl[i].InputMid = CFE_SB_ValueToMsgId(CFE_EVS_HK_TLM_MID);
+ CpyTbl[i].InputOffset = 12;
+ CpyTbl[i].OutputMid = CFE_SB_ValueToMsgId(HK_COMBINED_PKT1_MID);
+ CpyTbl[i].OutputOffset = ((i + 1) * overflowBytes);
+ CpyTbl[i].NumBytes = overflowBytes; /* Ensures overflow when summed across all entries */
+ }
+}
+
void HK_Test_InitEmptyCopyTable(hk_copy_table_entry_t *CpyTbl)
{
int32 i = 0;
diff --git a/unit-test/utilities/hk_test_utils.h b/unit-test/utilities/hk_test_utils.h
index 6c7cc6f..399282d 100644
--- a/unit-test/utilities/hk_test_utils.h
+++ b/unit-test/utilities/hk_test_utils.h
@@ -57,6 +57,8 @@ extern CFE_ES_WriteToSysLog_context_t context_CFE_ES_WriteToSysLog;
void HK_Test_InitGoodCopyTable(hk_copy_table_entry_t *CpyTbl);
+void HK_Test_InitOverflowCopyTable(hk_copy_table_entry_t *CpyTbl);
+
void HK_Test_InitEmptyCopyTable(hk_copy_table_entry_t *CpyTbl);
void HK_Test_InitGoodRuntimeTable(hk_runtime_tbl_entry_t *RtTbl);