embeddedlibrary
reusable software modules for embedded systems
printf Functionality for Buffer Module

Functions

void Push_printf (buffer_t *buf, char *str,...)
 printf implementation to char buffer More...
 
void Push_vprintf (buffer_t *buf, char *str, va_list vars)
 vprintf implementation to char buffer More...
 
void PushBinary16 (buffer_t *buf, uint16_t x)
 Push 16 bit binary number to char buffer. More...
 
void Push_uint16 (buffer_t *buf, uint16_t x)
 Push unsigned integer to char buffer. More...
 
void Push_int16 (buffer_t *buf, int16_t x)
 Push integer to char buffer. More...
 
void Push_uint32 (buffer_t *buf, uint32_t x)
 Push unsigned long integer to char buffer. More...
 
void Push_int32 (buffer_t *buf, int32_t x)
 Push long to char buffer. More...
 
void PushStr (buffer_t *buf, char *str)
 Push char array (string) to char buffer. More...
 
void PushHex (buffer_t *buf, uint16_t x)
 Push 16 bit value to char buffer in hex format. More...
 
void PushFloat (buffer_t *buf, float x)
 Cheap implementation of float to char buffer. More...
 

Detailed Description

buffer_printf.h

Created on: Mar 11, 2014 Author: Michael

Version
1.1 changed naming to match stdint and removed 2Buf from function names
1.2 added l for int32 and b for 16-bit binary

Function Documentation

void Push_int16 ( buffer_t buf,
int16_t  x 
)

Push integer to char buffer.

Note this function is dependent on Push_uint16()

Parameters
[in]bufPointer to char buffer to print int to
[in]xInteger to convert to text
void Push_int32 ( buffer_t buf,
int32_t  x 
)

Push long to char buffer.

Note this function is dependent on Push_uint32()

Parameters
[in]bufPointer to char buffer to print int to
[in]xLong to convert to text
void Push_printf ( buffer_t buf,
char *  str,
  ... 
)

printf implementation to char buffer

Currently supports the following replacement flags:

  • c char, replaces flag with specified ASCII char
  • b binary, replaces flag with Binary representation See PushBinary16()
  • l long, replaces flag with Binary Representation See Push_int32()
  • d signed 16 bit integer, replaces flag with specified int. See Push_int16()
  • e f or g float, replaces flag with specified float See PushFloat()
  • s string, replaces flag with specified null terminated string See PushString()
  • u unsigned 16 bit integer, replaces flag with specified unsigned int See Push_uint16()
  • x 16 bit hex formated integer, replaces flag with 4 digit hex value See PushHex()

Example:

1 buffer_t tx;
2 ...
3 int16_t x = -1;
4 char name[] = "Muhlbaier";
5 Push_printf(&tx, "x = %d, hex - 0x%x, unsigned %u, name = %s);

Would push to the buffer: "x = -1, hex - 0xFFFF, unsigned 65535, name = Muhlbaier"

Parameters
[in]bufPointer to char buffer to print formatted string to
[in]strPointer to null terminated string with replacement flags
[in]...Variable argument list corresponding with replacement flags
void Push_uint16 ( buffer_t buf,
uint16_t  x 
)

Push unsigned integer to char buffer.

Parameters
[in]bufPointer to char buffer to print unsigned int to
[in]xUnsigned integer to convert to text
void Push_uint32 ( buffer_t buf,
uint32_t  x 
)

Push unsigned long integer to char buffer.

Parameters
[in]bufPointer to char buffer to print unsigned long to
[in]xUnsigned integer to convert to text
void Push_vprintf ( buffer_t buf,
char *  str,
va_list  vars 
)

vprintf implementation to char buffer

Same as Push_printf() except with a va_list pointer instead of an actual variable argument list. This allows other functions similar to Push_printf to be implemented.

For example:

1 void LogStr(char * str, ...) {
2  va_list vars;
3  va_start(vars, str);
4  // use Push_vprintf to log to SUBSYS_UART
5  Push_vprintf(SUBSYS_UART, str, vars);
6  va_end(vars);
7 }

See Push_printf()

Parameters
[in]bufPointer to char buffer to print formatted string to
[in]strPointer to null terminated string with replacement flags
[in]varsVariable argument list corresponding with replacement flags
void PushBinary16 ( buffer_t buf,
uint16_t  x 
)

Push 16 bit binary number to char buffer.

Parameters
[in]bufPointer to char buffer to print to
[in]xUnsigned 16-bit integer to convert to text in binary format
void PushFloat ( buffer_t buf,
float  x 
)

Cheap implementation of float to char buffer.

Current implementation will format float as 0.000 by first printing out the integer portion of the float then multiplying the float by 1000 and subtracting the integer portion x 1000 and printing that after the .

Parameters
[in]bufPointer to char buffer to print float to
[in]xFloat value to convert to text
void PushHex ( buffer_t buf,
uint16_t  x 
)

Push 16 bit value to char buffer in hex format.

Will push four char's to the buffer, for example: A0F3

Parameters
[in]bufPointer to char buffer to print hex formatted int to
[in]xInteger to convert to hex
void PushStr ( buffer_t buf,
char *  str 
)

Push char array (string) to char buffer.

Parameters
[in]bufPointer to char buffer to print string to
[in]strPointer to null terminated char array (e.g. string)