HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
Data Structures | Macros | Functions
Main / Communication

Control the communication with the computer. More...

Data Structures

struct  comm_SyncVar
 

Macros

#define comm_SendDebugMessageDecimated(decimation, format, ...)
 Sends a debug message to the computer, with decimation. This macro is useful to print human-readable text, in a fast loop, to avoid overloading the communication bus, or the computer. More...
 

Functions

void comm_Init (void)
 Init the communication manager. More...
 
void comm_Step (void)
 Updates the communication manager. Send the bytes waiting in the TX buffer, and process the bytes received. More...
 
void comm_NotifyReady (void)
 Sends a packet to notify the PC that the board just (re)started. This informs the PC software that the board is ready, and that the variables list can be retrieved. More...
 
void comm_monitorVar (const char name[], void *address, comm_VarType type, uint8_t size, comm_VarAccess access)
 Adds a monitored variable to the list, with its address. More...
 
void comm_monitorVarFunc (const char name[], comm_VarType type, uint8_t size, void(*getFunc)(void), void(*setFunc)(void))
 Adds a monitored variable to the list, with getter/setter functions. If the getter and setter are set to an actual function address (not NULL), the variable will be READWRITE. If the getter is NULL but setter is not NULL, the variable will be WRITEONLY. If the getter is not NULL the setter is NULL, the variable will be READONLY. If the getter and setter are both NULL, the variable will not be added to the variables list. More...
 
void comm_monitorBool (const char name[], bool *address, comm_VarAccess access)
 Adds a monitored bool variable to the list, with its address. More...
 
void comm_monitorUint8 (const char name[], uint8_t *address, comm_VarAccess access)
 Adds a monitored uint8_t variable to the list, with its address. More...
 
void comm_monitorInt8 (const char name[], int8_t *address, comm_VarAccess access)
 Adds a monitored int8_t variable to the list, with its address. More...
 
void comm_monitorUint16 (const char name[], uint16_t *address, comm_VarAccess access)
 Adds a monitored uint16_t variable to the list, with its address. More...
 
void comm_monitorInt16 (const char name[], int16_t *address, comm_VarAccess access)
 Adds a monitored int16_t variable to the list, with its address. More...
 
void comm_monitorUint32 (const char name[], uint32_t *address, comm_VarAccess access)
 Adds a monitored uint32_t variable to the list, with its address. More...
 
void comm_monitorInt32 (const char name[], int32_t *address, comm_VarAccess access)
 Adds a monitored int32_t variable to the list, with its address. More...
 
void comm_monitorUint64 (const char name[], uint64_t *address, comm_VarAccess access)
 Adds a monitored uint64_t variable to the list, with its address. More...
 
void comm_monitorInt64 (const char name[], int64_t *address, comm_VarAccess access)
 Adds a monitored int64_t variable to the list, with its address. More...
 
void comm_monitorFloat (const char name[], float *address, comm_VarAccess access)
 Adds a monitored float variable to the list, with its address. More...
 
void comm_monitorDouble (const char name[], double *address, comm_VarAccess access)
 Adds a monitored double variable to the list, with its address. More...
 
void comm_monitorBoolFunc (const char name[], bool(*getFunc)(void), void(*setFunc)(bool))
 Adds a monitored bool variable to the list, with getter/setter. More...
 
void comm_monitorUint8Func (const char name[], uint8_t(*getFunc)(void), void(*setFunc)(uint8_t))
 Adds a monitored uint8_t variable to the list, with getter/setter. More...
 
void comm_monitorInt8Func (const char name[], int8_t(*getFunc)(void), void(*setFunc)(int8_t))
 Adds a monitored int8_t variable to the list, with getter/setter. More...
 
void comm_monitorUint16Func (const char name[], uint16_t(*getFunc)(void), void(*setFunc)(uint16_t))
 Adds a monitored uint16_t variable to the list, with getter/setter. More...
 
void comm_monitorInt16Func (const char name[], int16_t(*getFunc)(void), void(*setFunc)(int16_t))
 Adds a monitored int16_t variable to the list, with getter/setter. More...
 
void comm_monitorUint32Func (const char name[], uint32_t(*getFunc)(void), void(*setFunc)(uint32_t))
 Adds a monitored uint32_t variable to the list, with getter/setter. More...
 
void comm_monitorInt32Func (const char name[], int32_t(*getFunc)(void), void(*setFunc)(int32_t))
 Adds a monitored int32_t variable to the list, with getter/setter. More...
 
void comm_monitorUint64Func (const char name[], uint64_t(*getFunc)(void), void(*setFunc)(uint64_t))
 Adds a monitored uint64_t variable to the list, with getter/setter. More...
 
void comm_monitorInt64Func (const char name[], int64_t(*getFunc)(void), void(*setFunc)(int64_t))
 Adds a monitored int64_t variable to the list, with getter/setter. More...
 
void comm_monitorFloatFunc (const char name[], float(*getFunc)(void), void(*setFunc)(float))
 Adds a monitored float variable to the list, with getter/setter. More...
 
void comm_monitorDoubleFunc (const char name[], double(*getFunc)(void), void(*setFunc)(double))
 Adds a monitored double variable to the list, with getter/setter. More...
 
void comm_LockSyncVarsList (void)
 Locks the monitored variables, so it can be used. After the call to this function, adding variables will not be possible anymore. The PC will not be able to get the variables list until this function is called. More...
 
void comm_SendDebugMessage (const char *format,...)
 Sends a debug message to the computer. More...
 

Detailed Description

Control the communication with the computer.

This module controls all the communication logic between the board and the computer. It uses a specific communication protocol between the computer and the board, with a system of messages. Thanks to this, the the MATLAB application is able to get the value of selected variables on the STM, and is even capable of modifiying them remotely.

Make sure that the files communication.h/.c are up-to-date with the Excel spreadsheet "Protocol description.xlsx".

Call comm_Init() to setup this module. Its interrupt function will be called automatically when a message arrives, or periodically when the data streaming is enabled.

Macro Definition Documentation

◆ comm_SendDebugMessageDecimated

#define comm_SendDebugMessageDecimated (   decimation,
  format,
  ... 
)
Value:
do \
{ \
static int comm_decim##__COUNTER__ = 0; \
if(comm_decim##__COUNTER__++ % decimation == 0) \
{ \
comm_SendDebugMessage(format, ##__VA_ARGS__); \
} \
} while(0)

Sends a debug message to the computer, with decimation. This macro is useful to print human-readable text, in a fast loop, to avoid overloading the communication bus, or the computer.

Parameters
decimationthis macro will actually print once out of decimation, and do nothing otherwise.
formatformat string. See the printf() documentation for format specification.
...variables to be printed in the format string.

Function Documentation

◆ comm_Init()

void comm_Init ( void  )

Init the communication manager.

◆ comm_LockSyncVarsList()

void comm_LockSyncVarsList ( void  )

Locks the monitored variables, so it can be used. After the call to this function, adding variables will not be possible anymore. The PC will not be able to get the variables list until this function is called.

◆ comm_monitorBool()

void comm_monitorBool ( const char  name[],
bool *  address,
comm_VarAccess  access 
)

Adds a monitored bool variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorBoolFunc()

void comm_monitorBoolFunc ( const char  name[],
bool(*)(void)  getFunc,
void(*)(bool)  setFunc 
)

Adds a monitored bool variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorDouble()

void comm_monitorDouble ( const char  name[],
double *  address,
comm_VarAccess  access 
)

Adds a monitored double variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorDoubleFunc()

void comm_monitorDoubleFunc ( const char  name[],
double(*)(void)  getFunc,
void(*)(double)  setFunc 
)

Adds a monitored double variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorFloat()

void comm_monitorFloat ( const char  name[],
float *  address,
comm_VarAccess  access 
)

Adds a monitored float variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorFloatFunc()

void comm_monitorFloatFunc ( const char  name[],
float(*)(void)  getFunc,
void(*)(float)  setFunc 
)

Adds a monitored float variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorInt16()

void comm_monitorInt16 ( const char  name[],
int16_t *  address,
comm_VarAccess  access 
)

Adds a monitored int16_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorInt16Func()

void comm_monitorInt16Func ( const char  name[],
int16_t(*)(void)  getFunc,
void(*)(int16_t)  setFunc 
)

Adds a monitored int16_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorInt32()

void comm_monitorInt32 ( const char  name[],
int32_t *  address,
comm_VarAccess  access 
)

Adds a monitored int32_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorInt32Func()

void comm_monitorInt32Func ( const char  name[],
int32_t(*)(void)  getFunc,
void(*)(int32_t)  setFunc 
)

Adds a monitored int32_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorInt64()

void comm_monitorInt64 ( const char  name[],
int64_t *  address,
comm_VarAccess  access 
)

Adds a monitored int64_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorInt64Func()

void comm_monitorInt64Func ( const char  name[],
int64_t(*)(void)  getFunc,
void(*)(int64_t)  setFunc 
)

Adds a monitored int64_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorInt8()

void comm_monitorInt8 ( const char  name[],
int8_t *  address,
comm_VarAccess  access 
)

Adds a monitored int8_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorInt8Func()

void comm_monitorInt8Func ( const char  name[],
int8_t(*)(void)  getFunc,
void(*)(int8_t)  setFunc 
)

Adds a monitored int8_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorUint16()

void comm_monitorUint16 ( const char  name[],
uint16_t *  address,
comm_VarAccess  access 
)

Adds a monitored uint16_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorUint16Func()

void comm_monitorUint16Func ( const char  name[],
uint16_t(*)(void)  getFunc,
void(*)(uint16_t)  setFunc 
)

Adds a monitored uint16_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorUint32()

void comm_monitorUint32 ( const char  name[],
uint32_t *  address,
comm_VarAccess  access 
)

Adds a monitored uint32_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorUint32Func()

void comm_monitorUint32Func ( const char  name[],
uint32_t(*)(void)  getFunc,
void(*)(uint32_t)  setFunc 
)

Adds a monitored uint32_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorUint64()

void comm_monitorUint64 ( const char  name[],
uint64_t *  address,
comm_VarAccess  access 
)

Adds a monitored uint64_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorUint64Func()

void comm_monitorUint64Func ( const char  name[],
uint64_t(*)(void)  getFunc,
void(*)(uint64_t)  setFunc 
)

Adds a monitored uint64_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorUint8()

void comm_monitorUint8 ( const char  name[],
uint8_t *  address,
comm_VarAccess  access 
)

Adds a monitored uint8_t variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorUint8Func()

void comm_monitorUint8Func ( const char  name[],
uint8_t(*)(void)  getFunc,
void(*)(uint8_t)  setFunc 
)

Adds a monitored uint8_t variable to the list, with getter/setter.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_monitorVar()

void comm_monitorVar ( const char  name[],
void *  address,
comm_VarType  type,
uint8_t  size,
comm_VarAccess  access 
)

Adds a monitored variable to the list, with its address.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
addressa pointer to the variable to monitor.
typethe type of the variable.
sizethe size of the variable [bytes].
accessthe access rights to this variable (READONLY, WRITEONLY, or READWRITE).

◆ comm_monitorVarFunc()

void comm_monitorVarFunc ( const char  name[],
comm_VarType  type,
uint8_t  size,
void(*)(void)  getFunc,
void(*)(void)  setFunc 
)

Adds a monitored variable to the list, with getter/setter functions. If the getter and setter are set to an actual function address (not NULL), the variable will be READWRITE. If the getter is NULL but setter is not NULL, the variable will be WRITEONLY. If the getter is not NULL the setter is NULL, the variable will be READONLY. If the getter and setter are both NULL, the variable will not be added to the variables list.

Parameters
namethe description of the variable, as it should be displayed to the user. It should also include the unit, if relevant.
typethe type of the variable.
sizethe size of the variable [bytes].
getFuncfunction pointer on the getter function.
setFuncfunction pointer on the setter function.

◆ comm_NotifyReady()

void comm_NotifyReady ( void  )

Sends a packet to notify the PC that the board just (re)started. This informs the PC software that the board is ready, and that the variables list can be retrieved.

◆ comm_SendDebugMessage()

void comm_SendDebugMessage ( const char *  format,
  ... 
)

Sends a debug message to the computer.

Parameters
formatformat string.
...variables to be printed in the format string.

◆ comm_Step()

void comm_Step ( void  )

Updates the communication manager. Send the bytes waiting in the TX buffer, and process the bytes received.