SSLM1 / 2_GPS_GMS6-CR6

Dependents:   2-1_GMS6-CR6 5_flightmode 5-2_thrustermode 5-3_thruster_depressmode ... more

Revision:
3:b4133b354e5b
Parent:
2:98e44a8cca1d
Child:
4:dc48563aad90
--- a/GMS6_CR6.cpp	Mon Jul 13 11:51:00 2020 +0000
+++ b/GMS6_CR6.cpp	Fri Jul 17 12:13:26 2020 +0000
@@ -73,4 +73,61 @@
         *G = 4;
         *(G+1) = 4;
     }
+}
+
+void GMS6_CR6::read_low(float *G)
+{
+    char  gps_data[256];
+    memset(gps_data, '\0', 256);
+    
+    int cnt_gps = 0;
+    
+    float world_time;
+    int rlock, sat_num;
+    char lat, lon;
+    
+    float lon_east = 0;
+    float lat_north = 0;
+    int i = 0;
+    
+    while(lat_north < 20 && i < 1000000)                        //緯度が20度以上と測定されるまたは一定回数ループが回ると抜ける
+    {   
+        if(gps.readable())
+        {
+            gps_data[cnt_gps] = gps.getc();
+            
+            if(gps_data[cnt_gps] == '$' || cnt_gps == 256)
+            {
+                cnt_gps = 0;
+                memset(gps_data, '\0', 256); //この関数なんや
+            }
+            else if(gps_data[cnt_gps] == '\r')
+            {   
+                if(sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d", &world_time, &lat_north, &lat, &lon_east, &lon, &rlock, &sat_num) >= 1)
+                {
+                    if (rlock == 1)
+                    {
+                        lat_north = _DMS2DEG(lat_north);
+                        lon_east = _DMS2DEG(lon_east);
+                    }
+                }
+            }
+            else
+            {
+                cnt_gps++;
+            }
+        }
+        i++;
+    }
+        
+    if(lat_north > 20 && lat_north < 90 && lon_east > 90 && lon_east < 180)           //緯度が正常な値のときのみ値を返す
+    {
+        *G = lat_north;
+        *(G+1) = lon_east;
+    }
+    else
+    {
+        *G = 4;
+        *(G+1) = 4;
+    }
 }
\ No newline at end of file