添加注释 是能button驱动暂时没用使用
This commit is contained in:
parent
63d6ee9807
commit
09e350a28a
@ -65,6 +65,7 @@ CONFIG_PSRAM_AS_SYS_MEMORY=y
|
||||
CONFIG_MBEDTLS=y
|
||||
CONFIG_HTTPS=y
|
||||
CONFIG_OTA_HTTPS=y
|
||||
CONFIG_BUTTON=y
|
||||
#CONFIG_SECURITY_OTA=y
|
||||
|
||||
#CONFIG_FATFS=y
|
||||
|
159
projects/thirdparty/lock_lfvx/main/app_main.c
vendored
159
projects/thirdparty/lock_lfvx/main/app_main.c
vendored
@ -239,16 +239,14 @@ static void ilock_powersave_rx_wakeup(gpio_id_t gpio_id)
|
||||
reset_powersave_timer();
|
||||
}
|
||||
|
||||
static void key_gpio_int_isr(gpio_id_t id)
|
||||
{
|
||||
BK_LOGE(TAG,"key_gpio_int_isr :%d \r\n",id);
|
||||
bk_gpio_register_isr(GPIO_1 ,NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入低功耗休眠
|
||||
*/
|
||||
void ilock_power_save_enter(void)
|
||||
{
|
||||
//#if (CONFIG_SYS_CPU0)
|
||||
bk_timer_stop(time_task_powersave);
|
||||
//设置GPIO唤醒
|
||||
bk_gpio_register_isr(GPIO_34, ilock_powersave_rx_wakeup);
|
||||
bk_gpio_register_wakeup_source(GPIO_34,GPIO_INT_TYPE_RISING_EDGE);//GPIO_INT_TYPE_RISING_EDGE GPIO_INT_TYPE_HIGH_LEVEL
|
||||
bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_GPIO, NULL);
|
||||
@ -265,7 +263,9 @@ void ilock_power_save_enter(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 空闲回调 进入低功耗模式
|
||||
*/
|
||||
static void enter_powersave_callback_timer_isr(timer_id_t chan)
|
||||
{
|
||||
BK_LOGE(TAG,"try enter powersave!\r\n");
|
||||
@ -288,7 +288,9 @@ static void enter_powersave_callback_timer_isr(timer_id_t chan)
|
||||
}
|
||||
ilock_power_save_enter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置定时器
|
||||
*/
|
||||
void reset_powersave_timer(){
|
||||
//BK_LOGE(TAG,"reset powersave timer!\r\n");
|
||||
bk_timer_stop(time_task_powersave);
|
||||
@ -336,7 +338,7 @@ void init_mac(){
|
||||
sprintf(mac_str,"%02X%02X%02X%02X%02X%02X",base_mac[0], base_mac[1], base_mac[2], base_mac[3], base_mac[4], base_mac[5]);
|
||||
#endif
|
||||
//sprintf(mac_str,"%02X%02X%02X%02X%02X%02X",base_mac[0], base_mac[1], base_mac[2], base_mac[3], base_mac[4], base_mac[5]);
|
||||
|
||||
//拼装mqtt使用的设备ID
|
||||
char * ilock_device_id = poka_client_get_device_id();
|
||||
ilock_device_id[0]='L';
|
||||
ilock_device_id[1]='F';
|
||||
@ -375,8 +377,8 @@ void init_mac(){
|
||||
ilock_device_id[22]=mac_str[9];
|
||||
ilock_device_id[23]=mac_str[10];
|
||||
ilock_device_id[24]=mac_str[11];
|
||||
|
||||
BK_LOGE(TAG,"deviceID: %s\n", ilock_device_id);
|
||||
//拼装前面板使用的设备ID
|
||||
char * device_id = ilock_client_get_device_id();
|
||||
device_id[0]='A';
|
||||
device_id[1]='0';
|
||||
@ -402,16 +404,18 @@ void init_mac(){
|
||||
}
|
||||
|
||||
#if 1
|
||||
/**
|
||||
* 接收到视频通话指令
|
||||
*/
|
||||
void event_remote_video_callback(int audio, char* license, char* token){
|
||||
BK_LOGE(TAG,"remote_video: audio %d\r\n",audio);
|
||||
if(license != NULL){
|
||||
BK_LOGE(TAG,"event_remote_video: license %s\r\n",license);
|
||||
}
|
||||
BK_LOGE(TAG,"remote_video: audio %d\r\n",audio);
|
||||
|
||||
//BK_LOGE(TAG,"event_remote_video: audio:%d\r\n",audio);
|
||||
//BK_LOGE(TAG,"event_remote_video: token:%s\r\n",token);
|
||||
|
||||
//加入视频通话
|
||||
if(license !=NULL && strlen(license) > 0){
|
||||
agora_join_channel(poka_client_get_device_id(),token,license);//ilock_device_id
|
||||
}else{
|
||||
@ -430,9 +434,11 @@ void event_remote_video_callback(int audio, char* license, char* token){
|
||||
//回复
|
||||
poka_client_replay_invoke(EVENT_REMOTE_VIDEO,poka_client_get_message_id(),FUN_TRUE,NULL);
|
||||
}
|
||||
/*
|
||||
退出视频通话
|
||||
*/
|
||||
void event_remote_video_close_callback(){
|
||||
BK_LOGE(TAG,"remote_video_close\r\n");
|
||||
|
||||
agora_level_channel();
|
||||
//回复
|
||||
poka_client_replay_invoke(EVENT_REMOTE_VIDEO_CLOSE,poka_client_get_message_id(),FUN_TRUE,NULL);
|
||||
@ -578,7 +584,9 @@ void event_cloud_callback(data_transfer_t * data){
|
||||
}
|
||||
reset_powersave_timer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过物联网平台下发声网授权保存到本地(保留)
|
||||
*/
|
||||
void event_agora_license_callback(char* license,int license_len ){
|
||||
BK_LOGE(TAG,"license:%s\r\n",license);
|
||||
#if(CONFIG_SYS_CPU0)
|
||||
@ -596,7 +604,9 @@ void event_agora_license_callback(char* license,int license_len ){
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过物联网平台下发WIFI SSID 和密码保存到本地 (保留)
|
||||
*/
|
||||
void event_set_wifi_callback(char* ssid,int ssid_len ,char* password ,int password_len){
|
||||
BK_LOGE(TAG,"set_wifi ssid:%s pwd:%s \r\n",ssid,password );
|
||||
#if(CONFIG_SYS_CPU0)
|
||||
@ -622,7 +632,9 @@ void event_set_wifi_callback(char* ssid,int ssid_len ,char* password ,int passwo
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*视频通话时切换画质
|
||||
*/
|
||||
void event_set_video_quality_callback(int quality){
|
||||
BK_LOGE(TAG,"event_event_set_video_quality:%d\r\n",quality);
|
||||
agora_set_video_quality(quality);
|
||||
@ -674,7 +686,9 @@ void funs_ota_callback(int device_type, char* ota_file_url){
|
||||
ota_file.ota_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过物联网平台下发抓拍图片指令
|
||||
*/
|
||||
void funs_take_photo_callback(){
|
||||
BK_LOGE(TAG,"funs_take_photo_callback \r\n");
|
||||
camera_client_take_photo();
|
||||
@ -739,7 +753,9 @@ void event_ilock_unlock_sos_callback(int state){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接收到前面板的门铃事件
|
||||
*/
|
||||
void event_ilock_doorbell_callback(int audio, int video){
|
||||
BK_LOGE(TAG,"doorbell!!\r\n");
|
||||
|
||||
@ -755,12 +771,16 @@ void event_ilock_doorbell_callback(int audio, int video){
|
||||
}
|
||||
//camera_client_take_photo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收到前面板的配网事件
|
||||
*/
|
||||
void event_ilock_network_boarding_callback(){
|
||||
BK_LOGE(TAG,"network_boarding!!\r\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接收到锁体状态
|
||||
*/
|
||||
void event_ilock_state_callback(ilock_dev *dev_info){
|
||||
|
||||
BK_LOGE(TAG,"\r\n\r\n");
|
||||
@ -785,6 +805,7 @@ void event_ilock_state_callback(ilock_dev *dev_info){
|
||||
//camera_client_take_photo();
|
||||
}
|
||||
#if 1
|
||||
//判断状态是否有变化
|
||||
int diff = 0 ;
|
||||
|
||||
if(dev_info_lasted.lock_lockedin_state != dev_info->lock_lockedin_state){
|
||||
@ -834,6 +855,7 @@ void event_ilock_state_callback(ilock_dev *dev_info){
|
||||
if(diff == 1){
|
||||
#if 1
|
||||
if(!mqtt_is_wifi_connected())return;
|
||||
//上报属性
|
||||
poka_client_report_properties("",dev_info->lock_lockedin_state,
|
||||
dev_info->lock_door_state,
|
||||
dev_info->lock_lock_state,
|
||||
@ -842,7 +864,7 @@ void event_ilock_state_callback(ilock_dev *dev_info){
|
||||
dev_info->lock_disable_lock_state,
|
||||
dev_info->lock_power_supply);
|
||||
|
||||
|
||||
//上报事件到物联网平台(可选)
|
||||
cJSON *data = cJSON_CreateObject();
|
||||
//app_time_timestamp_ms()
|
||||
char str_time[32]={0};
|
||||
@ -870,7 +892,9 @@ void event_ilock_read_params_callback(char* params, int len){
|
||||
os_memset(dev_info_lasted.lock_params,0,sizeof(dev_info_lasted.lock_params));
|
||||
os_memcpy(&dev_info_lasted.lock_params, params, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收到前前面板和锁体的指令(用于透传)
|
||||
*/
|
||||
void event_lock_recv_data_callback(uint8_t *data, int len){
|
||||
//BK_LOGE(TAG,"event_lock_recv_data_callback flag:%02X len:%d\r\n",data[3],len);
|
||||
#if 1
|
||||
@ -878,16 +902,20 @@ void event_lock_recv_data_callback(uint8_t *data, int len){
|
||||
BK_LOGE(TAG,"lock_recv_data_callback len:%d\r\n",len);
|
||||
if(len > 0){
|
||||
int cmd = data[3];
|
||||
//过滤特定指令
|
||||
//0x23,0x25、0x26、0x27、0x45、0x46、0x52、0x53、0x54、0x55、0x56
|
||||
if(cmd == 0x47 ||cmd == 0x22 ||cmd == 0x23 || cmd == 0x25 ||cmd == 0x26 ||cmd == 0x27||cmd == 0x42||cmd == 0x43 ||cmd == 0x45 ||cmd == 0x46 ||cmd == 0x52 ||cmd == 0x53 ||cmd == 0x54||cmd == 0x55||cmd == 0x56){
|
||||
unsigned char out [64] = {0};
|
||||
hex_to_asciistring(data,len,out);
|
||||
//将接收到的指令发送给物联网平台,小程序监听物联网平台获取这些数据
|
||||
poka_client_report_event(EVENT_DATA_TRANSFER,(char*)&out);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取到锁体版本
|
||||
*/
|
||||
void event_lock_version_callback(char * version, int len){
|
||||
if(version != NULL && len > 0){
|
||||
if(!mqtt_is_wifi_connected())return;
|
||||
@ -910,7 +938,9 @@ static ilock_client_cb_ops_t ilock_event_ops = {
|
||||
|
||||
|
||||
//BLE_WIFI
|
||||
|
||||
/**
|
||||
*接收到小程序通过蓝牙传递过来的wifi信息 保存在本地 并启动wifi连接
|
||||
* */
|
||||
void event_ble_boarding_wifi_info_callback(char* ssid, int ssid_len, char* password,int password_len){
|
||||
is_ble_boarding = 0;
|
||||
if(ssid == NULL || password == NULL) return;
|
||||
@ -951,7 +981,9 @@ void event_ble_boarding_wifi_info_callback(char* ssid, int ssid_len, char* passw
|
||||
bk_wifi_sta_set_config(&sta_config);
|
||||
bk_wifi_sta_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收到小程序扫描wifi指令
|
||||
*/
|
||||
void event_ble_boarding_start_callback(){
|
||||
BK_LOGE(TAG,"event_ble_boarding start\r\n");
|
||||
//重置一下蓝牙关闭时间
|
||||
@ -966,7 +998,9 @@ void event_ble_boarding_start_callback(){
|
||||
BK_LOG_ON_ERR(bk_wifi_scan_start(NULL));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*接收到小程序传递的声网授权信息并保存在本地用于视频对讲
|
||||
*/
|
||||
void event_agora_info_callback(char* license, int license_len){
|
||||
BK_LOGE(TAG,"event_agora_info:(%d) %s\r\n",license_len,license);
|
||||
|
||||
@ -990,7 +1024,9 @@ static ble_boarding_cb_ops_t ble_boarding_event_ops = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 按键事件 长按3秒松开重启 长按8秒松开恢复出厂设置
|
||||
*/
|
||||
static void on_key_event (key_event_type key_event,key_event_code key_code){
|
||||
if(key_event == KEY_DOWN ){
|
||||
//唤醒系统
|
||||
@ -1054,7 +1090,9 @@ static void camera_client_on_take_photo_event (char *photo_id, int len){
|
||||
static camera_cb_ops_t camera_client_event_ops = {
|
||||
.on_take_photo_event = camera_client_on_take_photo_event,
|
||||
};
|
||||
|
||||
/**
|
||||
* 网络连接状态回调
|
||||
*/
|
||||
int app_wifi_event_cb(void *arg, event_module_t event_module,
|
||||
int event_id, void *event_data)
|
||||
{
|
||||
@ -1094,14 +1132,16 @@ int app_wifi_event_cb(void *arg, event_module_t event_module,
|
||||
|
||||
return BK_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化WIFI连接
|
||||
*/
|
||||
void init_wifi(){
|
||||
|
||||
bk_wlan_status_register_cb(wifi_sta_rw_event_func);
|
||||
BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_WIFI, EVENT_ID_ALL, app_wifi_event_cb, NULL));
|
||||
//BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_NETIF, EVENT_ID_ALL, cli_netif_event_cb, NULL));
|
||||
wifi_sta_config_t sta_config = {0};
|
||||
|
||||
//获取本地的wifi 账号和密码
|
||||
char wifi_ssid[32] = { 0 };
|
||||
char wifi_password[32] = { 0 };
|
||||
|
||||
@ -1143,7 +1183,7 @@ void init_wifi(){
|
||||
//sta_config.security = WIFI_SECURITY_NONE;
|
||||
//设置DTIM10(1:DTIM1)
|
||||
bk_wifi_send_listen_interval_req(1);
|
||||
|
||||
//启动连接
|
||||
bk_wifi_sta_set_config(&sta_config);
|
||||
bk_wifi_sta_start();
|
||||
|
||||
@ -1157,7 +1197,9 @@ void init_esay(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上报设备信息到物联网平台
|
||||
*/
|
||||
void report_device_info_to_cloud(){
|
||||
|
||||
uint8_t base_mac[BK_MAC_ADDR_LEN] = {0};
|
||||
@ -1186,19 +1228,21 @@ void report_device_info_to_cloud(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 视频通话时摄像头的状态
|
||||
*/
|
||||
void event_agora_camera_link_state_callback(camera_link_state state){
|
||||
BK_LOGE(TAG,"camera_link :%d\r\n",state);
|
||||
cJSON *data = cJSON_CreateObject();
|
||||
if(state == CAMERA_LINK_SUCCESS){
|
||||
if(state == CAMERA_LINK_SUCCESS){//摄像头连接成功
|
||||
//poka_client_report_event_int(EVENT_CAMERA_LINK,1);
|
||||
cJSON_AddNumberToObject(data, "link_state", 1);
|
||||
}
|
||||
else if(state == CAMERA_LINK_FAIL){
|
||||
else if(state == CAMERA_LINK_FAIL){//摄像头连接失败
|
||||
//poka_client_report_event_int(EVENT_CAMERA_LINK,0);
|
||||
cJSON_AddNumberToObject(data, "link_state", 0);
|
||||
}
|
||||
else if(state == CAMERA_LINK_INTERRUP){
|
||||
else if(state == CAMERA_LINK_INTERRUP){//摄像头连接中断
|
||||
//poka_client_report_event_int(EVENT_CAMERA_LINK,2);
|
||||
cJSON_AddNumberToObject(data, "link_state", 2);
|
||||
}
|
||||
@ -1255,7 +1299,7 @@ void test_ota(){
|
||||
ota_f->ota_data = NULL;
|
||||
}
|
||||
#else
|
||||
|
||||
//下载前面板固件程序
|
||||
int ret = ota_file_download_from_http("http://106.52.233.130:8888/HC32L07X.bin",&ota_file);
|
||||
if(ret != BK_OK){
|
||||
BK_LOGE(TAG,"download ota file fail !!\r\n");
|
||||
@ -1264,9 +1308,7 @@ void test_ota(){
|
||||
|
||||
BK_LOGE(TAG,"ota_data_len :%d\r\n",ota_file.ota_data_len);
|
||||
BK_LOGE(TAG, "%02X %02X %02X %02X\n",ota_file.ota_data[ota_file.ota_data_len-1],ota_file.ota_data[ota_file.ota_data_len-2],ota_file.ota_data[ota_file.ota_data_len-3],ota_file.ota_data[ota_file.ota_data_len-4]);
|
||||
|
||||
|
||||
|
||||
//将固件程序下发到前面板
|
||||
int result = ilock_client_ota_start(0x11,(uint8_t *)ota_file.ota_data, ota_file.ota_data_len);
|
||||
BK_LOGE(TAG,"test_ota result:%d !!\r\n",result);
|
||||
if(result == 0 ){
|
||||
@ -1293,73 +1335,74 @@ void user_app_main(void){
|
||||
|
||||
BK_LOGE(TAG,"VERSION:%d %d %d %d\r\n",ILOCK_SOFT_VERSION_1,ILOCK_SOFT_VERSION_2,ILOCK_SOFT_VERSION_3,ILOCK_SOFT_VERSION_4);
|
||||
|
||||
#if 1
|
||||
bk_gpio_driver_init();
|
||||
#if 1
|
||||
//初始化唤醒脚
|
||||
gpio_dev_unmap(GPIO_34);
|
||||
bk_gpio_enable_input(GPIO_34);
|
||||
//bk_gpio_disable_pull(GPIO_9);
|
||||
//bk_gpio_set_config(GPIO_9, &cfg);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
//打开功放PA控制脚
|
||||
gpio_dev_unmap(GPIO_7);
|
||||
bk_gpio_enable_output(GPIO_7);
|
||||
bk_gpio_set_output_high(GPIO_7);
|
||||
|
||||
#endif
|
||||
|
||||
//DEVICE ID
|
||||
//初始化设备ID
|
||||
init_mac();
|
||||
|
||||
//FLASH
|
||||
init_esay();
|
||||
|
||||
//TIMER
|
||||
//初始化定时器TIMER
|
||||
bk_timer_driver_init();
|
||||
|
||||
//WIFI
|
||||
//初始化WIFI
|
||||
init_wifi();
|
||||
|
||||
//初始化蓝牙配网
|
||||
ble_boarding_set_callback(&ble_boarding_event_ops);
|
||||
ble_client_boarding_init();
|
||||
|
||||
//key
|
||||
//初始化按键key
|
||||
key_client_set_cb(&key_event_ops);
|
||||
#if ILOCK_TEST_BROAD
|
||||
key_client_start();
|
||||
#endif
|
||||
|
||||
//初始化前面板锁体通信
|
||||
//lock body and lock front
|
||||
ilock_set_callback(&ilock_event_ops);
|
||||
ilock_init();
|
||||
|
||||
//camera
|
||||
//初始化摄像头camera (用于抓拍)
|
||||
camera_client_set_cb(&camera_client_event_ops);
|
||||
|
||||
|
||||
|
||||
//初始化网络检测
|
||||
net_check_start();
|
||||
//system
|
||||
system_client_start();
|
||||
//判断是否已经配置了网络
|
||||
//如果没有配置网络不启动wifi 开启蓝牙配网 并且5分钟超时后进入休眠
|
||||
ble_timeout_close_init();
|
||||
|
||||
//启动串口接收
|
||||
ilock_rx_start();
|
||||
//等待网络连接 如果网络连接不上 一直卡住这里
|
||||
mqtt_waiting_for_wifi_connected();
|
||||
|
||||
//网络连接成功后台 启动物联网平台连接
|
||||
//init poka cloud plat
|
||||
poka_client_set_callback(&cloud_event_ops);
|
||||
poka_client_init();
|
||||
//init agora
|
||||
//初始化声网相关回调
|
||||
agora_set_callback(&agora_client_event_ops);
|
||||
|
||||
//设置时间校准 发送网络时间给前锁面板
|
||||
ilock_set_utc(app_time_timestamp_s());
|
||||
rtos_delay_milliseconds(500);
|
||||
//上报设备信息给物联网平台
|
||||
report_device_info_to_cloud();
|
||||
|
||||
//获取锁体版本
|
||||
ilock_read_version();
|
||||
rtos_delay_milliseconds(500);
|
||||
//获取序列号
|
||||
ilock_read_serialno();
|
||||
|
||||
//ilock_read_state();
|
||||
|
106
projects/thirdparty/lock_lfvx/main/ilock_client.c
vendored
106
projects/thirdparty/lock_lfvx/main/ilock_client.c
vendored
@ -1206,6 +1206,20 @@ void lock_command_handle_thread( beken_thread_arg_t arg )
|
||||
{
|
||||
}
|
||||
BK_LOGE(TAG, "handle_thread:%02X\r\n",lock_command.cmd_type);
|
||||
|
||||
//发送串口
|
||||
//lock_command.cmds,lock_command.cmd_len;
|
||||
bk_uart_write_bytes(uart_id, lock_command.cmds,lock_command.cmd_len);
|
||||
//启动超时定时
|
||||
//等待串口回复
|
||||
while (1)
|
||||
{
|
||||
/* code */
|
||||
break;
|
||||
}
|
||||
|
||||
//判断命令序号
|
||||
//
|
||||
//rtos_delay_milliseconds(1000);
|
||||
switch(lock_command.cmd_type)
|
||||
{
|
||||
@ -1244,88 +1258,6 @@ int ilock_send_lock_commond(char *message_id,int cmd_type,int param){
|
||||
return 1;
|
||||
}
|
||||
|
||||
void parser_data2(uint8_t *recv, int len)
|
||||
{
|
||||
unsigned char recv_buff[CMD_PACKAGE_LEN_MAX];
|
||||
int data_len;
|
||||
int recv_len;
|
||||
ilock_recv_t cur_state = STATUS_IDLE;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
uint8_t data = recv[i];
|
||||
switch (cur_state)
|
||||
{
|
||||
case STATUS_IDLE:
|
||||
case STATUS_HEAD: // 接收0xAA头
|
||||
if (data == CMD_LOCK_START)
|
||||
{
|
||||
BK_LOGE(TAG, "FIND STX\n");
|
||||
recv_len = 0;
|
||||
recv_buff[recv_len++] = data;
|
||||
cur_state = STATUS_LEN;
|
||||
}
|
||||
break;
|
||||
case STATUS_LEN: // 接收LEN
|
||||
data_len = data;
|
||||
//BK_LOGE(TAG, "LEN:%d\n", data_len);
|
||||
recv_buff[recv_len++] = data;
|
||||
cur_state = STATUS_DATA;
|
||||
break;
|
||||
case STATUS_DATA: // 接收DATA
|
||||
recv_buff[recv_len++] = data;
|
||||
//BK_LOGE(TAG, "data:%02x\n", data);
|
||||
if (recv_len == data_len)
|
||||
{
|
||||
// DATA接收到缓冲区完成
|
||||
cur_state = STATUS_CRC1;
|
||||
}
|
||||
break;
|
||||
case STATUS_CRC1: // 接收CRC1
|
||||
recv_buff[recv_len++] = data;
|
||||
cur_state = STATUS_CRC2;
|
||||
//BK_LOGE(TAG, "CRC1:%02X\n", data);
|
||||
break;
|
||||
case STATUS_CRC2: // 接收CRC2
|
||||
recv_buff[recv_len++] = data;
|
||||
//BK_LOGE(TAG, "CRC2:%02X\n", data);
|
||||
|
||||
if (ILOCK_CHECK_CRC)
|
||||
{
|
||||
int crc = ilock_crc16_modbus(&recv_buff[2], recv_len - 4);
|
||||
unsigned char crc1 = recv_buff[recv_len - 2] & 0xFF;
|
||||
unsigned char crc2 = recv_buff[recv_len - 1] & 0xFF;
|
||||
int crcData = crc1 << 8 | crc2;
|
||||
if (crcData != crc)
|
||||
{
|
||||
BK_LOGE(TAG, "CRC ERROR!\r\n");
|
||||
recv_len = 0;
|
||||
cur_state = STATUS_IDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
BK_LOGE(TAG, "CRC OK!\r\n");
|
||||
// 处理一包完整的数据包
|
||||
ilock_parser_data(recv_buff, recv_len);
|
||||
recv_len = 0;
|
||||
data_len = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理一包完整的数据包
|
||||
ilock_parser_data(recv_buff, recv_len);
|
||||
recv_len = 0;
|
||||
data_len = 0;
|
||||
}
|
||||
|
||||
cur_state = STATUS_IDLE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uart_tx_rx_handle_thread(beken_thread_arg_t arg)
|
||||
{
|
||||
@ -1343,11 +1275,11 @@ void parser_data2(uint8_t *recv, int len)
|
||||
|
||||
os_printf("UART_RX_MSG \r\n");
|
||||
// 对接收到的数据逐个传入解析器 解析出完整的通信协议包
|
||||
//for (int i = 0; i < uMsg.len; i++)
|
||||
//{
|
||||
// parser_data(uMsg.msg[i]);
|
||||
//}
|
||||
parser_data2(uMsg.msg,uMsg.len);
|
||||
for (int i = 0; i < uMsg.len; i++)
|
||||
{
|
||||
parser_data(uMsg.msg[i]);
|
||||
}
|
||||
//parser_data2(uMsg.msg,uMsg.len);
|
||||
if (uMsg.msg)
|
||||
{
|
||||
os_free(uMsg.msg);
|
||||
|
48
projects/thirdparty/lock_lfvx/main/key_client.c
vendored
48
projects/thirdparty/lock_lfvx/main/key_client.c
vendored
@ -20,6 +20,10 @@
|
||||
#include "key_client.h"
|
||||
#include "ilock_config.h"
|
||||
|
||||
#include "bk_gpio.h"
|
||||
#include "key_main.h"
|
||||
#include "multi_button.h"
|
||||
|
||||
#define TAG "KEY"
|
||||
|
||||
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
|
||||
@ -112,12 +116,37 @@ static void key_gpio_int_isr(gpio_id_t id)
|
||||
//rtos_start_timer(&timer_handle);
|
||||
}
|
||||
#endif
|
||||
static int hold_time = 0;
|
||||
static void gpio_key_short_press_cb()
|
||||
{
|
||||
BK_LOGE(TAG,"SHORTDemo: GPIO Key Short Press\r\n");
|
||||
}
|
||||
static void gpio_key_double_press_cb()
|
||||
{
|
||||
BK_LOGE(TAG,"DOUBLE Demo: GPIO Key Double Press\r\n");
|
||||
}
|
||||
static void gpio_key_long_press_cb()
|
||||
{
|
||||
BK_LOGE(TAG,"LONG Demo: GPIO Key Long Press\r\n");
|
||||
}
|
||||
static void gpio_key_hold_press_cb()
|
||||
{
|
||||
hold_time++;
|
||||
if(hold_time > 3*1000/TICKS_INTERVAL){
|
||||
//BK_LOGE(TAG,"\r\n\r\nHOLD Demo: 3S \r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
if(hold_time > 8*1000/TICKS_INTERVAL){
|
||||
hold_time=0;
|
||||
BK_LOGE(TAG,"\r\n\r\nHOLD Demo: 8S \r\n\r\n");
|
||||
}
|
||||
//BK_LOGE(TAG,"HOLD Demo: GPIO Key Hold Press %d\r\n",hold_time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void key_client_start(){
|
||||
|
||||
bk_gpio_driver_init();
|
||||
|
||||
gpio_config_t cfg;
|
||||
@ -138,21 +167,8 @@ void key_client_start(){
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//BK_LOG_ON_ERR(bk_gpio_disable_output(key_ble_reset));
|
||||
//BK_LOG_ON_ERR(bk_gpio_enable_input(key_ble_reset));
|
||||
|
||||
//pull up
|
||||
//BK_LOG_ON_ERR(bk_gpio_enable_pull(key_ble_reset));
|
||||
//BK_LOG_ON_ERR(bk_gpio_pull_up(key_ble_reset));
|
||||
|
||||
//pull down
|
||||
//BK_LOG_ON_ERR(bk_gpio_enable_pull(id));
|
||||
//BK_LOG_ON_ERR(bk_gpio_pull_down(id));
|
||||
|
||||
// disable pull
|
||||
//BK_LOG_ON_ERR(bk_gpio_disable_pull(id));
|
||||
|
||||
//key_initialization();
|
||||
//key_item_configure(ILOCK_SETTINGS_KEY_GPIO,LOW_LEVEL_TRIGGER,gpio_key_short_press_cb,gpio_key_double_press_cb,gpio_key_long_press_cb,gpio_key_hold_press_cb);
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user