#ifndef _APP_LEAKAGE_H_
#define _APP_LEAKAGE_H_

#include "main.h"

#define ENABLE  (1)
#define DISABLE (0)

#define APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE    (0x0001)        /*漏液状态*/
#define APP_LEAKAGE_SUB_DEVICE_STATE_OPEN       (0x0002)        /*断带状态*/
#define APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT   (0xf000)        /*通讯超时*/

#define APP_LEAKAGE_STRING_NANE_LEN (10)
#define APP_LEAKAGE_SUB_DEVICE_NUM (32)
#define APP_LEAKAGE_SUB_DEVICE_CH_NUM (4)

/*子设备存储的参数*/
typedef struct
{
    u8 state;                                           /*状态 使能 非使能*/
    u8 com_port;                                        /*端口*/
    u8 modbus_id;                                       /*modbus id*/
    u8 device_name[APP_LEAKAGE_STRING_NANE_LEN];                /*设备名*/
    u8 region_name[APP_LEAKAGE_STRING_NANE_LEN];                /*区域名*/
}app_leakage_sub_device_flash_data_t;

/*子设备信息*/
typedef struct
{
    app_leakage_sub_device_flash_data_t flash_data;     /*flash存储数据*/
    struct
    {
        u16 state;                                      /*状态*/
        u16 distance;                                   /*漏液距离*/
    }ch_data[APP_LEAKAGE_SUB_DEVICE_CH_NUM];            /*通道数据*/
}app_leakage_sub_device_class_t;            
       

/*区域信息*/
typedef struct
{
    u8 leakage_num;                                     /*漏液数量*/
    u8 open_num;                                        /*断带数量*/
    u8 time_out_num;                                    /*通讯超时数量*/
    u8 sub_device_num;                                  /*设备总数量*/
    u8 name[APP_LEAKAGE_STRING_NANE_LEN];               /*区域名称*/
    u8 sub_device_index[APP_LEAKAGE_SUB_DEVICE_NUM];    /*设备的索引*/
}app_leakage_region_data_class_t;      

typedef struct
{
    u8 region_num;
    u8 sub_device_num;
    app_leakage_region_data_class_t region_data[APP_LEAKAGE_SUB_DEVICE_NUM];
    app_leakage_sub_device_class_t sub_device_data[APP_LEAKAGE_SUB_DEVICE_NUM];
    
    void (*init)(void);                                 /*初始化*/
    void (*task)(void);                                 /*执行任务*/
}app_leakage_t;
    
extern app_leakage_t leakage;
#endif