/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CFE_ES_ListTasks(int32 fd) { uint32 i; char Line [128]; int32 Result = CFE_SUCCESS; CFE_ES_TaskInfo_t TaskInfo; /* Make sure we start at the beginning of the file */ Result = OS_lseek(fd, 0, OS_SEEK_SET); if ( Result == 0 ) { sprintf(Line,"---- ES Task List ----\n"); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { Result = CFE_SUCCESS; for ( i = 0; i < OS_MAX_TASKS; i++ ) { if ((CFE_ES_Global.TaskTable[i].RecordUsed == TRUE) && (Result == CFE_SUCCESS)) { /* ** zero out the local entry */ CFE_PSP_MemSet(&TaskInfo,0,sizeof(CFE_ES_TaskInfo_t)); /* ** Populate the AppInfo entry */ Result = CFE_ES_GetTaskInfo(&TaskInfo,i); if ( Result == CFE_SUCCESS ) { sprintf(Line,"Task ID: %08d, Task Name: %20s, Prnt App ID: %08d, Prnt App Name: %20s\n", (int) TaskInfo.TaskId, TaskInfo.TaskName, (int)TaskInfo.AppId, TaskInfo.AppName); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { Result = CFE_SUCCESS; } /* if not success, returns whatever OS_write failire was */ } } } /* end for */ } /* End if OS_write */ } /* End if OS_lseek */ return Result; } /* end ES_ListTasks */
/* -------------------------------------------------------------------------------------- Name: OS_ShellOutputToFile Purpose: Takes a shell command in and writes the output of that command to the specified file Returns: OS_SUCCESS if success OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid OS_FS_ERROR if Error ---------------------------------------------------------------------------------------*/ int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd) { char LocalCmd [OS_MAX_CMD_LEN]; int32 Result; int32 ReturnCode = OS_FS_SUCCESS; int32 fdCmd; char * shellName; /* ** Check parameters */ if (Cmd == NULL) { return(OS_FS_ERR_INVALID_POINTER); } /* Make sure the file descriptor is legit before using it */ if (OS_fd < 0 || OS_fd >= OS_MAX_NUM_OPEN_FILES || OS_FDTable[OS_fd].IsValid == FALSE) { ReturnCode = OS_FS_ERR_INVALID_FD; } else { /* Create a file to write the command to (or write over the old one) */ fdCmd = OS_creat(OS_SHELL_CMD_INPUT_FILE_NAME,OS_READ_WRITE); if (fdCmd < OS_FS_SUCCESS) { Result = OS_FS_ERROR; } else { /* copy the command to the file, and then seek back to the beginning of the file */ strncpy(LocalCmd,Cmd, OS_MAX_CMD_LEN); OS_write(fdCmd,Cmd, strlen(LocalCmd)); OS_lseek(fdCmd,0,OS_SEEK_SET); /* Create a shell task the will run the command in the file, push output to OS_fd */ Result = shellGenericInit("INTERPRETER=Cmd",0,NULL, &shellName, FALSE, FALSE, OS_FDTable[fdCmd].OSfd, OS_FDTable[OS_fd].OSfd, OS_FDTable[OS_fd].OSfd); /* Wait for the command to terminate */ do{ taskDelay(sysClkRateGet()); }while (taskNameToId(shellName) != ERROR); /* Close the file descriptor */ OS_close(fdCmd); } /* else */ if (Result != OK) { ReturnCode = OS_FS_ERROR; } } return ReturnCode; }/* end OS_ShellOutputToFile */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CreateTestFile(char *Filename, int SizeInKs, boolean LeaveOpen) { int FileHandle; int i; FileHandle = OS_creat(Filename, OS_READ_WRITE); if (FileHandle >= OS_SUCCESS) { if (FillBuffer[0] == 0) { CFE_PSP_MemSet(FillBuffer, 0xA5, sizeof(FillBuffer)); } for (i = 0; i < SizeInKs; i++) { OS_write(FileHandle, FillBuffer, sizeof(FillBuffer)); } if (LeaveOpen) { OpenFileHandle = FileHandle; } else { OS_close(FileHandle); } } else { UTF_put_text("\nERROR CREATING TEST FILE %s\n", Filename); } return; } /* End of CreateTestFile() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CFE_ES_ListApplications(int32 fd) { uint32 i; char Line [OS_MAX_API_NAME +2]; int32 Result = CFE_SUCCESS; /* Make sure we start at the beginning of the file */ OS_lseek(fd,0, OS_SEEK_SET); for ( i = 0; i < CFE_ES_MAX_APPLICATIONS; i++ ) { if ( (CFE_ES_Global.AppTable[i].RecordUsed == TRUE) && (Result == CFE_SUCCESS) ) { /* We found an in use app. Write it to the file */ strcpy(Line, (char*) CFE_ES_Global.AppTable[i].StartParams.Name); strcat(Line,"\n"); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { Result = CFE_SUCCESS; } /* if not success, returns whatever OS_write failire was */ } } /* end for */ return Result; } /* end ES_ListApplications */
/****************************************************************************** ** ** DumpExObjTable ** ** Dump the packet table contents to a file as text. The function signature ** must correspond to the DumpTableFuncPtr type. ** */ static void DumpExObjTable(int32 FileHandle) { const EXOBJ_Table *ObjTblPtr; char DumpRecord[256]; int i; sprintf(DumpRecord,"\nIndex: Data 1, Data 2, Data 3\n"); OS_write(FileHandle,DumpRecord,strlen(DumpRecord)); ObjTblPtr = EXOBJ_GetTblPtr(); for (i=0; i < EXOBJ_TBL_MAX_ENTRY_ID; i++) { sprintf(DumpRecord,"%03d: %4d, %4d, %4d\n", i, ObjTblPtr->Entry[i].Data1, ObjTblPtr->Entry[i].Data2, ObjTblPtr->Entry[i].Data3); OS_write(FileHandle,DumpRecord,strlen(DumpRecord)); } } /* End DumpExObjTable() */
void DS_FileWriteData(int32 FileIndex, void *FileData, uint32 DataLength) { DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; int32 Result; /* ** Let cFE manage the file I/O... */ Result = OS_write(FileStatus->FileHandle, FileData, DataLength); if (Result == DataLength) { /* ** Success - update file size and data rate counters... */ DS_AppData.FileWriteCounter++; FileStatus->FileSize += DataLength; FileStatus->FileGrowth += DataLength; #if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_GPM) /* ** Current pkt time is now last pkt time for this file... */ DS_AppData.LastPktTime[FileIndex] = DS_AppData.CurrentPktTime; #endif } else { /* ** Error - send event, close file and disable destination... */ DS_FileWriteError(FileIndex, DataLength, Result); } return; } /* End of DS_FileWriteData() */
void Create_Input_File0(void) { /* FILE *to; */ int8 values[4] = {5,10,15,20}; char tableName[30]; CFE_FS_Header_t StdFileHeader; CFE_TBL_File_Hdr_t TblFileHeader; int32 FileDescriptor; int32 Status; int32 EndianCheck = 0x01020304; /* to = fopen("/tt_table_values0.dat", "wb"); if (to == 0) { UTF_error("Error opening file /tt_table_initial_values.dat to write\n"); UTF_exit(); } fwrite(values, sizeof(int8), 4, to); fclose(to); */ strcpy (tableName, "TT.FourNumbers"); /* Clear Header of any garbage before copying content */ CFE_PSP_MemSet(&StdFileHeader, 0, sizeof(CFE_FS_Header_t)); CFE_PSP_MemSet(&TblFileHeader, 0, sizeof(CFE_TBL_File_Hdr_t)); /* Create a new dump file, overwriting anything that may have existed previously */ FileDescriptor = OS_creat("/ram/tt_table_values0.dat", OS_WRITE_ONLY); if (FileDescriptor >= OS_FS_SUCCESS) { /* Initialize the standard cFE File Header for the Dump File */ StdFileHeader.SubType = CFE_FS_TBL_IMG_SUBTYPE; strcpy(&StdFileHeader.Description[0], "Table Load File"); /* Output the Standard cFE File Header to the Dump File */ Status = CFE_FS_WriteHeader(FileDescriptor, &StdFileHeader); if (Status == sizeof(CFE_FS_Header_t)) { /* Initialize the Table Image Header for the Dump File */ CFE_PSP_MemCpy(TblFileHeader.TableName, tableName, CFE_TBL_MAX_FULL_NAME_LEN); TblFileHeader.Offset = 0; TblFileHeader.NumBytes = 4; TblFileHeader.Reserved = 0; /* Determine if this is a little endian processor */ if ((*(char *)&EndianCheck) == 0x04) { CFE_TBL_ByteSwapTblHeader(&TblFileHeader); } /* Output the Table Image Header to the Dump File */ Status = OS_write(FileDescriptor, &TblFileHeader, sizeof(CFE_TBL_File_Hdr_t)); /* Make sure the header was output completely */ if (Status == sizeof(CFE_TBL_File_Hdr_t)) { /* Output the requested data to the dump file */ /* Output the active table image data to the dump file */ Status = OS_write(FileDescriptor, values, 4); } } /* We are done writing the load file. Close it. */ OS_close(FileDescriptor); } }
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), SEEK_SET); if (Result == sizeof(CFE_FS_Header_t)) { /* 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++; } #elif (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_GPM) /* ** Update GPM specific header fields... */ DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; char Buf8[8]; int32 Result; Result = OS_lseek(FileStatus->FileHandle, 16, SEEK_SET); if (Result == 16) { /* update last pkt time in file header */ Result = OS_write(FileStatus->FileHandle, &DS_AppData.LastPktTime[FileIndex], sizeof(uint32)); if (Result == sizeof(uint32)) { /* update file size in file header */ CFE_PSP_MemSet(Buf8, ' ', sizeof(Buf8)); DS_FileConvertGPM(Buf8, FileStatus->FileSize); Result = OS_write(FileStatus->FileHandle, Buf8, sizeof(Buf8)); if (Result == sizeof(Buf8)) { DS_AppData.FileUpdateCounter++; } else { DS_AppData.FileUpdateErrCounter++; } } else { DS_AppData.FileUpdateErrCounter++; } } else { DS_AppData.FileUpdateErrCounter++; } #endif return; } /* End of DS_FileUpdateHeader() */
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_PSP_MemSet(&CFE_FS_Header, 0, sizeof(CFE_FS_Header_t)); CFE_FS_Header.SubType = DS_FILE_HDR_SUBTYPE; strcpy(CFE_FS_Header.Description, DS_FILE_HDR_DESCRIPTION); /* ** 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)) { /* ** 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); /* ** Initialize the DS file header... */ CFE_PSP_MemSet(&DS_FileHeader, 0, sizeof(DS_FileHeader_t)); DS_FileHeader.FileTableIndex = FileIndex; DS_FileHeader.FileNameType = DestFile->FileNameType; strcpy(DS_FileHeader.FileName, FileStatus->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(CFE_FS_Header_t), Result); } #elif (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_GPM) DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; DS_FileHeaderGPM_t DS_FileHeaderGPM; int32 Result; /* ** Initialize GPM file header... */ CFE_PSP_MemSet(&DS_FileHeaderGPM, ' ', sizeof(DS_FileHeaderGPM_t)); DS_FileHeaderGPM.SourceID[0] = 'S'; DS_FileHeaderGPM.SourceID[1] = 'C'; DS_FileHeaderGPM.SourceID[2] = 'H'; DS_FileHeaderGPM.SourceID[3] = 'K'; DS_FileConvertGPM(DS_FileHeaderGPM.SequenceID, FileStatus->FileCount); DS_FileHeaderGPM.StartTime = DS_AppData.CurrentPktTime; /* ** Write GPM file header to the file... */ Result = OS_write(FileStatus->FileHandle, &DS_FileHeaderGPM, sizeof(DS_FileHeaderGPM_t)); if (Result == sizeof(DS_FileHeaderGPM_t)) { /* ** Success - update file size and data rate counters... */ DS_AppData.FileWriteCounter++; FileStatus->FileSize += sizeof(DS_FileHeaderGPM_t); FileStatus->FileGrowth += sizeof(DS_FileHeaderGPM_t); } else { /* ** Error - send event, close file and disable destination... */ DS_FileWriteError(FileIndex, sizeof(DS_FileHeaderGPM_t), Result); } #endif return; } /* End of DS_FileWriteHeader() */
/* -------------------------------------------------------------------------------------- Name: OS_ShellOutputToFile Purpose: Takes a shell command in and writes the output of that command to the specified file Returns: OS_FS_ERROR if the command was not executed properly OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid OS_SUCCESS if success ---------------------------------------------------------------------------------------*/ int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd) { int32 cmdFd; int32 tmpFd; rtems_status_code rtemsRc;; int32 ReturnCode = OS_SUCCESS; int32 fileStatus; int32 bytesRead; int32 bytesWritten; char readBuffer[256]; char outputFileName[OS_MAX_PATH_LEN + OS_SHELL_TMP_FILE_EXT_LEN]; char localCmd[OS_MAX_CMD_LEN]; /* Make sure the file descriptor is legit before using it */ if (OS_fd < 0 || OS_fd >= OS_MAX_NUM_OPEN_FILES || OS_FDTable[OS_fd].IsValid == FALSE) { ReturnCode = OS_FS_ERR_INVALID_FD; } else { /* ** Create a file to write the command to (or write over the old one) */ cmdFd = OS_creat(OS_SHELL_CMD_INPUT_FILE_NAME,OS_READ_WRITE); if (cmdFd < OS_FS_SUCCESS) { ReturnCode = OS_FS_ERROR; } else { /* ** Write the command to the buffer */ strncpy(localCmd,Cmd,OS_MAX_CMD_LEN); strncat(localCmd,"\n",1); /* ** This function passes in an open file descriptor to write the shell ** command output. The RTEMS shell script API expects a filename, not ** a file descriptor. So in addition to the temporary file for the shell input, ** we need to create a temporary file for the command output, then it has ** to be copied to the open file. */ strncpy(outputFileName,OS_SHELL_CMD_INPUT_FILE_NAME,OS_MAX_PATH_LEN); strncat(outputFileName,OS_SHELL_TMP_FILE_EXT,OS_SHELL_TMP_FILE_EXT_LEN); /* ** copy the shell command buffer to the file */ fileStatus = OS_write(cmdFd, localCmd, strlen(localCmd)); if ( fileStatus == strlen(localCmd) ) { /* ** Close the file */ OS_close(cmdFd); /* ** Spawn a task to execute the shell command */ rtemsRc = rtems_shell_script ( "RSHL", OS_SHELL_CMD_TASK_STACK_SIZE, OS_SHELL_CMD_TASK_PRIORITY, OS_SHELL_CMD_INPUT_FILE_NAME, outputFileName, FALSE, /* Do not append output to file */ TRUE, /* Wait for shell task to complete */ FALSE /* Echo output */ ); /* ** Now we have the temporary file with the output */ if((tmpFd = OS_open(outputFileName, OS_READ_ONLY,0)) == OS_FS_ERROR) { printf("OSAL:Could not open %s for reading\n",outputFileName); ReturnCode = OS_FS_ERROR; } else { while((bytesRead = OS_read(tmpFd, readBuffer, 256)) > 0) { bytesWritten = OS_write(OS_fd, readBuffer, bytesRead); } OS_close(tmpFd); /* ** Remove the temporary output file */ fileStatus = OS_remove(outputFileName); } } else { ReturnCode = OS_FS_ERROR; } } /* ** Remove the temporary shell input file */ fileStatus = OS_remove(OS_SHELL_CMD_INPUT_FILE_NAME); } return ReturnCode; }/* end OS_ShellOutputToFile */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CFE_ES_PerfLogDump(void){ int32 WriteStat; uint32 i; uint32 FileSize; CFE_FS_Header_t FileHdr; CFE_ES_RegisterChildTask(); /* Zero cFE header, then fill in fields */ CFE_PSP_MemSet(&FileHdr, 0, sizeof(CFE_FS_Header_t)); strcpy(&FileHdr.Description[0], CFE_ES_PERF_LOG_DESC); FileHdr.SubType = CFE_FS_ES_PERFDATA_SUBTYPE; /* write the cFE header to the file */ WriteStat = CFE_FS_WriteHeader( CFE_ES_PerfLogDumpStatus.DataFileDescriptor, &FileHdr); if(WriteStat != sizeof(CFE_FS_Header_t)) { CFE_ES_FileWriteByteCntErr(&CFE_ES_PerfLogDumpStatus.DataFileName[0], sizeof(CFE_FS_Header_t),WriteStat); OS_close(CFE_ES_PerfLogDumpStatus.DataFileDescriptor); CFE_ES_ExitChildTask(); }/* end if */ FileSize = WriteStat; /* write the performance metadata to the file */ WriteStat = OS_write(CFE_ES_PerfLogDumpStatus.DataFileDescriptor,(uint8 *)&Perf->MetaData,sizeof(CFE_ES_PerfMetaData_t)); if(WriteStat != sizeof(CFE_ES_PerfMetaData_t)) { CFE_ES_FileWriteByteCntErr(&CFE_ES_PerfLogDumpStatus.DataFileName[0], sizeof(CFE_ES_PerfMetaData_t),WriteStat); OS_close(CFE_ES_PerfLogDumpStatus.DataFileDescriptor); CFE_ES_ExitChildTask(); }/* end if */ FileSize += WriteStat; CFE_ES_PerfLogDumpStatus.DataToWrite = Perf->MetaData.DataCount; /* write the collected data to the file */ for(i=0; i < Perf->MetaData.DataCount; i++){ WriteStat = OS_write (CFE_ES_PerfLogDumpStatus.DataFileDescriptor, &Perf->DataBuffer[i], sizeof(CFE_ES_PerfDataEntry_t)); if(WriteStat != sizeof(CFE_ES_PerfDataEntry_t)) { CFE_ES_FileWriteByteCntErr(&CFE_ES_PerfLogDumpStatus.DataFileName[0], sizeof(CFE_ES_PerfDataEntry_t),WriteStat); OS_close(CFE_ES_PerfLogDumpStatus.DataFileDescriptor); /* Reset the DataToWrite variable, so a new file can be written */ CFE_ES_PerfLogDumpStatus.DataToWrite = 0; CFE_ES_ExitChildTask(); }/* end if */ FileSize += WriteStat; CFE_ES_PerfLogDumpStatus.DataToWrite--; if((i % CFE_ES_PERF_ENTRIES_BTWN_DLYS) == 0){ OS_TaskDelay(CFE_ES_PERF_CHILD_MS_DELAY); }/* end if */ }/* end for */ OS_close(CFE_ES_PerfLogDumpStatus.DataFileDescriptor); CFE_EVS_SendEvent(CFE_ES_PERF_DATAWRITTEN_EID,CFE_EVS_DEBUG, "%s written:Size=%d,EntryCount=%d", &CFE_ES_PerfLogDumpStatus.DataFileName[0],FileSize, Perf->MetaData.DataCount); CFE_ES_ExitChildTask(); }/* end CFE_ES_PerfLogDump */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CFE_ES_ShellOutputCommand(char * CmdString, char *Filename) { int32 Result; int32 ReturnCode = CFE_SUCCESS; int32 fd; int32 FileSize; int32 CurrFilePtr; uint32 i; /* the extra 1 added for the \0 char */ char CheckCmd [CFE_ES_CHECKSIZE + 1]; char Cmd [CFE_ES_MAX_SHELL_CMD]; char OutputFilename [OS_MAX_PATH_LEN]; /* Use default filename if not provided */ if (Filename[0] == '\0') { strncpy(OutputFilename, CFE_ES_DEFAULT_SHELL_FILENAME, OS_MAX_PATH_LEN); } else { strncpy(OutputFilename, Filename, OS_MAX_PATH_LEN); } /* Make sure string is null terminated */ OutputFilename[OS_MAX_PATH_LEN - 1] = '\0'; /* Remove previous version of output file */ OS_remove(OutputFilename); fd = OS_creat(OutputFilename, OS_READ_WRITE); if (fd < OS_FS_SUCCESS) { Result = OS_FS_ERROR; } else { strncpy(CheckCmd,CmdString,CFE_ES_CHECKSIZE); CheckCmd[CFE_ES_CHECKSIZE] = '\0'; strncpy(Cmd,CmdString, CFE_ES_MAX_SHELL_CMD); /* We need to check if this command is directed at ES, or at the operating system */ if (strncmp(CheckCmd,"ES_",CFE_ES_CHECKSIZE) == 0) { /* This list can be expanded to include other ES functionality */ if ( strncmp(Cmd,CFE_ES_LIST_APPS_CMD,strlen(CFE_ES_LIST_APPS_CMD) )== 0) { Result = CFE_ES_ListApplications(fd); } else if ( strncmp(Cmd,CFE_ES_LIST_TASKS_CMD,strlen(CFE_ES_LIST_TASKS_CMD) )== 0) { Result = CFE_ES_ListTasks(fd); } else if ( strncmp(Cmd,CFE_ES_LIST_RESOURCES_CMD,strlen(CFE_ES_LIST_RESOURCES_CMD) )== 0) { Result = CFE_ES_ListResources(fd); } /* default if there is not an ES command that matches */ else { Result = CFE_ES_ERR_SHELL_CMD; CFE_ES_WriteToSysLog("There is no ES Shell command that matches %s \n",Cmd); } } /* if the command is not directed at ES, pass it through to the * underlying OS */ else { Result = OS_ShellOutputToFile(Cmd,fd); } /* seek to the end of the file to get it's size */ FileSize = OS_lseek(fd,0,OS_SEEK_END); if (FileSize == OS_FS_ERROR) { OS_close(fd); CFE_ES_WriteToSysLog("OS_lseek call failed from CFE_ES_ShellOutputCmd 1\n"); Result = OS_FS_ERROR; } /* We want to add 3 characters at the end of the telemetry,'\n','$','\0'. * To do this we need to make sure there are at least 3 empty characters at * the end of the last CFE_ES_MAX_SHELL_PKT so we don't over write any data. If * the current file has only 0,1, or 2 free spaces at the end, we want to * make the file longer to start a new tlm packet of size CFE_ES_MAX_SHELL_PKT. * This way we will get a 'blank' packet with the correct 3 characters at the end. */ else { /* if we are within 2 bytes of the end of the packet*/ if ( FileSize % CFE_ES_MAX_SHELL_PKT > (CFE_ES_MAX_SHELL_PKT - 3)) { /* add enough bytes to start a new packet */ for (i = 0; i < CFE_ES_MAX_SHELL_PKT - (FileSize % CFE_ES_MAX_SHELL_PKT) + 1 ; i++) { OS_write(fd," ",1); } } else { /* we are exactly at the end */ if( FileSize % CFE_ES_MAX_SHELL_PKT == 0) { OS_write(fd," ",1); } } /* seek to the end of the file again to get it's new size */ FileSize = OS_lseek(fd,0,OS_SEEK_END); if (FileSize == OS_FS_ERROR) { OS_close(fd); CFE_ES_WriteToSysLog("OS_lseek call failed from CFE_ES_ShellOutputCmd 2\n"); Result = OS_FS_ERROR; } else { /* set the file back to the beginning */ OS_lseek(fd,0,OS_SEEK_SET); /* start processing the chunks. We want to have one packet left so we are sure this for loop * won't run over */ for (CurrFilePtr=0; CurrFilePtr < (FileSize - CFE_ES_MAX_SHELL_PKT); CurrFilePtr += CFE_ES_MAX_SHELL_PKT) { OS_read(fd, CFE_ES_TaskData.ShellPacket.ShellOutput, CFE_ES_MAX_SHELL_PKT); /* Send the packet */ CFE_SB_TimeStampMsg((CFE_SB_Msg_t *) &CFE_ES_TaskData.ShellPacket); CFE_SB_SendMsg((CFE_SB_Msg_t *) &CFE_ES_TaskData.ShellPacket); /* delay to not flood the pipe on large messages */ OS_TaskDelay(200); } /* finish off the last portion of the file */ /* over write the last packet with spaces, then it will get filled * in with the correct info below. This assures that the last non full * part of the packet will be spaces */ for (i =0; i < CFE_ES_MAX_SHELL_PKT; i++) { CFE_ES_TaskData.ShellPacket.ShellOutput[i] = ' '; } OS_read(fd, CFE_ES_TaskData.ShellPacket.ShellOutput, ( FileSize - CurrFilePtr)); /* From our check above, we are assured that there are at least 3 free * characters to write our data into at the end of this last packet * * The \n assures we are on a new line, the $ gives us our prompt, and the * \0 assures we are null terminalted. */ CFE_ES_TaskData.ShellPacket.ShellOutput[ CFE_ES_MAX_SHELL_PKT - 3] = '\n'; CFE_ES_TaskData.ShellPacket.ShellOutput[ CFE_ES_MAX_SHELL_PKT - 2] = '$'; CFE_ES_TaskData.ShellPacket.ShellOutput[ CFE_ES_MAX_SHELL_PKT - 1] = '\0'; /* Send the last packet */ CFE_SB_TimeStampMsg((CFE_SB_Msg_t *) &CFE_ES_TaskData.ShellPacket); CFE_SB_SendMsg((CFE_SB_Msg_t *) &CFE_ES_TaskData.ShellPacket); /* Close the file descriptor */ OS_close(fd); } /* if FilseSize == OS_FS_ERROR */ } /* if FileSeize == OS_FS_ERROR */ }/* if fd < OS_FS_SUCCESS */ if (Result != OS_SUCCESS && Result != CFE_SUCCESS ) { ReturnCode = CFE_ES_ERR_SHELL_CMD; CFE_ES_WriteToSysLog("OS_ShellOutputToFile call failed from CFE_ES_ShellOutputCommand\n"); } else { ReturnCode = CFE_SUCCESS; } return ReturnCode; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CFE_ES_ListResources(int32 fd) { OS_task_prop_t TaskProp; OS_queue_prop_t QueueProp; OS_bin_sem_prop_t SemProp; OS_count_sem_prop_t CountSemProp; OS_mut_sem_prop_t MutProp; OS_FDTableEntry FileProp; int32 Result = CFE_SUCCESS; int32 NumSemaphores = 0; int32 NumCountSems =0; int32 NumMutexes = 0; int32 NumQueues = 0; int32 NumTasks = 0; int32 NumFiles = 0; uint32 i; char Line[35]; for ( i= 0; i < OS_MAX_TASKS; i++) { if (OS_TaskGetInfo(i, &TaskProp) == OS_SUCCESS) { NumTasks++; } } for ( i= 0; i < OS_MAX_QUEUES; i++) { if (OS_QueueGetInfo(i, &QueueProp) == OS_SUCCESS) { NumQueues++; } } for ( i= 0; i < OS_MAX_COUNT_SEMAPHORES; i++) { if (OS_CountSemGetInfo(i, &CountSemProp) == OS_SUCCESS) { NumCountSems++; } } for ( i= 0; i < OS_MAX_BIN_SEMAPHORES; i++) { if (OS_BinSemGetInfo(i, &SemProp) == OS_SUCCESS) { NumSemaphores++; } } for ( i= 0; i < OS_MAX_MUTEXES; i++) { if (OS_MutSemGetInfo(i, &MutProp) == OS_SUCCESS) { NumMutexes++; } } for ( i= 0; i < OS_MAX_NUM_OPEN_FILES; i++) { if (OS_FDGetInfo(i, &FileProp) == OS_FS_SUCCESS) { NumFiles++; } } sprintf(Line,"OS Resources in Use:\n"); Result = OS_write(fd, Line, strlen(Line)); if( Result == strlen(Line)) { sprintf(Line,"Number of Tasks: %d\n", (int) NumTasks); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { sprintf(Line,"Number of Queues: %d\n", (int) NumQueues); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { sprintf(Line,"Number of Binary Semaphores: %d\n",(int) NumSemaphores); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { sprintf(Line,"Number of Counting Semaphores: %d\n",(int) NumCountSems); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { sprintf(Line,"Number of Mutexes: %d\n", (int) NumMutexes); Result = OS_write(fd, Line, strlen(Line)); if (Result == strlen(Line)) { sprintf(Line,"Number of Open Files: %d\n",(int) NumFiles); Result = OS_write(fd, Line, strlen(Line)); if ( Result == strlen(Line)) { Result = CFE_SUCCESS; } } } } } } } /* ** If any of the writes failed, return the OS_write ** failure */ return Result; }