}
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();
}
// 打印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;
}
}
}
////*************解析****************//////
-
+extern u8 is_bredr_close(void);
+extern void bt_init_bredr();
int ota_data_len = 0;
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;
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__);
// 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();
+
}