#ifndef _BLV_485_DEV_CHUANGJIALOCKFUN_H_
#define _BLV_485_DEV_CHUANGJIALOCKFUN_H_
#include "BLV_485_Dev_WeixinLockFun.h"

#define CJ_LOCKCYCLEWAITTIMEOUT		5000	//创佳微信锁轮询超时等待时间

#define CJ_TYPE					0x06//创佳锁设备类型
#define CJ_COMMAND_MAX			8	//8种控制命令
#define CJ_RECEIVE_MAX_LEN		42	//创佳锁接收数据的最大长度
#define CJ_RETRY_FLAG			0x40//创佳锁重发标志

#define CJ_NO_ACTION			0x00	//无动作
#define CJ_QUERY_STATUS			0x01	//查询状态
#define CJ_UNLOCKING			0x02	//开锁
#define CJ_SET_CLOCK			0x03	//设置时钟
#define CJ_LOCK_TIMER			0x04	//读取锁的时间
#define CJ_SET_CONNECT			0x05	//控制连接
#define CJ_READ_ROOM			0x06	//读取房号
#define CJ_READ_GATEWAY			0x07	//读取网关版本
#define CJ_CARD_UNLOCKING		0x08	//卡开锁

#define CJ_QUERY_STATUS_FLAG	0x01	//查询状态标志位
#define CJ_UNLOCKING_FLAG		0x02	//开锁标志位
#define CJ_SET_CLOCK_FLAG		0x04	//设置时钟标志位
#define CJ_LOCK_TIMER_FLAG		0x08	//读取锁的时间标志位
#define CJ_SET_CONNECT_FLAG		0x10	//控制连接标志位
#define CJ_READ_ROOM_FLAG		0x20	//读取房号标志位
#define CJ_READ_GATEWAY_FLAG	0x40	//读取网关版本标志位
#define CJ_CARD_UNLOCKING_FLAG	0x80	//卡开锁标志位

/*创佳锁指令格式*/
typedef enum
{
	CJ_OUR_ADD = 0,	//己方地址
	CJ_SEND_TYPE,	//发送类型
	CJ_DEVICE_TYPE,	//设备类型
	CJ_RECE_ADD,	//收方地址
	CJ_DATA_LEN,	//整包长度
	CJ_CHECK,		//校验和取反
	CJ_COMMAND,		//命令
	CJ_PARAM,		//参数
}CHUANGJIA_ORDER_FORMAT;

extern uint8_t CJ_Set_Timer[7];	//创佳锁设置时间
extern uint8_t CJ_Set_Connect;	//创佳锁配对控制参数

void ChuangJia_RS485_WxLockFun_Init(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFO *Rs485WxLockInfo);	//添加设备到链表 - 主动设备
uint8_t ChuangJia_WxLock_Polling_Ctrl(uint32_t dev_addr);	//创佳微信锁轮询控制函数（用于发送命令控制）
uint8_t ChuangJia_WxLock_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len);	//创佳微信锁接收处理函数

void ChuangJia_Query_Status(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁查询状态函数
void ChuangJia_Ctrl_Unlock(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁控制开锁函数
void ChuangJia_Set_Clock(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁设置时钟函数
void ChuangJia_Lock_Timer(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁读取时间函数
void ChuangJia_Set_Connect(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁控制配对连接函数
void ChuangJia_Read_Room(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁读取房号函数
void ChuangJia_Read_Gateway(Device_Public_Information_G *BUS_Public, RS485_WxLock_INFOP Rs485WxLockInfo);	//创佳微信锁读取网关版本函数
#endif
