合并冲突代码
authorp15692025051 <846603105@qq.com>
Mon, 18 Aug 2025 09:23:09 +0000 (17:23 +0800)
committerp15692025051 <846603105@qq.com>
Mon, 18 Aug 2025 09:23:09 +0000 (17:23 +0800)
2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c
2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.h
2.code/1.sdk/apps/BK_app/bk_app.c
2.code/1.sdk/apps/BK_app/bk_app.h
2.code/1.sdk/apps/common/third_party_profile/jieli/trans_data_demo/le_trans_data.c
2.code/1.sdk/apps/watch/task_manager/bt/bt_event_fun.c

index 411bc4f..a831010 100644 (file)
@@ -253,6 +253,13 @@ void bk_uart_task(void *p)
             }
             
             
+            break;
+        case  BK_UART_WRITE_DATA ://读数据
+            wakeup_cat1(); //先唤醒4g,预防4g休眠
+            ///int sleep_count = 0;
+            printf("BK_UART_WRITE_DATA1");
+            uart_send_blocking(ut, data, len, 3000);
+            printf("BK_UART_WRITE_DATA2");
             break;
         case  BK_UART_CLOSE_TIMER ://关闭定时器
             
@@ -388,8 +395,9 @@ int uart_send_AI_key_even(void)
         return -1;
     }
     // 打印JSON字符串
-    printf("JSON数据: %s\n", json_string);
-    uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    
+    bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
+    //bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));(ut, json_string, strlen(json_string), 20);
     // 释放内存
     cJSON_free(json_string);
     cJSON_Delete(root); 
@@ -416,7 +424,8 @@ int uart_send_PWR_key_even(void)
     }
     
     printf("JSON数据: %s\n", json_string);
-    uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
+    // (ut, json_string, strlen(json_string), 20);
     // 释放内存
     cJSON_free(json_string);
     cJSON_Delete(root);
@@ -466,7 +475,8 @@ int uart_send_single_bt_mac(u8 *name,u8 *mac,u8 connect)
         return -1;
     }
     printf("JSON数据: %s\n", json_string);
-    uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
+    // (ut, json_string, strlen(json_string), 20);
     // 释放内存
     cJSON_free(json_string);
     cJSON_Delete(root);
@@ -517,7 +527,8 @@ void send_bt_connect_state(void){
             return;
         }
         printf("JSON数据1: %s\n", json_string);
-        uart_send_blocking(ut, json_string, strlen(json_string), 20);
+        bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
+        //(ut, json_string, strlen(json_string), 20);
         // 释放内存
         cJSON_free(json_string);
         cJSON_Delete(root);
@@ -533,7 +544,8 @@ void send_bt_connect_state(void){
         }
         
         printf("JSON数据2: %s\n", json_string);
-        uart_send_blocking(ut, json_string, strlen(json_string), 20);
+        // uart_send_blocking(ut, json_string, strlen(json_string), 20);
+        bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
         // 释放内存
         cJSON_free(json_string);
         cJSON_Delete(root);
@@ -550,13 +562,14 @@ int uart_send_bt_list(u8 *data)
             //531
             if (date_len >= 512){
                 printf("uart_send_bt_list 1");
-                
-                uart_send_blocking(ut, data+len_tmp, 512, 200);
+                bk_uart_send_smg(BK_UART_WRITE_DATA, data+len_tmp,512);
+                // uart_send_blocking(ut, data+len_tmp, 512, 200);
                 len_tmp+=512;
             }else{
                 if(date_len >= 0){
                     printf("uart_send_bt_list 2");
-                    uart_send_blocking(ut, data+len_tmp, date_len, 200);
+                    bk_uart_send_smg(BK_UART_WRITE_DATA, data+len_tmp,date_len);
+                    // uart_send_blocking(ut, data+len_tmp, date_len, 200);
                     len_tmp+=date_len;
                 }
                 data_flag = 0;
@@ -573,7 +586,8 @@ int uart_send_bt_list(u8 *data)
         }
         return 0;
     }
-    uart_send_blocking(ut, data, strlen(data), 20);
+    bk_uart_send_smg(BK_UART_WRITE_DATA, data,strlen(data));
+    // uart_send_blocking(ut, data, strlen(data), 20);
     return 0;
 }
 int uart_send_ack(void)
@@ -594,12 +608,102 @@ int uart_send_ack(void)
     }
     // 打印JSON字符串
     //printf("JSON数据: %s\n", json_string);
-    uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    bk_uart_send_smg(BK_UART_WRITE_DATA, json_string,strlen(json_string));
+    // uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    // 释放内存
+    cJSON_free(json_string);
+    cJSON_Delete(root);
+    return 0;
+}
+int uart_send_get_ble_switch(void) //蓝牙开机主动向4g请求获取蓝牙开关状态
+{
+    cJSON *root = cJSON_CreateObject();
+    read_ack_flag = 0;
+    if (root == NULL) {
+        printf( " uart_send_get_ble_switch Failed to create JSON object\n");
+        return -1;
+    }
+    // 添加字符串字段 "event"
+    cJSON_AddStringToObject(root, "event", "get_ble_switch");
+    // 将JSON对象转换为字符串
+    char *json_string = cJSON_Print(root);
+    if (json_string == NULL) {
+        printf( "uart_send_get_ble_switch Failed to print JSON\n");
+        cJSON_Delete(root);
+        return -1;
+    }
+    // 打印JSON字符串
+    printf("uart_send_get_ble_switch JSON数据: %s\n", json_string);
+    bk_uart_send_smg(BK_UART_WRITE_DATA, json_string,strlen(json_string));
+    // uart_send_blocking(ut, json_string, strlen(json_string), 20);
     // 释放内存
     cJSON_free(json_string);
     cJSON_Delete(root);
+    int count = 100;
+    while(count--)
+    {
+        if(read_ack_flag == 1)
+        {
+            break;
+        }
+        os_time_dly(1);
+    }
     return 0;
 }
+int uart_send_get_cat1_imei(void) //蓝牙开机主动向4g请求获取imei号
+{
+    cJSON *root = cJSON_CreateObject();
+    if (root == NULL) {
+        printf( " uart_send_get_ble_switch Failed to create JSON object\n");
+        return -1;
+    }
+    // 添加字符串字段 "event"
+    cJSON_AddStringToObject(root, "event", "get_cat1_imei");
+    // 将JSON对象转换为字符串
+    char *json_string = cJSON_Print(root);
+    if (json_string == NULL) {
+        printf( "uart_send_get_ble_switch Failed to print JSON\n");
+        cJSON_Delete(root);
+        return -1;
+    }
+    // 打印JSON字符串
+    printf("uart_send_get_cat1_imei JSON数据: %s\n", json_string);
+    bk_uart_send_smg(BK_UART_WRITE_DATA, json_string,strlen(json_string));
+    // uart_send_blocking(ut, json_string, strlen(json_string), 20);
+    // 释放内存
+    cJSON_free(json_string);
+    cJSON_Delete(root);
+    return 0;
+}
+static  u8 get_ble_switch = 0;
+static  u16 get_ble_switch_timerid = 0;
+static  u8 get_cat1_imei_state = 0;
+extern void get_ble_switch_imei_timer_init();
+void UART_event(void){
+    
+    if(!get_ble_switch){
+        uart_send_get_ble_switch();
+    }
+    if(!get_cat1_imei_state && get_ble_switch==1){
+        uart_send_get_cat1_imei();
+    }
+    if(get_ble_switch == 1 && get_cat1_imei_state == 1){
+        sys_timer_del(get_ble_switch_timerid);
+        get_ble_switch_timerid=0;
+    }
+    
+}
+static void get_ble_switch_imei_timer_cb(void *priv)
+{
+    bk_app_send_smg(UART_EVENT,NULL,0);
+}
+void get_ble_switch_imei_timer_init(void)
+{
+    if(get_ble_switch_timerid==0){
+        get_ble_switch_timerid = sys_timer_add(NULL, get_ble_switch_imei_timer_cb, 5000); 
+    }
+        
+}
 int uart_send_error(void)
 {
     cJSON *root = cJSON_CreateObject();
@@ -669,6 +773,10 @@ int parse_uart_data(char *json_string)
         // {
 
         // }
+        if(!strcmp(event->valuestring,"ack"))
+        {
+            read_ack_flag =1;
+        }
         if(!strcmp(event->valuestring,"led_rgb_open"))
         {
             //led_rgb_open();
@@ -782,6 +890,7 @@ int parse_uart_data(char *json_string)
 
         if(!strcmp(event->valuestring,"switch_bt_state")) //收到4g传过来的ble开关状态 0 打开蓝牙扫描 1关闭蓝牙扫描
         {
+            read_ack_flag =1; 
             // {
             //     "event":"switch_bt_state",
             //     "data":{
@@ -798,10 +907,12 @@ int parse_uart_data(char *json_string)
                 if (cJSON_IsString(switch_bt_state) && (switch_bt_state->valuestring != NULL)) {
                     printf("蓝牙状态: %s\n", switch_bt_state->valuestring);
                     if (strcmp(switch_bt_state->valuestring, "0") == 0) {
+                        get_ble_switch=1;
                         set_adv_flag_fun(0) ;//开始蓝牙广播
                         // uart_send_PWR_key_even();
                     }else if (strcmp(switch_bt_state->valuestring, "1") == 0)
                     {
+                        get_ble_switch = 1;
                         set_adv_flag_fun(1); //关闭蓝牙广播
                     }
                 }
@@ -815,12 +926,12 @@ int parse_uart_data(char *json_string)
             cJSON *data = cJSON_GetObjectItemCaseSensitive(root, "data");
             if (cJSON_IsString(data) && (data->valuestring != NULL)) {
                 printf("蓝牙扫描: %s\n", data->valuestring);
-                if (strcmp(data->valuestring, "0") == 0) {
-                    set_scan_bt(0);
+                if (strcmp(data->valuestring, "1") == 0) {
+                    // set_scan_bt(0);
                     start_scan_bt();//开始扫描
-                }else if (strcmp(data->valuestring, "1") == 0)
+                }else if (strcmp(data->valuestring, "0") == 0)
                 {
-                    set_scan_bt(1);
+                    // set_scan_bt(1);
                     stop_scan_bt(); //关闭扫描
                 }
             }
@@ -847,6 +958,7 @@ int parse_uart_data(char *json_string)
             cJSON *data = cJSON_GetObjectItemCaseSensitive(root, "data");
             if (cJSON_IsString(data) && (data->valuestring != NULL)) {
                 printf("imei: %s\n", data->valuestring);
+                get_cat1_imei_state=1;
                 set_adv_imei(data->valuestring);//开始扫描
                 
             }
index ff8d8b5..aba5770 100644 (file)
@@ -6,6 +6,7 @@
 typedef enum 
 {
     BK_UART_READ_DATA = 0,
+    BK_UART_WRITE_DATA,
     BK_UART_CLOSE_TIMER,
 
 }bk_uart_msg_event;
@@ -17,4 +18,6 @@ int uart_send_PWR_key_even(void);
 void bk_uart_send_smg(bk_uart_msg_event event,char *data,int data_len);
 int uart_send_bt_list(u8 *data);
 int uart_send_single_bt_mac(u8 *name,u8 *mac,u8 connect);
+void get_ble_switch_imei_timer_init(void);
+void UART_event(void);
 #endif
index 6bfbc86..859cf7b 100644 (file)
@@ -80,7 +80,7 @@ void led_close(void)
 //唤醒4G,成功返回1,失败返回0
 int wakeup_cat1(void)
 {
-    gpio_write(IO_PORTB_03,0);
+    //gpio_write(IO_PORTB_03,0);
     gpio_write(IO_PORTB_03,1);
     int count = 300;
     while(count--)
@@ -187,6 +187,10 @@ void bk_app_task(void *p)
     int msg[16];
     log_info("%s:RUN !!!!!!\n",__FUNCTION__);
     log_info("%s:RUN !!!!!!\n",__FUNCTION__);
+    // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
+    // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
+    // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
+    // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
     while (1) {
         res = os_taskq_pend(NULL, msg, ARRAY_SIZE(msg));
         char *data = (int)msg[2];
@@ -227,7 +231,13 @@ void bk_app_task(void *p)
             AI_VC_start();
             break;
         
-            
+        case UART_EVENT:
+            if(wakeup_cat1() >0)
+            {
+                UART_event();
+            }
+                
+            break;    
         default:
             break;
         }
index 4afced3..783b64e 100644 (file)
@@ -10,6 +10,7 @@ typedef enum
     AI_CLOSE,
     WAKEUQ_BT,
     VAD_RUN,
+    UART_EVENT,
 
 }bk_app_msg_event;
 typedef enum 
index e44a089..5d64600 100644 (file)
@@ -238,6 +238,9 @@ void set_adv_imei(char *imei){
     bt_ble_init();
 }
 void stop_scan_bt(void){
+    if(!scan_state){
+        return;
+    }
     bt_emitter_stop_search_device();//停止扫描 
 }
 ///ble回复扫描耳机列表
@@ -314,11 +317,12 @@ void bt_scan_list(void) //扫描完成发送设备列表->小程序
     //to->uart
     uart_send_bt_list(json_str);
     printf("生成的JSON:\n%s json_str:%d\n", json_str,strlen(json_str));
+    cJSON_free(json_str);
     cJSON_Delete(root); // 释放整个JSON结构的内存
     //使用完之后清空数据
     clear_dev_list();
-    cJSON_free(json_str);
 }
+    
 static int str_to_u8_buf(const char *str, u8 *buf) {
     if (str == NULL || buf == NULL) {
         return -1; // 空指针错误
index 6412835..534414d 100644 (file)
@@ -64,7 +64,7 @@
 #define LOG_DUMP_ENABLE
 #define LOG_CLI_ENABLE
 #include "debug.h"
-
+#include "bk_drive/bk_uart.h"
 #if TCFG_APP_BT_EN
 
 #define __this         (&app_bt_hdl)
@@ -1168,6 +1168,7 @@ void  bt_status_init_ok(struct bt_event *bt)
         __this->auto_exit_limit_time = POWERON_AUTO_CONN_TIME * 1000;
         /* tone_dec_wait_stop(3000); */
     }
+    get_ble_switch_imei_timer_init();
 #if TCFG_USER_BLE_ENABLE
     if (BT_MODE_IS(BT_BQB)) {
         ble_bqb_test_thread_init();