Skip to content

Commit

Permalink
Fix #37, Sends message when file complete
Browse files Browse the repository at this point in the history
Adds FileStatus as the sole parameter to DS_FileTransmit(), Adds unit test,
Adds inclusion of ds_apps.h to ds_msg.h, Removes whitespaces, Adds dereference,
Adds logic to extract data from FileStatus, Adds copy of Move Directory,
Removes ds_apps.h inclusion, Sets OpenState to DS_CLOSED,
Adds unit test, Adds buffer struct, Adds CFE_SB_AllocateMessageBuffer
and CFE_SB_TransmitBuffer, Adds pointer cast in CFE_SB_AllocateMessageBuffer,
Adds CFE_SB_ValueToMsgId to CFE_MSG_Init, Adds & to CFE_SB_TransmitBuffer,
Adds pointer cast to CFE_SB_TransmitBuffer, Adds format correction,
Adds CFE_SB_Buffer_t to DS_FileCompletePkt_t, Adds requirement to csv,
Update software buffer use to work correctly, Corrects whitespace in csv,
Adds buffer to unit test
  • Loading branch information
chillfig committed Jul 28, 2022
1 parent 237385b commit 39b122e
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/ds_FunctionalRequirements.csv
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ a) Send an event message
b) Increment total number of file write errors
c) Close the destination file
d) Disable the destination",Notify operators of error and prevent ongoing future errors caused by writing to the same destination file.
DS3006,DS3006,DS shall send a file information telemetry message when closing a data storage file.,Provides file information telemetry packet containing the current status for a closed destination file.
DS5000,DS5000,"Upon receipt of a Disable command, DS shall stop filtering and storing messages.
Note: This command will set the Packet Processing State to DISABLED.",Operational control of packet processing state (message storage)
DS5001,DS5001,"Upon receipt of an Enable command, DS shall begin filtering and storing messages.
Expand Down
1 change: 1 addition & 0 deletions fsw/platform_inc/ds_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#define DS_HK_TLM_MID 0x08B8 /**< \brief DS Hk Telemetry Message ID ****/
#define DS_DIAG_TLM_MID 0x08B9 /**< \brief DS File Info Telemetry Message ID ****/
#define DS_COMP_TLM_MID 0x08BA /**< \brief DS Completed File Info Telemetry Message ID ****/

/**\}*/

Expand Down
70 changes: 70 additions & 0 deletions fsw/src/ds_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ds_verify.h"

#include "ds_appdefs.h"
#include "ds_msgids.h"

#include "ds_msg.h"
#include "ds_app.h"
Expand Down Expand Up @@ -960,13 +961,23 @@ void DS_FileCloseDest(int32 FileIndex)
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
}
}

/*
** Get the directory name...
*/
strncpy(FileStatus->FileName, PathName, sizeof(PathName));
#else
/*
** Close the file...
*/
OS_close(FileStatus->FileHandle);
#endif

/*
** Transmit file information telemetry...
*/
DS_FileTransmit(FileStatus);

/*
** Reset status for this destination file...
*/
Expand Down Expand Up @@ -1025,6 +1036,65 @@ void DS_FileTestAge(uint32 ElapsedSeconds)

} /* End of DS_FileTestAge() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* DS_FileTransmit() - transmit file info */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void DS_FileTransmit(DS_AppFileStatus_t *FileStatus)
{
DS_FileCompletePktBuf_t *PktBuf;

/*
** Get a Message block of memory and initialize it
*/
PktBuf = (DS_FileCompletePktBuf_t *)CFE_SB_AllocateMessageBuffer(sizeof(*PktBuf));

/*
** Process destination file info data...
*/
if (PktBuf != NULL)
{
CFE_MSG_Init(&PktBuf->Pkt.TlmHeader.Msg, CFE_SB_ValueToMsgId(DS_COMP_TLM_MID), sizeof(*PktBuf));

/*
** Set file age and size...
*/
PktBuf->Pkt.FileInfo.FileAge = FileStatus->FileAge;
PktBuf->Pkt.FileInfo.FileSize = FileStatus->FileSize;
/*
** Set file growth rate (computed when process last HK request)...
*/
PktBuf->Pkt.FileInfo.FileRate = FileStatus->FileRate;
/*
** Set current filename sequence count...
*/
PktBuf->Pkt.FileInfo.SequenceCount = FileStatus->FileCount;
/*
** Set file enable/disable state...
*/
PktBuf->Pkt.FileInfo.EnableState = FileStatus->FileState;
/*
** Set file closed state...
*/
PktBuf->Pkt.FileInfo.OpenState = DS_CLOSED;
/*
** Set current open filename...
*/
strcpy(PktBuf->Pkt.FileInfo.FileName, FileStatus->FileName);

/*
** Timestamp and send file info telemetry...
*/
CFE_SB_TimeStampMsg(&PktBuf->Pkt.TlmHeader.Msg);
CFE_SB_TransmitBuffer(&PktBuf->SBBuf, true);
}

return;

} /* End of DS_CmdGetCompleteFileInfo() */

/************************/
/* End of File Comment */
/************************/
16 changes: 16 additions & 0 deletions fsw/src/ds_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ void DS_FileCloseDest(int32 FileIndex);
*/
void DS_FileTestAge(uint32 ElapsedSeconds);

/**
* \brief Transmit file information telemetry handler
*
* \par Description
* Create and send a telemetry packet containing the current
* status for a closed destination file.
*
* \par Assumptions, External Events, and Notes:
* (none)
*
* \param[in] FileStatus Current state of destination file
*
* \sa #DS_GET_FILE_INFO_CC, #DS_GetFileInfoCmd_t, #DS_FileInfoPkt_t
*/
void DS_FileTransmit(DS_AppFileStatus_t *FileStatus);

/**
* \brief Determine whether Software Bus message packet is filtered
*
Expand Down
16 changes: 16 additions & 0 deletions fsw/src/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,22 @@ typedef struct
DS_FileInfo_t FileInfo[DS_DEST_FILE_CNT]; /**< \brief Current state of destination files */
} DS_FileInfoPkt_t;

/**
* \brief Completed application file info
*/
typedef struct
{
CFE_MSG_TelemetryHeader_t TlmHeader; /**< \brief cFE Software Bus telemetry message header */

DS_FileInfo_t FileInfo; /**< \brief Current state of destination file */
} DS_FileCompletePkt_t;

typedef union
{
CFE_SB_Buffer_t SBBuf;
DS_FileCompletePkt_t Pkt;
} DS_FileCompletePktBuf_t;

/**\}*/

#endif
34 changes: 34 additions & 0 deletions unit-test/ds_file_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,37 @@ void DS_IsPacketFiltered_Test_TimeFilter3(void)
UtAssert_BOOL_TRUE(Result);
}

void DS_FileTransmit_Test_Nominal(void)
{
DS_FileCompletePktBuf_t PktBuf;
DS_FileCompletePktBuf_t *PktBufPtr = &PktBuf;

/* setup for a call to CFE_SB_AllocateMessageBuffer() */
memset(PktBufPtr, 0, sizeof(*PktBufPtr));
UT_SetDataBuffer(UT_KEY(CFE_SB_AllocateMessageBuffer), &PktBufPtr, sizeof(PktBufPtr), true);

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileTransmit(&DS_AppData.FileStatus[0]));

/* Verify results */
UtAssert_STUB_COUNT(CFE_SB_AllocateMessageBuffer, 1);
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 1);
UtAssert_STUB_COUNT(CFE_SB_TransmitBuffer, 1);
}

void DS_FileTransmit_Test_NoBuf(void)
{
/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileTransmit(&DS_AppData.FileStatus[0]));

/* Verify results */
UtAssert_STUB_COUNT(CFE_SB_AllocateMessageBuffer, 1);
UtAssert_STUB_COUNT(CFE_MSG_Init, 0);
UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 0);
UtAssert_STUB_COUNT(CFE_SB_TransmitBuffer, 0);
}

void UtTest_Setup(void)
{
UtTest_Add(DS_FileStorePacket_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_FileStorePacket_Test_Nominal");
Expand Down Expand Up @@ -1855,6 +1886,9 @@ void UtTest_Setup(void)
UtTest_Add(DS_IsPacketFiltered_Test_TimeFilter3, DS_Test_Setup, DS_Test_TearDown,
"DS_IsPacketFiltered_Test_TimeFilter3");

UtTest_Add(DS_FileTransmit_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_FileTransmit_Test_Nominal");
UtTest_Add(DS_FileTransmit_Test_NoBuf, DS_Test_Setup, DS_Test_TearDown, "DS_FileTransmit_Test_NoBuf");

} /* end DS_File_Test_AddTestCases */

/************************/
Expand Down

0 comments on commit 39b122e

Please sign in to comment.