CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
Heartbeat consumer

CANopen Heartbeat consumer protocol. More...

+ Collaboration diagram for Heartbeat consumer:

Files

file  CO_HBconsumer.h
 CANopen Heartbeat consumer protocol.
 

Data Structures

struct  CO_HBconsNode_t
 One monitored node inside CO_HBconsumer_t. More...
 
struct  CO_HBconsumer_t
 Heartbeat consumer object. More...
 

Enumerations

enum  CO_HBconsumer_state_t { CO_HBconsumer_UNCONFIGURED = 0x00U , CO_HBconsumer_UNKNOWN = 0x01U , CO_HBconsumer_ACTIVE = 0x02U , CO_HBconsumer_TIMEOUT = 0x03U }
 Heartbeat state of a node. More...
 

Functions

CO_ReturnError_t CO_HBconsumer_init (CO_HBconsumer_t *HBcons, CO_EM_t *em, CO_HBconsNode_t *monitoredNodes, uint8_t monitoredNodesCount, OD_entry_t *OD_1016_HBcons, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdxStart, uint32_t *errInfo)
 Initialize Heartbeat consumer object.
 
void CO_HBconsumer_initCallbackPre (CO_HBconsumer_t *HBcons, void *object, void(*pFunctSignal)(void *object))
 Initialize Heartbeat consumer callback function.
 
void CO_HBconsumer_initCallbackNmtChanged (CO_HBconsumer_t *HBcons, uint8_t idx, void *object, void(*pFunctSignal)(uint8_t nodeId, uint8_t idx, CO_NMT_internalState_t NMTstate, void *object))
 Initialize Heartbeat consumer NMT changed callback function.
 
void CO_HBconsumer_initCallbackHeartbeatStarted (CO_HBconsumer_t *HBcons, uint8_t idx, void *object, void(*pFunctSignal)(uint8_t nodeId, uint8_t idx, void *object))
 Initialize Heartbeat consumer started callback function.
 
void CO_HBconsumer_initCallbackTimeout (CO_HBconsumer_t *HBcons, uint8_t idx, void *object, void(*pFunctSignal)(uint8_t nodeId, uint8_t idx, void *object))
 Initialize Heartbeat consumer timeout callback function.
 
void CO_HBconsumer_initCallbackRemoteReset (CO_HBconsumer_t *HBcons, uint8_t idx, void *object, void(*pFunctSignal)(uint8_t nodeId, uint8_t idx, void *object))
 Initialize Heartbeat consumer remote reset detected callback function.
 
void CO_HBconsumer_process (CO_HBconsumer_t *HBcons, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process Heartbeat consumer object.
 
int8_t CO_HBconsumer_getIdxByNodeId (CO_HBconsumer_t *HBcons, uint8_t nodeId)
 Get the heartbeat producer object index by node ID.
 
CO_HBconsumer_state_t CO_HBconsumer_getState (CO_HBconsumer_t *HBcons, uint8_t idx)
 Get the current state of a heartbeat producer by the index in OD 0x1016.
 
int8_t CO_HBconsumer_getNmtState (CO_HBconsumer_t *HBcons, uint8_t idx, CO_NMT_internalState_t *nmtState)
 Get the current NMT state of a heartbeat producer by the index in OD 0x1016.
 

Detailed Description

CANopen Heartbeat consumer protocol.

Heartbeat consumer monitors Heartbeat messages from remote nodes. If any monitored node don't send his Heartbeat in specified time, Heartbeat consumer sends emergency message. If all monitored nodes are operational, then variable allMonitoredOperational inside CO_HBconsumer_t is set to true. Monitoring starts after the reception of the first HeartBeat (not bootup).

Heartbeat set up is done by writing to the OD registers 0x1016. To setup heartbeat consumer by application, use

ODR_t odRet = OD_set_u32(entry, subIndex, val, false);
static ODR_t OD_set_u32(const OD_entry_t *entry, uint8_t subIndex, uint32_t val, bool_t odOrig)
Set uint32_t variable in Object Dictionary, see OD_set_value.
Definition CO_ODinterface.h:605
ODR_t
Return codes from OD access functions.
Definition CO_ODinterface.h:129
See also
NMT and Heartbeat

Enumeration Type Documentation

◆ CO_HBconsumer_state_t

Heartbeat state of a node.

Enumerator
CO_HBconsumer_UNCONFIGURED 

Consumer entry inactive.

CO_HBconsumer_UNKNOWN 

Consumer enabled, but no heartbeat received yet.

CO_HBconsumer_ACTIVE 

Heartbeat received within set time.

CO_HBconsumer_TIMEOUT 

No heatbeat received for set time.

Function Documentation

◆ CO_HBconsumer_init()

CO_ReturnError_t CO_HBconsumer_init ( CO_HBconsumer_t * HBcons,
CO_EM_t * em,
CO_HBconsNode_t * monitoredNodes,
uint8_t monitoredNodesCount,
OD_entry_t * OD_1016_HBcons,
CO_CANmodule_t * CANdevRx,
uint16_t CANdevRxIdxStart,
uint32_t * errInfo )

Initialize Heartbeat consumer object.

Function must be called in the communication reset section.

Parameters
HBconsThis object will be initialized.
emEmergency object.
monitoredNodesArray of monitored nodes, must be defined externally.
monitoredNodesCountSize of the above array, usually equal to number of array elements in OD 0x1016, valid values are 1 to 127
OD_1016_HBconsOD entry for 0x1016 - "Consumer heartbeat time", entry is required, IO extension will be applied.
CANdevRxCAN device for Heartbeat reception.
CANdevRxIdxStartStarting index of receive buffer in the above CAN device. Number of used indexes is equal to monitoredNodesCount.
[out]errInfoAdditional information in case of error, may be NULL.
Returns
CO_ReturnError_t CO_ERROR_NO in case of success.

◆ CO_HBconsumer_initCallbackPre()

void CO_HBconsumer_initCallbackPre ( CO_HBconsumer_t * HBcons,
void * object,
void(* pFunctSignal )(void *object) )

Initialize Heartbeat consumer callback function.

Function initializes optional callback function, which should immediately start processing of CO_HBconsumer_process() function. Callback is called after HBconsumer message is received from the CAN bus.

Parameters
HBconsThis object.
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_HBconsumer_initCallbackNmtChanged()

void CO_HBconsumer_initCallbackNmtChanged ( CO_HBconsumer_t * HBcons,
uint8_t idx,
void * object,
void(* pFunctSignal )(uint8_t nodeId, uint8_t idx, CO_NMT_internalState_t NMTstate, void *object) )

Initialize Heartbeat consumer NMT changed callback function.

Function initializes optional callback function, which is called when NMT state from the remote node changes.

Parameters
HBconsThis object.
idxindex of the node in HBcons object (only when CO_CONFIG_HB_CONS_CALLBACK_MULTI is enabled)
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL.
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_HBconsumer_initCallbackHeartbeatStarted()

void CO_HBconsumer_initCallbackHeartbeatStarted ( CO_HBconsumer_t * HBcons,
uint8_t idx,
void * object,
void(* pFunctSignal )(uint8_t nodeId, uint8_t idx, void *object) )

Initialize Heartbeat consumer started callback function.

Function initializes optional callback function, which is called for the first received heartbeat after activating hb consumer or timeout. Function may wake up external task, which handles this event.

Parameters
HBconsThis object.
idxindex of the node in HBcons object
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_HBconsumer_initCallbackTimeout()

void CO_HBconsumer_initCallbackTimeout ( CO_HBconsumer_t * HBcons,
uint8_t idx,
void * object,
void(* pFunctSignal )(uint8_t nodeId, uint8_t idx, void *object) )

Initialize Heartbeat consumer timeout callback function.

Function initializes optional callback function, which is called when the node state changes from active to timeout. Function may wake up external task, which handles this event.

Parameters
HBconsThis object.
idxindex of the node in HBcons object
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_HBconsumer_initCallbackRemoteReset()

void CO_HBconsumer_initCallbackRemoteReset ( CO_HBconsumer_t * HBcons,
uint8_t idx,
void * object,
void(* pFunctSignal )(uint8_t nodeId, uint8_t idx, void *object) )

Initialize Heartbeat consumer remote reset detected callback function.

Function initializes optional callback function, which is called when a bootup message is received from the remote node. Function may wake up external task, which handles this event.

Parameters
HBconsThis object.
idxindex of the node in HBcons object
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_HBconsumer_process()

void CO_HBconsumer_process ( CO_HBconsumer_t * HBcons,
bool_t NMTisPreOrOperational,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process Heartbeat consumer object.

Function must be called cyclically.

Parameters
HBconsThis object.
NMTisPreOrOperationalTrue if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL.
timeDifference_usTime difference from previous function call in [microseconds].
[out]timerNext_usinfo to OS - see CO_process().

◆ CO_HBconsumer_getIdxByNodeId()

int8_t CO_HBconsumer_getIdxByNodeId ( CO_HBconsumer_t * HBcons,
uint8_t nodeId )

Get the heartbeat producer object index by node ID.

Parameters
HBconsThis object.
nodeIdproducer node ID
Returns
index. -1 if not found

◆ CO_HBconsumer_getState()

CO_HBconsumer_state_t CO_HBconsumer_getState ( CO_HBconsumer_t * HBcons,
uint8_t idx )

Get the current state of a heartbeat producer by the index in OD 0x1016.

Parameters
HBconsThis object.
idxobject sub index
Returns
CO_HBconsumer_state_t

◆ CO_HBconsumer_getNmtState()

int8_t CO_HBconsumer_getNmtState ( CO_HBconsumer_t * HBcons,
uint8_t idx,
CO_NMT_internalState_t * nmtState )

Get the current NMT state of a heartbeat producer by the index in OD 0x1016.

NMT state is only available when heartbeat is enabled for this index!

Parameters
HBconsThis object.
idxobject sub index
[out]nmtStateof this index
Return values
0NMT state has been received and is valid
-1not valid