#ifndef UWATER_FRAME_FUNC_REPLAY_NB_H
#define	UWATER_FRAME_FUNC_REPLAY_NB_H

#include "type.h"

//////////////////////////////////////////积成规约控制字/////////////////////////////////////////////////////////
//写温度系数//CRC
#define FM_SET_TEMPERATURECOEFFICIENT_ARGUMENT_CTRL 0x45    
#define FM_SET_TEMPERATURECOEFFICIENT_REPLY_CTRL    0xB5
#define FM_SET_TEMPERATURECOEFFICIENT_DI0           0x35
#define FM_SET_TEMPERATURECOEFFICIENT_DI1           0xA0

//写流量系数
#define FM_SET_FLOWCOEFFICIENT_ARGUMENT_CTRL    0x46    
#define FM_SET_FLOWCOEFFICIENT_REPLY_CTRL       0xB6
#define FM_SET_FLOWCOEFFICIENT_DI0              0x36
#define FM_SET_FLOWCOEFFICIENT_DI1              0xA0

//启用关闭检定或红外功能//CRC
#define FM_SWITCH_VERIFICATION_OR_INFRARED_ARGUMENT_CTRL    0xBA    
#define FM_SWITCH_VERIFICATION_OR_INFRARED_REPLY_CTRL       0xBB
#define FM_SWITCH_VERIFICATION_OR_INFRARED_DI0              0x3B
#define FM_SWITCH_VERIFICATION_OR_INFRARED_DI1              0xA0

//加密读表数据//CRC和无磁兼容
#define FM_ENC_READ_DATA_ARGUMENT_CTRL          0x01           
#define FM_ENC_READ_DATA_REPLY_CTRL             0x81
#define FM_ENC_READ_DATA_DI0                    0x1F
#define FM_ENC_READ_DATA_DI1                    0x90

//读表地址
#define FM_READ_ADDR_ARGUMENT_CTRL			        0x03            
#define FM_READ_ADDR_REPLY_CTRL 			          0x83            
#define FM_READ_ADDR_DI0			                  0x0A           
#define FM_READ_ADDR_DI1 			                  0x81   

//阀门控制
#define VALVE_CONTROL_CTRL			            0x04           
#define ACK_VALVE_CONTROL_CTRL 			        0x84            
#define VALVE_CONTROL_DATA_ID0			        0x17            
#define VALVE_CONTROL_DATA_ID1                  0xA0            

//读取软件版本号//CS和无磁兼容
#define FM_READ_SWVERSION_ARGUMENT_CTRL         0x05       
#define FM_READ_SWVERSION_REPLY_CTRL            0x85
#define FM_READ_SWVERSION_DI0                   0x20
#define FM_READ_SWVERSION_DI1                   0xA0

//读取物理地址//CRC
#define FM_READ_MAC_ARGUMENT_CTRL               0x11       
#define FM_READ_MAC_REPLY_CTRL                  0x91
#define FM_READ_MAC_DI0                         0x1D
#define FM_READ_MAC_DI1                         0xA0

//请求写表地址控制码
#define FM_ENC_SET_ADDR_ARGUMENT_CTRL		   	    0x15            
#define FM_ENC_SET_ADDR_REPLY_CTRL  	 	        0x95            
#define FM_ENC_SET_ADDR_DI0		   	              0x18           
#define FM_ENC_SET_ADDR_DI1  	 	                0xA0     

//请求写初值控制码
#define FM_ENC_WRITE_INITVALUE_ARGUMENT_CTRL    0x16            
#define FM_ENC_WRITE_INITVALUE_REPLY_CTRL       0x96              
#define FM_ENC_WRITE_INITVALUE_DI0              0x16              
#define FM_ENC_WRITE_INITVALUE_DI1              0xA0     
//配置功能
#define FM_CFG_FUNCTIONCFG_ARGUMENT_CTRL                0x53            
#define FM_CFG_FUNCTIONCFG_REPLY_CTRL                   0xC3
#define FM_CFG_FUNCTIONCFG_DI0                          0x41
#define FM_CFG_FUNCTIONCFG_DI1                          0xA0  
//校时
#define FM_CALIBRATE_TIME_ARGUMENT_CTRL         0x22        
#define FM_CALIBRATE_TIME_REPLY_CTRL            0xA2
#define FM_CALIBRATE_TIME_DI0                   0x32
#define FM_CALIBRATE_TIME_DI1                   0xA0

//读出厂序列号//CS和无磁兼容
#define FM_READ_SERIALNUM_ARGUMENT_CTRL         0x31        
#define FM_READ_SERIALNUM_REPLY_CTRL            0xE1
#define FM_READ_SERIALNUM_DI0                   0x01
#define FM_READ_SERIALNUM_DI1                   0x89

//读温度系数//CS
#define FM_READ_TEMPERATURECOEFFICIENT_ARGUMENT_CTRL                0x3A    
#define FM_READ_TEMPERATURECOEFFICIENT_REPLY_CTRL                   0xBA
#define FM_READ_TEMPERATURECOEFFICIENT_DI0                          0x3A
#define FM_READ_TEMPERATURECOEFFICIENT_DI1                          0xA0

//清表数据//CRC
#define FM_CLEAR_METERDATA_ARGUMENT_CTRL        0x47        
#define FM_CLEAR_METERDATA_REPLY_CTRL           0xB7
#define FM_CLEAR_METERDATA_DI0                  0x37
#define FM_CLEAR_METERDATA_DI1                  0xA0

 //读流量系数//CS
#define FM_READ_FLOWCOEFFICIENT_ARGUMENT_CTRL   0x48       
#define FM_READ_FLOWCOEFFICIENT_REPLY_CTRL      0xB8
#define FM_READ_FLOWCOEFFICIENT_DI0             0x38
#define FM_READ_FLOWCOEFFICIENT_DI1             0xA0

 //设置为检定状态//CRC
#define FM_SET_VERIFICATIONSTATE_ARGUMENT_CTRL  0x49       
#define FM_SET_VERIFICATIONSTATE_REPLY_CTRL     0xB9
#define FM_SET_VERIFICATIONSTATE_DI0            0x39
#define FM_SET_VERIFICATIONSTATE_DI1            0xA0
#define FM_SET_VERIFICATIONSTATE_TOOL_DI1       0xA1 //脉冲检表工装进检定

//读检定数据//CS
#define FM_READ_VERIFICATIONDATA_ARGUMENT_CTRL                      0x4C            
#define FM_READ_VERIFICATIONDATA_REPLY_CTRL                         0xBC
#define FM_READ_VERIFICATIONDATA_DI0                                0x3C
#define FM_READ_VERIFICATIONDATA_DI1                                0xA0
#define FM_READ_VERIFICATIONDATA_TOOL_DI1                           0xA1

//读瞬时流量和温度//CS
#define FM_READ_INSTANTANEOUSFLOW_AND_TEMPERATURE_ARGUMENT_CTRL     0x4F    
#define FM_READ_INSTANTANEOUSFLOW_AND_TEMPERATURE_REPLY_CTRL        0xBF
#define FM_READ_INSTANTANEOUSFLOW_AND_TEMPERATURE_DI0               0x3F
#define FM_READ_INSTANTANEOUSFLOW_AND_TEMPERATURE_DI1               0xA0

//启动停止测试(只适用于检定状态)
#define FM_START_OR_STOP_TEST_ARGUMENT_CTRL             0x51            
#define FM_START_OR_STOP_TEST_REPLY_CTRL                0xC1
#define FM_START_OR_STOP_TEST_DI0                       0x3F
#define FM_START_OR_STOP_TEST_DI1                       0xA0

//(清)出厂启用
#define FM_START_OR_CLEAR_USING_ARGUMENT_CTRL           0x54            
#define FM_START_OR_CLEAR_USING_REPLY_CTRL              0xC4
#define FM_START_OR_CLEAR_USING_DI0                     0x42
#define FM_START_OR_CLEAR_USING_DI1                     0xA0

//读配置功能
#define FM_RD_FUNCTIONCFG_ARGUMENT_CTRL                 0x58            
#define FM_RD_FUNCTIONCFG_REPLY_CTRL                    0xB3
#define FM_RD_FUNCTIONCFG_DI0                           0x41
#define FM_RD_FUNCTIONCFG_DI1                           0xA0   

//RTCC校准
#define FM_RTC_CALIBTATION_ARGUMENT_CTRL                0x55           
#define FM_RTC_CALIBTATION_REPLY_CTRL                   0xC5
#define FM_RTC_CALIBTATION_DI0                          0x43
#define FM_RTC_CALIBTATION_DI1                          0xA0

//进入低功耗（测试规约）
#define FM_ENTER_LOWPOWER_ARGUMENT_CTRL                 0x56            
#define FM_ENTER_LOWPOWER_REPLY_CTRL                    0xC6
#define FM_ENTER_LOWPOWER_DI0                           0x44
#define FM_ENTER_LOWPOWER_DI1                           0xA0

//退出检定状态//CRC
#define FM_OUT_VERIFICATIONSTATE_ARGUMENT_CTRL          0x57       
#define FM_OUT_VERIFICATIONSTATE_REPLY_CTRL             0xC7
#define FM_OUT_VERIFICATIONSTATE_DI0                    0x45
#define FM_OUT_VERIFICATIONSTATE_DI1                    0xA0

//设置使动流量
#define FM_SET_START_FLOW_CTRL                          0x62       
#define FM_SET_START_FLOW_REPLY_CTRL                    0xD6
#define FM_SET_START_FLOW_DI0                           0x56
#define FM_SET_START_FLOW_DI1                           0x31
//读取使动流量
#define FM_READ_START_FLOW_CTRL                         0x63        
#define FM_READ_START_FLOW_REPLY_CTRL                   0xD7
#define FM_READ_START_FLOW_DI0                          0x57
#define FM_READ_START_FLOW_DI1                          0x32

//设置逆流计量开关
#define FM_SET_COUNTER_CURRENT_CTRL                     0x66            
#define FM_SET_COUNTER_CURRENT_REPLY_CTRL               0xCB            
#define FM_SET_COUNTER_CURRENT_CTRL_ID0                 0x42            
#define FM_SET_COUNTER_CURRENT_CTRL_ID1                 0x33  

//读取逆流计量开关
#define FM_READ_COUNTER_CURRENT_CTRL                    0x67        
#define FM_READ_COUNTER_CURRENT_REPLY_CTRL              0xCC            
#define FM_READ_COUNTER_CURRENT_CTRL_ID0                0x42            
#define FM_READ_COUNTER_CURRENT_CTRL_ID1                0x34   

//设置零流量校准开关
#define FM_SET_DIFTOF_CALIBRATION_CTRL                     0x68            
#define FM_SET_DIFTOF_CALIBRATION_REPLY_CTRL               0xD0            
#define FM_SET_DIFTOF_CALIBRATION_CTRL_ID0                 0x4A            
#define FM_SET_DIFTOF_CALIBRATION_CTRL_ID1                 0x36  

//硬件自检测
#define FM_TEST_SLEF_ARGUMENT_CTRL                      0xCF
#define FM_TEST_SLEF_REPLY_CTRL                         0xDF
#define FM_TEST_SLEF_DI0                                0x01
#define FM_TEST_SLEF_DI1                                0x30 
	 
/*NB新增通信规约*/
//深水读取历史数据
#define SS_READ_HIS_CTRL                        0x27     
#define SS_ACK_READ_HIS_CTRL                    0xa7
#define SS_READ_HIS_CTRL_ID0                    0x35
#define SS_READ_HIS_CTRL_ID1                    0xA0

#define QZ_READ_HIS_MONTH_CTRL_ID1              0x30 //月冻结数据
#define QZ_READ_HIS_DAILY_CTRL_ID1              0x31 //日冻结信息

//查询校准结果
#define CHECK_CALIBRATION_RESULT_CTRL           0x32            
#define ACK_CHECK_CALIBRATION_RESULT_CTRL       0xA2            
#define CHECK_CALIBRATION_RESULT_ID0            0x3A            
#define CHECK_CALIBRATION_RESULT_ID1            0xA0      

//远程升级_旧规约
#define FM_BOOTLOADER_ARGUMENT_CTRL             0x44 
#define FM_BOOTLOADER_REPLY_CTRL                0xB4            
#define FM_BOOTLOADER_DI0                       0x04           
#define FM_BOOTLOADER_DI1                       0xA1            

//远程升级_新规约
#define FM_BOOTLOADER_NEW_ARGUMENT_CTRL        0x6E
#define FM_BOOTLOADER_NEW_REPLY_CTRL           0xDE            
#define FM_BOOTLOADER_NEW_DI0                  0x2D           
#define FM_BOOTLOADER_NEW_DI1                  0x20   

//读写阀控参数 控制字和升级规约相同
#define ACK_SET_RD_VALVE_PARA2_CTRL            	0xF6
#define SET_RD_VALVE_PARA2_CTRL_DI0            	0x08
#define SET_RD_VALVE_PARA2_CTRL_DI1            	0x10 

//读取IP和端口号
#define READ_IP_PORT_CTRL                       0x4A            
#define ACK_READ_IP_PORT_CTRL                   0xBA           
#define READ_IP_PORT_DATA_ID0                   0x0A         
#define READ_IP_PORT_DATA_ID1                   0xA1            

 //写IP和端口号控制码
#define WRITE_IP_PORT_CTRL                      0x4B           
#define ACK_WRTIE_IP_PORT_CTRL                  0xBB           
#define WRITE_IP_PORT_DATA_ID0                  0x0B           
#define WRITE_IP_PORT_DATA_ID1                  0xA1           

//设置为全显状态
#define SS_SET_LCD_DISPLAY_CTRL                 0x61          
#define SS_ACK_SET_LCD_DISPLAY_CTRL             0xC8            
#define SS_SET_LCD_DISPLAY_CTRL_ID0             0x46           
#define SS_SET_LCD_DISPLAY_CTRL_ID1             0xA0 

//深水上传数据报文
#define SS_UPLOAD_CTRL                          0x67            
#define SS_ACK_UPLOAD_CTRL                      0xD6            
#define SS_UPLOAD_CTRL_ID0                      0x43          
#define SS_UPLOAD_CTRL_ID1                      0xA1           
#define SS_UPLOAD_CTRL_UDP_ID0                  0x31  //UDP上报数据数据标识
//短帧上报数据
#define SHORT_UPLOAD_CTRL                       0x9A           
#define SHORT_ACK_UPLOAD_CTRL                   0xEF            
#define SHORT_UPLOAD_CTRL_ID0                   0x02      
#define SHORT_UPLOAD_CTRL_ID1                   0x10    

//设置APN
#define SS_SET_APN_CTRL                         0x69    
#define SS_ACK_SET_APN_CTRL                     0xD8
#define SS_SET_APN_CTRL_ID0                     0x45
#define SS_SET_APN_CTRL_ID1                     0xA1

//读取APN
#define SS_RD_APN_CTRL                          0x70     
#define SS_ACK_RDT_APN_CTRL                     0xD9
#define SS_RD_APN_CTRL_ID0                      0x46
#define SS_RD_APN_CTRL_ID1                      0xA1

//深水统一设置参数 
#define SS_UNIFIED_SETTINGS_CTRL                0x71          
#define SS_ACK_UNIFIED_SETTINGS_CTRL            0xE9           
#define SS_UNIFIED_SETTINGS_CTRL_ID0            0x56       
#define SS_UNIFIED_SETTINGS_CTRL_ID1            0xa1                     

//深水设置大流量报警门限
#define SS_SET_THRESHOLD_CTRL                   0x72           
#define SS_ACK_SET_THRESHOLD_CTRL               0xda           
#define SS_SET_THRESHOLD_CTRL_ID0               0x47           
#define SS_SET_THRESHOLD_CTRL_ID1               0xa1            

 //深水读取大流量报警门限
#define SS_READ_THRESHOLD_CTRL                  0x73          
#define SS_ACK_READ_THRESHOLD_CTRL              0xdb           
#define SS_READ_THRESHOLD_CTRL_ID0              0x48           
#define SS_READ_THRESHOLD_CTRL_ID1              0xa1            

//深水设置上报起始时间、结束时间
#define SS_SET_START_END_CTRL                   0x74           
#define SS_ACK_SET_START_END_CTRL               0xdc            
#define SS_SET_START_END_CTRL_ID0               0x49            
#define SS_SET_START_END_CTRL_ID1               0xa1           

//深水读取上报起始时间、结束时间
#define SS_READ_START_END_CTRL                  0x75          
#define SS_ACK_READ_START_END_CTRL              0xdd          
#define SS_READ_START_END_CTRL_ID0              0x4a           
#define SS_READ_START_END_CTRL_ID1              0xa1          

//深水设置最小估长
#define SS_SET_STEPLENGTH_CTRL                  0x76           
#define SS_ACK_SET_STEPLENGTH_CTRL              0xde           
#define SS_SET_STEPLENGTH_CTRL_ID0              0x4b           
#define SS_SET_STEPLENGTH_CTRL_ID1              0xa1            

//深水读取最小估长
#define SS_READ_STEPLENGTH_CTRL                 0x77          
#define SS_ACK_READ_STEPLENGTH_CTRL             0xdf          
#define SS_READ_STEPLENGTH_CTRL_ID0             0x4c           
#define SS_READ_STEPLENGTH_CTRL_ID1             0xa1           

//深水读取水表时间、频点
#define SS_READ_TIME_FREQUENCY_CTRL             0x78         
#define SS_ACK_READ_TIME_FREQUENCY_CTRL         0xe0           
#define SS_READ_TIME_FREQUENCY_CTRL_ID0         0x4d           
#define SS_READ_TIME_FREQUENCY_CTRL_ID1         0xa1            

//深水设置重试次数
#define SS_SET_RETRY_COUNT_CTRL                 0x79           
#define SS_ACK_SET_RETRY_COUNT_CTRL             0xe1           
#define SS_SET_RETRY_COUNT_CTRL_ID0             0x4e            
#define SS_SET_RETRY_COUNT_CTRL_ID1             0xa1           

//深水读取重试次数
#define SS_READ_RETRY_COUNT_CTRL                0x7a           
#define SS_ACK_READ_RETRY_COUNT_CTRL            0xe2         
#define SS_READ_RETRY_COUNT_CTRL_ID0            0x4f        
#define SS_READ_RETRY_COUNT_CTRL_ID1            0xa1          

//深水设置上报数据频率
#define SS_SET_REPORTING_FREQUENCY_CTRL         0x7b          
#define SS_ACK_SET_REPORTING_FREQUENCY_CTRL     0xe3          
#define SS_SET_REPORTING_FREQUENCY_CTRL_ID0     0x50        
#define SS_SET_REPORTING_FREQUENCY_CTRL_ID1     0xa1           

//深水读取上报数据频率
#define SS_READ_REPORTING_FREQUENCY_CTRL        0x7c           
#define SS_ACK_READ_REPORTING_FREQUENCY_CTRL    0xe4          
#define SS_READ_REPORTING_FREQUENCY_CTRL_ID0    0x51          
#define SS_READ_REPORTING_FREQUENCY_CTRL_ID1    0xa1          

//深水统一读取参数
#define SS_UNIFIED_READ_CTRL                    0x7d         
#define SS_ACK_UNIFIED_READ_CTRL                0xe5            
#define SS_UNIFIED_READ_CTRL_ID0                0x52            
#define SS_UNIFIED_READ_CTRL_ID1                0xa1

//深水设置密集上报开始时间
#define SS_SET_REPORTSTARTTIME_CTRL             0x7e         
#define SS_ACK_SET_REPORTSTARTTIME_CTRL         0xe6           
#define SS_SET_REPORTSTARTTIME_CTRL_ID0         0x53        
#define SS_SET_REPORTSTARTTIME_CTRL_ID1         0xa1           

//深水读取密集上报开始时间
#define SS_READ_REPORTSTARTTIME_CTRL            0x7f           
#define SS_ACK_READ_REPORTSTARTTIME_CTRL        0xe7         
#define SS_READ_REPORTSTARTTIME_CTRL_ID0        0x54         
#define SS_READ_REPORTSTARTTIME_CTRL_ID1        0xa1           

//深水登录帧
#define SS_SIGN_IN_CTRL                         0x8f          
#define SS_ACK_SIGN_IN_CTRL                     0xe8         
#define SS_SIGN_IN_CTRL_ID0                     0x55           
#define SS_SIGN_IN_CTRL_ID1                     0xa1            

//读取IMEI控制码
#define SS_READ_IMEI_CTRL                       0x91           
#define SS_ACK_READ_IMEI_CTRL                   0xe9          
#define SS_READ_IMEI_CTRL_ID0                   0x56          
#define SS_READ_IMEI_CTRL_ID1                   0xa1 

//终端重启
#define SS_TERNAL_RESTART_CTRL                  0x92                
#define SS_ACK_TERNAL_RESTART_CTRL              0xEA             
#define SS_TERNAL_RESTART_CTRL_ID0              0x57               
#define SS_TERNAL_RESTART_CTRL_ID1              0xA1             

//读信号强度控制码
#define READ_SIGNAL_INTENSITY_CTRL              0x93            
#define ACK_READ_SIGNAL_INTENSITY_CTRL          0xEB          
#define READ_SIGNAL_INTENSITY_DATA_ID0          0x58         
#define READ_SIGNAL_INTENSITY_DATA_ID1          0xA1            

//清除失败次数
#define SS_CLEAR_FAIL_TIMES_CTRL                0x94            
#define SS_ACK_CLEAR_FAIL_TIMES_CTRL            0xEC
#define SS_CLEAR_FAIL_TIMES_CTRL_DI0            0x59 
#define SS_CLEAR_FAIL_TIMES_CTRL_DI1            0xA1 

//设置普通密钥
#define SS_SET_COMMON_KEY_CTRL                  0x95    
#define ACK_SS_SET_COMMON_KEY_CTRL              0xED
#define SS_SET_COMMON_KEY_CTRL_DI0              0x5A
#define SS_SET_COMMON_KEY_CTRL_DI1              0xA1

//读取普通密钥
#define SS_RD_COMMON_KEY_CTRL                   0x96   
#define ACK_SS_RD_COMMON_KEY_CTRL               0xEE
#define SS_RD_COMMON_KEY_CTRL_DI0               0x5B
#define SS_RD_COMMON_KEY_CTRL_DI1               0xA1

//读取RAM区数据
#define RD_RAM_CTRL                          	0x98    		
#define ACK_RD_RAM_CTRL                      	0xF0
#define RD_RAM_CTRL_DI0                      	0x5D
#define RD_RAM_CTRL_DI1                      	0xA1

 //发起短信上传,板卡测试阶段使用
#define SMS_UPLOAD_CTRL                         0xCB           
#define ACK_SMS_UPLOAD_CTRL                     0xDB            
#define SMS_UPLOAD_CTRL_ID0                     0x15           
#define SMS_UPLOAD_CTRL_ID1                     0xCC   



//******************************************江西水务定制规约-NB***********************************/
//设置密集存储间隔
#define FM_SET_MJJI_SPACE_TIME_CTRL               0x5A        
#define FM_SET_MJJI_SPACE_TIME_REPLY_CTRL         0xCA
#define FM_SET_MJJI_SPACE_TIME_DI0                0x48
#define FM_SET_MJJI_SPACE_TIME_DI1                0xA0

//读取密集存储间隔
#define FM_RED_MJJI_SPACE_TIME_CTRL               0x5B        
#define FM_RED_MJJI_SPACE_TIME_REPLY_CTRL         0xCB
#define FM_RED_MJJI_SPACE_TIME_DI0                0x49
#define FM_RED_MJJI_SPACE_TIME_DI1                0xA0

//设置采样频率  
#define FM_SET_SAMPLING_FREQUENCY_CTRL               0x5D        
#define FM_SET_SAMPLING_FREQUENCY_REPLY_CTRL         0xCD
#define FM_SET_SAMPLING_FREQUENCY_DI0                0x50
#define FM_SET_SAMPLING_FREQUENCY_DI1                0xA0

//读取采样频率
#define FM_READ_SAMPLING_FREQUENCY_CTRL               0x5E        
#define FM_READ_SAMPLING_FREQUENCY_REPLY_CTRL         0xCE
#define FM_READ_SAMPLING_FREQUENCY_DI0                0x51
#define FM_READ_SAMPLING_FREQUENCY_DI1                0xA0

//设置NB模组为PSM或断电模式
#define FM_SET_PSM_PWDOWN_CTRL               0x85        
#define FM_SET_PSM_PWDOWN_REPLY_CTRL         0x05
#define FM_SET_PSM_PWDOWN_DI0                0x04
#define FM_SET_PSM_PWDOWN_DI1                0xA0

//设置上报相关参数
#define FM_SET_RETRY_TIME_CTRL                         0x08     
#define FM_SET_RETRY_TIME_REPLY_CTRL                   0xB8
#define FM_SET_RETRY_TIME_DI0                          0x32
#define FM_SET_RETRY_TIME_DI1                          0xAA

//读取上报相关参数
#define FM_READ_RETRY_TIME_CTRL                         0x02    
#define FM_READ_RETRY_TIME_REPLY_CTRL                   0xB2
#define FM_READ_RETRY_TIME_DI0                          0x33
#define FM_READ_RETRY_TIME_DI1                          0xAB

#define ACK_UPLOAD_WITH_VAVLE_CTRL				0xC6			//携带控阀信息的周期应答帧
#define ACK_UPLOAD_WITH_VAVLE_CTRL_ID0			0x02			
#define ACK_UPLOAD_WITH_VAVLE_CTRL_ID1			0x10

//新增规约 
//以下为新增规约
#define IES_NEW_ADD_FRAME_CTRL					0x6F			//新增规约
#define ACK_IES_NEW_ADD_FRAME_CTRL				0xF7			//新增规约应答
#define COM_WATER_ID1_0x10						0x10			

#define READ_EEPROM_DATA_ID0					0x00			//读取任意位置EE数据
#define WRITE_EEPROM_DATA_ID0					0x01			//写任意位置EE数据
//#define SET_IR_USATR_AT_ID0						0x02			//进入红外透传
#define SET_UDP_IP_PORT_ID0						0x03			//设置udp的ip
#define READ_UDP_IP_PORT_ID0					0x04			//读取udp的ip
//#define SET_UPDATE_IP_PORT_ID0					0x05			//设置udp的ip
//#define READ_UPDATE_IP_PORT_ID0					0x06			//读取udp的ip
//#define READ_SUC_FAIL_RESET_TIMES_ID0			0x07			//读取发送成功、失败次数，复位次数
//#define SEND_UDP_CYCLE_DATA_ID0					0x08			//UDP发送的数据
//#define START_AUTO_CHECK_ID0					0x09			//启动自检
//#define READ_AUTO_CHECK_ID0						0x0A			//查询自检结果
////#define UPDATE_MCU_ID0							0x0B			//新远程升级
//#define JIANGE_TIME_SET_READ_ID0				0x0C			//重传间隔时间参数设置/读取
#define SET_EMERGENCY_NUM_ID0					0x0D			//设置紧急用水量
#define READ_EMERGENCY_NUM_ID0					0x0E			//读取紧急用水量
#define READ_TIMES_SOE_ID0						0x0F			//读取时间段SOE事件
#define READ_LAST_SOE_ID0						0x10			//读取最新SOE事件
#define READ_BATERY_PARA						0x11			//读取电量相关参数
#define CLEAR_BATERY_PARA                       0x12            //清除电量相关参数
#define FACTORY_TEST_UPLOAD_ID0                 0x1E           //厂区测试上传，只进行到附网完成
/////////////////////////////////////////////////积成规约数据结构///////////////////////////////////////////////
typedef struct 
{
	u8 head_site; //帧头位置
	u8 ctrl;
	u8 ack_ctrl;
	u8 len;
	u8 DI0;
	u8 DI1;
	u8 serial_num0;
	u8 serial_num1;
	u8 key_num;
	u8 end_site; //帧尾位置
	u8 check_len; //参与校验计算的数据长度
	u8 sta;  //GPRS加密状态0x80加密  0x40 主动发送(BIT2 = 0应答帧)
	u8 met_type;
} STRUCT_FRAME_IES;//存储数据帧重要内容

typedef union 
{
	struct 
	{
			u8 data0;
			u8 data1;
			u8 data2;
			u8 data3;
	} datas_map;
	u8 data_buf[4];
	u32 datas;
} SS_UNION_4U8TOU32;

typedef union 
{
	struct 
	{
			u8 data0;
			u8 data1;
	} datas_map;
	u8 data_buf[2];
	u16 datas;
} SS_UNION_2U8TOU16;

typedef struct{ 	
    SS_UNION_2U8TOU16 snr;
    u16 ecl;
    u16 rsrp; 
    u8 csq;
    u8 faile_times;//上报失败次数
    u8 format_error;//上报数据格式错误
	u32 cell_id;
	SS_UNION_2U8TOU16 report_fre;
}SIGNAL_INFO;

typedef union 
{
    SIGNAL_INFO SignalStruct;
    u8 SignalBuf[15];
} UNION_SIGNAL;
/******************************************************长帧上报数据格式*********************/
#define  STRU_DATA_LEN_IES  354
typedef union{
    struct{
        u8 data1;
        u8 data2;
    }datas_map;
    u16 u16_data;
}S_M_DATA_16,*p_S_M_DATA_16;
typedef union{
    struct{
        u16 RSRP_val;//信号强度
	    S_M_DATA_16 bat_val;//电池电压
        u16 snr_val;//信噪比
        u16 ecl_val;//无线信号覆盖等级
        u8 single_val;//csq 信号质量
        u8 bat_threshold_val;//电池欠压阈值
    }metinfo;
    u8 byte[10];
}MEASURE_UPLOAD_INFO;
typedef union {
	struct 
	{
		SS_UNION_4U8TOU32 CurrentFlow;//u8 CurrentFlow[4];
		SS_UNION_4U8TOU32 CurrentFlowReverse;//u8 CurrentFlowReverse[4];
		SS_UNION_4U8TOU32 CurrentFlowForward;//u8 CurrentFlowForward[4];
		u8 DailyHighestFlowAndTime[14];
		MEASURE_UPLOAD_INFO UploadInfo;
		u8 StepFlow[96]; //间隔流量
		u8 UploadTime[7];//上报时间
		u8 StepFlowStartTime[7];//间隔流量起始时间
		u8 StateBytes[5];//状态字
		SS_UNION_4U8TOU32 DailyActiveTime;//155字节
		//密集采集
		u8 MiJiCaiJiFlow[192];
		u8 MiJiCaiJiStartTime[7];
	}data;
	u8 buf[STRU_DATA_LEN_IES];//354
} STRU_UPLOAD_FRAME;

#define CURRENT_DATA_INFO_LEN  36
#define STEP_FLOW_START_ADDR   (0+CURRENT_DATA_INFO_LEN)
#define UPLOAD_TIME_ADDR       (STEP_FLOW_START_ADDR + 96)
#define STEP_FLOW_TIME_ADDR    (UPLOAD_TIME_ADDR + 7)

/******************************************************短帧上报数据格式*********************/
#define STRU_DATA_LEN_IES_SHORT     27 //短帧上报数据总长度
typedef union {
	struct 
	{
		SS_UNION_4U8TOU32 CurrentFlow_short;//u8 CurrentFlow[4];
		SS_UNION_4U8TOU32 null_buf;
        u8  RSRP_val;                            //信号强度1字节
		u16 bat_voltage;                         //电池电压2字节
		u16 mode_snr;                            //SNR2字节
		u8  mode_ecl;                             //ECL1字节
		u8  UploadTime[5];                       //上报时间 4字节		
		u8  StateBytes[4];                       //状态字5字节
		SS_UNION_2U8TOU16 soft_ver;              //软件版本2字节
		SS_UNION_2U8TOU16 temp_value;             //温度2字节
	}data;
	u8 buf[STRU_DATA_LEN_IES_SHORT];//27
} STRU_SHORT_UPLOAD_FRAME;

/******************************************************UDP上报数据格式*********************/
#define  STRU_DATA_LEN_IES_UDP  62
typedef union {
	struct 
	{
		SS_UNION_2U8TOU16 GP30_PeakUp;
		SS_UNION_2U8TOU16 GP30_PeakDown;
		SS_UNION_2U8TOU16 TempX100;
		SS_UNION_2U8TOU16 GP30_TempX100;
		SS_UNION_4U8TOU32 GP30_Diff;
		SS_UNION_4U8TOU32 GP30_DiffBig[4];
		u8 ResetCount;
		u16 ResetReason;
		u16 BateryPower;
		u16 Rsrp;
		u8  Snr;
		u8  UploadLastFailCode;
		SS_UNION_4U8TOU32 CellId;
		u8 Frequency;
		u8 Reverse[8];
		u8 Sta0;
		u8 Sta1;
		u8 Sta2;
		u8 Sta3;
		SS_UNION_4U8TOU32 CurrentFlow_short;
		SS_UNION_4U8TOU32 null_buf;
	}ProcMsgData;
	u8 buf[STRU_DATA_LEN_IES_UDP];//62
} STRU_PROC_MSG;

/**************************规约应答相关函数**********************************/
u8 up_deal_code_ies(void);
u8 check_met_addr_IES(u8 *p_buf,u8 *des_buf);
u8 crack_frame_IES_Base(u16 frame_lenth,u8 *frame_buffer, STRUCT_FRAME_IES* pFrameIES);
u8 crack_frame_IES(u16 frame_lenth,u8 *frame_buffer);
MEASURE_UPLOAD_INFO UploadGetInfo_Base(void);
void Frame_ack_IesBase(STRUCT_FRAME_IES temp_struct, u8* p_temp_buf, u16 p_temp_len, u8* p_send_buf, u16* p_send_len);

void Frame_ResetDealState_Ies(void);
void Frame_ack_IES(u8* p_send_buf, u16* p_send_len);
void Frame_nb_ss_upload(u8* p_send_buf, u16* p_send_len);
void Frame_nb_jx_upload(u8* p_send_buf, u16* p_send_len);
/**************************上报相关函数***************************************/
#define PERIOD_DATA_NUM  32 //周期数据记录总报数
#define JX_ONE_PACKET_COUNTS   45 //每包数据的间隔量条数


void GetUploadDataResetState_Product(void);
u8 GetUploadDataCheckIdle_Product(void);
u8 GetUploadDataCheckTask_Product(void);
void GetUploadDataMachine_Product(u8 data_step, u8* p_send_buf, u16* p_send_len);

void GetUploadDataResetState_IesUDP(void);
u8 GetUploadDataCheckIdle_IesUDP(void);
u8 GetUploadDataCheckTask_IesUDP(void);
void GetUploadDataMachine_IesUDP(u8 data_step, u8* p_send_buf, u16* p_send_len);

void SS_Store_InitApp(void);
u8 SS_Store_IfSleep(void);
/*****************************************************************************/
#endif	


