1 /*!
2  * \file      gps.h
3  *
4  * \brief     GPS driver implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __GPS_H__
24 #define __GPS_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include "utilities.h"
34 
35 /* Structure to handle the GPS parsed data in ASCII */
36 typedef struct
37 {
38     char NmeaDataType[6];
39     char NmeaUtcTime[11];
40     char NmeaDataStatus[2];
41     char NmeaLatitude[10];
42     char NmeaLatitudePole[2];
43     char NmeaLongitude[11];
44     char NmeaLongitudePole[2];
45     char NmeaFixQuality[2];
46     char NmeaSatelliteTracked[3];
47     char NmeaHorizontalDilution[6];
48     char NmeaAltitude[8];
49     char NmeaAltitudeUnit[2];
50     char NmeaHeightGeoid[8];
51     char NmeaHeightGeoidUnit[2];
52     char NmeaSpeed[8];
53     char NmeaDetectionAngle[8];
54     char NmeaDate[8];
55 }NmeaGpsData_t;
56 
57 /*!
58  * \brief Initializes the handling of the GPS receiver
59  */
60 void GpsInit( void );
61 
62 /*!
63  * \brief Switch ON the GPS
64  */
65 void GpsStart( void );
66 
67 /*!
68  * \brief Switch OFF the GPS
69  */
70 void GpsStop( void );
71 
72 /*!
73  * Updates the GPS status
74  */
75 void GpsProcess( void );
76 
77 /*!
78  * \brief PPS signal handling function
79  */
80 void GpsPpsHandler( bool *parseData );
81 
82 /*!
83  * \brief PPS signal handling function
84  *
85  * \retval ppsDetected State of PPS signal.
86  */
87 bool GpsGetPpsDetectedState( void );
88 
89 /*!
90  * \brief Indicates if GPS has fix
91  *
92  * \retval hasFix
93  */
94 bool GpsHasFix( void );
95 
96 /*!
97  * \brief Converts the latest Position (latitude and longitude) into a binary
98  *        number
99  */
100 void GpsConvertPositionIntoBinary( void );
101 
102 /*!
103  * \brief Converts the latest Position (latitude and Longitude) from ASCII into
104  *        DMS numerical format
105  */
106 void GpsConvertPositionFromStringToNumerical( void );
107 
108 /*!
109  * \brief Gets the latest Position (latitude and Longitude) as two double values
110  *        if available
111  *
112  * \param [OUT] lati Latitude value
113  * \param [OUT] longi Longitude value
114  *
115  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
116  */
117 LmnStatus_t GpsGetLatestGpsPositionDouble ( double *lati, double *longi );
118 
119 /*!
120  * \brief Gets the latest Position (latitude and Longitude) as two binary values
121  *        if available
122  *
123  * \param [OUT] latiBin Latitude value
124  * \param [OUT] longiBin Longitude value
125  *
126  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
127  */
128 LmnStatus_t GpsGetLatestGpsPositionBinary ( int32_t *latiBin, int32_t *longiBin );
129 
130 /*!
131  * \brief Parses the NMEA sentence.
132  *
133  * \remark Only parses GPGGA and GPRMC sentences
134  *
135  * \param [IN] rxBuffer Data buffer to be parsed
136  * \param [IN] rxBufferSize Size of data buffer
137  *
138  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
139  */
140 LmnStatus_t GpsParseGpsData( int8_t *rxBuffer, int32_t rxBufferSize );
141 
142 /*!
143  * \brief Returns the latest altitude from the parsed NMEA sentence
144  *
145  * \retval altitude
146  */
147 int16_t GpsGetLatestGpsAltitude( void );
148 
149 /*!
150  * \brief Format GPS data into numeric and binary formats
151  */
152 void GpsFormatGpsData( void );
153 
154 /*!
155  * \brief Resets the GPS position variables
156  */
157 void GpsResetPosition( void );
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif // __GPS_H__
164