ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
util.c File Reference

set of utility functions More...

#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <string.h>
#include "util.h"

Go to the source code of this file.

Functions

void util_debug (util_debug_func_t function, void *user_data, const char *format,...)
 
void util_hexdump (const char dir, const unsigned char *buf, size_t len, util_debug_func_t function, void *user_data)
 
unsigned char util_get_dt (const char *parent, const char *name)
 
uint8_t util_get_uid (unsigned int *bitmap, uint8_t max)
 
void util_clear_uid (unsigned int *bitmap, uint8_t id)
 

Detailed Description

set of utility functions

Author
Gilbert Brault

Definition in file util.c.

Function Documentation

void util_clear_uid ( unsigned int *  bitmap,
uint8_t  id 
)

Clear id bit in bitmap

Parameters
bitmapmap of bits
idbit rank to clear

Definition at line 172 of file util.c.

void util_debug ( util_debug_func_t  function,
void *  user_data,
const char *  format,
  ... 
)

create a str debug message using format and then call function(str,user_data)

Parameters
functionfunction to call
user_datadata for the "function"
formatformat string template of str string

Definition at line 56 of file util.c.

References timeout_data::user_data.

Referenced by bt_gatt_client_prepare_write(), can_read_data(), can_write_data(), disconnect_cb(), discover_chrcs_cb(), discover_descs(), discover_descs_cb(), discover_incl_cb(), discover_primary_cb(), discover_secondary_cb(), encode_pdu(), exchange_mtu_cb(), handle_conf(), handle_error_rsp(), handle_rsp(), handle_signed(), init_complete(), process_service_changed(), service_changed_cb(), service_changed_complete(), service_changed_register_cb(), and timeout_cb().

unsigned char util_get_dt ( const char *  parent,
const char *  name 
)

Helper for getting the dirent type in case readdir

Parameters
parentprefix to build full path
namesuffix to builld full path
Returns
DT_UNKNOWN or DT_DIR if parent/name is a DIR

Definition at line 130 of file util.c.

uint8_t util_get_uid ( unsigned int *  bitmap,
uint8_t  max 
)

Helpers for bitfield operations

Find unique id in range from 1 to max but no bigger then sizeof(int) * 8. ffs() is used since it is POSIX standard

Parameters
bitmapmap of bits
maxmax bit position
Returns

Definition at line 152 of file util.c.

void util_hexdump ( const char  dir,
const unsigned char *  buf,
size_t  len,
util_debug_func_t  function,
void *  user_data 
)

hexadecimal dump utility: create the str hex string and then call function(str,user_data)

Parameters
dirfirst char of str
bufbuffer to convert to hex (str)
lensize of buffer (should be less than or equal to 16)
functionfunction to call with (str,user_data)
user_datapointer to pass to function

Definition at line 81 of file util.c.

References timeout_data::user_data.

Referenced by can_read_data(), and can_write_data().