#ifndef UWATER_FRAME_FUNC_REPLAY_WT_H
#define	UWATER_FRAME_FUNC_REPLAY_WT_H

#include "type.h"

/************************************************水台子规约********************************************/
//固化物理地址//CRC
#define MFM_SOLIDIFY_MAC_ARGUMENT_CTRL           0x10    
#define MFM_SOLIDIFY_MAC_REPLY_CTRL              0x90
#define MFM_SOLIDIFY_MAC_DI0                     0x1C
#define MFM_SOLIDIFY_MAC_DI1                     0xA0

//模组/水台子规约：读表计通信地址----------------------------------------------------------
#define MFM_READ_ADDR_ARGUMENT_CTRL         0x03        
#define MFM_READ_ADDR_REPLY_CTRL            0x83
#define MFM_READ_ADDR_DI0                   0x0A
#define MFM_READ_ADDR_DI1                   0x81

//请求写表地址控制码
#define MFM_SET_ADDR_ARGUMENT_CTRL		   	    0x15            
#define MFM_SET_ADDR_REPLY_CTRL  	 	        0x95            
#define MFM_SET_ADDR_DI0		   	            0x18           
#define MFM_SET_ADDR_DI1  	 	                0xA0 

//模组/水台子规约：读出厂序列号------------------------------------------------------------
#define MFM_READ_SERIALNUM_ARGUMENT_CTRL         0x31        
#define MFM_READ_SERIALNUM_REPLY_CTRL            0xE1
#define MFM_READ_SERIALNUM_DI0                   0x01
#define MFM_READ_SERIALNUM_DI1                   0x89

//模组/水台子规约：读温度系数--------------------------------------------------------------
#define MFM_READ_TEMPERATURECOEFFICIENT_ARGUMENT_CTRL               0X4A 
#define MFM_READ_TEMPERATURECOEFFICIENT_REPLY_CTRL                  0xBA
#define MFM_READ_TEMPERATURECOEFFICIENT_DI0                         0x3A
#define MFM_READ_TEMPERATURECOEFFICIENT_DI1                         0xA0

//模组/水台子规约：读流量系数--------------------------------------------------------------
#define MFM_READ_FLOWCOEFFICIENT_ARGUMENT_CTRL   0x48       
#define MFM_READ_FLOWCOEFFICIENT_REPLY_CTRL      0xB8
#define MFM_READ_FLOWCOEFFICIENT_DI0             0x38
#define MFM_READ_FLOWCOEFFICIENT_DI1             0xA0

//模组/水台子规约：读检定数据--------------------------------------------------------------
#define MFM_READ_VERIFICATIONDATA_ARGUMENT_CTRL                      0x4C            
#define MFM_READ_VERIFICATIONDATA_REPLY_CTRL                         0xBC
#define MFM_READ_VERIFICATIONDATA_DI0                                0x3C
#define MFM_READ_VERIFICATIONDATA_DI1                                0xA0

//模组/水台子规约:退出检定状态-------------------------------------------------------------
#define MFM_OUT_VERIFICATIONSTATE_ARGUMENT_CTRL          0x57       
#define MFM_OUT_VERIFICATIONSTATE_REPLY_CTRL             0xC7
#define MFM_OUT_VERIFICATIONSTATE_DI0                    0x45
#define MFM_OUT_VERIFICATIONSTATE_DI1                    0xA0
//模组/水台子规约：读多项式建模系数--------------------------------------------------------
#define FM_READ_POLYNOMIALCOEFFICIENT_ARGUMENT_CTRL   0x65        
#define FM_READ_POLYNOMIALCOEFFICIENT_REPLY_CTRL      0xF1
#define FM_READ_POLYNOMIALCOEFFICIENT_DI0             0x61
#define FM_READ_POLYNOMIALCOEFFICIENT_DI1             0xA0
/************************************************水台子规约：动态解密的******************************/
//模组/水台子规约：读取物理地址--------------------------------------------------------
#define MFM_READ_MAC_ARGUMENT_CTRL             0x11       
#define MFM_READ_MAC_REPLY_CTRL                0x91
#define MFM_READ_MAC_DI0                       0x1D
#define MFM_READ_MAC_DI1                       0xA0
//模组/水台子规约：写温度系数-----------------------------------------------------
#define MFM_SET_TEMPERATURECOEFFICIENT_ARGUMENT_CTRL   0x45    
#define MFM_SET_TEMPERATURECOEFFICIENT_REPLY_CTRL      0xB5
#define MFM_SET_TEMPERATURECOEFFICIENT_DI0             0x35
#define MFM_SET_TEMPERATURECOEFFICIENT_DI1             0xA0

//模组/水台子规约：写流量系数------------------------------------------------------
#define MFM_SET_FLOWCOEFFICIENT_ARGUMENT_CTRL    0x46    
#define MFM_SET_FLOWCOEFFICIENT_REPLY_CTRL       0xB6
#define MFM_SET_FLOWCOEFFICIENT_DI0              0x36
#define MFM_SET_FLOWCOEFFICIENT_DI1              0xA0
//模组/水台子规约：设置为检定状态//CRC--------------------------------------------------
 //设置为检定状态//CRC
#define MFM_SET_VERIFICATIONSTATE_ARGUMENT_CTRL  0x49       
#define MFM_SET_VERIFICATIONSTATE_REPLY_CTRL     0xB9
#define MFM_SET_VERIFICATIONSTATE_DI0            0x39
#define MFM_SET_VERIFICATIONSTATE_DI1            0xA0
//模组/水台子规约：启动停止测试(只适用于检定状态)--------------------------------------------
#define MFM_START_OR_STOP_TEST_ARGUMENT_CTRL             0x51            
#define MFM_START_OR_STOP_TEST_REPLY_CTRL                0xC1
#define MFM_START_OR_STOP_TEST_DI0                       0x3F
#define MFM_START_OR_STOP_TEST_DI1                       0xA0
//模组/水台子规约：(清)出厂启用--------------------------------------------------------------
#define MFM_START_OR_CLEAR_USING_ARGUMENT_CTRL           0x54            
#define MFM_START_OR_CLEAR_USING_REPLY_CTRL              0xC4
#define MFM_START_OR_CLEAR_USING_DI0                     0x42
#define MFM_START_OR_CLEAR_USING_DI1                     0xA0
//模组/水台子规约： 写多项式建模系数--------------------------------------------------------
#define FM_SET_POLYNOMIALCOEFFICIENT_ARGUMENT_CTRL        0x64 
#define FM_SET_POLYNOMIALCOEFFICIENT_REPLY_CTRL           0xF0
#define FM_SET_POLYNOMIALCOEFFICIENT_DI0                  0x60
#define FM_SET_POLYNOMIALCOEFFICIENT_DI1                  0xA0

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_MBUS;//存储数据帧重要内容

u8 up_deal_code_mbus(void);
u8 crack_frame_MBUS(u16 frame_lenth,u8 *frame_buffer);
void Frame_ResetDealState_Mbus(void);
void Frame_CreatCrcCs_Ack(u8* p_send_buf, u16* p_send_len);
	
#endif	


