static void prvVerifyDemoFileUsing_f_getc( void ) { unsigned char ucReturn; int iByte, iReturned; F_FILE *pxFile; char cFileName[ fsMAX_FILE_NAME_LEN ]; /* Move into the directory in which the file was created. */ ucReturn = f_chdir( pcFullPath ); configASSERT( ucReturn == F_NO_ERROR ); /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); printf( "Back in directory %s\r\n", cRAMBuffer ); configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 ); /* Generate the file name. */ sprintf( cFileName, "%s.txt", pcDirectory2 ); /* Print out the file name and the directory from which the file is being read. */ printf( "Reading file %s in %s\r\n", cFileName, cRAMBuffer ); /* This time the file is opened for reading. */ pxFile = f_open( cFileName, "r" ); /* Read the file 1 byte at a time. */ for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ ) { iReturned = f_getc( pxFile ); configASSERT( iReturned == ( ( int ) '0' + iByte ) ); } /* Finished so close the file. */ f_close( pxFile ); /* Move back to the root directory. */ ucReturn = f_chdir( "../.." ); configASSERT( ucReturn == F_NO_ERROR ); /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); printf( "Back in root directory %s\r\n", cRAMBuffer ); }
static portBASE_TYPE prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) { const char *pcParameter; portBASE_TYPE xParameterStringLength, xReturn = pdTRUE; static F_FILE *pxFile = NULL; int iChar; size_t xByte; size_t xColumns = 50U; /* Ensure there is always a null terminator after each character written. */ memset( pcWriteBuffer, 0x00, xWriteBufferLen ); /* Ensure the buffer leaves space for the \r\n. */ configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) ); xWriteBufferLen -= strlen( cliNEW_LINE ); if( xWriteBufferLen < xColumns ) { /* Ensure the loop that uses xColumns as an end condition does not write off the end of the buffer. */ xColumns = xWriteBufferLen; } if( pxFile == NULL ) { /* The file has not been opened yet. Find the file name. */ pcParameter = FreeRTOS_CLIGetParameter ( pcCommandString, /* The command string itself. */ 1, /* Return the first parameter. */ &xParameterStringLength /* Store the parameter string length. */ ); /* Sanity check something was returned. */ configASSERT( pcParameter ); /* Attempt to open the requested file. */ pxFile = f_open( pcParameter, "r" ); } if( pxFile != NULL ) { /* Read the next chunk of data from the file. */ for( xByte = 0; xByte < xColumns; xByte++ ) { iChar = f_getc( pxFile ); if( iChar == -1 ) { /* No more characters to return. */ f_close( pxFile ); pxFile = NULL; break; } else { pcWriteBuffer[ xByte ] = ( char ) iChar; } } } if( pxFile == NULL ) { /* Either the file was not opened, or all the data from the file has been returned and the file is now closed. */ xReturn = pdFALSE; } strcat( pcWriteBuffer, cliNEW_LINE ); return xReturn; }