75 lines
2.1 KiB
C
75 lines
2.1 KiB
C
/**
|
|
* @file include/di/can/net/self.h
|
|
* @brief DI-Net CAN network maintenance of self node
|
|
* @date Dec 7, 2016
|
|
* @author jjacobs
|
|
* @copyright 2016 Dual Inventive Technology Centre B.V.
|
|
*/
|
|
#ifndef LIBDI_INCLUDE_DI_CAN_NET_SELF_H_
|
|
#define LIBDI_INCLUDE_DI_CAN_NET_SELF_H_
|
|
|
|
#include <di/can/net/node.h>
|
|
|
|
struct di_can_ctx;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* Set node type on self
|
|
* @note The node type may only be set once
|
|
* @note When type argument is DI_CAN_NET_NODE_TYPE_UNKNOWN the call is ignored
|
|
* @retval DNOK when node type is set, DNE_OPDENIED otherwise
|
|
*/
|
|
di_errno_t di_can_net_self_set_node_type(struct di_can_ctx *ctx, enum di_can_net_node_types type);
|
|
|
|
/**
|
|
* Set node role on self
|
|
* * PASSIVE and FOLLOWER is allowed
|
|
* * UNKNOWN and LEADER role is forbidden
|
|
* @retval DNE_OPDENIED when operation is denied
|
|
* @retval DNOK when successful
|
|
*/
|
|
di_errno_t di_can_net_self_set_node_role(struct di_can_ctx *ctx, enum di_can_net_node_roles role);
|
|
|
|
/**
|
|
* Set node error on self, and publishes the err on the CAN-bus
|
|
* @retval DNOK when successful
|
|
*/
|
|
di_errno_t di_can_net_self_set_error(struct di_can_ctx *ctx, const di_errno_t err);
|
|
|
|
/**
|
|
* Check if self is fulfilling the leader role
|
|
* @retval true when Self is leader false otherwise
|
|
*/
|
|
bool di_can_net_self_is_leader(struct di_can_ctx *ctx);
|
|
|
|
/**
|
|
* Check if the self node error is set (!DNOK).
|
|
*/
|
|
bool di_can_net_self_has_error(struct di_can_ctx *ctx);
|
|
|
|
/**
|
|
* Check if self can become the leader.
|
|
* * When current role is !FOLLOWER or already LEADER the call is "ignored"
|
|
* * Self cant become leader when ALL nodes are check against:
|
|
* * Node type == Self type AND
|
|
* * Node role == LEADER AND
|
|
* * Node state == ONLINE
|
|
* * Self can become leader when ALL nodes don't meet one of the conditions in the list above
|
|
* @note di_can_net_lock must be called before this function
|
|
*/
|
|
bool di_can_net_self_can_become_leader(struct di_can_ctx *ctx);
|
|
|
|
/**
|
|
* Publish heartbeat of self node type and role
|
|
*/
|
|
di_errno_t di_can_net_self_publish_heartbeat(struct di_can_ctx *ctx);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* LIBDI_INCLUDE_DI_CAN_NET_SELF_H_ */
|