weAut_01 / weAutSys    R 2.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Functions | Variables
Formatters
+ + Utilities and helpers + +

Overview

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

Function Documentation

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.

Parameters:
sstart position within string respectively char array
macthe (6 byte) address structure
Returns:
pointer to the (0-) character following the formatted MAC-address
See also:
formIpAdd
formIpConf
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.

Parameters:
sstart position within string respectively char array (length 16)
ipAddrthe (uint16-t[2] big endian) address structure
Returns:
pointer to the (0-) character following the formatted address
See also:
formMacAdd
formIpConf
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.

Parameters:
sstart position within string respectively char array
ipConfpointer to the IP configuration (addresses, masks, flags)
Returns:
pointer to the (0-) character following the formatted configuration
See also:
formMacAdd
formIPAdd
formIpConfDHCP
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.

Parameters:
sstart position within string respectively char array
ipConfpointer to the IP configuration (addresses, masks, flags)
Returns:
pointer to the (0-) character following the formatted configuration
See also:
formMacAdd
formIPAdd
formIpConf
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.

Parameters:
sstart position within string resp. char array
fatTimethe 16 bit FAT time structure
Returns:
pointer to the (0-) character following the formatted time
See also:
getFATtime()
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.

Parameters:
sstart position within string resp. char array
fatDatethe 16 bit FAT date structure
Returns:
pointer to the (0-) character following the formatted date
See also:
getFATtime()
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.

Parameters:
sstart position within string resp. char array (not NULL!)
tRunpointer to the time structure (not NULL!)
Returns:
points to the (0-) character behind the formated duration
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.

Parameters:
sstart position within string resp. char array
tTimpointer to the time structure
Returns:
points to the (0-) character behind the formated duration
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.

Parameters:
sstart position within string resp. char array
wd1..7 is Sunday .. Saturday
Returns:
points to the (0-) character behind the formated day of week
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.

Parameters:
sstart position within string resp. char array
tDatpointer to the time structure
Returns:
points to the (0-) character behind the formated day of week
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 "***".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
fourDigs(char*, uint8_t)
divWByVal1000(uint16_t)
divWByVal10toByte(uint16_t)
threeDigsB
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".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
fourDigs(char*, uint8_t)
divWByVal1000(uint16_t)
divWByVal10toByte(uint16_t)
threeDigs
Examples:
main.c.
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".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
threeDigs(char*, uint8_t)
fourHexs((char*, uint16_t)
divWByVal1000(uint16_t)
divWByVal10toByte(uint16_t)
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 "**".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
threeDigs(char*, uint16_t)
divByVal10(uint8_t)
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".

Parameters:
sstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
threeDigs(char*, uint16_t)
fourHexs((char*, uint16_t)
divByVal10(uint8_t)
Examples:
main.c.
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".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
twoHexs(char*, uint8_t)
threeDigs(char*, uint16_t)
eightHexs(char *, uint32_t)
divByVal10(uint8_t)
Examples:
main.c.
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.

Parameters:
beginstart position within the target string resp. char array
valuethe 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".

Parameters:
beginstart position within the target string resp. char array
valuethe value to convert
See also:
twoDigs(char*, uint8_t)
twoHexs(char*, uint8_t)
threeDigs(char*, uint16_t)
fourHexs(char *, uint16_t)
eightHexsBE(char *, uint32_t)
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.

Parameters:
beginstart position within the target string resp. char array
valuethe 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

Parameters:
sstart position within string respectively char array
seqpointer to the 16 byte sequence to be formatted
Returns:
points to the (0-) character behind the formated result
See also:
formN20BytSeq
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

Parameters:
sstart position within string resp. char array
seqpointer to the up to 20 byte sequence to be formatted
n0..20 number of bytes
Returns:
points to the (0-) character behind the formated result
See also:
form16BytSeq
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.

Parameters:
sstart position within string resp. char array
modTelegpointer to the Modbus TCP/IP telegram
Returns:
points to the (0-) character behind the formated result