149 lines
4.8 KiB
Plaintext
Executable File
149 lines
4.8 KiB
Plaintext
Executable File
/**
|
|
* @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 DI_DRV_XBEE_H_
|
|
#define DI_DRV_XBEE_H_
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <di/stdio.h>
|
|
|
|
//#include <di/drv/xbee/xbee_at_cmd.h>
|
|
#include <di/encoding/me.h>
|
|
#include <di/rpc/structures.h>
|
|
#include <di/drv/xbee/xbee_defines.h>
|
|
#include <di/drv/xbee/checksum.h>
|
|
#include <di/drv/xbee/frame.h>
|
|
//#include <di/drv/crtm/crtm.h>
|
|
#include <di/log.h>
|
|
#include <di/array.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct di_drv_xbee_ctx;
|
|
struct di_drv_xbee_frame;
|
|
|
|
/**
|
|
* Xbee sleep options.
|
|
*/
|
|
enum di_drv_xbee_sleep_options {
|
|
DI_DRV_XBEE_XBEE_SLEEP_COORDINATOR = 1, /**<Set module as sleep coordinator.*/
|
|
DI_DRV_XBEE_XBEE_NON_SLEEP_COORDINATOR = 2, /**<Set module as non-sleep coordinator.*/
|
|
DI_DRV_XBEE_XBEE_SLEEP_COORDINATOR_WITH_API = 5 /**<set module as sleep coordinator with API mode on.*/
|
|
};
|
|
|
|
/**
|
|
* Xbee sleep mode.
|
|
*/
|
|
enum di_drv_xbee_sleep_mode {
|
|
DI_DRV_XBEE_NORMAL = 0, /**<set sleep mode to normal(no sleep).*/
|
|
DI_DRV_XBEE_PIN_SLEEP = 1, /**<set sleep mode to sleep with pin wake-up.*/
|
|
DI_DRV_XBEE_ASYNCHRONOUS_CYCLIC_SLEEP = 4, /**<set sleep mode to asynchronous cyclic sleep.*/
|
|
DI_DRV_XBEE_ASYNCHRONOUS_CYCLIC_SLEEP_PIN = 5, /**<set sleep mode to asynchronous cyclic sleep with pin wake-up.*/
|
|
DI_DRV_XBEE_SLEEP_SUPPORT_MODE = 7, /**<set sleep mode to sleep support.*/
|
|
DI_DRV_XBEE_SYNCHONOUS_CYCLIC_SLEEP = 8 /**<set sleep mode to synchronous cyclic sleep.*/
|
|
};
|
|
|
|
/**
|
|
* Xbee baudrate.
|
|
*/
|
|
enum di_drv_xbee_baudrate {
|
|
DI_DRV_XBEE_BAUDRATE_9K6 = 3, /**<Baudrate 9600.*/
|
|
DI_DRV_XBEE_BAUDRATE_19K2 = 4, /**<Baudrate 19200.*/
|
|
DI_DRV_XBEE_BAUDRATE_38K4 = 5, /**<Baudrate 38400.*/
|
|
DI_DRV_XBEE_BAUDRATE_57K6 = 6, /**<Baudrate 57600.*/
|
|
DI_DRV_XBEE_BAUDRATE_115K2 = 7, /**<Baudrate 115200.*/
|
|
DI_DRV_XBEE_BAUDRATE_230K4 = 8 /**<Baudrate 230400.*/
|
|
};
|
|
|
|
/**
|
|
* Xbee api modes
|
|
*/
|
|
enum di_drv_xbee_api_modes {
|
|
DI_DRV_XBEE_TRANSPARANT_MODE, /**<Set API mode to transparant mode.*/
|
|
DI_DRV_XBEE_API_MODE_WITHOUT_ESCAPES, /**<Set API mode to API without escapes.*/
|
|
DI_DRV_XBEE_API_MODE_WITH_ESCAPES /**<Set API mode to API with escapes.*/
|
|
};
|
|
|
|
/**
|
|
* Xbee context
|
|
*/
|
|
struct di_drv_xbee_ctx {
|
|
enum di_drv_xbee_baudrate baudrate; /**<Baudrate of the XBee module.*/
|
|
uint64_t sn; /**<Serial number of the local XBee radio.*/
|
|
uint32_t firmware; /**<Firmware version of the local XBee radio.*/
|
|
uint16_t network_id; /**<Current network ID of the local XBee radio.*/
|
|
struct di_buffer buf; /**<DI_buffer for storing frames and data.*/
|
|
size_t (*read)(uint8_t *buf); /**<Read function of the XBee driver.*/
|
|
size_t (*write)(uint8_t *buf, size_t n); /**<Write function of the XBee driver.*/
|
|
};
|
|
|
|
static inline void di_drv_xbee_set_read_cb(struct di_drv_xbee_ctx *ctx, size_t (*read)(uint8_t *buf))
|
|
{
|
|
ctx->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).
|
|
* @param reply If true, the XBee radio wil return a confirm massage.
|
|
* @return Frame_id of the AT command, 0 if reply is false.
|
|
*/
|
|
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 des 64 bit destination address of the remote XBee radio.
|
|
* @param at_command The 2 letters of the AT command (see Xbee_defines).
|
|
* @param reply If true, the xbee radio wil return a confirm massage.
|
|
* @return Frame_id of the AT command, 0 if reply is false.
|
|
*/
|
|
di_errno_t di_drv_xbee_remote_cmd(struct di_drv_xbee_ctx *ctx, uint64_t dest_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_receive_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.
|
|
*/
|
|
bool di_drv_xbee_build_sn(struct di_drv_xbee_ctx *ctx, struct di_drv_xbee_frame *frame);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
#endif /* DI_DRV_XBEE_H__ */
|