Alex exoskeleton
ALEX SoftwareDocumentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
CO_comm_helpers.c File Reference
#include "CO_comm_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
Include dependency graph for CO_comm_helpers.c:

Go to the source code of this file.

Functions

int dtpHex (char *strout, int stroutSize, char *bufSdo, int bufLen)
 
int dtsHex (char *bufSdo, int bufSdoSize, char *strin)
 
char * getTok (char *initStr, const char *delim, int *err)
 
void lastTok (char *initStr, const char *delim, int *err)
 
uint32_t getU32 (char *token, uint32_t min, uint32_t max, int *err)
 
int32_t getI32 (char *token, int32_t min, int32_t max, int *err)
 
uint64_t getU64 (char *token, uint64_t min, uint64_t max, int *err)
 
int64_t getI64 (char *token, int64_t min, int64_t max, int *err)
 
float32_t getR32 (char *token, int *err)
 
float64_t getR64 (char *token, int *err)
 
const dataType_tgetDataType (char *token, int *err)
 

Variables

const char spaceDelim [] = " \t\n\r\f\v"
 

Function Documentation

int dtpHex ( char *  strout,
int  stroutSize,
char *  bufSdo,
int  bufLen 
)

Data type print function.

Functions writes binary data from bufSdo to strout (with sprintf). dtpHex outputs in hex format (two hex digits, space separated). There are other dtp functions inside dataTypes[] array.

Parameters
stroutOutput string.
bufSdoInput binary data.
bufLenSize of input binary data.
Returns
Number of bytes written to strout.

Definition at line 44 of file CO_comm_helpers.c.

int dtsHex ( char *  bufSdo,
int  bufSdoSize,
char *  strin 
)

Data type scan function.

Functions scans input string string and writes binary data to bufSdo. dtsHex scans from hex format (two hex digits, space separated). There are other dts functions inside dataTypes[] array.

Parameters
bufSdoOutput binary data.
strinInput string.
Returns
Number of bytes written to bufSdo, 0 on failure.

Definition at line 110 of file CO_comm_helpers.c.

const dataType_t* getDataType ( char *  token,
int *  err 
)

Get data type from token.

Token must exactly match one of the 'syntax' from dataTypes[].

Parameters
tokenInput string.
errInput and returning parameter sets to true in case of error. If err is already true, function returns 0 immediately.
Returns
Number.

Definition at line 385 of file CO_comm_helpers.c.

int32_t getI32 ( char *  token,
int32_t  min,
int32_t  max,
int *  err 
)

Definition at line 290 of file CO_comm_helpers.c.

int64_t getI64 ( char *  token,
int64_t  min,
int64_t  max,
int *  err 
)

Definition at line 328 of file CO_comm_helpers.c.

float32_t getR32 ( char *  token,
int *  err 
)

Definition at line 347 of file CO_comm_helpers.c.

float64_t getR64 ( char *  token,
int *  err 
)

Definition at line 366 of file CO_comm_helpers.c.

char* getTok ( char *  initStr,
const char *  delim,
int *  err 
)

Get token from currently parsing string.

Function calls thread safe strtok_r function and returns token. getTok itself may be used from one thread only.

Parameters
initStrSame as first argument to strtok_r.
delimSame as second argument to strtok_r.
errInput and returning parameter sets to true in case of error. If err is already true, function returns NULL immediately.
Returns
Next token or NULL.

Definition at line 241 of file CO_comm_helpers.c.

uint32_t getU32 ( char *  token,
uint32_t  min,
uint32_t  max,
int *  err 
)

Get number from token.

Token must contain no other characters and number must be inside limits.

Parameters
tokenInput string.
minMinimum value for the output number.
maxMaximum value for the output number.
errInput and returning parameter sets to true in case of error. If err is already true, function returns 0 immediately.
Returns
Number.

Definition at line 271 of file CO_comm_helpers.c.

uint64_t getU64 ( char *  token,
uint64_t  min,
uint64_t  max,
int *  err 
)

Definition at line 309 of file CO_comm_helpers.c.

void lastTok ( char *  initStr,
const char *  delim,
int *  err 
)

Verify, if there are no more tokens.

Function calls getTok and if there is another token and that token doesn't start with '#', it sets err to 1. (Comments are ignored.)

Parameters
initStrSame as in getTok.
delimSame as in getTok.
errSame as in getTok.

Definition at line 257 of file CO_comm_helpers.c.

Variable Documentation

const char spaceDelim[] = " \t\n\r\f\v"

Definition at line 36 of file CO_comm_helpers.c.