#ifndef _PROTO_MODBUS_MASTER_SENSOR_H_
#define _PROTO_MODBUS_MASTER_SENSOR_H_
#include "main.h"
#include "gas_data.h"

/*NIDR状态*/
#define PROTO_TDLAS_SYS_STATE_INIT                   (0U)    /*初始化      */
#define PROTO_TDLAS_SYS_STATE_CURR_DATA_GET          (1U)    /*获取实时数据*/
#define PROTO_TDLAS_SYS_STATE_ZERO_CALIB             (2U)    /*零点校准    */
#define PROTO_TDLAS_SYS_STATE_SPAN_CALIB             (3U)    /*量程校准    */
#define PROTO_TDLAS_SYS_STATE_RESET                  (4U)    /*恢复出厂    */
#define PROTO_TDLAS_SYS_STATE_FAC_CALIB              (5U)    /*厂家标定    */
#define PROTO_TDLAS_SYS_STATE_FAC_CALIB_PARA_SET     (6U)    /*厂家标定时的环境参数*/
#define PROTO_TDLAS_SYS_STATE_FAC_CALIB_DATA_GET     (7U)    /*获取标定信息*/

#define PROTO_TDLAS_ERROR_FLAG_TIME_OUT              (30U)    /*通讯超时*/


typedef struct
{
    void (*zero_calib)(u16);                                /*零点校准*/
    void (*span_calib)(u16);                                /*量程点校准*/
    void (*reset)(void);                                    /*恢复出厂设置*/
    void (*fac_calib)(u16,u8,u8);                           /*厂家标定时的浓度*/
    void (*fac_calib_para_set)(s16,u16,u16);                /*厂家标定时设置的温度、湿度、压力*/
    void (*fac_calib_data_get)(u8);                         /*厂家标定时设置的温度、湿度、压力*/
}proto_tdlas_control_t;

typedef struct
{
    u8 sys_state;
    u16 send_time;                                          /*发送次数*/
    u32 sensor_state;                                       /*传感器状态*/
    u8 print_flag;                                          /*实时数据打印标志位*/  
    u32 state_error_flag;                                   /*系统错误标志位*/
    u16 tx_time_out_count;                                  /*协议指令发送次数*/
}proto_tdlas_sys_t;

typedef struct
{
    
    u8 calib_point;
    u8 temp_point;
    u16 calib_value;
    s16 temp;
    u16 humidity;
    u16 press;
}proto_tdlas_set_data_t;

typedef struct
{
    u8 modbus_id;

    u16 sensor_index;                                       /*当前是哪个通道的传感器*/
    proto_tdlas_set_data_t set_data;
    proto_tdlas_sys_t sys[SENSOR_NUM];
    proto_tdlas_control_t control;

    void (*init)(void);
    void (*tx_task)(void);
    void (*rx_task)(u8 *,u16,void *);
    void (*print)(void);
    void (*warm_task)(void);
}proto_tdlas_t;

extern proto_tdlas_t tdlas;

#endif
