
/*******************************************************************************
* @Copyright (c)    :(C)2017, Qingdao ieslab Co., Whn
* @FileName         :GP22Gas_lcd_app.c
* @Author           :Team
* @Version          :V1.0
* @Date             :2017年8月25日 11:00:39
* @Description      :the function of the entity of GP22Gas_lcd_app.c
*******************************************************************************/

#include "type.h"
#include "UWater_lcd_driver.h"
#include "UWater_lcd_app.h"
#include "UWater_gp22_app.h"
#include "UWater_rtcc_app.h"
#include "UWater_key_app.h"
#include "UWater_power_app.h"
#include "UWater_frame_app.h"
#include "UWater_pt_app.h"
#include "UWater_valve_app.h"
#include "UWater_valve_driver.h"
#include "nb_driver_bc25.h"
#include "sys_processor.h"
#include "UWater_sys.h"

/*------------------------------ Variable Define -------------------------------------*/
//状态机状态变量
static u8 s_lcd_status_state; //表计状态指示状态变量
//static u8 s_lcd_rf_state; //表计无线状态指示状态机状态变量
static u8 s_lcd_time_state; //定时切屏状态机状态变量
//static u8 s_lcd_ram_state; //RAM监测状态机状态变量
static u8 s_lcd_key_state; //按键切屏状态机状态变量
//static u8 s_lcd_init_state; //初始化状态机状态变量
//static u8 s_lcd_up_state= 0;
//static u8 s_lcd_characters_state=1;//固化字符指示状态变量
//static u8 s_lcd_VAL_state_SET = 1;//
//static u8 s_lcd_VAL_Met_state = 1;//
//static u8 s_lcd_VAL_Ram_state = 1;//
//static u8 s_lcd_VAL_GSM_state = 1;
//static u8 s_lcd_first_power_state;
//菜单号
static u8 s_fst_num; //一级菜单的菜单号
static u8 s_sec_num; //二级菜单的菜单号

//定时器状态量
//static u32 s_Lcd_time_old_num = 0;
//static u32 s_Lcd_time_num = 0;


//表计运行备份数据
static u8 s_vol_app_state; //记录上次电池电压状态
static u8 s_low_flow_alarm_app_state; //记录上次超低流量报警信号状态
static u8 s_alarm_app_state; //记录上次报警状态
static u8 s_failure_app_state; //记录上次故障状态
static u8 s_active_RF_app_state; //记录上次正在无线通信状态
static u8 s_valve_app_state; //记录上次阀门状态
//static u8 s_lcd_check_gp30_msg;
static u8 s_lcd_check_gp30_app_msg;
//static u8 key_message =0;
//static u8 s_lcd_valve_stat;//阀门状态变量
//static u8 s_pay_state=0;// 预付费状态

static u8 s_a1_index; //记录非检定状态下GP30数据索引
static u8 s_a2_index; //记录第二屏数据索引
static u8 s_a3_index; //记录第三屏数据索引
static u8 s_a4_index; //记录检定状态下GP30数据索引
static u32 s_a1_backup; //记录非检定状态下当前LCD显示的数据
static u32 s_a2_backup; //记录A2当前LCD显示的数据
static u32 s_a3_backup; //记录A3当前LCD显示的数据
static u32 s_a4_backup; //记录检定状态下当前LCD显示的数据
//static u16 s_nb_active_time;//NB活跃时间
/*------------------------------ function declare -------------------------------------*/


//static void LcdSet1sTimer(u32 time5ms_span);
//static u8 LcdCheck1sTimer(void);

static u32 GetA1Data(u8 index);
static u32 GetA2Data(u8 index);
static u32 GetA3Data(u8 index);
static u32 GetA4Data(u8 index);

static void LcdDispayFLoat(float lcd_data, u8 point);
static void LcdDispayU32Data(u32 lcd_data, u8 point);

static void LcdDisplayMenu(u8 num);
static void LcdDisplayA1(u8 num);
static void LcdDisplayA2(u8 num);
static void LcdDisplayA3(u8 num);
static void LcdDisplayA4(u8 num);




/****************************************/

/*************************************************
Function:void KeySet1sTimer(u16 time5ms_span)
Description: 设置5ms定时器
Input:	time5ms_span:时间
Return: SUCCESS：初始化成功；ERROR ：初始化失败
Others:内部接口
*************************************************/
//static void LcdSet1sTimer(u32 time1s_span)
//{
//    s_Lcd_time_num = time1s_span * 1000 * 1000;
//    s_Lcd_time_old_num = Timer1usGetTick();
//}
/*************************************************
Function: u8 KeyCheck1sTimer(void)
Description: 检查定时器当前值，如果为0则说明定时时间到
Input:	void
Return: 定时器当前值
Others:	内部接口
*************************************************/
//static u8 LcdCheck1sTimer(void)
//{
//    u32 tmp_count = 0;

//    tmp_count = Timer1usGetTick() - s_Lcd_time_old_num;

//    if(tmp_count >= s_Lcd_time_num)
//    {
//        return 0;
//    }
//    else
//    {
//        return 1;
//    }
//}
///*************************************************
//Function:void KeySet5msTimer(u16 time5ms_span)
//Description: 设置5ms定时器
//Input:	time5ms_span:时间
//Return: SUCCESS：初始化成功；ERROR ：初始化失败
//Others:内部接口
//*************************************************/
//static void LcdSet_first5msTimer(u32 time5ms_span)
//{
//    s_Lcd_first_time_num = time5ms_span * 1000 * 5;
//    s_Lcd_first_time_old_num = Timer1usGetTick();
//}
///*************************************************
//Function: u8 KeyCheck5msTimer(void)
//Description: 检查定时器当前值，如果为0则说明定时时间到
//Input:	void
//Return: 定时器当前值
//Others:	内部接口
//*************************************************/
//static u8 Lcd_firstCheck5msTimer(void)
//{
//    u32 tmp_count = 0;

//    tmp_count = Timer1usGetTick() - s_Lcd_first_time_old_num;

//    if(tmp_count >= s_Lcd_first_time_num)
//    {
//        return 0;
//    }
//    else
//    {
//        return 1;
//    }
//}
/*************************************************************************************
 * @fun_name   static void LcdUpdateData()
 * @brief      	LCD更新数据
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdUpdateData()
{
    if (s_fst_num == A1 && s_sec_num != AB0)
    {
        if (s_a1_backup != GetA1Data(s_a1_index))
        {
            LcdDisplayA1(s_sec_num);
        }
    }
    if (s_fst_num == A2 && s_sec_num != AB0)
    {
        if (s_a2_backup != GetA2Data(s_a2_index))
        {
            LcdDisplayA2(s_sec_num);
        }
    }
    if (s_fst_num == A3 && s_sec_num != AB0)
    {
        if (s_a3_backup != GetA3Data(s_a3_index))
        {
            LcdDisplayA3(s_sec_num);
        }
    }
    if (s_fst_num == A4 && s_sec_num != AB0)
    {
        if (s_a4_backup != GetA4Data(s_a4_index))
        {
            LcdDisplayA4(s_sec_num);
        }
    }
}

/*************************************************************************************
 * @fun_name   static void LcdDispayU32Data(u32 lcd_data, u8 point)
 * @brief      	LCD显示U32数
 * @param[in] 	u32 lcd_data, u8 point
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDispayU32Data(u32 lcd_data, u8 point)
{
    s8 index = 8;
     u8 n;
    if (lcd_data != 0)
    {
        while (lcd_data && index >= 0)
        {
            LcdDisplayData(index--, lcd_data % 10);
            lcd_data /= 10;
					
        }
    }
    else
    {
		n=6-point;
		while(n&&(point!=0))
		{
		    LcdDisplayData(index--,0);
		    n--;
		}
		if(0==point)  // whn  2017-10-12 
		{
		    LcdDisplayData(8,0);
		}
    }
    //显示小数点
    switch(point)
    {
		case 0:
		{
			LcdDisplayFun(LcdGetDisplayFun());
			break;
		}
		case 1:
		{
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P1); 
			break;
		}
		case 2:
		{
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P2);
			break;
		}
		case 3:
		{
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P3);
			break;
		}
		case 4:
		{
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P4);
			break;
		}
		default:
		{
		    LcdDisplayFun(LcdGetDisplayFun());
		}
    }
}
///*************************************************************************************
// * @fun_name   static void LcdDispayTimeU32Data(u32 lcd_time_data)
// * @brief      	LCD显示u32数
// * @param[in] 	u32 lcd_data, u8 point
// * @param[out] 	None
// * @retval     	None
// * @other     	None
// *************************************************************************************/
//static void LcdDispayTimeU32Data(u32 lcd_time_data)
//{
//    if (lcd_time_data <100)
//    {   
//        if (lcd_time_data == 0)
//        {
//            LcdDisplayData(7, 0);
//            LcdDisplayData(6, 0);
//            LcdDisplayData(5, 0);
//        }
//        else if(s_a1_backup < 10)
//        {
//            LcdDisplayData(6, 0);
//            LcdDisplayData(5, 0);
//            LcdDispayU32Data(s_a1_backup, 0);
//        }
//        else 
//        {
//            LcdDisplayData(5, 0);
//            LcdDispayU32Data(s_a1_backup, 0);
//        }
//    }
//    else
//    {  
//        s8 index = 7;
//        while (lcd_time_data && index >= 0)
//         {
//             LcdDisplayData(index--, lcd_time_data % 10);
//             lcd_time_data /= 10;
//         }
//    }
//}
/*************************************************************************************
 * @fun_name   static void LcdDispayFLoat(float lcd_data, u8 point)
 * @brief      	LCD显示浮点数
 * @param[in] 	float lcd_data, u8 point
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDispayFLoat(float lcd_data, u8 point)
{
    s8 index = 9;
    u64 udata = 0;
    float temp = lcd_data;
    if (temp < 0)
    {
        temp = -temp;
    }
	switch(point)
    {
		case 0:
		{
			temp=1000000*temp;
			LcdDisplayFun(LcdGetDisplayFun());//不显示小数点
			break;
		}
		case 1:
		{
			temp=100000*temp;
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P1 |FUN_P1G|FUN_P2G|FUN_P3G|FUN_P4G|FUN_P5G);//显示P1小数点  gaishanxiugai
			break;
		}
		case 2:
		{
			temp=10000*temp;
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P2 |FUN_P2G|FUN_P3G|FUN_P4G|FUN_P5G);//显示P2小数点
			break;
		}
		case 3:
		{
			temp=1000*temp;
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P3 |FUN_P3G|FUN_P4G|FUN_P5G);//显示P3小数点
			break;
		}
		case 4:
		{
			temp=100*temp;
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P4 |FUN_P4G|FUN_P5G); //显示P4小数点
			break;
		}
		case 5:
		{
			temp=10*temp;
			LcdDisplayFun(LcdGetDisplayFun() | FUN_P5 |FUN_P5G); //显示P5小数点
		  break;
		}
		default:
		{
			temp=temp;
			LcdDisplayFun(LcdGetDisplayFun());//不显示小数点
		}
    }
    udata = (u64) (temp );
    if (udata != 0)
    {
        while (udata && index >= 0)
        {
            LcdDisplayData(index--, udata % 10);
            udata /= 10;
        }
    }
    else
    {
        LcdDisplayData(9, 0);//gaishanxiugai
    }
    //显示小数点
    if (point > 0 && point < 6)
    {
        LcdDisplayFun(LcdGetDisplayFun() | (FUN_REVERSE << point));
        while (index >= (3 + point))//补零显示
        {
            LcdDisplayData(index--, 0);
        }
    }
    //显示负号
    if (index >=0&& (lcd_data < 0))
    {
        LcdDisplayData(index--, DIS_HG);
    }	 
}

/*************************************************************************************
 * @fun_name   static u32 GetA1Data(u8 index)
 * @brief      	LCD返回A1界面数据
 * @param[in] 	index
 * @param[out] 	data
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static u32 GetA1Data(u8 index)
{
    u32 data = 0;
	if (index == 0x55)
	{
		data = RtccGetWorkHourApp(); //获取工作累计时间
	}
	else if(index==GP30_APP_INS_FLOW)
	{
	    data=Gp30CheckDataApp(GP30_APP_INS_FLOW); //获取瞬时流量
	}   	
	else if( index == GP30_APP_TOTAL_FLOW)
	{
	    data =Gp30CheckDataApp(GP30_APP_TOTAL_FLOW) ; //获取正向累计流量
	}
	else if( index == GP30_APP_TOTAL_FLOW_REVERSE)
	{
	    data =Gp30CheckDataApp(GP30_APP_TOTAL_FLOW_REVERSE) ; //获取逆向累计流量
	}
	
    return data;
}

/*************************************************************************************
 * @fun_name   static u32 GetA2Data(u8 index)
 * @brief      	LCD返回A2界面数据
 * @param[in] 	index
 * @param[out] 	data
 * @retval     	None
 * @other     	None
 *************************************************************************************/

static u32 GetA2Data(u8 index)
{
     u32 data = 0;
    if (index == 0x11)
    {
        //当前日期
        static DateTime date;
       if (RtccGetDateTime(&date))//如果获得正确的时间
        {
            data |= ((u32) date.s.year) << 16;
            data |= ((u32) date.s.month) << 8;
            data |= date.s.day;
        }
        else
        {
            data = 0xEEEEEE;//当获取的时间不正确
        }
    }

    else if (index == 0x22) //当前时间
    {

        static DateTime time;
        if (RtccGetDateTime(&time))
        {
            data |= ((u32) time.s.hour) << 16;
            data |= ((u32) time.s.minute) << 8;
            data |= time.s.second;
        }
        else
        {
            data = 0xEEEEEE;
        }
    }
	else if(index==1) //口径
	{
	    data = FrameCheckParaApp(FramePara_DNx);//2019-11-11改善项目，将口径由 FrameCheckParaApp(19)改为 FrameCheckParaApp(0),兼容GP30		
	}
	else if(index==2)//版本号
	{
	    data = FrameCheckParaApp(FramePara_ProgVersion);
	}
	else if(index==4)
	{
	    data = FrameCheckParaApp(FramePara_MetAddr0_3) ; //获取表计地址低4
	}
	else if(index==3)
	{
	    data = FrameCheckParaApp(FramePara_MetAddr4); //获取表记地址高1
	}
	else if(index==5)//显示小流量系数
	{
	    data = Read_Flow_CofficientApp_For_LCD(6);
	}
	else if(index==6)//显示中1流量系数
	{
	    data=Read_Flow_CofficientApp_For_LCD(7);
	}
	else if(index==7)//显示中2流量系数
	{
	    data=Read_Flow_CofficientApp_For_LCD(8);
	}
	else if(index==8)//显示中3流量系数
	{
	    data=Read_Flow_CofficientApp_For_LCD(9);
	}
	else if(index==9)//显示大流量系数
	{
	    data=Read_Flow_CofficientApp_For_LCD(10);
	}
	else if(index==10)//显示boot版本号
	{
	    data=FrameCheckParaApp(FramePara_BootVersion);
	}
	else if(index ==11)//NB状态信息
	{
		data = sys_get_net_state();
	}
	return data;
}

/*************************************************************************************
 * @fun_name   static u32 GetA3Data(u8 index)
 * @brief      	LCD返回A3界面数据
 * @param[in] 	index
 * @param[out] 	data
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static u32 GetA3Data(u8 index)
{
    u8 data = 0;
    //u8 temp;        
    u8 Lcd_Frame_state;
    //temp = s_lcd_check_gp30_msg;
    Lcd_Frame_state = s_lcd_check_gp30_app_msg;
    if(index == 0x01)
    {
        if (0x08 ==(Lcd_Frame_state & (0x08)))//bit3 管道无水 data的0 1 2 3位作为1界面的异常，代表为换能器老化，水温超限，表计装反，管道无水
        {
              data |= 0x08;
        }   
        else
        {
              data &= ~(0x08);
        }
        if (0x04 ==(Lcd_Frame_state & (0x04)))// bit2 表计装反
        {
              data |= 0x04;
        }
        else
        {
              data &= ~(0x04);
        }
        if (0x02 == (Lcd_Frame_state & (0x02)))//bit1 水温超出温度等级范围
        {
              data |= 0x02;
        }
        else
        {
              data &= ~(0x02);
        }
        if(0x40 == (Lcd_Frame_state & 0x40))//bit6 换能器老化
        {
              data|= 0x01;
        }
        else
        {
              data &= (~0x01);
        }

    }
    else if (index == 0x02)//
    { 
//        s_lcd_valve_stat = ValveGetStateApp();
        //if(0x08 ==(temp &(0x08)))//bit3 GP30故障 data的4 5 6 7位作为2界面的异常
        if(0x10 ==(Lcd_Frame_state &(0x10)))
		{                       //分别代表为 GP30故障，温度传感器短路，温度传感器断路，无线通信异常
            data |= 0x10;
        }
        else
        {
            data &= ~(0x10);
        }
//        if(0x01==Check_Ip_Set_Message())//IP设置失败
//        {
//            data |=0x20;
//        }
//        else
//        {
//            data&=~(0x20);
//        }
        if(NB_SS_Control_GetPara(NB_UploadFailTimes))//检查是否需要补报发送
        {                      
            data |= 0x80;//需要补报，置起通信故障标志
        }
        else
        {
            data &= ~(0x80);//不需要补报，清除通信故障标志
        }
		#if defined(VALVE)//阀门故障标志
        if(Sys_data_object.P1.ies_valve_paras.valve_err)
        {
            data |= 0x40;
        }
        else
        {
            data &= ~0x40;
        }	
		#endif
    }
    return data;
}

/*************************************************************************************
 * @fun_name   static u32 GetA4Data(u8 index)
 * @brief      	LCD返回A4界面数据
 * @param[in] 	index
 * @param[out] 	data
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static u32 GetA4Data(u8 index)
{
    u32 data = 0;
	To_lcd_Float temp;

	if( index == GP30_APP_TOTAL_FLOW )//获取累计流量
	{
		data=Gp30CheckTestDataApp(GP30_APP_TOTAL_FLOW);
	}
	else if (index ==GP30_APP_INS_FLOW) //获取瞬时流量
	{
		data=Gp30CheckTestDataApp(GP30_APP_INS_FLOW_LCD);
	}
	else if(index==GP30_APP_DIFF)//TOF时间差
	{
	//	  data= Gp22TimeDiffer(4);
		data=Gp30CheckTestDataApp(GP30_APP_DIFF);
	}
	else if(index==GP30_APP_TOF)//单程时间up顺流时间
	{
		data= Gp30CheckTestDataApp(GP30_APP_TOF);//实时up单程时间
	}
	else if(index==GP30_APP_DOWN) //单程时间down逆流时间
	{
		data= Gp30CheckTestDataApp(GP30_APP_DOWN);//实时down单程时间
	}
	else if(index==GP30_APP_TEMP)//温度值
	{
		temp.gp22_float = TempCheckValueApp();
		return temp.gp22_u32;
	}   
	return data;
}

/*************************************************************************************
 * @fun_name   void LcdDisplayMenu(u8 num)
 * @brief      	LCD显示一级菜单
 * @param[in] 	num :1-5
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDisplayMenu(u8 num)
{
    //显示效果如下A1 A2 A3 A4 
    LcdClearAll(); //清屏
    if (num > 0 && num < 5)
    {
        LcdDisplayFun(LcdGetDisplayFun());
        LcdDisplayData(3, DIS_HG); //显示-
        LcdDisplayData(4, DIS_A); //显示A
        LcdDisplayData(5, num); //显示编号
        LcdDisplayData(6, DIS_HG); //显示-
    }
    else
    {
        LcdDisplayData(3, DIS_E); //显示E
        LcdDisplayData(4, DIS_E); //显示E
        LcdDisplayData(5, DIS_HG); //显示-
        LcdDisplayData(6, DIS_A); //显示A
    }
}

/*************************************************************************************
 * @fun_name   void LcdDisplayA1(u8 num)
 * @brief      	LCD显示二级菜单A1
 * @param[in] 	num:从1开始
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDisplayA1(u8 num)
{
    To_lcd_Float temp;
    LcdClearAll(); //清屏
    switch (num)
    {
		case A1B1:	
		{
	//			//精确5位小数
			LcdDisplayFun(A1_ACCUMULATE_FLOW); //累计流量(显示分辨率为0.001m3)
			s_a1_index = GP30_APP_TOTAL_FLOW;
			s_a1_backup = GetA1Data(s_a1_index);
			temp.gp22_u32 =s_a1_backup;

			if (temp.gp22_float < A1_TOTAL_DISPLAY_4_D)//小于10方显示5位
			{
				LcdDispayFLoat(temp.gp22_float / 100, 1); //累计流量(float(iEEE754),放大倍数100)
			}
			else  //其他显示3位小数
			{
				LcdDispayFLoat(temp.gp22_float / 100, 3); //累计流量(float(iEEE754),放大倍数100)
			}
			break;
		}
		case A1B2:	
    {
			//逆流显示
				LcdDisplayFun(A1_ACCUMULATE_FLOW_REVERSE); //累计逆向流量(显示分辨率为0.001m3)
        s_a1_index = GP30_APP_TOTAL_FLOW_REVERSE;
        s_a1_backup = GetA1Data(s_a1_index);
        temp.gp22_u32 =s_a1_backup;				
				
			
        if (temp.gp22_float < A1_TOTAL_DISPLAY_2_D)
        {
            LcdDispayFLoat(-(temp.gp22_float / 100), 3); //累计流量(float(iEEE754),放大倍数100)
        }
        else if (temp.gp22_float < A1_TOTAL_DISPLAY_1_D)
        {
            LcdDispayFLoat(-(temp.gp22_float / 100), 4); //累计流量float(iEEE754),放大倍数100)
        }
        else if (temp.gp22_float < A1_TOTAL_DISPLAY_0_D)
        {
            LcdDispayFLoat(-(temp.gp22_float / 100), 5); //累计流量(float(iEEE754),放大倍数100)
        }
				else  //数据过大，不显示小数点。
				{
					LcdDispayFLoat(-(temp.gp22_float / 100), 6); //累计流量(float(iEEE754),放大倍数100)
				}
        break;
		}
    case A1B3:
    {
        LcdDisplayFun(A1_TIME_FLOW); //瞬时流量(显示分辨率为0.00001m3/h)
        s_a1_index = GP30_APP_INS_FLOW;
        s_a1_backup = GetA1Data(s_a1_index);
        LcdDispayFLoat(s_a1_backup / (float)65536.00/1000, 1); //0.00001m3/h)
        break;
    }
    case A1B4:
    {
        LcdDisplayFun(A1_ACCUMULATE_TIME); //累计运行时间(分辨率为1h)
        s_a1_index = 0x55;
        s_a1_backup = GetA1Data(s_a1_index);
        if(s_a1_backup < 10)
        {
            LcdDisplayData(7, 0);
            LcdDisplayData(6, 0);
            LcdDispayU32Data(s_a1_backup, 0);
        }
        else if(s_a1_backup < 100)
        {
            LcdDisplayData(6, 0);
            LcdDispayU32Data(s_a1_backup, 0);
        }
        else
        {
            LcdDispayU32Data(s_a1_backup, 0);
        }
        break;
    }
	case A1B5://全显
    {
		LcdDisplayAll();
		break;
    }

    default:
    {
        LcdDisplayData(2, DIS_E); //显示E
        LcdDisplayData(3, DIS_E); //显示E
        LcdDisplayData(4, DIS_A); //显示A
        LcdDisplayData(5, DIS_1); //显示1
    }
    }
}

/*************************************************************************************
 * @fun_name   void LcdDisplayA2(u8 num)
 * @brief      	LCD显示二级菜单A2
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
//extern void setuploadflag(void);
//u8 uploadcnt=0;
static void LcdDisplayA2(u8 num)
{
    LcdClearAll(); //清屏
    LcdDisplayFun(LcdGetDisplayFun());//固化字符
    switch (num)
    {
    case A2B1:
    {
        //显示当前日期
        s_a2_index = 0x11;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDisplayData(1, (s_a2_backup >> 20)&0x0F);
        LcdDisplayData(2, (s_a2_backup >> 16)&0x0F);
        LcdDisplayData(3, DIS_HG); //显示-
        LcdDisplayData(4, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(5, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(6, DIS_HG); //显示-
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
	//	uploadcnt=0;
        break;
    }
    case A2B2:
    {
        //显示当前时分秒
        s_a2_index = 0x22;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDisplayData(1, (s_a2_backup >> 20)&0x0F);
        LcdDisplayData(2, (s_a2_backup >> 16)&0x0F);
        LcdDisplayData(3, DIS_HG); //显示-
        LcdDisplayData(4, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(5, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(6, DIS_HG); //显示-
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
	/*	uploadcnt++;
		if(uploadcnt==10)
		{
			setuploadflag();
		}*/
        break;
    }
    case A2B3:
    {
        //显示口径1-   20
        LcdDisplayData(1, 1);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 1;
        s_a2_backup = GetA2Data(s_a2_index); 
        LcdDispayU32Data((s_a2_backup / 16 * 10 + s_a2_backup % 16), 0);
        break;
    }
    case A2B4:
    {
        //显示版本号2-   b0.1
        LcdDisplayData(1, 2);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 2;
        s_a2_backup = GetA2Data(s_a2_index); //0xB0, 0x10, 0x00, 0x00
        LcdDisplayFun(FUN_P3);
        LcdDisplayData(5, (s_a2_backup >> 28)&0x0F);
        LcdDisplayData(6, (s_a2_backup >> 24)&0x0F);
        LcdDisplayData(7, (s_a2_backup >> 20)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 16)&0x0F);
        break;
    }
    case A2B5:
    {
        //显示出厂编号(通讯地址第一个字节）
        LcdDisplayData(1, 3);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 3;
        s_a2_backup = GetA2Data(s_a2_index);
		LcdDisplayData(3, (s_a2_backup >> 20)&0x0F);
        LcdDisplayData(4, (s_a2_backup >> 16)&0x0F);
		LcdDisplayData(5, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(6, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
        break;
    }
    case A2B6:
    {
        //地址后续字节
        s_a2_index = 4;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDisplayData(1, (s_a2_backup >> 28)&0x0F);
        LcdDisplayData(2, (s_a2_backup >> 24)&0x0F);
        LcdDisplayData(3, (s_a2_backup >> 20)&0x0F);
        LcdDisplayData(4, (s_a2_backup >> 16)&0x0F);
        LcdDisplayData(5, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(6, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
        break;
    }
    case A2B7:
    {
        //显示小流量系数
        LcdDisplayData(1, 4);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 5;
        s_a2_backup = GetA2Data(s_a2_index); //0x00010000;
        LcdDispayFLoat(s_a2_backup / 65536.00, 3);
        break;
    }
    case A2B8:
    {
        //显示中1流量系数
        LcdDisplayData(1, 5);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 6;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDispayFLoat(s_a2_backup / 65536.00, 3);
        break;
    }
    case A2B9:
    {
        //显示中2流量系数
        LcdDisplayData(1, 6);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 7;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDispayFLoat(s_a2_backup / 65536.00, 3);
        break;
    }
    case A2B10:
    {
        //显示中3流量系数
        LcdDisplayData(1, 7);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 8;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDispayFLoat(s_a2_backup / 65536.00, 3);
        break;
    }
    case A2B11:
    {
        //显示大流量系数
        LcdDisplayData(1, 8);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 9;
        s_a2_backup = GetA2Data(s_a2_index);
        LcdDispayFLoat(s_a2_backup / 65536.00, 3);
        break;
    }
	case A2B12:
    {
        //显示boot版本号
        LcdDisplayData(1, 9);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 10;
        s_a2_backup = GetA2Data(s_a2_index); 
        LcdDisplayFun(FUN_P3);
        LcdDisplayData(5, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(6, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
        break;
    }
	case A2B13:
    {
        //显示硬件版本- 00.14
        LcdDisplayData(1, 10);
        LcdDisplayData(2, DIS_HG);
        s_a2_index = 2;
        s_a2_backup = GetA2Data(s_a2_index); 
        LcdDisplayFun(FUN_P3);
        LcdDisplayData(5, (s_a2_backup >> 12)&0x0F);
        LcdDisplayData(6, (s_a2_backup >> 8)&0x0F);
        LcdDisplayData(7, (s_a2_backup >> 4)&0x0F);
        LcdDisplayData(8, (s_a2_backup >> 0)&0x0F);
        break;
    }
	case A2B14://NB状态信息
    {
        s_a2_index = 11;
        s_a2_backup = GetA2Data(s_a2_index); 
		UNION_4U8TOU32 tempdata;
		tempdata.datas = s_a2_backup;
		if((s_a2_backup&0xFF)==1)//初始化
		{
			LcdDisplayData(0, 11);
			LcdDisplayData(1, DIS_HG);
			//主流程
			LcdDisplayData(2, tempdata.data_buf[0]);
			LcdDisplayData(3, DIS_HG);
			//联网流程
			LcdDisplayData(4, tempdata.data_buf[1]/10);
			LcdDisplayData(5, tempdata.data_buf[1]%10);
			//cereg
			LcdDisplayData(6, DIS_HG);
			LcdDisplayData(7, tempdata.data_buf[2]);
			//cgatt
			LcdDisplayData(8, DIS_HG);
			LcdDisplayData(9, tempdata.data_buf[3]);
		}
		if((s_a2_backup&0xFF)==2)//连服务器
		{
			LcdDisplayData(0, 11);
			LcdDisplayData(1, DIS_HG);

			//主流程
			LcdDisplayData(2, tempdata.data_buf[0]);
			LcdDisplayData(3, DIS_HG);
			//联网流程
			LcdDisplayData(4, tempdata.data_buf[1]/10);
			LcdDisplayData(5, tempdata.data_buf[1]%10);
			//cereg
			LcdDisplayData(6, DIS_HG);
			LcdDisplayData(7, tempdata.data_buf[2]);
			//cgatt
			LcdDisplayData(8, DIS_HG);
			LcdDisplayData(9, tempdata.data_buf[3]);
		}
		if((s_a2_backup&0xFF)==3)//信号相关值
		{
			//RSRP
			LcdDisplayData(0, DIS_HG);
			LcdDisplayData(1, (tempdata.data_buf[1]/100));
			LcdDisplayData(2, (tempdata.data_buf[1]/10)%10);
			LcdDisplayData(3, (tempdata.data_buf[1]%10));
			//SNR
			if(tempdata.data_buf[2]&0x80)//负数
			{
				LcdDisplayData(4, DIS_HG);
				LcdDisplayData(5, (tempdata.data_buf[2]&0x7F)/10);
				LcdDisplayData(6, (tempdata.data_buf[2]&0x7F)%10);
			}
			else
			{
				LcdDisplayData(4, DIS_BLANK);
				LcdDisplayData(5, (tempdata.data_buf[2]/10));
				LcdDisplayData(6, tempdata.data_buf[2]%10);
			}
			//CSQ
			LcdDisplayData(7, DIS_BLANK);
			LcdDisplayData(8, (tempdata.data_buf[3]/10));
			LcdDisplayData(9, (tempdata.data_buf[3]%10));
		}
		if((s_a2_backup&0xFF)==4)//蓝牙状态
		{
			LcdDisplayData(0, 11);
			LcdDisplayData(1, DIS_HG);
			//供电状态
			LcdDisplayData(2, (tempdata.data_buf[1]));
			//今日复位次数
			LcdDisplayData(3, DIS_HG);
			LcdDisplayData(4, tempdata.data_buf[2]/10);
			LcdDisplayData(5, tempdata.data_buf[2]%10);
		}
		
        break;
    }

    default:
    {
        break;
    }
    }
}
/*************************************************************************************
 * @fun_name   void LcdDisplayA3(u8 num)
 * @brief      	LCD显示二级菜单A3
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDisplayA3(u8 num)//查询异常MSG,相应位置1，报警发生
{
    LcdClearAll(); //清屏
    LcdDisplayFun(LcdGetDisplayFun());//固化字符
    switch (num)
    {
    case A3B1://报警1-0000
    {
        LcdDisplayData(1, 1);
        LcdDisplayData(2, DIS_HG);
        s_a3_index = 0x01;
        s_a3_backup = GetA3Data(s_a3_index);
        if ((s_a3_backup>>2) & 0x01)//显示在1-1000表计装反
        {
            LcdDisplayData(5, 1);
        }
        else
        {
            LcdDisplayData(5, 0);
        }
        if ((s_a3_backup>>3) & 0x01)//显示在1-0100管道无水
        {
            LcdDisplayData(6, 1);
        }
        else
        {
            LcdDisplayData(6, 0);
        }
        if ((s_a3_backup) & 0x01)// 显示在1-0010换能器老化
        {
            LcdDisplayData(7, 1);
        }
        else
        {
            LcdDisplayData(7, 0);
        }
        if((s_a3_backup>>1) & 0x01)//显示在1-0001水温超限
        {
            LcdDisplayData(8, 1);
        }
        else
        {
            LcdDisplayData(8, 0);
        }        
        break;
    }
    case A3B2://故障2-  0000
    {  
        LcdDisplayData(1, 2);
        LcdDisplayData(2, DIS_HG);
        s_a3_index = 0x02; 
        s_a3_backup = GetA3Data(s_a3_index);
        if ((s_a3_backup>>4) & 0x01)//显示在2-1000 GP30异常
        {
            LcdDisplayData(5, 1);
        }
        else
        {
            LcdDisplayData(5, 0);
        }
        if((s_a3_backup>>5) & 0x01)//显示在2-0100 温度传感器异常
        {
            LcdDisplayData(6, 1);
        }
        else
        {
            LcdDisplayData(6, 0);
        }
        if((s_a3_backup>>6) & 0x01)//阀门故障
        {
            LcdDisplayData(7, 1);
        }
        else
        {
            LcdDisplayData(7, 0);
        }
        if ((s_a3_backup>>7) & 0x01)//显示在2-0001 上报异常
        {
            LcdDisplayData(8, 1);
        }
        else
        {
            LcdDisplayData(8, 0);
        }
        break;
    }
    default:
    {
		break;
    }
    }
}

/*************************************************************************************
 * @fun_name   void LcdDisplayA4(u8 num)
 * @brief      	LCD显示二级菜单A4
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
static void LcdDisplayA4(u8 num)
{
    To_lcd_Float temp;
    float temp1;
    LcdClearAll(); //清屏
    switch (num)
    {
		case A4B1:	
		{
			//精确5位小数
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_ACCUMULATE_FLOW_NOTEST); //累计流量(检定时显示分辨率为0.00001m3,显示单位改为L,即0.01L)
			}
			else
			{
				LcdDisplayFun(A4_ACCUMULATE_FLOW); //累计流量(检定时显示分辨率为0.00001m3,显示单位改为L,即0.01L)
			}
			s_a4_index = GP30_APP_TOTAL_FLOW;
			s_a4_backup = GetA4Data(s_a4_index);
			temp.gp22_u32 =s_a4_backup;		
			LcdDispayFLoat(temp.gp22_float / 100000, 1);  //累计流量(float(iEEE754),放大100000)
			break;
		}
		case A4B2:
		{
			//精确5位小数
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_TIME_FLOW_NOTEST); // 瞬时流量(检定时显示分辨率为0.0001m3/h)
			}
			else
			{
				LcdDisplayFun(A4_TIME_FLOW); // 瞬时流量(检定时显示分辨率为0.0001m3/h)
			}
			s_a4_index = GP30_APP_INS_FLOW;
			s_a4_backup = GetA4Data(s_a4_index);
			LcdDispayFLoat(s_a4_backup/ 65536.00/1000, 1);//参数待定
			break;
		}
		case A4B3:
		{
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_TOF_TIME_NOTEST); // TOF时间差（分辨率为1h)
			}
			else
			{
				LcdDisplayFun(A4_TOF_TIME); // TOF时间差（分辨率为1h)
			}
			s_a4_index = GP30_APP_DIFF;
			s_a4_backup = GetA4Data(s_a4_index); 
			if (s_a4_backup >= 0x80000000)
			{
				s_a4_backup = s_a4_backup & 0x7FFFFFFF;
				temp1 = (float)((s_a4_backup) / 65536.0* (-25.0));//参数待定
			}
			else
			{    
				temp1 =(float)((s_a4_backup) / 65536.0*25.0); //参数待定
			}
				LcdDispayFLoat(temp1/100, 0);//ps
			break;
		}
		case A4B4:
		{
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_SINGLE_TIME_NOTEST); // 单程时间up(分辨率为1h)
			}
			else
			{
				LcdDisplayFun(A4_SINGLE_TIME); // 单程时间up(分辨率为1h)
			}
			LcdDisplayData(1, 1);
			LcdDisplayData(2, DIS_HG);
			s_a4_index = GP30_APP_TOF;
			s_a4_backup = GetA4Data(s_a4_index);
			temp1 =(float)(s_a4_backup / 65536.0*25.0);//参数待定
			LcdDispayFLoat(temp1/10000, 0); //单位为ns
			break;
		}
		case A4B5:
		{
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_SINGLE_TIME_NOTEST); // 单程时间down(分辨率为1h)
			}
			else
			{
				LcdDisplayFun(A4_SINGLE_TIME); // 单程时间down(分辨率为1h)
			}
		   LcdDisplayData(1, 2);
		   LcdDisplayData(2, DIS_HG);
		  
		   s_a4_index = GP30_APP_DOWN;
		   s_a4_backup = GetA4Data(s_a4_index);
		   temp1 = (float) ((s_a4_backup) / 65536.0*25.0 );//参数待定
		   LcdDispayFLoat(temp1/10000, 0); //单位为ns
		   break;
		}
		case A4B6:
		{
			if(Sys_data_object.P3.LCD_NoTestFlag == 0x55) 
			{
				LcdDisplayFun(A4_Tem_NOTEST); // 温度分辨率为0.1摄氏度
			}
			else
			{
				LcdDisplayFun(A4_Tem); // 温度分辨率为0.1摄氏度
			}
			#if WENDU_FANSUAN_OPEN
			LcdDisplayData(1, DIS_F);//显示F----只有反算程序显示	
			#endif
			s_a4_index = GP30_APP_TEMP;
			s_a4_backup = GetA4Data(s_a4_index);
			temp.gp22_u32 = s_a4_backup;
			LcdDispayFLoat(temp.gp22_float, 3); 
			break;
		}   
		default:
		{
			LcdDisplayData(3, DIS_E); //显示E
			LcdDisplayData(4, DIS_E); //显示E
			LcdDisplayData(5, DIS_A); //显示A
			LcdDisplayData(6, DIS_4); //显示4
		}
    }
}
/*************************************************************************************
 * @fun_name   void LcdInitApp()
 * @brief      	LCD应用层初始化
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
void LcdInitApp()
{
    //状态机状态变量
    s_lcd_status_state = 0; //表计状态指示状态机状态变量
//    s_lcd_rf_state = 0; //表计无线状态指示状态机状态变量
    s_lcd_time_state = 0; //定时切屏状态机状态变量
//    s_lcd_ram_state = 0; //RAM监测状态机状态变量
    s_lcd_key_state = 0; //按键切屏状态机状态变量
//    s_lcd_init_state = 0; //初始化状态机状态变量
//    s_lcd_characters_state=1;//初始化固化字符状态变量
//    s_lcd_valve_stat = 0;
//	  s_lcd_first_power_state = 0;
    //菜单号
	if(Gp30GetTestRamFlag() == GP30_COPY_RESET_TEST_FLAG)
	{
		s_fst_num = A4;
		s_sec_num = A4B1;
	}
	else
	{
		s_fst_num = A1; //一级菜单的菜单号
		s_sec_num = A1B1; //二级菜单的菜单号
	}

    //表计运行备份数据
    s_vol_app_state = NORMAL_POWER; //记录上次电池电压状态
//    s_valve_state = 0x40; //记录上次阀门状态
    s_low_flow_alarm_app_state = 0; //记录上次超低流量报警信号状态
    s_alarm_app_state = 0; //记录上次报警状态
    s_failure_app_state = 0; //记录上次故障状态
	s_valve_app_state = 0;
    s_active_RF_app_state =1; //记录上次正在无线通信状态 1为空闲
    s_a1_backup = 0; //记录非检定状态下当前LCD显示的数据
    s_a4_backup = 0; //记录检定状态下当前LCD显示的数据
}

/*************************************************************************************
 * @fun_name   u8 LcdCheckStateApp()
 * @brief      	LCD返回检定状态
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
u8 LcdCheckStateApp()
{
    if (s_fst_num == A4)
    {
        return 01;
    }
    else
    {
        return 10;
    }
}

/*************************************************************************************
 * @fun_name   u8 LcdIfSleepApp()
 * @brief      	LCD应用层是否允许休眠
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
u8 LcdIfSleepApp()
{
    if (s_fst_num == A2 && s_sec_num == A2B2)//系统时间界面不休眠
    {
        return FALSE;
    }
    else if (s_fst_num == A4 && s_sec_num != AB0)//检定状态不休眠
    {
        return FALSE;
    }
    else if (s_lcd_status_state != 0)//表计特殊状态显示完
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
/*************************************************************************************
 * @fun_name   u16 LcdCheckMeumApp()
 * @brief      	LCD返回菜单号
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
u16 LcdCheckMeumApp()
{
    return s_sec_num | ((u16) s_fst_num << 8);
}


/*******************************************************************************
 * @fun_name:	lcd_alarmCheckMsgSys()
 * @brief   :  报警检测
 * @param[in] :	None
 * @param[out]: None
 * @retval    : None
 * @other     :
 ******************************************************************************/
u8 lcd_alarmCheckWarningMsg(void)
{    
		if ((s_lcd_check_gp30_app_msg & 0x40)||  //低振幅
			(s_lcd_check_gp30_app_msg & 0x02)||  //水温超出温度等级范围
			(s_lcd_check_gp30_app_msg & 0x04)||  //倒转
			(s_lcd_check_gp30_app_msg & 0x08)    //无水 
		) //屏显报警
	 {
	    return 1;
	 }
     else
     {
	 	return 0; 
	 }
}
/*******************************************************************************
 * @fun_name:	lcd_alarmCheckMsgSys()
 * @brief   :  故障检测
 * @param[in] :	None
 * @param[out]: None
 * @retval    : None
 * @other     :
 ******************************************************************************/
u8 lcd_alarmCheckFaultMsg(void)//T2故障，屏显故障
{    
    if ((NB_SS_Control_GetPara(NB_UploadFailTimes)|| //需要补报，说明通信故障
        (s_lcd_check_gp30_app_msg & 0x10)) || //GPXX异常
        (s_lcd_check_gp30_app_msg & 0x80)  || //GPXX通信故障
        (s_lcd_check_gp30_app_msg & 0x01)     //过流
			 #if defined(VALVE)//阀门故障标志
		    ||(Sys_data_object.P1.ies_valve_paras.valve_err)
				#endif
		    ) 
        {
            return 1;
        }
        else
        {
            return 0; 
        }	 
}
/*******************************************************************************
 * @fun_name:	LcdDispalyMetStatus()
 * @brief   :   LCD实时显示表计报警、故障等状态(特殊字符)
 * @param[in] :	None
 * @param[out]: None
 * @retval    : None
 * @other     :
 ******************************************************************************/
void LcdDispalyMetStatus()
{
	s_lcd_check_gp30_app_msg =Gp30CheckErrDataApp();
    switch (s_lcd_status_state)
    {
        case 0:
        {
			if (PowerCheckStatusSys ()!= s_vol_app_state)//T5电压低
			{
				s_vol_app_state = PowerCheckStatusSys ();
				s_lcd_status_state = 1;
			}
			if ((s_lcd_check_gp30_app_msg & 0x20) != s_low_flow_alarm_app_state) //T4超低流量报警（bit5）
			{
				s_low_flow_alarm_app_state = s_lcd_check_gp30_app_msg & 0x20;
				s_lcd_status_state = 1;
			}
			if (lcd_alarmCheckWarningMsg() != s_alarm_app_state)//T1报警
			{
				s_alarm_app_state = lcd_alarmCheckWarningMsg();
				s_lcd_status_state = 1;
			}
			if (lcd_alarmCheckFaultMsg() != s_failure_app_state )//T2故障
			{
				s_failure_app_state =lcd_alarmCheckFaultMsg();
				s_lcd_status_state = 1;
			}
			#if defined(VALVE)
				if(ValveGetStateApp() != s_valve_app_state)	/*添加阀门显示*/
				{
					s_valve_app_state = ValveGetStateApp();
					s_lcd_status_state = 1;
				}	
			#endif			
            break;
        }
        case 1:
        {
            if (PowerCheckStatusSys () == LOW_POWER)//电压低
			{
			    LcdDisplayVol(1);
			}
            else
            {
                LcdDisplayVol(0);
            }
            if (s_low_flow_alarm_app_state == 0x20)//超低流量报警
            {
               LcdDisplayLowFlowAlarm(1);
            }
            else
            {
             LcdDisplayLowFlowAlarm(0);
            }
            if (s_alarm_app_state == 1)//报警
            {
                LcdDisplayAlarm(1);
            }
            else
            {
                LcdDisplayAlarm(0);
            }
            if (s_failure_app_state == 1)//故障
            {
                LcdDisplayFailure(1);
            }
            else
            {
                LcdDisplayFailure(0);
            }
            if(s_active_RF_app_state==0)//正在无线通信 0 代表繁忙
            {
             LcdDisplayActiveGPRS(1);
            }
            else
            {
             LcdDisplayActiveGPRS(0);
            }
			if(VALVE_STATE_CLOSE == s_valve_app_state ||VALVE_STATE_CLOSE_EMERGENCY == s_valve_app_state || VALVE_STATE_CLOSE_LOCK == s_valve_app_state)//阀门关闭
			{
				LcdDisplayValve(1);
			}
			else
			{
				LcdDisplayValve(0);
			}
            s_lcd_status_state = 0;
            break;
        }
		default:
		{
		    s_lcd_status_state = 0;
			break;
		}
    }
}

/*******************************************************************************
 * @fun_name:	LcdDisplayTimeUpChange()
 * @brief   :   LCD定时切屏状态机
 * @param[in] :	None
 * @param[out]: None
 * @retval    : None
 * @other     :
 ******************************************************************************/
void LcdDisplayTimeUpChange()
{
    switch (s_lcd_time_state)
    {
		case 0://设置屏幕保持时间
		{
			if ((s_fst_num == A1 && s_sec_num != A1B1 ) || s_fst_num == A2 || s_fst_num == A3)
			{
				RtccSetTimer(RTCC_TIMER_LCD_NUM, 60); //60s
				s_lcd_time_state = 1;
			}
			else if (s_fst_num == A4)
			{
				RtccSetTimer(RTCC_TIMER_LCD_NUM, LCD_A4_TIME); //检定状态下无按键(3h)返回A1B1
				s_lcd_time_state = 1;
			}
			break;
		}
		case 1:
		{
			if (!RtccCheckTimer(RTCC_TIMER_LCD_NUM))//定时时间到,恢复默认界面
			{
				s_fst_num = A1;
				s_sec_num = A1B1;
				LcdDisplayA1(s_sec_num);
				s_lcd_time_state = 0;
			}
			break;
		}
		default:
		{
			s_lcd_time_state = 0;
			break;
		}
   }
}
/*******************************************************************************
 * @fun_name:	LcdDisplayKey()
 * @brief   :   LCD按键切屏状态机
 * @param[in] :	None
 * @param[out]: None
 * @retval    : None
 * @other     :
 ******************************************************************************/
void LcdDisplayKey()
{
	if(s_lcd_key_state == 0)//表计重启时界面的切换
	{
		s_lcd_key_state = 1;
		if(Gp30GetTestRamFlag() == GP30_COPY_RESET_TEST_FLAG)//判断是否软复位前在检定状态
		{
			s_fst_num = A4;
			s_sec_num = A4B1;
			LcdDisplayA4(s_sec_num);
		}
		else
		{
			s_fst_num = A1;
			s_sec_num = A1B1;
			LcdDisplayA1(s_sec_num);
		}
	}
	else if(KeyCheckLcdMsgApp(MENU_ONE))//一级菜单的切换
	{
		s_lcd_time_state = 0;
		//切一级菜单
		KeyClearLcdMsgApp(MENU_ONE);
		if ((s_fst_num == A4)&&(s_sec_num == A4B3))//检定状态在瞬时流量退检定
		{
			s_fst_num = A1;
			s_sec_num = AB0;
			LcdClearAll(); //清屏
			LcdDisplayMenu(s_fst_num);
		}
		else
		{
			if(s_fst_num != A4)//非检定界面的切换
			{
				s_fst_num %= AU;
				s_fst_num++;
				s_sec_num = AB0;
				LcdClearAll(); //清屏
				LcdDisplayMenu(s_fst_num);
			}
		}
	}
	else if(KeyCheckLcdMsgApp(MENU_TWO))//二级菜单切换
	{
		s_lcd_time_state = 0;
		//切二级菜单
		LcdClearAll(); //清屏
		KeyClearLcdMsgApp(MENU_TWO);
		if (s_fst_num == A1)
		{
			s_sec_num %= B1U;
			s_sec_num++;
			LcdDisplayA1(s_sec_num);
		}
		if (s_fst_num == A2)
		{
			s_sec_num %= B2U;
			s_sec_num++;
			LcdDisplayA2(s_sec_num);
		}
		if (s_fst_num == A3)
		{
			s_sec_num %= B3U;
			s_sec_num++;
			LcdDisplayA3(s_sec_num);
		}
		if (s_fst_num == A4)
		{
			s_sec_num %= B4U;
			s_sec_num++;
			LcdDisplayA4(s_sec_num);
		}
	}
	else if(KeyCheckLcdMsgApp(MENU_DEFAULT))//异常按键切换到默认菜单
	{
		s_lcd_time_state = 0;
		KeyClearLcdMsgApp(MENU_DEFAULT);
		if (s_fst_num != A4 )
		{
			LcdClearAll(); //清屏
			//切默认菜单
			s_fst_num = A1;
			s_sec_num = A1B1;
			LcdDisplayA1(s_sec_num);
		}
	}
	else if(KeyCheckLcdMsgApp(MENU_TEST))//按键进检定
	{
		s_lcd_time_state = 0;
		LcdClearAll(); //清屏
		//切检定菜单
		KeyClearLcdMsgApp(MENU_TEST);
		s_fst_num = A4;
		s_sec_num = AB0;
		LcdDisplayMenu(s_fst_num);
		LcdDisplayFun(LcdGetDisplayFun() | FUN_TEST );
	}
	else if (FrameCheckMsgApp(LcdDisplayAllMsg))//全显
	{   
		s_lcd_time_state = 0;
		LcdClearAll(); //清屏
		FrameClearMsgApp(LcdDisplayAllMsg);
		s_fst_num = A1;
		s_sec_num = A1B5;
		LcdDisplayA1(s_sec_num);
	}
	else if (FrameCheckMsgApp(SetVerificationMsg))//进检定
	{
		s_lcd_time_state = 0;
		LcdClearAll(); //清屏
		FrameClearMsgApp(SetVerificationMsg);
		s_fst_num = A4;
		s_sec_num = A4B1;
		LcdDisplayA4(s_sec_num);
	}
	else if (FrameCheckMsgApp(OutVerificationMsg))//退检定
	{   
		s_lcd_time_state = 0;
		LcdClearAll(); //清屏
		FrameClearMsgApp(OutVerificationMsg);
		s_fst_num = A1;
		s_sec_num = A1B1;
		LcdDisplayA1(s_sec_num);
	}
}
/*************************************************************************************
 * @fun_name   void LcdMachineApp(void)
 * @brief      	LCD应用层状态机
 * @param[in] 	None
 * @param[out] 	None
 * @retval     	None
 * @other     	None
 *************************************************************************************/
void LcdMachineApp(void)
{
	if(!RtccCheckTimer(RTCC_TIMER_LCD_METSTATUES))
	{
		RtccSetTimer(RTCC_TIMER_LCD_METSTATUES,LCD_UPDATE_TIME); //定时1秒
		LcdDispalyMetStatus();
		LcdDisplayTimeUpChange();
		LcdUpdateData();  
		#if MODULE_BLE_USED  
			if((BleConnectIfIdle() == TASK_IDLE)&&(BleIfSleep()==TASK_IDLE))
			{
				LcdDisplayActiveGPRS(0);//清除无线符号
			}
			else
			{
				LcdDisplayActiveGPRS(1);//显示无线符号
			}
		#else
			if(FixedTimeNbIoTUploadIfIdle() == TASK_IDLE) 
			{
				LcdDisplayActiveGPRS(0);//清除无线符号
			}
			else
			{
				LcdDisplayActiveGPRS(1);//显示无线符号
			}
		#endif
	} 
	LcdDisplayKey(); 
 }
/*void setLcdA2B14(void)
{
	s_lcd_time_state = 0;
	LcdClearAll(); //清屏
	s_fst_num = A2;
	s_sec_num = A2B14;
	LcdDisplayA2(s_sec_num);
}*/
 

 
 
