MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
MFM::ByteSink Class Referenceabstract

#include <ByteSink.h>

Inheritance diagram for MFM::ByteSink:
MFM::LineTailByteSink< LINES, COLUMNS > MFM::CharBufferByteSink< BUFSIZE > MFM::DiscardBytes MFM::FileByteSink MFM::LineTailByteSink< LINES, BYTES_PER_LINE > MFM::OverflowableCharBufferByteSink< BUFSIZE > MFM::TeeByteSink MFM::OverflowableCharBufferByteSink< 16+2 > MFM::OverflowableCharBufferByteSink< 64+2 > MFM::OverflowableCharBufferByteSink< BYTES_PER_LINE > MFM::OverflowableCharBufferByteSink< MAX_PATH_LEN >

Public Member Functions

virtual void WriteBytes (const u8 *data, const u32 len)=0
 
virtual s32 CanWrite ()=0
 
virtual void WriteByte (u8 ch)
 
virtual void WriteNewline ()
 
void Print (const char *str, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (const u8 *str, u32 len, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (s32 decimal, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (u32 decimal, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (s64 decimal, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (u64 decimal, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (u32 num, Format::Type code, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (s32 num, Format::Type code, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (u64 num, Format::Type code, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (s64 num, Format::Type code, s32 fieldWidth=-1, u8 padChar= ' ')
 
void Print (ByteSerializable &byteSerializble, s32 argument=0)
 
void Println ()
 
void Println (u8 byte)
 
void Println (const char *str)
 
void Println (const u8 *str, u32 len)
 
void Println (s32 decimal)
 
void Println (u32 decimal)
 
void Println (u32 decimal, Format::Type code)
 
void Println (ByteSerializable &byteSerializable, s32 argument=0)
 
void Printf (const char *format,...)
 
void Vprintf (const char *format, va_list &ap)
 

Detailed Description

ByteSink is an abstract base class for byte stream output mechanisms. Concrete instantiations of ByteSink must implement two methods: WriteBytes to output a given sequence of bytes, in its entirety, blocking if need be to do so, and CanWrite to return the minimum number of bytes that can currently be written via WriteBytes without having it block.

Member Function Documentation

virtual s32 MFM::ByteSink::CanWrite ( )
pure virtual
void MFM::ByteSink::Print ( const char *  str,
s32  fieldWidth = -1,
u8  padChar = ' ' 
)

Print the contents of a null-terminated string to the ByteSink. Compare to ::Print(const u8 * str, u32 len).

Parameters
strA pointer to the null-terminate string to print.
Fails:
#NULL_POINTER if str is null.
void MFM::ByteSink::Print ( const u8 *  str,
u32  len,
s32  fieldWidth = -1,
u8  padChar = ' ' 
)

Print str, an array of bytes of length len, to the ByteSink. Compare to ::Print(const char * str).

Parameters
strA pointer to the byte array to print. Must be of length (at least) len; does not need to be null-terminated.
lenThe number of bytes in str to output. May be zero.
Fails:
NULL_POINTER if str is null.
void MFM::ByteSink::Print ( u32  num,
Format::Type  code,
s32  fieldWidth = -1,
u8  padChar = ' ' 
)

Print num, in a format selected by code, to the current xmit packet of face. The possible format codes are:

  • #DEC: Print one to ten bytes containing the base-10 representation of the 32 bits of num, using the ASCII characters '0' through '9'. See the 'd' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code DEC, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
  • #HEX: Print one to eight bytes containing the base-16 representation of the 32 bits of num, using the ASCII characters '0' through '9' to represent 0 through 9, and 'A' through 'F' to represent 10 through 15. See the 'x' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code HEX, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
  • #OCT: Print one to eleven bytes containing the base-8 representation of the 32 bits of num, using the ASCII characters '0' through '7' to represent 0 through 7. See the 'x' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code OCT, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
  • #BIN: Print one to 32 bytes containing the base-2 representation of the 32 bits of num, using the ASCII characters '0' and '1' to represent 0 and 1. See the 'b' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code BIN, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
  • #B36: Print one to six bytes containing the base-36 representation of the 32 bits of num, using the ASCII characters '0' through '9' to represent 0 through 9, and 'A' through 'Z' to represent 10 through 35. See the 't' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code B36, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
  • #BEU32: Print exactly four bytes containing the 32 bits of num, with the four bytes in 'big endian order', also known as 'network order'. See the 'l' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code BEU32, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
    BEU32 is called a 'binary' code, but it must not be confused with #BIN. With BEU32, each of the four output bytes may each contain any possible bit pattern, whereas with code #BIN each output byte is either the ASCII code for '0' or the ASCII code for '1'.
  • #BEU16: Print exactly two bytes containing the low-order 16 bits of num, with the two bytes in 'big endian order', also known as 'network order'. See the 'h' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code BEU16, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
    BEU16 is called a 'binary' code, but it must not be confused with #BIN. With BEU16, each of the two output bytes may each contain any possible bit pattern, whereas with code #BIN each output byte is either the ASCII code for '0' or the ASCII code for '1'.
  • #BYTE: Print exactly one byte containing the low-order 8 bits of num. See the 'c' code in #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was printed with code BYTE, and in #facePrintf(u8 face, const char * format,...) for an alternate way to print in this representation.
    BYTE is called a 'binary' code, but it must not be confused with #BIN. With BYTE, the output byte may each contain any possible bit pattern, whereas with code #BIN each output byte is either the ASCII code for '0' or the ASCII code for '1'.

In addition to those codes, it is also possible to print in other bases between 2 and 36, if there is call to do so. For example, using a code value of 13 will select printing in base 13, using the ASCII characters '0' through '9' and 'A' through 'C'.

Parameters
numA 32 bit number to be printed in a particular format.
codeWhat format to use (see above).
Fails:
BAD_FORMAT_ARG If code is an illegal code. The legal codes are #BEU32, #BEU16 or #BYTE, or any value from 2 to 36 (which includes #DEC, #HEX, #OCT, #BIN, and #B36).

XXX Sample all-ASCII printable packet generation:

Example:
void myHandler(u8 *) {
facePrint(SOUTH,"L 1234 in:");
facePrint(SOUTH," base 10="); facePrint(SOUTH, 1234, DEC); // Prints 1234
facePrint(SOUTH," base 16="); facePrint(SOUTH, 1234, HEX); // Prints 4D2
facePrint(SOUTH," base 8="); facePrint(SOUTH, 1234, OCT); // Prints 2322
facePrint(SOUTH," base 2="); facePrint(SOUTH, 1234, BIN); // Prints 10011010010
facePrint(SOUTH," base 36="); facePrint(SOUTH, 1234, B36); // Prints YA
facePrintln(SOUTH);
}

XXX Sample binary packet generation:

Example:
void setup() { /\* nothing to do *\/ }
void loop() { // Print a packet containing exactly eight bytes:
facePrint(ALL_FACES,"t"); // 1 byte containing an ASCII 't'
facePrint(ALL_FACES,millis(),BEU32); // +4 bytes of board uptime in big endian
facePrint(ALL_FACES,random(10000),BEU16); // +2 bytes of a random number 0..9999 in big endian
facePrintln(); // +1 byte containing an ASCII newline '\n'
delay(1000); // Wait a second, then do it again.
}
void MFM::ByteSink::Print ( s32  num,
Format::Type  code,
s32  fieldWidth = -1,
u8  padChar = ' ' 
)

The same as #Print(u32 num, Format code), except that if num is negative and code is DEC, then prints num as a negative, with a leading '-'.

Parameters
numA 32 bit number to be printed in a particular format.
codeWhat format to use
Fails:
BAD_FORMAT_ARG If code is an illegal code. The legal codes are #BEU32, #BEU16 or #BYTE, or any value from 2 to 36 (which includes #DEC, #HEX, #OCT, #BIN, and #B36).
Example:
XXX
...
int signedNum = -1;
u32 unsignedNum = signedNum;
facePrint(WEST,signedNum,DEC); // Prints "-1": Signed num with code DEC
facePrint(WEST,unsignedNum,DEC); // Prints "4294967295": Unsigned num with code DEC
facePrint(WEST,signedNum,HEX); // Prints "FFFFFFFF": Non-DEC codes are always
facePrint(WEST,unsignedNum,HEX); // Prints "FFFFFFFF": printed as unsigned
...
void MFM::ByteSink::Println ( const char *  str)
inline
Parameters
strSame as #Print(const char * str) followed by #Println().
void MFM::ByteSink::Println ( const u8 *  str,
u32  len 
)
inline
Parameters
lenSame as #Print(const u8 * str,u32 len) followed by #Println().
void MFM::ByteSink::Println ( s32  decimal)
inline
Parameters
decimalSame as #Print(s32 decimal)followed by #Println().
void MFM::ByteSink::Println ( u32  decimal)
inline
Parameters
decimalSame as #Print(u32 decimal) followed by #Println().
void MFM::ByteSink::Println ( u32  decimal,
Format::Type  code 
)
inline
Parameters
codeSame as #Print(u32 decimal, Format::Type code) followed by #Println().
virtual void MFM::ByteSink::WriteByte ( u8  ch)
inlinevirtual

Overridable convenience method Same as

WriteBytes(&ch, 1);
virtual void MFM::ByteSink::WriteBytes ( const u8 *  data,
const u32  len 
)
pure virtual

Write the len consecutive bytes starting at data to the ByteSink, blocking if and as long as necessary to do so. It is not an error for len to be zero and WriteBytes will never block if it is.

Fails:
OUT_OF_ROOM if there is permanently not enough room to perform the requested output
Fails:
IO_ERROR if some other unrecoverable output error occurs.
See Also
CanWrite

Implemented in MFM::DiscardBytes, MFM::TeeByteSink, MFM::LineTailByteSink< LINES, BYTES_PER_LINE >, MFM::LineTailByteSink< LINES, COLUMNS >, MFM::FileByteSink, MFM::CharBufferByteSink< BUFSIZE >, MFM::OverflowableCharBufferByteSink< BUFSIZE >, MFM::OverflowableCharBufferByteSink< 16+2 >, MFM::OverflowableCharBufferByteSink< MAX_PATH_LEN >, MFM::OverflowableCharBufferByteSink< 64+2 >, and MFM::OverflowableCharBufferByteSink< BYTES_PER_LINE >.

virtual void MFM::ByteSink::WriteNewline ( )
inlinevirtual

Overridable convenience method Same as

WriteByte('\n');

The documentation for this class was generated from the following files: