From 47f72711c2a670d32a8d9282d0072d539a798d51 Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 19 May 2025 16:58:24 +0800 Subject: [PATCH] =?utf8?q?=E6=89=8B=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=BA=94?= =?utf8?q?=E7=94=A8=E5=B8=82=E5=9C=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230/service/app_store/app_store.cpp | 136 ++++++++++++++++++ .../fd230/service/app_store/app_store.h | 4 + .../ble_service/blemoder/CMakeLists.txt | 1 + .../ble_service/blemoder/bleInstruct.cpp | 6 +- .../ble_service/blemoder/bleInstruct.h | 8 +- .../blemoder/ble_instruct_init.cpp | 3 + .../ble_service/bleservice/bleEvent.c | 2 +- .../ble_service/bleservice/bleEvent.h | 38 ++--- 8 files changed, 171 insertions(+), 27 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 8c6efbeb1..8a712b884 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 @@ -127,3 +127,139 @@ errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint1 } return ret; } +/////////////////////////////////////////////////////////////////////////////////// + + +#ifdef BLE_INSTRUCT + +// #include "bleEvent.h" +#include "bleInstruct.h" +#include "cJSON.h" +#include "adapter.h" + +bool ble_install_pkg(const char *pkgName) +{ + if (pkgName == nullptr || strlen(pkgName) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_install_pkg: null or empty pkgName"); + return false; + } + + uint8_t len = strlen(FS_DIR_APP_STORE) + strlen(pkgName) + 1; + char *pkgFullName = (char *)malloc(len); + if (pkgFullName != nullptr) { + (void)sprintf_s(pkgFullName, len, "%s%s", FS_DIR_APP_STORE, 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); + free(pkgFullName); + return ret; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to allocate memory for pkgFullName"); + return false; + } +} + +bool ble_uninstall_pkg(const char *pkgName) +{ + if (pkgName == nullptr || strlen(pkgName) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_uninstall_pkg: null or empty pkgName"); + return false; + } + + StopJsApp((char*)pkgName); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "AppStorePkgOperation uninstall pkgName=%s", pkgName); + InstallParam installParam = { .installLocation = 1, .keepData = false }; + uint8_t ret = OHOS::BundleMsClient::GetInstance().Uninstall((char*)pkgName, &installParam, UninstallCallbackFunc); + + return ret; +} + +//获取应用列表 +cJSON* ble_get_pkg_list() { + BundleInfo *bundleInfos = nullptr; + int32_t count = 0; + + // 1. 获取应用列表 + if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) !=0 ) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get bundle infos"); + return nullptr; + } + if (count <= 0) { + AdapterFree(bundleInfos); + return nullptr; + } + + // 2. 创建 JSON 数组 + cJSON *jsonArray = cJSON_CreateArray(); + if (jsonArray == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed"); + AdapterFree(bundleInfos); + return nullptr; + } + + // 3. 填充数组元素 + for (int32_t i = 0; i < count; i++) { + // 创建 JSON 对象 + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateObject failed at index %d", i); + goto CLEANUP; // 统一错误处理 + } + + // 添加 "name" 字段 + if (cJSON_AddStringToObject(jsonObject, "name", bundleInfos[i].bundleName) == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddStringToObject failed"); + cJSON_Delete(jsonObject); + goto CLEANUP; + } + + // 将对象添加到数组 + if (cJSON_AddItemToArray(jsonArray, jsonObject) != 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddItemToArray failed"); + cJSON_Delete(jsonObject); + goto CLEANUP; + } + } + + // 4. 释放资源并返回 + AdapterFree(bundleInfos); + return jsonArray; + +CLEANUP: + // 释放 JSON 数组及内部对象 + cJSON_Delete(jsonArray); + AdapterFree(bundleInfos); + return nullptr; +} + +//获取表端信息 +/** +watch_app_store_params +vendorIdentity String 品牌商在聚合平台注册 是 +consumerIdentity String 消费者账号 是 +consumerType String 消费者账号类型,0:品牌商注册账号,1:聚合平台注册账号 是 +deviceSn String 设备序列号,从表端获取,需要品牌商提前将序列号在聚合平台注册 是 +themeMode String H5页面主题, 模式:light(浅色)(默认)/dark(深色) 是 +chipPlatform String 芯片平台,如:hisi 是 +chipModel String 芯片型号, 如:300 是 +os String watch系统,如: openharmony等 是 +osVersion String watch系统版本,如: 5.0.1 是 +sdkVersion String sdk版本号,如: 13 是 +resolution String watch分辨率,格式:宽*高,如:466*466 是 +**/ +cJSON *ble_get_device_info() +{ + return nullptr; +} + + +void ble_app_store_init() +{ + bleInstruct_t.ble_bin_install = ble_install_pkg; + bleInstruct_t.ble_app_delete = ble_uninstall_pkg; + bleInstruct_t.ble_app_list = ble_get_pkg_list; + bleInstruct_t.ble_get_watch_msg = ble_get_device_info; +} + +#endif + diff --git a/code/sdk/application/wearable/fd230/service/app_store/app_store.h b/code/sdk/application/wearable/fd230/service/app_store/app_store.h index 7bbc93b96..47064738d 100644 --- a/code/sdk/application/wearable/fd230/service/app_store/app_store.h +++ b/code/sdk/application/wearable/fd230/service/app_store/app_store.h @@ -65,6 +65,10 @@ typedef struct { errcode_t AppStorePkgOperation(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +#ifdef BLE_INSTRUCT +void ble_app_store_init(void); +#endif + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/services/ble_service/blemoder/CMakeLists.txt b/code/sdk/zhihui/services/ble_service/blemoder/CMakeLists.txt index dfd4d789f..13f422c75 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/CMakeLists.txt +++ b/code/sdk/zhihui/services/ble_service/blemoder/CMakeLists.txt @@ -13,6 +13,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include + ${ROOT_DIR}/application/wearable/fd230/service/app_store/ ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/weather/include ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/heart_blood/health_service ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/sleep/include/ diff --git a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp index ecbebe9b1..ddb6c4318 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp @@ -1229,13 +1229,13 @@ bool IS_free_save_Mp3(uint32_t size) } -void ble_bin_install(void) +bool ble_bin_install(const char * data) { - return bleInstruct_t.ble_bin_install(); + return bleInstruct_t.ble_bin_install(data); } -bool ble_app_delete(char *data) +bool ble_app_delete(const char *data) { return bleInstruct_t.ble_app_delete(data); } diff --git a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h index 2ae025a8f..73df6e776 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h +++ b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h @@ -416,7 +416,7 @@ errcode_t get_dial_file_path(char* input_dialname ,uint32_t input_size, char* ou uint16_t get_str_nodisplay_number(char *str, uint32_t max_len); -void ble_bin_install(void); +bool ble_bin_install(const char * data); typedef struct bleInstruct { uint16_t (*get_str_nodisplay_number_cb)(char *str, uint32_t max_len); @@ -631,9 +631,9 @@ typedef struct bleInstruct void (*ble_disconnect_ok)(void); void (*hand_watch_first_time_Paired)(void); - void (*ble_bin_install)(void); + bool (*ble_bin_install)(const char * data); - bool (*ble_app_delete)(char * data); + bool (*ble_app_delete)(const char * data); cJSON* (*ble_app_list)(void); @@ -649,7 +649,7 @@ void ble_instruct_init(void); void ble_mp3_init(void); -bool ble_app_delete(char *data); +bool ble_app_delete(const char *data); cJSON* ble_app_list(void); diff --git a/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp b/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp index dc2de890b..351ec7b46 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp @@ -10,6 +10,7 @@ // #include "SetDialModel.h" #include "SleepModel.h" // #include "PlayersModel.h" +#include "app_store.h" void ble_instruct_init(void) { @@ -33,4 +34,6 @@ void ble_instruct_init(void) ble_config_init(); + ble_app_store_init(); + } \ No newline at end of file diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index dd706a85e..3b2ccdbbe 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -7959,7 +7959,7 @@ void decode_file_checksum_2AE6(ble_read_data *buffer_handle) CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); ble_reply_cmd(FILE_SUCC_TRANSFER,1); - ble_bin_install(); + // ble_bin_install(); // ble_mp3_list_update(); diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h index c0038997a..71de42b34 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h @@ -294,9 +294,8 @@ typedef struct #pragma pack(1) typedef struct { - - -}msg_stop_sport_mode_info_t;//开启指定运动模式 SWITCH_SPORT_MODE + uint8_t sport_mode;////0 健走 1跑步 2骑行 +}msg_stop_sport_mode_info_t;//停止指定运动模式 SWITCH_SPORT_MODE #pragma pack() #pragma pack(1) @@ -309,6 +308,7 @@ typedef struct #pragma pack(1) typedef struct { + uint8_t switch_hr; //0关闭 1开启 //对应数据的指令类型 }msg_switch_get_realhr_info_t;//开启/关闭自动获取实时训练数据SWITCH_GET_REAL_HEART_CMD #pragma pack() @@ -475,24 +475,24 @@ typedef struct #pragma pack() #pragma pack(1) -typedef struct -{ - //对应数据的指令类型 -}msg_factory_param_info_t;//app发送恢复出厂设置 +// typedef struct +// { +// //对应数据的指令类型 +// }msg_factory_param_info_t;//app发送恢复出厂设置 #pragma pack() #pragma pack(1) -typedef struct -{ - //对应数据的指令类型 -}msg_reset_param_info_t;//app发送重新启动 +// typedef struct +// { +// //对应数据的指令类型 +// }msg_reset_param_info_t;//app发送重新启动 #pragma pack() #pragma pack(1) -typedef struct -{ - //对应数据的指令类型 -}msg_poweroff_param_info_t;//app关机 +// typedef struct +// { +// //对应数据的指令类型 +// }msg_poweroff_param_info_t;//app关机 #pragma pack() #pragma pack(1) @@ -720,11 +720,11 @@ typedef struct #pragma pack() #pragma pack(1) -typedef struct -{ - //对应数据的指令类型 +// typedef struct +// { +// //对应数据的指令类型 -}msg_get_sys_time_info_t;//获取系统时间 +// }msg_get_sys_time_info_t;//获取系统时间 #pragma pack() #pragma pack(1) -- 2.17.1