Skip to content

Commit 79cfde6

Browse files
astrogecojphickey
authored andcommitted
Merge pull request #1102 from jphickey/fix-982-separate-pipeinfo
Fix #982, separate pipeinfo file data structure
2 parents a4aa481 + 137768d commit 79cfde6

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

fsw/cfe-core/src/inc/cfe_sb_msg.h

+30
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,36 @@ typedef struct CFE_SB_PipeDepthStats {
615615

616616
}CFE_SB_PipeDepthStats_t;
617617

618+
/**
619+
** \brief SB Pipe Information File Entry
620+
**
621+
** This statistics structure is output as part of the CFE SB
622+
** "Send Pipe Info" command (CFE_SB_SEND_PIPE_INFO_CC).
623+
**
624+
** Previous versions of CFE simply wrote the internal CFE_SB_PipeD_t object
625+
** to the file, but this also contains information such as pointers which are
626+
** not relevant outside the running CFE process.
627+
**
628+
** By defining the pipe info structure separately, it also provides some
629+
** independence, such that the internal CFE_SB_PipeD_t definition
630+
** can evolve without changing the binary format of the information
631+
** file.
632+
*/
633+
typedef struct CFE_SB_PipeInfoEntry
634+
{
635+
CFE_SB_PipeId_t PipeId; /**< The runtime ID of the pipe */
636+
CFE_ES_ResourceID_t AppId; /**< The runtime ID of the application that owns the pipe */
637+
char PipeName[CFE_MISSION_MAX_API_LEN]; /**< The Name of the pipe */
638+
char AppName[CFE_MISSION_MAX_API_LEN]; /**< The Name of the application that owns the pipe */
639+
uint16 MaxQueueDepth; /**< The allocated depth of the pipe (max capacity) */
640+
uint16 CurrentQueueDepth; /**< The current depth of the pipe */
641+
uint16 PeakQueueDepth; /**< The peak depth of the pipe (high watermark) */
642+
uint16 SendErrors; /**< Number of errors when writing to this pipe */
643+
uint8 Opts; /**< Pipe options set (bitmask) */
644+
uint8 Spare[3]; /**< Padding to make this structure a multiple of 4 bytes */
645+
646+
} CFE_SB_PipeInfoEntry_t;
647+
618648
/**
619649
** \cfesbtlm SB Statistics Telemetry Packet
620650
**

fsw/cfe-core/src/sb/cfe_sb_task.c

+30-5
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,8 @@ int32 CFE_SB_SendPipeInfo(const char *Filename)
11411141
uint32 EntryCount = 0;
11421142
CFE_FS_Header_t FileHdr;
11431143
CFE_SB_PipeD_t *PipeDscPtr;
1144-
CFE_SB_PipeD_t entry; /* NOTE: Should be separate/dedicated type */
1144+
CFE_SB_PipeInfoEntry_t FileEntry;
1145+
osal_id_t SysQueueId;
11451146

11461147
Status = OS_OpenCreate(&fd, Filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
11471148

@@ -1172,14 +1173,38 @@ int32 CFE_SB_SendPipeInfo(const char *Filename)
11721173
{
11731174
if (CFE_SB_PipeDescIsUsed(PipeDscPtr))
11741175
{
1175-
memcpy(&entry, PipeDscPtr, sizeof(CFE_SB_PipeD_t));
1176+
/*
1177+
* Ensure any old data in the struct has been cleared
1178+
*/
1179+
memset(&FileEntry, 0, sizeof(FileEntry));
1180+
1181+
/*
1182+
* Take a "snapshot" of the PipeDsc state while locked
1183+
*/
1184+
FileEntry.PipeId = CFE_SB_PipeDescGetID(PipeDscPtr);
1185+
FileEntry.AppId = PipeDscPtr->AppId;
1186+
FileEntry.MaxQueueDepth = PipeDscPtr->QueueDepth;
1187+
FileEntry.CurrentQueueDepth = PipeDscPtr->CurrentDepth;
1188+
FileEntry.PeakQueueDepth = PipeDscPtr->PeakDepth;
1189+
FileEntry.SendErrors = PipeDscPtr->SendErrors;
1190+
FileEntry.Opts = PipeDscPtr->Opts;
1191+
SysQueueId = PipeDscPtr->SysQueueId;
11761192

11771193
CFE_SB_UnlockSharedData(__FILE__,__LINE__);
11781194

1179-
Status = OS_write (fd, &entry, sizeof(CFE_SB_PipeD_t));
1180-
if (Status != sizeof(CFE_SB_PipeD_t))
1195+
/*
1196+
* Gather data from other subsystems while unlocked.
1197+
* This might fail if the pipe is deleted simultaneously while this runs, but in
1198+
* the unlikely event that happens, the name data will simply be blank as the ID(s)
1199+
* will not validate.
1200+
*/
1201+
OS_GetResourceName(SysQueueId, FileEntry.PipeName, sizeof(FileEntry.PipeName));
1202+
CFE_ES_GetAppName(FileEntry.AppName, FileEntry.AppId, sizeof(FileEntry.AppName));
1203+
1204+
Status = OS_write (fd, &FileEntry, sizeof(FileEntry));
1205+
if (Status != sizeof(FileEntry))
11811206
{
1182-
CFE_SB_FileWriteByteCntErr(Filename,sizeof(CFE_SB_PipeD_t),Status);
1207+
CFE_SB_FileWriteByteCntErr(Filename,sizeof(FileEntry),Status);
11831208
OS_close(fd);
11841209
return CFE_SB_FILE_IO_ERR;
11851210
}/* end if */

0 commit comments

Comments
 (0)