From: penglei <1624952103@qq.com> Date: Thu, 21 Aug 2025 07:22:20 +0000 (+0800) Subject: 增加pgnss缓存日志 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~177^2~3 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2119%2F1;p=mirrors%2FFD230.git 增加pgnss缓存日志 --- diff --git a/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c b/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c index d7130ad3d..a101cdef3 100644 --- a/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c +++ b/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c @@ -6,6 +6,8 @@ */ #include "pgnss_sample.h" #include +#include +#include #include "securec.h" #include "tiot_service_interface.h" #include "pm_definition.h" @@ -45,6 +47,8 @@ static int g_is_pgnss_poweron=0; static int g_is_pgnss_logon=0; static int g_pgnss_stopflag=0; +static char *pgnss_log = NULL; + static int32_t QryVersion(tiot_handle handle) { const uint8_t qryVersion[] = {0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; @@ -239,6 +243,19 @@ static void ListenGnssData(tiot_handle handle) if (decode_nmea(pbuf[index])==1) { // dump_location_data(&g_global_gpsData); + char temp_buf[512]; + dump_location_data_to_buf(&g_global_gpsData, temp_buf, sizeof(temp_buf)); + + // 追加到pgnss_log中 + if (pgnss_log != NULL) { + int current_len = strlen(pgnss_log); + int data_len = strlen(temp_buf); + if (current_len + data_len < 2047) { // 留1字节给字符串结束符 + // strcat(pgnss_log, temp_buf); + snprintf(pgnss_log + current_len, 2048 - current_len, "%s", temp_buf); + } + } + printf("decode_nmea done\r\n"); } } @@ -278,9 +295,24 @@ int PGnssLogEnable(bool enable) void PGnssServerStart(void) { printf("\nenter gnss samples\r\n"); + + if (pgnss_log == NULL) + { + pgnss_log = (char *)malloc(2048); + if (pgnss_log == NULL) { + printf("error: malloc pgnss_log failed!\n"); + return; + } + memset(pgnss_log, 0, 2048); + } + if(g_is_pgnss_poweron == 1) { printf("gnss already on\r\n"); + if (pgnss_log != NULL) { + free(pgnss_log); + pgnss_log = NULL; + } return ; } uapi_pm_add_sleep_veto(PM_ID_SYS); @@ -297,6 +329,11 @@ void PGnssServerStart(void) printf("tiot service init fail\r\n"); g_is_pgnss_poweron = 0; g_pgnss_stopflag = 1; + if (pgnss_log != NULL) { + free(pgnss_log); + pgnss_log = NULL; + } + return; } // 打开日志文件 @@ -305,6 +342,10 @@ void PGnssServerStart(void) g_gnssLogFp = fopen("/user/log/gnss.log", "w"); if (g_gnssLogFp == NULL) { printf("error: open log file error\n"); + if (pgnss_log != NULL) { + free(pgnss_log); + pgnss_log = NULL; + } return; } } @@ -316,6 +357,10 @@ void PGnssServerStart(void) printf("open tiot service fail\r\n"); g_is_pgnss_poweron = 0; g_pgnss_stopflag = 1; + if (pgnss_log != NULL) { + free(pgnss_log); + pgnss_log = NULL; + } return; } printf("open tiot service success\r\n"); @@ -367,4 +412,11 @@ void PGnssServerStart(void) sw_debug_uart_deinit(); uart_config_init(); printf("finish gnss samples\r\n"); + + printf("pgnss_log: %s\r\n", pgnss_log); + // 释放pgnss_log内存 + if (pgnss_log != NULL) { + free(pgnss_log); + pgnss_log = NULL; + } }