src.dualinventive.com/fw/dncm/libdi/include/di/drv/crtm.h

86 lines
2.6 KiB
C
Executable File

/**
* @ingroup XBee
* @defgroup crtm
* crtm specific functions
* @brief DI XBee driver crtm specific functions
* @date March 30, 2017
* @author svlies
* @copyright 2017 Dual Inventive Technology Centre B.V.
*
* DI XBee driver modules
* @{
*/
#ifndef LIBDI_INCLUDE_DI_DRV_CRTM_H
#define LIBDI_INCLUDE_DI_DRV_CRTM_H
#include <stdint.h>
#include <stdbool.h>
#include <di/buffer.h>
#include <di/sqrtf.h>
#include <di/device/uid.h>
#include <di/constants/rpc.h>
#include <di/constants/device/battery.h>
#include <stdio.h>
#include <string.h>
struct di_drv_xbee_ctx;
struct di_drv_xbee_frame;
#ifdef __cplusplus
extern "C" {
#endif
#define CRTM_NR_ADC_CHANNELS 6 /**<Number of ADC channels the CRTM has.*/
#define CRTM_STATUS_FRAME_TYPE 0x18 /**<CRTM custom frame value.*/
#define MCUTYPE_CRTM3000_SENSOR 0x0701 /**<CRTM device type identifier.*/
#define CRTM_CUSTOM_FRAME_SIZE 0x18 /**<CRTM custom frame size. */
struct di_drv_crtm_data {
char sn[17];/**<64 bit SN source address of the CRTM.*/
uint16_t mcu_version;/**<Software version of the source CRTM.*/
uint8_t patch_version;/**<Patch version of the source CRTM.*/
uint16_t mcu_type;/**<Device-type code of the source CRTM.*/
float temp1;/**<Sensor reading of the first temperature sensor in Celsius.*/
float temp2;/**<Sensor reading of the second temperature sensor in Celsius.*/
float bat1;/**<Sensor reading of the battery sensor in Voltage.*/
enum di_device_battery_state bat1_status; /**Battery status based on voltage. */
bool rail_detect;/**<Sensor reading of the rail detect sensor.*/
};
/**
* Calculate the network ID for the local radio with the LSB and MSB of the local radio.
* @param xbee_addr MAC address of the local XBee radio.
* @return Returns the calculated network ID.
*/
uint16_t di_drv_crtm_calc_network_id(const uint64_t xbee_addr);
/**
* Converts regular Xbee frame to custom CRTM frame.
* @param xbee_frame Frame to read from.
* @param d CRTM data frame to write to.
* @return Returns false if not correct Xbee frametype, custom crtm frame type or data size.
*/
bool di_drv_crtm_frame_converter(const struct di_drv_xbee_frame *f, struct di_drv_crtm_data *d);
/**
* Init a crtm_frame.
* @param d The frame to init.
*/
void di_drv_crtm_frame_init(struct di_drv_crtm_data *d);
/**
* Serializes the CRTM frame to an RPC message.
* @param f CRTM data frame with the sensor data.
* @param buf DI buffer where the RPC message is stored.
* @return DNOK when successful.
*/
di_errno_t di_drv_crtm_rpc_serialize_msg(const struct di_drv_crtm_data *f, struct di_buffer *buf);
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* LIBDI_INCLUDE_DI_DRV_CRTM_H */