From 3a5441607d0f756ffde32e94950916a12f878411 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Fri, 5 Jul 2024 17:20:45 +0800 Subject: [PATCH] =?utf8?q?=E5=90=88=E5=B9=B6=E8=93=9D=E7=89=99=E6=94=AF?= =?utf8?q?=E4=BB=98=E5=AE=9D=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../alipay/service/alipay_bluetooth.c | 72 ++++++++++++------- .../alipay/service/alipay_bluetooth.h | 9 +-- .../wearable/alipay/service/alipay_feature.h | 2 +- .../nativeui/bluetooth/src/BluetoothModel.cpp | 13 +++- .../service/ble_service/blemoder/bletest.cpp | 46 ++---------- .../service/ble_service/bleservice/bleEvent.c | 10 ++- .../ble_service/bleservice/bleService.c | 25 ++++--- 7 files changed, 94 insertions(+), 83 deletions(-) diff --git a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c index 03fe767a3..1237fa0a8 100644 --- a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c +++ b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c @@ -197,8 +197,10 @@ static void svr_alipay_ble_adv_stop_cb(uint8_t adv_id, adv_status_t status) static void svr_alipay_bt_gatts_service_add_cb(uint8_t server_id, bt_uuid_t *uuid, uint16_t srv_handle, errcode_t status) { - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t *)uuid->uuid) == ALIPAYY_SERVICE_ID)) { - ALIPAY_PRINT_DEBUG(0, "BtGattsServiceAddCallback 0x%x 0x%x 0x%x 0x%x", + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t *)uuid->uuid) == ALIPAYY_SERVICE_ID)) + { + + printf( "BtGattsServiceAddCallback 0x%x 0x%x 0x%x 0x%x", status, server_id, srv_handle, *((uint16_t *)uuid->uuid)); uint16_t id = ALIPAYY_CHARACTERISTIC_ID; gatts_add_chara_info_t character; @@ -224,7 +226,8 @@ static void svr_alipay_bt_gatts_service_add_cb(uint8_t server_id, bt_uuid_t *uui static void svr_alipay_bt_gatts_characteristic_add_cb(uint8_t server_id, bt_uuid_t *uuid, uint16_t srv_handle, gatts_add_character_result_t *result, errcode_t status) { - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t *)uuid->uuid) == ALIPAYY_CHARACTERISTIC_ID)) { + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t *)uuid->uuid) == ALIPAYY_CHARACTERISTIC_ID)) + { ALIPAY_PRINT_DEBUG(0, "BtGattsCharacteristicAddCallback 0x%x 0x%x 0x%x 0x%x 0x%x", status, server_id, srv_handle, result->handle, result->value_handle); uint8_t bas_ccc_val[] = { @@ -362,31 +365,50 @@ static void svr_alipay_btcallback_reg(void) #endif } -void svr_alipay_bt_init_gatts(void) +void ble_add_alipay_service(uint8_t server_id) +{ + printf("ble_add_alipay_service\r\n"); + bt_uuid_t alipay_service_uuid = {0}; + bts_data_to_uuid_len2(ALIPAYY_SERVICE_ID, &alipay_service_uuid); + //只有一个服务,永远是1 + errcode_t ret = 0; +#ifndef SUPPORT_AT_OHOSFWK + ret = gatts_add_service(server_id, &alipay_service_uuid, true); + printf(" NO SUPPORT_AT_OHOSFWK\r\n"); + #else + ret = wrapper_gatts_add_service(server_id, &alipay_service_uuid, true); + printf("ble_add_alipay_service wrapper_gatts_add_service ret: 0x%x serverId = 0x%x uuid.uuid_len:%d\n", ret, server_id,alipay_service_uuid.uuid_len); +#endif + g_alipay_server_id=server_id; +} + + +void svr_alipay_bt_init_gatts(uint8_t server_id ) { uint16_t service_id = ALIPAYY_SERVICE_ID; - uint8_t server_id = 0; + //uint8_t server_id = 0; bt_uuid_t uuid; int ret; uuid.uuid_len = sizeof(service_id); memcpy_s(uuid.uuid, sizeof(uuid.uuid), (char *)&service_id, sizeof(service_id)); -#ifndef SUPPORT_AT_OHOSFWK - ret = gatts_register_server(&uuid, &server_id); /* 注册gatt server */ - if (ret != ERRCODE_SUCC) { - ALIPAY_PRINT_ERR(0, "gatts_register_server ret:0x%x.\r\n", ret); - } -#else - ret = wrapper_gatts_register_server(&uuid, &server_id); /* 注册gatt server */ - if (ret != ERRCODE_SUCC) { - ALIPAY_PRINT_ERR(0, "wrapper_gatts_register_server ret:0x%x.\r\n", ret); - } -#endif +// #ifndef SUPPORT_AT_OHOSFWK +// ret = gatts_register_server(&uuid, &server_id); /* 注册gatt server */ +// if (ret != ERRCODE_SUCC) { +// ALIPAY_PRINT_ERR(0, "gatts_register_server ret:0x%x.\r\n", ret); +// } +// #else +// ret = wrapper_gatts_register_server(&uuid, &server_id); /* 注册gatt server */ +// if (ret != ERRCODE_SUCC) { +// ALIPAY_PRINT_ERR(0, "wrapper_gatts_register_server ret:0x%x.\r\n", ret); +// } +// #endif ALIPAY_PRINT_DEBUG(0, "gatts_register_server ret: 0x%x server_id = 0x%x", ret, server_id); g_alipay_server_id = server_id; uuid.uuid_len = sizeof(service_id); memcpy_s(uuid.uuid, sizeof(uuid.uuid), (char *)&service_id, sizeof(service_id)); + #ifndef SUPPORT_AT_OHOSFWK ret = gatts_add_service(server_id, &uuid, true); if (ret != ERRCODE_SUCC) { @@ -402,19 +424,21 @@ void svr_alipay_bt_init_gatts(void) return; } -void svr_alipay_bluetooth_init(void) +void svr_alipay_bluetooth_init(uint8_t server_id) { -#ifndef SUPPORT_AT_OHOSFWK - bool ret = enable_bt_stack(); - if (ret != ERRCODE_SUCC) { - ALIPAY_PRINT_ERR(0, "enable_bt_stack ret:%u.\r\n", ret); - } -#endif +// #ifndef SUPPORT_AT_OHOSFWK +// bool ret = enable_bt_stack(); +// if (ret != ERRCODE_SUCC) { +// ALIPAY_PRINT_ERR(0, "enable_bt_stack ret:%u.\r\n", ret); +// } +// #endif if (g_alipay_ble_init_flag == true) { return; } + printf("svr_alipay_bluetooth_init \r\n"); svr_alipay_btcallback_reg(); - svr_alipay_bt_init_gatts(); + svr_alipay_bt_init_gatts(server_id); + g_alipay_ble_init_flag = true; return; } diff --git a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.h b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.h index dac57ee4c..7da8ac99f 100644 --- a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.h +++ b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.h @@ -6,9 +6,9 @@ #include "bts_def.h" /* Gatt service UUID */ -#define ALIPAYY_SERVICE_ID 0x3802 +#define ALIPAYY_SERVICE_ID 0x0238 /* Gatt Characteristic UUID */ -#define ALIPAYY_CHARACTERISTIC_ID 0x4A02 +#define ALIPAYY_CHARACTERISTIC_ID 0x024A /* Client Characteristic Configuration UUID */ #define ALIPAYY_BLE_UUID_CLIENT_CHARACTERISTIC_CONF 0x2902 /* Gatt Characteristic max length */ @@ -25,12 +25,13 @@ #define ALIPAY_BLE_DEFAULT_NAME_LEN 9 #define ALIPAY_BLE_MAC_MAX_LEN 6 -void svr_alipay_bluetooth_init(void); +void svr_alipay_bluetooth_init(uint8_t); void ble_alipay_add_characters_input_report_cbk(uint16_t srvc_handle); void svr_alipay_bt_gatts_characteristic_add_dec(uint8_t server_id,uint16_t srv_handle); void svr_alipay_set_adv_start_state(bool state); bool svr_alipay_get_adv_start_state(void); -void svr_alipay_bt_init_gatts(void); +void svr_alipay_bt_init_gatts(uint8_t); void svr_alipay_ble_adv_start_t(void); +void ble_add_alipay_service(uint8_t server_id); #endif diff --git a/code/sdk/application/wearable/alipay/service/alipay_feature.h b/code/sdk/application/wearable/alipay/service/alipay_feature.h index a2f014740..704ba38c4 100755 --- a/code/sdk/application/wearable/alipay/service/alipay_feature.h +++ b/code/sdk/application/wearable/alipay/service/alipay_feature.h @@ -362,7 +362,7 @@ void svr_alipay_bt_gatts_noyify(uint8_t *data, uint16_t data_len); * @brief alipay BLE module initialization. * @return NULL. */ -void svr_alipay_bluetooth_init(void); +void svr_alipay_bluetooth_init(uint8_t); /* * @brief alipay svr init. diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 5d0ac7a8f..ff58c74ea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -35,6 +35,10 @@ #include "tcxo.h" #include "custom_runtime.h" #include "bleService.h" + +#ifdef SUPPORT_AT_OHOSFWK +#include "BluetoothWrapper.h" +#endif namespace OHOS { #define BT_SPP_TASK_STACK_SIZE 2048 @@ -148,14 +152,19 @@ static int bluetooth_init_all(void) BtInitCallBacks(); wrapper_ble_register(); #ifdef SUPPORT_ALIPAY_SEC - // svr_alipay_bluetooth_init(); //Alipay BLE + wrapper_gatts_clear_service(); //Alipay BLE #endif - + // svr_alipay_btcallback_reg(); /***Custom BleService */ +#ifdef SUPPORT_ALIPAY_SEC + //Alipay BLE +#endif svr_ble_bluetooth_init(); //CUSTOM BLE + // BtInitCallBacksEx(); //BLE // BtInitGatts(); //BLE + //start reg ble server wrapper_gatts_service_start(); // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_BLE_WRAPPERSTART,NULL,0); 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 70aade41a..423cdb293 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -199,37 +199,7 @@ cJSON* ble_get_recs_data() Tag_Trailer_t Mp3Trailer; Tag_ID3V2_TAG_T TAG_T; -void Tag_GetTrailer( FILE *fp) -{ -// Get Header - - - fseek(fp,-128,SEEK_END); - fread(Mp3Trailer.Header,3,1,fp); - printf("Header : %s",Mp3Trailer.Header); - // Get Title - fseek(fp,-125,SEEK_END); - fread(Mp3Trailer.Title,30,1,fp); - // Get Artist - fseek(fp,-95,SEEK_END); - fread(Mp3Trailer.Artist,30,1,fp); - printf("Artist : %s",Mp3Trailer.Artist); - // Get Album - fseek(fp,-65,SEEK_END); - fread(Mp3Trailer.Album,30,1,fp); - // Get Year - fseek(fp,-35,SEEK_END); - fread(Mp3Trailer.Year,4,1,fp); - // Get Comment - fseek(fp,-31,SEEK_END); - fread(Mp3Trailer.Comment,30,1,fp); - // Get Cenre - fseek(fp,-1,SEEK_END); - fread(Mp3Trailer.Cenre,1,1,fp); -} - - -void Tag_read_ID2V3( FILE *fp) +void Tag_read_ID3V2( FILE *fp) { // Get Header fseek(fp,10,SEEK_CUR); @@ -238,7 +208,7 @@ void Tag_read_ID2V3( FILE *fp) for(int i=7;i>0;i--) { memset_s(&TAG_T,sizeof(TAG_T),0,sizeof(TAG_T)); - int size =fread(TAG_T.ID,4,1,fp); + uint32_t size =fread(TAG_T.ID,4,1,fp); if(strcmp("TPE1",TAG_T.ID)==0) printf("Header :%d %s\r\n",size,TAG_T.ID); @@ -250,16 +220,13 @@ void Tag_read_ID2V3( FILE *fp) if(strcmp("TPE1",TAG_T.ID)==0) printf("Size :%d\r\n",size); - if(size<0) - return; - fread(TAG_T.Flags,2,1,fp); char buf[124]={0}; if(strcmp("TPE1",TAG_T.ID)==0) { - memset_s(&Mp3Trailer,sizeof(Mp3Trailer),0,sizeof(Mp3Trailer)); + fread(Mp3Trailer.Artist,1,size,fp); printf("data : %s\r\n",Mp3Trailer.Artist); } @@ -333,14 +300,14 @@ char * dir_to_json_buf_malloc_(uint8_t type) } Tag_ID3V2_t tag={0}; fread(tag.Header,3,1,fp); - //printf("tag.Header %s\r\n",tag.Header); fread(&tag.Ver,1,1,fp); - //printf("tag.Ver %d\r\n",tag.Ver); + + memset_s(&Mp3Trailer,sizeof(Mp3Trailer),0,sizeof(Mp3Trailer)); if(tag.Ver==3) { printf("%s\r\n",ent->d_name); fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - Tag_read_ID2V3(fp); + Tag_read_ID3V2(fp); } else { @@ -348,6 +315,7 @@ char * dir_to_json_buf_malloc_(uint8_t type) } fclose(fp); + cJSON* itemJSON = cJSON_CreateObject(); cJSON_AddNumberToObject(itemJSON,"uid",file_index); cJSON_AddStringToObject(itemJSON,"name",fileName.c_str()); 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 936713366..712f4ccd0 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -298,7 +298,10 @@ void send_big_data(uint8_t flag, char *data, int datalen, int total, uint32_t Pa printf("内存分配失败\n"); return; } - + if(Packet_id>=2) + { + msleep(10);//多包数据发送增加延迟 + } // 设置消息头部信息 buf[0] = 0x72; // 消息头 buf[1] = type; // 类型 @@ -486,6 +489,8 @@ errcode_t UnbindSucessCmd(uint8_t flag)//发送解绑指令,解绑界面调用 value[17] = flag; value[18] = Calculate_CRC(value,18); sendok = sendBleData(value,19); + msleep(50);//增加延时,确保可以成功发送解除绑定 + bool ret = bt_is_acl_connected(&phone_addr); if(flag == 1) { @@ -525,7 +530,8 @@ void clearPaireFlag(uint8_t flag) sendBleData(value,19); UnbindSucessCmd(1);//1确认解绑; - uapi_reboot_device(); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING, NULL, 0);//恢复出厂 + //uapi_reboot_device(); } void clearPaireCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue)//发送清除配对指令 { 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 7b542e5c6..fc1daa00f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -694,9 +694,10 @@ static void svr_ble_bt_gatts_service_add_cb(uint8_t server_id, bt_uuid_t *uuid, || uuid_tmp == BLE_UUID_HUMAN_INTERFACE_DEVICE || uuid_tmp == BLE_UUID_ATE_FACTORYTEST_SERVICE || uuid_tmp == BLE_UUID_PPG_BLE_SERVICE - || uuid_tmp == 0x3802 ) + || uuid_tmp == ALIPAYY_SERVICE_ID + ) { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " 0x%x\r\n",uuid_tmp); }else{ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "svr_ble_bt_gatts_service_add_cb UUID not supported 0x%x\r\n",uuid_tmp); return ; @@ -715,8 +716,8 @@ static void svr_ble_bt_gatts_service_add_cb(uint8_t server_id, bt_uuid_t *uuid, bt_uuid_t hid_service_uuid = {0}; bts_data_to_uuid_len2(BLE_UUID_HUMAN_INTERFACE_DEVICE, &hid_service_uuid); - bt_uuid_t alipay_service_uuid = {0}; - bts_data_to_uuid_len2(0x3802, &alipay_service_uuid); + // bt_uuid_t alipay_service_uuid = {0}; + // bts_data_to_uuid_len2(ALIPAYY_SERVICE_ID, &alipay_service_uuid);//0x3802 bt_uuid_t factory_service_uuid = {0}; bts_data_to_uuid_len2(BLE_UUID_ATE_FACTORYTEST_SERVICE, &factory_service_uuid); @@ -752,11 +753,11 @@ static void svr_ble_bt_gatts_service_add_cb(uint8_t server_id, bt_uuid_t *uuid, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ppg ble service svr_ble_bt_gatts_service_add_cb ret:%d\r\n",ret); } - if (ble_gatts_cmp_uuid(uuid, &alipay_service_uuid) == true){ - alipay_add_chart_decr_recv_cmd1(server_id,srv_handle); - ret = gatts_start_service(server_id, srv_handle); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "alipay_service_uuid service svr_ble_bt_gatts_service_add_cb ret:%d\r\n",ret); - } + // if (ble_gatts_cmp_uuid(uuid, &alipay_service_uuid) == true){ + // alipay_add_chart_decr_recv_cmd1(server_id,srv_handle); + // ret = gatts_start_service(server_id, srv_handle); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "alipay_service_uuid service svr_ble_bt_gatts_service_add_cb ret:%d\r\n",ret); + // } } uint16_t alipay_handle = 0; @@ -1162,6 +1163,8 @@ static void svr_ble_register_service(void) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "wrapper_gatts_add_service ret: 0x%x", ret); #endif + svr_alipay_bluetooth_init(serverId); + return; } bool ble_gatts_cmp_uuid(const bt_uuid_t *tgt_uuid, const bt_uuid_t *src_uuid)//比较源uuid和给定的uuid是否匹配 @@ -1192,6 +1195,7 @@ void ble_unregist_server(void) } + void svr_ble_bluetooth_init(void) { memset(&phone_addr,0,sizeof(bd_addr_t)); @@ -1207,7 +1211,7 @@ void svr_ble_bluetooth_init(void) // } //清除上次内容 - wrapper_gatts_clear_service(); + // osDelay(100); srv_ble_server_register_gap_ble_callbacks(); @@ -1220,7 +1224,6 @@ void svr_ble_bluetooth_init(void) // ble_hid_server_init(); #endif - // svr_alipay_bt_init_gatts(); ble_factory_server_init(g_ble_server_id); ble_ppgtest_server_init(g_ble_server_id); -- 2.17.1