A GPS serial interrupt service routine that has an on the fly nmea parser. Works with a STM32F411RE and a Adafruit GPS logger.

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of GPS by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GPSISR.cpp Source File

GPSISR.cpp

00001 /* mbed EM-406 GPS Module Library
00002  * Copyright (c) 2008-2010, sford
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022  
00023 #include <string> 
00024 #include "nmea.h"
00025 #include "GPSISR.h"
00026 
00027 NMEA nmea; //parse GPS Sentence.
00028 
00029 GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
00030     _gps.baud(Baud);
00031     _gps.attach(this,&GPS::Rx_interrupt, Serial::RxIrq);
00032     
00033     printf("Interrupt Attached");
00034 }
00035 
00036 void GPS::getline() {
00037     while(_gps.getc() != '$');    // wait for the start of a line
00038     for(int i=0; i<256; i++) {
00039         msg[i] = _gps.getc();
00040         if(msg[i] == '\r') {
00041             msg[i] = 0;
00042             return;
00043         }
00044     }
00045     error("Overflowed message limit");
00046     return;
00047 }
00048 
00049 // Interupt Routine to read in data from serial port
00050 void GPS::Rx_interrupt(void) {
00051     interrupt = 1;
00052     rx_in = _gps.getc();
00053     nmea.fusedata(rx_in);
00054     interrupt = 0;
00055     return;
00056 }
00057  bool GPS::dataready(void){
00058  return  nmea.isdataready();
00059      
00060 }     
00061 
00062 void GPS::read(void) {
00063     
00064     buffer.hours = nmea.getHour();
00065     buffer.minutes = nmea.getMinute();
00066     buffer.seconds = nmea.getSecond();
00067     buffer.day = nmea.getDay();
00068     buffer.month = nmea.getMonth();
00069     buffer.year = nmea.getYear();
00070     buffer.latitude = 0.0;
00071     buffer.longitude = 0.0;
00072 
00073     if (nmea.isdataready()) {
00074         buffer.latitude = nmea.getLatitude();
00075         buffer.longitude = nmea.getLongitude();
00076         buffer.speed = nmea.getSpeed();
00077         buffer.altitude = nmea.getAltitude();
00078         buffer.bearing = nmea.getBearing();
00079         buffer.satellites = nmea.getSatellites();
00080     }
00081 }