From: Caisking Date: Tue, 22 Jul 2025 08:40:23 +0000 (+0800) Subject: 解析gps bin文件 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=03823aecaa01fe015c36b0bdd0c623983e7026d9;p=mirrors%2FFD230.git 解析gps bin文件 --- diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 726710c5d..d8c8eb2b6 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -3390,8 +3390,43 @@ void uapi_get_a5133_rxdata_timestamp(uint32_t *timestamp) #endif } -void uapi_analysis_sleep_data(char * timepath , char *statuspath) -{ + +void uapi_analysis_sleep_data(char * timepath , char *statuspath,char*gpspath) +{ + typedef struct GPSData { + uint32_t timestamp; // 时间戳 + double latitude; // 纬度 + double longitude; // 经度 +}GPSData_t; +////////////////////////////////////////////////////////////////////// + FILE* file = fopen(gpspath, "rb"); + if (file == NULL) { + perror("无法打开文件"); + return; + } + // 获取文件大小 + fseek(file, 0, SEEK_END); + long fileSize = ftell(file); + rewind(file); + // 计算数据记录数量 + const size_t recordSize = sizeof(GPSData_t); + const size_t recordCount = fileSize / recordSize; + printf("发现 %zu 条GPS数据记录\n", recordCount); + // 逐个读取并打印记录 + GPSData_t gpsData; + for (size_t i = 0; i < recordCount; i++) { + if (fread(&gpsData, recordSize, 1, file) != 1) { + perror("读取数据失败"); + break; + } + + printf("记录 #%zu:\n", i + 1); + printf(" 时间戳: %u\n", gpsData.timestamp); + printf(" 纬度: %.8f\n", gpsData.latitude); + printf(" 经度: %.8f\n", gpsData.longitude); + } + fclose(gpspath); +/////////////////////////////////////////////////////////// uint16_t datelen = 0; uint8_t sleep_data[256] = {0}; @@ -3505,14 +3540,17 @@ void uapi_get_sleep_date_on_log(char *time) { char *timestr = "user/userdata/sleep/%s/sleep_time.bin"; char *statusstr = "user/userdata/sleep/%s/sleep_status.bin"; + char *gpsstr = "user/userdata/sport/GPS_Point/%s.bin"; char timefilePath[64] = {0}; char statusfilePath[64] = {0}; + char gpsfilePath[64] = {0}; sprintf(timefilePath,timestr,time); sprintf(statusfilePath,statusstr,time); + sprintf(gpsfilePath,gpsstr,time); - uapi_analysis_sleep_data(timefilePath,statusfilePath); + uapi_analysis_sleep_data(timefilePath,statusfilePath,gpsstr); }