Merge #2338 into sdk650pathc0423 from refs/changes/2338/head 2340/target/1 2341/target/1
author罗正 <1732036298@qq.com>
Sat, 20 Sep 2025 12:42:56 +0000 (12:42 +0000)
committer罗正 <1732036298@qq.com>
Sat, 20 Sep 2025 12:42:56 +0000 (12:42 +0000)
雷鸟:

* refs/changes/2338/head: (1 commits squashed)

  - 雷鸟:
    1.cat1_api_disable_cat1_cmd(1)改为cat1_api_disable_cat1_cmd(0)
    2.ota相关代码数组改为malloc方式

Signed-off-by: 罗正 <1732036298@qq.com>
Merged-by: 罗正 <1732036298@qq.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2338
12 files changed:
code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api.h
code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_exit.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_finish.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_token.c

index 7275652..1fe3519 100644 (file)
@@ -310,7 +310,7 @@ void cat1_api_wakeup_cat1(uint8_t wakeup)
     uint8_t wake=wakeup;
     if (en_pin == PIN_NONE)  
     {
-        printf("cat1_api_wakeup_cat1 en_pin is none\r\n");
+        // printf("cat1_api_wakeup_cat1 en_pin is none\r\n");
         return ;
     }
 
index 6eb760d..84c6e11 100644 (file)
@@ -19,7 +19,7 @@ extern void ln_story_player_simple_handle_message(int cmd, char *data, uint32_t
 
 static app_task_definition_t ln_send_taskcfg = {0};
 static app_task_definition_t ln_recv_taskcfg = {0};
-#define LN_HTTP_BOARD_TASK_SIZE 0x3000
+#define LN_HTTP_BOARD_TASK_SIZE 0x2500
 
 static unsigned long g_ln_send_queue = 0xFFFFFFFF;
 static unsigned long g_ln_recv_queue = 0xFFFFFFFF;
@@ -32,10 +32,10 @@ static char g_device_version[128] = {0};
 
 /* 记录最近一次 OTA 查询的升级类型与保存路径 */
 int g_ln_last_update_type = -1;          // -1:未知 0:可选 1:强制
-char g_ln_last_saved_path[256] = {0};    // 最近一次保存的 OTA 包路径
-char g_ln_last_package_url[512] = {0};   // 最近一次查询到的 OTA 包 URL
-char g_ln_last_target_version[64] = {0}; // 最近一次查询到的 OTA 包目标版本
-char g_ln_last_package_md5[65] = {0};    // 最近一次查询到的 OTA 包 MD5
+char *g_ln_last_saved_path = NULL;       // 最近一次保存的 OTA 包路径(动态分配)
+char *g_ln_last_package_url = NULL;      // 最近一次查询到的 OTA 包 URL(动态分配)
+char *g_ln_last_target_version = NULL;   // 最近一次查询到的 OTA 包目标版本(动态分配)
+char *g_ln_last_package_md5 = NULL;      // 最近一次查询到的 OTA 包 MD5(动态分配)
 int g_ln_last_package_size = 0;          // 最近一次查询到的 OTA 包大小(字节)
 static int g_ln_audio_download_cancel = 0; /* 0=正常, 1=取消 */
 int g_ln_is_device_bound = 0;           /* 设备绑定状态 */
@@ -124,7 +124,7 @@ int uapi_ln_ota_get_update_type(void)
 /* 提供给外部查询最近一次保存的 OTA 包路径 */
 const char *uapi_ln_ota_get_saved_path(void)
 {
-    return (g_ln_last_saved_path[0] != '\0') ? g_ln_last_saved_path : NULL;
+    return (g_ln_last_saved_path && g_ln_last_saved_path[0] != '\0') ? g_ln_last_saved_path : NULL;
 }
 
 /* 获取语音对话流录音音频路径 */
@@ -334,21 +334,28 @@ static void ln_handle_ota_task_response(const char *json_buf, int json_len)
            (packageUrl && cJSON_IsString(packageUrl)) ? packageUrl->valuestring : "<null>",
            (packageMd5 && cJSON_IsString(packageMd5)) ? packageMd5->valuestring : "<null>");
     /* 记录必要字段供后续 AT^LN_OTA_DOWNLOAD 使用 */
-    memset(g_ln_last_target_version, 0, sizeof(g_ln_last_target_version));  // 目标版本
-    memset(g_ln_last_package_url, 0, sizeof(g_ln_last_package_url));        // 升级包URL
-    memset(g_ln_last_package_md5, 0, sizeof(g_ln_last_package_md5));        // 升级包MD5
+    if (g_ln_last_target_version) { free(g_ln_last_target_version); g_ln_last_target_version = NULL; }
+    if (g_ln_last_package_url) { free(g_ln_last_package_url); g_ln_last_package_url = NULL; }
+    if (g_ln_last_package_md5) { free(g_ln_last_package_md5); g_ln_last_package_md5 = NULL; }
     g_ln_last_package_size = 0;
     if (targetVersion && cJSON_IsString(targetVersion)) {
-        strncpy(g_ln_last_target_version, targetVersion->valuestring, sizeof(g_ln_last_target_version) - 1);
+        size_t len = strlen(targetVersion->valuestring);
+        g_ln_last_target_version = (char *)malloc(len + 1);
+        if (g_ln_last_target_version) memcpy(g_ln_last_target_version, targetVersion->valuestring, len + 1);
     }
     if (packageUrl && cJSON_IsString(packageUrl)) {
-        strncpy(g_ln_last_package_url, packageUrl->valuestring, sizeof(g_ln_last_package_url) - 1);
+        size_t len = strlen(packageUrl->valuestring);
+        g_ln_last_package_url = (char *)malloc(len + 1);
+        if (g_ln_last_package_url) memcpy(g_ln_last_package_url, packageUrl->valuestring, len + 1);
     }
     if (packageMd5 && cJSON_IsString(packageMd5)) {
-        strncpy(g_ln_last_package_md5, packageMd5->valuestring, sizeof(g_ln_last_package_md5) - 1);
+        size_t len = strlen(packageMd5->valuestring);
+        g_ln_last_package_md5 = (char *)malloc(len + 1);
+        if (g_ln_last_package_md5) memcpy(g_ln_last_package_md5, packageMd5->valuestring, len + 1);
     }
     if (packageSize && cJSON_IsNumber(packageSize)) {
         g_ln_last_package_size = (int)packageSize->valuedouble;
+        if (g_ln_last_package_size < 0) g_ln_last_package_size = 0;
     }
 
     if (ut == 1)
@@ -1277,6 +1284,7 @@ static void ln_http_server_send_task(void const *arg)
             printf("free(mail.data)\n");
             free(mail.data);
         }
+        
     }
 }
 
@@ -1473,7 +1481,7 @@ errcode_t uapi_ln_http_server_init(void)
     ln_recv_taskcfg.create_queue_handle = create_ln_http_recv_queue;
     ln_recv_taskcfg.attr.name = "ln_http_server_recv_task";
     ln_recv_taskcfg.attr.priority = osPriorityNormal;
-    ln_recv_taskcfg.attr.stack_size = LN_HTTP_BOARD_TASK_SIZE;
+    ln_recv_taskcfg.attr.stack_size = 0x1000;
     ln_recv_taskcfg.func = ln_http_server_recv_task;
     ln_recv_taskcfg.use_mem = USE_EXTEND_MEM;
 
index 990ffd7..d881853 100644 (file)
@@ -228,10 +228,10 @@ ScheduleReminder uapi_ln_get_schedule_reminder(void);
 /* ============================== 共享全局状态(跨文件) ============================== */
 extern char *g_device_token;
 extern int g_ln_last_update_type;
-extern char g_ln_last_saved_path[256];
-extern char g_ln_last_package_url[512];
-extern char g_ln_last_target_version[64];
-extern char g_ln_last_package_md5[65];
+extern char *g_ln_last_saved_path;      /* 最近一次保存的 OTA 包路径(动态分配)*/
+extern char *g_ln_last_package_url;     /* 最近一次查询到的 OTA 包 URL(动态分配)*/
+extern char *g_ln_last_target_version;  /* 最近一次查询到的 OTA 包目标版本(动态分配)*/
+extern char *g_ln_last_package_md5;     /* 最近一次查询到的 OTA 包 MD5(动态分配)*/
 extern int g_ln_last_package_size;
 /* 全局角色配置结构体实例 */
 extern LnCharacterConfig g_ln_character_config;
index ba854bc..f12026c 100644 (file)
@@ -143,7 +143,7 @@ uint32_t ln_device_get_character_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
@@ -152,8 +152,9 @@ uint32_t ln_device_get_character_http(const char *device_id,
     client.isHttp = false;
     client.remotePort = 443;
 
-    char *header_buf = (char*)malloc(512);
-    if (!header_buf) return ERRCODE_FAIL;
+    char *header_buf = (char *)malloc(512);
+    if (!header_buf)
+        return ERRCODE_FAIL;
     int hdr = snprintf(header_buf, 512,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
@@ -219,7 +220,7 @@ uint32_t ln_device_get_user_id_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
@@ -228,8 +229,9 @@ uint32_t ln_device_get_user_id_http(const char *device_id,
     client.isHttp = false;
     client.remotePort = 443;
 
-    char *header_buf2 = (char*)malloc(512);
-    if (!header_buf2) return ERRCODE_FAIL;
+    char *header_buf2 = (char *)malloc(512);
+    if (!header_buf2)
+        return ERRCODE_FAIL;
     int hdr = snprintf(header_buf2, 512,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
@@ -311,7 +313,7 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
@@ -320,8 +322,9 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us
     client.isHttp = false;
     client.remotePort = 443;
 
-    char *header_buf3 = (char*)malloc(512);
-    if (!header_buf3) {
+    char *header_buf3 = (char *)malloc(512);
+    if (!header_buf3)
+    {
         return ERRCODE_FAIL;
     }
     int hdr = snprintf(header_buf3, 512,
index a9cfff2..3c17f02 100644 (file)
@@ -542,8 +542,9 @@ static inline int ln_fill_auth_header(HttpClient *client,
 {
     if (!client || !device_id || !device_token)
         return -1;
-    char *header_buf = (char*)malloc(512);
-    if (!header_buf) return -1;
+    char *header_buf = (char *)malloc(512);
+    if (!header_buf)
+        return -1;
     int hdr = snprintf(header_buf, 512,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
@@ -571,7 +572,7 @@ uint32_t ln_emoji_report_status_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
@@ -643,7 +644,7 @@ uint32_t ln_emoji_report_all_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
index 80e1a7a..c26defe 100644 (file)
@@ -16,7 +16,7 @@ uint32_t ln_ota_get_task_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
 #endif
 
@@ -105,8 +105,10 @@ uint32_t ln_ota_get_task_http(const char *device_id,
 end:
     HttpClientUnprepare(&clientData);
     HttpClientClse(&client);
-    if (header_buf) free(header_buf);
-    if (url_with_params) free(url_with_params);
+    if (header_buf)
+        free(header_buf);
+    if (url_with_params)
+        free(url_with_params);
     return ERRCODE_SUCC;
 }
 
@@ -134,7 +136,7 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(500); // 等待模块就绪
 #endif
 
@@ -211,7 +213,8 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path,
                 total_written += written;
                 // 进度上报(使用已知的total_size计算)
                 int percent = (int)((total_written * 100) / total_size);
-                if (percent > 100) percent = 100; // 防止超过100%
+                if (percent > 100)
+                    percent = 100; // 防止超过100%
                 if (percent != last_percent)
                 {
                     last_percent = percent;
@@ -271,7 +274,8 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path,
     fclose(fd);
     HttpClientClse(&client);
     HttpClientUnprepare(&client_data);
-    if (prog) free(prog);
+    if (prog)
+        free(prog);
     printf("[OTA] download process finished\n");
 
     return ret;
@@ -284,7 +288,7 @@ uint32_t ln_ota_download_flow_http(const char *device_id,
     (void)device_id;
     (void)device_token;
     (void)source_version;
-    if (g_ln_last_target_version[0] == '\0' || g_ln_last_package_url[0] == '\0')
+    if (!g_ln_last_target_version || !g_ln_last_package_url || g_ln_last_target_version[0] == '\0' || g_ln_last_package_url[0] == '\0')
     {
         printf("[OTA] no cached task to download, please GET_TASK first\n");
         return ERRCODE_FAIL;
@@ -296,8 +300,14 @@ uint32_t ln_ota_download_flow_http(const char *device_id,
         return ERRCODE_FAIL;
     }
     snprintf(save_path, sp_cap, LN_OTA_SAVE_DIR "/%s.fwpkg", g_ln_last_target_version);
-    memset(g_ln_last_saved_path, 0, sizeof(g_ln_last_saved_path));
-    strncpy(g_ln_last_saved_path, save_path, sizeof(g_ln_last_saved_path) - 1);
+    if (g_ln_last_saved_path)
+    {
+        free(g_ln_last_saved_path);
+        g_ln_last_saved_path = NULL;
+    }
+    g_ln_last_saved_path = (char *)malloc(strlen(save_path) + 1);
+    if (g_ln_last_saved_path)
+        strcpy(g_ln_last_saved_path, save_path);
 
     printf("[OTA] download only: version=%s, url=%s -> %s\n", g_ln_last_target_version, g_ln_last_package_url, save_path);
     int dres;
@@ -319,11 +329,11 @@ uint32_t ln_ota_download_flow_http(const char *device_id,
         return ERRCODE_FAIL;
     }
 
-    size_t done_cap = 64 + strlen(save_path) + strlen(g_ln_last_package_md5);
+    size_t done_cap = 64 + strlen(save_path) + (g_ln_last_package_md5 ? strlen(g_ln_last_package_md5) : 0);
     char *done = (char *)malloc(done_cap);
     if (done)
     {
-        int m = snprintf(done, done_cap, "{\"status\":%d,\"filePath\":\"%s\",\"md5\":\"%s\"}", OTA_DOWNLOAD_STATUS_COMPLETED, save_path, g_ln_last_package_md5);
+        int m = snprintf(done, done_cap, "{\"status\":%d,\"filePath\":\"%s\",\"md5\":\"%s\"}", OTA_DOWNLOAD_STATUS_COMPLETED, save_path, g_ln_last_package_md5 ? g_ln_last_package_md5 : "");
         if (m > 0)
             do_ln_http_server_recv_data(LN_HTTP_RECV_OTA_DOWNLOAD_MSG, done, (uint32_t)m);
         free(done);
index 589b7eb..d752e59 100644 (file)
@@ -51,15 +51,20 @@ static int ln_build_multipart_form_speech_chat(const char *boundary,
 {
     if (!boundary || !filename || !file_data || file_len <= 0 || !out_body || !out_len)
         return -1;
-    char *head = (char*)malloc(512);
-    if (!head) return -1;
+    char *head = (char *)malloc(512);
+    if (!head)
+        return -1;
     int head_len = snprintf(head, 512,
                             "--%s\r\n"
                             "Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n"
                             "Content-Type: audio/mpeg\r\n\r\n",
                             boundary, filename);
-    char *tail = (char*)malloc(128);
-    if (!tail) { free(head); return -1; }
+    char *tail = (char *)malloc(128);
+    if (!tail)
+    {
+        free(head);
+        return -1;
+    }
     int tail_len = snprintf(tail, 128, "\r\n--%s--\r\n", boundary);
     int total = head_len + file_len + tail_len;
     char *body = (char *)malloc((size_t)total);
@@ -107,7 +112,7 @@ uint32_t ln_speech_chat_stream_http(const char *device_id,
     uint8_t *audio_buf = ln_read_file_all_speech_chat(audio_path, &audio_len);
     if (!audio_buf)
     {
-        printf("chatstream: read audio failed\n");
+        printf("chatstream: read audio failed,读取音频报错\n");
         return ERRCODE_FAIL;
     }
     printf("chatstream: audio length = %d\n", audio_len);
@@ -145,7 +150,7 @@ uint32_t ln_speech_chat_stream_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(500);
 #endif
 
@@ -153,8 +158,12 @@ uint32_t ln_speech_chat_stream_http(const char *device_id,
     HttpClientData clientData = (HttpClientData){0};
 
     /* 自定义头:仅保留自定义业务头,Content-Type 交由 postContentType 指定 */
-    char *header_buf = (char*)malloc(512);
-    if (!header_buf) { free(body); return ERRCODE_FAIL; }
+    char *header_buf = (char *)malloc(512);
+    if (!header_buf)
+    {
+        free(body);
+        return ERRCODE_FAIL;
+    }
     int hdr = snprintf(header_buf, 512,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
index 33c5d3a..9856d94 100644 (file)
@@ -51,15 +51,20 @@ static int ln_build_multipart_form_story(const char *boundary,
 {
     if (!boundary || !filename || !file_data || file_len <= 0 || !out_body || !out_len)
         return -1;
-    char *head = (char*)malloc(512);
-    if (!head) return -1;
+    char *head = (char *)malloc(512);
+    if (!head)
+        return -1;
     int head_len = snprintf(head, 512,
                             "--%s\r\n"
                             "Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n"
                             "Content-Type: audio/mpeg\r\n\r\n",
                             boundary, filename);
-    char *tail = (char*)malloc(128);
-    if (!tail) { free(head); return -1; }
+    char *tail = (char *)malloc(128);
+    if (!tail)
+    {
+        free(head);
+        return -1;
+    }
     int tail_len = snprintf(tail, 128, "\r\n--%s--\r\n", boundary);
     int total = head_len + file_len + tail_len;
     char *body = (char *)malloc((size_t)total);
@@ -142,7 +147,7 @@ uint32_t ln_story_choose_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(500);
 #endif
 
@@ -150,8 +155,12 @@ uint32_t ln_story_choose_http(const char *device_id,
     HttpClientData clientData = {0};
 
     /* 设置请求头:精简头部,避免重复(Host/Connection 交由库设置) */
-    char *header_buf = (char*)malloc(1024);
-    if (!header_buf) { free(body); return ERRCODE_FAIL; }
+    char *header_buf = (char *)malloc(1024);
+    if (!header_buf)
+    {
+        free(body);
+        return ERRCODE_FAIL;
+    }
     int hdr = snprintf(header_buf, 1024,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
index 022781f..d1690fd 100644 (file)
@@ -6,14 +6,14 @@ uint32_t ln_story_exit_inquiry_http(const char *device_id,
 {
     if (!device_id || !device_token)
         return ERRCODE_FAIL;
-    #ifdef SUPPORT_CAT1_SERVICE
+#ifdef SUPPORT_CAT1_SERVICE
     /* CAT1 保活 */
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
-    #endif
+#endif
 
     HttpClient client = (HttpClient){0};
     HttpClientData clientData = (HttpClientData){0};
@@ -21,8 +21,9 @@ uint32_t ln_story_exit_inquiry_http(const char *device_id,
     client.remotePort = 443;
 
     /* 普通JSON头 */
-    char *header_buf = (char*)malloc(512);
-    if (!header_buf) return ERRCODE_FAIL;
+    char *header_buf = (char *)malloc(512);
+    if (!header_buf)
+        return ERRCODE_FAIL;
     int hdr = snprintf(header_buf, 512,
                        "deviceId: %s\r\ndeviceToken: %s\r\nContent-Type: application/json\r\n",
                        device_id, device_token);
@@ -68,6 +69,7 @@ uint32_t ln_story_exit_inquiry_http(const char *device_id,
 end:
     HttpClientUnprepare(&clientData);
     HttpClientClse(&client);
-    if (header_buf) free(header_buf);
+    if (header_buf)
+        free(header_buf);
     return ERRCODE_SUCC;
 }
index 12e3f0b..5918bff 100644 (file)
@@ -6,23 +6,24 @@ uint32_t ln_story_finish_http(const char *device_id,
 {
     if (!device_id || !device_token)
         return ERRCODE_FAIL;
-    
-    #ifdef SUPPORT_CAT1_SERVICE
+
+#ifdef SUPPORT_CAT1_SERVICE
     /* CAT1 保活 */
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(200);
-    #endif
+#endif
 
     HttpClient client = (HttpClient){0};
     HttpClientData clientData = (HttpClientData){0};
     client.isHttp = false;
     client.remotePort = 443;
 
-    char *header_buf = (char*)malloc(512);
-    if (!header_buf) return ERRCODE_FAIL;
+    char *header_buf = (char *)malloc(512);
+    if (!header_buf)
+        return ERRCODE_FAIL;
     int hdr = snprintf(header_buf, 512,
                        "deviceId: %s\r\ndeviceToken: %s\r\nContent-Type: application/json\r\n",
                        device_id, device_token);
index 5803588..ee367ef 100644 (file)
@@ -35,7 +35,7 @@ uint32_t ln_story_random_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(500);
 #endif
 
@@ -45,8 +45,9 @@ uint32_t ln_story_random_http(const char *device_id,
     client.remotePort = 443;
 
     /* 设置请求头(包含Content-Type,保持与Python一致) */
-    char *header_buf = (char*)malloc(1024);
-    if (!header_buf) return ERRCODE_FAIL;
+    char *header_buf = (char *)malloc(1024);
+    if (!header_buf)
+        return ERRCODE_FAIL;
     int hdr = snprintf(header_buf, 1024,
                        "deviceId: %s\r\n"
                        "deviceToken: %s\r\n"
@@ -69,12 +70,14 @@ uint32_t ln_story_random_http(const char *device_id,
     }
 
     /* 构建 JSON 请求体(增加转义处理,避免格式错误)*/
-    char *json_body = (char*)malloc(256);
-    char *escaped_theme = (char*)malloc(256);
+    char *json_body = (char *)malloc(256);
+    char *escaped_theme = (char *)malloc(256);
     if (!json_body || !escaped_theme)
     {
-        if (json_body) free(json_body);
-        if (escaped_theme) free(escaped_theme);
+        if (json_body)
+            free(json_body);
+        if (escaped_theme)
+            free(escaped_theme);
         free(header_buf);
         return ERRCODE_FAIL;
     }
index aadd2a5..382f16a 100644 (file)
@@ -52,7 +52,7 @@ static void ln_mkdir_p(const char *path)
 {
     if (!path)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_mkdir_p: path is NULL");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_mkdir_p: path is NULL");
         return;
     }
     (void)mkdir(path, 0755);
@@ -63,7 +63,7 @@ static uint32_t ln_token_save_json(const char *token, uint64_t expire_timestamp)
 {
     if (token == NULL || token[0] == '\0')
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_token_save_json: token is NULL");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_token_save_json: token is NULL");
         return ERRCODE_FAIL;
     }
     ln_mkdir_p(LN_DATA_PATH);
@@ -90,21 +90,21 @@ static uint32_t ln_token_save_json(const char *token, uint64_t expire_timestamp)
     FILE *fp = fopen(LN_TOKEN_FILE, "wb+");
     if (!fp)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_token_save_json: fopen failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_token_save_json: fopen failed");
         free(text);
         return ERRCODE_FAIL;
     }
     size_t n = fwrite(text, 1, strlen(text), fp);
     if (n != strlen(text))
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_token_save_json: fwrite failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_token_save_json: fwrite failed");
         fclose(fp);
         free(text);
         return ERRCODE_FAIL;
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_token_save_json: fwrite success");
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_token_save_json: fwrite success");
     /* 打印保存的json */
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_token_save_json: save json=%s", text);
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_token_save_json: save json=%s", text);
     fclose(fp);
     free(text);
     return (n > 0) ? ERRCODE_SUCC : ERRCODE_FAIL;
@@ -173,32 +173,48 @@ uint32_t uapi_ln_refresh_device_token(void)
  */
 uint32_t ln_token_is_expired(int *expired_out)
 {
-    if (expired_out) *expired_out = 1; /* 默认过期 */
+    if (expired_out)
+        *expired_out = 1; /* 默认过期 */
 
     FILE *fp = fopen(LN_TOKEN_FILE, "rb");
-    if (!fp) return ERRCODE_FAIL;
+    if (!fp)
+        return ERRCODE_FAIL;
     fseek(fp, 0, SEEK_END);
     long len = ftell(fp);
     fseek(fp, 0, SEEK_SET);
-    if (len <= 0 || len > 64 * 1024) { fclose(fp); return ERRCODE_FAIL; }
-    char *buf = (char*)malloc((size_t)len + 1);
-    if (!buf) { fclose(fp); return ERRCODE_FAIL; }
+    if (len <= 0 || len > 64 * 1024)
+    {
+        fclose(fp);
+        return ERRCODE_FAIL;
+    }
+    char *buf = (char *)malloc((size_t)len + 1);
+    if (!buf)
+    {
+        fclose(fp);
+        return ERRCODE_FAIL;
+    }
     size_t n = fread(buf, 1, (size_t)len, fp);
     fclose(fp);
     buf[n] = '\0';
 
     cJSON *root = cJSON_Parse(buf);
-    if (!root) { free(buf); return ERRCODE_FAIL; }
+    if (!root)
+    {
+        free(buf);
+        return ERRCODE_FAIL;
+    }
     cJSON *exp = cJSON_GetObjectItem(root, "expire_timestamp");
     time_t now_s = time(NULL);
     int expired = 1; /* 默认过期 */
-    if (exp && cJSON_IsNumber(exp)) {
+    if (exp && cJSON_IsNumber(exp))
+    {
         uint64_t saved_ts = (uint64_t)exp->valuedouble; /* 保存时的当前时间戳(秒) */
-        const uint64_t TTL_30D = 2592000ULL; /* 30 * 24 * 3600 */
+        const uint64_t TTL_30D = 2592000ULL;            /* 30 * 24 * 3600 */
         expired = ((uint64_t)now_s - saved_ts > TTL_30D) ? 1 : 0;
     }
 
-    if (expired_out) *expired_out = expired;
+    if (expired_out)
+        *expired_out = expired;
     cJSON_Delete(root);
     free(buf);
     return ERRCODE_SUCC;
@@ -230,7 +246,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
 {
     if (device_id == NULL || device_iccid == NULL)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: invalid parameters");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: invalid parameters");
         return ERRCODE_FAIL;
     }
 
@@ -245,19 +261,24 @@ uint32_t ln_get_device_token_http(const char *device_id,
 
     /* 2. 计算签名: deviceId:deviceIccid:timestamp:nonce */
     size_t sd_cap = strlen(device_id) + strlen(device_iccid) + strlen(timestamp) + strlen(nonce) + 4 + 1;
-    char *sign_data = (char*)malloc(sd_cap);
-    if (!sign_data) return ERRCODE_FAIL;
+    char *sign_data = (char *)malloc(sd_cap);
+    if (!sign_data)
+        return ERRCODE_FAIL;
     (void)snprintf(sign_data, sd_cap, "%s:%s:%s:%s", device_id, device_iccid, timestamp, nonce);
     char signature[65] = {0};
     if (ln_hmac_sha256_hex(LN_SIGN_SECRET, sign_data, signature, sizeof(signature)) != 0)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: hmac calc failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: hmac calc failed");
         return ERRCODE_FAIL;
     }
 
     /* 3. 组织自定义请求头 */
-    char *header_buf = (char*)malloc(1024);
-    if (!header_buf) { free(sign_data); return ERRCODE_FAIL; }
+    char *header_buf = (char *)malloc(1024);
+    if (!header_buf)
+    {
+        free(sign_data);
+        return ERRCODE_FAIL;
+    }
     int hdr_len = snprintf(header_buf, 1024,
                            "deviceId: %s\r\n"
                            "deviceIccid: %s\r\n"
@@ -272,7 +293,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
                            (device_version && device_version[0]) ? device_version : "1.0.0");
     if (hdr_len <= 0)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: header build failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: header build failed");
         free(sign_data);
         free(header_buf);
         return ERRCODE_FAIL;
@@ -283,7 +304,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     cat1_api_add_cat1_vote();
     cat1_api_wakeup_cat1(1);
     cat1_api_keep_wakeup(1);
-    cat1_api_disable_cat1_cmd(1);
+    cat1_api_disable_cat1_cmd(0);
     LOS_Msleep(500);
 #endif
 
@@ -295,7 +316,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     HTTPC_RESULT prep = HttpClientPrepare(&clientData, 2048, 4096);
     if (prep != HTTP_SUCCESS)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: HttpClientPrepare failed %d", prep);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: HttpClientPrepare failed %d", prep);
         free(sign_data);
         free(header_buf);
         return ERRCODE_FAIL;
@@ -304,7 +325,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     HTTPC_RESULT res = HttpClientGetRequest(&client, LN_FULL_URL, &clientData);
     if (res != HTTP_SUCCESS)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: request failed %d", res);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: request failed %d", res);
         HttpClientUnprepare(&clientData);
         HttpClientClse(&client);
         free(sign_data);
@@ -315,7 +336,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     int code = HttpClientGetResponseCode(&client);
     if (code != 200)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: HTTP %d", code);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: HTTP %d", code);
         HttpClientUnprepare(&clientData);
         HttpClientClse(&client);
         free(sign_data);
@@ -326,7 +347,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     /* 6. 解析响应JSON */
     if (clientData.responseBuf == NULL || clientData.responseBufLen <= 0)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: empty body");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: empty body");
         HttpClientUnprepare(&clientData);
         HttpClientClse(&client);
         free(sign_data);
@@ -353,7 +374,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     cJSON *root = cJSON_Parse(json_text);
     if (!root)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: JSON parse failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: JSON parse failed");
         free(json_text);
         HttpClientUnprepare(&clientData);
         HttpClientClse(&client);
@@ -367,8 +388,8 @@ uint32_t ln_get_device_token_http(const char *device_id,
     {
         cJSON *msg = cJSON_GetObjectItem(root, "message");
         /* 失败响应,打印errorCode和message 并返回失败 */
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: failed, err=%s", errorCode && cJSON_IsString(errorCode) ? errorCode->valuestring : "unknown");
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: failed, message=%s", msg && cJSON_IsString(msg) ? msg->valuestring : "unknown");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: failed, err=%s", errorCode && cJSON_IsString(errorCode) ? errorCode->valuestring : "unknown");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: failed, message=%s", msg && cJSON_IsString(msg) ? msg->valuestring : "unknown");
         cJSON_Delete(root);
         free(json_text);
         HttpClientUnprepare(&clientData);
@@ -409,7 +430,7 @@ uint32_t ln_get_device_token_http(const char *device_id,
     }
     else
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ln_get_device_token_http: no data field");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_get_device_token_http: no data field");
     }
 
     cJSON_Delete(root);