/*
 * File:   __GP22LoRa_GP22_APP_C
 * Author:
 *
 * Created on：2017-8-3
 */

#ifdef __cplusplus
extern "C"
{
#endif
#include "sys_config.h"
#include "UWater_gp22_app.h"
#include "UWater_rtcc_driver.h"
#include "UWater_rtcc_app.h"
#include "UWater_eeprom_driver.h"
#include "UWater_frame_app.h"	
#include "UWater_gp22_driver.h"
#include "UWater_pt_app.h" 
#include "UWater_gpio_driver.h"
#include "UWater_timer1uS_driver.h"
#include "UWater_uart_driver.h"	
#include "math.h"	
#include "UWater_power_app.h"
#include "UWater_lcd_app.h"
#include "UWater_lptimer_driver.h"
#include "UWater_TemperatureCalculate_app.h"
#include "sys_processor.h"
	
#define PowerSaveDataMsgSys  PowerUnSleepSaveDataMsgSys
/*------------------------------ Variable Define -------------------------------------*/
u32 gp22_sample_result;
/**********数据存储防护*************/	
static u8 gp22_date_save_state;
static To_Float_GP30 old_monitor_flow ;
	
/**********数据存储防护*************/
//GP22数据计算处理机
static u8 s_g_gp22_app_state_num = GP22_APP_S0; // GP22数据计算处理机
//static u8 s_g_sample_flow_num = 0; //实际记录的流量采集 次数
static u32 s_g_flow_data[GP22_APP_QUEUE_SIZE]; //流量采集队列

static u32 s_g_flow_type[GP22_APP_QUEUE_SIZE]; //类型采集队列

static u32 s_g_sample_sum_lcd;
static float s_g_diftof_data[GP22_APP_DIFTOF_SIZE]; //时间差滤波队列 2016-8-15
static u16 s_g_diftof_head = 0; //时间差滤波队列数据更新 头地址
static float s_g_diftof_data_2[GP22_APP_DIFTOF_SIZE_2]; //时间差滤波队列 2016-8-15
static u16 s_g_diftof_head_2 = 0; //时间差滤波队列数据更新 头地址
static u8 s_g_diftof_head_2_quotient = 0; 
static u8 s_g_diftof_for_total = FALSE; 

#if EN_LARGE_FILITER//2022-01-10
static float s_g_diftof_data_3[GP22_APP_DIFTOF_SIZE_3]; //第三次时间差滤波队列 2020-3-6
static float still_water_add_3 = 0;
static u16 s_g_diftof_head_3 = 0; //时间差滤波队列数据针对大口径增加  第三次滤波
static u8 s_g_diftof_head_3_quotient = 0; 
#endif

/*活塞台子添加*/
//温度采集与滤波相关
static float s_g_temp_data[MAX_TEMP_NUM]; //用于采集温度 2019-8-11
static u8 s_g_sample_head = 0; //时间差滤波队列数据更新 头地址
static u8 s_g_sample_length = 0; //采样长度
u8 s_g_sample_start_flag = FALSE; //采样标志位
static u8 s_g_sample_ok_flag= 0; //采样数据处理完成标志位
float temp_sample_value=0;//用于存储采样滤波后的温度数值
/*活塞台子添加*/

static u32 gp30_app_start_flow_filter;//用来接收始动流量数值
//static u32 gp22_app_start_flow_reverse;
static float gp30_app_start_flow_filter_float;//用来接收始动流量数值float类型
static float gp30_app_start_flow_reverse_float;
//static float gp30_app_start_flow_filter_for_float;


static u32 s_alarma_stop_check_tick = 0;

GP30_SYS_Date gp22_app_data; //gp22当前数据
GP30_SYS_Date gp22_test_data; //gp22检定状态下当前数据
EVENT gp30_event;
EVENT_FLAG gp30_event_flag;
EVENT_FLAG gp30_event_save_flag;
To_Float gp30_test_total_start_flow;
To_Float gp30_total_flow_last;  //GP30上次累计数2016-6-23
static u8 s_g_sample_flag = 0; //本次采集启动温度,标志

OVERRUN_NUM gp30_overrun_num;

static u32 s_g_sample_total_sum = 0; //时间差总计采样次数
//static float s_g_sample_add = 0; //时间差和

//GP22采样间隔处理机
static u8 s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S0;
//static float gp30_total_flow_calcult_factor = FACTOR_0_5;
//static u8 s_g_gp22_sample_span = GP22_SAMPLE_2HZ; //1对用0.5采样一次
//static u8 s_g_gp22_sample_sum = 0;//采样频率切换时的计数,超过5min的
//static u8 s_g_gp22_sample_flag_num = 0; //采样计数,与采样频率切换相关
//static float globle_total_flow_float = 0;
static u8 start_measure_flag = 1;  //初始化为启动流量测量

//static u8 s_g_send_data_app_state_num = SEND_DATA_S0;//主动上报处理机状态
To_Float_GP30 total_flow_old;//非检定状态累计流量
To_Float_GP30 total_flow_now;//非检定状态累计流量

To_Float_GP30 total_reverse_flow_old;//非检定状态逆流累计流量
To_Float_GP30 total_reverse_flow_now;//非检定状态逆流累计流量
u32 mater_waring_state;
u32 send_timer_old = 0;//检定状态定时1s
u32 low_power_timer_old = 0;//低电平状态时间
//static u8 total_flow_change_flag = 0;//累计流量更新标志
static u8 s_gp30_eep_complete=0;
////////////////////////////////////////////////////////////////////累积量改为double计算
To_Double duoble_total_flow;

////////////////////////////////////////////////////////////////////逆流计量增加内容

static float s_g_temp_float_flow_data[GP22_APP_QUEUE_SIZE]; //float类型时间差滤波队列 2019-5-10
static u8 ins_flow_flag = 0; //本次时间差滤波正负标志
static float globle_cur_total_flow_float = 0; 

////////////////////////////////////////////////////////////////////逆流计量增加内容

//静水时间相关
static u32 s_g_still_water_time = 0; //静水时间差
//static u32 s_g_still_time = 0; //静水时间
//static float s_g_still_lenth = 0; //静水距离
//static float s_g_still_water_time_min = 0; //静水时间差最小值
//static float s_g_still_water_time_max = 0; //静水时间差最大值
//static u8 s_g_still_flag = FALSE;
//static u8 s_g_still_finish = FALSE; //接口信息

//static u8 s_g_flow_err_sum = 0; //流量错误次数
//static u8 s_g_set_window = FALSE; //重新设置窗口
static u8 Gp30_init_data_flag = FALSE;//下初值标志

//GP22数据清零处理机
//主要工作: 处理上位机命令，将当前数据清零
static u8 s_g_gp22_app_clear_data_state_num = GP30_APP_CLEAR_DATA_S0;
GP30_APP_SAVE_DATA g_sample_save_data; //当前数据备份
GP30_DIFTOF_CAL_DATA g_diftof_cal_data;//校准的时间差和标志
static float calibration_diftof_value=0;//用于记录计算累积量时的当前时间差

//当前数据备份处理机
//主要工作: 完成GP22当前累计数据备份存储 
//（同时作为故障前，累计数据显示，用于LCD显示故障前累计值）
//当前数据区：第一次上电 状态字2 （0x77 0x88）+ 年月日时4 + 累计热量（kW?h）4 + 累计冷量（kW?h）4 + 累计流量（m3）4 + 静水时间差4 =  22字节  

//流量计算间隔切换处理机 2022-5-23 09:46:56
static u8 s_g_gp30_control_cal_state = GP30_CONTROL_S0;  //LPTIMER时间轴
static u32 s_g_gp30_control_cal_timer = 0;
static u8 s_gp22_cal_interval_msg = FALSE;    //计算时间轴，默认是用lptimer

/*ZCC 和 nB 上报防护  2022-7-21 15:38:06*/
static float ZCC_NB_buf[3]={0};
static u8 ZCC_direction_flow_flag[3]={0};
static float ZCC_ins_flow[3]={0};


//#pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wunknown-attributes"

#define __no_init __attribute__((zero_init))


__no_init volatile float gp22_copy_total_flow __attribute__((section(".ARM.__at_0x20007F00")));
__no_init volatile float gp22_copy_total_flow_reverse __attribute__((section(".ARM.__at_0x20007F04")));
__no_init volatile float gp22_copy_total_flow_test __attribute__((section(".ARM.__at_0x20007F08")));
__no_init volatile float gp22_copy_temp_total_flow_float_test __attribute__((section(".ARM.__at_0x20007F0C")));
__no_init volatile u32 gp22_copy_reset_flag_test __attribute__((section(".ARM.__at_0x20007F10")));
__no_init volatile u32 MCU_reset_judge __attribute__((section(".ARM.__at_0x20007F14")));
__no_init volatile float gp22_copy_temp_total_flow_float __attribute__((section(".ARM.__at_0x20007F18")));
__no_init volatile u16 record_last_calculative_time __attribute__((section(".ARM.__at_0x20007F1C"))); //用于记录距离上次计算的时间间隔，方便复位精确补偿


__no_init volatile float temp_calculate_last __attribute__((section(".ARM.__at_0x20007F38")));//记录上次的反算温度数值 

//非流量相关复位不丢失数据
/*以下位置在其他模块定义，注意不要重复
__no_init volatile u8 meter_reset_cnt __attribute__((section(".ARM.__at_0x20007F20")));//复位次数
__no_init volatile u8 meter_reset_reason __attribute__((section(".ARM.__at_0x20007F21")));//上次复位原因
__no_init volatile u8 s_valapp_upload_times __attribute__((section(".ARM.__at_0x20007F22")));//阀门关闭状态下，频繁上报的次数
*/
//#pragma clang diagnostic pop

static u8 s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S0;
GP30_APP_EVENT_DATA s_g_event_data;
//static DateTime gp30_get_time;

//GP22应用处理机上电初始化
//主要工作: GP22应用处理机上电初始化， EE数据读取 
//EEPROM区域： 0x80-0xB7
//第一次上电标志: 0x77 0x88
static u8 s_g_gp22_init_state_num = GP30_APP_INIT_S0;
static u8 g_gp22_init_flag = 0; //GP22 应用处理机上电初始化是否完成的判断

static u8 s_g_bootloader_msg = FALSE;
static u8 diftof_auto_calibration_msg = FALSE;//静水时间差自动校准标志
static u8 transducer_err_msg = FALSE;//换能器异常标志

static u8 s_g_gp22_err_flag = 0;
static u8 reverse_flow_sum = 0;

//static u8 s_gengxin_statebyte_msg = FALSE; 
//static u32 GP30_filter_last_value  = 0;//针对MID样机出现的小流异常数滤波用_传统体积法台子
//static float GP30_filter_last_value_for_shunshi = 0;//针对MID样机出现的小流异常数滤波用_活塞台子

//static float TempCurve(float x);
//float FlowCurveWaterMeter(float x);

TYP_FLOW_COEFFICIENT *flow_coef;
UNION_4U8TOU32 *seg_flow_coef;//2020-07-08 流量系数
//u16 g_test_start_sum = 0;
//u16 g_test_stop_sum = 0;

static u32 intval_time = 0;						//LPTIM定时,用于计算准确的间隔流量计量时间
static u16 record_calculative_time = 0;			//用于记录本次计算的当前时间，方便与下次计算的时间做差

/*GP30中断计算流量*/
static uint8_t  s_gp22_Data_Update_msg = 0;	//GP30中断标志，用于计算累积量时判断

#if WENDU_FANSUAN_OPEN
u32 s_g_up_am[GP22_APP_TEMP_INVERSE_DATA_SIZE+GP22_APP_TEMP_INVERSE_DATA_SIZE]; //am采集队列 数组中前4个存储第4~第7个波形振幅，后4个存储第8~第11个波形振幅
u32 s_g_down_am[GP22_APP_TEMP_INVERSE_DATA_SIZE+GP22_APP_TEMP_INVERSE_DATA_SIZE]; //down采集队列 数组中前4个存储第4~第7个波形振幅，后4个存储第8~第11个波形振幅
#else
static u32 s_g_up_am[GP22_APP_MAX_AM_BUFFER]; //UP振幅采集队列
static u32 s_g_down_am[GP22_APP_MAX_AM_BUFFER]; //down振幅采集队列
#endif

//float FilterJunZhi_float(float *p, u8 len);   //不排序，去掉两头 各两个最值20ms
//超声波在非流动介质中的声速
//const u32 sound_speed_back [101] = {
//    0X057A5604,
//    0X057F4FDC, 0X05842C89, 0X0588EC8C, 0X058D905F, 0X0592187F,
//    0X05968562, 0X059AD77F, 0X059F0F4B, 0X05A32D37, 0X05A731B3,
//    0X05AB1D2D, 0X05AEF011, 0X05B2AAC9, 0X05B64DBB, 0X05B9D94E,
//    0X05BD4DE6, 0X05C0ABE4, 0X05C3F3A9, 0X05C72592, 0X05CA41FD,
//    0X05CD4942, 0X05D03BBB, 0X05D319BF, 0X05D5E3A3, 0X05D899B9,
//    0X05DB3C54, 0X05DDCBC4, 0X05E04857, 0X05E2B259, 0X05E50A16,
//    0X05E74FD6, 0X05E983E2, 0X05EBA681, 0X05EDB7F6, 0X05EFB885,
//    0X05F1A871, 0X05F387F8, 0X05F5575C, 0X05F716D8, 0X05F8C6A9,
//    0X05FA670B, 0X05FBF835, 0X05FD7A62, 0X05FEEDC7, 0X0600529B,
//    0X0601A911, 0X0602F15D, 0X06042BB1, 0X0605583E, 0X06067734,
//    0X060788C1, 0X06088D14, 0X06098458, 0X060A6EB8, 0X060B4C60,
//    0X060C1D78, 0X060CE22A, 0X060D9A9C, 0X060E46F6, 0X060EE75D,
//    0X060F7BF6, 0X061004E5, 0X0610824D, 0X0610F450, 0X06115B11,
//    0X0611B6B0, 0X0612074D, 0X06124D07, 0X061287FE, 0X0612B84F,
//    0X0612DE18, 0X0612F975, 0X06130A83, 0X0613115E, 0X06130E20,
//    0X061300E6, 0X0612E9C7, 0X0612C8DF, 0X06129E46, 0X06126A16,
//    0X06122C66, 0X0611E54F, 0X061194E8, 0X06113B4A, 0X0610D88B,
//    0X06106CC2, 0X060FF805, 0X060F7A6B, 0X060EF40A, 0X060E64F8,
//    0X060DCD4A, 0X060D2D18, 0X060C8475, 0X060BD378, 0X060B1A36,
//    0X060A58C5, 0X06098F39, 0X0608BDA9, 0X0607E429, 0X060702D0,
//};

/*
RAM区数据校验判断
return 	TRUE 当前读出的数据奇偶检验出错
		FALSE 当前读出的数据奇偶检验正确
*/
u8 RAMDataVerify(u8* pCheckData,u8 nSizeof)
{
	u8 nCount=0;
	volatile u8 nDataTemp=0;
	u32 nCheck = 0;
	
	for(nCount=0; nCount<nSizeof;nCount++)
	{
		nDataTemp = *(pCheckData+nCount);
		nCheck = (u32)(pCheckData+nCount)&0x00007FFF;//-0x20000000;

		//数据检验错误
		if(nCheck == M0P_RAM->ERRADDR_f.ERRADDR)
		{
			M0P_RAM->ICLR_f.ERRCLR = 0;  
			return TRUE;
		}
	}
	
	return FALSE;
}

/*活塞台子代码开始区-------------------------------------------------------*/
/***************************************************************
函数名称： Check_Start_STOP_Filter_Flag()
返回值  ： 查询Start-Stop时，温度滤波标志
 ****************************************************************/
u8 Check_Start_STOP_Filter_Flag()
{
	return s_g_sample_ok_flag;		
}
/***************************************************************
函数名称： float sample_temp_value(void)  
返回值  ： 清零Start-Stop时，温度滤波标志
 ****************************************************************/
void Clear_Start_STOP_Filter_Flag()
{
	s_g_sample_ok_flag=0;		
}
/***************************************************************
函数名称： Check_Temperature_Parameter()
返回值  ： 返回Start-Stop的滤波后温度值
 ****************************************************************/
float Check_Temperature_Parameter()
{
	return temp_sample_value;		
}
/***************************************************************
函数名称： void start_temp_sample(void)
功    能； START 命令下开始进行温度采样
参    数： 
返回值  ： 
 ****************************************************************/
void start_temp_sample(void)
{
	if (10 == LcdCheckStateApp()) //非检定状态,不需每次都检测时间差
    {
        return;
    }
    
	if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定而且上位机不允许采样
	{
		return;
	}
	if(s_g_sample_start_flag)
	{
        s_g_temp_data[s_g_sample_head] = TempCheckValueApp(); //将温度值存入到数组中
        s_g_sample_head++;
		if(MAX_TEMP_NUM!=s_g_sample_head)//采样数组满了一次
		{
            if(s_g_sample_length !=MAX_TEMP_NUM) 
            {
                s_g_sample_length=s_g_sample_head;//
            }            
		}
        else
        {
            s_g_sample_length=MAX_TEMP_NUM;
        }
        s_g_sample_head %= MAX_TEMP_NUM;
	}
}
/*活塞台子*/
/* 
stop2下，闹钟失效的处理，RtccDriver，默认OB：看门狗在stop下运行
void WDTWakeUpClear(void);
void WDTWakeUpSumAdd(void);
u8 WDTWakeUpIfReset(void);
*/
u8 WDTWakeUpIfReset(void)
{
    return FALSE;  //先暂时未实现，PIC上已经实现
}
/*------------------------------ Function Define -------------------------------------*/
/******************************************************************************
 *   名称：  bcdToHex32
 *   功能：
 *   输入：  压缩BCD码
 *   输出：  hex值
 *   编写：
 *   日期：
 *   修改：  N/A
 ******************************************************************************/
u32 bcdToHex32(u32 value)
{
    signed char i;
    u8 factor;
    u32 rtval = 0;
    for (i = 28; i >= 0; i -= 4)
    {
        factor = (value >> i) & 0xf;
        if (factor > 9) return 0XFFFFFFFF; //数据错误
        rtval = rtval * 10 + factor;
    }
    return rtval;
}


/***************************************************************
函数名称： u32 FilterJunZhi(u32 *data, u8 data_len)
功    能； 中值+算数平均滤波
参    数： u32 *data 需要进行处理的数据数组地址
返回值  ： 滤波完成后的值
 ****************************************************************/
//void quick_sort(float *p, u8 l, u8 r)  //int a[]={49,38,65,97,76,13,27}; int l = 0;  int r = 6;
//{
//    u8 i, j;
//    float x;
//
//    if (l < r)
//    {
//        i = l;
//        j = r;
//        x = p[i];
//        while (i < j)
//        {
//            while(i < j && p[j] > x)
//                j--; /* 从右向左找第一个小于x的数 */
//            if(i < j)
//                p[i++] = p[j];
//
//            while(i < j && p[i] < x)
//                i++; /* 从左向右找第一个大于x的数 */
//            if(i < j)
//                p[j--] = p[i];
//
//        }
//        p[i] = x;
//        quick_sort(p, l, i-1); /* 递归调用 */
//        quick_sort(p, i+1, r);
//    }
//}


//void quiksort(float *a,u8 low,u8 high)
//{
//    u8 i = low;
//    u8 j = high;
//    float temp = a[i];
//
//    if( low < high)
//    {
//        while(i < j)
//        {
//            while((a[j] >= temp) && (i < j))
//            {
//                j--;
//            }
//            a[i] = a[j];
//            while((a[i] <= temp) && (i < j))
//            {
//                i++;
//            }
//            a[j]= a[i];
//        }
//        a[i] = temp;
//        quiksort(a,low,i-1);
//        quiksort(a,j+1,high);
//    }
//    else
//    {
//        return;
//    }
//}
//void quicksort(float* a,u8 left,u8 right)
//{
//    u8 i,j;
//    float temp;
//
//    i=left;
//    j=right;
//    temp=a[left];
//    if(left>right)
//        return;
//    while(i!=j)
//    {
//        while(a[j]>=temp&&j>i)
//            j--;
//        if(j>i)
//            a[i++]=a[j];
//        while(a[i]<=temp&&j>i)
//            i++;
//        if(j>i)
//            a[j--]=a[i];
//
//    }
//    a[i]=temp;
//    quicksort(a,left,i-1);
//    quicksort(a,i+1,right);
//}
//u32 FilterJunZhi(u32 *data, u8 data_len)
//{
//    u8 i, j, len, count;
//    u32 *p;
//    u32 temp = 0, sum = 0;

//    p = data;
//    len = data_len;

//    for (j = 0; j < len - 1; j++)
//    {
//        for (i = 0; i < len - 1 - j; i++)
//        {
//            if (p[i] > p[i + 1])
//            {
//                temp = p[i];
//                p[i] = p[i + 1];
//                p[i + 1] = temp;
//            }
//        }
//    }

//    for (count = 2; count < len - 2; count++)
//    {
//        sum += p[count];
//    }

//    return (u32) (sum / (len - 4));
//}
#if LILUNGONGSHI_MODLE_WATER_METER
 #if ROUND_LLGS_DN15_BRASS_40KPA_GP30_32768 || ROUND_LLGS_DN20_BRASS_40KPA_GP30_32768|| ROUND_LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768 \
 || ROUND_LLGS_XFZ_DN15_BRASS_40KPA_GP30_32768 ||  ROUND_LLGS_XFZ_DN20_BRASS_40KPA_GP30_32768 \
 ||Plastic_LLGS_WDFS_DN15_PALSTIC_40KPA_GP30_32768 
// 圆壳表专用  ----添上表计类型
/************理论公式判定误差补偿曲线函数*****************
Function:     遍历二维数组中的温度值确定温度范围，接着根据流量范围确定补偿曲线的数值    
Description: 需要传递值： 1、温度  2、时间差 3、瞬时流量
 ****************************************************************/
float ErrorModifyCruve(float temp_value_float,float time_dof_temp_float,float ins_flow_temp_float)
{
	u8 i=0;
	float error=1;
	u8 rows = sizeof(default_error_cruve)/sizeof(default_error_cruve[0]);//计算数组的行数
	
	for(i=0;i<(rows-1);i++)//先遍历找出温度所在的范围
	{
		if(temp_value_float <= default_error_cruve[i][0])
		{
			break;
		}
	}    
    if(ins_flow_temp_float <= SEGMENT_NUM_SMALL)//确定误差补偿曲线——————————用的误差建模时模型的分段 2021-11-17
	{
        error = default_error_cruve[i][1] + default_error_cruve[i][2]*temp_value_float + default_error_cruve[i][3]*time_dof_temp_float + 
						default_error_cruve[i][4]*temp_value_float*time_dof_temp_float + default_error_cruve[i][5]*time_dof_temp_float*time_dof_temp_float;
	}
	else if(ins_flow_temp_float <= SEGMENT_NUM_MIDDLE)
	{
		error = default_error_cruve[i][6] + default_error_cruve[i][7]*temp_value_float + default_error_cruve[i][8]*time_dof_temp_float + 
							  default_error_cruve[i][9]*temp_value_float*time_dof_temp_float + default_error_cruve[i][10]*time_dof_temp_float*time_dof_temp_float;
	}
	else//确定误差补偿曲线
	{
		error = default_error_cruve[i][11] + default_error_cruve[i][12]*temp_value_float + default_error_cruve[i][13]*time_dof_temp_float + 
							  default_error_cruve[i][14]*temp_value_float*time_dof_temp_float + default_error_cruve[i][15]*time_dof_temp_float*time_dof_temp_float;
	}
	return ins_flow_temp_float * error;
}
#else
/************理论公式判定误差补偿曲线函数*****************
Function:     遍历二维数组中的温度值确定温度范围，接着根据流量范围确定补偿曲线的数值    
Description: 需要传递值： 1、温度  2、时间差 3、瞬时流量
 ****************************************************************/
float ErrorModifyCruve(float temp_value_float,float time_dof_temp_float,float ins_flow_temp_float)
{
	u8 i=0;
	float error=1;
	u8 rows = sizeof(default_error_cruve)/sizeof(default_error_cruve[0]);//计算数组的行数
	
	for(i=0;i<(rows-1);i++)//先遍历找出温度所在的范围
	{
		if(temp_value_float <= default_error_cruve[i][0])
		{
			break;
		}
	}
    
    if(ins_flow_temp_float <= SEGMENT_NUM_MIDDLE)//确定误差补偿曲线——————————用的误差建模时模型的分段 2021-11-17
	{
		#if ERROR_MODIFY_CRUVE_FOR_SMALL_FLOW // 如果是PF25、PF32和PF40口径，就用小流量分段方式
        if(ins_flow_temp_float <= SEGMENT_NUM_SMALL)
        {
           error = default_error_cruve[i][1] + default_error_cruve[i][2]*temp_value_float + default_error_cruve[i][3]*time_dof_temp_float + 
							  default_error_cruve[i][4]*temp_value_float*time_dof_temp_float + default_error_cruve[i][5]*time_dof_temp_float*time_dof_temp_float;
		}
		else 
		{
			error = default_error_cruve[i][6] + default_error_cruve[i][7]*temp_value_float + default_error_cruve[i][8]*time_dof_temp_float + 
							  default_error_cruve[i][9]*temp_value_float*time_dof_temp_float + default_error_cruve[i][10]*time_dof_temp_float*time_dof_temp_float;	
		}
        #else
        error = default_error_cruve[i][1] + default_error_cruve[i][2]*temp_value_float + default_error_cruve[i][3]*time_dof_temp_float + 
						default_error_cruve[i][4]*temp_value_float*time_dof_temp_float + default_error_cruve[i][5]*time_dof_temp_float*time_dof_temp_float;
        #endif
	}
	else if(ins_flow_temp_float <= SEGMENT_NUM_ERROR_MIDDLE)//不锈钢15口径建模分段专用
	{
		error = default_error_cruve[i][6] + default_error_cruve[i][7]*temp_value_float + default_error_cruve[i][8]*time_dof_temp_float + 
							  default_error_cruve[i][9]*temp_value_float*time_dof_temp_float + default_error_cruve[i][10]*time_dof_temp_float*time_dof_temp_float;
	}
	else//确定误差补偿曲线
	{
		error = default_error_cruve[i][11] + default_error_cruve[i][12]*temp_value_float + default_error_cruve[i][13]*time_dof_temp_float + 
							  default_error_cruve[i][14]*temp_value_float*time_dof_temp_float + default_error_cruve[i][15]*time_dof_temp_float*time_dof_temp_float;
	}
	return ins_flow_temp_float * error;
}
    #endif
#endif 

float FilterJunZhi_TestForGp30_float(float *p, u8 data_len)   //滤波函数1——检定状态用于计算累积流量时，对瞬时流量的滤波
{
    u8 i, j, count,zero_sum = 0, valve_flag = 0, position = 0,start_flow_sum = 0;
    float temp = 0, sum = 0, average_diftof=0;
	if(data_len < 10)
	{
		return 0;
	}
	for (i = 0; i < data_len; i++)
	{
		if(((p[i]>=0)&&(p[i] < gp30_app_start_flow_filter_float))||((p[i]<0)&&(p[i] > gp30_app_start_flow_reverse_float)))
		{
			start_flow_sum++;
			zero_sum++;
			if (zero_sum == 2) //buffer0和buffer1静水，buffer234有流速，证明开阀
			{
				if(1==i)
				{
					if ((p[2] >= gp30_app_start_flow_filter_float)||(p[2] <= gp30_app_start_flow_reverse_float)) //后面连续3个大值，或者三个中有1个0的情况，表示开阀，只判正向开关阀
					{
						if((((p[3] >= gp30_app_start_flow_filter_float)||(p[3] <= gp30_app_start_flow_reverse_float)) && ((p[4] >= gp30_app_start_flow_filter_float)||(p[4] <= gp30_app_start_flow_reverse_float)))||((p[3] == 0) 
							&& ((p[4] >= gp30_app_start_flow_filter_float)||(p[4] <= gp30_app_start_flow_reverse_float)))||(((p[3] >= gp30_app_start_flow_filter_float)||(p[3] <= gp30_app_start_flow_reverse_float)) && (p[4] == 0)))
						{
							position = i;
							valve_flag = 1;
							break;
						}
					}
				}
				else if(15==i)//buffer14和buffer15静水，buffer11 12 13有流速，证明关阀
				{
					if((p[11] >= gp30_app_start_flow_filter_float)||(p[11] <= gp30_app_start_flow_reverse_float)) //后面连续3个大值，或者三个中有1个0的情况，表示开阀，只判正向开关阀
					{
						if((((p[12] >= gp30_app_start_flow_filter_float)||(p[12] <= gp30_app_start_flow_reverse_float)) && ((p[13] >= gp30_app_start_flow_filter_float)||(p[13] <= gp30_app_start_flow_reverse_float)))||((p[12] == 0) 
							&& ((p[13] >= gp30_app_start_flow_filter_float)||(p[13] <= gp30_app_start_flow_reverse_float)))||(((p[12] >= gp30_app_start_flow_filter_float)||(p[12] <= gp30_app_start_flow_reverse_float)) && (p[13] == 0)))
						{
							valve_flag = 2;
							position = i - 1;
							break;
						}
					}
				}
			}
			else if ((zero_sum >= 3)&&(zero_sum <= 13))  //连续3个低于始动
            {
                if (i < (data_len - 3))
                {
                    if ((p[i + 1] >= gp30_app_start_flow_filter_float)||(p[i + 1] <= gp30_app_start_flow_reverse_float)) //后面连续3个大值，或者三个中有1个0的情况，表示开阀，只判正向开关阀
                    {
						if((((p[i + 2] >= gp30_app_start_flow_filter_float)||(p[i+2] <= gp30_app_start_flow_reverse_float)) && ((p[i + 3] >= gp30_app_start_flow_filter_float)||(p[i+3] <= gp30_app_start_flow_reverse_float)))||((p[i + 2] == 0) 
							&& ((p[i + 3] >= gp30_app_start_flow_filter_float)||(p[i+3] <= gp30_app_start_flow_reverse_float)))||(((p[i + 2] >= gp30_app_start_flow_filter_float)||(p[i+2] <= gp30_app_start_flow_reverse_float)) && (p[i + 3] == 0)))
						{
							position = i;
							valve_flag = 1;
							break;
						}
                    }
                }
                if (i >= 5)
                {
                    if ((p[i - 3] >= gp30_app_start_flow_filter_float)||(p[i - 3] <= gp30_app_start_flow_reverse_float)) //前面连续3个大值，或者三个中有1个0的情况，表示关阀，只判正向开关阀
                    {
						if((((p[i - 4] >= gp30_app_start_flow_filter_float)||(p[i-4] <= gp30_app_start_flow_reverse_float)) && ((p[i - 5] >= gp30_app_start_flow_filter_float)||(p[i-5] <= gp30_app_start_flow_reverse_float)))||((p[i - 4] == 0) 
							&& ((p[i - 5] >= gp30_app_start_flow_filter_float)||(p[i-5] <= gp30_app_start_flow_reverse_float)))||(((p[i - 4] >= gp30_app_start_flow_filter_float)||(p[i-4] <= gp30_app_start_flow_reverse_float)) && (p[i - 5] == 0)))
						{
							valve_flag = 2;
							position = i - 2;
							break;
						}
                    }
                }
            }
			else if (zero_sum == 14) 
			{
				if (((p[14] >= gp30_app_start_flow_filter_float)||(p[14] <= gp30_app_start_flow_reverse_float)) && ((p[15] >= gp30_app_start_flow_filter_float)||(p[15] <= gp30_app_start_flow_reverse_float))) //14个0，判断 15 16是否是1，是1证明是开阀
				{
					valve_flag = 3;
					break;
				}
				else if (((p[0] >= gp30_app_start_flow_filter_float)||(p[0] <= gp30_app_start_flow_reverse_float)) && ((p[1] >= gp30_app_start_flow_filter_float)||(p[1] <= gp30_app_start_flow_reverse_float))) //14个0，判断 1 2是否是1，是1证明是关阀
				{
					valve_flag = 4;
					break;
				}
			}
		}
		else
		{
			zero_sum = 0;
		}
	}
	if(0==valve_flag)
    {
		for (j = 0; j < data_len - 1; j++)
		{
			for (i = 0; i < data_len - 1 - j; i++)
			{
				if (p[i] > p[i + 1])
				{
					temp = p[i];
					p[i] = p[i + 1];
					p[i + 1] = temp;
				}
			}
		}
		for (count = GP30_APP_FILTER_MAX_MIN_SIZE; count < (data_len - GP30_APP_FILTER_MAX_MIN_SIZE); count++) //两头各去掉2个数，应对数据跳变的异常，跳变处理，比这个数小1——即连续3次跳变就处理
		{
			sum += p[count];
		}
		sum =  sum / (data_len - GP30_APP_FILTER_SIZE);
			
		if((10 == LcdCheckStateApp())&&(start_flow_sum>=GP22_APP_EXCEED_START_FLOW_SUM))
		{			
			if(((sum > 0)&&(sum < FLOAT_15NS))||((sum < 0)&&((sum > -FLOAT_15NS))))
			{
					sum=0;
			}
		}
   }
    else if (1 == valve_flag)
    {
        position = position + 1;
        data_len = data_len - position;
        for (i = 0; i < data_len; i++)
        {
            sum += p[i + position];
        }
		average_diftof = sum/data_len;
		if(((average_diftof > 0)&&(average_diftof < FLOAT_2NS))||((average_diftof < 0)&&((average_diftof > -FLOAT_2NS))))
		{
			if((gp22_test_data.s.peak_up<=TOF_UP_AM)&&(gp22_test_data.s.peak_down<=TOF_DOWN_AM))
            {
               sum=0; 
            }
            else 
            {
               sum = sum / GP22_APP_QUEUE_SIZE; 
            }            
		}
		else
		{
			sum = sum / GP22_APP_QUEUE_SIZE;
		}
    }
    else if (2 == valve_flag)
    {
        for (i = 0; i < position; i++)
        {
            sum += p[i];
        }
		average_diftof = sum/position;
		if(((average_diftof > 0)&&(average_diftof < FLOAT_2NS))||((average_diftof < 0)&&((average_diftof > -FLOAT_2NS))))
		{
			if((gp22_test_data.s.peak_up<=TOF_UP_AM)&&(gp22_test_data.s.peak_down<=TOF_DOWN_AM))
            {
               sum=0; 
            }
            else 
            {
               sum = sum / GP22_APP_QUEUE_SIZE; 
            } 
		}
		else
		{
			sum = sum / GP22_APP_QUEUE_SIZE;
		}
    }
	else if (3 == valve_flag)//前面14个0，后面2个大于始动的开阀处理
    {
		sum = p[14]+p[15];
		average_diftof = sum/2;
		if(((average_diftof > 0)&&(average_diftof < FLOAT_2NS))||((average_diftof < 0)&&((average_diftof > -FLOAT_2NS))))
		{
			if((gp22_test_data.s.peak_up<=TOF_UP_AM)&&(gp22_test_data.s.peak_down<=TOF_DOWN_AM))
            {
               sum=0; 
            }
            else 
            {
               sum = sum / GP22_APP_QUEUE_SIZE; 
            } 
		}
		else
		{
			sum = sum / GP22_APP_QUEUE_SIZE;
		}
    }
	else if (4 == valve_flag)//前面2个大于始动的buffer，后面14个小于始动的关阀处理
    {
		sum =  p[0]+p[1];
		average_diftof = sum/2;
		if(((average_diftof > 0)&&(average_diftof < FLOAT_2NS))||((average_diftof < 0)&&((average_diftof > -FLOAT_2NS))))
		{
			if((gp22_test_data.s.peak_up<=TOF_UP_AM)&&(gp22_test_data.s.peak_down<=TOF_DOWN_AM))
            {
               sum=0; 
            }
            else 
            {
               sum = sum / GP22_APP_QUEUE_SIZE; 
            }
		}
		else
		{
			sum =  sum / GP22_APP_QUEUE_SIZE;
		}
    }
	return sum;
}
	
//u32 FilterJunZhi_TestForGp30(u32 *data, u8 data_len)   //滤波函数1——检定状态用于计算累积流量时，对瞬时流量的滤波
//{
//    u8 i, j, len, count;
//    u32 *p;
//    u32 temp = 0, sum = 0;
////	u32 front_avg = 0,behind_avg = 0;
////	u32 sum_difference_value[2]={0};//两次连续sum的差值
////	static u32 GP30_filter_value[3]={0};//上次数滤波缓存数组
////	static u8 sum_cnt=0;//sum次数

//    p = data;
//    len = data_len;
//	
//	if(len < 10)
//	{
//		return 0;
//	}

//    for (j = 0; j < len - 1; j++)
//    {
//        for (i = 0; i < len - 1 - j; i++)
//        {
//            if (p[i] > p[i + 1])
//            {
//                temp = p[i];
//                p[i] = p[i + 1];
//                p[i + 1] = temp;
//            }
//        }
//    }
////	//16个buffer中有大于等于一半的数是相同的，则用上次数
////	if((p[0]==p[7])||(p[1]==p[8])||(p[2]==p[9])||(p[3]==p[10])||(p[4]==p[11])||(p[5]==p[12])||(p[6]==p[13])||(p[7]==p[14])||(p[8]==p[15]))
////	{
////		return GP30_filter_last_value;
////	}
//    for (count = GP30_APP_FILTER_MAX_MIN_SIZE; count < (len - GP30_APP_FILTER_MAX_MIN_SIZE); count++) //两头各去掉4个数，应对数据跳变的异常，跳变处理，比这个数小1——即连续3次跳变就处理
//    {
//        sum += p[count];
//    }

//    sum = (u32) (sum / (len - GP30_APP_FILTER_SIZE));
////	if( sum < GP30_DIFTOF_FILTER_ENABLE_MAX_VALUE )//时间差小于30ns才进行滤波算法
////	{
////		GP30_filter_value[sum_cnt]=sum;
////		sum_cnt++;
////		if(3==sum_cnt)//sum值缓存数组元素个数为3
////		{
////			sum_cnt=0;
////		}
////		//计算sum第一个缓存和第二个缓存的差值
////		if(GP30_filter_value[1]>GP30_filter_value[0])
////		{
////			sum_difference_value[0]=GP30_filter_value[1]-GP30_filter_value[0];
////		}
////		else
////		{
////			sum_difference_value[0]=GP30_filter_value[0]-GP30_filter_value[1];
////		}
////		//计算sum第二个缓存和第三个缓存的差值
////		if(GP30_filter_value[2]>GP30_filter_value[1])
////		{
////			sum_difference_value[1]=GP30_filter_value[2]-GP30_filter_value[1];
////		}
////		else
////		{
////			sum_difference_value[1]=GP30_filter_value[1]-GP30_filter_value[2];
////		}
////		//sum三次值两两差值波动判断，波动平稳则更新上次数，不平稳上次数不更新。
////		if((sum_difference_value[0]<sum * FLOW_RATE_FILTER_COEFFICIENT)&&(sum_difference_value[1]<sum * FLOW_RATE_FILTER_COEFFICIENT))
////		{
////			GP30_filter_last_value=(GP30_filter_value[0]+GP30_filter_value[1]+GP30_filter_value[2])/3;//三次sum值都平稳，则选用这三次值的平均值当做上次数
////		}
////		
////		half_len = len/2 ;
////		
////		for (count = 0; count < half_len; count++) //前8个数
////		{
////			front_avg += p[count];
////		}
////		front_avg = front_avg/half_len;

////		for (count = half_len; count < len; count++) //后8个数
////		{
////			behind_avg += p[count];
////		}
////		behind_avg = behind_avg/half_len;
////		
////		if((behind_avg > front_avg) &&(sum >gp30_app_start_flow_filter)) 
////		{
////			if((behind_avg - front_avg) > sum * FLOW_RATE_FILTER_COEFFICIENT)
////			{
////				return GP30_filter_last_value;
////			}
////			else//这次采样的数值即使波动不大，与上次数比较，波动大也需要用上次数
////			{
////				if(sum > GP30_filter_last_value)
////				{
////					if((sum-GP30_filter_last_value)>sum * FLOW_RATE_FILTER_COEFFICIENT)
////					{
////						return GP30_filter_last_value;
////					}
////					else
////					{
////						return sum;
////					}
////				}
////				else
////				{
////					if((GP30_filter_last_value-sum)>sum * FLOW_RATE_FILTER_COEFFICIENT)
////					{
////						return GP30_filter_last_value;
////					}
////					else
////					{
////						return sum;
////					}
////				}
////			}
////		}
////		else if((behind_avg == front_avg) && (sum > gp30_app_start_flow_filter))
////		{
////			return GP30_filter_last_value;
////		}
////	}
//	return sum;
//}

/***************************************************************
函数名称： float FilterJunZhi_float(float *p, u8 len)   //不排序，去掉两头最值
功    能；
参    数：
返回值  ： 滤波完成后的值
 ****************************************************************/
//float FilterJunZhi_float(float *p, u16 len)   //不排序，去掉两头各一个最值14ms
//{
//    u16 i;
//    float nMax,nMin,sum = 0;
//
//    nMax = p[0];
//    nMin = p[0];
//    for (i=0; i<len; i++)
//    {
//        if (nMin > p[i])
//        {  
//            nMin = p[i];
//        }
//
//        if (nMax < p[i])
//        {
//            nMax = p[i];
//        }
//        
//        sum = sum + p[i];
//    }
//    sum = sum - nMax -nMin;
//    
//    return (float) (sum / (len - 2));
//}

//float FilterJunZhi_float(float *p, u8 len)   //不排序，去掉两头 各两个最值20ms
//{
//    u8 i;
//    float nMax,nMin,nMax2,nMin2,sum = 0;

//    nMax=0;
//    nMax2=0;
//    nMin=0x40000;
//    nMin2=0x40000;


//    for (i=0; i<len; i++)
//    {
//        if(p[i]>nMax)
//        {
//            nMax2=nMax;
//            nMax=p[i];
//        }
//        else if(p[i]>nMax2)
//        {
//            nMax2=p[i];
//        }

//        if(p[i]<nMin)
//        {
//            nMin2=nMin;
//            nMin=p[i];
//        }
//        else if(p[i]<nMin2)
//        {
//            nMin2=p[i];
//        }

//        sum = sum + p[i];
//    }
//    sum = sum - nMax -nMin - nMax2 - nMin2;

//    return (float) (sum / (len - 4));
//}

/**
 * 将输入序列划分为两个子序列，并返回中间位置的下标
 * 
 * @param arr 输入划分的输入序列
 * @param left 需要划分序列的最左侧元素下标
 * @param right 需要划分序列的最右侧位置下标
 * @return 找到的中心位置坐标
 */
//u8 partition(float arr[], int left, int right) 
//{
//    u8 j = left, i;
//    float selectedValue = arr[right];
//    float temp;
//    // 用j指定预期的中心点位置
//    // 用游标i从左向右遍历，如果小于选定值，则扔到j指定位置的左侧，否则继续向右
//    for (i = left; i < right; i++) {
//        if (arr[i] < selectedValue) {
//            // 交换i与j位置的值，并更新j指向的位置
//            temp = arr[i];
//            arr[i] = arr[j];
//            arr[j] = temp;
//            j++;
//        }
//    }
//    arr[right] = arr[j];
//    arr[j] = selectedValue;
//    return j;
//}

/**
 * 对输入序列进行快速排序
 *
 * @param arr 待排序数组
 * @param left 需要排列位置的最左侧元素下标
 * @param right 需要排序位置的最右侧位置下标
 */
//void quickSort(float arr[], u8 left, int right) 
//{
//    u8 q;
//    if (left < right) {
//        q = partition(arr, left, right);
//        quickSort(arr, left, q - 1);
//        quickSort(arr, q + 1, right);
//    }
//}

#if EN_LARGE_FILITER
float FilterJunZhi_float_GP30Filter(float *p, u8 len)   //滤波函数2——针对GP30一个buf数据波动的滤波
{
	u8 count,i,j;
	float sum=0,temp,sum_ou=0,sum_ji=0;
	float p_ji[8],p_ou[8];

	for (j = 0; j < len; j=j+2)
	{
		p_ou[j/2] = p[j];
		p_ji[j/2] = p[j+1];
	}

	//分开排序 滤波
	for (j = 0; j < len/2 - 1; j++)
    {
        for (i = 0; i < len/2 - 1 - j; i++)
        {
            if (p_ou[i] > p_ou[i + 1])
            {
                temp = p_ou[i];
                p_ou[i] = p_ou[i + 1];
                p_ou[i + 1] = temp;
            }
			
			if (p_ji[i] > p_ji[i + 1])
            {
                temp = p_ji[i];
                p_ji[i] = p_ji[i + 1];
                p_ji[i + 1] = temp;
            }
			
        }
    }

	for (count = 1; count < (len/2 - 1); count++) //两头各去掉1个数
    {
		sum_ou += p_ou[count];
        sum_ji += p_ji[count];
    }
    sum = (float) (sum_ou+sum_ji) / (len - 4);


	return sum;
}
#elif EN_SMALL_FILITER 
float FilterJunZhi_float_GP30Filter(float *p, u8 len)   //滤波函数2——针对GP30一个buf数据波动的滤波
{
	u8 count,filter_min_max,half_len,i,j;
	float sum=0,temp;
//	gp30_app_start_flow_filter_for_float = Gp30DataToFloat(gp30_app_start_flow_filter);
    
	//不再采用快速排序 2019-11-29 16:28:16
//    quickSort(p,0,len-1);
    for (j = 0; j < len - 1; j++)
    {
        for (i = 0; i < len - 1 - j; i++)
        {
            if (p[i] > p[i + 1])
            {
                temp = p[i];
                p[i] = p[i + 1];
                p[i + 1] = temp;
            }
        }
    }
//	if((p[0]==p[7])||(p[1]==p[8])||(p[2]==p[9])||(p[3]==p[10])||(p[4]==p[11])||(p[5]==p[12])||(p[6]==p[13])||(p[7]==p[14])||(p[8]==p[15]))
//	{
//		return -1000;
//	}
	half_len = len/2 ;  
	filter_min_max = half_len/2;  //排序后前后滤波的个数
	for (count = filter_min_max; count < (len - filter_min_max); count++) //两头各去掉filter_min_max个数
    {
        sum += p[count];
    }

    sum = (float) (sum / (len - half_len));
//	if( sum < Gp30DataToFloat(GP30_DIFTOF_FILTER_ENABLE_MAX_VALUE) )//时间差小于30ns才进行滤波算法
//	{
//		for (count = 0; count < half_len; count++) //前半个buf
//		{
//			front_avg += p[count];
//		}
//		front_avg = front_avg/half_len;

//		for (count = half_len; count < len; count++) //后半个buf
//		{
//			behind_avg += p[count];
//		}
//		behind_avg = behind_avg/half_len;
//		
//		if((behind_avg > front_avg) &&(sum > gp30_app_start_flow_filter_for_float))
//		{
//			if((behind_avg - front_avg) > sum * GP30_DIFTOF_FILTER_COEFFICIENT)   //2019-10-11 ——修改由0.3改为0.2
//			{
////				if((GP30_filter_last_value_for_shunshi > (float)30*sum)||(GP30_filter_last_value_for_shunshi < (float)0.03*sum))
//////				if(GP30_filter_last_value_for_shunshi < (float)0.03*sum)
////				{
////					return sum;
////				}
////				else
//				{
////					return GP30_filter_last_value_for_shunshi;
//					//返回一个固定数值，用于判断此次滤波数据是否需要丢弃
//					return -1000;
//				}
//			}
//			else
//			{
//				return sum;
//			}
//		}
//		else if((behind_avg == front_avg) && (sum > gp30_app_start_flow_filter_for_float))
//		{
////			return GP30_filter_last_value_for_shunshi;
//			return -1000;
//		}
//		else if(sum + gp30_app_start_flow_filter_for_float<0)
//		{
//			return -1000;
//		}
//	}
	return sum;
}
#endif
/****************************************************************
Function:    float FilterJunZhi_float_DIFTOFFilter (float *p, u8 len)
Description:  GP30时间差快速排序滤波，去掉2个最大和最小取平均，不做其他处理
Input:
Return:
Others:
 *****************************************************************/
float FilterJunZhi_float_DIFTOFFilter(float *p, u8 len)                     //滤波函数3——针对大数组以及非检定，只去掉一个最大一个最小值
{
//	float diftof_buffer[GP22_APP_DIFTOF_SIZE_2]={0}; //时间差滤波缓存 2019-8-21
	u8 i;
	float sum=0,nMax,nMin;
	
	if(len > GP22_APP_DIFTOF_SIZE_2)
    {
       len=GP22_APP_DIFTOF_SIZE_2;  
    }
//	for(i=0;i<len;i++)
//	{
//		diftof_buffer[i]=*(p+i);//将时间差数组的数据放进缓存buffer里，对缓存buffer进行排序，不对原始数组排序
//	}
	
	//quickSort(diftof_buffer,0,len-1);
	nMax = p[0];
	nMin = p[0];
    for (i=0; i<len; i++)
    {
        if (nMin > p[i])
        {  
            nMin = p[i];
        }

        if (nMax < p[i])
        {
            nMax = p[i];
        }
        
        sum = sum + p[i];
    }
    sum = sum - nMax -nMin;
    
    return (float) (sum / (len - 2));
	
//	for (count = 2; count < (len - 2); count++) //两头各去掉2个数
//    {
//        sum += diftof_buffer[count];
//    }
//	
//    return (float) (sum / (len - 4));
	
}

/****************************************************************
Function:    void Gp22AppDataPre (void)
Description:  备份数据组织
Input:
Return:
Others:
 *****************************************************************/
void Gp22AppDataPre(void) 
{
    static DateTime data_time;

    g_sample_save_data.s.flag[0] = 0x77;
    g_sample_save_data.s.flag[1] = 0x88;
    RtccGetDateTime(&data_time);
    g_sample_save_data.s.time[0] = data_time.s.year;
    g_sample_save_data.s.time[1] = data_time.s.month;
    g_sample_save_data.s.time[2] = data_time.s.day;
    g_sample_save_data.s.time[3] = data_time.s.hour;

    g_sample_save_data.s.total_flow.gp30_u32 = gp22_app_data.s.total_flow.gp30_u32;
	g_sample_save_data.s.total_flow_reverse.gp30_u32 = gp22_app_data.s.total_flow_reverse.gp30_u32;         
    g_sample_save_data.s.up_tof_dif.gp30_u32 = gp22_app_data.s.up_tof_dif.gp30_u32;
    g_sample_save_data.s.down_tof_dif.gp30_u32 = gp22_app_data.s.down_tof_dif.gp30_u32;
}

/****************************************************************
Function:    void Gp22AppInitProcess (void)
Description:  GP22应用处理机上电初始化操作 ,GP22部分
Input:
Return:
Others:
 *****************************************************************/
void Gp22AppInitProcess(void)
{
    static u8 ee_write_result_init;
    u8 i;
//    u32 data;
//    static float reset_limit_data = 0;
//	float nDoubleTemp=0.0;

	
	
    switch (s_g_gp22_init_state_num)
    {
    case GP30_APP_INIT_S0:
        if (EepIfIdle())
        {
            for (i = 0; i < GP30_APP_MAX_DATA; i++)
            {
                gp22_app_data.data[i] = 0;
                gp22_test_data.data[i] = 0;
            }
            EepRead(GP30_APP_DATA_ADDR, &g_sample_save_data.data[0], sizeof (GP30_APP_SAVE_DATA), &ee_write_result_init);
            s_g_gp22_init_state_num = GP30_APP_INIT_S1;
        }
        break;
    case GP30_APP_INIT_S1:
        if ((SUCCESS == EepCheckMsg(ee_write_result_init)) && (TASK_IDLE == EepIfIdle())) //读ee成功
        {
            if ((0x77 == g_sample_save_data.s.flag[0]) && (0x88 == g_sample_save_data.s.flag[1])) //不是第一次上电
            {
//                if((gp22_copy_total_flow > g_sample_save_data.s.total_flow.gp30_float)||(gp22_copy_total_flow_reverse > g_sample_save_data.s.total_flow_reverse.gp30_float))//2017 02,更改复位不丢数
//                {
//                    data = FrameCheckParaApp(FramePara_DNx);
//                    if(0x15 ==data)
//                    {
//                        reset_limit_data = 250.0;
//                    }
//                    else if(0x20 == data)
//                    {
//                        reset_limit_data = 400.0;
//                    }
//                    else if(0x25 == data)
//                    {
//                        reset_limit_data = 500.0;
//                    }
//                    else if(0x32 == data)
//                    {
//                        reset_limit_data = 1000.0;
//                    }
//                    else if(0x40 == data)
//                    {
//                        reset_limit_data = 1200.0;
//                    }					
				if(MCU_RESET_JUDGE_FLAG == MCU_reset_judge)//非断电复位
				{						
					//使用ram控制器自带的奇偶校验功能 判别gp22_copy_total_flow存放的ram数据是否正确
					//数据检验
					if(TRUE == RAMDataVerify((u8*)&gp22_copy_total_flow,sizeof(gp22_copy_total_flow)))
                    {
                        gp22_copy_total_flow=g_sample_save_data.s.total_flow.gp30_float;
                    }
                    else
                    {
                       g_sample_save_data.s.total_flow.gp30_float = gp22_copy_total_flow;
                    }
					//
					if(TRUE == RAMDataVerify((u8*)&gp22_copy_total_flow_reverse,sizeof(gp22_copy_total_flow_reverse)))
                    {  
                        gp22_copy_total_flow_reverse=g_sample_save_data.s.total_flow_reverse.gp30_float;
                    }
                    else
                    {
                        g_sample_save_data.s.total_flow_reverse.gp30_float = gp22_copy_total_flow_reverse;
                    } 
					s_g_gp22_init_state_num = GP30_APP_INIT_S5;
				}
				else
				{                   
					s_g_gp22_init_state_num = GP30_APP_INIT_S7;
				}
				
				//UP和DOWN单程时间补偿值合法性判断
				if(((g_sample_save_data.s.up_tof_dif.gp30_float)>TOF_COMPENSATION_COEFFICIENT)||((g_sample_save_data.s.down_tof_dif.gp30_float)>TOF_COMPENSATION_COEFFICIENT)|| \
					((g_sample_save_data.s.up_tof_dif.gp30_float)<-TOF_COMPENSATION_COEFFICIENT)||((g_sample_save_data.s.down_tof_dif.gp30_float)<-TOF_COMPENSATION_COEFFICIENT))
				{
					g_sample_save_data.s.up_tof_dif.gp30_float = 0;
					g_sample_save_data.s.down_tof_dif.gp30_float = 0; 
					s_g_gp22_init_state_num = GP30_APP_INIT_S5;                        
				}
								
                gp22_app_data.s.total_flow.gp30_u32 = g_sample_save_data.s.total_flow.gp30_u32;
				gp22_app_data.s.total_flow_reverse.gp30_u32 = g_sample_save_data.s.total_flow_reverse.gp30_u32;
				old_monitor_flow.gp30_u32 = g_sample_save_data.s.total_flow.gp30_u32;//非第一次上电记录EE累计流量值
				gp22_app_data.s.up_tof_dif.gp30_float = g_sample_save_data.s.up_tof_dif.gp30_float;
				gp22_app_data.s.down_tof_dif.gp30_float = g_sample_save_data.s.down_tof_dif.gp30_float;
                
                duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                //此处需要记录下初值给GP30
//                gp30_test_total_start_flow.gp30_u32 = gp22_app_data.total_flow.gp30_u32;

            }
            else //是第一次上电
            {
				 old_monitor_flow.gp30_u32 =0;//第一次上电流量值清零
                if (EepIfIdle())
                {
                    Gp22AppDataPre();
                    EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_init);
                    s_g_gp22_init_state_num = GP30_APP_INIT_S3;
                }
                else
                {
                    s_g_gp22_init_state_num = GP30_APP_INIT_S2;
                }
            }
        }
//        else if (ERROR == EepCheckMsg(ee_write_result_init)) //读EE异常
//        {
//            s_g_gp22_init_state_num = GP30_APP_INIT_S4;
//        }
        break;
    case GP30_APP_INIT_S2:
        if (EepIfIdle())
        {
            Gp22AppDataPre();
            EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_init);
            s_g_gp22_init_state_num = GP30_APP_INIT_S3;
        }
        break;
    case GP30_APP_INIT_S3: //查询是否写完成
        if ((SUCCESS == EepCheckMsg(ee_write_result_init))&& (TASK_IDLE == EepIfIdle())) //写成功
        {
            s_g_gp22_init_state_num = GP30_APP_INIT_S7;
        }
        break;
//    case GP30_APP_INIT_S4: //初始化完成
//		if (EepIfIdle())
//		{
//			if(0x00004D3C==FrameCheckParaApp(FramePara_CCFlow))//逆流开关
//			{
//				gp22_app_data.s.total_flow_reverse.gp30_float=0;
//				g_sample_save_data.s.total_flow_reverse.gp30_u32=0;
//				gp22_copy_total_flow_reverse=0;
//				EepWrite(&g_sample_save_data.data[14], GP30_APP_DATA_TOTAL_FLOW_ADDR_REVERSE, 4, &ee_write_result_init);
//			}
//			s_g_gp22_init_state_num = GP30_APP_INIT_S7;
//		}
//        break;
    case GP30_APP_INIT_S5://2017 02,更改复位不丢数
        if (EepIfIdle())
        {
            EepWrite(&g_sample_save_data.data[6], GP30_APP_DATA_TOTAL_FLOW_ADDR, 16, &ee_write_result_init);//原来只写正负流量  现在加上8字节的up和down单程时间的差值
            s_g_gp22_init_state_num = GP30_APP_INIT_S3;
        }
        break;
	case GP30_APP_INIT_S6:
//		if ((SUCCESS == EepCheckMsg(ee_write_result_init))&& (TASK_IDLE == EepIfIdle())) //写成功
//        {
            mater_waring_state = FrameCheckParaApp(FramePara_Sta1_2);
            g_gp22_init_flag = 1;
//        }
        break;
	case GP30_APP_INIT_S7:
		if ((SUCCESS == EepCheckMsg(ee_write_result_init))&& (TASK_IDLE == EepIfIdle())) //写成功
		{
			EepRead(DIFTOF_CALIBRATION_FLAG_ADDR, &g_diftof_cal_data.data[0], sizeof (GP30_DIFTOF_CAL_DATA), &ee_write_result_init);
			s_g_gp22_init_state_num = GP30_APP_INIT_S8;
		}
		break;
	case GP30_APP_INIT_S8:
		if ((SUCCESS == EepCheckMsg(ee_write_result_init))&& (TASK_IDLE == EepIfIdle())) //写成功
		{
			if(FALSE == CheckDiftofCalibrationFlag())
			{
				g_diftof_cal_data.s.diftof_calibration_value.data=0;
			}
			s_g_gp22_init_state_num = GP30_APP_INIT_S6;
		}
		break;
		
    default:
        break;
    }
}

/****************************************************************
Function:    void Gp22TestInitApp (void)
Description:  进入检定初始化
Input:
Return:
Others:
 *****************************************************************/
void Gp22TestInitApp(void)
{
    u16 i;
    LPTimer0Init(RTC_ClkSource(), 128);//定时1s
	//RtccSetAlrm(0, TEST_ALARMA_RTCC_US);		//500ms
	s_alarma_stop_check_tick=Timer1usGetTick();
//	gp30_total_flow_calcult_factor = FACTOR_0_5;
//	RtccSetAlrm(0, 62500);		//62.5ms
//    s_g_gp22_sample_span = GP22_SAMPLE_2HZ;    //2016-8-2 每次都计算
//    s_g_gp22_sample_flag_num = 0;

//    s_g_sample_flow_num = 0; //即采样次数清零
	if((TRUE == RAMDataVerify((u8*)&gp22_copy_temp_total_flow_float_test,sizeof(gp22_copy_temp_total_flow_float_test)))||\
		(TRUE == RAMDataVerify((u8*)&gp22_copy_total_flow_test,sizeof(gp22_copy_total_flow_test)))||\
		(gp22_copy_temp_total_flow_float_test<(float)0)||(gp22_copy_temp_total_flow_float_test >(float)1500)||(gp22_copy_total_flow_test < (float)0))      
	 {
		 gp22_copy_temp_total_flow_float_test = 0;//保证
		 gp22_copy_total_flow_test = 0;         
	 }
	 if((TRUE == RAMDataVerify((u8*)&record_last_calculative_time,sizeof(record_last_calculative_time))))
	 {
		record_last_calculative_time = 0;
	 }
     #if (HARDWARE_VERSION==0x18)//圆壳表主板 
      if(FrameCheckMsgApp(Msg_WdtReset)) //如果是没及时喂狗导致的复位
     {
         FrameClearMsgApp(Msg_WdtReset);//清除看门狗复位源
         gp22_test_data.s.total_flow.gp30_float= gp22_copy_total_flow_test+(((float)record_last_calculative_time/(float)128)+(float)2.06)*gp22_copy_temp_total_flow_float_test;//1s的累积量 2.2 -2 .05
		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)2.06)*gp22_copy_temp_total_flow_float_test/(float)1000;    
     }
     else//其他情况的复位	
     {
         gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test+(((float)record_last_calculative_time/(float)128)+(float)0.33)*gp22_copy_temp_total_flow_float_test;//1s的累积量 //0.5-0.3-0.36-0.33
		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)0.33)*gp22_copy_temp_total_flow_float_test/(float)1000;
     }
     #elif (HARDWARE_VERSION==0x14) //方壳表主板 
    if(FrameCheckMsgApp(Msg_WdtReset)) //如果是没及时喂狗导致的复位
     {
         FrameClearMsgApp(Msg_WdtReset);//清除看门狗复位源
         gp22_test_data.s.total_flow.gp30_float= gp22_copy_total_flow_test+(((float)record_last_calculative_time/(float)128)+(float)2.35)*gp22_copy_temp_total_flow_float_test;//1s的累积量  2.45
		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)2.35)*gp22_copy_temp_total_flow_float_test/(float)1000;    
     }
     else//其他情况的复位	
     {
         gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test+(((float)record_last_calculative_time/(float)128)+(float)0.35)*gp22_copy_temp_total_flow_float_test;//1s的累积量 0.46
		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)0.35)*gp22_copy_temp_total_flow_float_test/(float)1000;
     }
     #endif
    duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
    gp22_copy_temp_total_flow_float = 0;
	start_measure_flag = 1; //启动流量采样
    s_g_sample_ok_flag = 0;
//    temp_total_flow_u32 = 0;

	gp22_test_data.s.total_flow_reverse.gp30_float = 0;
	
    gp22_test_data.s.ins_flow = 0;
    gp22_app_data.s.ins_flow = 0;
    gp22_test_data.s.ins_flow_cnt = 0;//瞬时流量每计算一次就加1次
    gp22_test_data.s.ins_flow_sum = 0;//瞬时流量累计和
	gp22_test_data.s.ins_flow_sum_temp = 0;
	gp22_test_data.s.ins_flow_max = 0;
	gp22_test_data.s.ins_flow_min = 0;
	
    for (i = 0; i < GP22_APP_QUEUE_SIZE; i++)
    {
        s_g_flow_data[i] = 0;
    }
	memset(s_g_flow_type, 0, sizeof(s_g_flow_type));
    for (i = 0; i < GP22_APP_DIFTOF_SIZE; i++)
    {
        s_g_diftof_data[i] = 0;
    }
    for (i = 0; i < GP22_APP_DIFTOF_SIZE_2; i++) 
    {
        s_g_diftof_data_2[i] = 0;
    }
	
	#if EN_LARGE_FILITER
	for (i = 0; i < GP22_APP_DIFTOF_SIZE_3; i++) 
    {
        s_g_diftof_data_3[i] = 0;
    }
	s_g_diftof_head_3 = 0;
	s_g_diftof_head_3_quotient=0;
	#endif
	
    s_g_diftof_head = 0;
    s_g_diftof_head_2 = 0;
	s_g_diftof_head_2_quotient=0;
    s_g_sample_total_sum = 0;
    s_g_diftof_for_total = FALSE; 
//    s_g_sample_flow_head = 0;
    

//    s_g_sample_total_sum = 0;
//    s_g_sample_add = 0;
}
/****************************************************************
Function:    void Gp22SampleApp (void)
Description:  采样间隔设置处理机
Input:
Return:
Others:
 *****************************************************************/
void Gp22SampleApp(void)
{
//    u16 i;

    switch (s_g_gp22_sample_app_state_num)
    {
    case GP22_APP_SAMPLE_S0:
        if (10 == LcdCheckStateApp()) //非检定状态
        {     
			NormalResetCompensation();			
//            SetResetFlowcompMsg();
			
//            s_g_sample_flow_num = 0; //即采样次数清零
//            s_g_gp22_sample_flag_num = 0;
//			Gp22SetSampleRate(8); //采样频率8Hz
//			Gp22SetBufferLength(16);//长度16
            s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S2;
        }
        else //检定状态
        {
//			VerificationResetCompensation();
            Gp22TestInitApp();
//			Gp22SetSampleRate(16); //采样频率16Hz
//			Gp22SetBufferLength(16);//长度16
            s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S1;
        }
        break;
    case GP22_APP_SAMPLE_S1:
        if (10 == LcdCheckStateApp()) //非检定状态
        {
			LPTimer0_Work(FALSE);//不开启LPtimer
            s_g_sample_ok_flag=0;//清除采样完成标志位
			Gp22SetSampleRateMsg(8); //采样频率8Hz
//			Gp22SetBufferLength(16);//长度16
			gp22_copy_total_flow_test=0;//每次从检定到退检定，清掉copy的检定累计量和上1s的累积量
			gp22_copy_temp_total_flow_float_test=0;
			gp22_copy_temp_total_flow_float=0;
			gp22_copy_reset_flag_test = GP30_COPY_RESET_NORMAL_FLAG;//保存非检定标志
            s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S2;
//            s_g_sample_flow_num = 0; //即采样次数清零
//            s_g_gp22_sample_flag_num = 0;
        }
        break;
    case GP22_APP_SAMPLE_S2:
        if (1 == LcdCheckStateApp()) //检定状态
        {
            record_last_calculative_time = 0;//防止非检定进检定补偿
			Gp22TestInitApp();
			Gp22SetSampleRateMsg(16); //采样频率16Hz
//			Gp22SetBufferLength(16);//长度16
			gp22_copy_reset_flag_test = GP30_COPY_RESET_TEST_FLAG;//保存检定标志
            s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S1;
        }
        break;
    default:
        break;
    }
}


/******将数据（float类型）转化为16位整数，16位小数格式*************
Function:    u32 FloatToGp30Data (float data)
Description:  将数据（float类型）转化为16位整数，16位小数格式
Input:
Return:     返回1个 补码数据格式 数据
Others:     运行时间：130us @3.6864M不分频/ PIC24FJ128GA306 /s级优化
 ****************************************************************/
u32 FloatToGp30Data(float data)
{
    if (data > 32768)
    {
        return 0;
    }
    return ((u32) (data * (float)65536));
}

/*************将16位整数，16位小数转化为浮点数格式******************
Function:    float Gp30DataToFloat (u32 data)
Description:  将16位整数，16位小数转化浮点数格式
Input:
Return:     返回数浮点数
Others:     运行时间：130us @3.6864M不分频/ PIC24FJ128GA306 / s级优化
 ****************************************************************/
float Gp30DataToFloat(u32 data)
{
    return ((float) data / (float)65536);
}


/****************************************************************
Function:    void StillWatetCalculate (void)
Description:  计算时间差
Input:
Return:
Others:
 *****************************************************************/
#if EN_SMALL_FILITER
void StillWatetCalculate(u32 dif_value)
{
    u8 i = 0;
    u32 temp_value;
    float still_water_add = 0, float_differ=0;

    if (10 == LcdCheckStateApp()) //非检定状态,不需每次都检测时间差
    {
        return;
    }
	if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定状态，且上位机不允许采样
	{
		return;
	}

    temp_value = dif_value;
    if (temp_value >= 0x80000000) //负数
    {
		temp_value &= 0x7FFFFFFF;
		float_differ = 0 - Gp30DataToFloat(temp_value);
    }
    else
    {
//        float_differ_last_time = temp_value;
        float_differ = Gp30DataToFloat(temp_value);
    }

//	// 2019-12-10 10:14:37   滤波改动，应对跳变
//	if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定而且上位机不允许采样
//	{

//		s_g_diftof_data_testforlastvalue[s_g_diftof_head_testforlastvalue] = float_differ;//带正负号
//		s_g_diftof_head_testforlastvalue++;
//		s_g_diftof_head_testforlastvalue %= GP22_APP_DIFTOF_SIZE;
//		
//		if(0 == s_g_diftof_head_testforlastvalue) //每次数组满的时候
//		{
//			GP30_filter_last_value_for_shunshi = FilterJunZhi_float_GP30Filter(s_g_diftof_data_testforlastvalue,GP22_APP_DIFTOF_SIZE);
//		}
//		return;
//	}

    s_g_diftof_data[s_g_diftof_head] = float_differ;//带正负号
    s_g_diftof_head++;
    s_g_diftof_head %= GP22_APP_DIFTOF_SIZE;

    if(0 == s_g_diftof_head) //每次数组满的时候
    {
        s_g_diftof_for_total = TRUE;
//		if(0 == s_g_diftof_head_2)
//		{
//			s_g_diftof_data_2[s_g_diftof_head_2] = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data,GP22_APP_DIFTOF_SIZE);
//		}
//		else
		{
			float temp_diftof_data_filter = FilterJunZhi_float_GP30Filter(s_g_diftof_data,GP22_APP_DIFTOF_SIZE);
			if(temp_diftof_data_filter > -900)
			{
				s_g_diftof_data_2[s_g_diftof_head_2] = temp_diftof_data_filter;
				s_g_diftof_head_2 ++;
				s_g_sample_total_sum ++;
				s_g_diftof_head_2_quotient =s_g_diftof_head_2/GP22_APP_DIFTOF_SIZE_2;
				s_g_diftof_head_2 %= GP22_APP_DIFTOF_SIZE_2;
			}			
		}
   
//		GP30_filter_last_value_for_shunshi = s_g_diftof_data_2[s_g_diftof_head_2] ;
//        s_g_diftof_head_2 ++;
//        s_g_sample_total_sum ++;
//        s_g_diftof_head_2 %= GP22_APP_DIFTOF_SIZE_2;


        if((0 != s_g_diftof_head_2) && (s_g_sample_total_sum < GP22_APP_DIFTOF_SIZE_2))//每次数组没满的时候
        {
            if(s_g_diftof_head_2 > 4)
            {
                still_water_add = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data_2,s_g_diftof_head_2);
            }
            else
            {
                for (i = 0; i < s_g_diftof_head_2; i++)
                {
                    still_water_add = still_water_add + s_g_diftof_data_2[i];
                }
                still_water_add = still_water_add / s_g_diftof_head_2;
            }
        }
        else if((0 != s_g_diftof_head_2)||((s_g_diftof_head_2_quotient!=0)&&(0 == s_g_diftof_head_2)))//每次数组满的时候
        {
//            for (i = 0; i < GP22_APP_DIFTOF_SIZE_2; i++)
//            {
//                still_water_add = still_water_add + s_g_diftof_data_2[i];
//            }
//            still_water_add = still_water_add / GP22_APP_DIFTOF_SIZE_2;
            
            still_water_add = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data_2,GP22_APP_DIFTOF_SIZE_2);
        }
		else if((0 == s_g_diftof_head_2)&&(0 == s_g_diftof_head_2_quotient))//start到stop之前如果全部滤波数据均满足if((behind_avg - front_avg) > sum * GP30_DIFTOF_FILTER_COEFFICIENT)
		{
			still_water_add = 0;
		}

        if (still_water_add >= 0)
        {
            s_g_still_water_time = FloatToGp30Data(still_water_add);
        }
        else
        {
            still_water_add = 0 - still_water_add;
            s_g_still_water_time = FloatToGp30Data(still_water_add);
            s_g_still_water_time |= 0x80000000;
        }

        gp22_app_data.s.TOF_diff = s_g_still_water_time;
        gp22_test_data.s.TOF_diff = s_g_still_water_time;
    }
}
	
/****************************************************************
Function:    void StillWatetCalculate (void)
Description:  计算时间差，检定，大表应用的程序
Input:
Return:
Others:
 *****************************************************************/
#elif EN_LARGE_FILITER
void StillWatetCalculate(u32 dif_value)
{
    u8 i = 0;
    u32 temp_value;
    float still_water_add = 0, float_differ=0;

    if (10 == LcdCheckStateApp()) //非检定状态,不需每次都检测时间差
    {
        return;
    }
	if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定状态，且上位机不允许采样
	{
		return;
	}

    temp_value = dif_value;
    if (temp_value >= 0x80000000) //负数
    {
		temp_value &= 0x7FFFFFFF;
		float_differ = 0 - Gp30DataToFloat(temp_value);
    }
    else
    {
//        float_differ_last_time = temp_value;
        float_differ = Gp30DataToFloat(temp_value);
    }

//	// 2019-12-10 10:14:37   滤波改动，应对跳变
//	if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定而且上位机不允许采样
//	{

//		s_g_diftof_data_testforlastvalue[s_g_diftof_head_testforlastvalue] = float_differ;//带正负号
//		s_g_diftof_head_testforlastvalue++;
//		s_g_diftof_head_testforlastvalue %= GP22_APP_DIFTOF_SIZE;
//		
//		if(0 == s_g_diftof_head_testforlastvalue) //每次数组满的时候
//		{
//			GP30_filter_last_value_for_shunshi = FilterJunZhi_float_GP30Filter(s_g_diftof_data_testforlastvalue,GP22_APP_DIFTOF_SIZE);
//		}
//		return;
//	}

    s_g_diftof_data[s_g_diftof_head] = float_differ;//带正负号
    s_g_diftof_head++;
    s_g_diftof_head %= GP22_APP_DIFTOF_SIZE;

    if(0 == s_g_diftof_head) //每次数组满的时候，每次16个buff数据
    {
        s_g_diftof_for_total = TRUE;
//		if(0 == s_g_diftof_head_2)
//		{
//			s_g_diftof_data_2[s_g_diftof_head_2] = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data,GP22_APP_DIFTOF_SIZE);
//		}
//		else
		{
			float temp_diftof_data_filter = FilterJunZhi_float_GP30Filter(s_g_diftof_data,GP22_APP_DIFTOF_SIZE);
			if(temp_diftof_data_filter > -900)
			{
				s_g_diftof_data_2[s_g_diftof_head_2] = temp_diftof_data_filter;
				s_g_diftof_head_2 ++;
				s_g_sample_total_sum ++;
				s_g_diftof_head_2_quotient =s_g_diftof_head_2/GP22_APP_DIFTOF_SIZE_2;
				s_g_diftof_head_2 %= GP22_APP_DIFTOF_SIZE_2;
			}
			
		}
   
//		GP30_filter_last_value_for_shunshi = s_g_diftof_data_2[s_g_diftof_head_2] ;
//        s_g_diftof_head_2 ++;
//        s_g_sample_total_sum ++;
//        s_g_diftof_head_2 %= GP22_APP_DIFTOF_SIZE_2;


        if((0 != s_g_diftof_head_2) && (s_g_sample_total_sum < GP22_APP_DIFTOF_SIZE_2))//每次数组没满的时候
        {
            if(s_g_diftof_head_2 > 4)
            {
                still_water_add = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data_2,s_g_diftof_head_2);
            }
            else
            {
                for (i = 0; i < s_g_diftof_head_2; i++)
                {
                    still_water_add = still_water_add + s_g_diftof_data_2[i];
                }
                still_water_add = still_water_add / s_g_diftof_head_2;
            }
        }
        else if(((s_g_diftof_head_2_quotient!=0)&&(0 == s_g_diftof_head_2)))//数组满的时候
        {     	
            still_water_add_3 =0;			
            s_g_diftof_data_3[s_g_diftof_head_3] = FilterJunZhi_float_DIFTOFFilter(s_g_diftof_data_2,GP22_APP_DIFTOF_SIZE_2);//30个滤波值
			
//			s_g_diftof_data_3[s_g_diftof_head_3] = still_water_add; //第三次时间差滤波队列 2020-3-6			
			s_g_diftof_head_3++;	
			s_g_diftof_head_3_quotient =s_g_diftof_head_3/GP22_APP_DIFTOF_SIZE_3;//取整
			s_g_diftof_head_3 %= GP22_APP_DIFTOF_SIZE_3;//取余
			//第三次20个数据滤波
			if((0 != s_g_diftof_head_3) && (s_g_sample_total_sum < GP22_APP_DIFTOF_SUM))//数组没满的时候 40*15
			{
				for (i = 0; i < s_g_diftof_head_3; i++)
				{
					still_water_add_3 =  still_water_add_3+s_g_diftof_data_3[i];
				}
				still_water_add_3 = still_water_add_3 / s_g_diftof_head_3;
			}
			else if((0 != s_g_diftof_head_3)||((s_g_diftof_head_3_quotient!=0)&&(0 == s_g_diftof_head_3)))//数组满的时候
			{          
				for (i = 0; i < GP22_APP_DIFTOF_SIZE_3; i++)
				{
					still_water_add_3 = still_water_add_3 + s_g_diftof_data_3[i];
				}
				still_water_add_3 = still_water_add_3 / GP22_APP_DIFTOF_SIZE_3;				
			}
        }
		
		else if((0 == s_g_diftof_head_2)&&(0 == s_g_diftof_head_2_quotient))//start到stop之前如果全部滤波数据均满足if((behind_avg - front_avg) > sum * GP30_DIFTOF_FILTER_COEFFICIENT)
		{
			still_water_add = 0;
		}	
		if(s_g_sample_total_sum >= GP22_APP_DIFTOF_SIZE_2)
		{
		    still_water_add= still_water_add_3;
		}			
        if (still_water_add >= 0)
        {
            s_g_still_water_time = FloatToGp30Data(still_water_add);//溢出测试2019-12-27
        }
        else
        {
            still_water_add = 0 - still_water_add;
            s_g_still_water_time = FloatToGp30Data(still_water_add);//溢出测试2019-12-27
            s_g_still_water_time |= 0x80000000;
        }

        gp22_app_data.s.TOF_diff = s_g_still_water_time;
        gp22_test_data.s.TOF_diff = s_g_still_water_time;
    }
}
#endif

/////////////////////////////////////////////保留2////////////////////////////
//void StillWatetCalculate(u32 dif_value)
//{
//    static u8 sum = 0;
//    u32 temp_value;
//    static float still_water_add = 0, float_differ;
//
//    if (10 == LcdCheckStateApp()) //非检定状态,不需每次都检测时间差
//    {
//        return;
//    }
//
//    if (sum < GP22_APP_DIFTOF_SIZE)
//    {
////        temp_value = Gp22TimeDiffer(4);  //带正负号时间差
//        temp_value = dif_value;
//
//        if (temp_value >= 0x80000000) //负数
//        {
//            temp_value &= 0x7FFFFFFF;
//            float_differ = 0 - Gp30DataToFloat(temp_value);
//        }
//        else
//        {
//            float_differ = Gp30DataToFloat(temp_value);
//        }
//
//        if (0 == sum) //刚开始
//        {
//            sum++; //已经开始
//            s_g_still_water_time_max = float_differ;
//            s_g_still_water_time_min = float_differ;
//        }
//        else
//        {
//            sum++; //已经开始
//            if (float_differ > s_g_still_water_time_max)
//            {
//                still_water_add += s_g_still_water_time_max;
//                s_g_still_water_time_max = float_differ;
//            }
//            else if (float_differ < s_g_still_water_time_min)
//            {
//                still_water_add += s_g_still_water_time_min;
//                s_g_still_water_time_min = float_differ;
//            }
//            else
//            {
//                still_water_add += float_differ;
//            }
//        }
//    }
//    else //GP22_APP_DIFTOF_SIZE 次了
//    {
//        still_water_add = still_water_add / (GP22_APP_DIFTOF_SIZE-1);
//
//        if (still_water_add >= 0)
//        {
//            s_g_still_water_time = FloatToGp30Data(still_water_add);
//        }
//        else
//        {
//            still_water_add = 0 - still_water_add;
//            s_g_still_water_time = FloatToGp30Data(still_water_add);
//            s_g_still_water_time |= 0x80000000;
//        }
//
//        gp22_app_data.TOF_diff = s_g_still_water_time;
//        gp22_test_data.TOF_diff = s_g_still_water_time;
//        sum = 0;
//        still_water_add = 0;
//    }
//}

//////////////////////////////////////////////////////////// 保留测量静水时间的代码////////////////////////////////////////////
//void StillWatetCalculate(u32 dif_value)
//{
//    static u8 sum = 0, result;
//    u32 temp_value, temp_time;//, temp_speed;
//    static float still_water_add = 0, float_differ;
//    static u32 still_time_max, still_time_min, time_add = 0;
//
//    if (TRUE == s_g_still_flag)
//    {
//        if (sum < 100)
//        {
//            temp_value = Gp22TimeDiffer(4);
//            temp_time = Gp22TimeDiffer(5); // 2014-5-12 16:53:20
//
//            if (temp_value > 0x80000000) //负数
//            {
//                temp_value &= 0x7FFFFFFF;
//                float_differ = 0 - Gp30DataToFloat(temp_value);
//            }
//            else
//            {
//                float_differ = Gp30DataToFloat(temp_value);
//            }
//
//            if (0 == sum) //刚开始
//            {
//                sum++; //已经开始
//                s_g_still_water_time_max = float_differ;
//                s_g_still_water_time_min = float_differ;
//
//                still_time_max = temp_time;
//                still_time_min = temp_time;
//            }
//            else
//            {
//                sum++; //已经开始
//                if (float_differ > s_g_still_water_time_max)
//                {
//                    still_water_add += s_g_still_water_time_max;
//                    s_g_still_water_time_max = float_differ;
//                }
//                else if (float_differ < s_g_still_water_time_min)
//                {
//                    still_water_add += s_g_still_water_time_min;
//                    s_g_still_water_time_min = float_differ;
//                }
//                else
//                {
//                    still_water_add += float_differ;
//                }
//
//                // 静水时间，没有差
//                if (temp_time > still_time_max)
//                {
//                    time_add += still_time_max;
//                    still_time_max = temp_time;
//                }
//                else if (temp_time < still_time_min)
//                {
//                    time_add += still_time_min;
//                    still_time_min = temp_time;
//                }
//                else
//                {
//                    time_add += temp_time;
//                }
//            }
//        }
//        else //100次了
//        {
//            still_water_add = still_water_add / 99;
//            time_add = time_add / 99;
//
//            s_g_still_time = time_add; //没乘250 的ns
//
//            u8 temp_in_int = (u8) (TempCheckValueApp() >> 16);//////////////////////////////////实际测试///////////////////////////////////////////
//            u32 temp_speed = sound_speed_back[temp_in_int];
//            s_g_still_lenth = Gp30DataToFloat(s_g_still_time) * Gp30DataToFloat(temp_speed);
//
//            Gp22AppDataPre();
//            if (EepIfIdle()) //忙的话暂时不存了，等待1h的存储周期
//            {
//                EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &result);
//            }
//            if (still_water_add >= 0)
//            {
//                s_g_still_water_time = FloatToGp30Data(still_water_add);
//            }
//            else
//            {
//                still_water_add = 0 - still_water_add;
//                s_g_still_water_time = FloatToGp30Data(still_water_add);
//                s_g_still_water_time |= 0x80000000;
//            }
//            s_g_still_flag = FALSE;
//            s_g_still_finish = TRUE;
//            sum = 0;
//            still_water_add = 0;
//            time_add = 0;
//        }
//    }
//}



/****************************************************************
Function:    void Gp22SampleChange (void)
Description:  GP22 在非检定状态下,切换采样频率
Input:
Return:
Others:
 *****************************************************************/
//void Gp22SampleChange (void)
//{
//    if (10 == LcdCheckStateApp()) //非检定状态
//    {
//        if(0 != gp22_test_data.s.ins_flow) //流量不是0,立即切换成高采样频率
//        {
//            s_g_gp22_sample_span = GP22_SAMPLE_2HZ; //0.5s
//            s_g_gp22_sample_sum = 0;
//        }
//        else
//        {
//            if(GP22_SAMPLE_2HZ == s_g_gp22_sample_span)//流量是0,且当前是0.5s的采样间隔
//            {
//                s_g_gp22_sample_sum++;
//                if(s_g_gp22_sample_sum > 40) //2min之后,切换到1s   =3*参数
//                {
//                    s_g_gp22_sample_span = GP22_SAMPLE_0_5HZ; //2s
//                    s_g_gp22_sample_sum = 0;
//                }
//            }
//        }
//    }
//}


/****************************************************************
Function:    void Gp22AppClearData (void)
Description:  GP22-流量检测状态机
Input:当前用于计算流量的流速
Return:
 *****************************************************************/
void Gp22FlowDetect(float current_ins_flow)
{
	static u8 gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S0;
	static float original_total_flow=0;//记录原始正向累积量
	float accumulate_volume_diff=0,accumulate_volume_diff_5L=0,accumulate_volume_diff_10L=0,accumulate_volume_diff_100L=0;//当前累积量-初始累积量	
	static u8 NbIoTUpload_state=FALSE;
    
    if(FixedTimeNbIoTUploadIfIdle() == TASK_BUSY)//
    {
        NbIoTUpload_state = TRUE;
    }
        
	switch (gp30_app_flow_detect_state)
	{
		case GP30_APP_FLOW_DETECT_S0:
		{
			if(current_ins_flow!=0)//当前流速不为0
			{
				 if (10 == LcdCheckStateApp()) //非检定状态
				 {
					 original_total_flow = gp22_app_data.s.total_flow.gp30_float;//获取当前非检定累积量
				 }
				 else//否则就是检定
				 {
					 original_total_flow = gp22_test_data.s.total_flow.gp30_float;//获取当前检定累积量
				 }				
				 RtccSetTimer(FLOW_DETECT_TIME, FLOW_DETECT_5S);//定时5s
                 NbIoTUpload_state = FALSE;
				 gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S1;
			}
			break;
		}
		case GP30_APP_FLOW_DETECT_S1:
		{
			if(0==RtccCheckTimer(FLOW_DETECT_TIME))//检测时间到了
			{
				gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S2;
			}
			break;
		}
		case GP30_APP_FLOW_DETECT_S2:
		{
//			if(current_ins_flow<=(float)200)//当前流速小于200L/h
			{
				if(0==current_ins_flow)//当前流速为0
				{					
                    if (10 == LcdCheckStateApp()) //非检定状态
					{
						accumulate_volume_diff = gp22_app_data.s.total_flow.gp30_float - original_total_flow;//计算当前累积量量差值
						
						accumulate_volume_diff_5L = accumulate_volume_diff - (float)0.5;//与5L的差值
						accumulate_volume_diff_10L = accumulate_volume_diff - (float)1;//与10L的差值
                        accumulate_volume_diff_100L = accumulate_volume_diff - (float)10;//与100L的差值 
						
						if((accumulate_volume_diff_10L >=(float)-0.035)&&(accumulate_volume_diff_10L <= (float)0.035))
						{
							gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - accumulate_volume_diff_10L *(float)0.2;//缩小80%
                            duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                        }					
						else if((accumulate_volume_diff_5L >=(float)-0.0175)&&(accumulate_volume_diff_5L <= (float)0.0175))
						{
							gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - accumulate_volume_diff_5L *(float)0.2;//缩小80%
                            duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                        }
                        else if((accumulate_volume_diff_100L >=(float)-0.8)&&(accumulate_volume_diff_100L <= (float)0.8))
						{
                            if(TRUE==NbIoTUpload_state)
                            {
                                 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - accumulate_volume_diff_100L *(float)0.85;//缩小15%
                                 duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                            }                          
						}
					}
					else//检定状态
					{
						accumulate_volume_diff = gp22_test_data.s.total_flow.gp30_float - original_total_flow;//计算当前累积量量差值
						
						accumulate_volume_diff_5L = accumulate_volume_diff - (float)500;//与5L的差值
						accumulate_volume_diff_10L = accumulate_volume_diff - (float)1000;//与10L的差值
						
						if((accumulate_volume_diff_10L >=(float)-35)&&(accumulate_volume_diff_10L <= (float)35))
						{
							gp22_test_data.s.total_flow.gp30_float = gp22_test_data.s.total_flow.gp30_float - accumulate_volume_diff_10L *(float)0.2;//缩小80%
						}					
						else if((accumulate_volume_diff_5L >=(float)-17.5)&&(accumulate_volume_diff_5L <= (float)17.5))
						{
							gp22_test_data.s.total_flow.gp30_float = gp22_test_data.s.total_flow.gp30_float - accumulate_volume_diff_5L *(float)0.2;//缩小80%
						}
					}
                    NbIoTUpload_state = FALSE;
					gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S0;																	
				}
			}
//			else //流速大于200  则不进行累积量计算
//			{
//				gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S3;
//			}
			break;
		}
		case GP30_APP_FLOW_DETECT_S3:
		{
			if(0==current_ins_flow)//当前流速为0
			{
				gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S0;
			}
			break;
		}
		default:
		{
			gp30_app_flow_detect_state = GP30_APP_FLOW_DETECT_S0;
			break;	
		}			
	}
}
/****************************************************************
Function:    void Gp22EventCheckApp(void)
Description:  检测事件记录
Input:  
Return:
Others: 
 *****************************************************************/
void Gp22EventCheckApp(u32 ins_flow)
{
    //15	20	25	32	40         口径
    //0.002	0.004	0.006	0.010	0.025      使动流量
    //0.010	0.016	0.025	0.040	0.064      最小流量
    //0.016	0.025	0.040	0.064	0.100      分界流量
    //2.5	4.0	6.3	10.0	16.0       常用流量
    //3.125	5.0	7.875	12.5	20.0       过载流量
    
//    ins_flow = MulGp30Data(ins_flow, 0x00000041); //转换成立方米每小时

    if((ins_flow != 0)&&((ins_flow < MIN_FLOW_0_6)||(ins_flow > MAX_FLOW_1_02)))  ///最小流量的60%,过载流量的102%
    {
        gp22CheckErrEventApp(GP30_low_high_flow);  // 5/4
    }
    else
    {
        gp22CheckErrEventApp(GP30_low_high_flow_DE);  // 5/4 DE
    }

    if((ins_flow != 0)&&(ins_flow < MIN_FLOW_0_3))  //最小流量的30%作为微漏，3L/h
    {
        gp22CheckErrEventApp(GP30_low_flow);  // 3/4
    }
    else
    {
        gp22CheckErrEventApp(GP30_low_flow_DE);  // 3/4 DE
    }

    float temp_temp = TempCheckValueApp();
    if((temp_temp > 55) || (temp_temp < -0.5)) //T50温度范围,0-55℃
    {
        gp22CheckErrEventApp(GP30_out_temp);  // 4/4
    }
    else
    {
        gp22CheckErrEventApp(GP30_out_temp_DE);  // 4/4 DE
    }
}

/****************************************************************
Function:    void 
Description:  体积台子流量修正
Input:  
Return:
Others: 
 *****************************************************************/
float ModifyForVolumeTestbench(float temp_ins_flow_float) 
{	
	float temp_value = TempCheckValueApp();
	#if LLGS_DN15_BRASS_40KPA_GP30_32768
	if(temp_ins_flow_float >= (float)110) //流量范围
	{
		if((temp_value >= (float)28)&&(temp_value < (float)31))  //温度范围
		{
			temp_ins_flow_float = temp_ins_flow_float * ((float)-0.0013*temp_value + (float)1.0373);//28 1  31 -0.4%
		}
		else if((temp_value >= (float)31)&&(temp_value < (float)34))  //温度范围
		{
			temp_ins_flow_float = temp_ins_flow_float * ((float)0.0013*temp_value + (float)0.9547);//34 1  31 -0.4%
		}
	}
    else if((temp_ins_flow_float > (float)23)&&(temp_ins_flow_float < (float)27))//流量范围
	{
		if(temp_value < (float)23)  //温度范围
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.005;//
		}
	}
	else if(temp_ins_flow_float <= (float)23) //流量范围
	{
		if((temp_value >= (float)12)&&(temp_value < (float)23))  //温度范围
		{
            temp_ins_flow_float = temp_ins_flow_float * ((float)-0.00018182*temp_value +(float)1.00718182);//12+0.5% 23 +0.3  
		}
		else if(temp_value < (float)12)  //温度范围
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.005;//
		}
	}
    #elif Buxiugang_LLGS_WDFS_DN15_BXG_40KPA_GP30_32768  
        
    #elif Plastic_LLGS_WDFS_DN15_PALSTIC_40KPA_GP30_32768
    
    #elif ROUND_LLGS_DN15_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768 
        
    if(temp_value < (float)16.41)
	{
        if(temp_ins_flow_float < (float)8.5)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
        }   
//        else if((temp_ins_flow_float >= (float)6)&&(temp_ins_flow_float < (float)8.5))	
//        {
//            temp_ins_flow_float = temp_ins_flow_float * ((float)0.0032*temp_ins_flow_float+ (float)0.9758);//6:-0.5%  8.5:+0.3%
//        }
//        else if((temp_ins_flow_float >= (float)8.5)&&(temp_ins_flow_float < (float)25))	
//        {
//            temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
//        }
//        else if(temp_ins_flow_float >= (float)180)	
//        {
//            temp_ins_flow_float = temp_ins_flow_float * (float)1.0025;
//        }        
    }
    else if((temp_value >= (float)16.41)&&(temp_value < (float)22.43))	
    {
        if((temp_ins_flow_float >= (float)8.5)&&(temp_ins_flow_float < (float)25))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
        }
        else if(temp_ins_flow_float >= (float)180)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.0025;
        } 
    }
	else if((temp_value >= (float)28.06)&&(temp_value < (float)34.86))	 //2022-5-30 14:30:33
    {
        if(temp_ins_flow_float <= (float)25)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.002;
        }
    }
    else if((temp_value >= (float)34.86)&&(temp_value < (float)41.9))	
    {
        if(temp_ins_flow_float >= (float)180)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.002;
        }
    }
    else if(temp_value >= (float)41.9)  //温度范围
    {
        if((temp_ins_flow_float >= (float)8.5)&&(temp_ins_flow_float < (float)25))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
        }
    }
    #elif EN_DN15_BRASS_63KPA_GP30_32768 // 体积台子没有修正
    #elif MID_DN15_BRASS_63KPA_GP30_32768
	if(temp_value >= (float)35)
	{
		if(temp_ins_flow_float < (float)25)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)0.998;
		}
		else if(temp_ins_flow_float>= (float)2100)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
		}
	}
	else if((temp_value >= (float)17)&&(temp_value < (float)35))	
	{
		if(temp_ins_flow_float < (float)25)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
		}
	}
	else if((temp_value >= (float)15)&&(temp_value < (float)17))	
	{
		if(temp_ins_flow_float <= (float)30)
		{
			temp_ins_flow_float = temp_ins_flow_float * ((float)0.003*temp_value +(float) 0.955);
		}
	}
	#elif  PF_DN15_BRASS_63KPA_GP30_32768
	if(temp_value >= (float)17)
	{
		if(temp_ins_flow_float < (float)25)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.008;
		}
		else if((temp_ins_flow_float >= (float)25)&&(temp_ins_flow_float < (float)30))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.005;//
		}
		else if((temp_ins_flow_float >= (float)30)&&(temp_ins_flow_float < (float)45))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if((temp_value >= (float)15)&&(temp_value < (float)17))	
	{
		if(temp_ins_flow_float <= (float)30)
		{
			temp_ins_flow_float = temp_ins_flow_float * ((float)0.003*temp_value +(float) 0.955);
		}
	}
    #elif EN_DN20_BRASS_63KPA_GP30_32768

	#elif MID_DN20_BRASS_63KPA_GP30_32768
	if(temp_ins_flow_float <= (float)22)
	{
		if(temp_value < (float)13)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.005;
		}
		else if((temp_value >= (float)13)&&(temp_value < (float)21))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)0.0004*temp_value + (float)1.0001);//35:+0.5%-0.85%
		}
		else if((temp_value >= (float)21)&&(temp_value < (float)23))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)-0.002*temp_value + (float)1.05);//35:+0.8%-0.4%
		}	
		else if((temp_value >= (float)27)&&(temp_value < (float)30))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)0.001*temp_value + (float)0.977);//35:+0.4%-0.7%
		}
		else if((temp_value >= (float)30)&&(temp_value < (float)34))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)-0.001*temp_value + (float)1.037);//35:+0.7%-0.3%
		}	
		else if(temp_value >= (float)40)	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if((temp_ins_flow_float > (float)22)&&(temp_ins_flow_float <= (float)24)) //主要是与22以下流量过渡作用
	{
		if(temp_value <= (float)23)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.004;
		}	
		else if((temp_value >= (float)27)&&(temp_value < (float)34))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if(temp_ins_flow_float > (float)260) 
	{
		temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
	}		
	#elif DN20_BRASS_40KPA_GP30_32768
	if(temp_ins_flow_float <= (float)200)
	{
		temp_ins_flow_float = temp_ins_flow_float * TEST_BENCH_coefficient;//机械台子修正
	}
	#elif LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768	
	if(temp_value <15)
	{
		if(temp_ins_flow_float < (float)35)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)0.995;
		}
	}
	else if((temp_value >= (float)30))
	{
		if(temp_ins_flow_float < (float)35)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
		}
	}
	#elif PF_DN20_BRASS_63KPA_GP30_32768
	if(temp_ins_flow_float <= (float)22)
	{
		if(temp_value < (float)13)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.005;
		}
		else if((temp_value >= (float)13)&&(temp_value < (float)21))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)0.0004*temp_value + (float)1.0001);//35:+0.5%-0.85%
		}
		else if((temp_value >= (float)21)&&(temp_value < (float)23))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)-0.002*temp_value + (float)1.05);//35:+0.8%-0.4%
		}	
		else if((temp_value >= (float)27)&&(temp_value < (float)30))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)0.001*temp_value + (float)0.977);//35:+0.4%-0.7%
		}
		else if((temp_value >= (float)30)&&(temp_value < (float)34))	
		{
			temp_ins_flow_float = temp_ins_flow_float *((float)-0.001*temp_value + (float)1.037);//35:+0.7%-0.3%
		}	
		else if(temp_value >= (float)40)	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if((temp_ins_flow_float > (float)22)&&(temp_ins_flow_float <= (float)24)) //主要是与22以下流量过渡作用
	{
		if(temp_value <= (float)23)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.004;
		}	
		else if((temp_value >= (float)27)&&(temp_value < (float)34))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if(temp_ins_flow_float > (float)260) 
	{
		temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
	}	
	#elif LLGS_DN20_BRASS_40KPA_GP30_32768
	if(temp_value < (float)12.97)
	{
		if(temp_ins_flow_float < (float)30)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.005;
		}
		else if((temp_ins_flow_float >= (float)30)&&(temp_ins_flow_float < (float)100))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.008;//
		}
		else if((temp_ins_flow_float >= (float)100)&&(temp_ins_flow_float < (float)150))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.005;//
		}
		else if((temp_ins_flow_float >= (float)150)&&(temp_ins_flow_float < (float)180))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if((temp_value >= (float)12.97)&&(temp_value < (float)22.62))	
	{
		if(temp_ins_flow_float < (float)180)
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.007;
		}
		else if((temp_ins_flow_float >= (float)180)&&(temp_ins_flow_float < (float)220))	
		{
			temp_ins_flow_float = temp_ins_flow_float *(float)1.003;//
		}
	}
	else if((temp_value >= (float)22.62)&&(temp_value < (float)25.54))	
	{
		if(temp_ins_flow_float <= (float)150)
		{
			temp_ins_flow_float = temp_ins_flow_float * ((float)-0.0017*temp_value + (float)1.0437);//0.5-0
		}
	}
    else if((temp_value >= (float)27.99)&&(temp_value < (float)31.12))	
	{
		if(temp_ins_flow_float < (float)45)	
		{
			temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
		}
	} 
   #elif Buxiugang_LLGS_WDFS_DN20_BXG_40KPA_GP30_32768  
                 
    #elif ROUND_LLGS_DN20_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768 
    if(temp_value < (float)19.83)
	{
        if((temp_ins_flow_float >= (float)19)&&(temp_ins_flow_float < (float)35))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.002;
        }
        else if((temp_ins_flow_float >= (float)180)&&(temp_ins_flow_float < (float)4300))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.996;
        }        
    }
    else if((temp_value >= (float)19.83)&&(temp_value < (float)25.5))	
    {
        if(temp_ins_flow_float <= (float)35)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.002;
        }
        else if((temp_ins_flow_float >= (float)180)&&(temp_ins_flow_float < (float)4300))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.998;
        } 
    }
    else if((temp_value >= (float)25.5)&&(temp_value < (float)40))	
    {
		if(temp_ins_flow_float <= (float)19)	
        {
            temp_ins_flow_float = temp_ins_flow_float *((float)0.0003*temp_value + (float)0.993);//基于温度的曲线 25.5度 +0， 40度：+0.4%
        }
        else if((temp_ins_flow_float >= (float)150)&&(temp_ins_flow_float < (float)180))
        {
             temp_ins_flow_float = temp_ins_flow_float * (float)0.998;
        }
        else if((temp_ins_flow_float >= (float)180)&&(temp_ins_flow_float < (float)4300))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.995;
        }
        else if(temp_ins_flow_float >= (float)4300)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.998;
        }
    }
    else if(temp_value >= (float)40)  //温度范围
    {
        if((temp_ins_flow_float >= (float)150)&&(temp_ins_flow_float < (float)180))
        {
             temp_ins_flow_float = temp_ins_flow_float * (float)0.997;
        }
        else if((temp_ins_flow_float >= (float)180)&&(temp_ins_flow_float < (float)4300))	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.993;
        }
        else if(temp_ins_flow_float >= (float)4300)	
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)0.996;
        }
    }
    #elif PF_DN25_BRASS_63KPA_GP30_32768
     if(temp_value > (float)35)
     {       
        if((temp_ins_flow_float > (float)400))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.996;
        }            
     }
    else if((temp_value > (float)27.69)&&(temp_value <= (float)35))	
	{
        if(temp_ins_flow_float <= (float)65)
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
        }
        else if((temp_ins_flow_float > (float)4500))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.998;
        }
	}
     else if(temp_value <= (float)27.69)
     {       
        if(temp_ins_flow_float <= (float)65)
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.005;
        }
        else if((temp_ins_flow_float > (float)4500))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.998;
        }        
     }
    #elif DN25_BRASS_40KPA_GP30_32768
     if(temp_value > (float)35)
     {       
        if((temp_ins_flow_float > (float)400))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.996;
        }            
     }
    else if((temp_value > (float)27.69)&&(temp_value <= (float)35))	
	{
        if(temp_ins_flow_float <= (float)65)
        {
            temp_ins_flow_float = temp_ins_flow_float * (float)1.003;
        }
        else if((temp_ins_flow_float > (float)4500))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.998;
        }
	}
     else if((temp_value <= (float)27.69))	
     {       
		if((temp_ins_flow_float > (float)4500))
        {
            temp_ins_flow_float = temp_ins_flow_float *(float)0.996;
        }        
     }
	#endif
		return  temp_ins_flow_float;
}		
 /****************************************************************
Function:    void Gp22FlowCalculate(u32 time_dof)   
Description:  由时间差计算瞬时流量，以及温度补偿
Input:   
Return:
Others: 
 *****************************************************************/
float Gp22FlowCalculate(u32 time_dof)
{
	static u32 diftof_abnormal_cnt=0;
	static u32 transducer_check_cnt=0;
    float ins_flow_temp_float = 0;
	float time_dof_temp_float = 0;
	float temp_value_float=0;
	
    #if  WENDU_FANSUAN_OPEN        
     Water_Meter_Temp_calculate(time_dof);//传递给我时间差---用于计算流速度
    #endif
	if(RtccCheckMsgApp(RtccMsg_Transducer_Check))
	{
		RtccClearMsgApp(RtccMsg_Transducer_Check);//清每天2点置检测换能器是否异常的标志
		if(transducer_check_cnt>DIFTOF_CALIBRATION_CNT)
		{
			transducer_err_msg = TRUE;
		}
		else
		{
			transducer_err_msg = FALSE;
		}
		transducer_check_cnt=0;
	}
	if((time_dof < gp30_app_start_flow_filter)||(time_dof >= 0x40000)) //DN15、DN20整表：900、700ps（3.77L、5 L）——模组的800、600（3.3L、4.2）//2019年1月22日，先暂时写死
    {
        ins_flow_temp_float = 0;
    }
    else
    {	
		transducer_check_cnt++;	
        time_dof_temp_float = Gp30DataToFloat(time_dof);  //先把有效时间差转换成浮点数
        time_dof_temp_float = time_dof_temp_float * (float)250;// 将us转换成真实的ns， /4 *1000=ns
        //------------------------------------------------- 反算温度代码开始区-------------     
		if(TRUE == CheckDiftofCalibrationFlag())
		{
			diftof_abnormal_cnt++;
			if(RtccCheckMsgApp(RtccMsg_DiftofCalibration))
			{
				RtccClearMsgApp(RtccMsg_DiftofCalibration);//清每天2点置校准零流量标志
				if(diftof_abnormal_cnt>DIFTOF_CALIBRATION_CNT)
				{
					Gp30DiftofCalibration();
					diftof_auto_calibration_msg = TRUE;
				}
				diftof_abnormal_cnt=0;
			}
		}
		else
		{
		 diftof_abnormal_cnt=0;
		}
		
		if(s_g_sample_ok_flag)
		{
			temp_value_float = temp_sample_value;//获取滤波后的温度数值
		}
		else
		{			
			temp_value_float = TempCheckValueApp();//获取实时的温度数据-----宏定义区分	
		}
		if((temp_value_float<-0.5)&&((gp22_app_data.s.peak_up>95)&&(gp22_app_data.s.peak_down>95)))//温度异常且振幅正常，判断为温度传感器异常
		{
			temp_value_float = 20;
		}
		
		flow_coef=ReadCofficientApp();//将流量系数首地址传出
		#if  DN15_BRASS_40KPA_GP30_32768 || WDFS_DN15_BRASS_40KPA_GP30_32768 || LLGS_DN15_BRASS_40KPA_GP30_32768 || LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-3.089 + (float)0.1979*temp_value_float + (float)5.032*time_dof_temp_float -(float)0.004616*temp_value_float*temp_value_float + (float)0.03869*temp_value_float*time_dof_temp_float + (float)0.02473*time_dof_temp_float*time_dof_temp_float;				
        #elif  ROUND_LLGS_DN15_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-3.089 + (float)0.1979*temp_value_float + (float)5.032*time_dof_temp_float -(float)0.004616*temp_value_float*temp_value_float + (float)0.03869*temp_value_float*time_dof_temp_float + (float)0.02473*time_dof_temp_float*time_dof_temp_float;				       
        #elif Plastic_LLGS_WDFS_DN15_PALSTIC_40KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-2.994 + (float)0.1383*temp_value_float + (float) 5.823*time_dof_temp_float -(float)0.002506*temp_value_float*temp_value_float + (float)0.03894*temp_value_float*time_dof_temp_float + (float)0.02752*time_dof_temp_float*time_dof_temp_float;				       
        #elif Buxiugang_LLGS_WDFS_DN15_BXG_40KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-3.219 + (float)0.1349*temp_value_float + (float)5.279*time_dof_temp_float -(float)0.002371*temp_value_float*temp_value_float + (float)0.02696*temp_value_float*time_dof_temp_float + (float)0.01182*time_dof_temp_float*time_dof_temp_float;				              
        #elif ROUND_LLGS_XFZ_DN15_BRASS_40KPA_GP30_32768
        float Mum_T_DIFTOF = (float)-2.163+ (float)0.1283*temp_value_float + (float)5.585*time_dof_temp_float -(float)0.002701*temp_value_float*temp_value_float + (float)0.0443*temp_value_float*time_dof_temp_float + (float)0.02777*time_dof_temp_float*time_dof_temp_float;				               
        #elif  DN20_BRASS_40KPA_GP30_32768 || WDFS_DN20_BRASS_40KPA_GP30_32768 || LLGS_DN20_BRASS_40KPA_GP30_32768 || LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768 || ROUND_LLGS_DN20_BRASS_40KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-4.374+ (float)0.2251*temp_value_float + (float)7.566*time_dof_temp_float -(float)0.004431*temp_value_float*temp_value_float + (float)0.05552*temp_value_float*time_dof_temp_float + (float)0.03715*time_dof_temp_float*time_dof_temp_float;
		#elif ROUND_LLGS_XFZ_DN20_BRASS_40KPA_GP30_32768
        float Mum_T_DIFTOF = (float)-4.228+ (float)0.2106*temp_value_float + (float)7.191*time_dof_temp_float -(float)0.003052*temp_value_float*temp_value_float + (float)0.03379*temp_value_float*time_dof_temp_float + (float)0.007546*time_dof_temp_float*time_dof_temp_float;		
        #elif ROUND_LLGS_DN20_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-4.374+ (float)0.2251*temp_value_float + (float)7.566*time_dof_temp_float -(float)0.004431*temp_value_float*temp_value_float + (float)0.05552*temp_value_float*time_dof_temp_float + (float)0.03715*time_dof_temp_float*time_dof_temp_float;		
		#elif Buxiugang_LLGS_WDFS_DN20_BXG_40KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-4.363+ (float)0.1885*temp_value_float + (float)8.31*time_dof_temp_float -(float)0.003478*temp_value_float*temp_value_float + (float)0.05026*temp_value_float*time_dof_temp_float + (float)0.02686*time_dof_temp_float*time_dof_temp_float;		
		#elif  DN25_BRASS_40KPA_GP30_32768 || LLGS_DN25_BRASS_40KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-4.629 + (float)0.1449*temp_value_float + (float)7.528*time_dof_temp_float -(float)0.002609*temp_value_float*temp_value_float + (float)0.05185*temp_value_float*time_dof_temp_float + (float)0.03089*time_dof_temp_float*time_dof_temp_float;       
		#elif DN32_BRASS_63KPA_GP30_32768	
		float Mum_T_DIFTOF = (float)-13.82 + (float)0.4569 *temp_value_float + (float)12.48*time_dof_temp_float -(float)0.006447*temp_value_float*temp_value_float + (float)0.06745*temp_value_float*time_dof_temp_float + (float)0.02257*time_dof_temp_float*time_dof_temp_float;		
        #elif DN40_BRASS_63KPA_GP30_32768	
		float Mum_T_DIFTOF = (float)-29.04 + (float)1.514*temp_value_float + (float)23.38*time_dof_temp_float -(float)0.0237*temp_value_float*temp_value_float + (float)0.1134*temp_value_float*time_dof_temp_float + (float)0.008339*time_dof_temp_float*time_dof_temp_float;
				
		#elif BM_DN15_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-1.889+ (float)0.08152*temp_value_float + (float)4.085*time_dof_temp_float -(float)0.001562*temp_value_float*temp_value_float + (float)0.03146*temp_value_float*time_dof_temp_float + (float)0.03695*time_dof_temp_float*time_dof_temp_float;		
		#elif BM_DN20_BRASS_63KPA_GP30_32768  	
		float Mum_T_DIFTOF=(float)-4.947 + (float)0.2216*temp_value_float + (float)8.223*time_dof_temp_float -(float)0.003235*temp_value_float*temp_value_float + (float)0.04133*temp_value_float*time_dof_temp_float + (float)0.02369*time_dof_temp_float*time_dof_temp_float;
		#elif BM_DN25_BRASS_63KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-4.629 + (float)0.1449*temp_value_float + (float)7.528*time_dof_temp_float -(float)0.002609*temp_value_float*temp_value_float + (float)0.05185*temp_value_float*time_dof_temp_float + (float)0.03089*time_dof_temp_float*time_dof_temp_float;
        #elif BM_DN32_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-13.82 + (float)0.4569 *temp_value_float + (float)12.48*time_dof_temp_float -(float)0.006447*temp_value_float*temp_value_float + (float)0.06745*temp_value_float*time_dof_temp_float + (float)0.02257*time_dof_temp_float*time_dof_temp_float;		
        #elif BM_DN40_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-29.04 + (float)1.514*temp_value_float + (float)23.38*time_dof_temp_float -(float)0.0237*temp_value_float*temp_value_float + (float)0.1134*temp_value_float*time_dof_temp_float + (float)0.008339*time_dof_temp_float*time_dof_temp_float;
			
		#elif MID_DN15_BRASS_63KPA_GP30_32768	
		float Mum_T_DIFTOF = (float)-3.484 + (float)0.08413*temp_value_float + (float)5.147*time_dof_temp_float -(float)0.0009018*temp_value_float*temp_value_float + (float)0.02242*temp_value_float*time_dof_temp_float + (float)0.01383*time_dof_temp_float*time_dof_temp_float;
		#elif MID_DN20_BRASS_63KPA_GP30_32768 	
		float Mum_T_DIFTOF = (float)-4.779 + (float)0.1773*temp_value_float + (float)7.718*time_dof_temp_float -(float)0.0029*temp_value_float*temp_value_float + (float)0.04264*temp_value_float*time_dof_temp_float + (float)0.02904*time_dof_temp_float*time_dof_temp_float;
        #elif MID_DN25_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-10.63 + (float)0.4456 *temp_value_float + (float)8.033*time_dof_temp_float -(float)0.007159*temp_value_float*temp_value_float + (float)0.04336*temp_value_float*time_dof_temp_float + (float)0.009849*time_dof_temp_float*time_dof_temp_float;
		
		#elif EN_DN15_BRASS_63KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-3.484 + (float)0.08413*temp_value_float + (float)5.147*time_dof_temp_float -(float)0.0009018*temp_value_float*temp_value_float + (float)0.02242*temp_value_float*time_dof_temp_float + (float)0.01383*time_dof_temp_float*time_dof_temp_float;
		#elif EN_DN20_BRASS_63KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-6.865 + (float)0.334*temp_value_float + (float)8.025*time_dof_temp_float -(float)0.005138*temp_value_float*temp_value_float + (float)0.04061*temp_value_float*time_dof_temp_float + (float)0.01638*time_dof_temp_float*time_dof_temp_float;
		//20211204
        #elif PF_DN15_BRASS_63KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-3.484 + (float)0.08413*temp_value_float + (float)5.147*time_dof_temp_float -(float)0.0009018*temp_value_float*temp_value_float + (float)0.02242*temp_value_float*time_dof_temp_float + (float)0.01383*time_dof_temp_float*time_dof_temp_float;
        #elif PF_DN20_BRASS_63KPA_GP30_32768
		float Mum_T_DIFTOF = (float)-4.779 + (float)0.1773*temp_value_float + (float)7.718*time_dof_temp_float -(float)0.0029*temp_value_float*temp_value_float + (float)0.04264*temp_value_float*time_dof_temp_float + (float)0.02904*time_dof_temp_float*time_dof_temp_float;
		#elif PF_DN25_BRASS_63KPA_GP30_32768 
        float Mum_T_DIFTOF = (float)-4.629 + (float)0.1449*temp_value_float + (float)7.528*time_dof_temp_float -(float)0.002609*temp_value_float*temp_value_float + (float)0.05185*temp_value_float*time_dof_temp_float + (float)0.03089*time_dof_temp_float*time_dof_temp_float;       
		#elif PF_DN32_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-13.82 + (float)0.4569 *temp_value_float + (float)12.48*time_dof_temp_float -(float)0.006447*temp_value_float*temp_value_float + (float)0.06745*temp_value_float*time_dof_temp_float + (float)0.02257*time_dof_temp_float*time_dof_temp_float;		
        #elif PF_DN40_BRASS_63KPA_GP30_32768 
		float Mum_T_DIFTOF = (float)-29.04 + (float)1.514*temp_value_float + (float)23.38*time_dof_temp_float -(float)0.0237*temp_value_float*temp_value_float + (float)0.1134*temp_value_float*time_dof_temp_float + (float)0.008339*time_dof_temp_float*time_dof_temp_float;
        #endif
		
		#if LILUNGONGSHI_MODLE_WATER_METER
		
		if (Mum_T_DIFTOF <= SEGMENT_NUM_LARGE)  //小流段用理论公式+误差补偿曲线
		{
			
			float sound_speed_C;
			float reynolds_coefficient;
		
			//*******************************理论模型********************************//
			//查表得到C
			u8 calculate_num ; //查表位置
			float calculate_decimal ; //温度的小数部分
			
			if((temp_value_float < 0) || (temp_value_float > 100))  //异常温度判断，防止数组越界
			{
				sound_speed_C = sound_speed_in_water[20];
			}
			else
			{
				calculate_num = (u8) (temp_value_float); //查表位置
				calculate_decimal = temp_value_float - calculate_num; //温度的小数部分

				sound_speed_C = sound_speed_in_water[calculate_num] + calculate_decimal * (sound_speed_in_water[calculate_num + 1] - sound_speed_in_water[calculate_num]);
			}
			//计算理论流速
			float ins_flow_rate_float = sound_speed_C * sound_speed_C * time_dof_temp_float * FLOW_RATE_MULTIPLIER;
			
			//计算雷诺数
			float temp_cal = temp_value_float;
			if(temp_value_float < 0) 
			{
				temp_cal = 0;
			}
			else if(temp_value_float > 55) 
			{
				temp_cal = 55;
			}
			float kinematic_viscosity = (float)-0.006*temp_cal*temp_cal*temp_cal + (float)0.9153*temp_cal*temp_cal - (float)55.214*temp_cal + (float)1784.2;
			float water_density = 1000*((float)-0.00000535*temp_cal*temp_cal+(float)0.0000130707*temp_cal+(float)1.0001);  
			float Reynolds_number = 1000*water_density * ins_flow_rate_float * MEASYRING_TUBE_DIAMETER / kinematic_viscosity;  //雷诺数Re = ρ*v*L/η  L特征长度
			
			//计算理论流量
			ins_flow_temp_float = ins_flow_rate_float * FLOW_MULTIPLIER; // L/h
			
			
	//		u32 tickstart_test = Timer1usGetTick();  //测试计算时间
			
			//弦向速度补偿——2021-2-1
			//————————层流区先按照第一段
			/*
			4000<Re<100000 n=6，补偿系数=1.08887
				   <120000 n=7，补偿系数=1.075704
				   <350000 n=8，补偿系数=1.065936
				   <3240000 n=9，补偿系数=1.0584
				   >3240000 n=10，补偿系数=1.05241	
			*/
	//		float XIAN_coefficient =  (float)1.08887;
	//		if(Reynolds_number < (float)100000)
	//		{
	//			XIAN_coefficient =  (float)1.08887;
	//		}
	//		else if(Reynolds_number < (float)120000)
	//		{
	//			XIAN_coefficient =  (float)1.075704;
	//		}
	//		else if(Reynolds_number < (float)350000)
	//		{
	//			XIAN_coefficient =  (float)1.065936;
	//		}
	//		else if(Reynolds_number < (float)3240000)
	//		{
	//			XIAN_coefficient =  (float)1.0584;
	//		}
	//		else
	//		{
	//			XIAN_coefficient =  (float)1.05241;
	//		}
	//		ins_flow_temp_float = ins_flow_temp_float*XIAN_coefficient;
			
			
			//线速度补偿——先暂时不分段  
			//=Y3/(1+0.01*SQRT(6.25+431*POWER(V3,-0.237))) 收敛性更好，暂使用这一段
			
			//泰勒展开拟合 
	//		r = taylor(1 + (0.01 * sqrt(6.25 + 431*power(x,-0.237))),x,'order',10)
			
			//公式法
	//		reynolds_coefficient = (float)1 + ((float)0.01 * sqrt((float)6.25 + 431*pow(Reynolds_number,-0.237)));  
	//		reynolds_coefficient = (float)1 + ((float)0.01 * ((float)6.25 + 431*pow(Reynolds_number,-0.237)));
	//		reynolds_coefficient = (float)1 + ((float)0.01 * sqrt((float)6.25 + 431*(Reynolds_number)));
	//		reynolds_coefficient = (float)1 / reynolds_coefficient;

			//多项式拟合  注意：1、每个口径根据最小雷诺数重新拟合；2、拟合时选择科学计数，4位小数
			float x = Reynolds_number/(float)1000;
			if(x < (float)5.4)  
			{
				reynolds_coefficient = (float)0.000047977*x*x*x*x*x - (float)0.00081617*x*x*x*x + (float)0.005381*x*x*x - (float)0.017564*x*x + (float)0.031606*x + (float)0.89468;//雷诺补偿K计算
			}
			else if(x < (float)50)  
			{
				reynolds_coefficient = (float)0.00000000027746*x*x*x*x*x - (float)0.000000046288*x*x*x*x + (float)0.0000030565*x*x*x - (float)0.00010318*x*x + (float)0.0020177*x + (float)0.91854;//雷诺补偿K计算
			}
			else if(x < (float)400)
			{
				reynolds_coefficient = (float)0.0000000000000068051*x*x*x*x*x - (float)0.0000000000089476*x*x*x*x + (float)0.0000000046656*x*x*x - (float)0.0000012475*x*x + (float)0.00019399*x + (float)0.93385;//雷诺补偿K计算
			}
			else//用1000以下数据拟合的
			{
				reynolds_coefficient = -(float)0.00000000000000625752*x*x*x*x + (float)0.00000000002284921079*x*x*x - (float)0.00000003409499816486*x*x + (float)0.00002828954763422040*x + (float)0.94386733698271600000;
			} 
					
			ins_flow_temp_float = ins_flow_temp_float * reynolds_coefficient;  //雷诺数补偿	
									
			// 理论公式模型，误差曲线补偿代码
			ins_flow_temp_float = ErrorModifyCruve(temp_value_float,time_dof_temp_float,ins_flow_temp_float);
			}			
			else   //大流段用多项式模型
			{
				if(temp_value_float > (float)35)//由于方壳DN15口径 大流量按照温度分为了2段 建模
				{
					if(Mum_T_DIFTOF < DXS_SEGMENT_NUM_LARGE)//由于不锈钢和塑料壳体DN15口径 大流量按照流量分为了2段 
                    {
                        ins_flow_temp_float = default_error_DXS[1]+default_error_DXS[2]*temp_value_float
                        +default_error_DXS[3]*(time_dof_temp_float+default_error_DXS[0])
                        +default_error_DXS[4]*temp_value_float*temp_value_float
                        +default_error_DXS[5]*(time_dof_temp_float+default_error_DXS[0])*temp_value_float
                        +default_error_DXS[6]*(time_dof_temp_float+default_error_DXS[0])*(time_dof_temp_float+default_error_DXS[0])
                        +default_error_DXS[7]*temp_value_float*temp_value_float*temp_value_float
                        +default_error_DXS[8]*(time_dof_temp_float+default_error_DXS[0])*temp_value_float*temp_value_float
                        +default_error_DXS[9]*(time_dof_temp_float+default_error_DXS[0])*(time_dof_temp_float+default_error_DXS[0])*temp_value_float
                        +default_error_DXS[10]*(time_dof_temp_float+default_error_DXS[0])*(time_dof_temp_float+default_error_DXS[0])*(time_dof_temp_float+default_error_DXS[0]);	
                    }
                    else
                    {
                        ins_flow_temp_float = default_error_DXS[12]+default_error_DXS[13]*temp_value_float
                        +default_error_DXS[14]*(time_dof_temp_float+default_error_DXS[11])
                        +default_error_DXS[15]*temp_value_float*temp_value_float
                        +default_error_DXS[16]*(time_dof_temp_float+default_error_DXS[11])*temp_value_float
                        +default_error_DXS[17]*(time_dof_temp_float+default_error_DXS[11])*(time_dof_temp_float+default_error_DXS[11])
                        +default_error_DXS[18]*temp_value_float*temp_value_float*temp_value_float
                        +default_error_DXS[19]*(time_dof_temp_float+default_error_DXS[11])*temp_value_float*temp_value_float
                        +default_error_DXS[20]*(time_dof_temp_float+default_error_DXS[11])*(time_dof_temp_float+default_error_DXS[11])*temp_value_float
                        +default_error_DXS[21]*(time_dof_temp_float+default_error_DXS[11])*(time_dof_temp_float+default_error_DXS[11])*(time_dof_temp_float+default_error_DXS[11]);	
                    }
				}
				else 
				{
					if(Mum_T_DIFTOF < DXS_SEGMENT_NUM_LARGE)
                    {
                        ins_flow_temp_float = default_error_DXS[23]+default_error_DXS[24]*temp_value_float
                        +default_error_DXS[25]*(time_dof_temp_float+default_error_DXS[22])
                        +default_error_DXS[26]*temp_value_float*temp_value_float
                        +default_error_DXS[27]*(time_dof_temp_float+default_error_DXS[22])*temp_value_float
                        +default_error_DXS[28]*(time_dof_temp_float+default_error_DXS[22])*(time_dof_temp_float+default_error_DXS[22])
                        +default_error_DXS[29]*temp_value_float*temp_value_float*temp_value_float
                        +default_error_DXS[30]*(time_dof_temp_float+default_error_DXS[22])*temp_value_float*temp_value_float
                        +default_error_DXS[31]*(time_dof_temp_float+default_error_DXS[22])*(time_dof_temp_float+default_error_DXS[22])*temp_value_float
                        +default_error_DXS[32]*(time_dof_temp_float+default_error_DXS[22])*(time_dof_temp_float+default_error_DXS[22])*(time_dof_temp_float+default_error_DXS[22]);	
                    }
                    else 
                    {                    
                        ins_flow_temp_float = default_error_DXS[34]+default_error_DXS[35]*temp_value_float
                        +default_error_DXS[36]*(time_dof_temp_float+default_error_DXS[33])
                        +default_error_DXS[37]*temp_value_float*temp_value_float
                        +default_error_DXS[38]*(time_dof_temp_float+default_error_DXS[33])*temp_value_float
                        +default_error_DXS[39]*(time_dof_temp_float+default_error_DXS[33])*(time_dof_temp_float+default_error_DXS[33])
                        +default_error_DXS[40]*temp_value_float*temp_value_float*temp_value_float
                        +default_error_DXS[41]*(time_dof_temp_float+default_error_DXS[33])*temp_value_float*temp_value_float
                        +default_error_DXS[42]*(time_dof_temp_float+default_error_DXS[33])*(time_dof_temp_float+default_error_DXS[33])*temp_value_float
                        +default_error_DXS[43]*(time_dof_temp_float+default_error_DXS[33])*(time_dof_temp_float+default_error_DXS[33])*(time_dof_temp_float+default_error_DXS[33]);	                        
                    }
				}
//				ins_flow_temp_float=ins_flow_temp_float*(0.00002844805f*ins_flow_temp_float+0.93148870327f);
			}		
		#endif
				
		#if SUBSECTION_NUM_THREE
//		if (Mum_T_DIFTOF <= SEGMENT_NUM_SMALL)
//		{
//			ins_flow_temp_float = flow_coef[23].flt+flow_coef[24].flt*temp_value_float
//			+flow_coef[25].flt*(time_dof_temp_float+flow_coef[22].flt)
//			+flow_coef[26].flt*temp_value_float*temp_value_float
//			+flow_coef[27].flt*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float
//			+flow_coef[28].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)
//			+flow_coef[29].flt*temp_value_float*temp_value_float*temp_value_float
//			+flow_coef[30].flt*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float*temp_value_float
//			+flow_coef[31].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float
//			+flow_coef[32].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt);
//		}
//		else if (Mum_T_DIFTOF <= SEGMENT_NUM_MIDDLE)
//		{
//			ins_flow_temp_float = flow_coef[12].flt+flow_coef[13].flt*temp_value_float
//			+flow_coef[14].flt*(time_dof_temp_float+flow_coef[11].flt)
//			+flow_coef[15].flt*temp_value_float*temp_value_float
//			+flow_coef[16].flt*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float
//			+flow_coef[17].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)
//			+flow_coef[18].flt*temp_value_float*temp_value_float*temp_value_float
//			+flow_coef[19].flt*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float*temp_value_float
//			+flow_coef[20].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float
//			+flow_coef[21].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt);
//		}
//		else
//		{
//			ins_flow_temp_float = flow_coef[1].flt+flow_coef[2].flt*temp_value_float
//			+flow_coef[3].flt*(time_dof_temp_float+flow_coef[0].flt)
//			+flow_coef[4].flt*temp_value_float*temp_value_float
//			+flow_coef[5].flt*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float
//			+flow_coef[6].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)
//			+flow_coef[7].flt*temp_value_float*temp_value_float*temp_value_float
//			+flow_coef[8].flt*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float*temp_value_float
//			+flow_coef[9].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float
//			+flow_coef[10].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt);
//		}
		#elif SUBSECTION_NUM_FOUR

		if(Mum_T_DIFTOF <= SEGMENT_NUM_SMALL)
		{
			#if LILUNGONGSHI_MODLE_WATER_METER				
			ins_flow_temp_float = ins_flow_temp_float*(flow_coef[34].flt + flow_coef[36].flt*ins_flow_temp_float);
			#else
			ins_flow_temp_float = flow_coef[34].flt+flow_coef[35].flt*temp_value_float
			+flow_coef[36].flt*(time_dof_temp_float+flow_coef[33].flt)
			+flow_coef[37].flt*temp_value_float*temp_value_float
			+flow_coef[38].flt*(time_dof_temp_float+flow_coef[33].flt)*temp_value_float
			+flow_coef[39].flt*(time_dof_temp_float+flow_coef[33].flt)*(time_dof_temp_float+flow_coef[33].flt)
			+flow_coef[40].flt*temp_value_float*temp_value_float*temp_value_float
			+flow_coef[41].flt*(time_dof_temp_float+flow_coef[33].flt)*temp_value_float*temp_value_float
			+flow_coef[42].flt*(time_dof_temp_float+flow_coef[33].flt)*(time_dof_temp_float +flow_coef[33].flt)*temp_value_float
			+flow_coef[43].flt*(time_dof_temp_float+flow_coef[33].flt)*(time_dof_temp_float+flow_coef[33].flt)*(time_dof_temp_float+flow_coef[33].flt);
			#endif
		}
		else if (Mum_T_DIFTOF <= SEGMENT_NUM_MIDDLE)
		{
			#if LILUNGONGSHI_MODLE_WATER_METER				
			ins_flow_temp_float = ins_flow_temp_float*(flow_coef[23].flt + flow_coef[25].flt*ins_flow_temp_float);
			#else
			ins_flow_temp_float = flow_coef[23].flt+flow_coef[24].flt*temp_value_float
			+flow_coef[25].flt*(time_dof_temp_float+flow_coef[22].flt)
			+flow_coef[26].flt*temp_value_float*temp_value_float
			+flow_coef[27].flt*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float
			+flow_coef[28].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)
			+flow_coef[29].flt*temp_value_float*temp_value_float*temp_value_float
			+flow_coef[30].flt*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float*temp_value_float
			+flow_coef[31].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)*temp_value_float
			+flow_coef[32].flt*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt)*(time_dof_temp_float+flow_coef[22].flt);
			#endif
		}
		else if (Mum_T_DIFTOF <= SEGMENT_NUM_LARGE)
		{
			#if LILUNGONGSHI_MODLE_WATER_METER			
			ins_flow_temp_float = ins_flow_temp_float*(flow_coef[12].flt + flow_coef[14].flt*ins_flow_temp_float);
			#else
			ins_flow_temp_float = flow_coef[12].flt+flow_coef[13].flt*temp_value_float
			+flow_coef[14].flt*(time_dof_temp_float+flow_coef[11].flt)
			+flow_coef[15].flt*temp_value_float*temp_value_float
			+flow_coef[16].flt*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float
			+flow_coef[17].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)
			+flow_coef[18].flt*temp_value_float*temp_value_float*temp_value_float
			+flow_coef[19].flt*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float*temp_value_float
			+flow_coef[20].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)*temp_value_float
			+flow_coef[21].flt*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt)*(time_dof_temp_float+flow_coef[11].flt);
			#endif
		}
		else
		{
			#if LILUNGONGSHI_MODLE_WATER_METER				
			ins_flow_temp_float = ins_flow_temp_float*(flow_coef[1].flt + flow_coef[3].flt*ins_flow_temp_float);
			#else
			ins_flow_temp_float = flow_coef[1].flt+flow_coef[2].flt*temp_value_float
			+flow_coef[3].flt*(time_dof_temp_float+flow_coef[0].flt)
			+flow_coef[4].flt*temp_value_float*temp_value_float
			+flow_coef[5].flt*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float
			+flow_coef[6].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)
			+flow_coef[7].flt*temp_value_float*temp_value_float*temp_value_float
			+flow_coef[8].flt*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float*temp_value_float
			+flow_coef[9].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)*temp_value_float
			+flow_coef[10].flt*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt)*(time_dof_temp_float+flow_coef[0].flt);
			#endif
		}

		//以下是流量防护判定2021-06-28
		#if  WENDU_FANSUAN_OPEN
		if(temp_value_float<(float)0.5)//温度反算0度及以下时防止结冰表计走数
		{
			return 0;
		}
		else if((temp_value_float<(float)5)&&((gp22_app_data.s.peak_up<95)||(gp22_app_data.s.peak_down<95)))//温度值小于5度，并且单边幅值小于95mv
		{
			return 0;
		}
		#endif
        if((temp_value_float<(float)0.1)&&(0!=temp_value_float))
		{
			return 0;
		}	
		if(TRUE == CheckDiftofCalibrationFlag())
		{
			if(ins_flow_temp_float <= CALIBRATION_PROTECT_VALUE)
			{
				return 0;
			}
		}		
		#if DOMESTIC_TYPE_METER
        if(((gp22_app_data.s.peak_up < TOF_UP_AM_0_8 )||(gp22_app_data.s.peak_down < TOF_DOWN_AM_0_8))&&(ins_flow_temp_float<=Q1_0_8))
		{
			return 0;
		}
		#endif
		if(ins_flow_temp_float<0)
		{
			ins_flow_temp_float=0;
		}//如果流量曲线不合适导致计算的瞬时流量为负数，则写为0
		#elif SUBSECTION_NUM_FIVE
		//待添加五条曲线
		#endif
		//建模曲线单修位置
		#if  	DN15_BRASS_40KPA_GP30_32768 || WDFS_DN15_BRASS_40KPA_GP30_32768//待验证
		
		#elif LLGS_DN15_BRASS_40KPA_GP30_32768 //更新2022-02-18 Lv
		if(temp_value_float < (float)13)  //温度范围
		{
			if(ins_flow_temp_float < (float)23) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//-0.3%
			}
			else if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)350)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}				
		}	
		if((temp_value_float >= (float)13)&&(temp_value_float < (float)17))  //温度范围
		{		
			if((ins_flow_temp_float >= (float)23)&&(ins_flow_temp_float < (float)43)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5%
			}
			else if(ins_flow_temp_float >= (float)350) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}				
		}
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)23))  //温度范围
		{
			if((ins_flow_temp_float >= (float)25)&&(ins_flow_temp_float < (float)43)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)28))  //温度范围
		{
			if((ins_flow_temp_float >= (float)25)&&(ins_flow_temp_float < (float)43)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if(ins_flow_temp_float >= (float)85) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)28)&&(temp_value_float < (float)31))  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if(ins_flow_temp_float >= (float)85) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;
			}
		}
		else if((temp_value_float >= (float)31)&&(temp_value_float < (float)38))  //温度范围
		{
			if(ins_flow_temp_float < (float)23) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)23)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if(temp_value_float >= (float)38) //温度范围
		{
			if(ins_flow_temp_float < (float)60) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)110)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}
			else if(ins_flow_temp_float >= (float)1400) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
		}
        #elif Buxiugang_LLGS_WDFS_DN15_BXG_40KPA_GP30_32768
		if(temp_value_float < (float)11.3)  //温度范围
		{			
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004; // 流量21以下：0.6%
			}
			else if((ins_flow_temp_float >= (float)21)&&(ins_flow_temp_float < (float)26)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;//流量21~27：0.2%
			}			
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//流量26~65：-0.3%
			}
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)150)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)1500)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;//
			}
			else if((ins_flow_temp_float >= (float)1500)&&(ins_flow_temp_float < (float)1900)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if(ins_flow_temp_float >= (float)2800)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//
			}			
		}
		else if((temp_value_float >= (float)11.3)&&(temp_value_float < (float)16))  //温度范围
		{			
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004; // 流量19以下：0.6%
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)21)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//流量19~21：0.3%
			}
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//流量26~65：-0.5%
			}
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)150)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)1500)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;//
			}
			else if((ins_flow_temp_float >= (float)1500)&&(ins_flow_temp_float < (float)1900)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if(ins_flow_temp_float >= (float)2800)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//
			}
		}
		//过度曲线
		else if((temp_value_float >= (float)16)&&(temp_value_float < (float)17))  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; // 流量19以下：0.3%
			}
			else if((ins_flow_temp_float >= (float)24)&&(ins_flow_temp_float < (float)26)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  //
			}
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)55)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;  //
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  //流量55~65：-0.5%
			}
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)150)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)1200)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;//
			}			
			else if((ins_flow_temp_float >= (float)1200)&&(ins_flow_temp_float < (float)1500)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;//
			}
			else if(ins_flow_temp_float >= (float)2800)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//
			}
		}
		//常温修正
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)25.14))  //温度范围
		{
			if((ins_flow_temp_float >= (float)24)&&(ins_flow_temp_float < (float)26)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  //
			}
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)28)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;  //
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.986;  //
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)55)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;  //
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  //流量55~65：-0.5%
			}
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)150)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)1200)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;//
			}			
			else if((ins_flow_temp_float >= (float)1200)&&(ins_flow_temp_float < (float)1500)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;//
			}
			else if(ins_flow_temp_float >= (float)2800)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;//
			}
		}
		//温度过度曲线
		else if((temp_value_float >= (float)25.14)&&(temp_value_float < (float)28))  //温度范围
		{
			if((ins_flow_temp_float >= (float)24)&&(ins_flow_temp_float < (float)26)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.002797*temp_value_float + (float)0.924678); //温度曲线25.14~28-->-0.5~0.3% 0.002797+0.924678 
			}
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)55)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.005245*temp_value_float + (float)0.858147); //0.005245+0.858147 温度曲线25.14~28-->-1~0.5%  
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)60)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.0035*temp_value_float + (float)0.9071); //0.00350+0.90710 温度曲线25.14~28-->-0.5~0.5%
			}
			else if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)65)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.001748*temp_value_float + (float)0.956049); //0.001748+ 0.956049 温度曲线25.14~28-->0~0.5%
			}
			else if((ins_flow_temp_float >= (float)65)&&(ins_flow_temp_float < (float)1200)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
			}
		}
		else if((temp_value_float >= (float)28)&&(temp_value_float < (float)36))  //温度范围
		{
			if(ins_flow_temp_float < (float)26) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007; //
			}
			else if((ins_flow_temp_float >= (float)26)&&(ins_flow_temp_float < (float)1200)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;  //
			}
			else if((ins_flow_temp_float >= (float)1200)&&(ins_flow_temp_float < (float)2100))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  //流量1100以上：0.3%
			}
			else if((ins_flow_temp_float >= (float)2100)&&(ins_flow_temp_float < (float)2800))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  //流量1100以上：0.3%
			}
		}
		else if(temp_value_float >= (float)36)  //温度范围
		{
			if(ins_flow_temp_float < (float)1200) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01; // 流量20以下：0.7%
			}
			else if((ins_flow_temp_float >= (float)1200)&&(ins_flow_temp_float < (float)1300))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  //
			}
			else if((ins_flow_temp_float >= (float)1300)&&(ins_flow_temp_float < (float)2800)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  //流量1200以上：0.3%
			}				
		}
        #elif Plastic_LLGS_WDFS_DN15_PALSTIC_40KPA_GP30_32768
		if(temp_value_float < (float)13)
		{
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;//
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)33)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; // 
			}
			else if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)95)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005; // 
			}
			else if(ins_flow_temp_float >= (float)95) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002; // 
			}			
		}
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)17))
		{
			if(ins_flow_temp_float < (float)23) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//
			}
			else if((ins_flow_temp_float >= (float)23)&&(ins_flow_temp_float < (float)33)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004; // 
			}
			else if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)95)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002; // 
			}			
		}
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)28.4))  //温度范围
		{
			if((ins_flow_temp_float >= (float)23)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;//流量23~35：0.2%
			}				
		}
		else if((temp_value_float >= (float)28.4)&&(temp_value_float < (float)33.67))  //温度范围
		{
			if(ins_flow_temp_float < (float)5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//
			}
			else if((ins_flow_temp_float >= (float)5)&&(ins_flow_temp_float < (float)12))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.001286*ins_flow_temp_float+(float)0.988571); //0.001286+0.988571  5-0.995 12-1.004
			}	
			else if((ins_flow_temp_float >= (float)12)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;//
			}
			else if((ins_flow_temp_float >= (float)1700)&&(ins_flow_temp_float < (float)2100)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if(ins_flow_temp_float >= (float)2100) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}	
		}
		else if((temp_value_float >= (float)33.67)&&(temp_value_float < (float)36))  //温度范围
		{
			if(ins_flow_temp_float < (float)5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//
			}
			else if((ins_flow_temp_float >= (float)5)&&(ins_flow_temp_float < (float)12))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.002*ins_flow_temp_float+(float)0.98); //0.002+ 0.98   5-0.99 12-1.004
			}
			else if((ins_flow_temp_float >= (float)12)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;//
			}
			else if((ins_flow_temp_float >= (float)1700)&&(ins_flow_temp_float < (float)2100)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)2100)&&(ins_flow_temp_float < (float)2800)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
			else if(ins_flow_temp_float >= (float)2800)
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}			
		}
		else if((temp_value_float >= (float)36)&&(temp_value_float < (float)43))  //温度范围
		{
			if(ins_flow_temp_float < (float)5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//
			}
			else if((ins_flow_temp_float >= (float)5)&&(ins_flow_temp_float < (float)12))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.002286*ins_flow_temp_float+(float)0.978571); //0.002286+0.978571   5-0.99 12-1.006
			}
			else if((ins_flow_temp_float >= (float)12)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.006;//
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)75)&&(ins_flow_temp_float < (float)1700)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)1700)&&(ins_flow_temp_float < (float)2100)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)2100)&&(ins_flow_temp_float < (float)2800)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.009;
			}	
			else if(ins_flow_temp_float >= (float)2800)
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.013;
			}			
		}
		else if(temp_value_float >= (float)43)  //温度范围
		{
			if(ins_flow_temp_float < (float)5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//
			}
			else if((ins_flow_temp_float >= (float)5)&&(ins_flow_temp_float < (float)12))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.002286*ins_flow_temp_float+(float)0.978571); //0.002286+0.978571   5-0.99 12-1.006
			}
			else if((ins_flow_temp_float >= (float)12)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.006;//
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)75)&&(ins_flow_temp_float < (float)78)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}
			else if((ins_flow_temp_float >= (float)78)&&(ins_flow_temp_float < (float)1700)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;
			}
			else if((ins_flow_temp_float >= (float)1700)&&(ins_flow_temp_float < (float)2100)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.009;
			}
			else if((ins_flow_temp_float >= (float)2100)&&(ins_flow_temp_float < (float)2800)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.014;
			}	
			else if(ins_flow_temp_float >= (float)2800)
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.018;
			}			
		}
        #elif ROUND_LLGS_DN15_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768 //需要测试看看反算表能否适配常规圆壳量产曲线
        if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)130))//流量40-50
		{
			ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
		}
//		else if(ins_flow_temp_float < (float)7) //流量范围
//		{
//			ins_flow_temp_float = ins_flow_temp_float *(float)0.99; //曲线补偿 -1%
//		}
//		else if((ins_flow_temp_float >= (float)7)&&(ins_flow_temp_float < (float)7.5))//流量7-8.5
//		{
//			ins_flow_temp_float = ins_flow_temp_float *((float)0.02*ins_flow_temp_float+(float)0.85); //曲线补偿 -1%-0过度
//		}
//        else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)110))//流量50-110
//		{
//			ins_flow_temp_float = ins_flow_temp_float *(float)1.004;
//		}
//        else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)130))//流量110-130
//		{
//			ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
//		}
		if(ins_flow_temp_float < (float)7) //流量范围
		{
			if(temp_value_float >= (float)30) //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.995; //曲线补偿 -1%数据修该为0.995  04 22
			}
//			else if((temp_value_float >= (float)25)&&(temp_value_float < (float)30))  //温度范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.995; //曲线补偿 -0.5%//
//			}
		}
		else if((ins_flow_temp_float >= (float)7)&&(ins_flow_temp_float < (float)8.5))//流量7-8.5
		{
			if(temp_value_float >= (float)30) //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.0033*ins_flow_temp_float + (float)0.9717); //曲线补偿0-- -0.5%  
			}
			else if((temp_value_float >= (float)25)&&(temp_value_float < (float)30))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)-0.001*temp_value_float + (float)1.025); //曲线补偿0-- -0.5%//
			}
		}
		else if((ins_flow_temp_float >= (float)8.5)&&(ins_flow_temp_float < (float)18))//流量8.5-18
		{
			if(temp_value_float >= (float)47) //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003; //曲线补偿0-- 0.3%
			}
			else if((temp_value_float >= (float)28)&&(temp_value_float < (float)42))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997; //曲线补偿0-- -0.3%
			}
		}
		else if((ins_flow_temp_float >= (float)25)&&(ins_flow_temp_float < (float)32))//流量25-32
		{
			if(temp_value_float >= (float)25)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997; //曲线补偿0-- -0.3%
			}
		}
		else if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)38))//流量33-38
		{
			if(temp_value_float >= (float)38)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.002; //曲线补偿0-- 0.2%
			}
		}
		else if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)55))//流量38-55
		{
			if(temp_value_float >= (float)45)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.007; //曲线补偿0-- 0.7%
			}
			else if(temp_value_float >= (float)38)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.004; //曲线补偿0-- 0.4%
			}
			else if(temp_value_float >= (float)25)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.002; //曲线补偿0-- 0.2%
			}
		}
//		else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)85))//流量55-85
//		{
//			if(temp_value_float >= (float)35)  //温度范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)1.005; //曲线补偿0-- 0.5%
//			}
//			else if(temp_value_float >= (float)25)  //温度范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)1.003; //曲线补偿0-- 0.3%
//			}
//		}
		else if((ins_flow_temp_float >= (float)140)&&(ins_flow_temp_float < (float)280))//流量140-280
		{
			if((temp_value_float >= (float)34.86)&&(temp_value_float < (float)38))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996; //曲线补偿0-- -0.4%
			}
			else if((temp_value_float >= (float)28)&&(temp_value_float < (float)34.86))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997; //曲线补偿0-- -0.3%
			}
		}
		else if((ins_flow_temp_float >= (float)280)&&(ins_flow_temp_float < (float)400))//流量280-400
		{
			if((temp_value_float >= (float)34.86)&&(temp_value_float < (float)38))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996; //曲线补偿0-- -0.4%
			}
			else if((temp_value_float >= (float)25)&&(temp_value_float < (float)34.86))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997; //曲线补偿0-- -0.3%
			}
		}
		else if((ins_flow_temp_float >= (float)400)&&(ins_flow_temp_float < (float)1200))//流量400-1200
		{
			if((temp_value_float >= (float)25)&&(temp_value_float < (float)34.86))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997; //曲线补偿0-- -0.3%
			}
		}
		else if(ins_flow_temp_float >= (float)1200)//流量1200+
		{
			if(temp_value_float < (float)13.07)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.002; //曲线补偿0-- 0.2%
			}
		}
		#elif LLGS_WDFS_DN15_BRASS_40KPA_GP30_32768
		//全温度修正 2021/8/6  
		if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)70))//流量50-70，流量范围无重叠
		{
			ins_flow_temp_float = ins_flow_temp_float *(float)0.995;
		}
		//温度修正 2021/8/6
		if(temp_value_float >= (float)35) //温度范围
		{
			if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)200))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.004;
			}
			else if(ins_flow_temp_float >= (float)200)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.007;
			}
		}
		else if((temp_value_float >= (float)30)&&(temp_value_float < (float)35))  //温度范围
		{
			if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; //曲线补偿+0.3%
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)200))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.0016*temp_value_float + (float)0.948); //30~35度，曲线补偿-0.4%~0.4%
			}
			else if(ins_flow_temp_float >= (float)200)
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.0014*temp_value_float + (float)0.958); //30~35度，曲线补偿0~0.7%
			}			
		}
		else if((temp_value_float >= (float)15)&&(temp_value_float < (float)30)) //温度范围
		{
			if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)200)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996; //曲线补偿-0.4%
			}		
		}
		if((temp_value_float >= (float)15)&&(temp_value_float < (float)17)) //温度范围
		{
			if(ins_flow_temp_float <= (float)50) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0025*temp_value_float + (float)1.0425); //15~17度，曲线补偿+0.5%~0
			}		
		}
		else if((temp_value_float >= (float)10)&&(temp_value_float < (float)15))//温度范围
		{
			if(ins_flow_temp_float <= (float)50)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)-0.002*temp_value_float + (float)1.035); //15~10度，曲线补偿0.5~1.5%
			}
			else if(ins_flow_temp_float >= (float)70)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)-0.001*temp_value_float + (float)1.015); //15~10度，曲线补偿0%~05%
			}
		}
		else if(temp_value_float < (float)10)//温度范围
		{
			if(ins_flow_temp_float <= (float)50)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.015; //曲线补偿+1.5%
			}
			else if(ins_flow_temp_float >= (float)70)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)-0.002*temp_value_float + (float)1.025); //10~5度，曲线补偿0.5%~1.5%
			}
		}
//		//流量修正 2021-07-24	
		#elif 	BM_DN15_BRASS_63KPA_GP30_32768 
		 if(temp_value_float >= (float)35)  //温度范围
        {
           ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 			
        }        
		#elif 	MID_DN15_BRASS_63KPA_GP30_32768       
		if(temp_value_float < (float)13)  //温度范围
		{
			if(ins_flow_temp_float < (float)50) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)200))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}				
		}	
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)21))  //温度范围
		{
			
			if(ins_flow_temp_float < (float)50)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
//			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
//			}			
		}
		else if((temp_value_float >= (float)21)&&(temp_value_float < (float)23))  //温度范围
		{
			if(ins_flow_temp_float < (float)17)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0025*temp_value_float + (float)1.0575);//+0.5--0过度
			}
			else if((ins_flow_temp_float >= (float)17)&&(ins_flow_temp_float < (float)19)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0025*ins_flow_temp_float + (float)0.9625);//1.005-1.01过度
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)45)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.0275);//1.01-1.005过度
			}			
//			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
//			}
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)25))  //温度范围
		{
			if(ins_flow_temp_float < (float)35) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.004*temp_value_float+ (float)0.908);//0--0.8过度
			}
//			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
//			}
		}
		else if((temp_value_float >= (float)25)&&(temp_value_float < (float)27))  //温度范围
		{
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}	
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
//			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
//			}
		}
		else if((temp_value_float >= (float)27)&&(temp_value_float < (float)33))  //温度范围
		{
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)13)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}		
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)55)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.001*ins_flow_temp_float + (float)1.05);//0.5~~~-0.5 过度
			}				
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
            else if(ins_flow_temp_float >= (float)2000) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
		}
		else if((temp_value_float >= (float)33)&&(temp_value_float < (float)46))  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)22)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}	
			else if((ins_flow_temp_float >= (float)22)&&(ins_flow_temp_float < (float)32)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)60)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}		
			else if(ins_flow_temp_float >= (float)150) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}			
		}
		else if(temp_value_float >= (float)46)  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)22)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}	
			else if((ins_flow_temp_float >= (float)22)&&(ins_flow_temp_float < (float)24)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)32)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}			
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)60)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}					
		}
        #elif	EN_DN15_BRASS_63KPA_GP30_32768
        if(temp_value_float >= (float)41) //温度范围
		{
			if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; 
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)55))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0004*ins_flow_temp_float + (float)1.017); //-0.0004x + 1.017 35-1.003 55 0.995
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)155))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
			else if((ins_flow_temp_float >= (float)155)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99; 
			}
			else if(ins_flow_temp_float >= (float)1900)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
		}
		else if((temp_value_float >= (float)33)&&(temp_value_float < (float)41))
		{
			if(ins_flow_temp_float < (float)13)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;  
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)19))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0012*ins_flow_temp_float + (float)0.9808); //0.0012x + 0.9808  13-0.4 19+0.3
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; 
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)55))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.0223); //-0.0005x + 1.0223 35-1.003 55 0.992
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99; 
			}
			else if(ins_flow_temp_float >= (float)1900)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
		}
		else if((temp_value_float >= (float)28)&&(temp_value_float < (float)33))
		{
			if(ins_flow_temp_float < (float)13)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;  
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)19))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0008*ins_flow_temp_float + (float)0.9872); //0.0008x + 0.9872  13-0.2 19+0.3
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; 
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)55))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0004*ins_flow_temp_float + (float)1.017); //-0.0004x + 1.017 35-1.003 55 0.995
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
			else if(ins_flow_temp_float >= (float)1900)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997; 
			}
		}
		else if((temp_value_float >= (float)18)&&(temp_value_float < (float)28))
		{
			if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; 
			}
		}
		else if((temp_value_float >= (float)14)&&(temp_value_float < (float)18))
		{
			if(ins_flow_temp_float < (float)13)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)19))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0013*ins_flow_temp_float + (float)0.9777); // 0.0013x + 0.9777  13-0.5 18+0.3
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003; 
			}
			else if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)78))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if(ins_flow_temp_float >= (float)85)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997; 
			}
		}
		else if(temp_value_float < (float)14)
		{
			if(ins_flow_temp_float < (float)13)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;  
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998; 
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)55))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)65))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0013*ins_flow_temp_float + (float)0.9235); //0.0013x + 0.9235 55-0.5 65+0.8
			}
			else if((ins_flow_temp_float >= (float)65)&&(ins_flow_temp_float < (float)75))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)75)&&(ins_flow_temp_float < (float)85))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0011*ins_flow_temp_float + (float)1.0905); //-0.0011x + 1.0905 65+0.8 85-0.3
			}
			else if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)95))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
			else if(ins_flow_temp_float >= (float)95)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.992; 
			}
		}
		#elif ROUND_LLGS_XFZ_DN15_BRASS_40KPA_GP30_32768
		if(temp_value_float >= (float)28.58)  //温度范围
		{
			if(ins_flow_temp_float < (float)8.5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)8.5)&&(ins_flow_temp_float < (float)13))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)19))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)600)&&(ins_flow_temp_float < (float)700))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)700)&&(ins_flow_temp_float < (float)1400))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)1400)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)28.58))
		{
			if(ins_flow_temp_float < (float)8.5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)8.5)&&(ins_flow_temp_float < (float)28))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)90))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)180))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)350)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if((temp_value_float >= (float)18.5)&&(temp_value_float < (float)23))
		{
			if(ins_flow_temp_float < (float)8.5) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}
			else if((ins_flow_temp_float >= (float)8.5)&&(ins_flow_temp_float < (float)28))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.013;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)90))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)100))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)250)&&(ins_flow_temp_float < (float)350))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)350)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}
			else if((ins_flow_temp_float >= (float)1900)&&(ins_flow_temp_float < (float)2000))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if((temp_value_float >= (float)17.5)&&(temp_value_float < (float)18.5))
		{
			if(ins_flow_temp_float < (float)28)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)180))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)350)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if((temp_value_float >= (float)14)&&(temp_value_float < (float)17.5))
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}	
			else if((ins_flow_temp_float >= (float)95)&&(ins_flow_temp_float < (float)120))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)180))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)190))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)550)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
		}
		else if(temp_value_float < (float)14)  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}	
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)25))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)95))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)95)&&(ins_flow_temp_float < (float)120))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)180))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.985;
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)190))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float >= (float)190)&&(ins_flow_temp_float < (float)230))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)550)&&(ins_flow_temp_float < (float)750))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)750)&&(ins_flow_temp_float < (float)1100))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.007;
			}
			else if((ins_flow_temp_float >= (float)1100)&&(ins_flow_temp_float < (float)1900))  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
		}
        #elif PF_DN15_BRASS_63KPA_GP30_32768
		if(temp_value_float < (float)13)  //温度范围
		{
			if(ins_flow_temp_float < (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if(ins_flow_temp_float >= (float)90)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}				
		}	
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)21))  //温度范围
		{
			
			if(ins_flow_temp_float < (float)50)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}			
		}
		else if((temp_value_float >= (float)21)&&(temp_value_float < (float)23))  //温度范围
		{
			if(ins_flow_temp_float < (float)17)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0025*temp_value_float + (float)1.0575);//+0.5--0过度
			}
			else if((ins_flow_temp_float >= (float)17)&&(ins_flow_temp_float < (float)19)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0025*ins_flow_temp_float + (float)0.9625);//1.005-1.01过度
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)45)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.0275);//1.01-1.005过度
			}			
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)25))  //温度范围
		{
			if(ins_flow_temp_float < (float)35) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.004*temp_value_float+ (float)0.908);//0--0.8过度
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)25)&&(temp_value_float < (float)27))  //温度范围
		{
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}	
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)27)&&(temp_value_float < (float)33))  //温度范围
		{
			if(ins_flow_temp_float < (float)8) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)13)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)35)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}
			else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)45)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}		
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)55)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.001*ins_flow_temp_float + (float)1.05);//0.5~~~-0.5 过度
			}				
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)70)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)150)&&(ins_flow_temp_float < (float)2000)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)33)&&(temp_value_float < (float)46))  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)22)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}	
			else if((ins_flow_temp_float >= (float)22)&&(ins_flow_temp_float < (float)32)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)60)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}		
			else if(ins_flow_temp_float >= (float)150) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}			
		}
		else if(temp_value_float >= (float)46)  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)22)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
			}	
			else if((ins_flow_temp_float >= (float)22)&&(ins_flow_temp_float < (float)24)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)32)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}			
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)60)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}		
			else if(ins_flow_temp_float >= (float)150) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}			
		}
		
		#elif  	DN20_BRASS_40KPA_GP30_32768  ||  WDFS_DN20_BRASS_40KPA_GP30_32768
        
		if((temp_value_float < (float)17))  //温度范围
		{
			if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)50))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.995;
			}
			else if(ins_flow_temp_float < (float)35) 
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0007*ins_flow_temp_float+(float)1.0222);//-0.2%~1.6%
			}
			else if(ins_flow_temp_float < (float)9) 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.015;
			}			
		} 
        else if((temp_value_float >= (float)25)&&(temp_value_float < (float)35))  //温度范围
        {
			ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
        }
        else if(temp_value_float >= (float)35)  //温度范围
        {
            if(ins_flow_temp_float >= (float)130) //流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.01; 
            }           
        }
        #elif LLGS_DN20_BRASS_40KPA_GP30_32768 //更新2022-02-18 
		if(temp_value_float < (float)13)  //温度范围
		{
			if(ins_flow_temp_float < (float)65) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.008;
			}		
			else if(ins_flow_temp_float >=(float)120) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}			
		}	
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)17))  //温度范围
		{		
			if(ins_flow_temp_float < (float)65)  //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}	
			else if(ins_flow_temp_float >=(float)120) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}			
		}
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)24))  //温度范围
		{
			if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)120)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}	
		}
		else if((temp_value_float >= (float)24)&&(temp_value_float < (float)27))  //温度范围
		{
			if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)120)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
			}
		}
		else if(temp_value_float >= (float)27) //温度范围
		{
			if(ins_flow_temp_float < (float)120) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
		}
		#elif Buxiugang_LLGS_WDFS_DN20_BXG_40KPA_GP30_32768
		if(temp_value_float >= (float)33) //温度范围
		{
			if(ins_flow_temp_float < (float)28) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)33))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.007;
			}
			else if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)36))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.002;
			}
			else if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)95))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996;
			}
		}
		else if((temp_value_float >= (float)29.9)&&(temp_value_float < (float)33))  //温度范围
		{
			if(ins_flow_temp_float < (float)36)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
			}
			else if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)65))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996;
			}
			else if((ins_flow_temp_float >= (float)65)&&(ins_flow_temp_float < (float)130))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
			}
		}
		else if((temp_value_float >= (float)24.5)&&(temp_value_float < (float)29.9))  //温度范围
		{
			if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)38))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
			}
			else if((ins_flow_temp_float >= (float)65)&&(ins_flow_temp_float < (float)130))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996;
			}
		}
		else if((temp_value_float >= (float)18.46)&&(temp_value_float < (float)24.5))  //温度范围
		{
			if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)43))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
			}
			else if((ins_flow_temp_float >= (float)65)&&(ins_flow_temp_float < (float)130))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996;
			}
		}
		else if(temp_value_float < (float)18.46) //温度范围
		{
			if(ins_flow_temp_float < (float)28)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.998;
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)48))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.003;
			}
			else if((ins_flow_temp_float >= (float)48)&&(ins_flow_temp_float < (float)65))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)1.005;
			}
			else if((ins_flow_temp_float >= (float)75)&&(ins_flow_temp_float < (float)130))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.996;
			}
			else if((ins_flow_temp_float >= (float)130)&&(ins_flow_temp_float < (float)550))
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
			}
		}
        #elif ROUND_LLGS_DN20_BRASS_40KPA_GP30_32768 || ROUND_LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768 
        //		if((ins_flow_temp_float >= (float)1500)&&(ins_flow_temp_float < (float)3000))//流量1500-3000
//		{
//			ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
//		}
		if(temp_value_float >= (float)35) //温度范围
		{
			if(ins_flow_temp_float < (float)8)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.99;
			}
			else if((ins_flow_temp_float >= (float)8)&&(ins_flow_temp_float < (float)13))
			{
				ins_flow_temp_float = ins_flow_temp_float *((float)0.002*ins_flow_temp_float+(float)0.974);//-1--- 0
			}
//			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)35))
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
//			}
		}
		else if((temp_value_float >= (float)33)&&(temp_value_float < (float)35))  //温度范围 --过度段
		{
			if(ins_flow_temp_float < (float)13)
			{
				ins_flow_temp_float = ins_flow_temp_float *(float)0.995;
			}
//			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)35))
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.998;
//			}
		}
//		else if((temp_value_float >= (float)12.7)&&(temp_value_float < (float)17))  //温度范围
//		{
//			if(ins_flow_temp_float < (float)13)
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.995;
//			}
//			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)38))
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
//			}
//		}
//		else if(temp_value_float < (float)12.7)  //温度范围
//		{
//			if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)35))
//			{
//				ins_flow_temp_float = ins_flow_temp_float *(float)0.997;
//			}
//		}
		#elif LLGS_WDFS_DN20_BRASS_40KPA_GP30_32768
		
		if(ins_flow_temp_float < (float)30) //流量范围
		{
			if(temp_value_float >= (float)35)  //
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.006;
			}
			else if((temp_value_float >= (float)30)&&(temp_value_float < (float)35))  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.001*temp_value_float + (float)0.97);  //30--35度 0%~0.5%  
			}		 
		}
		else if((ins_flow_temp_float >= (float)30)&&(ins_flow_temp_float < (float)130))//流量范围
		{
			if(temp_value_float >= (float)30)  //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.006;
			}
			else if((temp_value_float > (float)15)&&(temp_value_float < (float)30))  
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((ins_flow_temp_float >= (float)200))//流量范围
		{
			if(temp_value_float < (float)15)  
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		#elif 	BM_DN20_BRASS_63KPA_GP30_32768 
		//2020-06-28 建模后第一次单独修正
		if(temp_value_float >= (float)45)  //温度范围
		{
			if(ins_flow_temp_float < (float)55) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;  //2020-09-11 根据机械台子修正
			}
            else if((ins_flow_temp_float >= (float)130)&&(ins_flow_temp_float < (float)600))//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
		}
        else if((temp_value_float < (float)40)&&(temp_value_float >= (float)30))  //温度范围
        {
            if(ins_flow_temp_float < (float)20) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  
			}
            else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)90))//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
        }
        //流量修正
        if((ins_flow_temp_float >= (float)130)&&(ins_flow_temp_float < (float)600))//流量范围
        {
            if((temp_value_float < (float)45)&&(temp_value_float >=(float)15))  //温度范围  //温度范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)0.995;   
            }
            else if(temp_value_float <(float)15)//
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.992;
            }
        }
        else if(ins_flow_temp_float > (float)600)//流量范围
        {
            if(temp_value_float >= (float)35)//2020-09-11 根据机械台子修正
            {
                 ins_flow_temp_float = ins_flow_temp_float * (float)0.998; 
            }           
        }
        //机械台子修正 2020-07-08
        if(ins_flow_temp_float < (float)50)//流量范围
        {
            if((temp_value_float < (float)40)&&(temp_value_float >=(float)15))  //温度范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;   
            }
            else if(temp_value_float >= (float)40)  //温度范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)0.996;   
            }            
        }        
		//流量单独修正		
		if(temp_value_float >= (float)15)//2021-05-12 
		{
		    if((ins_flow_temp_float >= (float)30)&&(ins_flow_temp_float <= (float)50))//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float > (float)50)&&(ins_flow_temp_float < (float)100))//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.991;
			}
			else if((ins_flow_temp_float >= (float)100)&&(ins_flow_temp_float < (float)120))//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}				
		}
		//2021-05-10 
		else if(temp_value_float <(float)15)
		{
			if(ins_flow_temp_float < (float)30)//流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998; 
			}
			else
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
			}
		}
        #elif	MID_DN20_BRASS_63KPA_GP30_32768 
        if(temp_value_float < (float)13)  //温度范围
		{	
			if(ins_flow_temp_float >= (float)70)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
            }
//			else if(ins_flow_temp_float <= (float)22) //流量范围
//			{
//				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
//			}			
		}
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)15))  //温度范围
		{
			if(ins_flow_temp_float >= (float)130) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)22))  //温度范围
		{
			if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)45)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;//1.005
			}					
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)27))  //温度范围
		{
			if(ins_flow_temp_float >= (float)95) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}	
		}
		else if((temp_value_float >= (float)27)&&(temp_value_float < (float)30))  //温度范围
		{
			if(ins_flow_temp_float <= (float)50) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00167 *temp_value_float + (float)1.045);//0--0.5%过度
			}				
		}
		else if((temp_value_float >= (float)30)&&(temp_value_float < (float)34))  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.00125*temp_value_float + (float)0.9525);//0.99-0.995
			}	
			else if(ins_flow_temp_float >= (float)180) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}			
		}
		else if((temp_value_float >= (float)37)&&(temp_value_float < (float)43))  //温度范围
		{
			if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;//0.996
			}
			else if(ins_flow_temp_float >= (float)70) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.992;
			}			
		}
		else if(temp_value_float >= (float)43)  //温度范围
		{
			if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;//0.996
			}	
			else if(ins_flow_temp_float >= (float)70) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}			
		}
		if(temp_value_float >= (float)40)  //温度范围
		{
			if(ins_flow_temp_float < (float)20) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;//+0.5
			}
		}        
		#elif 	EN_DN20_BRASS_63KPA_GP30_32768       
		if(temp_value_float >= (float)34.35)  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)43)&&(ins_flow_temp_float < (float)125)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;
			}
			else if((ins_flow_temp_float >= (float)135)&&(ins_flow_temp_float < (float)180)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float) -0.000111*ins_flow_temp_float + (float)1.015);//-0.000111+ 1.015  135 0 180 -0.5
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)620)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float >= (float)620)&&(ins_flow_temp_float < (float)2600)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;
			}
			else if(ins_flow_temp_float >= (float)2600) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
		}
		else if((temp_value_float >= (float)27.5)&&(temp_value_float < (float)34.35))//温度范围
		{
			if((ins_flow_temp_float >= (float)14)&&(ins_flow_temp_float < (float)23)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
			else if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)38)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)83)&&(ins_flow_temp_float < (float)125)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)230)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)230)&&(ins_flow_temp_float < (float)620)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float >= (float)620)&&(ins_flow_temp_float < (float)2600)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;
			}
			else if(ins_flow_temp_float >= (float)2600) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
		}
		else if((temp_value_float >= (float)18.7)&&(temp_value_float < (float)27.5))//温度范围
		{
			if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)48)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.004;
			}
			else if((ins_flow_temp_float >= (float)73)&&(ins_flow_temp_float < (float)83)) //流量范围 过渡
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
			else if((ins_flow_temp_float >= (float)83)&&(ins_flow_temp_float < (float)125)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float >= (float)125)&&(ins_flow_temp_float < (float)140)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.000667*ins_flow_temp_float + (float)0.911667);//0.000667+0.911667 125 0.5 140 -0.5
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)620)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)620)&&(ins_flow_temp_float < (float)3300)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
		}
		else if((temp_value_float >= (float)13.24)&&(temp_value_float < (float)18.7))//温度范围
		{
			if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)48)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.002;
			}
			else if((ins_flow_temp_float >= (float)73)&&(ins_flow_temp_float < (float)83)) //流量范围 过渡
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
			else if((ins_flow_temp_float >= (float)83)&&(ins_flow_temp_float < (float)125)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float >= (float)125)&&(ins_flow_temp_float < (float)140)) //流量范围 过渡
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0006*ins_flow_temp_float + (float)0.918);//0.0006+ 0.918  125 -0.7 140 0.2
			} 
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)620)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)620)&&(ins_flow_temp_float < (float)2600)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
		}
		else if(temp_value_float < (float)13.24)//温度范围
		{
			if(ins_flow_temp_float < (float)38) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
			else if((ins_flow_temp_float >= (float)73)&&(ins_flow_temp_float < (float)83)) //流量范围 过渡
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)83)&&(ins_flow_temp_float < (float)125)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float >= (float)125)&&(ins_flow_temp_float < (float)180)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.002*temp_value_float + (float)0.97);// 0.002x + 0.97 15℃ 0   10℃ -1
			}
			else if((ins_flow_temp_float >= (float)180)&&(ins_flow_temp_float < (float)620)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float >= (float)620)&&(ins_flow_temp_float < (float)2600)) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.992;
			}
			else if(ins_flow_temp_float >= (float)2600) //流量范围 
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
		}
        #elif PF_DN20_BRASS_63KPA_GP30_32768
		if(temp_value_float < (float)13)  //温度范围
		{	
			if(ins_flow_temp_float >= (float)70)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
            }
			else if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}			
		}
		else if((temp_value_float >= (float)13)&&(temp_value_float < (float)15))  //温度范围
		{
			if(ins_flow_temp_float >= (float)130) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}
			else if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}
		}
		else if((temp_value_float >= (float)15)&&(temp_value_float < (float)17))  //温度范围
		{
			if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
			}				
		}
		else if((temp_value_float >= (float)17)&&(temp_value_float < (float)22))  //温度范围
		{
			if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)45)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)1.005;//1.005
			}					
		}
		else if((temp_value_float >= (float)23)&&(temp_value_float < (float)27))  //温度范围
		{
			if(ins_flow_temp_float >= (float)95) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}	
		}
		else if((temp_value_float >= (float)27)&&(temp_value_float < (float)30))  //温度范围
		{
			if(ins_flow_temp_float <= (float)50) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00167 *temp_value_float + (float)1.045);//0--0.5%过度
			}				
		}
		else if((temp_value_float >= (float)30)&&(temp_value_float < (float)34))  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)50)) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.00125*temp_value_float + (float)0.9525);//0.99-0.995
			}	
			else if(ins_flow_temp_float >= (float)180) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
			}			
		}
		else if((temp_value_float >= (float)37)&&(temp_value_float < (float)43))  //温度范围
		{
			if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;//0.996
			}
			else if(ins_flow_temp_float >= (float)70) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.992;
			}			
		}
		else if(temp_value_float >= (float)43)  //温度范围
		{
			if(ins_flow_temp_float <= (float)22) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;//0.996
			}	
			else if(ins_flow_temp_float >= (float)70) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}			
		}
		//更换换能器以后修正
		if((temp_value_float >= (float)27)&&(temp_value_float < (float)30))  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.005*temp_value_float + (float)1.135);//0---1.5
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)32)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0033*temp_value_float + (float)1.09);//0--1
			}
			else if((ins_flow_temp_float >= (float)32)&&(ins_flow_temp_float < (float)45)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0017*temp_value_float + (float)1.045);//0----0.5
			}
		}
		else if((temp_value_float >= (float)30)&&(temp_value_float < (float)32))  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.985;//-1.5
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)32)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//-1
			}
			else if((ins_flow_temp_float >= (float)32)&&(ins_flow_temp_float < (float)55)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5
			}
		}
		else if((temp_value_float >= (float)32)&&(temp_value_float < (float)34))  //温度范围
		{
			if(ins_flow_temp_float < (float)32) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//-1
			}
			else if((ins_flow_temp_float >= (float)32)&&(ins_flow_temp_float < (float)55)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5
			}
		}
		else if((temp_value_float >= (float)34)&&(temp_value_float < (float)37))  //温度范围
		{
			if(ins_flow_temp_float <= (float)32) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5
			}
			else if(ins_flow_temp_float >= (float)90) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
		}
		else if((temp_value_float >= (float)37)&&(temp_value_float < (float)40))  //温度范围
		{
			if(ins_flow_temp_float < (float)19) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float) -0.00667 *temp_value_float+ (float)1.24167);//-0.5-----2.5
			}
			else if((ins_flow_temp_float >= (float)19)&&(ins_flow_temp_float < (float)32)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float) -0.005*temp_value_float + (float)1.18);//-0.5-----2
			}
			else if((ins_flow_temp_float >= (float)32)&&(ins_flow_temp_float < (float)38)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00333*temp_value_float + (float)1.11833);//-0.5----1.5
			}
			else if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)45)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00333*temp_value_float + (float)1.12333);//0--1
			}
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)55)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5
			}
		}
		else if(temp_value_float >= (float)40)  //温度范围
		{
			if(ins_flow_temp_float < (float)13) //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.97;//-3
			}
			else if((ins_flow_temp_float >= (float)13)&&(ins_flow_temp_float < (float)22)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.975;//-2.5
			}
			else if((ins_flow_temp_float >= (float)22)&&(ins_flow_temp_float < (float)28)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.98;//-2
			}
			else if((ins_flow_temp_float >= (float)28)&&(ins_flow_temp_float < (float)38)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.985;//-1.5
			}
			else if((ins_flow_temp_float >= (float)38)&&(ins_flow_temp_float < (float)45)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;//0--1
			}
			else if((ins_flow_temp_float >= (float)45)&&(ins_flow_temp_float < (float)55)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;//-0.5
			}
			else if((ins_flow_temp_float >= (float)55)&&(ins_flow_temp_float < (float)70)) //流量范围 //流量范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.997;//-0.3
			}
		}
        
		#elif 	DN25_BRASS_40KPA_GP30_32768 
        if(temp_value_float > (float)39)  //温度范围
		{	
            if(ins_flow_temp_float <= (float)18)
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float > (float)18)&&(ins_flow_temp_float <= (float)22))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)22)&&(ins_flow_temp_float <= (float)35))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.988;
			}
			else if((ins_flow_temp_float > (float)35)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)90))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)90)&&(ins_flow_temp_float <= (float)110))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*ins_flow_temp_float + (float)0.958); //0.0004x + 0.958 90-0.6 110+0.2
			}
			else if((ins_flow_temp_float > (float)110)&&(ins_flow_temp_float <= (float)130))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.055); //-0.0005x + 1.055 110+0  130-1
			}
			else if((ins_flow_temp_float > (float)130)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float <= (float)190))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0007*ins_flow_temp_float + (float)0.864); //0.0007x + 0.864 180-1 190-0.3
			}
			else if(ins_flow_temp_float >= (float)190)
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
            }                      
		}
        else if((temp_value_float > (float)37)&&(temp_value_float <= (float)39))  //温度范围
		{	
			if((ins_flow_temp_float > (float)18)&&(ins_flow_temp_float <= (float)22))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float > (float)22)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)90))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)90)&&(ins_flow_temp_float <= (float)110))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*ins_flow_temp_float + (float)0.958); //0.0004x + 0.958 90-0.6 110+0.2
			}
			else if((ins_flow_temp_float > (float)110)&&(ins_flow_temp_float <= (float)130))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.055); //-0.0005x + 1.055 110+0  130-1
			}
			else if((ins_flow_temp_float > (float)130)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float <= (float)190))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0007*ins_flow_temp_float + (float)0.864); //0.0007x + 0.864 180-1 190-0.3
			}
			else if(ins_flow_temp_float >= (float)190)
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
            }                      
		}
		else if((temp_value_float > (float)33)&&(temp_value_float <= (float)37))  //温度范围
		{
            if(ins_flow_temp_float <= (float)18)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
			else if((ins_flow_temp_float > (float)22)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.996;
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)90))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float > (float)90)&&(ins_flow_temp_float <= (float)110))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*ins_flow_temp_float + (float)0.958); //0.0004x + 0.958 90-0.6 110+0.2
			}
			else if((ins_flow_temp_float > (float)110)&&(ins_flow_temp_float <= (float)130))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.055); //-0.0005x + 1.055 110+0  130-1
			} 
			else if((ins_flow_temp_float > (float)130)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.993;
			}
			else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float <= (float)190))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0007*ins_flow_temp_float + (float)0.867); //0.0007x + 0.867 180-0.7 190-0
			}		
		}
		else if((temp_value_float > (float)27)&&(temp_value_float <= (float)33))  //温度范围
		{
			if(ins_flow_temp_float <= (float)18)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
			else if((ins_flow_temp_float > (float)18)&&(ins_flow_temp_float <= (float)22))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0012*ins_flow_temp_float + (float)1.0255); //-0.0012x + 1.0255 18+0.3 22-0.2
			}
			else if((ins_flow_temp_float > (float)22)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.998;
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)90))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if((ins_flow_temp_float > (float)110)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
		}
		else if((temp_value_float > (float)15)&&(temp_value_float <= (float)17))  //温度范围
		{
			if(ins_flow_temp_float <= (float)18)//流量范围
			{
			   ins_flow_temp_float = ins_flow_temp_float * ((float)0.004*temp_value_float + (float)0.927); //15℃：-1.3%~17℃-0.5% 0.004x + 0.927
			}
			else if((ins_flow_temp_float > (float)18)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0015*temp_value_float + (float)0.9695); //15℃：-0.8%~17℃-0.5% 0.0015x + 0.9695
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)65))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.004*temp_value_float + (float)0.927); //15℃：-1.3%~17℃-0.5% 0.004x + 0.927
			}
			else if((ins_flow_temp_float > (float)65)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0065*temp_value_float + (float)0.8845); //15℃：-1.8%~17℃-0.5% 0.0065x + 0.8845
			}
			else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float <= (float)320))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.004*temp_value_float + (float)0.927); //15℃：-1.3%~17℃-0.5% 0.004x + 0.927
			}
			else if((ins_flow_temp_float > (float)320)&&(ins_flow_temp_float <= (float)550))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0025*temp_value_float + (float)0.9525); //15℃：-1%~17℃-0.5% 0.0025x + 0.9525
			}
			else if(ins_flow_temp_float>(float)4800)
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)0.0025*temp_value_float + (float)0.9525); //15℃：-1%~17℃-0.5% 0.0025x + 0.9525
			}
		}
		else if(temp_value_float <= (float)15)  //温度范围
		{
			if(ins_flow_temp_float <= (float)18)//流量范围
			{
			   ins_flow_temp_float = ins_flow_temp_float * (float)0.987;
			}
			else if((ins_flow_temp_float > (float)18)&&(ins_flow_temp_float <= (float)45))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.992;
			}
			else if((ins_flow_temp_float > (float)45)&&(ins_flow_temp_float <= (float)65))
			{	
				ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.0145); //-0.0005x + 1.0145 45 -0.8 65 -1.8
			}
			else if((ins_flow_temp_float > (float)65)&&(ins_flow_temp_float <= (float)180))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.982;
			}
			else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float <= (float)320))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.987;
			}
			else if((ins_flow_temp_float > (float)320)&&(ins_flow_temp_float <= (float)550))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
			else if((ins_flow_temp_float > (float)550)&&(ins_flow_temp_float <= (float)4800))
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else if(ins_flow_temp_float > (float)4800)
			{	
				ins_flow_temp_float = ins_flow_temp_float * (float)0.99;
			}
		}
//        else if(temp_value_float <= (float)15)  //温度范围
//		{
//			if(temp_value_float>=(float)10)
//            {
//                if(ins_flow_temp_float <= (float)90)//流量范围
//                {
//                   ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*temp_value_float + (float)0.989); //15℃：-0.5%~~10℃：-0.7%
//                }
//                else if(ins_flow_temp_float>(float)90)
//                {
//                   ins_flow_temp_float = ins_flow_temp_float * ((float)0.001*temp_value_float + (float)0.983);//15℃：-0.2%~~10℃：-0.7%
//                } 
//            }
//            else //10度以下
//            {
//                ins_flow_temp_float = ins_flow_temp_float * (float)0.993; 
//            }                      
//		}
        //流量单独修正
        if((ins_flow_temp_float > (float)90)&&(ins_flow_temp_float <= (float)120))//流量范围
        {
            if((temp_value_float >= (float)15)&&(temp_value_float < (float)22))  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0009*temp_value_float + (float)0.9841); //15℃：-0.3%~~22℃：+0.3%  
            }
            else if((temp_value_float > (float)22)&&(temp_value_float <= (float)32))  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
		}
		#elif LLGS_DN25_BRASS_40KPA_GP30_32768
		
		#elif  	BM_DN25_BRASS_63KPA_GP30_32768 
		
		
		
		#elif  	MID_DN25_BRASS_63KPA_GP30_32768 
		#elif  	PF_DN25_BRASS_63KPA_GP30_32768
        if(temp_value_float > (float)35)  //温度范围
		{
			if(ins_flow_temp_float <= (float)43)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
            else if(ins_flow_temp_float >= (float)130)
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
            }                       
		}
		else if((temp_value_float > (float)24)&&(temp_value_float <= (float)35))  //温度范围
		{
            if(ins_flow_temp_float <= (float)47)//流量范围
            {
               ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
		}
        else if(temp_value_float <= (float)15)  //温度范围
		{
			if(temp_value_float>=(float)10)
            {
                if(ins_flow_temp_float <= (float)90)//流量范围
                {
                   ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*temp_value_float + (float)0.989); //15℃：-0.5%~~10℃：-0.7%
                }
                else if(ins_flow_temp_float>(float)90)
                {
                   ins_flow_temp_float = ins_flow_temp_float * ((float)0.001*temp_value_float + (float)0.983);//15℃：-0.2%~~10℃：-0.7%
                } 
            }
            else //10度以下
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.993; 
            }                      
		}
        //流量单独修正
        if((ins_flow_temp_float > (float)90)&&(ins_flow_temp_float <= (float)120))//流量范围
        {
            if((temp_value_float >= (float)15)&&(temp_value_float < (float)22))  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0009*temp_value_float + (float)0.9841); //15℃：-0.3%~~22℃：+0.3%  
            }
            else if((temp_value_float > (float)22)&&(temp_value_float <= (float)32))  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.003;
            }
        }
        		
		#elif DN32_BRASS_63KPA_GP30_32768
		if(temp_value_float > (float)49.01) //温度范围
		{
			if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)43))//流量范围  
            {
               ins_flow_temp_float = ins_flow_temp_float * ((float)0.0005*ins_flow_temp_float + (float)0.9825); //35:0   43:0.4
            }
            if((ins_flow_temp_float >= (float)43)&&(ins_flow_temp_float < (float)70))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
            else if((ins_flow_temp_float >= (float)90)&&(ins_flow_temp_float < (float)120))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
			else if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)160))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.008;  
            }
			else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)230))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.012;  
            }
			else if((ins_flow_temp_float >=(float)230)&&(ins_flow_temp_float < (float)280))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.008;  
            }          
            else if((ins_flow_temp_float >=(float)280)&&(ins_flow_temp_float < (float)300))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00035*ins_flow_temp_float + (float)1.102); //280: 0.4~300:-0.3
            }
            else if((ins_flow_temp_float >=(float)300)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00014*ins_flow_temp_float + (float)0.955);  //300: -0.4~350:0.4
            }
            else if((ins_flow_temp_float >=(float)350)&&(ins_flow_temp_float < (float)600))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.008;  
            }           
			else if((ins_flow_temp_float >= (float)600)&&(ins_flow_temp_float < (float)850))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
        } 
		else if((temp_value_float >= (float)43.67)&&(temp_value_float < (float)49.01))  //温度范围
		{
            if((ins_flow_temp_float >=(float)28)&&(ins_flow_temp_float < (float)43))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >=(float)43)&&(ins_flow_temp_float < (float)70))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00015*ins_flow_temp_float + (float)0.99863);  //43:0.5  70:0.9
            }
            else if((ins_flow_temp_float >=(float)70)&&(ins_flow_temp_float < (float)90))//流量范围
            {
            	ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
            }
			else if((ins_flow_temp_float >=(float)90)&&(ins_flow_temp_float < (float)160))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
			else if((ins_flow_temp_float >=(float)160)&&(ins_flow_temp_float < (float)230))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.008;  
            }
			else if((ins_flow_temp_float >=(float)230)&&(ins_flow_temp_float < (float)280))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
            else if((ins_flow_temp_float >=(float)280)&&(ins_flow_temp_float < (float)300))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00035*ins_flow_temp_float + (float)1.102); //280: 0.4~300:-0.3
            }
            else if((ins_flow_temp_float >=(float)300)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00014*ins_flow_temp_float + (float)0.955);  //300: -0.4~350:0.4
            }
            else if((ins_flow_temp_float >=(float)350)&&(ins_flow_temp_float < (float)850))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
        }
		else if((temp_value_float >= (float)35.71)&&(temp_value_float < (float)43.67))  //温度范围
		{
            if(ins_flow_temp_float < (float)28)//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >=(float)28)&&(ins_flow_temp_float < (float)43))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
            }            
            else if((ins_flow_temp_float >=(float)43)&&(ins_flow_temp_float < (float)70))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float *((float)0.000111*ins_flow_temp_float + (float)1.005222); //43:1.01~ 70:1.013     
            }
            else if((ins_flow_temp_float >=(float)70)&&(ins_flow_temp_float < (float)90))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.01;
            }
			else if((ins_flow_temp_float >=(float)90)&&(ins_flow_temp_float < (float)160))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
			else if((ins_flow_temp_float >=(float)160)&&(ins_flow_temp_float < (float)230))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.008;  
            }
			else if((ins_flow_temp_float >=(float)230)&&(ins_flow_temp_float < (float)280))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
            else if((ins_flow_temp_float >=(float)280)&&(ins_flow_temp_float < (float)300))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0005*ins_flow_temp_float + (float)1.144); //280: 0.4~300:-0.6
            }
            else if((ins_flow_temp_float >=(float)300)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0002*ins_flow_temp_float + (float)0.934);  //300: -0.6~350:0.4   
            }
            else if((ins_flow_temp_float >=(float)350)&&(ins_flow_temp_float < (float)850))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
        }        
		else if((temp_value_float >= (float)29)&&(temp_value_float < (float)35.71))  //温度范围
		{
            if(ins_flow_temp_float < (float)35)//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)43))//流量范围  
            {
               ins_flow_temp_float = ins_flow_temp_float * ((float)0.0005*ins_flow_temp_float + (float)0.9875); //35:0.5   43:0.9  
            }
            else if((ins_flow_temp_float >=(float)43)&&(ins_flow_temp_float < (float)70))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.009;
            }
            else if((ins_flow_temp_float >=(float)70)&&(ins_flow_temp_float < (float)90))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
            }            
            else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
            else if((ins_flow_temp_float >=(float)280)&&(ins_flow_temp_float < (float)300))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00025*ins_flow_temp_float + (float)1.07); //280: 0~300:-0.5
            }
            else if((ins_flow_temp_float >=(float)300)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00014*ins_flow_temp_float + (float)0.953);  //300: -0.5~350:0.2   
            }            
		}        
        else if((temp_value_float >= (float)27.18)&&(temp_value_float < (float)29))  //温度范围
		{
            if(ins_flow_temp_float < (float)90)//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
            else if((ins_flow_temp_float >=(float)280)&&(ins_flow_temp_float < (float)300))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00025*ins_flow_temp_float + (float)1.07); //280: 0~300:-0.5
            }
            else if((ins_flow_temp_float >=(float)300)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00014*ins_flow_temp_float + (float)0.953);  //300: -0.5~350:0.2   
            }            
		}
        else if((temp_value_float >= (float)25)&&(temp_value_float < (float)27.18))  //温度范围
		{
            if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
			else if((ins_flow_temp_float >= (float)2000)&&(ins_flow_temp_float < (float)9500))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
		}
        else if((temp_value_float >= (float)19.6)&&(temp_value_float < (float)25))  //温度范围
		{
            if(ins_flow_temp_float<(float)70)
            {
        	  ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00056*temp_value_float + (float)1.01389 );  //19.6度 0.3   25度 :0  
            }
            else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
			else if((ins_flow_temp_float >= (float)2000)&&(ins_flow_temp_float < (float)9500))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
		}
		else if((temp_value_float >= (float)18.6)&&(temp_value_float < (float)19.6))  //温度范围
		{
            if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
			else if((ins_flow_temp_float >= (float)2000)&&(ins_flow_temp_float < (float)9500))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
		}
		else if((temp_value_float >= (float)13.73)&&(temp_value_float < (float)18.6))  //温度范围
		{
            if(ins_flow_temp_float<(float)25)
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >= (float)25)&&(ins_flow_temp_float < (float)50))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0004*ins_flow_temp_float + (float)1.015);//  25 0.5 50 -0.5
            }
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)110))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)0.995;  
            }
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)160))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * ((float)0.0001*ins_flow_temp_float + (float)0.9840);//0.0001+ 0.9840  110 -0.5 160 0
            }
			else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
			else if((ins_flow_temp_float >= (float)2000)&&(ins_flow_temp_float < (float)9500))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
		}
		else if(temp_value_float < (float)13.73)  //温度范围
		{
            if(ins_flow_temp_float<(float)25)
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else if((ins_flow_temp_float >= (float)25)&&(ins_flow_temp_float < (float)50))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0006*ins_flow_temp_float + (float)1.02);//  25 0.5 50 -1  
            }
			else if((ins_flow_temp_float >= (float)50)&&(ins_flow_temp_float < (float)110))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)0.99;  
            }
			else if((ins_flow_temp_float >= (float)110)&&(ins_flow_temp_float < (float)160))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * ((float)0.0002*ins_flow_temp_float + (float)0.968);//  110 -1 160 0
            }
			else if((ins_flow_temp_float >= (float)160)&&(ins_flow_temp_float < (float)260))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }            
			else if((ins_flow_temp_float >= (float)2000)&&(ins_flow_temp_float < (float)9500))//流量范围
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
		}
		//以流量修正 保留原始校准点修正
        if((ins_flow_temp_float >= (float)33)&&(ins_flow_temp_float < (float)75))//流量范围
        {
            if((temp_value_float >= (float)22)&&(temp_value_float < (float)33))  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.005; 
            }
		}
		else if((ins_flow_temp_float >= (float)400)&&(ins_flow_temp_float < (float)600))//流量范围
		{
			if(temp_value_float >= (float)22)  //温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
            }
        }
		#elif BM_DN32_BRASS_63KPA_GP30_32768 	
        if(temp_value_float < (float)15) //温度范围
		{
            if(ins_flow_temp_float < (float)55)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.003;  
            }
        }		
		#elif PF_DN32_BRASS_63KPA_GP30_32768 
            
            //流量修正
            if((ins_flow_temp_float > (float)33)&&(ins_flow_temp_float <= (float)75))//流量范围
            {
              	if(temp_value_float < (float)15) //温度范围
                {           
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
                }
                else if((temp_value_float >= (float)15)&&(temp_value_float < (float)22))  //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * ((float)0.0011*temp_value_float + (float)0.9779); //15℃：-0.5%~~22℃：+0.3%   
                }
                else if((temp_value_float >= (float)22)&&(temp_value_float < (float)33))  //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)1.005; 
                }
                else if(temp_value_float >= (float)33) //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)1.01; 
                }
            }
            else if((ins_flow_temp_float >= (float)78)&&(ins_flow_temp_float < (float)170))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.993; 
            }
            else if((ins_flow_temp_float >= (float)170)&&(ins_flow_temp_float < (float)400))//流量范围
            {
                if(temp_value_float >= (float)33) //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.99; 
                }
                else 
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.993; 
                }
            }           
            else if((ins_flow_temp_float >= (float)400)&&(ins_flow_temp_float <= (float)600))//流量范围
            {
                if(temp_value_float < (float)15) //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.997; 
                }
                else if((temp_value_float >= (float)15)&&(temp_value_float < (float)22))  //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*temp_value_float + (float)0.9906); //15℃：-0.3%~~22℃：+0%   
                }
                else  if(temp_value_float > (float)22) //温度范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.997; 
                }
            }            
            else if((ins_flow_temp_float >= (float)600)&&(ins_flow_temp_float <= (float)3100))//流量范围
            {
            	if(temp_value_float < (float)17) //温度范围
				{
					ins_flow_temp_float = ins_flow_temp_float * (float)0.992; 
				}
				else 
				{
					ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
				}				
            }
            //温度单独修正 2022- 03 -21
            if(temp_value_float < (float)15) //温度范围
            {                           
                if(ins_flow_temp_float <= (float)43)//流量范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)1.005;
                }
                else if((ins_flow_temp_float > (float)43)&&(ins_flow_temp_float <= (float)50))//流量范围
                {
                    ins_flow_temp_float = ins_flow_temp_float *((float)-0.00114* ins_flow_temp_float + (float)1.05414);  //43 :0.5   50:-0.3 
                }
                else if((ins_flow_temp_float > (float)50)&&(ins_flow_temp_float <= (float)75))//流量范围
                {
                    ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
                }
            }                       
		#elif DN40_BRASS_63KPA_GP30_32768
        if(temp_value_float < (float)11.98)//温度范围
        {
            if(ins_flow_temp_float < (float)35)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else  if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)60))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00012*ins_flow_temp_float + (float)1.0092);//35:+0.5% ~ 60:+0.2  -0.00012x + 1.0092 
            }
            else  if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)70))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0006*ins_flow_temp_float + (float)1.038);//60:+0.2% ~ 70:-0.4%  
            }
            else  if((ins_flow_temp_float >= (float)70)&&(ins_flow_temp_float < (float)85))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.996; 
            }
            else if(ins_flow_temp_float >= (float)600)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
        }
        else if(temp_value_float < (float)16.5)//温度范围
        {
            if(ins_flow_temp_float < (float)35)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            else  if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)60))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00012*ins_flow_temp_float + (float)1.0092);//35:+0.5% ~ 60:+0.2  -0.00012x + 1.0092 
            }
            else  if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)70))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0006*ins_flow_temp_float + (float)1.038);//60:+0.2% ~ 70:-0.4%  
            }
            else  if((ins_flow_temp_float >= (float)70)&&(ins_flow_temp_float < (float)85))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.992; 
            }
			else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)120))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.996; 
            }			   
            else  if((ins_flow_temp_float >= (float)200)&&(ins_flow_temp_float < (float)320))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.004; 
            }
            else  if((ins_flow_temp_float >= (float)320)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.000133*ins_flow_temp_float + (float)1.046667);//320:+0.4% ~ 350:+0    
            }
            else if(ins_flow_temp_float >= (float)600)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }
        }
        else if(temp_value_float < (float)20.54)//温度范围
        {
            if(ins_flow_temp_float < (float)60)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.004;  
            }			
            else  if((ins_flow_temp_float >= (float)70)&&(ins_flow_temp_float < (float)85))//流量范围   
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.997; //75:+0% ~ 85:+0.5  
            }
			else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)120))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.003*temp_value_float + (float)0.947); //16.5 -0.4  20.54 +0.8  0.003x + 0.947 温度曲线
            }
			else  if((ins_flow_temp_float >= (float)120)&&(ins_flow_temp_float < (float)200))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.001*temp_value_float + (float)0.9837); //16.5 0  20.54 +0.4 0.001x + 0.9837  温度曲线
            }			
            else  if((ins_flow_temp_float >= (float)200)&&(ins_flow_temp_float < (float)320))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.004; 
            }
            else  if((ins_flow_temp_float >= (float)320)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.000267*ins_flow_temp_float + (float)1.093333);//320:+0.8% ~ 350:+0    
            }
        }
        else if(temp_value_float < (float)27.5)//温度范围
        {
            if((ins_flow_temp_float >= (float)75)&&(ins_flow_temp_float < (float)85))//流量范围   
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0003*ins_flow_temp_float + (float)0.9775);//75:0% ~ 85:+0.3   0.0003 x + 0.9775 
            }
            else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)280))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.008; 
            }
            else  if((ins_flow_temp_float >= (float)280)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.000071*ins_flow_temp_float + (float)1.025);//280:+0.5% ~ 350:+0    
            }
        }
        else if(temp_value_float < (float)33.56)//温度范围
        {
            if(ins_flow_temp_float<(float)60)
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0015*temp_value_float + (float)0.9577);  //27.5度 0   33.56度 :0.9
            }
            else if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)70))//流量范围   
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*ins_flow_temp_float + (float)0.98);//60:+0.4% ~ 70:+0.8   
            }
            else  if((ins_flow_temp_float >= (float)70)&&(ins_flow_temp_float < (float)85))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0002*ins_flow_temp_float + (float)0.991);//70:+0.5% ~ 85:+0.8    
            }
            else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)280))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.012; 
            }
            else  if((ins_flow_temp_float >= (float)280)&&(ins_flow_temp_float < (float)320))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.008; 
            }
            else  if((ins_flow_temp_float >= (float)320)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.00020*ins_flow_temp_float + (float)1.07);//320:+0.6% ~ 350:+0   -0.00020 x + 1.07000  
            }
        }
       else if(temp_value_float < (float)39.62)//温度范围
        {
            if(ins_flow_temp_float<(float)60)
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.009;  
            }
            else if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)70))//流量范围   
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0004*ins_flow_temp_float + (float)0.98);//60:+0.4% ~ 70:+0.8   
            }
            else  if((ins_flow_temp_float >= (float)70)&&(ins_flow_temp_float < (float)85))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0003*ins_flow_temp_float + (float)0.9893);//70:+0.8% ~ 85:+1.2    
            }
            else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)280))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.012; 
            }
            else  if((ins_flow_temp_float >= (float)280)&&(ins_flow_temp_float < (float)320))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.008; 
            }
            else  if((ins_flow_temp_float >= (float)320)&&(ins_flow_temp_float < (float)350))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.000267*ins_flow_temp_float + (float)1.093333);//320:+0.8% ~ 350:+0    
            }
        }
        else if(temp_value_float < (float)43.67)//温度范围
        {
            if(ins_flow_temp_float < (float)60)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.009;  
            }
            else  if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)85))//流量范围  
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0002*ins_flow_temp_float + (float)0.995); //60:0.7% ~ 85:1.2  0.00020 x + 0.99500   
            }
            else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)220))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.012; 
            }
            else  if((ins_flow_temp_float >= (float)220)&&(ins_flow_temp_float < (float)280))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.007; 
            }
            else  if((ins_flow_temp_float >= (float)280)&&(ins_flow_temp_float < (float)320))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0006*temp_value_float + (float)1.0284); //39度 0.5  44度:0.2  -0.00060 x + 1.02840 
            }            
            else  if((ins_flow_temp_float >= (float)320)&&(ins_flow_temp_float < (float)350))//流量范围  
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.000167*ins_flow_temp_float + (float)1.055333);//320:+0.2% ~ 350:-0.3      
            }
            else if(ins_flow_temp_float > (float)350)
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)0.997;  
            }
        }
        else if(temp_value_float >= (float)43.67)//温度范围
        {
            if(ins_flow_temp_float < (float)35)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)1.005;  
            }
            if((ins_flow_temp_float >= (float)35)&&(ins_flow_temp_float < (float)60))//流量范围   
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0002*ins_flow_temp_float + (float)0.9994);//35:0% ~ 60:0.6%      ---> 35:0.5% ~ 60:0.9%  
            }
            else  if((ins_flow_temp_float >= (float)60)&&(ins_flow_temp_float < (float)85))//流量范围    
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.00036*ins_flow_temp_float + (float)0.9844);//60:0.6% ~ 85:1.5   
            }
            else  if((ins_flow_temp_float >= (float)85)&&(ins_flow_temp_float < (float)220))//流量范围
            {
                ins_flow_temp_float = ins_flow_temp_float * (float)1.015; 
            }
            else  if((ins_flow_temp_float >= (float)220)&&(ins_flow_temp_float < (float)320))//流量范围  
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0001*ins_flow_temp_float + (float)1.032);//220:+1% ~ 320:+0    
            }
        }        
        #elif 	BM_DN40_BRASS_63KPA_GP30_32768    
        if(temp_value_float > (float)35) //温度范围
		{
            if(ins_flow_temp_float < (float)80)
            {
              ins_flow_temp_float = ins_flow_temp_float * (float)0.997;  
            }
        }
		if((ins_flow_temp_float > (float)110)&&(ins_flow_temp_float <= (float)180))//流量范围
		{
			ins_flow_temp_float = ins_flow_temp_float * ((float)0.00001648*ins_flow_temp_float*ins_flow_temp_float - (float)0.00475923*ins_flow_temp_float + (float)1.32378501);
			
			if(ins_flow_temp_float <= (float)160)
			{
				if((temp_value_float < (float)31)&&(temp_value_float >= (float)10))//温度范围
				{
					ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0000241*temp_value_float*temp_value_float + (float)0.0003506*temp_value_float + (float)1.0147);
				}
				else if(temp_value_float < (float)10) //温度范围
				{
					ins_flow_temp_float = ins_flow_temp_float * (float)1.015;
				}
			}
		}
		else if((ins_flow_temp_float > (float)180)&&(ins_flow_temp_float < (float)1100))//流量范围
		{
			if(temp_value_float > (float)15) //温度范围
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.995;
			}
			else
			{
				ins_flow_temp_float = ins_flow_temp_float * (float)0.987;
			}
		}
        #elif   PF_DN40_BRASS_63KPA_GP30_32768        
        if((ins_flow_temp_float > (float)57)&&(ins_flow_temp_float <= (float)90))//流量范围
        {
            if(temp_value_float <= (float)15) //温度范围
            {           
                ins_flow_temp_float = ins_flow_temp_float * (float)0.995; 
            }
            else if(temp_value_float > (float)35) //温度范围
            {           
                ins_flow_temp_float = ins_flow_temp_float * (float)0.996; 
            }
        }
        else if((ins_flow_temp_float >= (float)95)&&(ins_flow_temp_float <= (float)130))//流量范围
        {
            if(temp_value_float < (float)32) //温度范围
            {           
                ins_flow_temp_float = ins_flow_temp_float * (float)1.006; 
            }
            else  
            {           
                ins_flow_temp_float = ins_flow_temp_float * (float)1.012; 
            }
        }
        else if((ins_flow_temp_float >= (float)260)&&(ins_flow_temp_float <= (float)350))//流量范围
        {
            ins_flow_temp_float = ins_flow_temp_float * (float)0.997;
        }       
        else if((ins_flow_temp_float >= (float)700)&&(ins_flow_temp_float <= (float)1800))//流量范围
        {
            if((temp_value_float >= (float)15)&&(temp_value_float < (float)22))//温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)-0.0008*temp_value_float + (float)1.0125); //15℃：0%~~22℃：-0.5%  
            }
            else if((temp_value_float >= (float)22)&&(temp_value_float < (float)25))//温度范围
            {
                ins_flow_temp_float = ins_flow_temp_float * ((float)0.0012*temp_value_float + (float)0.9688); //22℃：-0.5%~~25℃：+0%  
            }
        }
		#endif
		ins_flow_temp_float=modify_flow(ins_flow_temp_float);
    }

    if(ins_flow_temp_float > LIMIT_FLOW_1_5Q4)  //以过载流量的1.5倍作为截止，并且超过后不再清零，2019-4-20 3.125*1.5=4.68
    {
        ins_flow_temp_float = LIMIT_FLOW_1_5Q4;
    }

    return ins_flow_temp_float;
}

/*ZCC 和 nB 上报防护  2022-7-21 15:38:06*/

float ZCC_NB_judge(float interval_value , u8 ins_flow_flag, float ins_flow)
{
	float temp_value;
	//每次赋值都给数组第三个元素赋值，滑动移动数组元素
	ZCC_NB_buf[0]=ZCC_NB_buf[1];
	ZCC_NB_buf[1]=ZCC_NB_buf[2];
	ZCC_NB_buf[2]=interval_value;
	ZCC_direction_flow_flag[0]=ZCC_direction_flow_flag[1];
	ZCC_direction_flow_flag[1]=ZCC_direction_flow_flag[2];
	ZCC_direction_flow_flag[2]=ins_flow_flag;
	
	ZCC_ins_flow[0]=ZCC_ins_flow[1];
	ZCC_ins_flow[1]=ZCC_ins_flow[2];
	ZCC_ins_flow[2]=ins_flow;
	
	if(FixedTimeNbIoTUploadIfIdle() == TASK_IDLE)//NB上报期间才考虑
	{
		return 0;
	}
	
	if((0 == ZCC_ins_flow[0]) && (0 == ZCC_ins_flow[2]))//第一种情况，静水
	{
		if( GP22_APP_DIFTOF_NEGT == ZCC_direction_flow_flag[1] )//如果中间值是负数，则不补偿
		{
			return 0;	
		}
		else
		{
			return (0 - ZCC_NB_buf[1]);
		}
	}
	else  //第2种情况，跑水
	{
		if(ZCC_ins_flow[0] >= ZCC_ins_flow[2])
		{
			temp_value = ZCC_ins_flow[0] - ZCC_ins_flow[2];
		}
		else
		{
			temp_value = ZCC_ins_flow[2] - ZCC_ins_flow[0];
		}
		if(temp_value < (ZCC_ins_flow[0] * 0.1)) //第一个数和第三个数相差很小
		{	
			if(( GP22_APP_DIFTOF_NEGT == ZCC_direction_flow_flag[1] )&&( GP22_APP_DIFTOF_POST == ZCC_direction_flow_flag[0] )&&( GP22_APP_DIFTOF_POST == ZCC_direction_flow_flag[2] ))
			{
				ZCC_direction_flow_flag[1] =GP22_APP_DIFTOF_POST;//如果中间值是负数，则使用上次数，同时把异常数更新为正常数据
				ZCC_NB_buf[1]= ZCC_NB_buf[0];
				return ZCC_NB_buf[0];
			}		
			else if(((ZCC_ins_flow[1] - ZCC_ins_flow[0]) > 0.4 * ZCC_ins_flow[0]) || ((ZCC_ins_flow[0] - ZCC_ins_flow[1]) > 0.4 * ZCC_ins_flow[0]))  //判断中间数，与第一个数差别
			{
				return (ZCC_NB_buf[0] - ZCC_NB_buf[1]); //返回补偿值
			}
		}
	}
	return 0;
}
				
/****************************************************************
Function:    void Gp22FilterCalculate (u8 temp_flag)
Description:  GP22 滤波和计算 函数
Input:   温度是否采集 标志
Return:
Others: 读取温度接口参数: 0流量时间差、1进口温度时间、2出口温度时间 3标准电阻时间
 *****************************************************************/
void Gp22FilterCalculate(u8 temp_flag)
{
    u32 temp_value;
    u8 i;
    float temp_total_flow_float = 0, temp_ins_flow_float= 0, temp_value_float = 0;
    
	 gp30_app_start_flow_filter=FrameCheckParaApp(FramePara_StartFlow);//此处需要记录下初值给GP30
//     gp22_app_start_flow_reverse =0x80000000|gp30_app_start_flow_filter; 
     gp30_app_start_flow_filter_float=Gp30DataToFloat(gp30_app_start_flow_filter);
	 gp30_app_start_flow_reverse_float=0-gp30_app_start_flow_filter_float;
//	 s_gengxin_statebyte_msg = TRUE;

        //时间差滤波
    for (i = 0; i < GP22_APP_QUEUE_SIZE; i++)
    {           
        if ( s_g_flow_data[i] >= 0x80000000) //负数
        {
            s_g_flow_data[i] &= 0x7FFFFFFF;
            s_g_temp_float_flow_data[i] = 0 - Gp30DataToFloat( s_g_flow_data[i]);
            s_g_flow_data[i] |= 0x80000000;
        }
        else
        {
            s_g_temp_float_flow_data[i] = Gp30DataToFloat(s_g_flow_data[i]);
        }	
    }
    /* 更新当前数据gp22_app_data。（检定状态下同时更新检定数据gp22_test_data）*/
    if (10 == LcdCheckStateApp()) //非检定状态
    {
//        if (GP22_APP_FLOW_TEMP == temp_flag) //同时温度+流量时,才计算一次
//        {
			s_g_sample_flag = 0;
        
			temp_value_float = FilterJunZhi_TestForGp30_float(&s_g_temp_float_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波

//			if(start_flow_sum >= GP22_APP_EXCEED_START_FLOW_SUM)  //低于始动流量的时间差大于一半次数
//			{
//				temp_value_float = 0;
//			}
//			else
//			{
				//temp_value = FlowFilter(&s_g_temp_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波 开关阀
            	//temp_value =  Gp22TimeDiffer(GP22_APP_FLOW_DIFFER); //不 滤波
			//temp_value_float = FilterJunZhi_TestForGp30_float(&s_g_temp_float_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波
			calibration_diftof_value = temp_value_float;//用于记录非检定下时间差，便于零流量自校准。
//			}
			if(temp_value_float <0)
			{
				ins_flow_flag = GP22_APP_DIFTOF_NEGT;//滤波时间差为负的标志
                
				temp_value_float = 0 - temp_value_float;
			}
			else
			{
                
				ins_flow_flag = GP22_APP_DIFTOF_POST;//滤波时间差为正的标志
			}
			temp_value = FloatToGp30Data(temp_value_float);
            //瞬时流量计算
			temp_ins_flow_float = Gp22FlowCalculate(temp_value);
            gp22_test_data.s.ins_flow = FloatToGp30Data(temp_ins_flow_float);
            gp22_app_data.s.ins_flow = gp22_test_data.s.ins_flow;
            Gp22EventCheckApp(gp22_test_data.s.ins_flow);  //事件记录的检测与清除
			
			if(TRUE == gp30_event_flag.reverse_flow)
            {
//                gp22_app_data.s.ins_flow = 0;
				reverse_flow_sum++;
				if(reverse_flow_sum >= 240)////原来是10次20s，240次八分钟reverse_flow_sum是u8类型
				{
					reverse_flow_sum = 0;
//					Gp22AppSetGp22Err();
				}
            }
			else
			{
				reverse_flow_sum = 0;
			}

            if(gp22_app_data.s.ins_flow != 0)
            {
                gp22CheckErrEventApp(GP30_no_water_DE);  // 1/4 DE
				gp22CheckErrEventApp(GP30_TOF_overrun_DE); 
            }

           
//			temp_ins_flow_float = temp_ins_flow_float * (float)Compensate_Coefficient_For_Normal;//所有表计类型非鉴定下流量补偿 2020-12-30
             //机械台子修正
			temp_ins_flow_float = ModifyForVolumeTestbench(temp_ins_flow_float);
			Gp22FlowDetect(temp_ins_flow_float);	
			
				
			if(0 != temp_ins_flow_float) //瞬时流量不为零再计算累积流量
			{
				
//				total_flow_change_flag = 1;
//              //非检定状态  放大100倍
                {
                    //根据不同的采样间隔计算累积流量
//					temp_total_flow_float = temp_ins_flow_float * (float)((GP22_APP_SAMPLE_SIZE / 2) * s_g_gp22_sample_span) ;
					if(FALSE == s_gp22_cal_interval_msg) //LPTIMER时间轴
					{
						temp_total_flow_float = temp_ins_flow_float * ((float)intval_time/(float)128);//256分频，0x80代表1s
					}
					else
					{
						temp_ins_flow_float = temp_ins_flow_float*(float)0.997;//仅在上报期间修正原始流速 
                        temp_total_flow_float = temp_ins_flow_float * (float)intval_time / (float)1000000;
					}

                    temp_total_flow_float = temp_total_flow_float * (float)100 / (float)3600;
                    
                    temp_total_flow_float = temp_total_flow_float / (float)1000.0;   //lifangmi
                }
				if(GP22_APP_DIFTOF_POST == ins_flow_flag)
				{
					// 流量累加时，浮点数精度问题，当浮点数增大时，调整累加的单位
//					if(gp22_app_data.s.total_flow.gp30_float > 99999000)
//					{
//						globle_total_flow_float = globle_total_flow_float + temp_total_flow_float;
//						if(globle_total_flow_float > 100)
//						{
//							globle_total_flow_float = globle_total_flow_float - 100;
//							gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + 100;
//						}
//					}
//					else if(gp22_app_data.s.total_flow.gp30_float > 9999990)
//					{
//						globle_total_flow_float = globle_total_flow_float + temp_total_flow_float;
//						if(globle_total_flow_float > 10)
//						{
//							globle_total_flow_float = globle_total_flow_float - 10;
//							gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + 10;
//						}
//					}
//					else if(gp22_app_data.s.total_flow.gp30_float > 999990)
//					{
//						globle_total_flow_float = globle_total_flow_float + temp_total_flow_float;
//						if(globle_total_flow_float > 1)
//						{
//							globle_total_flow_float = globle_total_flow_float - 1;
//							gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + 1;
//						}
//					}
//					else
//					{
//						 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + temp_total_flow_float;
//					}
                    duoble_total_flow.gp30_double += (double)temp_total_flow_float;  
//                    gp22_app_data.s.total_flow.gp30_float = (float) duoble_total_flow.gp30_double;
//					gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//2017 02,更改复位不丢数
//					gp22_copy_temp_total_flow_float = temp_total_flow_float;//保存复位不初始化 通过不同的采样间隔计算的累积流量
				}
				else
				{
					if(0x00004D3C==FrameCheckParaApp(FramePara_CCFlow))  //方式1
					{
						//gp22_app_data.s.cur_total_flow.gp30_float=0;
						//gp22_copy_cur_total_flow=0;
						// 流量累加时，浮点数精度问题，当浮点数增大时，调整累加的单位
//						if(gp22_app_data.s.total_flow.gp30_float > 99999000)
//						{
//							globle_total_flow_float = globle_total_flow_float - temp_total_flow_float;
//							if(globle_total_flow_float < -100)
//							{
//								globle_total_flow_float = globle_total_flow_float + 100;
//								gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - 100;
//							}
//						}
//						else if(gp22_app_data.s.total_flow.gp30_float > 9999990)
//						{
//							globle_total_flow_float = globle_total_flow_float - temp_total_flow_float;
//							if(globle_total_flow_float < -10)
//							{
//								globle_total_flow_float = globle_total_flow_float + 10;
//								gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - 10;
//							}
//						}
//						else if(gp22_app_data.s.total_flow.gp30_float > 999990)
//						{
//							globle_total_flow_float = globle_total_flow_float - temp_total_flow_float;
//							if(globle_total_flow_float < -1)
//							{
//								globle_total_flow_float = globle_total_flow_float + 1;
//								gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - 1;
//							}
//						}
//						else
//						{
//							if(gp22_app_data.s.total_flow.gp30_float <= temp_total_flow_float)
//							{
//								gp22_app_data.s.total_flow.gp30_float = 0;
//							}
//							else
//							{
//								gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float - temp_total_flow_float;
//							}
//						}

						if(duoble_total_flow.gp30_double <= temp_total_flow_float)
						{
							duoble_total_flow.gp30_double = 0;
						}
						else
						{
							duoble_total_flow.gp30_double = duoble_total_flow.gp30_double - temp_total_flow_float;                            
						}
                        gp22_app_data.s.total_flow.gp30_float = (float)duoble_total_flow.gp30_double; 
						gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//2017 02,更改复位不丢数
					}
										
						// 流量累加时，浮点数精度问题，当浮点数增大时，调整累加的单位
						if(gp22_app_data.s.total_flow_reverse.gp30_float > 99999000)
						{
							globle_cur_total_flow_float = globle_cur_total_flow_float + temp_total_flow_float;
							if(globle_cur_total_flow_float > 100)
							{
								globle_cur_total_flow_float = globle_cur_total_flow_float - 100;
								gp22_app_data.s.total_flow_reverse.gp30_float = gp22_app_data.s.total_flow_reverse.gp30_float + 100;
							}
						}
						else if(gp22_app_data.s.total_flow_reverse.gp30_float > 9999990)
						{
							globle_cur_total_flow_float = globle_cur_total_flow_float + temp_total_flow_float;
							if(globle_cur_total_flow_float > 10)
							{
								globle_cur_total_flow_float = globle_cur_total_flow_float - 10;
								gp22_app_data.s.total_flow_reverse.gp30_float = gp22_app_data.s.total_flow_reverse.gp30_float + 10;
							}
						}
						else if(gp22_app_data.s.total_flow_reverse.gp30_float > 999990)
						{
							globle_cur_total_flow_float = globle_cur_total_flow_float + temp_total_flow_float;
							if(globle_cur_total_flow_float > 1)
							{
								globle_cur_total_flow_float = globle_cur_total_flow_float - 1;
								gp22_app_data.s.total_flow_reverse.gp30_float = gp22_app_data.s.total_flow_reverse.gp30_float + 1;
							}
						}
						else
						{
							gp22_app_data.s.total_flow_reverse.gp30_float = gp22_app_data.s.total_flow_reverse.gp30_float + temp_total_flow_float;
						}
						gp22_copy_total_flow_reverse = gp22_app_data.s.total_flow_reverse.gp30_float;//2017 02,更改复位不丢数					
                    }                
            }
			else
            {
//                gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//复位不丢数 
                gp22_copy_total_flow_reverse = gp22_app_data.s.total_flow_reverse.gp30_float;//2021 01,更改复位不丢数
//                gp22_copy_temp_total_flow_float = 0;
            }
			/*ZCC 和 nB 上报防护  2022-7-21 15:38:06*/
			float correct_value = ZCC_NB_judge(temp_total_flow_float,ins_flow_flag,temp_ins_flow_float);
			if((correct_value > 2) || (correct_value < -2))//合法性判断
			{
				correct_value = 0;
			}
			duoble_total_flow.gp30_double += correct_value;
			gp22_app_data.s.total_flow.gp30_float = (float) duoble_total_flow.gp30_double;
			gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//2017 02,更改复位不丢数
			gp22_copy_temp_total_flow_float = temp_total_flow_float;//保存复位不初始化 通过不同的采样间隔计算的累积流量
			/*ZCC 和 nB 上报防护  2022-7-21 15:38:06*/
			MCU_reset_judge = MCU_RESET_JUDGE_FLAG;  //只有在赋值累计流量后，再置起来完全上电成功
            //每次计算流量后,判断是否需要更新采样间隔,2016-7-21
//            Gp22SampleChange();  //非检定状态下才需要检测
//        }
    }
    else  //检定状态，每次采样都计算，2016-10-24 
    {         
        if(TRUE == s_g_diftof_for_total)
        {
            s_g_diftof_for_total = FALSE;
            start_temp_sample();//反算温度和常规温度都可以通过这个函数实现采集
        }
                
        //累计流量计算，2016-10-26
        //时间差滤波,用灵敏度高的
//        for (i = 0; i < GP22_APP_QUEUE_SIZE; i++)
//        {
//			if ( s_g_flow_data[i] >= 0x80000000) //负数
//			{
//				s_g_flow_data[i] &= 0x7FFFFFFF;
//				s_g_temp_float_flow_data[i] = 0 - Gp30DataToFloat( s_g_flow_data[i]);
//				s_g_flow_data[i] |= 0x80000000;
//			}
//			else
//			{
//				s_g_temp_float_flow_data[i] = Gp30DataToFloat(s_g_flow_data[i]);
//			}
			
//			if(s_g_temp_flow_data[i] >= 0x80000000)
//			{
//				s_g_temp_flow_data[i] = 0;
//			}
//			if(s_g_temp_flow_data[i] < gp30_app_start_flow_filter)
//			{
//				start_flow_sum ++;
//				if(start_flow_sum > GP22_APP_EXCEED_START_FLOW_SUM_VERIFICATION)
//				{
//					break;
//				}
//			}
//        }
		
//		if(start_flow_sum > GP22_APP_EXCEED_START_FLOW_SUM_VERIFICATION)  //低于始动流量的时间差大于一半次数
//		{
//			temp_value = 0;
//		}
//		else
//		{
//		temp_value = FilterJunZhi_TestForGp30(&s_g_temp_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波，适配累计量校准的瞬时速度计算
	//		temp_value = FilterJunZhi(&s_g_temp_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波，适配累计量校准的瞬时速度计算
        //temp_value_float = FilterJunZhi_TestForGp30_float(&s_g_temp_float_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波

		temp_value_float = FilterJunZhi_TestForGp30_float(&s_g_temp_float_flow_data[0], GP22_APP_QUEUE_SIZE); //滤波
		calibration_diftof_value = temp_value_float;//用于记录检定下时间差，便于零流量自校准。
//		}
		//GP30_filter_last_value = temp_value;
		if(temp_value_float<0)
		{
			temp_value_float=0;
		}
		temp_value = FloatToGp30Data(temp_value_float);
        temp_ins_flow_float = Gp22FlowCalculate(temp_value);
        s_g_sample_sum_lcd = FloatToGp30Data(temp_ins_flow_float);
		
		if(TRUE == gp30_event_flag.reverse_flow)
        {
//            temp_ins_flow_float = 0;
//            gp22_test_data.s.ins_flow = 0;
//            gp22_app_data.s.ins_flow = gp22_test_data.s.ins_flow; 
        	reverse_flow_sum++;
			if(reverse_flow_sum >= 15)  
			{
				reverse_flow_sum = 0;
//				Gp22AppSetGp22Err();
			}
        }
		else
		{
			reverse_flow_sum = 0;
		}
		
	    //机械台子修正
		temp_ins_flow_float = ModifyForVolumeTestbench(temp_ins_flow_float);
        DiftofForTestbench(temp_ins_flow_float);//针对称重台子进行瞬时流量计算均值 
        Gp22FlowDetect(temp_ins_flow_float);
        
        if(0 != temp_ins_flow_float) //瞬时流量不为零再计算累积流量
        {
            gp22CheckErrEventApp(GP30_no_water_DE);  // 1/4 DE
			gp22CheckErrEventApp(GP30_TOF_overrun_DE); 

//			temp_total_flow_float = temp_ins_flow_float * (float)1.73611;
            temp_total_flow_float = temp_ins_flow_float * ((float)intval_time/(float)128)/(float)36;//256分频，0x80代表1s;  
            gp22_test_data.s.total_flow.gp30_float += temp_total_flow_float;
            duoble_total_flow.gp30_double += temp_total_flow_float/(float)1000;
			gp22_app_data.s.total_flow.gp30_float = (float)duoble_total_flow.gp30_double;
			gp22_copy_total_flow_test=gp22_test_data.s.total_flow.gp30_float;
			gp22_copy_temp_total_flow_float_test=temp_total_flow_float;
			
            gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//复位不丢数 
//            globle_total_flow_float_jian += temp_total_flow_float;


//            time =  125 * 65536 / 2;  //62.5ms的，后续测试完成,考虑把这个值直接算出来 ,2016-8-2
//            temp_total_flow = MulGp30Data(GP22_APP_TOTAL_FLOW_PARA_JIAN, temp_value_total_shunshi);
//            temp_total_flow = MulGp30Data(temp_total_flow , time);
//
//            temp_total_flow_float = Gp30DataToFloat(temp_total_flow);
//            temp_total_flow_u32 += (u32)(temp_total_flow_float*1000.0); //4294967295
//            if(temp_total_flow_u32 > 100000000)
//            {
//                temp_total_flow_u32 -= 100000000;
//                temp_total_flow_u32_1 ++;0
//
//            }
////            temp_total_flow_float = temp_total_flow_float/1000.0;
//            gp22_test_data.total_flow.gp30_float = (float)temp_total_flow_u32_1*100  + ((float)(temp_total_flow_u32))/1000000.0;

//            gp22_app_data.total_flow.gp30_float += temp_total_flow_float/1000000;

        }
		else
		{
			gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//复位不丢数 
			gp22_copy_total_flow_reverse = gp22_app_data.s.total_flow_reverse.gp30_float;//2021 01,更改复位不丢数
			gp22_copy_temp_total_flow_float_test = 0;
		}
		MCU_reset_judge = MCU_RESET_JUDGE_FLAG;  //只有在赋值累计流量后，再置起来完全上电成功
    }
}
/****************************************************************
Function:    void gp22CheckErrEventApp (u8 err_event)
Description:  检测异常事件
Input:
Return:
Others:

//                   //Bit0：当前流量>Q4或者<Q1、
//                //Bit1：水温超出温度等级范围
//                //Bit2 ：GP30信号超时（无水）
//                //Bit3 ：GP30故障
//                //Bit4：表装反
//                //Bit5：低流量报警
//                //Bit6：换能器老化
Bit0:当前流量>Q4或者<Q1    GP30_low_high_flow
Bit1:水温超出温度等级范围  GP30_out_temp
Bit2:倒转           GP30_reverse_flow
Bit3:无水           GP30_no_water
Bit4:GP30异常		GP30_err
Bit5:低流量报警     GP30_low_flow
Bit6:换能器接受信号低（低振幅）	GP30_low_amp;
Bit7:GP30通信异常  GP30_communication_err
Bit8:TOF overrun   GP30_TOF_overrun

 *****************************************************************/
void gp22CheckErrEventApp (u8 err_event)
{
    u8 sum_res = 0;
    static u8 sum_reverse_clear = 0;
	static u8 sum_no_water_clear = 0;
	static u8 sum_water_diredtion_clear = 0;
	static u8 sum_low_amp_clear = 0;
    
    if(10 == LcdCheckStateApp())  //NORMAL
    {
        sum_res = GP30_APP_EVENT_SUM_NORMAL;
    }
    else
    {
        sum_res = GP30_APP_EVENT_SUM_TEST;
    }
    switch (err_event)
    {
    case GP30_communication_err:
        gp30_event.communication_err++;
        if(gp30_event.communication_err > sum_res)
        {
            gp30_event_flag.communication_err = TRUE;
            gp30_event_save_flag.communication_err = TRUE;
        }
        break;
    case GP30_no_water:
        gp30_event.no_water++;
        if(gp30_event.no_water > sum_res)
        {
			sum_no_water_clear=0;
            gp30_event_flag.no_water = TRUE;
            gp30_event_save_flag.no_water = TRUE;
        }
        break;
    case GP30_low_flow:
       gp30_event.low_flow++;
       if(gp30_event.low_flow > sum_res)
        {
            gp30_event_flag.low_flow = TRUE;
            gp30_event_save_flag.low_flow = TRUE;
        }
       break;
    case GP30_out_temp:
       gp30_event.out_temp++;
       if(gp30_event.out_temp > sum_res)
        {
            gp30_event_flag.out_temp = TRUE;
            gp30_event_save_flag.out_temp = TRUE;
        }
       break;
   case GP30_low_high_flow:
       gp30_event.low_high_flow++;
       if(gp30_event.low_high_flow > sum_res)
        {
            gp30_event_flag.low_high_flow = TRUE;
            gp30_event_save_flag.low_high_flow = TRUE;
        }
       break;
   case GP30_reverse_flow:
//       gp30_event.reverse_flow++;
//       sum_reverse_clear = 0;
//       if(gp30_event.reverse_flow > (sum_res+sum_res))
//        {
//            gp30_event_flag.reverse_flow = TRUE;
//            gp30_event_save_flag.reverse_flow = TRUE;
//        }
		
       gp30_event.reverse_flow++;
       if(gp30_event.reverse_flow > (sum_res+sum_res))
        {
			sum_reverse_clear = 0;
			gp30_event.reverse_flow = 0;
            gp30_event_flag.reverse_flow = TRUE;
            gp30_event_save_flag.reverse_flow = TRUE;
        }
		
       break;

	case GP30_TOF_overrun:
        gp30_event.tof_overrun++;
		if(gp30_event.tof_overrun > sum_res)
        {
            gp30_event_flag.tof_overrun = TRUE;
            gp30_event_save_flag.tof_overrun = TRUE;
        }
		break;
	case GP30_low_amp:	
        gp30_event.low_amp++;
		if(gp30_event.low_amp > sum_res)
        {
			sum_low_amp_clear=0;
            gp30_event_flag.low_amp = TRUE;
            gp30_event_save_flag.low_amp = TRUE;
        }
		break;
	case GP30_err:	
        gp30_event.gp30_err++;
		if(gp30_event.gp30_err > sum_res)
        {
            gp30_event_flag.gp30_err = TRUE;
            gp30_event_save_flag.gp30_err = TRUE;
        }
		break;
 
    case GP30_water_direction:
       gp30_event.water_direction_reverse++;
       if(gp30_event.water_direction_reverse > sum_res)    
        {
            gp30_event_flag.water_direction = TRUE;
			sum_water_diredtion_clear= 0;
        }        
        break;
        
    case GP30_communication_err_DE:
        gp30_event_flag.communication_err = FALSE;
        gp30_event.communication_err = 0;
        break;
    case GP30_no_water_DE:
		sum_no_water_clear++;
		if(sum_no_water_clear > GP30_APP_EVENT_SUM_NORMAL)
		{
			sum_no_water_clear=0;
			gp30_event_flag.no_water = FALSE;
			gp30_event.no_water = 0; 
		}
        break;
    case GP30_low_flow_DE:
        gp30_event_flag.low_flow = FALSE;
        gp30_event.low_flow = 0;
        break;
    case GP30_out_temp_DE:
        gp30_event_flag.out_temp = FALSE;
        gp30_event.out_temp = 0;
        break;
   case GP30_low_high_flow_DE:
        gp30_event_flag.low_high_flow = FALSE;
        gp30_event.low_high_flow = 0;
        break;
   case GP30_reverse_flow_DE:
//       if(TRUE == gp30_event_flag.reverse_flow)
       {
           sum_reverse_clear++;
           if(sum_reverse_clear > GP30_APP_EVENT_SUM_NORMAL)
           {
                sum_reverse_clear = 0;
                gp30_event_flag.reverse_flow = FALSE;
                gp30_event.reverse_flow = 0;
           }
       }
        break;
	case GP30_TOF_overrun_DE:
        gp30_event_flag.tof_overrun = FALSE;
        gp30_event.tof_overrun = 0;
		break;
	case GP30_low_amp_DE:
		sum_low_amp_clear++;
		if(sum_low_amp_clear > GP30_APP_EVENT_SUM_NORMAL)
		{
			sum_low_amp_clear=0;
			gp30_event_flag.low_amp = FALSE;
			gp30_event.low_amp = 0;
		}
        break;
	case GP30_err_DE:
        gp30_event_flag.gp30_err = FALSE;
        gp30_event.gp30_err = 0;
        break;
    case GP30_water_direction_DE:
		sum_water_diredtion_clear++;
		if(sum_water_diredtion_clear > GP30_APP_EVENT_SUM_NORMAL)
		{
			gp30_event_flag.water_direction = FALSE;
			gp30_event.water_direction_reverse = 0;
			sum_water_diredtion_clear = 0;
		}
        break;
    
    case GP30_clear_all:
        gp30_event.communication_err = 0;
        gp30_event.no_water = 0;
        gp30_event.low_flow = 0;
        gp30_event.out_temp = 0;
        gp30_event.low_high_flow = 0;
        gp30_event.water_direction_reverse = 0;

//        gp30_event_flag.trans_err = FALSE;
//        gp30_event_flag.no_water = FALSE;
//        gp30_event_flag.low_flow = FALSE;
//        gp30_event_flag.out_temp = FALSE;
//        gp30_event_flag.low_high_flow = FALSE;

        gp30_event_save_flag.communication_err = FALSE;
        gp30_event_save_flag.no_water = FALSE;
        gp30_event_save_flag.low_flow = FALSE;
        gp30_event_save_flag.out_temp = FALSE;
        gp30_event_save_flag.low_high_flow = FALSE;
    
       
        break;
    default:
        break;
    }
}
/****************************************************************
Function:    void gp22App (void)
Description:  GP22数据计算处理机
Input:
Return:
Others:
 *****************************************************************/
void Gp22App(void)
{
//    u32 gp22_sample_result;
    u8 gp22_err_result;
//    u8 temp_flow_head;
//    u32 temp_dif_time;
	u8 i = 0;
	
	u8 GP30_low_amp_cnt = 0;//每16个buffer中低振幅的次数
//	static u8 s_diftof_overrun_num = 0;
//	static u8 s_tdc_overrun_num = 0;  //无水
//	static u8 s_tof_overrun_num = 0;
//	float temp_value_float = 0;
	u32 *s_g_flow_data_pointer; //流量采集队列指针
	u32 *s_g_flow_type_pointer; //流量采集队列指针
	
	#if WENDU_FANSUAN_OPEN
	u32 *s_g_tof_am_pointer; //获取单程时间和振幅值
	#else
	static u8 s_temp_sample_num = 0;
    u32  sum_up_am=0,sum_down_am=0;//计算Up和Down振幅加和
    u8   up_am_cnt=0,down_am_cnt=0;//统计符合合法范围的振幅值个数 2022-05-11
	u32 *s_g_up_am_pointer; //UP振幅采集队列指针
	u32 *s_g_down_am_pointer; //DOWN振幅采集队列指针
	#endif	
		
    switch (s_g_gp22_app_state_num)
    {
    case GP22_APP_S0:
		gp22_sample_result = Gp22CheckSampleMsg();
		if (gp22_sample_result != BIT2) //未正在采样
		{
//			if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定而且上位机不允许采样
//			{
//				Gp22ClearSampleMsg(); 
//				TempStartTaskApp();//启动温度采集
//				break;
//			}
//			else
//			{
				#if !WENDU_FANSUAN_OPEN
				if(10== LcdCheckStateApp())   //非检定
				{
					s_temp_sample_num++;
					if(0 == s_temp_sample_num % 3)
					{
						s_temp_sample_num = 0;
						TempStartTaskApp();//启动温度采集
						s_g_sample_flag = GP22_APP_FLOW_TEMP; //本次采集温度标志
					}
				}
				else
				{
					TempStartTaskApp();//启动温度采集
					s_g_sample_flag = GP22_APP_FLOW_TEMP; //本次采集温度标志
				}
				#endif				
				s_g_gp22_app_state_num = GP22_APP_S1;
//			}
		}
        break;
    case GP22_APP_S1:
        if (0x01 == (gp22_sample_result & 0x01)) //采样成功
        {
			gp30_overrun_num.GP30_sample_err_num = 0 ;
			Gp22ClearSampleMsg(); //清采样完成MSG
			s_g_gp22_err_flag = 0;
			
			gp22CheckErrEventApp(GP30_communication_err_DE);
			Gp22DateBuf(&s_g_flow_data_pointer);
			Gp22TypeBuf(&s_g_flow_type_pointer);
			
			#if WENDU_FANSUAN_OPEN				
				Gp22_TOF_AM_Buf(&s_g_tof_am_pointer);
			#else
				Gp22DOWN_AM_Buf(&s_g_down_am_pointer);
				Gp22UP_AM_Buf(&s_g_up_am_pointer);
			#endif

			
			for(i = 0;i < GP22_APP_QUEUE_SIZE;i++)
			{
				s_g_flow_data[i] = *(s_g_flow_data_pointer + i);
				s_g_flow_type[i] = *(s_g_flow_type_pointer + i);
				
				#if WENDU_FANSUAN_OPEN	
					Tof_And_AM_Data_Collect(i,s_g_tof_am_pointer[i]);//用于单程时间和振幅数据的采集				
				#else 
				if(i < GP22_APP_MAX_AM_BUFFER)
				{					
					s_g_up_am[i] =	*(s_g_up_am_pointer + i);
					s_g_down_am[i] = *(s_g_down_am_pointer + i);
					s_g_up_am[i] = (s_g_up_am[i] & 0x000000FFU) << 24 | (s_g_up_am[i] & 0x0000FF00U) << 8 | (s_g_up_am[i] & 0x00FF0000U) >> 8 | (s_g_up_am[i] & 0xFF000000U) >> 24;  //大小端转换
					s_g_down_am[i] = (s_g_down_am[i] & 0x000000FFU) << 24 | (s_g_down_am[i] & 0x0000FF00U) << 8 | (s_g_down_am[i] & 0x00FF0000U) >> 8 | (s_g_down_am[i] & 0xFF000000U) >> 24;  //大小端转换
					if(0x80000000 == (s_g_up_am[i] & 0x80000000)) //振幅为负:写为0
					{
						s_g_up_am[i] = 0;                     
					}
					if(0x80000000 == (s_g_down_am[i] & 0x80000000)) //振幅为负写为0
					{
						s_g_down_am[i] = 0;                     
					}
                    if((s_g_up_am[i]>0)&&(s_g_up_am[i] < UP_AM_MAX))//UP振幅只计算(0~UP_AM_MAX)范围内的数据加和
                    {                       
                        sum_up_am += s_g_up_am[i];//计算有效UP振幅的总和
                        up_am_cnt++;//统计有效UP振幅的个数
                    }
					if((s_g_down_am[i]>0)&&(s_g_down_am[i] < DOWN_AM_MAX))//DOWN振幅只计算(0~DOWN_AM_MAX)范围内的数据加和
                    {                        
                        sum_down_am += s_g_down_am[i];//计算有效DOWN振幅的总和
                        down_am_cnt++;//统计有效DOWN振幅的个数 
                    } 
				}
				#endif
				s_g_flow_data[i] = (s_g_flow_data[i] & 0x000000FFU) << 24 | (s_g_flow_data[i] & 0x0000FF00U) << 8 | (s_g_flow_data[i] & 0x00FF0000U) >> 8 | (s_g_flow_data[i] & 0xFF000000U) >> 24;  //大小端转换
//				s_g_flow_type[i] = (s_g_flow_type[i] & 0x000000FFU) << 24 | (s_g_flow_type[i] & 0x0000FF00U) << 8 | (s_g_flow_type[i] & 0x00FF0000U) >> 8 | (s_g_flow_type[i] & 0xFF000000U) >> 24;  //大小端转换  //type不用转换大小端
				// +5 -2 -11 -1 -5 -11 
//				s_g_flow_data[i]=s_g_flow_data[i]-11;

				if(TRUE == CheckDiftofCalibrationFlag())
				{					
					s_g_flow_data[i]=s_g_flow_data[i] + g_diftof_cal_data.s.diftof_calibration_value.data;
//					temp_value_float = TempCheckValueApp();
//					if(temp_value_float > 35)
//					{
//							s_g_flow_data[i] = s_g_flow_data[i]-DIFTOF_HIGH_TEMP_CALIBRATION_VALUE;
//					}
				}
				if(0x01000000 == (s_g_flow_type[i] & 0x01000000)) //正常DIFTOF数据
				{
					//如果时间差为负,把补码转换为原码
					if(0x80000000 == (s_g_flow_data[i] & 0x80000000)) //时间差为负:符号位为1
					{
						s_g_flow_data[i] &= 0x7FFFFFFF;
						s_g_flow_data[i] = (~s_g_flow_data[i]) + 1;   //包括符号位的原码	
                        gp22CheckErrEventApp(GP30_water_direction);  //水流反向                      
					}
				    else
					{
						gp22CheckErrEventApp(GP30_water_direction_DE);//
					}
					//时间差判断
					if(((s_g_flow_data[i] > 0) && (s_g_flow_data[i] <= LIMIT_DIFTOF_FORWARD)) || ((s_g_flow_data[i] >= 0x80000000) && (s_g_flow_data[i] <= 0x80000107)))  //0~700ns或者-1~0ns  ——2019-3-9 计量范围-200-800ns
					{
						gp22CheckErrEventApp(GP30_reverse_flow_DE);   
					}
					//小于1ns的逆流暂时不计量，作为静水波动处理
					//后续计量逆流时，需要考虑全流量范围的负数，需要修改此处 2019-3-11
					else if((s_g_flow_data[i] > 0x80000107) && (s_g_flow_data[i] <= LIMIT_DIFTOF_REVERSE))  //-200ns ~ -1ns(需要低于最小流量时间差,注意不同口径)  —— 2019-3-9 计量范围-200-800ns
					{
						gp22CheckErrEventApp(GP30_reverse_flow); 
//						if (01== LcdCheckStateApp()) //检定状态
//						{						
//							if(TRUE == gp30_event_flag.reverse_flow)//连续次数后，判断真的倒转了,为了应对跳变,暂时不清零2018-12-17————改成DLY固件后，连续多少次确定是逆流，暂时逆流不计量，（清零）2019-3-9
//							{
//								s_g_flow_data[i] = 0;   //先暂时不计量逆流 2018-10-12 14:37:22
//							}
//							else   //用上次数
//							{
//								if (0 == i)
//								{
//									s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
//								}
//								else
//								{
//									s_g_flow_data[i] = s_g_flow_data[i-1];
//								}	
//							}
//						}
					}
					else if((s_g_flow_data[i] > LIMIT_DIFTOF_REVERSE) && (s_g_flow_data[i] <= 0x80040000))  //-1000ns ~ -100ns
					{
						s_g_flow_data[i] = 0x00040000-(s_g_flow_data[i]&0x7FFFFFFF);
					}
					else
					{
						if (0 == i)
						{
							s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
						}
						else
						{
							s_g_flow_data[i] = s_g_flow_data[i-1];
						}
					}
					
					StillWatetCalculate(s_g_flow_data[i]); //时间差
					
					gp22CheckErrEventApp(GP30_err_DE);
					gp22CheckErrEventApp(GP30_no_water_DE);
					gp22CheckErrEventApp(GP30_TOF_overrun_DE); 
					gp30_overrun_num.tdc_overrun_num = 0;//无水
					gp30_overrun_num.tof_overrun_num = 0;//TOF Overrun
					gp30_overrun_num.diftof_overrun_num = 0; //清跳变累计次数
					gp30_overrun_num.type_err_num = 0;//清GP30异常累计次数
					Gp22ClearErrMsg(0);
					Gp22ClearErrMsg(1);
				}
				/*
				Norbert Breyer: 2019-3-9 
				1. No receive at all - TDC overrun

				2. very small signal or noise, TDC gets triggered but amplitude very low - MIN_AMP error
				
				TOF overrun as well
				*/
				else if(0x08000000 == (s_g_flow_type[i]&0x08000000)) //无水:TDC overrun
				{
					if(gp30_overrun_num.tdc_overrun_num >= GP22_APP_QUEUE_SIZE)
					{
						s_g_flow_data[i] = 0;
					}
					else
					{
						gp30_overrun_num.tdc_overrun_num++;
						if (0 == i)
						{
							s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
						}
						else
						{
							s_g_flow_data[i] = s_g_flow_data[i-1];
						}
					}
					StillWatetCalculate(s_g_flow_data[i]); //时间差  2019-7-4 18:48:02
                
					gp22CheckErrEventApp(GP30_no_water);
					gp22CheckErrEventApp(GP30_water_direction_DE);//无水情况下，水流不反向
					gp22CheckErrEventApp(GP30_reverse_flow_DE);
					gp30_overrun_num.diftof_overrun_num = 0; //清跳变累计次数
					gp30_overrun_num.type_err_num = 0;//清GP30异常累计次数
					gp22CheckErrEventApp(GP30_err_DE);
					Gp22ClearErrMsg(0);
					Gp22ClearErrMsg(1);
				
				}
				else if(0x02000000 == (s_g_flow_type[i]&0x02000000)) //GP30_TOF_overrun
				{
					if(gp30_overrun_num.tof_overrun_num >= GP22_APP_QUEUE_SIZE)
					{
						s_g_flow_data[i] = 0;
					}
					else
					{
						gp30_overrun_num.tof_overrun_num++;
						if (0 == i)
						{
							s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
						}
						else
						{
							s_g_flow_data[i] = s_g_flow_data[i-1];
						}
					}
					StillWatetCalculate(s_g_flow_data[i]); //时间差  2019-7-4 18:48:02
					gp22CheckErrEventApp(GP30_TOF_overrun);
					
					gp22CheckErrEventApp(GP30_err_DE);
					gp22CheckErrEventApp(GP30_no_water);   //TOF Overrun和无水 需要确认
					gp22CheckErrEventApp(GP30_water_direction_DE);//置水流不反向
					gp22CheckErrEventApp(GP30_reverse_flow_DE);					
					gp30_overrun_num.diftof_overrun_num = 0; //清跳变累计次数
					gp30_overrun_num.type_err_num = 0;//清GP30异常累计次数
					Gp22ClearErrMsg(0);
					Gp22ClearErrMsg(1);
					
				}
				
				//跳变暂时单独判断
				else if(0x04000000 == (s_g_flow_type[i]&0x04000000)) //GP30_DIFTOF overrun 
				{
					//连续跳变的次数
					gp30_overrun_num.diftof_overrun_num++;
					
//					if(gp30_overrun_num.diftof_overrun_num >= (GP22_APP_QUEUE_SIZE + GP22_APP_QUEUE_SIZE))
//					{
//						//后续添加处理措施
//						//先暂时复位GP30——如果检定start开始就跳变，会丢一个buf的累积量？——2018-11-28
//						//正常状态下，不会丢累积量，因为上次数有
//						
//						gp30_overrun_num.diftof_overrun_num = 0;
////						#if defined(DLY_SWITCH)
////							Gp22AppSetGp22Err();
////						#endif						
//					}
					
//					//如果时间差为负,把补码转换为原码
//					if(0x80000000 == (s_g_flow_data[i] & 0x80000000)) //时间差为负:符号位为1
//					{
//						s_g_flow_data[i] &= 0x7FFFFFFF;
//						s_g_flow_data[i] = (~s_g_flow_data[i]) + 1;   //包括符号位的原码			
//					}
//				
//					if((s_g_flow_data[i] < 0x80080000) && (s_g_flow_data[i] >= 0x80053333)) //-2000~-1300ns
//					{
//						s_g_flow_data[i] &= 0x7FFFFFFF;  //时间差转换为正
//						s_g_flow_data[i] = 0x80000 - s_g_flow_data[i];    //2000-
//						gp22CheckErrEventApp(GP30_reverse_flow_DE);
//					}
//					else if((s_g_flow_data[i] < 0x80040000) && (s_g_flow_data[i] >= 0x80013333))  //-1000~-300ns
//					{
//						s_g_flow_data[i] &= 0x7FFFFFFF;  //时间差转换为正
//						s_g_flow_data[i] = 0x40000 - s_g_flow_data[i];	//1000-
//						gp22CheckErrEventApp(GP30_reverse_flow_DE);
//					}
//					else if((s_g_flow_data[i] > 0x40000) && (s_g_flow_data[i] <= 0x6CCCC))  //1000~1700ns
//					{
//						s_g_flow_data[i] -= 0x40000;	//-1000ns
//						gp22CheckErrEventApp(GP30_reverse_flow_DE);
//					}
//					else if((s_g_flow_data[i] > 0x80000) && (s_g_flow_data[i] <= 0xACCCC))  //2000~2700ns
//					{
//						s_g_flow_data[i] -= 0x80000;	//-2000ns
//						gp22CheckErrEventApp(GP30_reverse_flow_DE);
//					}
//					else 
//					{
						//用上次值
						if(gp30_overrun_num.diftof_overrun_num <= 3)
						{
							if (0 == i)
							{
								s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
							}
							else
							{
								s_g_flow_data[i] = s_g_flow_data[i-1];
							}
						}							
//					}
					
					StillWatetCalculate(s_g_flow_data[i]);
					
//					gp22CheckErrEventApp(GP30_no_water_DE);
//					gp22CheckErrEventApp(GP30_TOF_overrun_DE); 
//					gp30_overrun_num.tdc_overrun_num = 0;
//					gp30_overrun_num.tof_overrun_num = 0;
				}
				else if((0x20000000 == (s_g_flow_type[i]&0x20000000)) || (0 == s_g_flow_type[i])) //GP30异常:GP30 cannot make valid DIFTOF measurements (internal error)
				{
                    gp22CheckErrEventApp(GP30_err);
					gp30_overrun_num.type_err_num++;
                    
                    if (0 == i)
                    {
                        s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
                    }
                    else
                    {
                        s_g_flow_data[i] = s_g_flow_data[i-1];
                    }
                    
                    if(gp30_overrun_num.type_err_num >= (GP22_APP_QUEUE_SIZE))
					{
                        gp30_overrun_num.type_err_num = 0;
                        
                        if(FixedTimeNbIoTUploadIfIdle() == TASK_IDLE)//上报期间不调用GP30 初始化
                        {
                             Gp22ErrInit();
                        }                      
					}
                    
                    /*
					gp22CheckErrEventApp(GP30_err);
//					gp30_overrun_num.type_err_num++;
					
					if(gp30_overrun_num.type_err_num >= (GP22_APP_QUEUE_SIZE*8))
					{
//						gp30_overrun_num.type_err_num = GP22_APP_QUEUE_SIZE*8;//待定---如果一直复位，type_err_num一直++，u8类型的会超范围，用上次数会导致走数。
						s_g_flow_data[i] = 0;
					}
					else
					{
                        gp30_overrun_num.type_err_num++;
						if (0 == i)
						{
							s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
						}
						else
						{
							s_g_flow_data[i] = s_g_flow_data[i-1];
						}
					}*/
					StillWatetCalculate(s_g_flow_data[i]); //时间差  2019-7-4 18:48:02


				}
				else
				{
					gp22CheckErrEventApp(GP30_err_DE);
//					gp30_overrun_num.type_err_num = 0; //清type为0的次数
					//用上次值
					if (0 == i)
					{
						s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
					}
					else
					{
						s_g_flow_data[i] = s_g_flow_data[i-1];
					}
				
					StillWatetCalculate(s_g_flow_data[i]);
				}
				
				/*
				Having delay window only, no first hit level, the amplitude is the only measure to detect an empty tube. 
				I propose to set the MIN_AMP level to a very low value and to take this as empty tube detection.
				*/
				if(0x10000000 == (s_g_flow_type[i] & 0x10000000))  //判断是否低振幅
				{
					gp22CheckErrEventApp(GP30_low_amp);
					GP30_low_amp_cnt++;
					
					if(GP30_low_amp_cnt==GP22_APP_QUEUE_SIZE)
					{
						for(i = 0;i<GP22_APP_QUEUE_SIZE;i++)
						{
							s_g_flow_data[i] = 1; //2021-12-09
						}
					}
					
					if (0 == i)//
					{
						if((s_g_flow_data[GP22_APP_QUEUE_SIZE-1]<=0x80000000)&&(s_g_flow_data[GP22_APP_QUEUE_SIZE-1]>=0x00006666))//时间差大于正向100ns
						{
							s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];  
						}
						else 
						{
							s_g_flow_data[i] = 1; //2021-12-09
						}						
					}
					else
					{
						if((s_g_flow_data[i-1]<=0x80000000)&&(s_g_flow_data[i-1]>=0x00006666))//时间差大于正向100ns
						{
							s_g_flow_data[i] = s_g_flow_data[i-1];
						}
						else 
						{
							s_g_flow_data[i] = 1; //2021-12-09
						}							
					}
				}
				else
				{
					gp22CheckErrEventApp(GP30_low_amp_DE);
				}
			}
            
			#if WENDU_FANSUAN_OPEN
            //Find_MaxValue_for_AM1(s_g_up_am,s_g_down_am,2*GP22_APP_TEMP_INVERSE_DATA_SIZE);//用于寻找6个振幅中最大的幅值对应的单程时间 
            //单程时间计算均值
            Gp30_Tof_Collect_and_Deal();//对采集的振幅和单程时间进行数据的处理
			gp22_test_data.s.peak_up=GetTemperatureCalculateParameter(UP_AM_AVERAGE);
			gp22_test_data.s.peak_down=GetTemperatureCalculateParameter(DOWN_AM_AVERAGE);
			#else
            if(down_am_cnt!=0)
            {
               gp22_test_data.s.peak_down=sum_down_am/(down_am_cnt);
            }
            else 
            {
               gp22_test_data.s.peak_down = 0; 
            }
            if(up_am_cnt!=0)
            {
                gp22_test_data.s.peak_up=sum_up_am/(up_am_cnt);
            }
            else 
            {
               gp22_test_data.s.peak_up = 0;  
            }
            #endif
			GP30_Set_Data_UpdateMsg();			
			gp22_app_data.s.peak_up=gp22_test_data.s.peak_up;
			gp22_app_data.s.peak_down=gp22_test_data.s.peak_down;
//			Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样
			s_g_gp22_app_state_num = GP22_APP_S0;
        }
        else if (0x02 == (gp22_sample_result & 0x02)) //采样失败
        {
			gp30_overrun_num.GP30_sample_err_num++;
			Gp22ClearSampleMsg(); //清采样完成MSG
            gp22_err_result = Gp22CheckErrMsg();
			
//			Gp22AppSetGp22Err();  驱动层已经处理
			if(gp30_overrun_num.GP30_sample_err_num >= 5)
			{
				gp30_overrun_num.GP30_sample_err_num = 5;
				memset(s_g_flow_data, 0, sizeof(s_g_flow_data));
				memset(s_g_flow_type, 0, sizeof(s_g_flow_type));
			}
			else
			{
				for(i = 0;i < GP22_APP_QUEUE_SIZE;i++)
				{
					if (0 == i)
					{
						s_g_flow_data[i] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
					}
					else
					{
						s_g_flow_data[i] = s_g_flow_data[i-1];
					}
				}
			
				StillWatetCalculate(s_g_flow_data[i]);
			}
			
			if(0x01 == (gp22_err_result & 0x01)) //Bit0 中断等待超时
			{
				gp22CheckErrEventApp(GP30_communication_err);
			}
			else if(0x02 == (gp22_err_result & 0x02)) //Bit1 通讯超时
			{
				gp22CheckErrEventApp(GP30_communication_err);
				
			}
//			Gp22FilterCalculate(s_g_sample_flag);
			s_g_gp22_app_state_num = GP22_APP_S0;

        }
		
        break;
    default:
        break;
    }
	
	/******************************************************************************
	
	*******************************************************************************/
//	u32 gp22_sample_result;
//    u8 gp22_err_result;
//    u8 temp_flow_head;
//    u32 temp_dif_time;
//    u8 sample_flag = 0;
	
//    switch (s_g_gp22_app_state_num)
//    {
//    case GP22_APP_S0:
//		if(TASK_IDLE == Gp22IfIdle())
//		{
//			if ((BIT2 == (RtccCheckMsg() & BIT2))) //收到其中一个采样消息
//			{
//				RtccClearMsg(2);
//				if((01 == LcdCheckStateApp()) && (0 == start_measure_flag)) //检定而且上位机不允许采样
//				{
//					break;
//				}
//				else
//				{
//					sample_flag = 1;
//				}
//			}
//	    }
//        if (sample_flag) //收到其中一个采样消息 
//        {
//            sample_flag = 0;
////            s_g_gp22_sample_flag_num++;
////            s_g_gp22_sample_flag_num = s_g_gp22_sample_flag_num % 5;
////            if(s_g_gp22_sample_flag_num == s_g_gp22_sample_span) //采样频率符合
//            {
////				STM32_GPIO_TogglePin(GPIOE, STM32_GPIO_PIN_15);
//				
////                s_g_gp22_sample_flag_num = 0;

////                if (s_g_sample_flow_num >= GP22_APP_SAMPLE_SIZE)
//                {
////                    s_g_sample_flow_num = 0;
//                    Gp22StartTask(GP22_APP_FLOW); //启动流量+温度
//                    TempStartTaskApp();//启动温度采集
//                    s_g_sample_flag = GP22_APP_FLOW_TEMP; //本次采集温度标志
//                }
////                else
////                {
////                    Gp22StartTask(GP22_APP_FLOW); //只启动流量
////                    s_g_sample_flag = GP22_APP_FLOW; //本次没有采集温度标志
////                }

////                s_g_sample_flow_num++;
//                s_g_gp22_app_state_num = GP22_APP_S1;
//            }
//        }
//        break;
//    case GP22_APP_S1:
//        gp22_sample_result = Gp22CheckSampleMsg();
//        if (1 == (gp22_sample_result & 0x01)) //采样完成
//        {
//            s_g_flow_data[s_g_sample_flow_head] = Gp22TimeDiffer(GP22_APP_FLOW_DIFFER_SIGN);///////改成带正负号的
//            if((s_g_flow_data[s_g_sample_flow_head] >= 0x80000419))
//            {
////                Nop();
////                Nop();
////                s_g_flow_err_sum = 0; //连续5次
//            }
//            
////            if(TRUE == gp30_event_flag.reverse_flow)//连续次数后，判断真的到转了
////            {
////                s_g_flow_data[s_g_sample_flow_head] = 0;
////            }
//            
//            StillWatetCalculate(s_g_flow_data[s_g_sample_flow_head]); //时间差  1/4
//            s_g_sample_flow_head++;
//            s_g_sample_flow_head %= GP22_APP_QUEUE_SIZE;

////            s_g_flow_err_sum = 0; //连续5次

//            gp22CheckErrEventApp(GP30_no_water_DE);  // 1/4 DE
//            gp22CheckErrEventApp(GP30_reverse_flow_DE);
//			
//			s_g_gp22_err_flag = 0; //2018-7-12

//            Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样

//            s_g_gp22_app_state_num = GP22_APP_S0;
//        }
//        else if (2 == (gp22_sample_result & 0x02)) //采样失败
//        {
//            gp22_err_result = Gp22CheckErrMsg();
//            if (1 == ((gp22_err_result >> 4)&0x01)) //时间差为负数
//            {
//                temp_dif_time = Gp22TimeDiffer(GP22_APP_FLOW_DIFFER);
//                if ((temp_dif_time < 0x00040000) && (temp_dif_time > 0x00018F5C)) //发生跳变数据 0.39-1us
//                {
//                    s_g_flow_data[s_g_sample_flow_head] = 0x00040000 - temp_dif_time;

//                    if((temp_dif_time >= 0x00040000))
//                    {
//        //                Nop();
//        //                Nop();
////                        s_g_flow_err_sum = 0; //连续5次
//                        temp_dif_time = 0;
//                    }
//                    //倒转
//                    //gp22CheckErrEventApp(GP30_reverse_flow);
//                   // if(TRUE == gp30_event_flag.reverse_flow)//连续次数后，判断真的到转了
//                  //  {
//                  //      s_g_flow_data[s_g_sample_flow_head] = 0;
//                  //  }
//                    ///////////////////////////////
//                    StillWatetCalculate(s_g_flow_data[s_g_sample_flow_head]); //时间差  2/4

////                    s_g_flow_err_sum++;
////                    if (s_g_flow_err_sum >= 5)
////                    {
////                        s_g_flow_err_sum = 0;
////                        s_g_set_window = TRUE; //重新配置时间窗
////                    }
//                }
//                else //装反处理,或者静水时间的负值
//                {
//                    if ((temp_dif_time > 0x00000190) && (temp_dif_time <= 0x00018F5C)) //倒转范围内 使动0.0015-0.39us
//                    {
//                        gp22CheckErrEventApp(GP30_reverse_flow);

////                        u32 temp111 = Gp22TimeDiffer(GP22_APP_FLOW_DIFFER_SIGN);
////                        temp111 = temp111;
//                        StillWatetCalculate(float_differ_last_time); //时间差  3/4  2016-9-18 11:21:55 用上次值

//                        if(TRUE == gp30_event_flag.reverse_flow)//连续次数后，判断真的到转了
//                        {
//                            s_g_flow_data[s_g_sample_flow_head] = 0;
//                        }
//                        else   //用上次数
//                        {
//                            if (0 == s_g_sample_flow_head)
//                            {
//                                s_g_flow_data[s_g_sample_flow_head] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
//                            }
//                            else
//                            {
//                                temp_flow_head = s_g_sample_flow_head - 1;
//                                s_g_flow_data[s_g_sample_flow_head] = s_g_flow_data[temp_flow_head];
//                            }
//                        }
//                    }
//                    else
//                    {
//                        gp22CheckErrEventApp(GP30_reverse_flow_DE);
//                        StillWatetCalculate(Gp22TimeDiffer(GP22_APP_FLOW_DIFFER_SIGN)); //时间差  3/4
//                        s_g_flow_data[s_g_sample_flow_head] = 0;
//                    }
////                    s_g_flow_err_sum = 0; //连续5次
//                }
//				
//				s_g_gp22_err_flag = 0; //2018-7-12
//				
//                s_g_sample_flow_head++;
//                s_g_sample_flow_head %= GP22_APP_QUEUE_SIZE;

//                Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样
//            }
//            else if (1 == ((gp22_err_result >> 2)&0x01)) //信号超时（无水）
//            {
//                s_g_flow_data[s_g_sample_flow_head] = 0;
//                s_g_sample_flow_head++;
//                s_g_sample_flow_head %= GP22_APP_QUEUE_SIZE;

////                s_g_flow_err_sum = 0; //连续5次
//                
//                gp22CheckErrEventApp(GP30_no_water);  // 1/4
//                gp22CheckErrEventApp(GP30_reverse_flow_DE);
//				
//				s_g_gp22_err_flag = 0; //2018-7-12

//                Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样
//            }
//            if ((16 != gp22_err_result) && (4 != gp22_err_result)) //短路、断路、GP22故障
//            {
////                gp22_app_data.in_temp = 0;
////                gp22_app_data.s.ins_flow = 0; 
////                gp22_app_data.ins_power = 0;
////                gp22_app_data.out_temp = 0;

////                gp22_test_data.in_temp = 0;
////                gp22_test_data.s.ins_flow = 0;
////                gp22_test_data.ins_power = 0;
////                gp22_test_data.out_temp = 0;
//                
////                gp22CheckErrEventApp(GP30_trans_err);  // 2/4
//				
//				
//				s_g_flow_data[s_g_sample_flow_head] = 0;
//                s_g_sample_flow_head++;
//                s_g_sample_flow_head %= GP22_APP_QUEUE_SIZE;

//                Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样
//				/*************************/

////                s_g_flow_err_sum = 0; //连续5次
//				
////				if(0 != gp22_err_result)
////				{
////					Gp22AppSetGp22Err();
////				}
//            }

//            s_g_gp22_app_state_num = GP22_APP_S0;
//        }
//        else if (4 == (gp22_sample_result & 0x04)) //完成,但是有气泡
//        {
//            if (0 == s_g_sample_flow_head)
//            {
//                s_g_flow_data[s_g_sample_flow_head] = s_g_flow_data[GP22_APP_QUEUE_SIZE-1];
//            }
//            else
//            {
//                temp_flow_head = s_g_sample_flow_head - 1;
//                s_g_flow_data[s_g_sample_flow_head] = s_g_flow_data[temp_flow_head];
//            }
//            StillWatetCalculate(s_g_flow_data[s_g_sample_flow_head]); //时间差  4/4
//            s_g_sample_flow_head++;
//            s_g_sample_flow_head %= GP22_APP_QUEUE_SIZE;

////            s_g_flow_err_sum = 0; //连续5次

//            Gp22FilterCalculate(s_g_sample_flag); //GP22 滤波和采样
//			
//			s_g_gp22_err_flag = 0; //2018-7-12
//            s_g_gp22_app_state_num = GP22_APP_S0;
//        }
//        break;
//    default:
//        break;
//    }
	//if (FrameCheckMsgApp(GP22_APP_STILL_WATER_FRAME)) //上位机需要查询静水时间差
    //////////////////////////////////////////////////////////////////////////////////////////////////
//    if (Gp22CheckMeasureMsg())
//    {
//        if (01 == LcdCheckStateApp()) //检定状态
//        {
//            //FrameClearMsgApp(GP22_APP_STILL_WATER_FRAME);
//            Gp22ClearMeasureMsg();
//            s_g_still_finish = FALSE;
//            s_g_still_flag = TRUE;
//            s_g_still_time = 0;
//        }
//    }
}

/****************************************************************
Function:    void Gp22AppSetGp22Err (void)
Description:  2018-8-6 
Input:
Return:
Others:    
 *****************************************************************/
void Gp22AppSetGp22Err (void)
{
	
    if(s_g_gp22_err_flag < 10)
	{
//		if(GP22_S2 != s_gp22_machine_state)//把GP30连接线断开,GP30的驱动会啊卡死在S2状态
//        {
        s_g_gp22_err_flag++;//2018-8-9增加GP22通信异常防护
//        }
        Gp22ErrInit();        
	}
	else
	{
//		if(1 == LcdCheckStateApp()) //检定状态
//		{
//		    FrameSetMsgApp(OutVerificationMsg);//FrameExitTest();
//		}
//		FrameSetMsgApp(BootloaderMsg);	
//		NVIC_SystemReset();     //reset //重启

		Gp30Sleep();
	}		
}

/****************************************************************
Function:    void Gp22AppClearData (void)
Description:  GP22数据清零处理机
Input:
Return:
Others:    不清零静水时间差
 *****************************************************************/
void Gp22AppClearData(void)
{
    u8 i;
    static u8 ee_write_result_clear_data;

    switch (s_g_gp22_app_clear_data_state_num)
    {
      case GP30_APP_CLEAR_DATA_S0:
      {
        if (1 == FrameCheckMsgApp(ClearRealtimeDataMsg)) //上位机清表数据消息
        {
            FrameClearMsgApp(ClearRealtimeDataMsg); //清MSG
            for (i = 0; i < GP22_APP_QUEUE_SIZE; i++)
            {
                s_g_flow_data[i] = 0;
            }
//            s_g_sample_flow_head = 0;
//            s_g_sample_flow_num = 0;
            duoble_total_flow.gp30_double = 0;
            gp22_app_data.s.total_flow.gp30_u32 = 0;
			gp22_app_data.s.total_flow_reverse.gp30_u32 = 0;
            gp22_test_data.s.total_flow.gp30_u32 = 0;
			gp22_test_data.s.total_flow_reverse.gp30_u32 = 0;
			
			total_flow_old.gp30_float = 0;
			gp22_copy_total_flow = 0;  
			gp22_copy_total_flow_reverse = 0; 
			
			gp22_copy_total_flow_test=0;
			gp22_copy_temp_total_flow_float_test=0;
			
            Gp22AppDataPre();
            if (EepIfIdle())
            {
                EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_clear_data);
                s_g_gp22_app_clear_data_state_num = GP30_APP_CLEAR_DATA_S0;

                gp22CheckErrEventApp(GP30_clear_all);//每个整点全部清除报警记录信息
            }
            else
            {
                s_g_gp22_app_clear_data_state_num = GP30_APP_CLEAR_DATA_S1;
            }
        }
			}
        break;
    case GP30_APP_CLEAR_DATA_S1:
        if (EepIfIdle())
        {
            EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_clear_data);
            s_g_gp22_app_clear_data_state_num = GP30_APP_CLEAR_DATA_S0;

            gp22CheckErrEventApp(GP30_clear_all);//每个整点全部清除报警记录信息
        }
        break;
    default:
        break;
    }
}

/****************************************************************
Function:    void Gp22AppSaveData (void)
Description:  GP22数据备份处理机
Input:
Return:
Others:
 *****************************************************************/
void Gp22AppSaveData(void)
{
    static u8 ee_write_result_save_data = 0;
    float temp_diff;

    switch (s_g_gp22_app_save_data_state_num)
    {
    case GP30_APP_SAVE_S0:
        RtccSetTimer(RTCC_TIMER_GP30_NUM, SAMPLE_INTERVAL_1h);
        s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S1;
        break;
    case GP30_APP_SAVE_S1:
		//定时存储、不休眠存储、远程升级、下初值、看门狗（暂未实现）
        if ((0 == RtccCheckTimer(RTCC_TIMER_GP30_NUM)) || (TRUE == PowerSaveDataMsgSys()) ||  (1== FrameCheckMsgApp(BootloaderMsg))||Gp30_init_data_flag || (TRUE == CheckAutoCalibrationMsg())||(TRUE == WDTWakeUpIfReset())
            #if WENDU_FANSUAN_OPEN
			|| (TempInverseCheckMsgApp(TofCaliberateMsg)==TRUE)//用于存储单程时间校准补偿系数标志
			#endif
		)//清零状态或者数据存储状态            
        {           
			if (EepIfIdle())
            {               
                #if WENDU_FANSUAN_OPEN
				TempInverseClearMsgApp(TofCaliberateMsg);//清零存储变量标志!!!				
				#endif
				if(0 == RtccCheckTimer(RTCC_TIMER_GP30_NUM))  //定时存储
                {
                    temp_diff = gp22_app_data.s.total_flow.gp30_float - gp30_total_flow_last.gp30_float;
                    if((temp_diff > (float)1)||(temp_diff < (float)-1)) //超过10L才存储
                    {
                        gp30_total_flow_last.gp30_float = gp22_app_data.s.total_flow.gp30_float;
                        Gp22AppDataPre();
                        EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_save_data);
                        s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S6;
                    }
                    else
                    {
                        s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S0;
                    }
                }
				else if(TRUE == CheckAutoCalibrationMsg())
				{
					diftof_auto_calibration_msg = FALSE;
					EepWrite(&g_diftof_cal_data.data[8], DIFTOF_CALIBRATION_VALUE_ADDR, 4, &s_gp30_eep_complete);
				}
                else
                {
                    Gp30_init_data_flag = FALSE;
                    Gp22AppDataPre();
                    EepWrite(&g_sample_save_data.data[0], GP30_APP_DATA_ADDR, sizeof (GP30_APP_SAVE_DATA), &ee_write_result_save_data);
                    s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S6;
                }
            }
        }
        break;
//    case GP30_APP_SAVE_S2: //shijian 1
////        if (gp30_event.trans_err >= GP30_APP_EVENT_SUM)
//        if (TRUE == gp30_event_save_flag.trans_err)
//        {
//            if (EepIfIdle())
//            {
//                RtccGetDateTime(&gp30_get_time);
//                s_g_event_data.s.time[0] = gp30_get_time.s.year;
//                s_g_event_data.s.time[1] = gp30_get_time.s.month;
//                s_g_event_data.s.time[2] = gp30_get_time.s.day;
//                s_g_event_data.s.time[3] = gp30_get_time.s.hour;
//                s_g_event_data.s.time[4] = gp30_get_time.s.minute;
//                s_g_event_data.s.time[5] = gp30_get_time.s.second;
//                s_g_event_data.s.total_flow.gp30_u32 = Gp30CheckDataApp(GP30_APP_TOTAL_FLOW);
//                s_g_event_data.s.state = FrameCheckByte();
//                EepWrite(&s_g_event_data.s.time[0], GP30_APP_TRANS_ERR_ADDR, sizeof (GP30_APP_EVENT_DATA), &ee_write_result_save_data);

////                gp30_event.trans_err = 0;
//                s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S3;
//            }
//        }
//        else
//        {
//            s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S3;
//        }
//        break;
//    case GP30_APP_SAVE_S3: //shijian 2
////        if (gp30_event.no_water >= GP30_APP_EVENT_SUM)
//        if (TRUE == gp30_event_save_flag.no_water)
//        {
//            if (EepIfIdle())
//            {
//                RtccGetDateTime(&gp30_get_time);
//                s_g_event_data.s.time[0] = gp30_get_time.s.year;
//                s_g_event_data.s.time[1] = gp30_get_time.s.month;
//                s_g_event_data.s.time[2] = gp30_get_time.s.day;
//                s_g_event_data.s.time[3] = gp30_get_time.s.hour;
//                s_g_event_data.s.time[4] = gp30_get_time.s.minute;
//                s_g_event_data.s.time[5] = gp30_get_time.s.second;
//                s_g_event_data.s.total_flow.gp30_u32 = Gp30CheckDataApp(GP30_APP_TOTAL_FLOW);
//                s_g_event_data.s.state = FrameCheckByte();
//                EepWrite(&s_g_event_data.s.time[0], GP30_APP_NO_WATER_ADDR, sizeof (GP30_APP_EVENT_DATA), &ee_write_result_save_data);

////                gp30_event.no_water = 0;
//                s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S4;
//            }
//        }
//        else
//        {
//            s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S4;
//        }
//        break;
//    case GP30_APP_SAVE_S4: //shijian 3
////        if (gp30_event.low_flow >= GP30_APP_EVENT_SUM)
//        if (TRUE == gp30_event_save_flag.low_flow)
//        {
//            if (EepIfIdle())
//            {
//                RtccGetDateTime(&gp30_get_time);
//                s_g_event_data.s.time[0] = gp30_get_time.s.year;
//                s_g_event_data.s.time[1] = gp30_get_time.s.month;
//                s_g_event_data.s.time[2] = gp30_get_time.s.day;
//                s_g_event_data.s.time[3] = gp30_get_time.s.hour;
//                s_g_event_data.s.time[4] = gp30_get_time.s.minute;
//                s_g_event_data.s.time[5] = gp30_get_time.s.second;
//                s_g_event_data.s.total_flow.gp30_u32 = Gp30CheckDataApp(GP30_APP_TOTAL_FLOW);
//                s_g_event_data.s.state = FrameCheckByte();
//                EepWrite(&s_g_event_data.s.time[0], GP30_APP_LOW_FLOW_ADDR, sizeof (GP30_APP_EVENT_DATA), &ee_write_result_save_data);

////                gp30_event.low_flow = 0;
//                s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S5;
//            }
//        }
//        else
//        {
//            s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S5;
//        }
//        break;
//    case GP30_APP_SAVE_S5: //shijian 4
////        if (gp30_event.out_temp >= GP30_APP_EVENT_SUM)
//        if (TRUE == gp30_event_save_flag.out_temp)
//        {
//            if (EepIfIdle())
//            {
//                RtccGetDateTime(&gp30_get_time);
//                s_g_event_data.s.time[0] = gp30_get_time.s.year;
//                s_g_event_data.s.time[1] = gp30_get_time.s.month;
//                s_g_event_data.s.time[2] = gp30_get_time.s.day;
//                s_g_event_data.s.time[3] = gp30_get_time.s.hour;
//                s_g_event_data.s.time[4] = gp30_get_time.s.minute;
//                s_g_event_data.s.time[5] = gp30_get_time.s.second;
//                s_g_event_data.s.total_flow.gp30_u32 = Gp30CheckDataApp(GP30_APP_TOTAL_FLOW);
//                s_g_event_data.s.state = FrameCheckByte();
//                EepWrite(&s_g_event_data.s.time[0], GP30_APP_OUT_TEMP_ADDR, sizeof (GP30_APP_EVENT_DATA), &ee_write_result_save_data);

////                gp30_event.out_temp = 0;
//                s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S6;
//            }
//        }
//        else
//        {
//            s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S6;
//        }
//        break;
    case GP30_APP_SAVE_S6:

        if (EepIfIdle()) //每个整点全部清除报警记录信息
        {
            gp22CheckErrEventApp(GP30_clear_all);//每个整点全部清除报警记录信息

            if (1 == FrameCheckMsgApp(BootloaderMsg))
            {
                FrameClearMsgApp(BootloaderMsg);
                s_g_bootloader_msg = TRUE;
            }
            if ((TRUE == PowerSaveDataMsgSys())||(TRUE == WDTWakeUpIfReset()))
            {
				Meter_ResetCountAdd(0x01);
                NVIC_SystemReset();     //reset //重启
            }
            s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S0;
        }
        break;
    default:
        break;
    }
}
/*
 *
 *
 *
 *
 *
 *
 *                 接口设计
 *
 *
 *
 *
 *
 *
 */
/****************************************************************
Function:    void Gp22SaveDataMotinor(void)
Description:  GP22数据存储防护
Input:
Return:
Others:
 *****************************************************************/
void Gp22SaveDataMotinor(void)
{
    To_Float_GP30 gp22_temp_flow;
    switch (gp22_date_save_state)
    {
        case GP22_APP_MONITOR_S(0):
		{
			RtccSetTimer(TIMER_DATE_SAVE_MONITOR, 60); //1min
			gp22_date_save_state = GP22_APP_MONITOR_S(1);
			break;
		}
        case GP22_APP_MONITOR_S(1):
        {
            if(0==RtccCheckTimer(TIMER_DATE_SAVE_MONITOR))
            {
                gp22_temp_flow.gp30_u32 =  Gp30CheckDataApp(2);
                if( (0==FrameCheckMsgApp(InitialDataMsg)) && ((gp22_temp_flow.gp30_float - old_monitor_flow.gp30_float) > (float)150) )//按30立方米每小时流量做限制
                { 				
                     gp22_app_data.s.total_flow.gp30_float = old_monitor_flow.gp30_float;
                     duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                }
                else
                {
                     FrameClearMsgApp(InitialDataMsg);
                     old_monitor_flow.gp30_float = gp22_temp_flow.gp30_float;
                }           
                gp22_date_save_state = GP22_APP_MONITOR_S(0);			
            }  		
            break;
        }
        default:
        {
            break;
        }
    }
}
/***********************基于温度的流量补偿系数计算****************
Function:  flow_coefficient_calculate    
Input: target_temperature ---目标温度   source_temperature--源温度，就是常温系数修正为1  Compensation_factor补偿因子
Return: 目标温度平滑后对应的流量补偿系数  
Others:  源温度：18℃~35℃  补偿系数为+1
 ****************************************************************/
float temperature_coefficient_calculate(float target_temperature,float Compensation_factor)
{
    float flow_coefficient_value = 1;
    float k = 0,b = 0;
    float temperature_diff = 0,source_temperature = 0; //温度差值
    
    if(target_temperature>=46)
    {
        target_temperature = (float)46;//超过46度，按照46度进行计算
        temperature_diff = (float)11;
        source_temperature = (float)35;
    }
    else if((target_temperature>35)&&(target_temperature<46))
    {
        temperature_diff = (float)11;
        source_temperature = (float)35;
    }
    else if((target_temperature>15)&&(target_temperature<18))
    {
        temperature_diff = (float)-3;
        source_temperature = (float)18;
    }
    else if(target_temperature<=15)
    {
        target_temperature = (float)15;//小于15度，按照15度进行计算
        temperature_diff = (float)-3;
        source_temperature = (float)18;
    }
    	
	if(temperature_diff!=0)
	{
		k = (Compensation_factor-1)/(temperature_diff);
	    b = 1 - k*source_temperature;
    
	    flow_coefficient_value = k*target_temperature + b;
	}
    
    return flow_coefficient_value;
}

/***********************基于流量的流量补偿系数计算****************
Function:  flow_coefficient_calculate    
Input: target_temperature ---目标温度   Compensation_factor_source对应的补偿因子 Compensation_factor_target对应的补偿因子 ins_flow_temp_float:当前的流速
Return: 目标流量平滑后对应的流量补偿系数  
Others:  只适用与1.3的R250Q2~0.33Q3流量范围
 ****************************************************************/
float flow_coefficient_calculate(float target_temperature,float Compensation_factor_source,float Compensation_factor_target,float ins_flow_temp_float)
{
    float flow_coefficient_value = 1;
    float k = 0,b = 0,x=0;
    float flow_diff = 0,temp_Compensation_factor_source = 0,temp_Compensation_factor_target = 0;
    
    
    if(ins_flow_temp_float > (R250Q2*(float)2))
    {
        flow_diff = Q3_6_6 - R250Q2*(float)2;//计算流量差值 
        x = R250Q2*(float)2;
    }   
    else 
    {
        flow_diff =  R250Q2*(float)2 - R250Q2*(float)1.3;//计算流量差值 
        x = R250Q2*(float)1.3;
    }
        
    temp_Compensation_factor_source = temperature_coefficient_calculate(target_temperature,Compensation_factor_source);//
    temp_Compensation_factor_target = temperature_coefficient_calculate(target_temperature,Compensation_factor_target);//
    
    k = (temp_Compensation_factor_target-temp_Compensation_factor_source)/(flow_diff);
	b = temp_Compensation_factor_source - k*x;
    
	flow_coefficient_value = k*ins_flow_temp_float + b;
    return  flow_coefficient_value;
}
/***********************流量系数防护****************
Function:    	ProtectFrameCheckParaApp(u32 parameter, u8 flag)
Description:    判断系数是否在合法区间内
Input: 			流量系数  
Return:     	流量系数
 ****************************************************************/
u32 ProtectParaApp(u32 parameter)
{	
    if((parameter < FLOW_COEFFICIENT_MIN)||(parameter > FLOW_COEFFICIENT_MAX))
    {
        FrameSetMsgApp(BootloaderMsg);
        parameter = 65536;//返回默认系数1 (放大65536倍)
    }
    return parameter;
}
/***********************流量计算****************
Function:    float modify_flow( float ins_flow_temp_float)
Description:  
Input: 瞬时流量 ins_flow_temp_float
Return:     
Others:
 ****************************************************************/
float modify_flow( float ins_flow_temp_float)
{
		float flow_temp_float,temp_value_float;
        seg_flow_coef = Read_Flow_CofficientApp();//2020-07-08
        temp_value_float = TempCheckValueApp();//读取瞬时温度
    
        if(temp_value_float<(float)18)
        {
            if((temp_value_float>(float)15)&&(temp_value_float<(float)18))//曲线过度
            {
                if((ins_flow_temp_float>0)&&(ins_flow_temp_float <= R400Q1 + R400Q1*(float)0.3))
                {                 
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[0].datas)));
                }
                else if(ins_flow_temp_float <= R400Q2 + R400Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[1].datas)));
                }
                else if(ins_flow_temp_float <= R250Q2 + R250Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[2].datas)));
                }
                else if(ins_flow_temp_float <= R250Q2*(float)2)
                {
                    if(65536==seg_flow_coef[3].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[2].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)));
                    }
                }
                else if(ins_flow_temp_float <= Q3_3_3)//0.33 * Q3
                {
                    if(65536==seg_flow_coef[3].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[4].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                         flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas));
                    }
                }            
                else if(ins_flow_temp_float <= Q3_6_6)//0.66 * Q3
                {
                    flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[4].datas));
                }
                else 
                {
                    flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[5].datas));
                }
            }
            else 
            {
                if((ins_flow_temp_float>0)&&(ins_flow_temp_float <= R400Q1 + R400Q1*(float)0.3))
                {                 
                      flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[0].datas));
                }
                else if(ins_flow_temp_float <= R400Q2 + R400Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[1].datas));
                }
                else if(ins_flow_temp_float <= R250Q2 + R250Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[2].datas));
                }
                else if(ins_flow_temp_float <= R250Q2*(float)2)
                {
                    if(65536==seg_flow_coef[3].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[2].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)));
                    }
                }
                else if(ins_flow_temp_float <= Q3_3_3)//0.33 * Q3
                {
                    if(65536==seg_flow_coef[3].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[3].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[4].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                         flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[4].datas)));
                    }
                }            
                else if(ins_flow_temp_float <= Q3_6_6)//0.66 * Q3
                {
                    flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[4].datas)));
                }
                else 
                {
                    flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[5].datas)));
                }
            }    
        }
        else if(temp_value_float<(float)35)
        {
            if((ins_flow_temp_float>0)&&(ins_flow_temp_float <= R400Q1 + R400Q1*(float)0.3))
            {
                 flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[6].datas));
            }
            else if(ins_flow_temp_float <= R400Q2 + R400Q2*(float)0.3)
            {
                 flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[7].datas));
            }
            else if(ins_flow_temp_float <= R250Q2 + R250Q2*(float)0.3)
            {
                 flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[8].datas));
            }
            else if(ins_flow_temp_float <= Q3_3_3)//0.33 * Q3 
            {
                flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[9].datas));
            }
            else if(ins_flow_temp_float <= Q3_6_6)//0.66 * Q3
            {
                flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[10].datas));
            }
            else 
            {
                flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[11].datas));
            } 
        }
        else
        {
           if((temp_value_float>(float)35)&&(temp_value_float<(float)46))//曲线过度
           {
               if((ins_flow_temp_float>0)&&(ins_flow_temp_float <= R400Q1 + R400Q1*(float)0.3))
                {                 
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[12].datas)));
                }
                else if(ins_flow_temp_float <= R400Q2 + R400Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[13].datas)));
                }
                else if(ins_flow_temp_float <= R250Q2 + R250Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[14].datas)));
                }
                else if(ins_flow_temp_float <= R250Q2*(float)2)
                {
                    if(65536==seg_flow_coef[15].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[14].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)));
                    }
                }
                else if(ins_flow_temp_float <= Q3_3_3)//0.33 * Q3
                {
                    if(65536==seg_flow_coef[15].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[16].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                         flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas));
                    }
                }            
                else if(ins_flow_temp_float <= Q3_6_6)//0.66 * Q3
                {
                    flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[16].datas));
                }
                else 
                {
                    flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[17].datas));
                }
           }
           else 
           {
               if((ins_flow_temp_float>0)&&(ins_flow_temp_float <= R400Q1 + R400Q1*(float)0.3))
                {                 
                      flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[12].datas));
                }
                else if(ins_flow_temp_float <= R400Q2 + R400Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float *Gp30DataToFloat(ProtectParaApp(seg_flow_coef[13].datas));
                }
                else if(ins_flow_temp_float <= R250Q2 + R250Q2*(float)0.3)
                {
                      flow_temp_float = ins_flow_temp_float * Gp30DataToFloat(ProtectParaApp(seg_flow_coef[14].datas));
                }
                else if(ins_flow_temp_float <= R250Q2*(float)2)
                {
                    if(65536==seg_flow_coef[15].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[14].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                      flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)));
                    }
                }
                else if(ins_flow_temp_float <= Q3_3_3)//0.33 * Q3
                {
                    if(65536==seg_flow_coef[15].datas)
                    {
                      flow_temp_float = ins_flow_temp_float * flow_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)),Gp30DataToFloat(ProtectParaApp(seg_flow_coef[16].datas)),ins_flow_temp_float);                                                                         
                    }
                    else 
                    {
                         flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[15].datas)));
                    }
                }            
                else if(ins_flow_temp_float <= Q3_6_6)//0.66 * Q3
                {
                    flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[16].datas)));
                }
                else 
                {
                    flow_temp_float = ins_flow_temp_float *temperature_coefficient_calculate(temp_value_float,Gp30DataToFloat(ProtectParaApp(seg_flow_coef[17].datas)));
                } 
           }           
        }
		return flow_temp_float;
}
/*************************************************
Function:  void FlowIntvalTimeLPTimer(void)
Description: 用于获取检定状态下两次计量的时间间隔
Input：
Return:
Others:
*************************************************/
void FlowIntvalTimeLPTimer(void)
{		
//	static u16 test_temp[50] = {0};
//	static u16 test_temp1=0;
	u16 temp = 0;//读取两次，防止累计误差
	temp = (u16)LPTimer1GetTick();
	intval_time = (u16)(temp - record_calculative_time);
//	test_temp[test_temp1]=intval_time;
//	test_temp1++;
//	if(50==test_temp1)
//	{
//		test_temp1=0;
//	}
//	if(0x200!=intval_time)
//	{
//		u8 a=1;
//	}
	record_calculative_time = temp;	
	if(intval_time >= 0x500)//如果间隔大于10s，认为异常，使用6s
	{
		intval_time = 0x300;
	}
}
/*************************************************
Function:  void RecordCalculativeIntvalTimeLPTimer(void)
Description: 用于记录距离上次计算累积量的间隔时间，方便复位后精确补偿
Input：
Return:
Others:
*************************************************/
void RecordCalculativeIntvalTimeLPTimer(void)
{	
	record_last_calculative_time = (u16)(LPTimer1GetTick() - record_calculative_time);
	if(record_last_calculative_time >= 0x500)//如果间隔大于10s，认为异常，使用1s
	{		
		if(01 == LcdCheckStateApp())//检定取0.5 ----实际测试
		{
			record_last_calculative_time = 0x80;	
		}
		else//非检定
		{
			record_last_calculative_time = 0x300;//按照6s计算
		}				
	}
}
/***********************任务建立接口***************************
Function:    void Gp22MachineApp (void)
Description:  应用层建立任务接口
Input:
Return:
Others:
 *****************************************************************/
void Gp30MachineApp(void)
{
	Gp22SampleApp();
	Gp22App();
	RecordCalculativeIntvalTimeLPTimer();
	if(10 == LcdCheckStateApp())//非检定
	{		
		switch (s_g_gp30_control_cal_state)
		{
			case GP30_CONTROL_S0:
			{
				if(0x08 == (RtccCheckMsg() & 0x08))//不上报就用RTC+GP30中断计算流量
				{
					if(TRUE== GP30_Check_Data_UpdateMsg())
					{
						RtccClearMsg(3);
						GP30_Clear_Data_UpdateMsg();
						FlowIntvalTimeLPTimer();
						s_g_gp30_control_cal_timer = Timer1usGetTick();  //内部时钟时间轴获取计算时间
						
						Gp22FilterCalculate(s_g_sample_flag);
						
						if(FixedTimeNbIoTUploadIfIdle() == TASK_BUSY)//上报期间用GP30中断计算流量
						{
							s_gp22_cal_interval_msg = TRUE;
							s_g_gp30_control_cal_state = GP30_CONTROL_S1;  // 内部时钟时间轴
						}
					}
				}
				break;
			}
			case GP30_CONTROL_S1:
			{
				if(TRUE== GP30_Check_Data_UpdateMsg())
				{
					RtccClearMsg(3);               
					GP30_Clear_Data_UpdateMsg();               
					FlowIntvalTimeLPTimer();				
					intval_time = Timer1usGetTick() - s_g_gp30_control_cal_timer;	//重新初始化intval_time计算间隔
					s_g_gp30_control_cal_timer = Timer1usGetTick();
					if(intval_time > 10000000)
					{
						intval_time = 2000000;
					}
					Gp22FilterCalculate(s_g_sample_flag);
					
					//if((FixedTimeNbIoTUploadIfIdle() == TASK_IDLE)&&(0==gp22_app_data.s.ins_flow))//是在上报完成基础上而且是静水
					if(FixedTimeNbIoTUploadIfIdle() == TASK_IDLE)//上报完成
					{
						s_g_gp30_control_cal_state = GP30_CONTROL_S0;  //LPTIMER时间轴
						s_gp22_cal_interval_msg = FALSE;
					}
				}
				break;
			}	
		}       
	}
	else if((01 == LcdCheckStateApp())&&(TRUE == GetLpTimerFlag()))//检定 该模式下用lptimer进行0.5s定时中断
	{
		
		s_alarma_stop_check_tick=Timer1usGetTick();
		if(TRUE== GP30_Check_Data_UpdateMsg())
		{
			GP30_Clear_Data_UpdateMsg();
			ClearLpTimerFlag();
			FlowIntvalTimeLPTimer();
			Gp22FilterCalculate(s_g_sample_flag);
			FrameClearMsgApp(MsgRtccAdjustTime);//清校时消息,该消息是防止检定0.5s超时复位用的
		}
	}
	else if((01 == LcdCheckStateApp())&&((Timer1usGetTick() - s_alarma_stop_check_tick) >= ALARMA_STOP_CHECK_TICKS))//检定闹钟flag如果超时不置位，则补偿置位间隔时间的流量，并且表计重启
	{
		if(FrameCheckMsgApp(MsgRtccAdjustTime) == 0)//如果不是校时引起的RTC中断延长一下,则复位
		{
			if(FixedTimeNbIoTUploadIfIdle() == TASK_IDLE)//如果NB模组没有工作
			{
				#if (HARDWARE_VERSION==0x18)//圆壳表主板 
				gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test + (((float)record_last_calculative_time/(float)128)+(float)0.33)*gp22_copy_temp_total_flow_float_test;//1s的累积量
				gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)0.33)*gp22_copy_temp_total_flow_float_test/(float)1000;				
				#elif  (HARDWARE_VERSION==0x14)//方壳表主板 
				gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test + (((float)record_last_calculative_time/(float)128)+(float)0.35)*gp22_copy_temp_total_flow_float_test;//1s的累积量
				gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)128)+(float)0.35)*gp22_copy_temp_total_flow_float_test/(float)1000;				
				#endif
				duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
                Meter_ResetCountAdd(0x02);
				NVIC_SystemReset();
			}
		}
        else
        {
            FrameClearMsgApp(MsgRtccAdjustTime);//清校时消息,该消息是防止检定0.5s超时复位用的
        }        
	}
	Gp22AppClearData();
	Gp22AppSaveData();
	//SendDataApp();
	Gp22SaveDataMotinor();
	
	#if WENDU_FANSUAN_OPEN
	FanSuan_Caliberate_Timeout();//单程时间校准超时防护函数
	#endif
}

/****************************************************************
Function:    void Gp22InitApp (void)
Description:  应用层初始化函数
Input:
Return:
Others:
 *****************************************************************/
void Gp30InitApp(void)
{
    gp30_event_flag.low_flow = FALSE;
    gp30_event_flag.no_water = FALSE;
    gp30_event_flag.out_temp = FALSE;
    gp30_event_flag.communication_err = FALSE;

    s_g_gp22_sample_app_state_num = GP22_APP_SAMPLE_S0;         //采样间隔
    s_g_gp22_app_state_num = GP22_APP_S0;                       // GP22数据计算处理机
    s_g_gp22_app_clear_data_state_num = GP30_APP_CLEAR_DATA_S0; //数据清零处理机
    s_g_gp22_app_save_data_state_num = GP30_APP_SAVE_S0;        //数据备份
	gp22_date_save_state = GP22_APP_MONITOR_S(0);
//	////////////////////////////////////////////////////////////////
//	///////////////////////////////////////////////////////////////////
//	////////////////////////////////////////////////////////////////////test
//    gp22_app_data.s.total_flow.gp30_float = 1200;
//	////////////////////////////////////////////////////////////////
//	///////////////////////////////////////////////////////////////////
//	////////////////////////////////////////////////////////////////////
    while (!g_gp22_init_flag)
    {
        EepMachineDriver(); //EE处理机
        FrameMachineApp();
        Gp22AppInitProcess();
    }
//	if(GP30_filter_last_value>GP30_DIFTOF_FILTER_ENABLE_MAX_VALUE)
//	{
//		GP30_filter_last_value=0;
//	}
//	if((0x33!=gp30_error_restart_flag)&&(0x77!=gp30_error_restart_flag))
//	{
//		gp30_error_restart_flag=0x33;//0x33表示GP30异常可以复位表计一次
//	}
    //软件复位+非第一次上电时温度的合法性判断2021-03-13
    if(TRUE == RAMDataVerify((u8*)&temp_calculate_last,sizeof(temp_calculate_last))||\
		(temp_calculate_last<0)||(temp_calculate_last>60))
    {
        temp_calculate_last = (float)20;//上电情况下默认20摄氏度
    }
        
	if((GP30_COPY_RESET_NORMAL_FLAG!=gp22_copy_reset_flag_test)&&(GP30_COPY_RESET_TEST_FLAG!=gp22_copy_reset_flag_test))
	{
		gp22_copy_reset_flag_test=GP30_COPY_RESET_NORMAL_FLAG;//0x55表示非检定的标志
        temp_calculate_last = (float)20;//硬件复位下，默认20度
	}
	if(GP30_COPY_RESET_TEST_FLAG==gp22_copy_reset_flag_test)//检定状态复位
	{
		Gp22SetSampleRateMsg(16); //采样频率16Hz
		FrameSetMsgApp(SetVerificationMsg);//设定为检定状态
	}
	else  
	{

		gp22_copy_total_flow_test=0;
		gp22_copy_temp_total_flow_float_test=0;
	}
   
}
/****************************************************************
Function:    u16 Gp30CheckErrDataApp (void)
Description:  查询错误信息
Input:
Return:
Others:
Bit0:当前流量>Q4或者<Q1    GP30_low_high_flow
Bit1:水温超出温度等级范围  GP30_out_temp
Bit2:倒转           GP30_reverse_flow
Bit3:无水           GP30_no_water
Bit4:GP30异常		GP30_err
Bit5:低流量报警     GP30_low_flow
Bit6:换能器接受信号低（低振幅）	GP30_low_amp;
Bit7:GP30通信异常  GP30_communication_err
Bit8:TOF overrun   GP30_TOF_overrun
Bit9:水流方向    water_reverse
*****************************************************************/
u16 Gp30CheckErrDataApp(void)
{
    u16 temp_flag = 0;    
    temp_flag = (  (gp30_event_flag.low_high_flow<<0)|
	               (gp30_event_flag.out_temp<<1)|
	               (gp30_event_flag.reverse_flow<<2)|
	               (gp30_event_flag.no_water<<3) | 
	               (gp30_event_flag.gp30_err<<4) | 
				   (gp30_event_flag.low_flow<<5)|
	               (gp30_event_flag.low_amp<<6) | 
				   (gp30_event_flag.communication_err<<7)|
	               (gp30_event_flag.tof_overrun<<8)|
				   (gp30_event_flag.water_direction<<9));
    return temp_flag;
}

/***********************查询当前数据(系统数据)*****************
Function:    u32 Gp30CheckDataApp (u8)
Description:  查询当前系统实时数据
Input:
输入参数对应返回值：
1：//瞬时流量
2：//累计流量
3：//温度

4：//up单程时间
5：//up脉冲宽度比
6：//up峰值

7：//down单程时间
8：//down脉冲宽度比
9：//down峰值

10：//时间差

Return:     输入参数对应返回值（4字节补码数据格式）：
Others:
 ****************************************************************/
u32 Gp30CheckDataApp(u8 data_para)
{
    switch (data_para)
    {
    case 1:
        return (gp22_app_data.s.ins_flow);
    case 2:
		if(gp22_app_data.s.total_flow.gp30_float<0)
		{
			gp22_app_data.s.total_flow.gp30_float=0;
            duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
		}
        return (gp22_app_data.s.total_flow.gp30_u32);
    case 3:
		if(gp22_app_data.s.total_flow_reverse.gp30_float<0)
		{
			gp22_app_data.s.total_flow_reverse.gp30_float=0;
		}
        return (gp22_app_data.s.total_flow_reverse.gp30_u32);
    case 4:
        return (gp22_app_data.s.TOF_up);
    case 5:
        return (gp22_app_data.s.ratio_up);
    case 6:
        return (gp22_app_data.s.peak_up);
    case 7:
        return (gp22_app_data.s.TOF_down);
    case 8:
        return (gp22_app_data.s.ratio_down);
    case 9:
        return (gp22_app_data.s.peak_down);
    case 10:
        return (gp22_app_data.s.TOF_diff);
	case 11:		
        return (gp22_app_data.s.up_tof_dif.gp30_u32);//校准时的UP单程时间校准差值*1000 将us转化为ns
    case 12: 
        return (gp22_app_data.s.down_tof_dif.gp30_u32);//校准时的DOWN单程时间校准差值*1000 将us转化为ns
    default:
        return (0xffffffff);
    }
}

u32 Gp30CheckTestDataApp(u8 data_para)
{
    switch (data_para)
    {
    case 1:
        return (gp22_test_data.s.ins_flow);
    case 2:
        return (gp22_test_data.s.total_flow.gp30_u32);
    case 3:
        return (gp22_test_data.s.total_flow_reverse.gp30_u32);
    case 4:
		#if WENDU_FANSUAN_OPEN
		gp22_test_data.s.TOF_up = GetTemperatureCalculateParameter(TOF_UP);
		#endif
        return (gp22_test_data.s.TOF_up);
    case 5:
        return (gp22_test_data.s.ratio_up);
    case 6:
        return (gp22_test_data.s.peak_up);
    case 7:
	   #if WENDU_FANSUAN_OPEN
		gp22_test_data.s.TOF_down = GetTemperatureCalculateParameter(TOF_DOWN);
		#endif
        return (gp22_test_data.s.TOF_down);
    case 8:
        return (gp22_test_data.s.ratio_down);
    case 9:
        return (gp22_test_data.s.peak_down);
    case 10:
        return (gp22_test_data.s.TOF_diff);
    case 12:
        return ( s_g_sample_sum_lcd);
    default:
        return (0xffffffff);
    }
}

/***********************启动停止测量*****************
Function:    void Gp30StartMeasureApp (u8 flag)
Description:  启动/停止流量测量
Input:
Return:     flag：1 启动流量测量     0：停止流量测量
Others:
 ****************************************************************/
void Gp30StartMeasureApp (u8 flag)
{
    u16 i;
    float temp_max =s_g_temp_data[0], temp_min =s_g_temp_data[0];
    
    start_measure_flag = flag;
	s_g_sample_start_flag=flag;
    
    if(flag) //启动时才清
    {        
        #if WENDU_FANSUAN_OPEN
		if(FrameCheckMsgApp(MsgCaliberate))//获取校准标志-----1: 表示允许校准 0：不允许校准
        {           		   	
           GP30_tof_buchang_filter(START_CALIBREATE);
        }		
        #endif
		
        for (i = 0; i < GP22_APP_DIFTOF_SIZE; i++)
        {
            s_g_diftof_data[i] = 0;
        }
        for (i = 0; i < GP22_APP_DIFTOF_SIZE_2; i++)
        {
            s_g_diftof_data_2[i] = 0;
        }
		#if EN_LARGE_FILITER
		for (i = 0; i < GP22_APP_DIFTOF_SIZE_3; i++)
        {
            s_g_diftof_data_3[i] = 0;
        }
		s_g_diftof_head_3_quotient=0;
		s_g_diftof_head_3 = 0;
		#endif
//        s_g_sample_flow_head = 0;
        s_g_diftof_head = 0;
        s_g_diftof_head_2 = 0;
		s_g_diftof_head_2_quotient=0;
        s_g_sample_total_sum = 0;
        s_g_diftof_for_total = FALSE; 

//        s_g_sample_total_sum = 0;
//        s_g_sample_add = 0;

        gp22_app_data.s.ins_flow = 0;
        gp22_test_data.s.ins_flow = 0;
        gp22_test_data.s.ins_flow_cnt = 0;//瞬时流量每计算一次就加1次
        gp22_test_data.s.ins_flow_sum = 0;//瞬时流量累计和
		gp22_test_data.s.ins_flow_sum_temp = 0;//
		gp22_app_data.s.ins_flow_max = 0;//
		gp22_app_data.s.ins_flow_min = 0;
		/*配合水台子*/
		for(i=0;i<MAX_TEMP_NUM;i++)
		{
			s_g_temp_data[i]=0;//给温度值采集数组赋初值零
		}
		s_g_sample_head=0;//数值采样头节点清零
        s_g_sample_length=0;//采样数组长度清零
        s_g_sample_ok_flag=0;//采样完成标志清?

        temp_sample_value=0;	//温度滤波值清零			
    }             
	else
	{   
        #if WENDU_FANSUAN_OPEN
		FrameClearMsgApp(MsgCaliberate);//清零 单程时间校准校准标志		
		GP30_tof_buchang_filter(STOP_CALIBREATE);//开始计算单程时间补偿数值
		#endif		
		if(s_g_sample_length>3)
        {  
			
            //1、进行温度滤波 方法：去除最大和最小值 然后剩下数据取平均值
            for(i=0;i<s_g_sample_length;i++)
            {
                if((s_g_temp_data[i]>=temp_max))
                {
                   temp_max = s_g_temp_data[i];
                }        
                if((s_g_temp_data[i]<=temp_min))
                {
                    temp_min = s_g_temp_data[i];
                }
                temp_sample_value+=s_g_temp_data[i];//将采集的温度滤波数值进行求和
            }
            temp_sample_value=(temp_sample_value-temp_max-temp_min)/(s_g_sample_length-2);//1、温度滤波均值 2、存储温度滤波均值
            
            s_g_sample_length=0;//采样数组长度清零
            s_g_sample_ok_flag=1;//采样完成标志置1
		}
		else //用实时温度值
		{
            s_g_sample_length=0;//采样数组长度清零
            s_g_sample_ok_flag=0;//采样完成标志清零
            temp_sample_value=0;//温度滤波数值清零
		}
		
	}
}


/***********************查询模块是否允许休眠*****************
Function:    u8 Gp30IfSleepApp (void)
Description:  查询模块是否允许休眠
Input:
Return:     SLEEP_TRUE：1 允许休眠     SLEEP_FALSE：0 不允许休眠
Others:
 ****************************************************************/
u8 Gp30IfSleepApp(void) 
{
    if ((s_g_gp30_control_cal_state == GP30_CONTROL_S0)&&(s_g_gp22_app_clear_data_state_num == GP30_APP_CLEAR_DATA_S0) && (s_g_gp22_app_save_data_state_num == GP30_APP_SAVE_S1) &&
        ((s_g_gp22_app_state_num == GP22_APP_S0) &&(0x04 == (Gp22CheckSampleMsg()&0x04))))
    {
        return TRUE;
    }
    return FALSE;
}

/***********************下初值(系统数据)*************************
Function:    u8 Gp30InitDataApp (u32 total_flow, u32 negative_total_flow)
Description:  下初值(系统数据):正向流量,逆向流量
Input:
Return:     TRUE:正常  FALSE：初值不合法
Others:
 ****************************************************************/
u8 Gp30InitDataApp(u32 total_flow, u32 negative_total_flow)
{
		gp22_app_data.s.total_flow.gp30_float = (float)(total_flow);//(float)bcdToHex32(total_flow);
        duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;
		total_flow_old.gp30_float = gp22_app_data.s.total_flow.gp30_float;
		gp22_copy_total_flow = gp22_app_data.s.total_flow.gp30_float;//2017 02,更改复位不丢数
//	    if(0x00002B1A==FrameCheckParaApp(FramePara_CCFlow))   //方式2
//	    {
		    gp22_app_data.s.total_flow_reverse.gp30_float = (float)(negative_total_flow);//(float)bcdToHex32(negative_total_flow);
//	    }
//	    else
//	    {
//		    gp22_app_data.s.total_flow_reverse.gp30_float = 0;
//	    }
		gp22_copy_total_flow_reverse = gp22_app_data.s.total_flow_reverse.gp30_float;//2017 02,更改复位不丢数
		Gp30_init_data_flag = TRUE;
	
    return TRUE;
}
/************************************************
Function:    void Gp30DiftofCalibration(void)
Description:  用于计算零流量校准补偿的时间差值
Input: 
Return:
Others:
 ****************************************************************/
void Gp30DiftofCalibration(void)
{
	float diftof_value=0;
	
//	temp_value_float = TempCheckValueApp();//获取当前温度值
//	diftof_value = (float)0.0010128*temp_value_float*temp_value_float - (float)0.0045999*temp_value_float - (float)0.30159;//不同温度下时间差变化量做了条曲线，输入温度，求出此温度下时间差应该被校准为多少ns
//	diftof_value = diftof_value/(float)250;//转化为程序里的GP30格式
	if(TRUE == CheckDiftofCalibrationFlag())
	{
		if(0x80000000 == (g_diftof_cal_data.s.diftof_calibration_value.data & (0x80000000)))//补偿值为负
		{
			calibration_diftof_value += Gp30DataToFloat(~(g_diftof_cal_data.s.diftof_calibration_value.data)+1);//已开启校准则还原原始时间差
		}
		else    //补偿值为正
		{
			calibration_diftof_value -= Gp30DataToFloat(g_diftof_cal_data.s.diftof_calibration_value.data);//已开启校准则还原原始时间差
		}
//		if(temp_value_float > (float)35)
//		{
//			calibration_diftof_value += DIFTOF_HIGH_TEMP_CALIBRATION_VALUE_FLOAT;//温度大于35，时间差提高1500ps，还原由于温度大于35度而减少的1500ps的时间差
//		}
	}
	diftof_value = -calibration_diftof_value;//计算时间差补偿值
	if((diftof_value<DIFTOF_CALIBRATION_MIN)||(diftof_value>DIFTOF_CALIBRATION_MAX))//0.04=10ns/250 如果校准值大于10ns或者小于-10ns则不校准
	{
		return;
	}
	if(diftof_value<0)
	{
		diftof_value = -diftof_value;
		g_diftof_cal_data.s.diftof_calibration_value.data = ~(FloatToGp30Data(diftof_value)-1);//转化为GP30格式		
	}
	else
	{
		g_diftof_cal_data.s.diftof_calibration_value.data = FloatToGp30Data(diftof_value);//转化为GP30格式
	}	
}
/************************************************
Function:    u8 CheckAutoCalibrationMsg(void)
Description:  检查零流量自动校准标志
Input:
Return: diftof_auto_calibration_msg
Others:
 ****************************************************************/
u8 CheckAutoCalibrationMsg(void)
{
	return diftof_auto_calibration_msg;
}
/************************************************
Function:    u8 CheckTransducerErrorMsg(void)
Description:  检查换能器是否冻坏标志
Input:
Return: transducer_err_msg
Others:
 ****************************************************************/
u8 CheckTransducerErrorMsg(void)
{
	return transducer_err_msg;
}
/************************************************
Function:    u8 CheckDiftofCalibrationFlag(void)
Description:  检查零流量校准开启标志
Input:
Return: True or False
Others:
 ****************************************************************/
u8 CheckDiftofCalibrationFlag(void)
{
	if(DIFTOF_CALIBRATION_FLAG ==g_diftof_cal_data.s.diftof_calibration_flag.data)
	{
		return TRUE;
	}
		return FALSE;
}
/************************************************
Function:    void Gp30TestFlowInit(void)
Description:  进入检定状态后,清除初始值
Input:
Return:
Others:
 ****************************************************************/
//void Gp30TestFlowInit(void)
//{
//    u8 i;

//    gp30_test_total_start_flow.gp30_u32 = gp22_app_data.s.total_flow.gp30_u32;

//    for (i = 0; i < GP30_APP_MAX_DATA; i++)
//    {
//        gp22_test_data.data[i] = 0;
//    }
//}
/************************************************
Function:    void VerificationResetCompensation(void)
Description:  检定复位补偿
Input:
Return:
Others:
 ****************************************************************/
//void VerificationResetCompensation(void)
//{
//	if((gp22_copy_temp_total_flow_float_test<(float)0)||(gp22_copy_temp_total_flow_float_test >(float)1500)||(gp22_copy_total_flow_test < (float)0))      
//	 {
//		 gp22_copy_temp_total_flow_float_test = 0;//保证
//		 gp22_copy_total_flow_test = 0;         
//	 }
//     if(Reset_GetFlag(ResetFlagMskWdt)) //如果是没及时喂狗导致的复位
//     {
//         Reset_ClearFlag(ResetFlagMskWdt);//清除看门狗复位源
//         gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test+gp22_copy_temp_total_flow_float_test*(float)4.0;
//		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (float)4.0*gp22_copy_temp_total_flow_float_test/(float)1000;
//     }
//     else//其他情况的复位	
//     {
//         gp22_test_data.s.total_flow.gp30_float=gp22_copy_total_flow_test+gp22_copy_temp_total_flow_float_test*(float)4.2;
//		 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (float)4.2*gp22_copy_temp_total_flow_float_test/(float)1000;
//     }
//}
/************************************************
Function:    void NormalResetCompensation(void)
Description:  非检定复位补偿
Input:
Return:
Others:
 ****************************************************************/
void NormalResetCompensation(void)
{
    if((gp22_copy_reset_flag_test == GP30_COPY_RESET_NORMAL_FLAG)&&(MCU_RESET_JUDGE_FLAG == MCU_reset_judge))  //非断电复位，且复位前是非检定
	{
		 if(TRUE == RAMDataVerify((u8*)&gp22_copy_temp_total_flow_float,sizeof(gp22_copy_temp_total_flow_float))||\
			 (gp22_copy_temp_total_flow_float<(float)0)||(gp22_copy_temp_total_flow_float>(float)56))//按照1000 000L/h计算 得到最大的瞬时累积量为560L
		 {
			 gp22_copy_temp_total_flow_float =0;						 
		 }
		 if(gp22_app_data.s.total_flow.gp30_float<(float)0)
		 {
			gp22_app_data.s.total_flow.gp30_float = 0;	
		 }
		 if(TRUE == RAMDataVerify((u8*)&record_last_calculative_time,sizeof(record_last_calculative_time)))
		 {
			record_last_calculative_time = 0;
		 }
		 
         #if (HARDWARE_VERSION==0x18)//圆壳表主板 
		  if(FrameCheckMsgApp(Msg_WdtReset)) //如果是没及时喂狗导致的复位
		 {
			 FrameClearMsgApp(Msg_WdtReset);//清除看门狗复位源
			 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)256)+(float)1.27)*gp22_copy_temp_total_flow_float; //2s的累积量  1.55-1.34-1.32-1.3
		 }
		 else 
		 {
			 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)256)+(float)0.21)*gp22_copy_temp_total_flow_float; //0.58-0.36-0.2-0.21
		 }
         #elif (HARDWARE_VERSION==0x14)//方壳表主板 
         if(FrameCheckMsgApp(Msg_WdtReset)) //如果是没及时喂狗导致的复位
		 {
			  FrameClearMsgApp(Msg_WdtReset);//清除看门狗复位源
			 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)256)+(float)1.25)*gp22_copy_temp_total_flow_float; // 1.6-
		 }
		 else 
		 {
			 gp22_app_data.s.total_flow.gp30_float = gp22_app_data.s.total_flow.gp30_float + (((float)record_last_calculative_time/(float)256)+(float)0.25)*gp22_copy_temp_total_flow_float;// 0.7
		 }
         #endif
		 duoble_total_flow.gp30_double = gp22_app_data.s.total_flow.gp30_float;   
	}
}

/***************************************************************
Function:    u8 Gp30CheckBootloaderMsgApp (void)
Description:
Input:
Return:
Others:
 ****************************************************************/
u8 Gp30CheckBootloaderMsgApp(void)
{
    if (s_g_bootloader_msg)
    {
        s_g_bootloader_msg = FALSE;
        return TRUE;
    }
    return FALSE;
}
/***************************************************************
Function:    u8 Gp30GetTestRamFlag (void)
Description: 获取检定状态下是否复位标志
Input:
Return:
Others:
 ****************************************************************/
u32 Gp30GetTestRamFlag(void)
{
   return gp22_copy_reset_flag_test;
}
/*2021-06-04
用于检测GP30中断标志，用于计算累积量的时候判断中断是否产生
*/
u8 GP30_Check_Data_UpdateMsg(void)
{
    return s_gp22_Data_Update_msg;
}
void GP30_Set_Data_UpdateMsg(void)
{
    s_gp22_Data_Update_msg=1;
}
void GP30_Clear_Data_UpdateMsg(void)
{
    s_gp22_Data_Update_msg=0;
}
/****************************************************************
Function:    void DiftofForTestbench(float temp_ins_flow_float)
Description:  计算瞬时流量的平均值
Input:        
Return:       无
 *****************************************************************/
void DiftofForTestbench(float temp_ins_flow_float)
{   
	
    if(0 == start_measure_flag) //检定状态，且上位机不允许采样
	{
		return;
	}
	
	gp22_test_data.s.ins_flow_cnt++;
	if(1 == gp22_test_data.s.ins_flow_cnt%20)
	{
		
		gp22_app_data.s.ins_flow_max = temp_ins_flow_float;
		gp22_app_data.s.ins_flow_min = temp_ins_flow_float;
		
	}
	if(temp_ins_flow_float > gp22_app_data.s.ins_flow_max) 
	{
		gp22_app_data.s.ins_flow_max = temp_ins_flow_float;
	}
	
	if(temp_ins_flow_float < gp22_app_data.s.ins_flow_min) 
	{
		gp22_app_data.s.ins_flow_min = temp_ins_flow_float;
	}
	
	gp22_test_data.s.ins_flow_sum_temp += temp_ins_flow_float; //阶段累加
	
	if(( gp22_test_data.s.ins_flow_cnt%20>=3 )||( 0 == gp22_test_data.s.ins_flow_cnt%20))	
	{
		temp_ins_flow_float = (gp22_test_data.s.ins_flow_sum+(gp22_test_data.s.ins_flow_sum_temp - gp22_app_data.s.ins_flow_max-gp22_app_data.s.ins_flow_min))/(gp22_test_data.s.ins_flow_cnt-((gp22_test_data.s.ins_flow_cnt+17)/20)*2);
		// 公式中(gp22_test_data.s.ins_flow_cnt-((gp22_test_data.s.ins_flow_cnt+17)/20)*2 不能约分，17的取值范围17、18、19
	}
	else
	{
		temp_ins_flow_float = (gp22_test_data.s.ins_flow_sum+(gp22_test_data.s.ins_flow_sum_temp ))/(gp22_test_data.s.ins_flow_cnt-(gp22_test_data.s.ins_flow_cnt/20)*2);// '/10=/20*2
	}
	
	if(0 == gp22_test_data.s.ins_flow_cnt%20)
	{
		gp22_test_data.s.ins_flow_sum += gp22_test_data.s.ins_flow_sum_temp - gp22_app_data.s.ins_flow_max-gp22_app_data.s.ins_flow_min;//gp22_test_data.s.ins_flow_sum_temp总累积量
		gp22_test_data.s.ins_flow_sum_temp = 0;//gp22_test_data.s.ins_flow_sum_temp20次积量
	}
	
	
//    gp22_test_data.s.ins_flow_cnt++;
//    gp22_test_data.s.ins_flow_sum += temp_ins_flow_float;//瞬时流量累加和
//    temp_ins_flow_float = gp22_test_data.s.ins_flow_sum / (float)gp22_test_data.s.ins_flow_cnt;//每次计算瞬时流量平均值

    if(gp22_test_data.s.ins_flow_cnt>INS_FLOW_CAL_CNT_MAX)//超过30分钟，瞬时流量重新开始记录
    {
        gp22_test_data.s.ins_flow_cnt = 0;
        gp22_test_data.s.ins_flow_sum = 0;
		gp22_test_data.s.ins_flow_sum_temp = 0;
		gp22_test_data.s.ins_flow_max = 0;
		gp22_test_data.s.ins_flow_min = 0;
    }    
	
    gp22_test_data.s.ins_flow = FloatToGp30Data(temp_ins_flow_float);         
    gp22_app_data.s.ins_flow = gp22_test_data.s.ins_flow;
    Gp22EventCheckApp(gp22_test_data.s.ins_flow);  //事件记录的检测与清除
}
#ifdef __cplusplus
}
#endif		//#ifdef __cplusplus
