AMU Library 3.0
C/C++ library for communicating with AMU (Aerospace Measurement Unit) devices
Loading...
Searching...
No Matches
utils_private.h File Reference
#include <stdint.h>
#include "config.h"
#include "types.h"

Go to the source code of this file.

Macros

#define LOCAL
#define SCPI_DTOSTRE_UPPERCASE   1
#define SCPI_DTOSTRE_ALWAYS_SIGN   2
#define SCPI_DTOSTRE_PLUS_SIGN   4
#define min(a, b)
#define max(a, b)

Functions

char * strnpbrk (const char *str, size_t size, const char *set)
scpi_bool_t compareStr (const char *str1, size_t len1, const char *str2, size_t len2)
scpi_bool_t compareStrAndNum (const char *str1, size_t len1, const char *str2, size_t len2, int32_t *num)
size_t UInt32ToStrBaseSign (uint32_t val, char *str, size_t len, int8_t base, scpi_bool_t sign)
size_t UInt64ToStrBaseSign (uint64_t val, char *str, size_t len, int8_t base, scpi_bool_t sign)
size_t strBaseToInt32 (const char *str, int32_t *val, int8_t base)
size_t strBaseToUInt32 (const char *str, uint32_t *val, int8_t base)
size_t strBaseToInt64 (const char *str, int64_t *val, int8_t base)
size_t strBaseToUInt64 (const char *str, uint64_t *val, int8_t base)
size_t strToFloat (const char *str, float *val)
size_t strToDouble (const char *str, double *val)
scpi_bool_t locateText (const char *str1, size_t len1, const char **str2, size_t *len2)
scpi_bool_t locateStr (const char *str1, size_t len1, const char **str2, size_t *len2)
size_t skipWhitespace (const char *cmd, size_t len)
scpi_bool_t matchPattern (const char *pattern, size_t pattern_len, const char *str, size_t str_len, int32_t *num)
scpi_bool_t matchCommand (const char *pattern, const char *cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value, bool *query)
scpi_bool_t composeCompoundCommand (const scpi_token_t *prev, scpi_token_t *current)
char * SCPI_dtostre (double __val, char *__s, size_t __ssize, unsigned char __prec, unsigned char __flags)
scpi_array_format_t SCPI_GetNativeFormat (void)
uint16_t SCPI_Swap16 (uint16_t val)
uint32_t SCPI_Swap32 (uint32_t val)
uint64_t SCPI_Swap64 (uint64_t val)
size_t BSD_strnlen (const char *s, size_t maxlen)
int OUR_strncasecmp (const char *s1, const char *s2, size_t n)
char * OUR_strndup (const char *s, size_t n)

Macro Definition Documentation

◆ LOCAL

#define LOCAL

Definition at line 51 of file utils_private.h.

◆ max

#define max ( a,
b )
Value:
(((a) > (b)) ? (a) : (b))

Definition at line 106 of file utils_private.h.

◆ min

#define min ( a,
b )
Value:
(((a) < (b)) ? (a) : (b))

Definition at line 102 of file utils_private.h.

◆ SCPI_DTOSTRE_ALWAYS_SIGN

#define SCPI_DTOSTRE_ALWAYS_SIGN   2

Definition at line 73 of file utils_private.h.

◆ SCPI_DTOSTRE_PLUS_SIGN

#define SCPI_DTOSTRE_PLUS_SIGN   4

Definition at line 74 of file utils_private.h.

◆ SCPI_DTOSTRE_UPPERCASE

#define SCPI_DTOSTRE_UPPERCASE   1

Definition at line 72 of file utils_private.h.

Function Documentation

◆ BSD_strnlen()

size_t BSD_strnlen ( const char * s,
size_t maxlen )

Definition at line 734 of file utils.c.

◆ compareStr()

scpi_bool_t compareStr ( const char * str1,
size_t len1,
const char * str2,
size_t len2 )

Compare two strings with exact length

Parameters
str1
len1
str2
len2
Returns
TRUE if len1==len2 and "len" characters of both strings are equal

Definition at line 348 of file utils.c.

◆ compareStrAndNum()

scpi_bool_t compareStrAndNum ( const char * str1,
size_t len1,
const char * str2,
size_t len2,
int32_t * num )

Compare two strings, one be longer but may contains only numbers in that section

Parameters
str1
len1
str2
len2
Returns
TRUE if strings match

Definition at line 368 of file utils.c.

◆ composeCompoundCommand()

scpi_bool_t composeCompoundCommand ( const scpi_token_t * prev,
scpi_token_t * current )

Compose command from previous command anc current command

Parameters
prevpointer to previous command
currentpointer of current command

prev and current should be in the same memory buffer

Definition at line 688 of file utils.c.

◆ locateStr()

scpi_bool_t locateStr ( const char * str1,
size_t len1,
const char ** str2,
size_t * len2 )

◆ locateText()

scpi_bool_t locateText ( const char * str1,
size_t len1,
const char ** str2,
size_t * len2 )

◆ matchCommand()

scpi_bool_t matchCommand ( const char * pattern,
const char * cmd,
size_t len,
int32_t * numbers,
size_t numbers_len,
int32_t default_value,
bool * query )

Compare pattern and command

Parameters
patterneg. [:MEASure]:VOLTage:DC?
cmd- command
len- max search length
Returns
TRUE if pattern matches, FALSE otherwise

Definition at line 505 of file utils.c.

◆ matchPattern()

scpi_bool_t matchPattern ( const char * pattern,
size_t pattern_len,
const char * str,
size_t str_len,
int32_t * num )

Match pattern and str. Pattern is in format UPPERCASElowercase

Parameters
pattern
pattern_len
str
str_len
Returns

Definition at line 479 of file utils.c.

◆ OUR_strncasecmp()

int OUR_strncasecmp ( const char * s1,
const char * s2,
size_t n )

Definition at line 747 of file utils.c.

◆ OUR_strndup()

char * OUR_strndup ( const char * s,
size_t n )

◆ SCPI_dtostre()

char * SCPI_dtostre ( double __val,
char * __s,
size_t __ssize,
unsigned char __prec,
unsigned char __flags )

Definition at line 1017 of file utils.c.

◆ SCPI_GetNativeFormat()

scpi_array_format_t SCPI_GetNativeFormat ( void )

Get native CPU endiannes

Returns

Definition at line 1106 of file utils.c.

◆ SCPI_Swap16()

uint16_t SCPI_Swap16 ( uint16_t val)

Swap 16bit number

Parameters
val
Returns

Definition at line 1121 of file utils.c.

◆ SCPI_Swap32()

uint32_t SCPI_Swap32 ( uint32_t val)

Swap 32bit number

Parameters
val
Returns

Definition at line 1131 of file utils.c.

◆ SCPI_Swap64()

uint64_t SCPI_Swap64 ( uint64_t val)

Swap 64bit number

Parameters
val
Returns

Definition at line 1143 of file utils.c.

◆ skipWhitespace()

size_t skipWhitespace ( const char * cmd,
size_t len )

Count white spaces from the beggining

Parameters
cmd- command
len- max search length
Returns
number of white spaces

Definition at line 410 of file utils.c.

◆ strBaseToInt32()

size_t strBaseToInt32 ( const char * str,
int32_t * val,
int8_t base )

Converts string to signed 32bit integer representation

Parameters
strstring value
val32bit integer result
Returns
number of bytes used in string

Definition at line 274 of file utils.c.

◆ strBaseToInt64()

size_t strBaseToInt64 ( const char * str,
int64_t * val,
int8_t base )

Converts string to signed 64bit integer representation

Parameters
strstring value
val64bit integer result
Returns
number of bytes used in string

Definition at line 298 of file utils.c.

◆ strBaseToUInt32()

size_t strBaseToUInt32 ( const char * str,
uint32_t * val,
int8_t base )

Converts string to unsigned 32bit integer representation

Parameters
strstring value
val32bit integer result
Returns
number of bytes used in string

Definition at line 286 of file utils.c.

◆ strBaseToUInt64()

size_t strBaseToUInt64 ( const char * str,
uint64_t * val,
int8_t base )

Converts string to unsigned 64bit integer representation

Parameters
strstring value
val64bit integer result
Returns
number of bytes used in string

Definition at line 310 of file utils.c.

◆ strnpbrk()

char * strnpbrk ( const char * str,
size_t size,
const char * set )

Find the first occurrence in str of a character in set.

Parameters
str
size
set
Returns

Definition at line 59 of file utils.c.

◆ strToDouble()

size_t strToDouble ( const char * str,
double * val )

Converts string to double (64 bit) representation

Parameters
strstring value
valdouble result
Returns
number of bytes used in string

Definition at line 334 of file utils.c.

◆ strToFloat()

size_t strToFloat ( const char * str,
float * val )

Converts string to float (32 bit) representation

Parameters
strstring value
valfloat result
Returns
number of bytes used in string

Definition at line 322 of file utils.c.

◆ UInt32ToStrBaseSign()

size_t UInt32ToStrBaseSign ( uint32_t val,
char * str,
size_t len,
int8_t base,
scpi_bool_t sign )

Converts signed/unsigned 32 bit integer value to string in specific base

Parameters
valinteger value
strconverted textual representation
lenstring buffer length
baseoutput base
sign
Returns
number of bytes written to str (without '\0')

Definition at line 81 of file utils.c.

◆ UInt64ToStrBaseSign()

size_t UInt64ToStrBaseSign ( uint64_t val,
char * str,
size_t len,
int8_t base,
scpi_bool_t sign )

Converts signed/unsigned 64 bit integer value to string in specific base

Parameters
valinteger value
strconverted textual representation
lenstring buffer length
baseoutput base
sign
Returns
number of bytes written to str (without '\0')

Definition at line 167 of file utils.c.