231 lines
4.6 KiB
C
231 lines
4.6 KiB
C
![]() |
#ifndef __ILOCK_H__
|
|||
|
#define __ILOCK_H__
|
|||
|
#ifdef __cplusplus
|
|||
|
extern "C" {
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
#define ILOCK_STATE_OPENED 0
|
|||
|
#define ILOCK_STATE_CLOSED 1
|
|||
|
|
|||
|
|
|||
|
#define CMD_CLOSE_LOCK 0x41
|
|||
|
#define CMD_OPEN_LOCK 0x40
|
|||
|
#define CMD_OPEN_LOCK_SOS 0x4A
|
|||
|
#define CMD_PING 0x49
|
|||
|
#define CMD_OPEN_CAMERA 0x49
|
|||
|
#define CMD_CLOSE_CAMERA 0x49
|
|||
|
#define CMD_PLAY_VOICE 0x48
|
|||
|
#define CMD_SET_UTC 0x12
|
|||
|
#define CMD_READ_STATE 0x44
|
|||
|
#define CMD_READ_VERSION 0x21
|
|||
|
#define CMD_READ_SERIALNO 0x20
|
|||
|
#define CMD_FACTORY_RESET 0x24
|
|||
|
|
|||
|
#define CMD_LOCK_READ_FIRMWARE_VERSION 0x21
|
|||
|
|
|||
|
/**
|
|||
|
* 0x1:请求包,都需要回复
|
|||
|
0x2:响应包,回复执行结果
|
|||
|
0x3:回执包,仅通知收到(高 4BIT)
|
|||
|
*/
|
|||
|
#define CMD_TYPE_REQ 0x01
|
|||
|
#define CMD_TYPE_RET 0x02
|
|||
|
#define CMD_TYPE_REC 0x03//receipt
|
|||
|
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
int serial_no;//指令序号
|
|||
|
int cmd_type;
|
|||
|
char message_id[32];
|
|||
|
uint8_t cmds[128];
|
|||
|
int cmd_len;
|
|||
|
int retry_count;
|
|||
|
int timeout;
|
|||
|
int resp_state;//0 无回应,1-有回应
|
|||
|
int cmd_result;
|
|||
|
|
|||
|
} lock_command_t;
|
|||
|
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
int serial_no;//指令序号
|
|||
|
int cmd_type;//指令
|
|||
|
|
|||
|
int cmd_result;//指令结果
|
|||
|
uint8_t data[128];//返回数据
|
|||
|
uint8_t data_len;//返回长度
|
|||
|
} lock_package_t;
|
|||
|
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
uint8_t data[64];//返回数据
|
|||
|
uint8_t data_len;//返回长度
|
|||
|
} ota_version_t;
|
|||
|
|
|||
|
int ilock_send_lock_commond(char *message_id,int cmdType,int param);
|
|||
|
|
|||
|
|
|||
|
typedef struct ilock_dev
|
|||
|
{
|
|||
|
uint8_t event_code;
|
|||
|
/**
|
|||
|
* 门状态
|
|||
|
*/
|
|||
|
uint8_t lock_door_state;
|
|||
|
/**
|
|||
|
* 供电状态
|
|||
|
*/
|
|||
|
uint8_t lock_power_supply;
|
|||
|
/**
|
|||
|
* 锁状态
|
|||
|
*/
|
|||
|
uint8_t lock_lock_state;
|
|||
|
/**
|
|||
|
* 电池状态
|
|||
|
*/
|
|||
|
uint8_t lock_batt_state;
|
|||
|
/**
|
|||
|
* 电池电量
|
|||
|
*/
|
|||
|
uint8_t lock_batt_value;
|
|||
|
|
|||
|
/**反锁状态*/
|
|||
|
uint8_t lock_lockedin_state;
|
|||
|
|
|||
|
/**钥匙禁用*/
|
|||
|
uint8_t lock_disable_lock_state;
|
|||
|
|
|||
|
|
|||
|
char lock_params [32];
|
|||
|
}ilock_dev;
|
|||
|
|
|||
|
extern ilock_dev dev_info_lasted;
|
|||
|
|
|||
|
typedef struct ilock_client_cb_ops{
|
|||
|
|
|||
|
/*
|
|||
|
*门铃事件
|
|||
|
*/
|
|||
|
void (*event_doorbell)(int audio, int video);
|
|||
|
void (*event_lock_upload_state)(int state);
|
|||
|
void (*event_lock_serial_no)(char* serial_no ,int serial_no_len);
|
|||
|
void (*event_lock_version)(char* version ,int version_len);
|
|||
|
/**
|
|||
|
* 关锁 0-关锁失败 1- 关锁成功
|
|||
|
*/
|
|||
|
void (*event_lock_lock)(int state);//
|
|||
|
/*
|
|||
|
* 开锁 0 -开锁失败 1- 开锁成功
|
|||
|
*/
|
|||
|
void (*event_lock_unlock)(int state); //0-fail 1-succ
|
|||
|
|
|||
|
/*
|
|||
|
* 紧急开锁 0 -开锁失败 1- 开锁成功
|
|||
|
*/
|
|||
|
void (*event_lock_unlock_sos)(int state); //0-fail 1-succ
|
|||
|
|
|||
|
/**
|
|||
|
* 配网事件
|
|||
|
*/
|
|||
|
void (*event_network_boarding)();
|
|||
|
|
|||
|
/**
|
|||
|
* 锁体状态
|
|||
|
*/
|
|||
|
void (*event_lock_state)(ilock_dev *dev_info);
|
|||
|
void (*event_lock_params)(char *params, int len);
|
|||
|
/**
|
|||
|
* 串口数据
|
|||
|
*/
|
|||
|
void (*event_lock_recv_data)(uint8_t *data, int len);
|
|||
|
//void (*event_lock_state)(int lockedin_state,int lock_state ,int door_state, int batt_state, int batt_cap, int lock_disable_lock_state);
|
|||
|
}ilock_client_cb_ops_t;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void ilock_init(void);
|
|||
|
void ilock_uart_init(void);
|
|||
|
void ilock_uart_deinit();
|
|||
|
void ilock_rx_start();
|
|||
|
void ilock_rx_stop();
|
|||
|
void ilock_uart_enable_rx();
|
|||
|
void ilock_deinit(void);
|
|||
|
|
|||
|
void ilock_set_callback(ilock_client_cb_ops_t *cb_ops);
|
|||
|
/**
|
|||
|
* 开锁
|
|||
|
*/
|
|||
|
int ilock_open_lock(int uid);
|
|||
|
|
|||
|
/**
|
|||
|
* 开锁SOS
|
|||
|
*/
|
|||
|
int ilock_open_lock_sos(int uid);
|
|||
|
int ilock_read_status();
|
|||
|
/**
|
|||
|
* 关锁
|
|||
|
*/
|
|||
|
int ilock_close_lock(int uid);
|
|||
|
|
|||
|
/**
|
|||
|
* 反锁
|
|||
|
*/
|
|||
|
int ilock_enable_lockout();
|
|||
|
|
|||
|
/**
|
|||
|
* 解除反锁
|
|||
|
*/
|
|||
|
int ilock_disable_lockout();
|
|||
|
|
|||
|
/**
|
|||
|
* 钥匙启用
|
|||
|
*/
|
|||
|
int ilock_enable_key();
|
|||
|
|
|||
|
/**
|
|||
|
* 钥匙禁用
|
|||
|
*/
|
|||
|
int ilock_disable_key();
|
|||
|
|
|||
|
int ilock_read_state();
|
|||
|
|
|||
|
int ilock_read_version();
|
|||
|
|
|||
|
int ilock_read_serialno();
|
|||
|
|
|||
|
int ilock_set_utc(long utc);
|
|||
|
/*
|
|||
|
*获取锁体参数
|
|||
|
*/
|
|||
|
int ilock_read_lock_params();
|
|||
|
|
|||
|
int ilock_ping();
|
|||
|
|
|||
|
int ilock_play_voice(int voice_index);
|
|||
|
|
|||
|
int ilock_open_camera();
|
|||
|
int ilock_close_camera();
|
|||
|
|
|||
|
/**
|
|||
|
* 恢复出厂设置
|
|||
|
*/
|
|||
|
int ilock_factory_reset();
|
|||
|
|
|||
|
/*
|
|||
|
*给锁控制板发送消息
|
|||
|
*/
|
|||
|
int ilock_sendData(char* data,int len);
|
|||
|
|
|||
|
|
|||
|
char * ilock_client_get_device_id();
|
|||
|
|
|||
|
//OTA
|
|||
|
int ilock_client_is_ota_mode();
|
|||
|
int ilock_client_ota_start(int target,uint8_t* data, int data_len);
|
|||
|
|
|||
|
#ifdef __cplusplus
|
|||
|
}
|
|||
|
#endif
|
|||
|
#endif
|