SdFat
|
StdioStream implements a minimal stdio stream. More...
#include <StdioStream.h>
Public Member Functions | |
void | clearerr () |
int | fclose () |
int | feof () |
int | ferror () |
int | fflush () |
int | fgetc () |
char * | fgets (char *str, size_t num, size_t *len=0) |
bool | fopen (const char *path, const char *mode) |
int | fputc (int c) |
int | fputs (const char *str) |
size_t | fread (void *ptr, size_t size, size_t count) |
int | fseek (int32_t offset, int origin) |
int32_t | ftell () |
size_t | fwrite (const void *ptr, size_t size, size_t count) |
int | getc () |
size_t | print (char c) |
size_t | print (const char *str) |
size_t | print (const __FlashStringHelper *str) |
size_t | print (double val, uint8_t prec=2) |
size_t | print (float val, uint8_t prec=2) |
template<typename T > | |
size_t | print (T val) |
int | printDec (char n) |
int | printDec (signed char n) |
int | printDec (unsigned char n) |
int | printDec (int16_t n) |
int | printDec (uint16_t n) |
int | printDec (int32_t n) |
int | printDec (uint32_t n) |
int | printDec (double value, uint8_t prec) |
int | printDec (float value, uint8_t prec) |
int | printField (double value, char term, uint8_t prec=2) |
int | printField (float value, char term, uint8_t prec=2) |
template<typename T > | |
int | printField (T value, char term) |
int | printHex (uint32_t n) |
int | printHexln (uint32_t n) |
size_t | println () |
size_t | println (double val, uint8_t prec=2) |
size_t | println (float val, uint8_t prec=2) |
template<typename T > | |
size_t | println (T val) |
int | putc (int c) |
int | putCRLF () |
bool | rewind () |
StdioStream () | |
int | ungetc (int c) |
Private Member Functions | |
uint32_t | available () |
void | clearError () |
void | clearWriteError () |
bool | close () |
bool | contiguousRange (uint32_t *bgnBlock, uint32_t *endBlock) |
bool | createContiguous (FatFile *dirFile, const char *path, uint32_t size) |
bool | createContiguous (const char *path, uint32_t size) |
uint32_t | curCluster () const |
uint32_t | curPosition () const |
bool | dirEntry (dir_t *dir) |
uint16_t | dirIndex () |
uint32_t | dirSize () |
void | dmpFile (print_t *pr, uint32_t pos, size_t n) |
bool | exists (const char *path) |
int16_t | fgets (char *str, int16_t num, char *delim=0) |
uint8_t | fileAttr () const |
uint32_t | fileSize () const |
uint32_t | firstBlock () |
uint32_t | firstCluster () const |
uint8_t | getError () |
bool | getName (char *name, size_t size) |
void | getpos (FatPos_t *pos) |
bool | getSFN (char *name) |
bool | getWriteError () |
bool | isDir () const |
bool | isFile () const |
bool | isHidden () const |
bool | isLFN () const |
bool | isOpen () const |
bool | isReadOnly () const |
bool | isRoot () const |
bool | isRoot32 () const |
bool | isRootFixed () const |
bool | isSubDir () const |
bool | isSystem () const |
void | ls (uint8_t flags=0) |
void | ls (print_t *pr, uint8_t flags=0, uint8_t indent=0) |
bool | mkdir (FatFile *dir, const char *path, bool pFlag=true) |
bool | open (FatFileSystem *fs, const char *path, uint8_t oflag) |
bool | open (FatFile *dirFile, uint16_t index, uint8_t oflag) |
bool | open (FatFile *dirFile, const char *path, uint8_t oflag) |
bool | open (const char *path, uint8_t oflag=O_READ) |
bool | openNext (FatFile *dirFile, uint8_t oflag=O_READ) |
bool | openRoot (FatVolume *vol) |
int | peek () |
bool | printCreateDateTime (print_t *pr) |
int | printField (int16_t value, char term) |
int | printField (uint16_t value, char term) |
int | printField (int32_t value, char term) |
int | printField (uint32_t value, char term) |
size_t | printFileSize (print_t *pr) |
bool | printModifyDateTime (print_t *pr) |
size_t | printName () |
size_t | printName (print_t *pr) |
size_t | printSFN (print_t *pr) |
int | read () |
int | read (void *buf, size_t nbyte) |
int8_t | readDir (dir_t *dir) |
bool | remove () |
bool | rename (FatFile *dirFile, const char *newPath) |
bool | rmdir () |
bool | rmRfStar () |
bool | seekCur (int32_t offset) |
bool | seekEnd (int32_t offset=0) |
bool | seekSet (uint32_t pos) |
void | setpos (FatPos_t *pos) |
bool | sync () |
bool | timestamp (FatFile *file) |
bool | timestamp (uint8_t flags, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
bool | truncate (uint32_t length) |
FatVolume * | volume () const |
int | write (const char *str) |
int | write (uint8_t b) |
Static Private Member Functions | |
static FatFile * | cwd () |
static void | dateTimeCallback (void(*dateTime)(uint16_t *date, uint16_t *time)) |
static void | dateTimeCallbackCancel () |
static uint8_t | dirName (const dir_t *dir, char *name) |
static bool | legal83Char (uint8_t c) |
static void | printFatDate (uint16_t fatDate) |
static void | printFatDate (print_t *pr, uint16_t fatDate) |
static void | printFatTime (uint16_t fatTime) |
static void | printFatTime (print_t *pr, uint16_t fatTime) |
static bool | remove (FatFile *dirFile, const char *path) |
static bool | setCwd (FatFile *dir) |
StdioStream implements a minimal stdio stream.
StdioStream does not support subdirectories or long file names.
|
inline |
Constructor
|
inline |
Clear the stream's end-of-file and error indicators.
int StdioStream::fclose | ( | ) |
Close a stream.
A successful call to the fclose function causes the stream to be flushed and the associated file to be closed. Any unwritten buffered data is written to the file; any unread buffered data is discarded. Whether or not the call succeeds, the stream is disassociated from the file.
|
inline |
Test the stream's end-of-file indicator.
|
inline |
Test the stream's error indicator.
int StdioStream::fflush | ( | ) |
Flush the stream.
If stream is an output stream or an update stream in which the most recent operation was not input, any unwritten data is written to the file; otherwise the call is an error since any buffered input data would be lost.
|
inline |
Get a byte from the stream.
char * StdioStream::fgets | ( | char * | str, |
size_t | num, | ||
size_t * | len = 0 |
||
) |
Get a string from a stream.
The fgets function reads at most one less than the number of characters specified by num from the stream into the array pointed to by str. No additional characters are read after a new-line character (which is retained) or after end-of-file. A null character is written immediately after the last character read into the array.
[out] | str | Pointer to an array of where the string is copied. |
[in] | num | Maximum number of characters including the null character. |
[out] | len | If len is not null and fgets is successful, the length of the string is returned. |
bool StdioStream::fopen | ( | const char * | path, |
const char * | mode | ||
) |
Open a stream.
Open a file and associates the stream with it.
[in] | path | file to be opened. |
[in] | mode | a string that indicates the open mode. |
"r" or "rb" | Open a file for reading. The file must exist. |
"w" or "wb" | Truncate an existing to zero length or create an empty file for writing. |
"wx" or "wbx" | Create a file for writing. Fails if the file already exists. |
"a" or "ab" | Append; open or create file for writing at end-of-file. |
"r+" or "rb+" or "r+b" | Open a file for update (reading and writing). |
"w+" or "w+b" or "wb+" | Truncate an existing to zero length or create a file for update. |
"w+x" or "w+bx" or "wb+x" | Create a file for update. Fails if the file already exists. |
"a+" or "a+b" or "ab+" | Append; open or create a file for update, writing at end-of-file. |
The character 'b' shall have no effect, but is allowed for ISO C standard conformance.
Opening a file with append mode causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to the fseek function.
When a file is opened with update mode, both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file.
|
inline |
Write a byte to a stream.
[in] | c | the byte to be written (converted to an unsigned char). |
int StdioStream::fputs | ( | const char * | str | ) |
Write a string to a stream.
[in] | str | a pointer to the string to be written. |
size_t StdioStream::fread | ( | void * | ptr, |
size_t | size, | ||
size_t | count | ||
) |
Binary input.
Reads an array of up to count elements, each one with a size of size bytes.
[out] | ptr | pointer to area of at least (size*count) bytes where the data will be stored. |
[in] | size | the size, in bytes, of each element to be read. |
[in] | count | the number of elements to be read. |
int StdioStream::fseek | ( | int32_t | offset, |
int | origin | ||
) |
Set the file position for the stream.
[in] | offset | number of offset from the origin. |
[in] | origin | position used as reference for the offset. It is specified by one of the following constants. |
SEEK_SET - Beginning of file.
SEEK_CUR - Current position of the file pointer.
SEEK_END - End of file.
int32_t StdioStream::ftell | ( | ) |
Get the current position in a stream.
size_t StdioStream::fwrite | ( | const void * | ptr, |
size_t | size, | ||
size_t | count | ||
) |
Binary output.
Writes an array of up to count elements, each one with a size of size bytes.
[in] | ptr | pointer to (size*count) bytes of data to be written. |
[in] | size | the size, in bytes, of each element to be written. |
[in] | count | the number of elements to be written. |
|
inline |
Get a byte from the stream.
getc and fgetc are equivalent but getc is in-line so it is faster but require more flash memory.
|
inline |
Write a character.
[in] | c | the character to write. |
|
inline |
Write a string.
[in] | str | the string to be written. |
size_t StdioStream::print | ( | const __FlashStringHelper * | str | ) |
Print a string stored in flash memory.
[in] | str | the string to print. |
|
inline |
Print a floating point number.
[in] | prec | Number of digits after decimal point. |
[in] | val | the number to be printed. |
|
inline |
Print a floating point number.
[in] | prec | Number of digits after decimal point. |
[in] | val | the number to be printed. |
|
inline |
Print a number.
[in] | val | the number to be printed. |
|
inline |
Print a char as a number.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | signed char | n | ) |
print a signed 8-bit integer
[in] | n | number to be printed. |
|
inline |
Print an unsigned 8-bit number.
[in] | n | number to be print. |
int StdioStream::printDec | ( | int16_t | n | ) |
Print a int16_t
[in] | n | number to be printed. |
int StdioStream::printDec | ( | uint16_t | n | ) |
print a uint16_t.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | int32_t | n | ) |
Print a signed 32-bit integer.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | uint32_t | n | ) |
Write an unsigned 32-bit number.
[in] | n | number to be printed. |
|
inline |
Print a double.
[in] | value | The number to be printed. |
[in] | prec | Number of digits after decimal point. |
int StdioStream::printDec | ( | float | value, |
uint8_t | prec | ||
) |
Print a float.
[in] | value | The number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
int StdioStream::printHex | ( | uint32_t | n | ) |
Print HEX
[in] | n | number to be printed as HEX. |
|
inline |
Print HEX with CRLF
[in] | n | number to be printed as HEX. |
|
inline |
Write a CR/LF.
|
inline |
Print a floating point number followed by CR/LF.
[in] | val | the number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a floating point number followed by CR/LF.
[in] | val | the number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print an item followed by CR/LF
[in] | val | the item to be printed. |
|
inline |
Write a byte to a stream.
putc and fputc are equivalent but putc is in-line so it is faster but require more flash memory.
[in] | c | the byte to be written (converted to an unsigned char). |
|
inline |
Write a CR/LF.
bool StdioStream::rewind | ( | ) |
Set position of a stream to the beginning.
The rewind function sets the file position to the beginning of the file. It is equivalent to fseek(0L, SEEK_SET) except that the error indicator for the stream is also cleared.
int StdioStream::ungetc | ( | int | c | ) |
Push a byte back into an input stream.
[in] | c | the byte (converted to an unsigned char) to be pushed back. |
One character of push-back is guaranteed. If the ungetc function is called too many times without an intervening read or file positioning operation on that stream, the operation may fail.
A successful intervening call to a file positioning function (fseek, fsetpos, or rewind) discards any pushed-back characters for the stream.