Skip to content

Commit

Permalink
Merge pull request nasa#124 from chillfig/cond_comp_code
Browse files Browse the repository at this point in the history
Fix nasa#95, Replaces conditionally compiled code with runtime conditional logic
  • Loading branch information
dzbaker authored Mar 28, 2024
2 parents ce8902c + 3f41af7 commit ec96b02
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 250 deletions.
2 changes: 0 additions & 2 deletions fsw/inc/ds_extern_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ typedef struct
*/
typedef struct
{
#if (DS_MOVE_FILES == true)
char Movename[DS_PATHNAME_BUFSIZE]; /**< \brief Move files to this dir after close */
#endif
char Pathname[DS_PATHNAME_BUFSIZE]; /**< \brief Path portion of filename */
char Basename[DS_BASENAME_BUFSIZE]; /**< \brief Base portion of filename */
char Extension[DS_EXTENSION_BUFSIZE]; /**< \brief Extension portion of filename */
Expand Down
1 change: 1 addition & 0 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ CFE_Status_t DS_AppInitialize(void)
memset(&DS_AppData, 0, sizeof(DS_AppData));

DS_AppData.AppEnableState = DS_DEF_ENABLE_STATE;
DS_AppData.EnableMoveFiles = DS_MOVE_FILES;

/*
** Mark files as closed
Expand Down
2 changes: 2 additions & 0 deletions fsw/src/ds_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ typedef struct

DS_HashLink_t HashLinks[DS_PACKETS_IN_FILTER_TABLE]; /**< \brief Hash table linked list elements */
DS_HashLink_t *HashTable[DS_HASH_TABLE_ENTRIES]; /**< \brief Each hash table entry is a linked list */

uint8 EnableMoveFiles; /**< \brief Whether to move files to downlink directory after close */
} DS_AppData_t;

/** \brief DS global data structure reference */
Expand Down
237 changes: 115 additions & 122 deletions fsw/src/ds_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,73 +376,73 @@ void DS_FileWriteData(int32 FileIndex, const void *FileData, uint32 DataLength)

void DS_FileWriteHeader(int32 FileIndex)
{
#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)

DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex];
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_FS_Header_t CFE_FS_Header;
DS_FileHeader_t DS_FileHeader;
int32 Result;

/*
** Initialize selected parts of the cFE file header...
*/
CFE_FS_InitHeader(&CFE_FS_Header, DS_FILE_HDR_DESCRIPTION, DS_FILE_HDR_SUBTYPE);

/*
** Let cFE finish the init and write the primary header...
*/
Result = CFE_FS_WriteHeader(FileStatus->FileHandle, &CFE_FS_Header);

if (Result == sizeof(CFE_FS_Header_t))
if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(CFE_FS_Header_t);
FileStatus->FileGrowth += sizeof(CFE_FS_Header_t);
DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex];
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_FS_Header_t CFE_FS_Header;
DS_FileHeader_t DS_FileHeader;
int32 Result;

/*
** Initialize the DS file header...
** Initialize selected parts of the cFE file header...
*/
memset(&DS_FileHeader, 0, sizeof(DS_FileHeader));
DS_FileHeader.FileTableIndex = FileIndex;
DS_FileHeader.FileNameType = DestFile->FileNameType;
strncpy(DS_FileHeader.FileName, FileStatus->FileName, sizeof(DS_FileHeader.FileName));
CFE_FS_InitHeader(&CFE_FS_Header, DS_FILE_HDR_DESCRIPTION, DS_FILE_HDR_SUBTYPE);

/*
** Manually write the secondary header...
** Let cFE finish the init and write the primary header...
*/
Result = OS_write(FileStatus->FileHandle, &DS_FileHeader, sizeof(DS_FileHeader_t));
Result = CFE_FS_WriteHeader(FileStatus->FileHandle, &CFE_FS_Header);

if (Result == sizeof(DS_FileHeader_t))
if (Result == sizeof(CFE_FS_Header_t))
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(DS_FileHeader_t);
FileStatus->FileGrowth += sizeof(DS_FileHeader_t);
FileStatus->FileSize += sizeof(CFE_FS_Header_t);
FileStatus->FileGrowth += sizeof(CFE_FS_Header_t);

/*
** Initialize the DS file header...
*/
memset(&DS_FileHeader, 0, sizeof(DS_FileHeader));
DS_FileHeader.FileTableIndex = FileIndex;
DS_FileHeader.FileNameType = DestFile->FileNameType;
strncpy(DS_FileHeader.FileName, FileStatus->FileName, sizeof(DS_FileHeader.FileName));

/*
** Manually write the secondary header...
*/
Result = OS_write(FileStatus->FileHandle, &DS_FileHeader, sizeof(DS_FileHeader_t));

if (Result == sizeof(DS_FileHeader_t))
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(DS_FileHeader_t);
FileStatus->FileGrowth += sizeof(DS_FileHeader_t);
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(DS_FileHeader_t), Result);
}
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(DS_FileHeader_t), Result);
DS_FileWriteError(FileIndex, sizeof(CFE_FS_Header_t), Result);
}
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(CFE_FS_Header_t), Result);
}
#endif
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -761,35 +761,36 @@ void DS_FileCreateSequence(char *Buffer, uint32 Type, uint32 Count)

void DS_FileUpdateHeader(int32 FileIndex)
{
#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
/*
** Update CFE specific header fields...
*/
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_TIME_SysTime_t CurrentTime = CFE_TIME_GetTime();
int32 Result;

Result = OS_lseek(FileStatus->FileHandle, sizeof(CFE_FS_Header_t), OS_SEEK_SET);

if (Result == sizeof(CFE_FS_Header_t))
if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
{
/* update file close time */
Result = OS_write(FileStatus->FileHandle, &CurrentTime, sizeof(CFE_TIME_SysTime_t));
/*
** Update CFE specific header fields...
*/
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_TIME_SysTime_t CurrentTime = CFE_TIME_GetTime();
int32 Result;

if (Result == sizeof(CFE_TIME_SysTime_t))
Result = OS_lseek(FileStatus->FileHandle, sizeof(CFE_FS_Header_t), OS_SEEK_SET);

if (Result == sizeof(CFE_FS_Header_t))
{
DS_AppData.FileUpdateCounter++;
/* update file close time */
Result = OS_write(FileStatus->FileHandle, &CurrentTime, sizeof(CFE_TIME_SysTime_t));

if (Result == sizeof(CFE_TIME_SysTime_t))
{
DS_AppData.FileUpdateCounter++;
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
#endif
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -800,68 +801,74 @@ void DS_FileUpdateHeader(int32 FileIndex)
void DS_FileCloseDest(int32 FileIndex)
{
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];

#if (DS_MOVE_FILES == true)
/*
** Move file from working directory to downlink directory...
*/
int32 OS_result;
int32 PathLength;
char *FileName;
char PathName[DS_TOTAL_FNAME_BUFSIZE];
int32 OS_result;
int32 PathLength;
char * FileName;
char PathName[DS_TOTAL_FNAME_BUFSIZE];

/*
** First, close the file...
*/
OS_close(FileStatus->FileHandle);

/*
** Move file only if table has a downlink directory name...
*/
if (DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] != '\0')
if (DS_AppData.EnableMoveFiles == DS_ENABLED)
{
/*
** Make sure directory name does not end with slash character...
** Move file only if table has a downlink directory name...
*/
CFE_SB_MessageStringGet(PathName, DS_AppData.DestFileTblPtr->File[FileIndex].Movename, NULL, sizeof(PathName),
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename));
PathLength = strlen(PathName);
if (PathName[PathLength - 1] == '/')
if (DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] != '\0')
{
PathName[PathLength - 1] = '\0';
PathLength--;
}

/*
** Get a pointer to slash character before the filename...
*/
FileName = strrchr(FileStatus->FileName, '/');
/*
** Make sure directory name does not end with slash character...
*/
CFE_SB_MessageStringGet(PathName, DS_AppData.DestFileTblPtr->File[FileIndex].Movename, NULL,
sizeof(PathName), sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename));
PathLength = strlen(PathName);
if (PathName[PathLength - 1] == '/')
{
PathName[PathLength - 1] = '\0';
PathLength--;
}

if (FileName != NULL)
{
/*
** Verify that directory name plus filename is not too large...
** Get a pointer to slash character before the filename...
*/
if ((PathLength + strlen(FileName)) < DS_TOTAL_FNAME_BUFSIZE)
FileName = strrchr(FileStatus->FileName, '/');

if (FileName != NULL)
{
/*
** Append the filename (with slash) to the directory name...
** Verify that directory name plus filename is not too large...
*/
strcat(PathName, FileName);
if ((PathLength + strlen(FileName)) < DS_TOTAL_FNAME_BUFSIZE)
{
/*
** Append the filename (with slash) to the directory name...
*/
strcat(PathName, FileName);

/*
** Use OS function to move/rename the file...
*/
OS_result = OS_mv(FileStatus->FileName, PathName);
/*
** Use OS function to move/rename the file...
*/
OS_result = OS_mv(FileStatus->FileName, PathName);

if (OS_result != OS_SUCCESS)
if (OS_result != OS_SUCCESS)
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: src = '%s', tgt = '%s', result = %d", FileStatus->FileName,
PathName, (int)OS_result);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: src = '%s', tgt = '%s', result = %d", FileStatus->FileName,
PathName, (int)OS_result);
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
}
}
else
Expand All @@ -870,27 +877,13 @@ void DS_FileCloseDest(int32 FileIndex)
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
"FILE MOVE error: dir name = '%s', filename = 'NULL'", PathName);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = 'NULL'", PathName);
}

/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(FileStatus->FileName));
/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(FileStatus->FileName));
}
}
#else
/*
** Close the file...
*/
OS_close(FileStatus->FileHandle);
#endif

/*
** Transmit file information telemetry...
Expand Down
2 changes: 0 additions & 2 deletions fsw/src/ds_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
/**
* \brief DS File Header (follows cFE file header at start of file)
*/
Expand All @@ -49,7 +48,6 @@ typedef struct

char FileName[DS_TOTAL_FNAME_BUFSIZE]; /**< \brief On-board filename */
} DS_FileHeader_t;
#endif

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand Down
16 changes: 9 additions & 7 deletions fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ CFE_Status_t DS_TableInit(void)
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 (DS_MAKE_TABLES_CRITICAL == 1)
{
TableRegisterFlags |= CFE_TBL_OPT_CRITICAL;
}

/*
** If registration fails for either table then the DS app will
Expand Down Expand Up @@ -909,10 +910,11 @@ CFE_Status_t DS_TableCreateCDS(void)
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 (DS_CDS_ENABLE_STATE == 1)
{
/* Only restore enable/disable state if configured */
DS_AppData.AppEnableState = (uint8)DataStoreBuffer[DS_DEST_FILE_CNT];
}
}
}

Expand Down
Loading

0 comments on commit ec96b02

Please sign in to comment.