优化gps数据的获取以及添加
authorCaisking <Casiking@zhihuishixun.com>
Wed, 23 Jul 2025 02:33:33 +0000 (10:33 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Wed, 23 Jul 2025 02:33:33 +0000 (10:33 +0800)
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp

index b7ac223..0b313d1 100644 (file)
@@ -58,9 +58,8 @@
 #if defined(SUPPORT_GNSS)
 #include "NMEA0183.h"
 #include "gnss_ctl.h"
-#include "pgnss_sample.h"
 #include "graphic_service.h"
-gps_data_t send_gps_data = {0};
+#include "pgnss_sample.h"
 #endif
 
 #ifdef __cplusplus
@@ -189,39 +188,6 @@ static void Training_Notify(void *args, const Topic topic, Request *request) {
     uint8_t heart = *((u_int8_t *)(request->data)); // 进行类型转换
     TraingModel::GetInstance()->AnalysisHeartData(heart);
   }
-#if 0
-  //使用随机数来进行测试
-  srand(time(NULL));
-  // 纬度范围:
-  float lat = (rand() % 420) / 10.0f + 224.5;
-  lat = lat / 10.0f;
-  // 经度范围:
-  float lng = (rand() % 890) / 10.0f + 1137.5;
-  lng = lng / 10.0f;
-  uint32_t time = TraingModel::GetInstance()->get_current_time();
-  TraingModel::GetInstance()->AddGPSData(time, lat, lng);
-  return;
-#endif
-#if defined(SUPPORT_GNSS)
-  //训练GPS
-  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) {
-    //添加经纬度
-    uint32_t time = TraingModel::GetInstance()->get_current_time();
-    TraingModel::GetInstance()->AddGPSData(time, send_gps_data.location.lat,
-                                           send_gps_data.location.lng);
-  }
-  return;
-#endif
 }
 #ifdef __cplusplus
 }
@@ -3037,31 +3003,45 @@ void TraingModel::stop_heart_gps() { CloseGPS(); }
 static osTimerId_t g_timer = nullptr;
 static int Time = 30;
 /*定时器到期时的处理*/
+/*定时器到期时的处理*/
 static void Traing_TimerCallbackProc(int data) {
-  // 倒计时
-  Time--;
-  // 到时的处理
-  if (Time < 0) {
-    // TraingModel::GetInstance()->Traing_timer_callback_out();
-    // return;
-  }
+  /*
+      定时倒计时 后续实现
+  */
 #if defined(SUPPORT_GNSS)
-  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) {
-    //定位成功
-    TraingModel::GetInstance()->SetGPSConnectState(true);
-  } else {
-    TraingModel::GetInstance()->SetGPSConnectState(false);
-  }
+    gps_data_t send_gps_data = {0};
+    gps_data_t *gps_data = getPGPSGlobaldata();
+    
+    if (gps_data == NULL) {
+        PRINT("gps_data == NULL \n");
+        return;
+    }
+
+    // 判断是否为第一次定位并复制GPS数据
+    if (gps_data->last_gps_time_ms > 0) {
+      memcpy_s(&send_gps_data, sizeof(gps_data_t), gps_data, sizeof(gps_data_t));
+    }
+    else
+    {
+      return;
+    }
+
+    // 判断是否定位成功并设置连接状态
+    bool isGpsConnected = (send_gps_data.status > 1);
+    TraingModel::GetInstance()->SetGPSConnectState(isGpsConnected);
+
+    // 判断是否在运动或训练已结束
+    if (uapi_dev_runtime_get_train_status() == 0 ||
+        TraingModel::GetInstance()->GetSportState() == ExerciseState::End) {
+        return;
+    }
+
+    // 如果定位成功,添加经纬度数据
+    if (isGpsConnected) {
+        uint32_t time = TraingModel::GetInstance()->get_current_time();
+        TraingModel::GetInstance()->AddGPSData(time, send_gps_data.location.lat,
+                                              send_gps_data.location.lng);
+    }
 #endif
 }
 /*