util: Useful utils for the enduser (p_util_...)


Functions

int p_util_escape (unsigned char *out_data, const unsigned char *in_data, size_t len, size_t maxlen)
 Escaping data.
int p_util_unescape (unsigned char *out_data, const unsigned char *in_data, size_t len, size_t maxlen)
 Unescaping data.
int p_util_decode_dot (uint8_t *out, const char *dotted_str, size_t len)
 Decoding a dotted string to an array of bytes.
char * p_util_acl2str (const uint8_t *acl_type, char *out)
 Decoding 3 characters out of 2 bytes.
uint8_t * p_util_str2acl (const char *in, uint8_t *acl_type)
 Coding 3 characters into 2 bytes.
void p_util_location2raw (uint8_t root[16], const char *node1, const char *node2, const char *node3, const char *node4, int x, int y, int z, uint8_t deviation, unsigned char location[44])
 Encode / Calculate a location-string.
void p_util_raw2location (uint8_t root[16], char node1[10], char node2[10], char node3[10], char node4[10], int *x, int *y, int *z, uint8_t *deviation, const unsigned char location[44])
 Decoding / parse a location-string.
int p_util_3to2 (uint8_t *out, const char *in, size_t len)
 : Coding strings with 3to2
int p_util_2to3 (char *out, const uint8_t *in, size_t len)
 : Decoding strings with 2to3
int p_util_crc16 (const char *data, size_t length, uint8_t *phb, uint8_t *plb)
 Calculates CRC16.
int p_util_crc16_append (char *data, size_t length)
 Calculates CRC16 and appends the result to data.
int p_util_crc16_check (const char *data, size_t length)
 Tests whether the CRC is correct.
int p_util_get_local_interfaces (uint32_t ip[], uint32_t broadcast[], size_t max)
 Get all local IP-address and according broadcast-addresses.
int p_util_get_local_addresses (uint32_t *ip, uint32_t *broadcast)
 Get a single local IP-address and according broadcast-address.
uint32_t p_util_getmstime ()
 Get a timestamp.
void p_util_sleepms (unsigned long milliseconds)
 Lets the program sleep.
char * p_util_strerr (int error)
 returns a little description for libparticle error numbers
void p_util_perror (const char *str)
 print the current error message
char * p_util_location2WKT (const unsigned char location[44], char *wkt, size_t n)
 returns the GPS location in WKT (Well known Text) Format

Function Documentation

int p_util_2to3 ( char *  out,
const uint8_t *  in,
size_t  len 
)

: Decoding strings with 2to3

Function to decode code in longer byte-arrays with the 2-to-3 decoding.

Parameters:
*in Pointer to the input (byte-array)
*out Pointer to the output string
*len Length of the input data.
Returns:
Length of the decoded data

int p_util_3to2 ( uint8_t *  out,
const char *  in,
size_t  len 
)

: Coding strings with 3to2

Function to encode code longer stings with the 3-to-2 coding.

Parameters:
*in Pointer to the Input string
*out Pointer to the output (byte-array)
*len Length of the input data.
Returns:
Length of the encoded data

char* p_util_acl2str ( const uint8_t *  acl_type,
char *  out 
)

Decoding 3 characters out of 2 bytes.

Function to decode three characters out of two bytes. out can be set to NULL if result should only be returned and not stored.

Parameters:
*acl_type 2 byte Input
*out Pointer, where the decodes 3 characters should be stored
Returns:
out

int p_util_crc16 ( const char *  data,
size_t  length,
uint8_t *  phb,
uint8_t *  plb 
)

Calculates CRC16.

Calculates CRC16 using the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1)

Parameters:
*data Buffer to calculate CRC for
length Length of data in data
*phb Initial value for the high byte
*plb Initial value for the low byte
Returns:
1 on success, -1 on error

int p_util_crc16_append ( char *  data,
size_t  length 
)

Calculates CRC16 and appends the result to data.

Calculates CRC16 using the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1). The result will be stored in the last two bytes of data.

Parameters:
*data Buffer to calculate CRC for
length Length of data in data
Returns:
1 on success, -1 on error

int p_util_crc16_check ( const char *  data,
size_t  length 
)

Tests whether the CRC is correct.

Parameters:
*data Buffer to be checked
length Length of data in data
Returns:
1 if CRC is OK, 0 if CRC is wrong and -1 on error.

int p_util_decode_dot ( uint8_t *  out,
const char *  dotted_str,
size_t  len 
)

Decoding a dotted string to an array of bytes.

Parameters:
out Pointer to the byte array where the result is stored
dotted_str Pointer to the dotted string which should be decoded
len Maximum length of the out array
Returns:
Length of out

int p_util_escape ( unsigned char *  out_data,
const unsigned char *  in_data,
size_t  len,
size_t  maxlen 
)

Escaping data.

Escaping reserved symbols from in_data.

Parameters:
in_data Pointer to the data that should be escaped
out_data Pointer to the escaped result
len Length of in_data
maxlen Maximum length which is reserved for out_data
Returns:
Length of out_data

int p_util_get_local_addresses ( uint32_t *  ip,
uint32_t *  broadcast 
)

Get a single local IP-address and according broadcast-address.

Get the IP-address from a local network adaptor. If at least one non-loopback device is found, the addresses for the first non-loopback device will be returned. If no non-loopback device is found, the address from a loopback-device will be returned.

Parameters:
ip Pointer to an uint32_t array, where the local IP should be stored
broadcast Pointer to an uint32_t array, where the according broadcast-address should be stored
Returns:
array length

int p_util_get_local_interfaces ( uint32_t  ip[],
uint32_t  broadcast[],
size_t  max 
)

Get all local IP-address and according broadcast-addresses.

Gets the IP-addresses from all local network adaptors.

Parameters:
ip Pointer to an uint32_t array, where the IP addresses should be stored
broadcast Pointer to an uint32_t array, where the according broadcast-addresses should be stored
max maximum array length

uint32_t p_util_getmstime (  ) 

Get a timestamp.

Returns:
timestamp (milliseconds)

void p_util_location2raw ( uint8_t  root[16],
const char *  node1,
const char *  node2,
const char *  node3,
const char *  node4,
int  x,
int  y,
int  z,
uint8_t  deviation,
unsigned char  location[44] 
)

Encode / Calculate a location-string.

This function takes the information about the root, 4 nodes, x, y and z-values and the deviation and calculates a location string, which is according to this information. A location string has 44 bytes.

The first 16 bytes of the location-string will be the 16 bytes of the root-information.

After that, 6 bytes are reserved for each of the 4 nodes, which have 9 characters and will be 3-to-2 encoded.

Bytes 41, 42 and 43 are for the x, y and z-value, which will be encoded with AB_ENCODE

The last byte is the deviation.

Parameters:
root Pointer to the root (16 byte)
node1 Pointer to node 1 (9 byte chars)
node2 Pointer to node 2 (9 byte chars)
node3 Pointer to node 3 (9 byte chars)
node4 Pointer to node 4 (9 byte chars)
x x-value
y y-value
z z-value
deviation The known deviation of the 3 x-, y- and z-values
location Pointer to the place, where the calculated location should be stored.

char* p_util_location2WKT ( const unsigned char  location[44],
char *  wkt,
size_t  n 
)

returns the GPS location in WKT (Well known Text) Format

Parameters:
location the raw location to decode
wkt the string to store the wkt in.
n the length of wkt.
Returns:
a pointer to the supplied wkt buffer or NULL on error.

void p_util_perror ( const char *  str  ) 

print the current error message

Parameters:
str error prefix.

void p_util_raw2location ( uint8_t  root[16],
char  node1[10],
char  node2[10],
char  node3[10],
char  node4[10],
int *  x,
int *  y,
int *  z,
uint8_t *  deviation,
const unsigned char  location[44] 
)

Decoding / parse a location-string.

This function takes a location-string and decodes the stored information (root, 4 nodes, x, y, z and deviation) See p_util_location2raw for more information about the location-string and it's calculation.

Parameters:
root Pointer to the root (16 byte)
node1 Pointer to node 1 (10 byte, 9 for chars + 0-termination)
node2 Pointer to node 2 (10 byte, 9 for chars + 0-termination)
node3 Pointer to node 3 (10 byte, 9 for chars + 0-termination)
node4 Pointer to node 4 (10 byte, 9 for chars + 0-termination)
x x-value
y y-value
z z-value
deviation The known deviation of the 3 x-, y- and z-values
location Pointer to the location-string to be parsed
See also:
p_util_location2raw

void p_util_sleepms ( unsigned long  milliseconds  ) 

Lets the program sleep.

Parameters:
milliseconds How long should the program sleep?

uint8_t* p_util_str2acl ( const char *  in,
uint8_t *  acl_type 
)

Coding 3 characters into 2 bytes.

Function to encode three characters into two bytes. acl_type can be set to NULL if result should only be returned and not stored.

Parameters:
*in Input string
*acl_type Where 2 byte encoded type is stored
Returns:
acl_type

char* p_util_strerr ( int  error  ) 

returns a little description for libparticle error numbers

Parameters:
error Number of the error that should be described

int p_util_unescape ( unsigned char *  out_data,
const unsigned char *  in_data,
size_t  len,
size_t  maxlen 
)

Unescaping data.

Unescaping in_data. Reserved symbols will be put back into the string.

Parameters:
in_data Pointer to the data that should be unescaped
out_data Pointer to the unescaped result
len Lenght of in_data
maxlen Maximum lenght which is reserved for out_data
Returns:
Length of out_data


Generated on Tue Apr 10 15:22:26 2007 for libparticle by  doxygen 1.5.1