Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #37, Sends message when file complete #39

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [strncpy](1) is not checked.
#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)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion

All functions of more than 10 lines should have at least one assertion.
{
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));

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [CFE_MSG_Init](1) is not checked.

/*
** Set file age and size...
*/
PktBuf->Pkt.FileInfo.FileAge = FileStatus->FileAge;

Check warning

Code scanning / CodeQL-coding-standard

Unchecked function argument

This use of parameter FileStatus has not been checked.
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);

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [strcpy](1) is not checked.

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

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [CFE_SB_TransmitBuffer](1) is not checked.
}

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_FileCompletePktBuf_t
*/
void DS_FileTransmit(DS_AppFileStatus_t *FileStatus);

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

/**
* \brief Single application file info packet
*/
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;

/**
* \brief Single application file info packet buffer
*
* This typedef supports CFE_SB_AllocateMessageBuffer use with a DS_FileCompletePkt_t
* that compiles with the alignment constraints of a CFE_SB_Buffer_t
*/
typedef union
{
Fixed Show fixed Hide fixed

Check notice

Code scanning / CodeQL-coding-standard

AV Rule 153

AV Rule 153: Unions shall not be used.
CFE_SB_Buffer_t SBBuf; /**< \brief Message buffer for alignment */
DS_FileCompletePkt_t Pkt; /**< \brief Single application file info packet */
} 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