/** * @file include/di/drv/xbee.h * @defgroup XBee * @brief DI XBee driver modules * @date March 30, 2017 * @author svlies * @copyright 2017 Dual Inventive Technology Centre B.V. * * DI XBee driver modules * @{ */ #ifndef LIBDI_INCLUDE_DI_DRV_XBEE_H_ #define LIBDI_INCLUDE_DI_DRV_XBEE_H_ #include #include #ifdef __cplusplus extern "C" { #endif struct di_drv_xbee_ctx; struct di_drv_xbee_frame; #define DI_DRV_XBEE_ADRR_LENGTH 17 #define DI_DRV_XBEE_CMD_HEADER_SIZE 4 #define DI_DRV_XBEE_REMOTE_CMD_HEADER_SIZE 15 /** * Xbee sleep options. */ enum di_drv_xbee_sleep_options { DI_DRV_XBEE_SLEEP_OPTIONS_SLEEP_COORDINATOR = 1, /**read = read; } static inline void di_drv_xbee_set_write_cb(struct di_drv_xbee_ctx *ctx, size_t (*write)(uint8_t *buf, size_t n)) { ctx->write = write; } /** * xbee initialize context * - Resets ALL fields in ctx */ void di_drv_xbee_init(struct di_drv_xbee_ctx *ctx); /** * Send an AT command to the local XBee radio. * @param ctx Context of the XBee driver. * @param at_command The 2 letters of the AT command (see Xbee_defines). * @return di_errno_t Returns DNOK if successful, else an errorcode. */ di_errno_t di_drv_xbee_cmd(struct di_drv_xbee_ctx *ctx, const char *at_command); /** * Send an AT command to a remote XBee radio. * @param ctx Context of the XBee driver. * @param dst_addr 64 bit destination address of the remote XBee radio. * @param at_command The 2 letters of the AT command (see Xbee_defines). * @return Returns DNOK if successful, else an errorcode. */ di_errno_t di_drv_xbee_remote_cmd(struct di_drv_xbee_ctx *ctx, uint64_t dst_addr, const char *at_command); /** * Check if a frame is available at the read function, and checks the size and checksum of the received frame. * @param ctx Context of the XBee driver. * @return Returns true if an correct frame is received. */ bool di_drv_xbee_recv_frame(struct di_drv_xbee_ctx *ctx, struct di_drv_xbee_frame *frame); /** * Reconstructs the 64 bit MSB or LSB part of the local XBee radio address from the frame to the ctx. * @param ctx Context of the XBee driver to write to. * @param frame Frame with xbee frame. * @return Returns false if incorrect AT command response. */ di_errno_t di_drv_xbee_build_sn(struct di_drv_xbee_ctx *ctx, struct di_drv_xbee_frame *frame); /** * converts the xbee radio address to an RPC UID. * @param xbee_mac buffer with the XBee address. * @param device_uid buffer to write the RPC UID to. * @return DNOK if successful. */ di_errno_t di_drv_xbee_mac_to_device_uid(const char *xbee_mac, char device_uid[DI_DEVICE_UID_LEN]); #include #include #include #include #ifdef __cplusplus } #endif /** @} */ #endif /* LIBDI_INCLUDE_DI_DRV_XBEE_H__ */