فهرست منبع

定位模块优化,定位成功后,导出新增使用卫星数和总卫星数给上层

niujiuru 2 هفته پیش
والد
کامیت
295b823d6b
5فایلهای تغییر یافته به همراه26 افزوده شده و 17 حذف شده
  1. 11 7
      air530z/air530z.c
  2. 1 1
      air530z/air530z.go
  3. 1 1
      air530z/air530z.h
  4. 3 3
      air530z/air530z_test.c
  5. 10 5
      air530z/bridge.go

+ 11 - 7
air530z/air530z.c

@@ -48,8 +48,10 @@ typedef struct
   struct
   {
     bool bOK; // 定位是否成功
-    char lat[MAX_LINE_CHARS]; // 纬度字符串
-    char lon[MAX_LINE_CHARS]; // 经度字符串
+    char lat[32];   // 纬度字符串
+    char lon[32];   // 经度字符串
+    char inuse[8];  // 使用卫星数
+    char inview[8]; // 总的卫星数
   } outPos2d;
   void *out_rwlock;
 } SAir530ZCom;
@@ -77,6 +79,7 @@ static int comio_data_recv_proc(unsigned long wParam/*传递打开的串口句
     else { bWeakPos = true; pComIO->filter.weak_cnt++; }
 
     double lat = pComIO->info.lat, lon = pComIO->info.lon;
+    int inuse = pComIO->info.satinfo.inuse, inview = pComIO->info.satinfo.inview;
 
     if(IS_COORD_NAN(pComIO->filter.lat) || IS_COORD_NAN(pComIO->filter.lon))
     {
@@ -111,13 +114,14 @@ static int comio_data_recv_proc(unsigned long wParam/*传递打开的串口句
       sw_rwlock_wrlock(pComIO->out_rwlock, WAIT_FOREVER);
       sprintf(pComIO->outPos2d.lat, "%.6f", out_lat);
       sprintf(pComIO->outPos2d.lon, "%.6f", out_lon);
+      sprintf(pComIO->outPos2d.inuse, "%d",   inuse);
+      sprintf(pComIO->outPos2d.inview, "%d", inview);
       pComIO->outPos2d.bOK = true;
       sw_rwlock_unlock(pComIO->out_rwlock);
 
       // 3-打印定位结果
       sw_log_trace("[%s] 已定位: lat=%.6f, lon=%.6f, HDOP=%.1f, Sats=%d/%d, DeltaMeters=%.1fm, IsWeakPos=%d", MODULE_NAME,
-                   out_lat, out_lon, pComIO->info.HDOP,
-                   pComIO->info.satinfo.inuse, pComIO->info.satinfo.inview, dist, bWeakPos);
+                   out_lat, out_lon, pComIO->info.HDOP, inuse, inview, dist, bWeakPos);
     }
 
     if(pComIO->filter.weak_cnt >= CONT_WEAK_FRAMES)
@@ -178,15 +182,15 @@ int Air530Z_ComExit()
 }
 
 // 获取当前的2D位置, 返回: 0成功, -1未定位
-int Air530Z_GetPos2D(char lat[MAX_LINE_CHARS], char lon[MAX_LINE_CHARS])
+int Air530Z_GetPos2D(char lat[32], char lon[32], char inuse[8], char inview[8])
 {
   bool bOK = false;
   if(!s_myCom.h || !s_myCom.out_rwlock) return -1; // 防御检查, 加强健壮性
   sw_rwlock_rdlock(s_myCom.out_rwlock, WAIT_FOREVER);
   bOK = s_myCom.outPos2d.bOK;
   if(bOK) {
-    strcpy(lat, s_myCom.outPos2d.lat);
-    strcpy(lon, s_myCom.outPos2d.lon);
+    strcpy(lat, s_myCom.outPos2d.lat); strcpy(lon, s_myCom.outPos2d.lon);
+    strcpy(inuse, s_myCom.outPos2d.inuse); strcpy(inview, s_myCom.outPos2d.inview);
   }
   sw_rwlock_unlock(s_myCom.out_rwlock);
   return bOK ? 0 : -1;

+ 1 - 1
air530z/air530z.go

@@ -53,6 +53,6 @@ func ModuleExit() {
 	air530Z_ComExit()
 }
 
-func Get2DPosition() (lat string, lon string, err error) {
+func Get2DPosition() (lat string, lon string, inuse string, inview string, err error) {
 	return air530Z_Get2DPosition()
 }

+ 1 - 1
air530z/air530z.h

@@ -18,7 +18,7 @@ int Air530Z_ComInit();
 int Air530Z_ComExit();
 
 // 获取当前的2D位置, 返回: 0成功, -1未定位
-int Air530Z_GetPos2D(char lat[MAX_LINE_CHARS], char lon[MAX_LINE_CHARS]);
+int Air530Z_GetPos2D(char lat[32], char lon[32], char inuse[8], char inview[8]);
 
 #ifdef _DEBUG
 void *Air530Z_GetSerialHandle(); // 仿真串口输入, 模拟单元测试时使用

+ 3 - 3
air530z/air530z_test.c

@@ -28,16 +28,16 @@ int main(int argc,char *argv[])
 
   for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) serial_write_recv_buffer(Air530Z_GetSerialHandle(), (unsigned char*)pos[j], strlen(pos[j]));
 
-  char lat[MAX_LINE_CHARS] = {0}, lon[MAX_LINE_CHARS] = {0};
+  char lat[32] = {0}, lon[32] = {0}, inuse[8] = {0}, inview[8] = {0};
 pos_p:
-  ret = Air530Z_GetPos2D(lat, lon);
+  ret = Air530Z_GetPos2D(lat, lon, inuse, inview);
   if(ret == -1)
   {
     sw_log_warn("未定位!");
     sw_thrd_delay(1000);
     goto pos_p;
   }
-  sw_log_info("已定位: lat=%s, lon=%s", lat, lon);
+  sw_log_info("已定位: lat=%s, lon=%s, inuse=%s, inview=%s", lat, lon, inuse, inview);
 
 end_p:
   Air530Z_ComExit();

+ 10 - 5
air530z/bridge.go

@@ -31,11 +31,16 @@ func air530Z_ComExit() error {
 }
 
 // 获取当前的2D位置
-func air530Z_Get2DPosition() (lat string, lon string, err error) {
-	var bufLat, bufLon [64]byte
-	ret := int(C.Air530Z_GetPos2D((*C.char)(unsafe.Pointer(&bufLat[0])), (*C.char)(unsafe.Pointer(&bufLon[0]))))
+func air530Z_Get2DPosition() (lat string, lon string, inuse string, inview string, err error) {
+	var bufLat, bufLon [32]byte
+	var bufInUse, bufInView [8]byte
+
+	ret := int(C.Air530Z_GetPos2D((*C.char)(unsafe.Pointer(&bufLat[0])), (*C.char)(unsafe.Pointer(&bufLon[0])),
+		(*C.char)(unsafe.Pointer(&bufInUse[0])), (*C.char)(unsafe.Pointer(&bufInView[0]))))
 	if ret == -1 {
-		return "", "", fmt.Errorf("未定位, 请稍后")
+		return "", "", "", "", fmt.Errorf("未定位, 请稍后")
 	}
-	return C.GoString((*C.char)(unsafe.Pointer(&bufLat[0]))), C.GoString((*C.char)(unsafe.Pointer(&bufLon[0]))), nil
+
+	return C.GoString((*C.char)(unsafe.Pointer(&bufLat[0]))), C.GoString((*C.char)(unsafe.Pointer(&bufLon[0]))),
+		C.GoString((*C.char)(unsafe.Pointer(&bufInUse[0]))), C.GoString((*C.char)(unsafe.Pointer(&bufInView[0]))), nil
 }