Example with new gnss libraries

Dependencies:   gnss

Fork of example-gnss by u-blox

Files at this revision

API Documentation at this revision

Comitter:
fahim.alavi@u-blox.com
Date:
Fri Jul 20 14:38:50 2018 +0500
Parent:
7:746ae478fdf7
Commit message:
New gnss library pass through enabled

Changed in this revision

gnss.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 746ae478fdf7 -r c8b7490c3fb0 gnss.lib
--- a/gnss.lib	Mon Jul 31 10:48:08 2017 +0100
+++ b/gnss.lib	Fri Jul 20 14:38:50 2018 +0500
@@ -1,1 +1,1 @@
-https://mbed.org/teams/ublox/code/gnss/#56eda66d585b
+https://os.mbed.com/users/fahimalavi/code/gnss/
diff -r 746ae478fdf7 -r c8b7490c3fb0 main.cpp
--- a/main.cpp	Mon Jul 31 10:48:08 2017 +0100
+++ b/main.cpp	Fri Jul 20 14:38:50 2018 +0500
@@ -15,7 +15,7 @@
  */
 
 #include "mbed.h"
-#include "gnss.h"
+#include "gnss_operations.h"
 
 #define CHECK_TALKER(s) ((buffer[3] == s[0]) && (buffer[4] == s[1]) && (buffer[5] == s[2]))
 
@@ -35,74 +35,85 @@
  * GNSS module will flash as the module achieves a fix.
  */
 
+GnssOperations gnss;
+Serial host_serial(USBTX, USBRX);
+
+bool print_hex_buffer(char *buffer, uint32_t length) {
+
+	char log[256] = "";
+
+	for (int i =0; i < length; i++) {
+		sprintf(log, "%s%02X ", log, buffer[i]);
+	}
+	printf(log);
+
+	return true;
+}
+
+void passThroughThreadHandler() {
+	while (1) {
+
+		gnss.send_to_gnss(host_serial.getc());
+
+	}
+}
+
+
 int main()
 {
-    GnssSerial gnss;
     int gnssReturnCode;
     int length;
     char buffer[256];
+    bool enable_pass_through = true;
+    Thread passThroughThread;
+    host_serial.baud(115200);
     
     printf ("Starting up...\n");
     if (gnss.init()) {
         printf ("Waiting for GNSS to receive something...\n");
+        passThroughThread.start(callback(passThroughThreadHandler));
+        gnss.enable_ubx_odo();
+        gnss.enable_ubx_nav_odo();
+        gnss.enable_ubx_nav_pvt();
         while (1) {
-            gnssReturnCode = gnss.getMessage(buffer, sizeof(buffer));
-            if (gnssReturnCode > 0) {
-                ledGreen = 0;
-                ledBlue = 1;
-                ledRed = 1;
-                length = LENGTH(gnssReturnCode);
+    		double lat = 0.0, lon = 0.0;
 
-                printf("NMEA: %.*s\n", length - 2, buffer);
+    		gnssReturnCode = gnss.getMessage(buffer, sizeof(buffer));
 
-                if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6)) {
-                    // Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
-                    if ((buffer[0] == '$') || buffer[1] == 'G') {
-                      if (CHECK_TALKER("GLL")) {
-                            double latitude = 0, longitude = 0;
-                            char ch;
+    		if (gnssReturnCode > 0) {
+    			length = LENGTH(gnssReturnCode);
 
-                            if (gnss.getNmeaAngle(1, buffer, length, latitude) && 
-                                gnss.getNmeaAngle(3, buffer, length, longitude) && 
-                                gnss.getNmeaItem(6, buffer, length, ch) && (ch == 'A')) {
-                                ledBlue = 0;
-                                ledRed = 0;
-                                ledGreen = 0;
+    			if (enable_pass_through){
+    				for (int i=0; i<length; i++)
+    					printf("%c", buffer[i]);
+    			}
+
+    			if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6)) {
 
-                                printf("\nGNSS: location is %.5f %.5f.\n\n", latitude, longitude); 
-                                printf("I am here: https://maps.google.com/?q=%.5f,%.5f\n\n",
-                                       latitude, longitude); 
-                            }
-                        } else if (CHECK_TALKER("GGA") || CHECK_TALKER("GNS")) {
-                            double altitude = 0; 
-                            const char *timeString = NULL;
-
-                            // Altitude
-                            if (gnss.getNmeaItem(9, buffer, length, altitude)) {
-                                printf("\nGNSS: altitude is %.1f m.\n", altitude); 
-                            }
+    				// Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
+    				if ((buffer[0] == '$') || buffer[1] == 'G') {
+    				  if (CHECK_TALKER("GLL")) {
+    						char ch;
 
-                            // Time
-                            timeString = gnss.findNmeaItemPos(1, buffer, buffer + length);
-                            if (timeString != NULL) {
-                                ledBlue = 0;
-                                ledRed = 1;
-                                ledGreen = 1;
+    						if (gnss.getNmeaAngle(1, buffer, length, lat) &&
+    							gnss.getNmeaAngle(3, buffer, length, lon) &&
+    							gnss.getNmeaItem(6, buffer, length, ch) && (ch == 'A')) {
+    						}
+    					}
+    				}
+    				buffer[length] = '\0';
 
-                                printf("\nGNSS: time is %.6s.\n\n", timeString);
-                            }
-                        } else if (CHECK_TALKER("VTG")) {
-                            double speed = 0; 
+    				printf(buffer);
+    			}
+    			else if ((PROTOCOL(gnssReturnCode) == GnssParser::UBX) && (length > 6)) {
+    				eUBX_MESSAGE ubx_message_type = gnss.get_ubx_message(buffer);
 
-                            // Speed
-                            if (gnss.getNmeaItem(7, buffer, length, speed)) {
-                                printf("\nGNSS: speed is %.1f km/h.\n\n", speed);
-                            }
-                        }
-                    }
-                }
-            }
-        }
+    				uint16_t payload_length = buffer[4] | (buffer[5] << 8);
+
+    				//print_hex_buffer(buffer, payload_length + UBX_FRAME_SIZE);
+    			}
+    		}
+         }
     } else {
         printf("Unable to initialise GNSS.\n");
     }
@@ -114,4 +125,4 @@
     MBED_ASSERT(false);
 }
 
-// End Of File
\ No newline at end of file
+// End Of File
diff -r 746ae478fdf7 -r c8b7490c3fb0 mbed-os.lib
--- a/mbed-os.lib	Mon Jul 31 10:48:08 2017 +0100
+++ b/mbed-os.lib	Fri Jul 20 14:38:50 2018 +0500
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#78a1eddf61efa705ef1e99fc597dcaa5e737fb4c
+https://github.com/ARMmbed/mbed-os/