#ifndef _SOFT_FLOW_H
#define _SOFT_FLOW_H
#include "common.h"

//恩曌流量计
#define CAN_MIMO_FLOW (0x210)
#define CAN_MIMO_FLOW_K (0xFB)
#define FlOW_KP 22
//恩曌雷达版本信息应答
#define CAN_MIMO_VERSION (0XFB)


#pragma pack(1)
typedef struct
{
    uint8_t ch;
    uint16_t flow_speed;
    uint16_t total_ml;
    uint8_t status;
    uint8_t circu_time;
    uint8_t signal_str;

    bool get_k;
    bool set_k;
    uint16_t flow_k; //当前K
    uint16_t flow_calk;//校准K

    char soft_version[2];
    char sn[14];
    uint16_t last_total_ml;
    uint8_t overturn_count;

}mimo_flow;
#pragma pack()
extern mimo_flow flow_mimo1;
extern mimo_flow flow_mimo2;

#pragma pack(1)
typedef struct 
{
    uint16_t speed;
    uint16_t ml;
    uint8_t warn;

    uint16_t last_ml;
    uint16_t overturn;

    uint16_t k;
    uint16_t k_multiple;

    bool get_k;
    bool set_k;
    uint16_t cal_k;

    bool clear_background;
}flow_info;
#pragma pack()

#pragma pack(1)
typedef struct 
{
    uint8_t ch;
    flow_info ch1,ch2;
}flow;
#pragma pack()
extern flow flow_inf;


//霍尔流量计
#pragma pack(1)
typedef struct
{
    bool count_flag;
    uint32_t time;
    uint32_t last_time;
    uint32_t irq_count;  //单位时间内经过的液体体积      
    uint32_t irq_last_count;
    bool exti_error;
    int speed;
    bool rising_delay_flag;
    bool falling_delay_falg;
    uint32_t cal_delay_time;
    uint8_t  irq_flag;
    bool sem_flag;

    uint32_t rising_delay_time;
    uint32_t falling_delay_time;
}flow_hl;
extern flow_hl flow_dev1;
extern flow_hl flow_dev2;
#pragma pack()

extern GPIO_PinState L3_status;
extern GPIO_PinState L4_status;



void can_recv_mimor_flow_function(uint32_t CanID, uint8_t data[], uint8_t len);
void Flow_recieved_hookfuction(uint32_t cellCanID,uint8_t data[], uint8_t len);
void can_sendmsg_flow(void);
#endif