From 73e489d761cae78c08aa353f57f51a7d5641186e Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 28 Oct 2024 18:26:47 +0800 Subject: [PATCH] =?utf8?q?BR=E5=9B=9E=E8=BF=9E=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/ClassicBlueToothPresenter.cpp | 25 ++++++ .../service/ble_service/blemoder/bletest.cpp | 11 +-- .../service/ble_service/bleservice/bleEvent.c | 87 ++++++++++++------- .../ble_service/bleservice/bleService.c | 30 ++++++- 4 files changed, 118 insertions(+), 35 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index aa764e3dc..12cdc63ae 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -15,6 +15,9 @@ #include "wearable_log.h" #include "ConfigModel.h" #include +#include "BluetoothModel.h" +#include "custom_runtime.h" +#include "ConfigModelC.h" namespace OHOS { // 当前Presenter属性实例化的内存指针 @@ -112,11 +115,33 @@ namespace OHOS bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange"); + bd_addr_t bdaddr={0}; switch (state) { case UICheckBox::SELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); start_custom_ble_service(); // 主动开启蓝牙 + //开启完增加回连 + + uapi_get_br_address(&bdaddr); + if( uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) + { + if (false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 + && bdaddr.addr[4]==0 && bdaddr.addr[5]==0)) + { + int ret = gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret,bdaddr.addr[5],bdaddr.addr[4],bdaddr.addr[3]); + } + else + { + + if(cm_get_A2DP_switch() || cm_get_HFP_switch()) + uapi_a2dp_snk_connect(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + } + + } + ConfigModel::GetInstance()->SetClassicBlueToothState(true); break; diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 9668d15b3..134023b92 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -732,6 +732,7 @@ uint8_t ble_get_sleep_data(uint32_t file_size,uint8_t day_,uint8_t *data) fseek(fp, 0, SEEK_SET); uint16_t read_size_status =fread(data+offset+3+read_size,1,sleep_file_size,fp); read_size+=read_size_status; + read_size+=1; memcpy(data+offset,&read_size,2); fclose(fp); @@ -1297,11 +1298,11 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) break; case 0x45://同步站立历史数据 - if(get_stand_falg()) - { - memcpy(buf+size,&creationTime,4); - size+=4; - } + // if(get_stand_falg()) + // { + // memcpy(buf+size,&creationTime,4); + // size+=4; + // } break; case 0x46://同步卡路里历史数据 diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index ca8d20eb3..ecfe67cc7 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -681,7 +681,7 @@ void clearPaireCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,ui clearPaireFlag(0); } } -uint8_t *savephonename; +uint8_t *savephonename=NULL; //确认配对指令 uint8_t first_bond = 0;//是否第一次绑定 第一次绑定保存配对mac地址 void comfirmPaire(uint8_t flag) @@ -799,6 +799,11 @@ static uint8_t *getPhoneName(uint8_t *data)//获取手机设备名称 { memcpy(str,(uint8_t *)pn->valuestring,datalen+1); } + if(savephonename) + { + ym_free(savephonename); + savephonename=NULL; + } savephonename = ym_malloc(sizeof(char)*datalen); if(savephonename != NULL){ memcpy(savephonename,(uint8_t *)pn->valuestring,datalen+1); @@ -823,7 +828,7 @@ void getPhoneMac(uint8_t *data,uint8_t *phoneMac)//获取手机设备mac这个 memset(phone_tmp,0,6); cJSON* root = cJSON_Parse((const char *)json); uint8_t datalen = 0; - uint8_t count = 0; + uint8_t count = 5; if(root != NULL) { cJSON* mac = cJSON_GetObjectItem(root, "mac"); @@ -834,7 +839,8 @@ void getPhoneMac(uint8_t *data,uint8_t *phoneMac)//获取手机设备mac这个 if (cJSON_IsNumber(macElement)) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"%d", macElement->valueint); if (macElement->prev != NULL) { - phone_tmp[count++] = macElement->valueint; + phone_tmp[count] = macElement->valueint; + count--; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,", "); } } @@ -1351,7 +1357,14 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to cJSON_Delete(dataJSON); // 读取JSON文件 - memcpy(value+18,addr->addr,6); + //memcpy(value+18,addr->addr,6); + value[18]=addr->addr[5]; + value[19]=addr->addr[4]; + value[20]=addr->addr[3]; + value[21]=addr->addr[2]; + value[22]=addr->addr[1]; + value[23]=addr->addr[0]; + memcpy(parie_mac,addr->addr,6); length = 18+6; uint8_t crcvalue = Calculate_CRC(value,length); @@ -2812,11 +2825,20 @@ uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 uapi_get_br_address(&bdaddr); if( uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) { - if (false==bt_is_acl_connected(&bdaddr)) + if (false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 + && bdaddr.addr[4]==0 && bdaddr.addr[5]==0)) { int ret = gap_reconnect_media_device(&bdaddr); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u", ret); - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret,bdaddr.addr[5],bdaddr.addr[4],bdaddr.addr[3]); + } + else + { + + if(cm_get_A2DP_switch() || cm_get_HFP_switch()) + uapi_a2dp_snk_connect(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + } + } @@ -7311,27 +7333,38 @@ errcode_t decode_single_dial_info(ble_read_data *buffer_handle) if (check_dial_freespace(ble_dial_uid, file_size) == false) { + + TRANSMIT_DATA=TRANS_DIAL_FAIL; + CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); return ERRCODE_FAIL; } + else + { + buffer_handle->file_recv_stat.file_name = filename; + buffer_handle->file_recv_stat.file_size = file_size; + buffer_handle->file_recv_stat.file_type = 3;//表盘 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP," filetype = %d, file_name=%s, file_size=%d , dial_uid %04X ,dial_count %d, dial_filetype %d\n", + buffer_handle->file_recv_stat.file_type, + buffer_handle->file_recv_stat.file_name, + buffer_handle->file_recv_stat.file_size, + dialinfo.dial_uid, + dialinfo.dial_count, + dialinfo.file_type - buffer_handle->file_recv_stat.file_name = filename; - buffer_handle->file_recv_stat.file_size = file_size; - buffer_handle->file_recv_stat.file_type = 3;//表盘 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP," filetype = %d, file_name=%s, file_size=%d , dial_uid %04X ,dial_count %d, dial_filetype %d\n", - buffer_handle->file_recv_stat.file_type, - buffer_handle->file_recv_stat.file_name, - buffer_handle->file_recv_stat.file_size, - dialinfo.dial_uid, - dialinfo.dial_count, - dialinfo.file_type + ); + buffer_handle->file_recv_stat.received_size = 0; + buffer_handle->file_recv_stat.lrcvalue = 0; + buffer_handle->receive_file_flag = 1; + uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH); - ); - buffer_handle->file_recv_stat.received_size = 0; - buffer_handle->file_recv_stat.lrcvalue = 0; - buffer_handle->receive_file_flag = 1; - uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH); + TRANSMIT_DATA=TRANS_DIAL_TRANSMITTING; + CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); + return ERRCODE_SUCC; + } - return ERRCODE_SUCC; + + + } static errcode_t install_dial(void) @@ -7414,7 +7447,7 @@ static errcode_t install_dial(void) //安装完后删除表盘 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"remove %s\r\n",lzma_filepath); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"remove %s\r\n",lzma_filepath); if(0!=remove(lzma_filepath)) return ERRCODE_FAIL; @@ -7770,8 +7803,7 @@ void type2AE0Data(ble_read_data *buffer_handle) } else { - TRANSMIT_DATA=TRANS_DIAL_TRANSMITTING; - CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); + ble_reply_cmd(DIAL_FILE_RECV_CMD,1); } @@ -7788,8 +7820,6 @@ void type2AE0Data(ble_read_data *buffer_handle) { ble_reply_cmd(SINGLE_DIAL_FILE_RECV_CMD,1); } else { - TRANSMIT_DATA=TRANS_DIAL_FAIL; - CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); ble_reply_cmd(SINGLE_DIAL_FILE_RECV_CMD,2); } break; @@ -7992,7 +8022,6 @@ errcode_t cancel_recv_file(void) //"/user/userdata/music" char filepath[256]={0}; create_mp3_name(filepath,musicpath,ble_read_timer_p->file_recv_stat.file_name); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"filepath %s\r\n",filepath); remove(filepath); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"filepath %s\r\n",filepath); } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 5ef0bee37..41b5a8266 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -502,7 +502,35 @@ void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, gap_bl int ret =svr_ble_adv_stop(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"%x",ret); - + + // if(!get_ble_pair()&&( cm_get_A2DP_switch() || cm_get_HFP_switch())) + // { + // bd_addr_t bdaddr={0}; + // uapi_get_br_address(&bdaddr); + // if(!(bdaddr.addr[0]==addr->addr[0] && bdaddr.addr[1]==addr->addr[1] && bdaddr.addr[2]==addr->addr[2] && bdaddr.addr[3]==addr->addr[3] + // && bdaddr.addr[4]==addr->addr[4] && bdaddr.addr[5]==addr->addr[5])) + // { + + // if(false==(bt_is_acl_connected(addr))) + // { + // if(cm_get_A2DP_switch() || cm_get_HFP_switch()) + // { + // int ret=gap_reconnect_media_device(addr); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_reconnect_media_device!!! %X\r\n",ret); + // } + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_reconnect_media_device!!! \r\n"); + // } + // else + // { + // if(cm_get_A2DP_switch() || cm_get_HFP_switch()) + // uapi_a2dp_snk_connect(); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + // } + // } + + // } + + set_phone_info(addr,conn_id); -- 2.17.1