From: dxy <1731678236qq.com> Date: Wed, 20 Aug 2025 11:12:17 +0000 (+0800) Subject: 开关蓝牙广播 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f602edb4b683533526b331a7ba3b62fd6ea89244;p=mirrors%2F7PIN_V1_5_Jl_SDK.git 开关蓝牙广播 开关经典蓝牙 --- diff --git a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c index 16db19f..7942eb1 100644 --- a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c +++ b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c @@ -655,6 +655,41 @@ int uart_send_get_ble_switch(void) //蓝牙开机主动向4g请求获取蓝牙 } return 0; } +int uart_send_get_bt_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_bt_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(); @@ -673,25 +708,40 @@ int uart_send_get_cat1_imei(void) //蓝牙开机主动向4g请求获取imei号 } // 打印JSON字符串 printf("uart_send_get_cat1_imei JSON数据: %s\n", json_string); + read_ack_flag = 0; 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; } static u8 get_ble_switch = 0; static u16 get_ble_switch_timerid = 0; static u8 get_cat1_imei_state = 0; +static u8 get_bt_switch = 0; void UART_event(void){ + printf("get_ble_switch:%d get_cat1_imei_state:%d get_bt_switch:%d",get_ble_switch,get_cat1_imei_state,get_bt_switch); 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){ + if(!get_bt_switch){ + uart_send_get_bt_switch(); + } + if(get_ble_switch == 1 && get_cat1_imei_state == 1 && get_bt_switch == 1){ sys_timer_del(get_ble_switch_timerid); get_ble_switch_timerid=0; } @@ -826,7 +876,8 @@ void print_hex(char *data ,int len) } } ////*************解析****************////// - +extern u8 is_bredr_close(void); +extern void bt_init_bredr(); int ota_data_len = 0; int parse_uart_data(char *json_string) { @@ -981,11 +1032,44 @@ int parse_uart_data(char *json_string) // 从data对象中获取"switch_bt_state"字段 cJSON *switch_bt_state = cJSON_GetObjectItemCaseSensitive(data, "switch_bt_state"); 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_bt_switch=1; + if (is_bredr_close() == 1) { + printf("3 is_bredr_close: %d\n", is_bredr_close()); + bt_init_bredr(); + } + }else if (strcmp(switch_bt_state->valuestring, "1") == 0) + { + get_bt_switch=1; + if (!is_bredr_close()) { + printf("4 is_bredr_close: %d\n", is_bredr_close()); + bt_close_bredr(); + } + } + } + } + } + if(!strcmp(event->valuestring,"switch_ble_state")) //收到4g传过来的ble开关状态 0 打开蓝牙扫描 1关闭蓝牙扫描 + { + read_ack_flag =1; + // { + // "event":"switch_bt_state", + // "data":{ + // "switch_bt_state":"0" + // } + // } + printf("switch_ble_state : json_string = %s\n", json_string); + + // 获取"data"对象 + cJSON *data = cJSON_GetObjectItemCaseSensitive(root, "data"); + if (cJSON_IsObject(data)) { + // 从data对象中获取"switch_bt_state"字段 + cJSON *switch_bt_state = cJSON_GetObjectItemCaseSensitive(data, "switch_ble_state"); + 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; diff --git a/2.code/1.sdk/apps/BK_app/bk_app.c b/2.code/1.sdk/apps/BK_app/bk_app.c index e9f60e6..eb6886f 100644 --- a/2.code/1.sdk/apps/BK_app/bk_app.c +++ b/2.code/1.sdk/apps/BK_app/bk_app.c @@ -187,6 +187,7 @@ void bk_app_task(void *p) int msg[16]; log_info("%s:RUN !!!!!!\n",__FUNCTION__); log_info("%s:RUN !!!!!!\n",__FUNCTION__); + get_ble_switch_imei_timer_init(); // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__); // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__); // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__); @@ -375,14 +376,14 @@ void bk_app_init(void) // init_vad(&conf); // //err = os_task_create(bk_ALG_task, NULL, 31, 1024*8, 255, "bk_ALG_task"); // err = task_create(bk_ALG_task, NULL, "bk_ALG_task"); - + err = os_task_create(bk_app_task, NULL, 31, 512, 255, "bk_app_task"); //int err = task_create(bk_app_task, NULL, "bk_app_task"); if (err != OS_ERR_NONE) { r_printf("creat fail %x\n", err); } //AI_VC_1S_id = sys_timer_add(NULL, AI_VC_1S_cb, 1000); - get_ble_switch_imei_timer_init(); + } diff --git a/2.code/1.sdk/apps/watch/common/task_table.c b/2.code/1.sdk/apps/watch/common/task_table.c index 0e8c3f5..476b9d5 100644 --- a/2.code/1.sdk/apps/watch/common/task_table.c +++ b/2.code/1.sdk/apps/watch/common/task_table.c @@ -126,7 +126,7 @@ const struct task_info task_info_table[] = { // {"user_ble_protocol", 3, 0, 1024, 256 }, //{"bk_app_task", 3, 0, 1024*2, 256 }, {"bk_ALG_task", 3, 1, 1024, 256 }, - {"bk_uart_task", 3, 1, 2*1024, 256 }, + {"bk_uart_task", 3, 0, 2*1024, 256 }, {0, 0}, };