Library for ublox neo 6m

Dependents:   GPS-Tracking-Velo

Revision:
1:9a8a3f68b005
Parent:
0:8f2e256775d7
Child:
2:2b9befe69d07
--- a/GPS.cpp	Mon May 04 03:41:27 2015 +0000
+++ b/GPS.cpp	Fri Apr 12 17:48:32 2019 +0000
@@ -26,12 +26,22 @@
     //_gps.baud(4800);
     longitude = 0.0;
     latitude = 0.0;
+    altitude = 0.0;
+    
 }
 
 int GPS::sample() {
-    float time;
-    char ns, ew;
-    int lock;
+    float time,horizontal;
+    float time2,longitude2,latitude2,Speed,track;
+    char  ns,ew,aut,ac,ns2,ew2;
+    //int data;
+    float Hdop, Pdop;
+    char Aut;
+    //char star;
+    //int check_data;
+    //char  Pdop;
+    //int   fix_3d;
+    //int   Id1,Id2,Id3,Id4,Id5,Id6,Id7,Id8,Id9,Id10,Id11,Id12;
 
     //return 1; //testing by Jigar
     while (1) {
@@ -39,37 +49,40 @@
         //printf("\n\rentered the GPS.sample while loop \n\r %s\n\r", msg);
         
         
-        // Check if it is a GPGGA msg (matches both locked and non-locked msg)
-        // $GPGGA,000116.031,,,,,0,00,,,M,0.0,M,,0000*52
-        /*
-        eg3. $GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
-                        1       2     3  4       5 6  7  8   9  10 11 12 13  14   15
-            1    = UTC of Position
-            2    = Latitude
-            3    = N or S
-            4    = Longitude
-            5    = E or W
-            6    = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
-            7    = Number of satellites in use [not those in view]
-            8    = Horizontal dilution of position
-            9    = Antenna altitude above/below mean sea level (geoid)
-            10   = Meters  (Antenna height unit)
-            11   = Geoidal separation (Diff. between WGS-84 earth ellipsoid and
-                   mean sea level.  -=geoid is below WGS-84 ellipsoid)
-            12   = Meters  (Units of geoidal separation)
-            13   = Age in seconds since last update from diff. reference station
-            14   = Diff. reference station ID#
-            15   = Checksum
+        /* $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
 
-        */
+     Where:
+     GGA          Global Positioning System Fix Data
+     123519       Fix taken at 12:35:19 UTC
+     4807.038,N   Latitude 48 deg 07.038' N
+     01131.000,E  Longitude 11 deg 31.000' E
+     1            Fix quality: 0 = invalid
+                               1 = GPS fix (SPS)
+                               2 = DGPS fix
+                               3 = PPS fix
+                   4 = Real Time Kinematic
+                   5 = Float RTK
+                               6 = estimated (dead reckoning) (2.3 feature)
+                   7 = Manual input mode
+                   8 = Simulation mode
+     08           Number of satellites being tracked
+     0.9          Horizontal dilution of position
+     545.4,M      Altitude, Meters, above mean sea level
+     46.9,M       Height of geoid (mean sea level) above WGS84
+                      ellipsoid
+     (empty field) time in seconds since last DGPS update
+     (empty field) DGPS station ID number
+     *47          the checksum data, always begins with **/
        // if (sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%*d,%*d, %*f,%*f,%*f,%*f,%*f,%*f,%d ", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) {
-        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) { 
+        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &time, &latitude, &ns, &longitude, &ew, &fix,& sat_tracked,&horizontal,&altitude) >= 1) { 
 
-            if (!lock) 
+            if (!fix) 
             {
                 longitude = 0.0;
                 latitude = 0.0;
+                altitude = 0.0;
                 utc=0.0;
+                sat_tracked=0;
                 return 0;
             } 
             else 
@@ -83,16 +96,104 @@
                 float degrees = trunc(latitude / 100.0f);
                 float minutes = latitude - (degrees * 100.0f);
                 latitude = degrees + minutes / 60.0f;
-                 degrees = trunc(longitude / 100.0f ); //degrees = trunc(longitude / 100.0f * 0.01f);
+                degrees = trunc(longitude / 100.0f ); //degrees = trunc(longitude / 100.0f * 0.01f);
                 minutes = longitude - (degrees * 100.0f);
                 longitude = degrees + minutes / 60.0f;
+                /*int hour = time/10000;
+                int min = (time % 10000)/100;
+                int sek = (time % 100);*/
                 utc=time;
+                //sat_use=sat;
+                //altitude = altitude;
+                //fix=lock;
                 return 1;
             }
-        }  
+        } 
+       //getline();
+       /** $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
+
+     Where:
+     GSA      Satellite status
+     A        Auto selection of 2D or 3D fix (M = manual) 
+     3        3D fix - values include: 1 = no fix
+                                       2 = 2D fix
+                                       3 = 3D fix
+     04,05... PRNs of satellites used for fix (space for 12) 
+     2.5      PDOP (dilution of precision) 
+     1.3      Horizontal dilution of precision (HDOP) 
+     2.1      Vertical dilution of precision (VDOP)
+     *39      the checksum data, always begins with **/
+     //getline2();
+       /*if(sscanf(msg, "GPGSA,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f",&fix_3d,&id1,&id2,&id3,&id4,&id5,&id6,&id7,&id8,&id9,&id10,&id11,&id12,&Pdop,&Hdop)>=1);
+       {
+           
+            if (fix_3d==1) 
+            {
+                id1=id2=id3=id4=id5=id6=id7=id8=id9=id10=id11=id12=0;
+                pdop=0.0;
+                hdop=0.0;
+                //vdop=0.0;
+                
+                return 0;
+            } 
+            else
+            {
+                pdop=Pdop;
+                hdop=Hdop;
+                //vhop=Vhop;
+                //aut=Aut;
+                return 1;
+                
+            }
+       }*/
+        if(sscanf(msg, "GPGSA,%c,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f", &Aut, &fix_3d,&id1,&id2,&id3,&id4,&id5,&id6,&id7,&id8,&id9,&id10,&id11,&id12,&id13,&pdop,&hdop) >= 1) 
+       {
+           
+            if (fix_3d==1) 
+            {
+                id1=id2=id3=id4=id5=id6=id7=id8=id9=id10=id11=id12=0;
+                pdop=0.0;
+                hdop=0.0;
+                //vdop=0.0;
+                
+                return 0;
+            } 
+            else
+            {
+                //pdop=Pdop;
+                //hdop=Hdop;
+                //vhop=Vhop;
+                aut=Aut;
+                return 1;
+                
+            }
+       }
+          if(sscanf(msg, "GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &time2, &ac, &latitude2, &ns2, &longitude2, &ew2, &speed, &date)>=1)
+        {
+            //speed=Speed;
+            //date=Date;
+            //return 1;
+        }   
         return 0;
+        }
     }
-}
+
+       /**$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+        Where:
+        RMC          Recommended Minimum sentence C
+        123519       Fix taken at 12:35:19 UTC
+        A            Status A=active or V=Void.
+        4807.038,N   Latitude 48 deg 07.038' N
+        01131.000,E  Longitude 11 deg 31.000' E
+        022.4        Speed over the ground in knots
+        084.4        Track angle in degrees True
+        230394       Date - 23rd of March 1994
+        003.1,W      Magnetic Variation
+        *6A          The checksum data, always begins with **/  
+     
+        
+        //return 0;
+
 
 float GPS::trunc(float v) {
     if (v < 0.0) {
@@ -109,7 +210,7 @@
     char c;
     while (c = _gps.getc() != '$');   // wait for the start of a line
     // printf("entered the getline loop\n\r");
-    for (int i=0; i<256; i++) {
+    for (int i=0; i<280; i++) {
         msg[i] = _gps.getc();
         if (msg[i] == '\r') {
             msg[i] = 0;
@@ -118,6 +219,19 @@
     }
     error("Overflowed message limit");
 }
+/*void GPS::getline2() {
+    char c;
+    while (c = _gps.getc() != '$');   // wait for the start of a line
+    // printf("entered the getline loop\n\r");
+    for (int i=0; i<300; i++) {
+        msg2[i] = _gps.getc();
+        if (msg2[i] == '\r') {
+            msg2[i] = 0;
+            return;
+        }
+    }
+    error("Overflowed message limit");
+}*/
 
 /*
 $GPRMC,000115.039,V,,,,,,,291006,,*2C