AM261x MCU+ SDK: String Utilities

| AM261x MCU+ SDK 26.00.00 |

Files | Functions | Typedefs
String Utilities
APIs for Unibase Binding

## 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

typedef ub_bytearray8_t 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

typedef ub_bytearray6_t 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

  console | select output to consol
  debug | select output to debug memory
  buf | reference to the data buffer
  size | size of the data to be dumped.
  addr | offset 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

  a | a byte value
  astr | 2-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

  bstr | hex string array separated by delim
  bytes | byte array to return the result
  delim | a delimiter character
  len | length 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

  bmac | mac address in binary format.
  smac | the 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

  smac | mac address in string format
  bmac | the 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

  bsid | stream id in binary format
  ssid | the 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

  ssid | stream id in string format; either lower case format or upper scale format
  bsid | the 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

  input | byte array in string format; either lower or upper case hex
  dest | the converted byte array. The caller is responsible to reserve enough size of memory with 'dest'.
  base | used 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

  dest | the converted byte array in string format; lower case hex The caller is responsible to reserve enough size of memory with 'dest'.
  bytes | byte array to be converted
  len | number 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

  astr | string
  maxn | max 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

  astr | string
  maxn | max 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

  line | command line string
  argv | the result of argment array
  maxargc | maximum number of arguments

## ◆ ub_strncpy()

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

copy a string

Returns
  0:success, -1:fail

Parameters

  dest | destination string space, must have maxlen size including null
  src | source string
  maxlen | max length