GPS Library for Nucleo

Dependencies:   Adafruit_GPS

Dependents:   Full-Project

Fork of MBed_Adafruit-GPS-Library by Myron Lee

Committer:
ptcrews
Date:
Mon Dec 07 00:05:43 2015 +0000
Revision:
5:1249c2cfdede
Parent:
3:f2477af055c3
Added comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptcrews 3:f2477af055c3 1 #include "GPS_Wrapper.h"
ptcrews 3:f2477af055c3 2
ptcrews 5:1249c2cfdede 3 /* Function: setup
ptcrews 5:1249c2cfdede 4 * ---------------
ptcrews 5:1249c2cfdede 5 * Initially sets up the GPS. Draws from the Adafruit GPS library.
ptcrews 5:1249c2cfdede 6 */
ptcrews 3:f2477af055c3 7 void GPS_Sensor::setup() {
ptcrews 3:f2477af055c3 8 wait(2);
ptcrews 3:f2477af055c3 9 turnOn();
ptcrews 3:f2477af055c3 10 myGPS.begin(GPS_BAUD);
ptcrews 3:f2477af055c3 11 myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
ptcrews 3:f2477af055c3 12 myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
ptcrews 3:f2477af055c3 13 myGPS.sendCommand(PGCMD_ANTENNA);
ptcrews 3:f2477af055c3 14 wait(1);
ptcrews 3:f2477af055c3 15 refresh_Timer.start(); //starts the clock on the timer
ptcrews 3:f2477af055c3 16 printf("setupGPS seems to be fine\n");
ptcrews 3:f2477af055c3 17 wait(2);
ptcrews 3:f2477af055c3 18 }
ptcrews 3:f2477af055c3 19
ptcrews 5:1249c2cfdede 20 /* Function: read
ptcrews 5:1249c2cfdede 21 * --------------
ptcrews 5:1249c2cfdede 22 * Records a single reading to the reading struct passed by reference.
ptcrews 5:1249c2cfdede 23 */
ptcrews 3:f2477af055c3 24 void GPS_Sensor::read(struct reading& lastReadingBuffer) {
ptcrews 5:1249c2cfdede 25 // Continually checks for a GPS fix for SEC_WAIT_FOR_FIX (default = 60)
ptcrews 3:f2477af055c3 26 for(int i = 0; i < SEC_WAIT_FOR_FIX; i++){
ptcrews 3:f2477af055c3 27 wait(1);
ptcrews 3:f2477af055c3 28 if(myGPS.fix) break;
ptcrews 3:f2477af055c3 29 }
ptcrews 3:f2477af055c3 30 printf("\n");
ptcrews 3:f2477af055c3 31 for (int i = 0; i < N_GPS_QUERIES; i++) {
ptcrews 5:1249c2cfdede 32 char c = myGPS.read(); // Queries the GPS. When read via Adafruit_GPS::read(), the class returns single character stored here
ptcrews 3:f2477af055c3 33
ptcrews 5:1249c2cfdede 34 if (c) { printf("%c", c); } // This line will echo the GPS data if not paused
ptcrews 3:f2477af055c3 35
ptcrews 5:1249c2cfdede 36 //Check if we recieved a new message from GPS, if so, attempt to parse it,
ptcrews 3:f2477af055c3 37 if ( myGPS.newNMEAreceived() ) {
ptcrews 3:f2477af055c3 38 if ( !myGPS.parse(myGPS.lastNMEA()) ) {
ptcrews 3:f2477af055c3 39 continue;
ptcrews 3:f2477af055c3 40 }
ptcrews 3:f2477af055c3 41 }
ptcrews 5:1249c2cfdede 42 // Check if enough time has passed to warrant printing GPS info to screen
ptcrews 5:1249c2cfdede 43 // Note if refresh_Time is too low or pcSerial.baud is too low, GPS data may be lost during printing
ptcrews 3:f2477af055c3 44 if (refresh_Timer.read_ms() >= REFRESH_TIME ) {
ptcrews 3:f2477af055c3 45 refresh_Timer.reset();
ptcrews 3:f2477af055c3 46 printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
ptcrews 3:f2477af055c3 47 printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
ptcrews 3:f2477af055c3 48 printf("Fix: %d\n", (int) myGPS.fix);
ptcrews 3:f2477af055c3 49 printf("Quality: %d\n", (int) myGPS.fixquality);
ptcrews 3:f2477af055c3 50
ptcrews 3:f2477af055c3 51 lastReadingBuffer.hour = myGPS.hour;
ptcrews 3:f2477af055c3 52 lastReadingBuffer.minutes = myGPS.minute;
ptcrews 3:f2477af055c3 53 lastReadingBuffer.day = myGPS.day;
ptcrews 3:f2477af055c3 54 lastReadingBuffer.month = myGPS.month;
ptcrews 3:f2477af055c3 55 lastReadingBuffer.year = myGPS.year;
ptcrews 3:f2477af055c3 56 lastReadingBuffer.latitude = 0.0;
ptcrews 3:f2477af055c3 57 lastReadingBuffer.longitude = 0.0;
ptcrews 3:f2477af055c3 58 if (myGPS.fix) {
ptcrews 3:f2477af055c3 59 lastReadingBuffer.latitude = myGPS.latitude;
ptcrews 3:f2477af055c3 60 if(myGPS.lat == 'S')
ptcrews 3:f2477af055c3 61 lastReadingBuffer.latitude *= -1;
ptcrews 3:f2477af055c3 62 lastReadingBuffer.longitude = myGPS.longitude;
ptcrews 3:f2477af055c3 63 if(myGPS.lon == 'W')
ptcrews 3:f2477af055c3 64 lastReadingBuffer.longitude *= -1;
ptcrews 3:f2477af055c3 65 printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
ptcrews 3:f2477af055c3 66 printf("Speed: %5.2f knots\n", myGPS.speed);
ptcrews 3:f2477af055c3 67 printf("Angle: %5.2f\n", myGPS.angle);
ptcrews 3:f2477af055c3 68 printf("Altitude: %5.2f\n", myGPS.altitude);
ptcrews 3:f2477af055c3 69 printf("Satellites: %d\n", myGPS.satellites);
ptcrews 3:f2477af055c3 70 }
ptcrews 3:f2477af055c3 71 }
ptcrews 3:f2477af055c3 72 }
ptcrews 3:f2477af055c3 73 printf("\n");
ptcrews 3:f2477af055c3 74 }