增加手表端的获取应用市场信息接口
authorCaisking <Casiking@zhihuishixun.com>
Mon, 19 May 2025 12:07:25 +0000 (20:07 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 19 May 2025 12:07:25 +0000 (20:07 +0800)
code/sdk/application/wearable/fd230/service/app_store/app_store.cpp

index 8a712b8..9890d1e 100644 (file)
@@ -136,6 +136,7 @@ errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint1
 #include "bleInstruct.h"
 #include "cJSON.h"
 #include "adapter.h"
+#include "custom_utils.h"
 
 bool ble_install_pkg(const char *pkgName)
 {
@@ -235,21 +236,113 @@ CLEANUP:
 //获取表端信息
 /** 
 watch_app_store_params
-vendorIdentity String  品牌商在聚合平台注册  是
+vendorIdentity String  品牌商在聚合平台注册  是  V5ADA3E85818E4B5
 consumerIdentity       String  消费者账号 是
 consumerType   String  消费者账号类型,0:品牌商注册账号,1:聚合平台注册账号        是
 deviceSn       String  设备序列号,从表端获取,需要品牌商提前将序列号在聚合平台注册      是
 themeMode      String  H5页面主题, 模式:light(浅色)(默认)/dark(深色)       是
 chipPlatform   String  芯片平台,如:hisi       是
 chipModel      String  芯片型号, 如:300 是
-os     String  watch系统,如: openharmony等 是
+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;
+    // 创建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 
+    uint32_t len = sizeof(btaddr);
+    char version_buf[128] = {0};// 版本信息
+    uint32_t version_len = sizeof(version_buf);
+
+    // 1. 添加vendorIdentity 
+    if (cJSON_AddStringToObject(root, "vendorIdentity", "V5ADA3E85818E4B5") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 2. 添加consumerIdentity 测试
+    if (cJSON_AddStringToObject(root, "consumerIdentity", "custom") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 3. 添加consumerType 
+    if (cJSON_AddStringToObject(root, "consumerType", "0") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 4. 添加deviceSn (使用蓝牙地址
+    if (uapi_get_nv_btaddr(btaddr, &len) != 0) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get BT address");
+        goto ERRORGOTO;
+    }
+    
+    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;
+    }
+
+    // 5. 添加themeMode (默认值)
+    if (cJSON_AddStringToObject(root, "themeMode", "light") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 6. 添加chipPlatform 
+    if (cJSON_AddStringToObject(root, "chipPlatform", "hisi") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 7. 添加chipModel 
+    if (cJSON_AddStringToObject(root, "chipModel", "YH601S") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 8. 添加os 
+    if (cJSON_AddStringToObject(root, "os", "openharmony") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 9. 添加osVersion 
+    if (cJSON_AddStringToObject(root, "osVersion", "5.0.1") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 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;
+        }
+    } else {
+        if (cJSON_AddStringToObject(root, "sdkVersion", version_buf) == NULL) {
+            goto ERRORGOTO;
+        }
+    }
+
+    // 11. 添加resolution 
+    if (cJSON_AddStringToObject(root, "resolution", "466*466") == NULL) {
+        goto ERRORGOTO;
+    }
+
+    // 所有字段添加成功,返回JSON对象
+    return root;
+
+ERRORGOTO:
+    // 发生错误时清理资源
+    cJSON_Delete(root);
+    return NULL;
 }