void SC_LoadDefaultTables(void) { char TableName[OS_MAX_PATH_LEN]; int32 FileDesc; int32 RtsIndex; int32 RtsCount = 0; /* ** Currently, only RTS tables are loaded during initialization. ** ** ATS and ATS Append tables must be loaded by command. */ for (RtsIndex = 0; RtsIndex < SC_NUMBER_OF_RTS; RtsIndex++) { /* Example filename: /cf/apps/sc_rts001.tbl */ sprintf(TableName, "%s%03ld.tbl", SC_RTS_FILE_NAME, RtsIndex + 1); FileDesc = OS_open(TableName, OS_READ_ONLY, 0); if (FileDesc >= 0) { OS_close(FileDesc); /* Only try to load table files that can be opened, ignore others */ if(CFE_TBL_Load(SC_OperData.RtsTblHandle[RtsIndex], CFE_TBL_SRC_FILE, TableName) == CFE_SUCCESS){ RtsCount++; } } } /* Display startup RTS load count */ CFE_EVS_SendEvent(SC_RTS_LOAD_COUNT_INFO_EID, CFE_EVS_INFORMATION, "RTS table file load count = %ld", RtsCount); return; } /* end SC_LoadDefaultTables() */
/* -------------------------------------------------------------------------------------- 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 */
/****************************************************************************** ** ** ParseXmlFile ** ** Parse an XML file */ static boolean ParseXmlFile(const char* FilePathName, XML_StartElementHandler StartElementHandler, XML_EndElementHandler EndElementHandler) { int FileHandle; int32 ReadStatus; boolean Done; boolean ParseErr = FALSE; boolean RetStatus = FALSE; XML_Parser XmlParser = XML_ParserCreate(NULL); if (! XmlParser) { CFE_EVS_SendEvent(TBLMGR_CREATE_ERR_EID, CFE_EVS_ERROR, "Failed to allocate memory for XML parser"); } else { XML_SetElementHandler(XmlParser, StartElementHandler, EndElementHandler); FileHandle = OS_open(FilePathName, OS_READ_ONLY, 0); if (FileHandle >= 0) { Done = FALSE; while (!Done) { ReadStatus = OS_read(FileHandle, TblFileBuff, TBLMGR_BUFFSIZE); if ( ReadStatus == OS_FS_ERROR ) { CFE_EVS_SendEvent(TBLMGR_FILE_READ_ERR_EID, CFE_EVS_ERROR, "File read error, EC = 0x%08X",ReadStatus); Done = TRUE; ParseErr = TRUE; } else if ( ReadStatus == 0 ) /* EOF reached */ { Done = TRUE; } else { /* ReadStatus contains number of bytes read */ if (XML_Parse(XmlParser, TblFileBuff, ReadStatus, Done) == XML_STATUS_ERROR) { CFE_EVS_SendEvent(TBLMGR_PARSE_ERR_EID, CFE_EVS_ERROR, "Parse error at line %l, error code = %s", XML_GetCurrentLineNumber(XmlParser), XML_ErrorString(XML_GetErrorCode(XmlParser))); Done = TRUE; ParseErr = TRUE; } /* End if valid parse */ } /* End if valid fread */ } /* End file read loop */ RetStatus = !ParseErr; OS_close(FileHandle); } /* End if file opened */ else { CFE_EVS_SendEvent(TBLMGR_FILE_OPEN_ERR_EID, CFE_EVS_ERROR, "File open error for %s, Error = %d", FilePathName, FileHandle ); } XML_ParserFree(XmlParser); } /* end if parser allocated */ return RetStatus; } /* End ParseXmlFile() */