Skip to content

Commit

Permalink
Fix nasa#95, Replaces conditionally compiled code with runtime condit…
Browse files Browse the repository at this point in the history
…ional logic
  • Loading branch information
jdfiguer authored and jdfiguer committed Feb 29, 2024
1 parent ce8902c commit 621a2fa
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 262 deletions.
2 changes: 1 addition & 1 deletion docs/dox_src/cfs_ds.dox
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
the platform.

<h2>Move File Capability</h2>
If the DS_MOVE_FILES configuration parameter is set to TRUE, the telemetry
If the DS_MOVE_FILES configuration parameter is set to a non-empty string, the telemetry
database, Destination File table load images and the File Table display page
require changes. The Destination File Table rdl file uses the DS_MOVE_FILES
definition in the ds_platform_cfg.h file. However, in order to get the
Expand Down
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
6 changes: 3 additions & 3 deletions fsw/inc/ds_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@
*
* \par Limits
* This parameter must be set to one of the following:
* true = add move pathname field to Destination File Table
* false = do not add move pathname to Destination File Table
* non-empty string = add move pathname field to Destination File Table
* empty string = do not add move pathname to Destination File Table
*/
#define DS_MOVE_FILES true
#define DS_MOVE_FILES "Move to downlink directory"

/**
* \brief Application Per Packet Pipe Limit
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 (strlen(DS_MOVE_FILES) > 0)
{
/*
** 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
Loading

0 comments on commit 621a2fa

Please sign in to comment.