// ----------------------------------------------------------------------------------------
//
//  common/gps/nmea.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file implements a state machine to parse selected NMEA sentences.
//
//  Copyright (C) 2008 Bob Cook
//
//      This program is free software; you can redistribute it and/or modify it
//      under the terms of the GNU General Public License as published by the
//      Free Software Foundation; either version 2 of the License, or (at your
//      option) any later version.
//    
//      This program is distributed in the hope that it will be useful, but 
//      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
//      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//      for more details.
//    
//      You should have received a copy of the GNU General Public License along
//      with this program; if not, write to the Free Software Foundation, Inc., 
//      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//
//  Note: this package requires 42 bytes of RAM for state information.
//
// ----------------------------------------------------------------------------------------


#if !defined( BCDRL_COMMON_GPS_NMEA_H )
#define BCDRL_COMMON_GPS_NMEA_H


#include <stdint.h>

#include "packages/common/util/fixedpoint.h"


// ----------------------------------------------------------------------------------------
//  nmea_parse
//
//      Accept another byte for the NMEA parsing state machine.
//
//      Returns true when the sentence is correctly decoded.
//

bool nmea_parse( uint8_t byte );


// ----------------------------------------------------------------------------------------
//  nmea_error_count
//
//      Returns the accumulated parse error count.
//

uint8_t nmea_error_count();

    
// ----------------------------------------------------------------------------------------
//  nmea_timestamp
//
//      Return the packed version of the UTC timestamp field from a GPGGA sentence. The
//      caller must supply a ptr to a 6-byte buffer for the data.
//
//      This value will only be meaningful if nmea_parse() returns true.
//

void nmea_timestamp( uint8_t* timestamp );


// ----------------------------------------------------------------------------------------
//  nmea_latitude
//
//      Retrieve the degrees and minutes of the latitude field from a GPGGA sentence.
///     The degrees will be positive for northern locations, negative for southern.
//
//      This value will only be meaningful if nmea_parse() returns true.
//

void nmea_latitude( int16_t* degrees, fixed16dot16* minutes );


// ----------------------------------------------------------------------------------------
//  nmea_longitude
//
//      Retrieve the degrees and minutes of the longitude field from a GPGGA sentence.
//      The degrees will be positive for eastern locations, negative for western.
//
//      This value will only be meaningful if nmea_parse() returns true.
//

void nmea_longitude( int16_t* degrees, fixed16dot16* minutes );


// ----------------------------------------------------------------------------------------
//  nmea_position_fix
//
//      Test whether the GPGGA sentence was derived from a valid position fix. If the
//      supplied ptr is not null the number of satellites used is provided.
//
//      This value will only be meaningful if nmea_parse() returns true.
//

bool nmea_position_fix( uint8_t* satellite_count = 0 );

    
#endif  // #if defined( BCDRL_COMMON_GPS_NMEA_H )
// ----------------------------------------------------------------------------------------
//  end of nmea.h
// ----------------------------------------------------------------------------------------

