MPHELL  4.0.0
Macros | Functions
mphell-util.c File Reference

Definition of miscellaneous function. More...

#include "mphell-util.h"
Include dependency graph for mphell-util.c:

Go to the source code of this file.

Macros

#define MAX_MARKER_LEN   50
 

Functions

uint8_t bits_to_nblock (const uint16_t nbits)
 Return the number of blocks required to store a nbits number. More...
 
uint8_t max_size (uint8_t a, uint8_t b)
 Return the max of a and b. More...
 
time_t get_s (struct timespec *start, struct timespec *end)
 Return the elapsed time in second between "start" and "end". More...
 
unsigned int get_ns (struct timespec *start, struct timespec *end)
 Return the elapsed time in nano second to add to the result of get_s(). More...
 
void print_bytes_string_hex (const uint8_t *bytes_string, uint16_t length)
 Print the byte string "bytes_string" under hexadecimal form. More...
 
void bytes_string2hex (char *hex_string, const uint8_t *bytes_string, uint16_t length)
 Convert the byte string "bytes_string" under hexadecimal form. More...
 
void hex_string2bytes (uint8_t *bytes_string, const char *hex_string, uint16_t length)
 Convert the hexadecimal string "hex_string" under bytes string form. More...
 
void bin2hex (const unsigned char *old, const uint32_t oldlen, unsigned char *result)
 
uint32_t hex2bin (const char *in, unsigned char *out)
 Convert an hexadecimal string into a binary string. More...
 
int FindMarker (FILE *infile, const char *marker)
 Find a marker in a file. More...
 
int ReadHex (FILE *infile, char *A, const int Length, char *str)
 Read an hexadecimal string in file "infile". More...
 
void char2bin (char c, uint8_t *b)
 Convert a character into a byte (according to its ascii value) More...
 
void printchar2bin (uint8_t b)
 print a byte More...
 
void string2bin (char *s, uint8_t *output)
 Convert a string into a byte array. More...
 
void printstring2bin (uint8_t *s, uint32_t len)
 Print a byte array. More...
 

Detailed Description

Definition of miscellaneous function.

Definition in file mphell-util.c.

Function Documentation

◆ bits_to_nblock()

uint8_t bits_to_nblock ( const uint16_t  nbits)

Return the number of blocks required to store a nbits number.

Parameters
nbitsNumber of bits
Returns
Number of block required to store a nbits number

Definition at line 29 of file mphell-util.c.

◆ bytes_string2hex()

void bytes_string2hex ( char *  hex_string,
const uint8_t *  bytes_string,
uint16_t  length 
)

Convert the byte string "bytes_string" under hexadecimal form.

Parameters
hex_stringResulting hexadecimal string, must be allocated of size length*2
bytes_stringByte string to convert
lengthLength of bytes_string (in byte)

Definition at line 67 of file mphell-util.c.

◆ char2bin()

void char2bin ( char  c,
uint8_t *  b 
)

Convert a character into a byte (according to its ascii value)

Parameters
ccharacter to convert
bdestination byte

Definition at line 242 of file mphell-util.c.

◆ FindMarker()

int FindMarker ( FILE *  infile,
const char *  marker 
)

Find a marker in a file.

Parameters
infileFilename
markerMarker to find
Returns
O if marker is not find
1 if marker is not find

Definition at line 167 of file mphell-util.c.

◆ get_ns()

long get_ns ( struct timespec *  start,
struct timespec *  end 
)

Return the elapsed time in nano second to add to the result of get_s().

Parameters
startBegin of chrono
endEnd of chrono
Returns
Elapse time in nano second to add to the result of get_s().

Definition at line 48 of file mphell-util.c.

◆ get_s()

time_t get_s ( struct timespec *  start,
struct timespec *  end 
)

Return the elapsed time in second between "start" and "end".

Parameters
startBegin of chrono
endEnd of chrono
Returns
Elapse time in second

Definition at line 39 of file mphell-util.c.

◆ hex2bin()

uint32_t hex2bin ( const char *  in,
unsigned char *  out 
)

Convert an hexadecimal string into a binary string.

Parameters
inHexadecimal string
outBinary string
Returns
Length (int bytes) of "out"

Definition at line 111 of file mphell-util.c.

◆ hex_string2bytes()

void hex_string2bytes ( uint8_t *  bytes_string,
const char *  hex_string,
uint16_t  length 
)

Convert the hexadecimal string "hex_string" under bytes string form.

Parameters
bytes_stringResulting byte string, must be allocated of size length/2
hex_stringHexadecimal string to convert
lengthLength of resulting byte string

Definition at line 78 of file mphell-util.c.

◆ max_size()

int max_size ( uint8_t  a,
uint8_t  b 
)

Return the max of a and b.

Parameters
asize of an element in number blocks (< 256)
bsize of an element in number blocks (< 256)
Returns
Max between a and b

Definition at line 34 of file mphell-util.c.

◆ print_bytes_string_hex()

void print_bytes_string_hex ( const uint8_t *  bytes_string,
uint16_t  length 
)

Print the byte string "bytes_string" under hexadecimal form.

Parameters
bytes_stringByte string to print
lengthLength of bytes_string (in byte)

Definition at line 58 of file mphell-util.c.

◆ printchar2bin()

void printchar2bin ( uint8_t  b)

print a byte

Parameters
bbyte to print

Definition at line 254 of file mphell-util.c.

◆ printstring2bin()

void printstring2bin ( uint8_t *  s,
uint32_t  len 
)

Print a byte array.

Parameters
sbyte array
lenlength of "s"

Definition at line 281 of file mphell-util.c.

◆ ReadHex()

int ReadHex ( FILE *  infile,
char *  A,
const int  Length,
char *  str 
)

Read an hexadecimal string in file "infile".

Parameters
infileFilename
ADestination string
LengthSize in bytes of the string to read
strMarker used to detect the string
Returns
O if marker is not find
1 if marker is not find

Definition at line 196 of file mphell-util.c.

◆ string2bin()

void string2bin ( char *  s,
uint8_t *  output 
)

Convert a string into a byte array.

Parameters
sstring to convert
outputdestination byte array

Definition at line 271 of file mphell-util.c.