src.dualinventive.com/dinet/sec-multi-proxy/libdi/include/di/can/net/discover.h

91 lines
2.7 KiB
C

/**
* @file include/di/can/net/discover.h
* @brief DI-Net CAN network discovery
* @date Oct 17, 2016
* @author jjacobs
* @copyright 2016 Dual Inventive Technology Centre B.V.
*
* CAN network discovery
*/
#ifndef LIBDI_INCLUDE_DI_CAN_NET_DISCOVER_H_
#define LIBDI_INCLUDE_DI_CAN_NET_DISCOVER_H_
struct di_can_msg;
struct di_can_ctx;
struct di_can_net;
#include <stdbool.h>
#include <di/can/callback.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Callback item for net discover request message */
#define DI_CAN_NET_DISCOVER_CALLBACK_REQUEST_ITEM { \
DI_CAN_CALLBACK_CANID( \
DI_CAN_MSGTYPE_NET, \
DI_CAN_TRANSFERTYPE_REQUEST, \
DI_CAN_NET_DTYPE_DISCOVER \
), \
di_can_net_discover_cb \
}
/** Callback item for net discover reply message */
#define DI_CAN_NET_DISCOVER_CALLBACK_REPLY_ITEM { \
DI_CAN_CALLBACK_CANID( \
DI_CAN_MSGTYPE_NET, \
DI_CAN_TRANSFERTYPE_REPLY, \
DI_CAN_NET_DTYPE_DISCOVER \
), \
di_can_net_discover_cb \
}
/** Network discovery states */
enum di_can_net_discover_state {
DI_CAN_NET_DISCOVER_STATE_UNKNOWN, /**< Network not discovered yet */
DI_CAN_NET_DISCOVER_STATE_REQUEST, /**< Network discover request send */
DI_CAN_NET_DISCOVER_STATE_FINISH /**< Network discover finished */
};
/**
* Send broadcast discover request
* @note Discover state is not updated, as this is handled by di_can_net_discover_fsm
* @param ctx CAN context
* @return DNOK when discovery is sent
*/
di_errno_t di_can_net_discover(struct di_can_ctx *ctx);
/**
* Callback for discover request/reply messages handling
* * Request message will send a reply and updates it local state based on the request
* * Reply message will update its local state
* @param msg Request or reply discover message
* @param ctx CAN context
*/
void di_can_net_discover_cb(const struct di_can_msg *msg, struct di_can_ctx *ctx);
/**
* Execute the discover FSM
* * Network node discover
* * When DISCOVER_STATE_UNKNOWN -> ping request is send
* * When DISCOVER_STATE_REQUEST -> reply timeout exceed
* * When DISCOVER_STATE_FINISH -> network discovery finished
* * When DISCOVER_STATE_FINISH
* * Update leader nodes of same type (last seen)
* * Fire a di_can_net_node_event when leader node is offline
* @note Subsystem must be locked before calling
*/
void di_can_net_discover_fsm(struct di_can_ctx *ctx);
/**
* Check if the network is discovered
*/
bool di_can_net_is_discovered(struct di_can_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* LIBDI_INCLUDE_DI_CAN_NET_DISCOVER_H_ */