Slightly modified version of the SerialGPS library (https://os.mbed.com/teams/components/code/SerialGPS/) to support the BufferedSerial class

SerialGPS.h

Committer:
runesla
Date:
2021-03-02
Revision:
3:ebd79e3acf14
Parent:
2:e7f24389167b
Child:
4:2c76f1ec13a9

File content as of revision 3:ebd79e3acf14:

/* mbed GPS Module Library
 * Copyright (c) 2008-2010, sford
 * Copyright (c) 2013, B.Adryan
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef MBED_GPS_H
#define MBED_GPS_H

#include "mbed.h"
#include "BufferedSerial.h"

#define MAX_LINELENGTH 255

class SerialGPS 
{
    public:
        SerialGPS(PinName tx, PinName rx, int baud);

        SerialGPS(BufferedSerial* serial);
    
        /** 
        * Sample the incoming GPS data
        */
        void read();
    
        /**
        * Send PMTK command to GPS
        *
        * @param cmd the PMTK command to send to the GPS module
        */
        void send_command(const char* cmd);

        /**
        * GPS fix
        *
        * @return true if the GPS module has acquired fix
        */ 
        bool fix();

        /** 
        * The longitude (call sample() to set) 
        *
        * @return _lat the latitude component
        */
        float get_lon();

        /** 
        * The latitude (call sample() to set) 
        *
        * @return _lon the longitude component
        */
        float get_lat();
    
    private:
        float trunc(float v);
        void getline();
        void set_vals();
        char read_char();

        BufferedSerial* _gps_p;
        BufferedSerial& _gps;

        char _nmea[MAX_LINELENGTH];
        bool _fix;

        float _UTCtime, _lat, _lon;
        int _lock;
        char _status, _NS, _EW;
};

#endif