From 43beb40f4e2d3f179a35a7681e0be089d6804754 Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 20 May 2025 20:44:46 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8=E5=B8=82?= =?utf8?q?=E5=9C=BA=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230/service/app_store/app_store.cpp | 104 +++++++++++------- .../ble_service/bleservice/bleEvent.c | 10 +- 2 files changed, 69 insertions(+), 45 deletions(-) diff --git a/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp b/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp index 9890d1ecf..21b36cba2 100644 --- a/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp +++ b/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp @@ -152,6 +152,7 @@ bool ble_install_pkg(const char *pkgName) WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "AppStorePkgOperation install pkgFullName=%s", pkgFullName); InstallParam installParam = { .installLocation = 1, .keepData = false }; uint8_t ret = OHOS::BundleMsClient::GetInstance().Install(pkgFullName, &installParam, InstallCallbackFunc); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER,"install ret = %d",ret); free(pkgFullName); return ret; } else { @@ -175,18 +176,23 @@ bool ble_uninstall_pkg(const char *pkgName) return ret; } -//获取应用列表 + +// 获取应用列表 cJSON* ble_get_pkg_list() { BundleInfo *bundleInfos = nullptr; int32_t count = 0; + char *jsonString; // 1. 获取应用列表 - if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) !=0 ) { + if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get bundle infos"); return nullptr; } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_BLE, "Successfully retrieved %d bundle infos", count); if (count <= 0) { AdapterFree(bundleInfos); + WEARABLE_LOGW(WEARABLE_LOG_MODULE_BLE, "No packages found"); return nullptr; } @@ -204,35 +210,41 @@ cJSON* ble_get_pkg_list() { cJSON *jsonObject = cJSON_CreateObject(); if (jsonObject == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateObject failed at index %d", i); - goto CLEANUP; // 统一错误处理 + goto CLEANUP; } // 添加 "name" 字段 if (cJSON_AddStringToObject(jsonObject, "name", bundleInfos[i].bundleName) == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddStringToObject failed"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to add 'name' field for package at index %d", i); cJSON_Delete(jsonObject); goto CLEANUP; } // 将对象添加到数组 if (cJSON_AddItemToArray(jsonArray, jsonObject) != 1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddItemToArray failed"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to add package at index %d to JSON array", i); cJSON_Delete(jsonObject); goto CLEANUP; } } - // 4. 释放资源并返回 + // 4. 打印最终结果并返回 + jsonString = cJSON_Print(jsonArray); + if (jsonString != nullptr) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_BLE, "Package List JSON:\n%s", jsonString); + cJSON_free(jsonString); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to print package list JSON"); + } + AdapterFree(bundleInfos); return jsonArray; CLEANUP: - // 释放 JSON 数组及内部对象 cJSON_Delete(jsonArray); AdapterFree(bundleInfos); return nullptr; } - //获取表端信息 /** watch_app_store_params @@ -249,98 +261,108 @@ sdkVersion String sdk版本号,如: 13 是 resolution String watch分辨率,格式:宽*高,如:466*466 是 **/ -cJSON *ble_get_device_info() +// 获取设备信息 +cJSON* ble_get_device_info() { - // 创建JSON对象 cJSON *root = cJSON_CreateObject(); if (root == NULL) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to create JSON object"); return NULL; } + // 初始化变量 uint8_t btaddr[6] = {0}; - char btaddr_str[18] = {0}; // MAC地址格式: XX:XX:XX:XX:XX:XX + char btaddr_str[18] = {0}; uint32_t len = sizeof(btaddr); - char version_buf[128] = {0};// 版本信息 + char version_buf[128] = {0}; uint32_t version_len = sizeof(version_buf); + char *jsonString; - // 1. 添加vendorIdentity + // 1. 添加vendorIdentity if (cJSON_AddStringToObject(root, "vendorIdentity", "V5ADA3E85818E4B5") == NULL) { - goto ERRORGOTO; + goto error; } - // 2. 添加consumerIdentity 测试 + // 2. 添加consumerIdentity if (cJSON_AddStringToObject(root, "consumerIdentity", "custom") == NULL) { - goto ERRORGOTO; + goto error; } - // 3. 添加consumerType - if (cJSON_AddStringToObject(root, "consumerType", "0") == NULL) { - goto ERRORGOTO; + // 3. 添加consumerType + if (cJSON_AddStringToObject(root, "consumerType", "1") == NULL) { + goto error; } - // 4. 添加deviceSn (使用蓝牙地址 + // 4. 添加deviceSn (蓝牙地址) + + if (uapi_get_nv_btaddr(btaddr, &len) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get BT address"); - goto ERRORGOTO; + goto error; } sprintf(btaddr_str, "%02X:%02X:%02X:%02X:%02X:%02X", btaddr[0], btaddr[1], btaddr[2], btaddr[3], btaddr[4], btaddr[5]); if (cJSON_AddStringToObject(root, "deviceSn", btaddr_str) == NULL) { - goto ERRORGOTO; + goto error; } - // 5. 添加themeMode (默认值) + // 5. 添加themeMode if (cJSON_AddStringToObject(root, "themeMode", "light") == NULL) { - goto ERRORGOTO; + goto error; } - // 6. 添加chipPlatform + // 6. 添加chipPlatform if (cJSON_AddStringToObject(root, "chipPlatform", "hisi") == NULL) { - goto ERRORGOTO; + goto error; } - // 7. 添加chipModel + // 7. 添加chipModel if (cJSON_AddStringToObject(root, "chipModel", "YH601S") == NULL) { - goto ERRORGOTO; + goto error; } - // 8. 添加os + // 8. 添加os if (cJSON_AddStringToObject(root, "os", "openharmony") == NULL) { - goto ERRORGOTO; + goto error; } - // 9. 添加osVersion + // 9. 添加osVersion if (cJSON_AddStringToObject(root, "osVersion", "5.0.1") == NULL) { - goto ERRORGOTO; + goto error; } - // 10. 添加sdkVersion (从系统获取) + // 10. 添加sdkVersion if (uapi_get_buildversion((uint8_t *)version_buf, version_len) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get SDK version"); - // 版本获取失败时添加默认值 if (cJSON_AddStringToObject(root, "sdkVersion", "unknown") == NULL) { - goto ERRORGOTO; + goto error; } } else { if (cJSON_AddStringToObject(root, "sdkVersion", version_buf) == NULL) { - goto ERRORGOTO; + goto error; } } - // 11. 添加resolution + // 11. 添加resolution if (cJSON_AddStringToObject(root, "resolution", "466*466") == NULL) { - goto ERRORGOTO; + goto error; + } + + // 打印最终结果 + jsonString = cJSON_Print(root); + if (jsonString != NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Device Info JSON:\n%s", jsonString); + cJSON_free(jsonString); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to print device info JSON"); } - // 所有字段添加成功,返回JSON对象 return root; -ERRORGOTO: - // 发生错误时清理资源 +error: cJSON_Delete(root); return NULL; } diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index c5544d1ad..154e644e4 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -221,6 +221,8 @@ static errcode_t get_app_file_path(char* input_filename ,uint32_t input_size, ch return ERRCODE_FAIL; } + uapi_create_dir("/user/app_store"); + int ret = sprintf_s(output_file_path,max_output_size,"/user/app_store/%s",input_filename); if (ret < 0) return ERRCODE_FAIL; @@ -7015,8 +7017,8 @@ errcode_t decode_ota_data(ble_read_data *buffer_handle,uint8_t *data,uint16_t da char filepath[128]={0}; if (get_app_file_path(buffer_handle->file_recv_stat.file_name,strlen(buffer_handle->file_recv_stat.file_name),filepath,sizeof(filepath)) == ERRCODE_SUCC) { - buffer_handle->file_recv_stat.file = fopen(filepath,"w+"); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"create file %s %X\n",filepath,buffer_handle->file_recv_stat.file); + buffer_handle->file_recv_stat.file = fopen(filepath,"w+");//? + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create file %s %X\n",filepath,buffer_handle->file_recv_stat.file); }else{ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"create file %s error %X\n",buffer_handle->file_recv_stat.file_name,buffer_handle->file_recv_stat.file); } @@ -7037,7 +7039,7 @@ errcode_t decode_ota_data(ble_read_data *buffer_handle,uint8_t *data,uint16_t da if (buffer_handle->file_recv_stat.file == NULL) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"6185 buffer_handle->file_recv_stat.file \n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"6185 buffer_handle->file_recv_stat.file \n"); return ERRCODE_FAIL; } size_t writtensize = fwrite(data_,1,datalen,buffer_handle->file_recv_stat.file); @@ -7872,7 +7874,7 @@ void get_watch_msg(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t crcvalue) int num=(ble_nus_max_data_len-18); if(num>482)num=482; - send_long_data(jsonString,num,0x06,0x0E); + send_long_data(jsonString,num,0x06,0x0F); cJSON_free(jsonString); } -- 2.17.1