73 lines
2.2 KiB
C
73 lines
2.2 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 <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 */
|
|
};
|
|
|
|
di_errno_t di_can_net_discover(struct di_can_ctx *ctx);
|
|
|
|
/** Callback for discover request/reply messages */
|
|
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);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* LIBDI_INCLUDE_DI_CAN_NET_DISCOVER_H_ */
|