From 0cdf171e3ce5eb5faf4c8d20e2cb0551caf67c5c Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 21 Oct 2025 12:00:08 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99=E4=BA=A7?= =?utf8?q?=E6=B5=8BGPS=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../factorytest_protocol.c | 173 ++++++++++++++---- code/sdk/zhihui/services/gnss/src/NMEA0183.c | 2 +- 2 files changed, 134 insertions(+), 41 deletions(-) diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c index bf6c06b5b..8f6a71ccd 100644 --- a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c +++ b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-17 14:31:08 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-08-18 18:37:51 + * @LastEditTime: 2025-10-21 11:11:55 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -67,6 +67,11 @@ #include "gnss_ctl.h" #include "NMEA0183.h" static gps_data_t send_gps_data = {0}; +static osTimerId_t g_gps_test_timer = NULL; +static uint8_t g_gps_test_flag = 0; +static uint32_t g_gps_test_count = 0; +static char *g_gps_tmp_buffer = NULL; +static char *g_gps_time_buffer = NULL; #endif #ifdef ENABLE_BN02 @@ -213,6 +218,116 @@ void ble_acc_check_timer_callback(void) 6); } +#ifdef SUPPORT_GNSS +void gps_test_timer_callback(void) +{ + if(g_gps_tmp_buffer == NULL) + { + g_gps_tmp_buffer = (char*)malloc(1024); + if(g_gps_tmp_buffer == NULL) + { + PRINT("GPS timer callback: malloc tmp buffer failed\n"); + return; + } + } + + if(g_gps_time_buffer == NULL) + { + g_gps_time_buffer = (char*)malloc(10); + if(g_gps_time_buffer == NULL) + { + PRINT("GPS timer callback: malloc time buffer failed\n"); + return; + } + } + + memset(g_gps_tmp_buffer, 0, 1024); + memset(g_gps_time_buffer, 0, 10); + + gps_data_t *gps_data = getPGPSGlobaldata(); + if(gps_data == NULL) + { + PRINT("gps_data == NULL \n"); + + if(g_gps_test_timer != NULL) + { + osTimerStop(g_gps_test_timer); + osTimerDelete(g_gps_test_timer); + g_gps_test_timer = NULL; + } + gnss_stop(); + + if(g_gps_tmp_buffer != NULL) + { + free(g_gps_tmp_buffer); + g_gps_tmp_buffer = NULL; + } + if(g_gps_time_buffer != NULL) + { + free(g_gps_time_buffer); + g_gps_time_buffer = NULL; + } + return; + } + + if (gps_data->last_gps_time_ms > 0) + { + memcpy_s(&send_gps_data, sizeof(gps_data_t), gps_data, sizeof(gps_data_t)); + } + + g_gps_test_count++; + + memset_s(g_gps_tmp_buffer, 1024, 0, 1024); + dump_location_data_to_factory(&send_gps_data, g_gps_tmp_buffer, 1024); + memset_s(g_gps_time_buffer, 10, 0, 10); + sprintf_s(g_gps_time_buffer, 10, "%d", g_gps_test_count); + strcat_s(g_gps_tmp_buffer, 1024, g_gps_time_buffer); + + if(g_gps_tmp_buffer != NULL) + { + uint16_t data_len = (uint16_t)strlen(g_gps_tmp_buffer); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GPS, + 0x01, + (uint8_t*)g_gps_tmp_buffer, + data_len); + } + + if(send_gps_data.status > 1) + { + g_gps_test_flag = 1; + } + + if(g_gps_test_flag || g_gps_test_count >= 2 * 60) + { + if(g_gps_test_timer != NULL) + { + osTimerStop(g_gps_test_timer); + osTimerDelete(g_gps_test_timer); + g_gps_test_timer = NULL; + } + + + gnss_stop(); + + g_gps_test_flag = 0; + g_gps_test_count = 0; + + + if(g_gps_tmp_buffer != NULL) + { + free(g_gps_tmp_buffer); + g_gps_tmp_buffer = NULL; + } + if(g_gps_time_buffer != NULL) + { + free(g_gps_time_buffer); + g_gps_time_buffer = NULL; + } + } +} +#endif + static uint8_t aging_start_flag = 0; void factorytest_start_aging_test(void) @@ -2211,48 +2326,26 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint if (testitem == 0x01) { //定位 - uint8_t send_data = 0; - bool flag = 0; - char tmp[1024]={0}; - char time[10]={0}; #ifdef SUPPORT_GNSS + g_gps_test_flag = 0; + g_gps_test_count = 0; + memset(&send_gps_data, 0, sizeof(gps_data_t)); + gnss_start(); LOS_Msleep(100); - do{ - gps_data_t *gps_data = getPGPSGlobaldata(); - if(gps_data == NULL) - { - PRINT("gps_data == NULL \n"); - return; - } - if (gps_data->last_gps_time_ms > 0) - { - memcpy_s(&send_gps_data,sizeof(gps_data_t),gps_data,sizeof(gps_data_t)); - } - if(send_gps_data.status > 1) - { - flag = 1; - } - else - { - LOS_Msleep(1000); - send_data++; - } - memset_s(tmp,sizeof(tmp),0,sizeof(tmp)); - dump_location_data_to_factory(&send_gps_data,tmp,sizeof(tmp)); - memset_s(time,sizeof(time),0,sizeof(time)); - sprintf_s(time,sizeof(time),"%d",send_data); - strcat_s(tmp,sizeof(tmp),time); - PRINT("send_gps_data.status : %d time : %d\n",send_gps_data.status,send_data); - PRINT("tmp : %s size : %d\n",tmp,strlen(tmp)); - factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, - BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GPS, - 0x01, - (uint8_t*)tmp, - strlen(tmp)); - }while(send_data <= 2 * 60 && !flag); - // PRINT("定位超时 关闭GPS\n"); - gnss_stop(); + + if(g_gps_test_timer == NULL) + { + g_gps_test_timer = osTimerNew((osTimerFunc_t)gps_test_timer_callback, osTimerPeriodic, NULL, NULL); + } + if(g_gps_test_timer != NULL) + { + osTimerStart(g_gps_test_timer, 1000); // 1秒定时 + } + else + { + gnss_stop(); + } #endif } else if(testitem == 0x02) diff --git a/code/sdk/zhihui/services/gnss/src/NMEA0183.c b/code/sdk/zhihui/services/gnss/src/NMEA0183.c index bf27cbe7c..46bd78f2d 100644 --- a/code/sdk/zhihui/services/gnss/src/NMEA0183.c +++ b/code/sdk/zhihui/services/gnss/src/NMEA0183.c @@ -1277,7 +1277,7 @@ void dump_location_data_to_factory(gps_data_t *locationdata,char* buf,int max_bu if (locationdata->starcountN>0) { memset_s(tmpbuf,DUMP_BUF_SIZE,0,DUMP_BUF_SIZE); - sprintf_s(tmpbuf,DUMP_BUF_SIZE,";N,%d", + sprintf_s(tmpbuf,DUMP_BUF_SIZE,"N,%d", locationdata->starcountN); strcat_s(buf,max_buflen,tmpbuf); for(int i=0;i<5;i++) -- 2.17.1