#ifndef		__MD_Connect_H_
#define		__MD_Connect_H_
/*H******************************************************************************
* NAME:         MD_Connect.h
*********************************************************************************/

typedef struct 
{
	u8 ADDRH;
	u8 ADDRL;
	u8 Communication;
	u8 CRYPTH;
	u8 CRYPTL;
} LORA_Set_Type;

//硬件定义
#define	MD_ConnectUsart1 USART2
#define	MD_Connect_DMA	DMA1

#define MD_Connect_TX1_DMAAddrSet(x) (DMA1_Stream6->M0AR = x)      //设置流量计接收缓存地址
#define MD_Connect_TX1_DMALenSet(x) (DMA1_Stream6->NDTR = x)   //设置发送DMA长度
#define MD_Connect_TX1_DMAStart()   DMA_Cmd(DMA1_Stream6,ENABLE) //开启发送DMA
#define MD_Connect_TX1_DMAStop()    DMA_Cmd(DMA1_Stream6,DISABLE) //开启发送DMA

#define MD_Connect_RX1_DMALenSet(x) (DMA1_Stream5->NDTR = x)   //设置DMA长度
#define MD_Connect_RX1_DMAStart()   DMA_Cmd(DMA1_Stream5,ENABLE) //开启DMA
#define MD_Connect_RX1_DMAStop()    DMA_Cmd(DMA1_Stream5,DISABLE) //开启DMA

#define	MD_ConnectUsart2 USART4
#define	MD_Connect_DMA	DMA1

#define MD_Connect_TX2_DMAAddrSet(x) (DMA1_Stream4->M0AR = x)      //设置流量计接收缓存地址
#define MD_Connect_TX2_DMALenSet(x) (DMA1_Stream4->NDTR = x)   //设置发送DMA长度
#define MD_Connect_TX2_DMAStart()   DMA_Cmd(DMA1_Stream4,ENABLE) //开启发送DMA
#define MD_Connect_TX2_DMAStop()    DMA_Cmd(DMA1_Stream4,DISABLE) //开启发送DMA

#define MD_Connect_RX2_DMALenSet(x) (DMA1_Stream2->NDTR = x)   //设置DMA长度
#define MD_Connect_RX2_DMAStart()   DMA_Cmd(DMA1_Stream2,ENABLE) //开启DMA
#define MD_Connect_RX2_DMAStop()    DMA_Cmd(DMA1_Stream2,DISABLE) //开启DMA

#define	MD_ConnectUsart3 USART5
#define	MD_Connect_DMA	DMA1

#define MD_Connect_TX3_DMAAddrSet(x) (DMA1_Stream7->M0AR = x)      //设置流量计接收缓存地址
#define MD_Connect_TX3_DMALenSet(x) (DMA1_Stream7->NDTR = x)   //设置发送DMA长度
#define MD_Connect_TX3_DMAStart()   DMA_Cmd(DMA1_Stream7,ENABLE) //开启发送DMA
#define MD_Connect_TX3_DMAStop()    DMA_Cmd(DMA1_Stream7,DISABLE) //开启发送DMA

#define MD_Connect_RX3_DMALenSet(x) (DMA1_Stream0->NDTR = x)   //设置DMA长度
#define MD_Connect_RX3_DMAStart()   DMA_Cmd(DMA1_Stream0,ENABLE) //开启DMA
#define MD_Connect_RX3_DMAStop()    DMA_Cmd(DMA1_Stream0,DISABLE) //开启DMA

#define	MD_ConnectUsart4 USART3
#define	MD_Connect_DMA	DMA1

#define MD_Connect_TX4_DMAAddrSet(x) (DMA1_Stream3->M0AR = x)      //设置流量计接收缓存地址
#define MD_Connect_TX4_DMALenSet(x) (DMA1_Stream3->NDTR = x)   //设置发送DMA长度
#define MD_Connect_TX4_DMAStart()   DMA_Cmd(DMA1_Stream3,ENABLE) //开启发送DMA
#define MD_Connect_TX4_DMAStop()    DMA_Cmd(DMA1_Stream3,DISABLE) //开启发送DMA

#define MD_Connect_RX4_DMALenSet(x) (DMA1_Stream1->NDTR = x)   //设置DMA长度
#define MD_Connect_RX4_DMAStart()   DMA_Cmd(DMA1_Stream1,ENABLE) //开启DMA
#define MD_Connect_RX4_DMAStop()    DMA_Cmd(DMA1_Stream1,DISABLE) //开启DMA


#define Check_NONE 0
#define Check_EVEN 1
#define Check_ODD  2                           

/*********************蓝天协议指令集************************/

#define BaudRateSync                         115200

#define	MDConnect_start                      0xF5  //通信头

#define	MDConnect_false		                   0x4E	//失败	

#define	MDConnect_succeed	                   0x59	//成功
#define	MDConnect_GetICCID                   0x5A	//

#define	C_MDConnectCmdWriteDensity           0XA2  //写密度
#define	C_MDConnectCmdReadDensity            0XA6  //读密度


#define	C_MDConnectCmdWritePrice             0XB2  //写单价
#define	C_MDConnectResumeFueling             0xB3  //继续
#define	C_MDConnectCmdWritePrsetSale         0xB5  //写预置金额
#define	C_MDConnectCmdReadPrice              0XB6  //读单价
#define	C_MDConnectCmdWritePrsetVolume       0xB9  //写预置体积
#define	C_MDConnectPauseFueling	             0xBA  //暂停

#define	C_MDConnectCmdStart		               0xC3  //开机
#define	C_MDConnectCmdReadTotal	             0xC5  //读总累
#define	C_MDConnectCmdReadSquadTop           0XC7  //读班累
#define	C_MDConnectCmdStop		               0xCA  //停机
#define	C_MDConnectCmdWriteTotal	           0xCE  //写总累

#define	C_MDConnectCmdWriteValveTurnOff      0xD2  //写提前关阀量PulseCoefficient
#define	C_MDConnectCmdReadState              0xD5  //读取加油机状态
#define	C_MDConnectCmdReadValveTurnOff       0xD6  //读提前关阀量
#define	C_MDConnectAakIDCardNummber          0xD7  //要ID卡卡号
#define	C_MDConnectCmdReadFuelState          0xD9  //读取加油机状态和流量信息

#define	C_MDConnectCmdWritePulseCoefficient  0xE1  //写PulseCoefficient
#define	C_MDConnectCmdReadPulseCoefficient   0xE2  //读
#define	C_MDConnectASKControlPower	         0xE5  //要控制权
#define	C_MDConnectReturnControlPower        0xE7  //还控制权
#define	C_MDConnectCmdClrSquadTop            0XEA  //清班累
#define	C_MDConnectChangePassWord	           0xEB  //改机械锁密码

#define	C_MDConnectCmdReadVersion            0x11  //读版本号
#define	C_MDConnectCmdSetBaudRate            0x12  //同步波特率
#define	C_MDConnectCmdSendFrame		           0x13  //传送帧

/*********************LY JP协议指令集************************/
#define	LY_MDConnectCmdPoll                  0XA1  //轮询
#define	LY_MDConnectCmdReadState             0XA2  //读状态
#define	LY_MDConnectCmdChoiceGun             0XA3  //选择枪
#define	LY_MDConnectCmdAuthorize             0XA4  //授权
#define	LY_MDConnectCmdWritePrice            0XA5  //写单价
#define	LY_MDConnectCmdACK0                  0XA6  //1030
#define	LY_MDConnectCmdACK1                  0XA7  //1031
#define	LY_MDConnectCmdHandshake             0XA8  //握手
#define	LY_MDConnectCmdReadTotal             0XA9  //读总累
#define	LY_MDConnectCmdDisauthorize          0XAA  //取消授权

/*********************Dart协议指令集************************/
#define	DART_MDConnectCmdPoll                  0XB1  //轮询
#define	DART_MDConnectCmdReadState             0XB2  //读状态
#define	DART_MDConnectCmdReStart               0XB3  //重连
#define	DART_MDConnectCmdAuthorize             0XB4  //授权
#define	DART_MDConnectCmdWritePrice            0XB5  //写单价
#define	DART_MDConnectCmdACK                   0XB6  //ACK
#define	DART_MDConnectCmdNAK                   0XB7  //NAK
#define	DART_MDConnectCmdReadVTotal            0XB8  //读油量总累
#define	DART_MDConnectCmdReadPTotal            0XB9  //读金额总累
#define	DART_MDConnectCmdDisauthorize          0XBA  //取消授权

/*********************液位仪协议指令集************************/
#define	YWY_MDConnectCmdReadData            0X31  //读数据
#define	YWY_MDConnectCmdWriteApacity        0X45  //下载罐容表

/*********************LORA协议指令集************************/
#define	LORA_ParameterSet                   0XFF  //LORA设置
/*********************RFID协议指令集************************/
#define	RFID_MDConnectCmdReadData            0XF1  //读单枪数据
#define	RFID_MDConnectCmdWriteCardInfo       0XF2  //
#define	RFID_MDConnectCmdWriteFullingInfo    0XF3  //
#define	RFID_MDConnectCmdReadVersion         0XF4  //
#define	RFID_MDConnectCmdWriteBindingInfo    0XF6  //发送绑定的枪号
#define	RFID_MDConnectCmdLossACK                 0XF7  //
#define	RFID_MDConnectCmdFindACK                 0XF8  //
#define	RFID_MDConnectCmdROMownload          0X05  //
#define	RFID_MDConnectCmdAllData         0X06  //读一个键盘所有枪的数据

/*********************英高协议指令集************************/
#define	YG_MDConnectCmdWritePrset             0x01  //写预置
#define	YG_MDConnectCmdWritePrice             0X02  //写单价
#define	YG_MDConnectCmdStop		                0x04  //停机
#define	YG_MDConnectCmdStart		              0x05  //授权
#define	YG_MDConnectControlMode	              0x06  //设置油机为联机或脱机模式，由命令参数决定
#define	YG_MDConnectCmdReadTotal	            0x07  //读总累
#define	YG_MDConnectCmdRemovePrset            0x08  //取消预置
#define	YG_MDConnectCmdSetTime                0x0C  //同步时间
#define	YG_MDConnectCmdInTestMode             0x0D  //同步时间
#define	YG_MDConnectCmdOutTestMode            0x0E  //同步时间
#define	YG_MDConnectCmdReadVersion            0X0F  //读取油机的软件版本号
#define	YG_MDConnectCmdUnLock                 0X10  //解锁
#define	YG_MDConnectCmdLock                   0X11  //锁定
#define	YG_MDConnectCmdReadFuelVolumeState    0x14  //读取加油机状态和流量信息
#define	YG_MDConnectCmdReadFuelSaleState      0x15  //回复金额
#define	YG_MDConnectCmdReadFuelRecord         0x16  //读取加油记录
#define	YG_MDConnectCmdReadFuelRecordNull     0x18  //回复记录空
#define	YG_MDConnectCmdReadFuelRecordConfirm  0x17  //加油记录确认

/*********************弘扬协议指令集************************/
#define	HY_MDConnectCmdWritePrice             0X80  //写单价
#define	HY_MDConnectCmdWritePrsetSale         0x89  //写预置金额
#define	HY_MDConnectCmdReadPrice              0X8C  //读单价
#define	HY_MDConnectCmdWritePrsetVolume       0x8B  //写预置体积
#define	HY_MDConnectCmdStart		              0x08  //开机
#define	HY_MDConnectCmdReadTotal	            0x8E  //读总累
#define	HY_MDConnectCmdStop		                0x10  //停机
#define	HY_MDConnectCmdReadFuelData           0x8F  //读取流量信息
#define	HY_MDConnectASKControlPower	          0x15  //要控制权
#define	HY_MDConnectReturnControlPower        0x14  //还控制权
/**********************蓝枫协议指令集******************************/
#define	LF_MDConnectCmdWritePrice             0XA1  //写单价
#define	LF_MDConnectCmdReadTotal	            0xA3  //读总累
#define	LF_MDConnectCmdReadState              0xB0  //读取加油机状态
#define	LF_MDConnectCmdFuilingStateReply      0xB3  //加油中回复
#define	LF_MDConnectCmdIdleStateReply         0xBA  //空闲状态回复
#define	LF_MDConnectCmdRecordConfirm          0xD2  //交易记录确认
#define	LF_MDConnectCmdReadFuelRecord         0xE3  //读取加油记录
#define	LF_MDConnectCmdWritePrset             0xE4  //写预置
#define	LF_MDConnectASKControlPower	          0xE5  //要控制权
#define	LF_MDConnectReturnControlPower        0xE6  //还控制权
#define	LF_MDConnectCmdStop		                0xE7  //停机

/**********************蓝天Plus协议指令集******************************/
#define	LTP_DriverCMD                         0xA1  //机指令
#define	LTP_GunCMD                            0XA2  //枪
//机指令列表
#define	LTP_DriverCMDReadPassword             0X01  //读密码
#define	LTP_DriverCMDWritePassword            0X02  //写密码
#define	LTP_DriverCMDReadVerAndMac            0X03  //读版本和唯一码
#define	LTP_DriverCMDLock                     0X04  //锁机
#define	LTP_DriverCMDUnlock                   0X05  //解锁
#define	LTP_DriverCMDSendFrame                0X06  //在线升级传送帧
//枪参数列表
#define	LTP_GunCMDReadState                   0x01  //读取加油机状态
#define	LTP_GunCMDReadStateAndData            0x02  //读取加油机状态和数据
#define	LTP_GunCMDReadTotal                   0x03  //读总累
#define	LTP_GunCMDWritePrset                  0x04  //写预置
#define	LTP_GunCMDAuthorize                   0x05  //授权
#define	LTP_GunCMDStop                        0x06  //停机
#define	LTP_GunCMDReadEvent                   0x07  //读事件
#define	LTP_GunCMDReadError                   0x08  //读错误
#define	LTP_GunCMDReadParameter               0x09  //读参数
#define	LTP_GunCMDWriteParameter              0x0A  //写参数
#define	LTP_GunCMDSuspend                     0x0B  //暂停
#define	LTP_GunCMDContinue                    0x0C  //继续
//枪参数列表
#define	LTP_GunParameterListPrice             0x01  //单价参数
#define	LTP_GunParameterListPluse             0x02  //脉冲当量参数
#define	LTP_GunParameterListTurnOff           0x03  //提前关阀量参数
#define	LTP_GunParameterListMinDisp           0x04  //最小显示值参数

/*********************CNGPLC指令集************************/
#define	PLC_MDConnectCmdReadData              0X01  //读数据
#define	PLC_MDConnectCmdReadErro              0X02  //读错误

/*********************单价牌指令集************************/
#define	Price_MDConnectCmdWriteParameter      0X00  //写参数
#define	Price_MDConnectCmdWritePrice          0X01  //写单价
#define	Price_MDConnectCmdReadParameter       0X02  //读参数
#define	Price_MDConnectCmdReadPrice           0X03  //读单价
#define	Price_MDConnectCmdWriteDecimal        0X04  //写单价

#define MD_Connect_RS485_Tx1EN       GPIO_ResetBits(GPIOD,GPIO_Pin_7);
#define MD_Connect_RS485_Rx1EN       GPIO_SetBits(GPIOD,GPIO_Pin_7);
#define MD_Connect_RS485_Tx2EN       GPIO_ResetBits(GPIOD,GPIO_Pin_3);
#define MD_Connect_RS485_Rx2EN       GPIO_SetBits(GPIOD,GPIO_Pin_3);
#define MD_Connect_RS485_Tx3EN       GPIO_ResetBits(GPIOA,GPIO_Pin_8);
#define MD_Connect_RS485_Rx3EN       GPIO_SetBits(GPIOA,GPIO_Pin_8);
#define MD_Connect_RS485_Tx4EN       GPIO_ResetBits(GPIOD,GPIO_Pin_10);
#define MD_Connect_RS485_Rx4EN       GPIO_SetBits(GPIOD,GPIO_Pin_10);

#define MD_Connect_LORA_SetMode1       GPIO_SetBits(GPIOG,GPIO_Pin_14);
#define MD_Connect_LORA_IdleMode1      GPIO_ResetBits(GPIOG,GPIO_Pin_14);
#define MD_Connect_LORA_SetMode2       GPIO_SetBits(GPIOG,GPIO_Pin_13);
#define MD_Connect_LORA_IdleMode2      GPIO_ResetBits(GPIOG,GPIO_Pin_13);
#define MD_Connect_LORA_SetMode3       GPIO_SetBits(GPIOG,GPIO_Pin_12);
#define MD_Connect_LORA_IdleMode3      GPIO_ResetBits(GPIOG,GPIO_Pin_12);
#define MD_Connect_LORA_SetMode4       GPIO_SetBits(GPIOG,GPIO_Pin_11);
#define MD_Connect_LORA_IdleMode4      GPIO_ResetBits(GPIOG,GPIO_Pin_11);

//******************************************************************************
//*-------------- 变量声名 -----------------------------------------------------
//******************************************************************************
typedef enum
{
	LORA_Master,
  LORA_Slave,

}LORA_MODE_Tyye;
extern volatile u8 MD_ConnectRX1Task_Flag;  //MD_Connect卡通讯DMA接收完成标志标志
extern volatile u8 MD_ConnectRX2Task_Flag;  //MD_Connect卡通讯DMA接收完成标志标志
extern volatile u8 MD_ConnectRX3Task_Flag;  //MD_Connect卡通讯DMA接收完成标志标志
extern volatile u8 MD_ConnectRX4Task_Flag;  //MD_Connect卡通讯DMA接收完成标志标志
														
//******************************************************************************
//*-------------- 函数声名 -----------------------------------------------------
//******************************************************************************
extern  void MD_Connect_USART_Configuration(u8 PortNum,u32 Baud,u16 USART_WordLength,u8 Check);
extern  void MD_Connect_Init(void);              //MD_Connect卡键盘任务初始化
extern  void MD_Port_Init(u8 Port);
extern	void MD_Connect_DMARX1_IRQHandler(void); //MD_Connect卡键盘接收中断服务函数
extern	void MD_Connect_DMATX1_IRQHandler(void); //DMA发送中断服务函数
extern	void MD_Connect_DMARX2_IRQHandler(void); //MD_Connect卡键盘接收中断服务函数
extern	void MD_Connect_DMATX2_IRQHandler(void); //DMA发送中断服务函数
extern	void MD_Connect_DMARX3_IRQHandler(void); //MD_Connect卡键盘接收中断服务函数
extern	void MD_Connect_DMATX3_IRQHandler(void); //DMA发送中断服务函数
extern	void MD_Connect_DMARX4_IRQHandler(void); //MD_Connect卡键盘接收中断服务函数
extern	void MD_Connect_DMATX4_IRQHandler(void); //DMA发送中断服务函数
extern  u64 MD_Connect_u64ToBCD(u64 Dat);
extern  u64 MD_Connect_BCDTou64(u64 Dat);
extern  void MD_ConnectRXTask(void);
extern  void MD_ConnectTXTask(u8 Port,u8 GunNum,u8 MD_TX_CMD);
extern  void MD_Port_LORASet(u8 Port,u8 Mode);
extern u8 BCC_CheckSum(u8 *buf, u8 len);//BCC校验函数;
extern float StrToFloat(u8 *str,u8 len);
#endif	//#ifndef		
