#ifndef __CA_CAU_H__
#define __CA_CAU_H__

#ifdef CFG_DEV_TYPE_LAND_CA
/* Includes ------------------------------------------------------------------*/
#include "ca_main.h"

/* Define --------------------------------------------------------------------*/
#define     MODBUS_DATA_LENGTH  (512)

#define     MESSAGE_HEAD_POS        (0)
#define     MESSAGE_FUNC_POS        (1)
#define     MESSAGE_DATA_LEN_POS    (2)
//#define     MESSAGE_BODY_LEN_POS    (1)
//#define     MESSAGE_BODY_POS        (2)
//#define     MODBUS_HEAD_POS         (0)
//#define     MODBUS_FUNC_POS         (1)

#define     CALI_POINT_MAX          (5) // 5个校准点

/* Exported types ------------------------------------------------------------*/

typedef struct 
{
    float       tag[MAX_CAU_CHANNEL];
}cau_real_data_t;


typedef struct
{
    cau_real_data_t cauVal[100];// 每个点采集20次取平均值
    cau_real_data_t cauAvg[5];//校准计算平均值
}cali_value_t;

typedef int32_t (*cb_send_data)(int cmd, char *psrc, int len);

typedef struct
{
    int serial_fd;
    unsigned char modbus_recv_buf[MODBUS_DATA_LENGTH];
    unsigned char modbus_send_buf[MODBUS_DATA_LENGTH];
    cau_real_data_t real_data;
    unsigned int    last_collect_time;
    Parameters_t cali_param;
    cali_value_t cali_val;
    int ismanual;
    int workstat;   //0:正常工作 1:正在校准
    cb_send_data send_data;
} cau_t;

typedef struct
{
    int vsc;//超级电容 输出电压 单位mv
    int vbat;//电池电压 单位mv
    int vout;//系统供电电压（Vsc  ,Vbat,V5v三者的最大值） 用于判断电池是否在供电中
} pwr_t;

/* Exported macro ------------------------------------------------------------*/

/* Extern global variables ---------------------------------------------------*/
//extern csg_t csg;
extern cau_t cau;
extern pwr_t pwr;

/* Extern functions ----------------------------------------------------------*/
extern int32_t cau_handle_init(void);
extern int _cau_set_calibration_param(float *pparam);
#endif
#endif

