AM64x MCU+ SDK  10.00.00
String Utilities

Introduction

Files

file  ub_strutils.h
 Utility functions for strings.
 

Functions

void ub_hexdump (bool console, bool debug, unsigned char *buf, int size, int addr)
 dump out data in hex format to the console More...
 
void ub_byte2hexstr (uint8_t a, char *astr)
 convert a byte to 2-digit hex string More...
 
int ub_hexstr2barray (const char *bstr, uint8_t *bytes, const char delim, int len)
 convert array of 2-digit hex string More...
 
char * ub_bmac2smac (ub_macaddr_t bmac, char *smac)
 convert a binary type mac address to a string type mac address('XX:XX:XX:XX:XX:XX' format) More...
 
uint8_t * ub_smac2bmac (const char *smac, ub_macaddr_t bmac)
 convert a string type mac address('XX:XX:XX:XX:XX:XX' format) to a binary type mac address. More...
 
char * ub_bsid2ssid (ub_streamid_t bsid, char *ssid)
 convert a binary type stream id to a string type stream id ('XX:XX:XX:XX:XX:XX:XX:XX' format) More...
 
uint8_t * ub_ssid2bsid (const char *ssid, ub_streamid_t bsid)
 convert a string type stream id('XX:XX:XX:XX:XX:XX:XX:XX' format) to a binary type stream id More...
 
int ub_str2bytearray (uint8_t *dest, const char *input, uint8_t base)
 convert a string type byte array('01,00,1e,00,00,03,....02,00,01') to a byte array More...
 
char * ub_bytearray2str (char *dest, const unsigned char *bytes, int len)
 convert a byte array to a string type byte array('01,00,1e,00,00,03,....02,00,01') More...
 
int ub_find_nospace (const char *astr, int maxn)
 look for non space charcter and return the number of passed characters More...
 
int ub_find_space (const char *astr, int maxn)
 look for space charcter and return the number of passed characters More...
 
int ub_command_line_parser (char *line, char *argv[], int maxargc)
 parse a command line string and make argc,argv[] for main function, More...
 
int ub_strncpy (char *dest, const char *src, int maxlen)
 copy a string More...
 

Typedefs

typedef uint8_t ub_bytearray8_t[8]
 8-byte binary array More...
 
typedef ub_bytearray8_t ub_streamid_t
 8-byte binary array is used for Stream ID More...
 
typedef uint8_t ub_bytearray6_t[6]
 6-byte binary array More...
 
typedef ub_bytearray6_t ub_macaddr_t
 6-byte binary array is used for MAC Address More...
 

Typedef Documentation

◆ ub_bytearray8_t

typedef uint8_t ub_bytearray8_t[8]

8-byte binary array

◆ ub_streamid_t

8-byte binary array is used for Stream ID

◆ ub_bytearray6_t

typedef uint8_t ub_bytearray6_t[6]

6-byte binary array

◆ ub_macaddr_t

6-byte binary array is used for MAC Address

Function Documentation

◆ ub_hexdump()

void ub_hexdump ( bool  console,
bool  debug,
unsigned char *  buf,
int  size,
int  addr 
)

dump out data in hex format to the console

Parameters
consoleselect output to consol
debugselect output to debug memory
bufreference to the data buffer
sizesize of the data to be dumped.
addroffset address at the top of the data

◆ ub_byte2hexstr()

void ub_byte2hexstr ( uint8_t  a,
char *  astr 
)

convert a byte to 2-digit hex string

Parameters
aa byte value
astr2-byte string pointer to return 2-digit hex string

◆ ub_hexstr2barray()

int ub_hexstr2barray ( const char *  bstr,
uint8_t *  bytes,
const char  delim,
int  len 
)

convert array of 2-digit hex string

Parameters
bstrhex string array separated by delim
bytesbyte array to return the result
delima delimiter character
lenlength of bytes
Returns
the number of bytes converted into the byte array

◆ ub_bmac2smac()

char* ub_bmac2smac ( ub_macaddr_t  bmac,
char *  smac 
)

convert a binary type mac address to a string type mac address('XX:XX:XX:XX:XX:XX' format)

Returns
mac address in string format, the same pointer as smac
Parameters
bmacmac address in binary format.
smacthe converted mac addrsss.
Note
smac must have at least 18 bytes.

◆ ub_smac2bmac()

uint8_t* ub_smac2bmac ( const char *  smac,
ub_macaddr_t  bmac 
)

convert a string type mac address('XX:XX:XX:XX:XX:XX' format) to a binary type mac address.

Returns
a reference of the mac address in binary format, the same pointer as bmac.
Parameters
smacmac address in string format
bmacthe converted mac address in binary format

◆ ub_bsid2ssid()

char* ub_bsid2ssid ( ub_streamid_t  bsid,
char *  ssid 
)

convert a binary type stream id to a string type stream id ('XX:XX:XX:XX:XX:XX:XX:XX' format)

Returns
the converted stream id in string format, the same pointer as sidstr
Parameters
bsidstream id in binary format
ssidthe converted stream id in string format.
Note
ssid must have at least 24 bytes

◆ ub_ssid2bsid()

uint8_t* ub_ssid2bsid ( const char *  ssid,
ub_streamid_t  bsid 
)

convert a string type stream id('XX:XX:XX:XX:XX:XX:XX:XX' format) to a binary type stream id

Returns
a reference of the mac address in binary format, the same pointer as bsid
Parameters
ssidstream id in string format; either lower case format or upper scale format
bsidthe converted stream id in binary format

◆ ub_str2bytearray()

int ub_str2bytearray ( uint8_t *  dest,
const char *  input,
uint8_t  base 
)

convert a string type byte array('01,00,1e,00,00,03,....02,00,01') to a byte array

Returns
the length of the returned array
Parameters
inputbyte array in string format; either lower or upper case hex
destthe converted byte array. The caller is responsible to reserve enough size of memory with 'dest'.
baseused for strtoul conversion, must be '10','16'
Note
the conversion is stopped when it meets non-convertible string Whatever non-convertible characters are treated as a delimiter.

◆ ub_bytearray2str()

char* ub_bytearray2str ( char *  dest,
const unsigned char *  bytes,
int  len 
)

convert a byte array to a string type byte array('01,00,1e,00,00,03,....02,00,01')

Returns
the converted byte array.
Parameters
destthe converted byte array in string format; lower case hex The caller is responsible to reserve enough size of memory with 'dest'.
bytesbyte array to be converted
lennumber of bytes to be converted to string
Note
the conversion is stopped when the value of len is reached

◆ ub_find_nospace()

int ub_find_nospace ( const char *  astr,
int  maxn 
)

look for non space charcter and return the number of passed characters

Parameters
astrstring
maxnmax number of characters to be checked
Note
whitespace is either of space,tab,CR,LF
Returns
the index of the first non-whitespace charcter

◆ ub_find_space()

int ub_find_space ( const char *  astr,
int  maxn 
)

look for space charcter and return the number of passed characters

Returns
the index of the first whitespace charcter appears.
Parameters
astrstring
maxnmax number of characters to be checked
Note
whitespace is either of space,tab,CR,LF
whitespaces quoted by ' or " are skipped, and they can be escaped with back slash

◆ ub_command_line_parser()

int ub_command_line_parser ( char *  line,
char *  argv[],
int  maxargc 
)

parse a command line string and make argc,argv[] for main function,

Returns
the number of parameters (argc)
Parameters
linecommand line string
argvthe result of argment array
maxargcmaximum number of arguments

◆ ub_strncpy()

int ub_strncpy ( char *  dest,
const char *  src,
int  maxlen 
)

copy a string

Returns
0:success, -1:fail
Parameters
destdestination string space, must have maxlen size including null
srcsource string
maxlenmax length