The formatter function provided by weAutSys are a (quite) faster alternative to using stdio format strings.
Formatting either return void (a) or a pointer (b) to the character after the last one set by the documented formating process.
In the void case (a) the formatting functions are changing a fixed and documented number of characters in the destination string respectively character array.
In the return pointer case (b) the (next) character position pointed to will have been set 0. This automatically provides an end of string if not overridden by using the returned pointer. Anyway in cases (b) the caller has to provide space for this trailing zero.
Functions | |
void | eightHexs (char *begin, uint32_t value) |
Set an eight digit hexadecimal number with leading zeroes into a string. | |
void | eightHexsBE (char *begin, uint32_t value) |
Set an eight digit big endian hexadecimal number with into a string. | |
char * | form16BytSeq (char *s, uint8_t *seq) |
Format a sequence of 16 bytes in four hex groups and as characters. | |
char * | formDateIso (char *s, date_t *tDat) |
Format a date (date_t structure) | |
char * | formFATdate (char *s, uint16_t fatDate) |
Format a FAT date. | |
char * | formFATtime (char *s, uint16_t fatTime) |
Format a FAT time. | |
char * | formIpAdd (char *s, uip_ipaddr_t ipAddr) |
Format an ipV4 Ethernet address. | |
char * | formIpConf (char *s, ipConf_t *ipConf) |
Format an IP configuration (w/o DHCP) | |
char * | formIpConfDHCP (char *s, ipConf_t *ipConf) |
Format an IP configuration, the DHCP part. | |
char * | formMacAdd (char *s, eth_addr_t *mac) |
Format a MAC address. | |
char * | formModTelegr (char *s, struct modTelegr_t *modTeleg) |
Format a Modbus telegram. | |
char * | formN20BytSeq (char *s, uint8_t *seq, uint8_t n) |
Format a sequence of 0..20 bytes in five hex groups and as characters. | |
char * | formTimDur (char *s, datdur_t *tRun) |
Format a time (datdur_t structure) as duration. | |
char * | formTimOfD (char *s, datdur_t *tTim) |
Format a time (datdur_t structure) as time of day. | |
char * | formWdShort (char *s, uint8_t wd) |
Format the day of week as short clear text. | |
void | fourDigs (char *begin, uint16_t value) |
Set a four decimal digit number into a string. | |
void | fourHexs (char *begin, uint16_t value) |
Set a four digit hexadecimal number with leading zeroes into a string. | |
void | fourHexsBE (char *begin, uint16_t value) |
Set an four digit big endian hexadecimal big endian number into a string. | |
void | threeDigs (char *begin, uint16_t value) |
Set a three decimal digit number with leading zeroes into a string. | |
void | threeDigsB (char *begin, uint8_t value) |
Set a three decimal digit number with leading zeroes into a string. | |
void | twoDigs (char *begin, uint8_t value) |
Set a two decimal digit number with leading zeroes into a string. | |
void | twoHexs (char *s, uint8_t value) __attribute__((always_inline)) |
Set a two hexadecimal digit number with leading zeroes into a string. | |
Variables | |
char * | wDaysShort [] |
flash array of the (flash) short weekdays |
char* formMacAdd | ( | char * | s, |
eth_addr_t * | mac | ||
) |
Format a MAC address.
The MAC address from the structure mac
will be formatted as 11:22:33:44:55:66 delivering 18 characters in s
including a trailing zero.
s | start position within string respectively char array |
mac | the (6 byte) address structure |
char* formIpAdd | ( | char * | s, |
uip_ipaddr_t | ipAddr | ||
) |
Format an ipV4 Ethernet address.
The IP address from the structure ipAddr
supplied will be formatted as 112.12.0.1 delivering 8..16 characters including a trailing zero.
s | start position within string respectively char array (length 16) |
ipAddr | the (uint16-t[2] big endian) address structure |
char* formIpConf | ( | char * | s, |
ipConf_t * | ipConf | ||
) |
Format an IP configuration (w/o DHCP)
This function formats the IP configuration ipConf
to a multi-line text.
The length of the text delivered (to *s
) is up to 165 characters including a trailing zero.
The output does not contain the DHCP information.
s | start position within string respectively char array |
ipConf | pointer to the IP configuration (addresses, masks, flags) |
char* formIpConfDHCP | ( | char * | s, |
ipConf_t * | ipConf | ||
) |
Format an IP configuration, the DHCP part.
This function formats the IP configuration to a multi-line text.
The length of the text delivered (to *s
) is up to 65 characters including a trailing zero.
The output does only contain the DHCP information.
s | start position within string respectively char array |
ipConf | pointer to the IP configuration (addresses, masks, flags) |
char* formFATtime | ( | char * | s, |
uint16_t | fatTime | ||
) |
Format a FAT time.
This function formats a 16 bit time delivered as (old fashined) FAT time structure.
The format will be
"23:59:58"
.
The length of the text delivered (to *s
) is 9 characters including a trailing zero.
Note that the seconds in that (old DOS) FAT time format are 2 s increments so no odd value for seconds is possible.
s | start position within string resp. char array |
fatTime | the 16 bit FAT time structure |
char* formFATdate | ( | char * | s, |
uint16_t | fatDate | ||
) |
Format a FAT date.
This function formats a 16 bit delivered as (old fashined) FAT date structure (upper 16 bits 16..31).
The format (ISO 8601 / EN 28601) will be
"2009-01-31"
.
The length of the text delivered (to *s
) is 11 characters including a trailing zero.
s | start position within string resp. char array |
fatDate | the 16 bit FAT date structure |
char* formTimDur | ( | char * | s, |
datdur_t * | tRun | ||
) |
Format a time (datdur_t structure) as duration.
This function formats a time structure datdur_t as duration.
The format will be
"1234d 23h59m59s"
. 16 characters will be put to *s
including a trailing zero.
s | start position within string resp. char array (not NULL!) |
tRun | pointer to the time structure (not NULL!) |
char* formTimOfD | ( | char * | s, |
datdur_t * | tTim | ||
) |
Format a time (datdur_t structure) as time of day.
This function formats a time structure datdur_t as time of day or clock time.
The format will be
"23:59:59"
. 9 characters will be put to *s
including a trailing zero.
The field d
of tTim
is not used for the result.
s | start position within string resp. char array |
tTim | pointer to the time structure |
char* formWdShort | ( | char * | s, |
uint8_t | wd | ||
) |
Format the day of week as short clear text.
This function puts the three character short English day of week into s
.
The format for wd
1..7 will be
"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"
.
4 characters will be put *s
including a trailing zero.
For wd
outside 1..7 just *s
will be set 0 and s
is returned.
s | start position within string resp. char array |
wd | 1..7 is Sunday .. Saturday |
char* formDateIso | ( | char * | s, |
date_t * | tDat | ||
) |
Format a date (date_t structure)
This function formats a date (structure date_t).
The format (ISO 8601 / EN 28601) will be
"2009-01-31"
.
11 characters will be put *s
including a trailing zero.
The field wd
is not used for the result.
s | start position within string resp. char array |
tDat | pointer to the time structure |
void threeDigs | ( | char * | begin, |
uint16_t | value | ||
) |
Set a three decimal digit number with leading zeroes into a string.
This function converts a number 0..999 into three characters "000" .. "999". Values of 1000 and above will get "***".
begin | start position within the target string resp. char array |
value | the value to convert |
void threeDigsB | ( | char * | begin, |
uint8_t | value | ||
) |
Set a three decimal digit number with leading zeroes into a string.
This function converts an eight bit number 0..255 into three characters "000" .. "255".
begin | start position within the target string resp. char array |
value | the value to convert |
void fourDigs | ( | char * | begin, |
uint16_t | value | ||
) |
Set a four decimal digit number into a string.
This function converts a number 0..9999 into three characters " 0" .. "9999". Values of 10000 and above will get " **0".
begin | start position within the target string resp. char array |
value | the value to convert |
void twoDigs | ( | char * | begin, |
uint8_t | value | ||
) |
Set a two decimal digit number with leading zeroes into a string.
This function converts a number 0..99 into two characters "00" .. "99". Values of 100 and above will get "**".
begin | start position within the target string resp. char array |
value | the value to convert |
void twoHexs | ( | char * | s, |
uint8_t | value | ||
) |
Set a two hexadecimal digit number with leading zeroes into a string.
This function converts a number 0..255 into two characters "00" .. "FF".
s | start position within the target string resp. char array |
value | the value to convert |
void fourHexs | ( | char * | begin, |
uint16_t | value | ||
) |
Set a four digit hexadecimal number with leading zeroes into a string.
This function converts a 16 bit number into four characters "0000" .. "FFFF".
begin | start position within the target string resp. char array |
value | the value to convert |
void fourHexsBE | ( | char * | begin, |
uint16_t | value | ||
) |
Set an four digit big endian hexadecimal big endian number into a string.
This function does the same as eightHexs except for the wrong andianess of the value
parameter.
begin | start position within the target string resp. char array |
value | the big endian value to convert |
void eightHexs | ( | char * | begin, |
uint32_t | value | ||
) |
Set an eight digit hexadecimal number with leading zeroes into a string.
This function converts a 32 bit number into eight characters "00000000" .. "FFFFFFFF".
begin | start position within the target string resp. char array |
value | the value to convert |
void eightHexsBE | ( | char * | begin, |
uint32_t | value | ||
) |
Set an eight digit big endian hexadecimal number with into a string.
This function does the same as eightHexs except for the wrong andianess of the value
parameter.
begin | start position within the target string resp. char array |
value | the big endian value to convert |
char* form16BytSeq | ( | char * | s, |
uint8_t * | seq | ||
) |
Format a sequence of 16 bytes in four hex groups and as characters.
This function formats the first 16 bytes pointed to by seq
in four groups of 8 hexadecimal digits separated by space followed by said 16 bytes as 16 character text. There control characters (0..0x20 and 0x80..0xA0) are put as blank space.
The result's length is 55 characters including a trailing blank and terminating 0.
The result looks like 20746578 74206F6E 20612032 4720534D text on a 2G SM
s | start position within string respectively char array |
seq | pointer to the 16 byte sequence to be formatted |
char* formN20BytSeq | ( | char * | s, |
uint8_t * | seq, | ||
uint8_t | n | ||
) |
Format a sequence of 0..20 bytes in five hex groups and as characters.
This function formats the c
(max. 20) bytes pointed to by seq
in five groups of 8 hexadecimal digits separated by dot (.) followed by 20 bytes as 20 character text. In this text field control characters (0..0x20 and 0x80..0xA0) as well as the bytes [>=
n
] are put as blank space.
The maximum length of the result (for n=20
) is 68 characters including a trailing blank and terminating 0.
The result (for n=17
) looks like 20746578.74206F6E.20612032.4720534D.43....... text on a 2G SMC
s | start position within string resp. char array |
seq | pointer to the up to 20 byte sequence to be formatted |
n | 0..20 number of bytes |
char* formModTelegr | ( | char * | s, |
struct modTelegr_t * | modTeleg | ||
) |
Format a Modbus telegram.
This function formats a Modbus TCP/IP telegram provided as structure modTeleg
.. This consists of seven bytes called MBAB header plus 11..13 bytes called PDU. From the MBAB the sequence number (#), bytes to follow (+) and the unit (u) are formatted. The PDU part starts with the function code (fx) followed by 0..6 words (16 bit) The number and interpretation of the latter is dependent of the function code and direction (request / response).
The format returned is
" #.... +.... u.. fx.. .... .... .... .... .... .... .... "
All values are formated hexadecimal; 16 bit numbers are interpreted as (wrong) big endian.
s | start position within string resp. char array |
modTeleg | pointer to the Modbus TCP/IP telegram |