Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2136 - 1
/*
2
    File:       nmea.h
3
    Version:    0.1.0
4
    Date:       Feb. 23, 2013
5
        License:        GPL v2
6
 
7
        NMEA GPS content parser
8
 
9
    ****************************************************************************
10
    Copyright (C) 2013 Radu Motisan  <radu.motisan@gmail.com>
11
 
12
        http://www.pocketmagic.net
13
 
14
    This program is free software; you can redistribute it and/or modify
15
    it under the terms of the GNU General Public License as published by
16
    the Free Software Foundation; either version 2 of the License, or
17
    (at your option) any later version.
18
 
19
    This program is distributed in the hope that it will be useful,
20
    but WITHOUT ANY WARRANTY; without even the implied warranty of
21
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
    GNU General Public License for more details.
23
 
24
    You should have received a copy of the GNU General Public License
25
    along with this program; if not, write to the Free Software
26
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
    ****************************************************************************
28
 */
29
 
30
#include <string.h>
31
//#include <util/delay.h>
32
#include <avr/interrupt.h>
33
#include <avr/pgmspace.h>
34
#include <stdbool.h>
35
#include <stdlib.h>
36
#include <math.h>
37
#include <stdio.h>
38
 
39
//---------------------------------
40
#define NMEA_TIMEOUT    500             // Timeout 5 sek.
41
//---------------------------------
42
typedef struct
43
{
44
    uint32_t Counter;                   // Zaehler empfangene GPGGA Pakete
45
    int32_t  Latitude;                  // in 1E-7 deg
46
    int32_t  Longitude;                 // in 1E-7 deg
47
    int16_t  Altitude;                  // Hoehe in Meter
48
    uint8_t  SatFix;                    // GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix, 6=Estimated)
49
    uint8_t  SatsInUse;                 // Number of satelites currently in use
50
    int16_t  HDOP;                      // Horizontal Dilution of Precision, 1.1 -xx.x, niederiger = besser
51
    char     Time[9];                   // "hh:mm:ss"
52
} NMEA_GPGGA_t;
53
 
54
//---------------------------------
55
// export vars
56
//---------------------------------
57
extern NMEA_GPGGA_t     NMEA;
58
extern uint8_t receiveNMEA;
59
extern volatile uint32_t res_nNMEAcounter;
60
 
61
// /*class NMEA {
62
//
63
//      private:
64
//              bool                    m_bFlagRead,                                    // flag used by the parser, when a valid sentence has begun
65
//                                              m_bFlagDataReady;                               // valid GPS fix and data available, user can call reader functions
66
//              char                    tmp_words[20][15],                              //      hold parsed words for one given NMEA sentence
67
//                                              tmp_szChecksum[15];                             //      hold the received checksum for one given NMEA sentence
68
//
69
//              // will be set to true for characters between $ and * only
70
//              bool                    m_bFlagComputedCks ;                    // used to compute checksum and indicate valid checksum interval (between $ and * in a given sentence)
71
//              int                             m_nChecksum ;                                   // numeric checksum, computed for a given sentence
72
//              bool                    m_bFlagReceivedCks ;                    // after getting  * we start cuttings the received checksum
73
//              int                             index_received_checksum ;               // used to parse received checksum
74
//
75
//              // word cutting variables
76
//              int                             m_nWordIdx ,                                    // the current word in a sentence
77
//                                              m_nPrevIdx,                                             // last character index where we did a cut
78
//                                              m_nNowIdx ;                                             // current character index
79
//
80
//              // globals to store parser results
81
//              float                   res_fLongitude;                                 // GPRMC and GPGGA
82
//              float                   res_fLatitude;                                  // GPRMC and GPGGA
83
//              unsigned char   res_nUTCHour, res_nUTCMin, res_nUTCSec,         // GPRMC and GPGGA
84
//                                              res_nUTCDay, res_nUTCMonth, res_nUTCYear;       // GPRMC
85
//              int                             res_nSatellitesUsed;                    // GPGGA
86
//              float                   res_fAltitude;                                  // GPGGA
87
//              float                   res_fSpeed;                                             // GPRMC
88
//              float                   res_fBearing;                                   // GPRMC
89
//
90
//              // the parser, currently handling GPRMC and GPGGA, but easy to add any new sentences
91
//              void                    parsedata();
92
//              // aux functions
93
//              int                             digit2dec(char hexdigit);
94
//              float                   string2float(char* s);
95
//              int                             mstrcmp(const char *s1, const char *s2);
96
//
97
//      public:
98
//              // constructor, initing a few variables
99
 
100
/*
101
 * The serial data is assembled on the fly, without using any redundant buffers.
102
 * When a sentence is complete (one that starts with $, ending in EOL), all processing is done on
103
 * this temporary buffer that we've built: checksum computation, extracting sentence "words" (the CSV values),
104
 * and so on.
105
 * When a new sentence is fully assembled using the fusedata function, the code calls parsedata.
106
 * This function in turn, splits the sentences and interprets the data. Here is part of the parser function,
107
 * handling both the $GPRMC NMEA sentence:
108
 */
109
 
110
uint8_t fusedata(char c);
111
void parsedata(void);
112
int32_t NMEA_floatStrToInt( const char *s, int32_t power1 );
113
int32_t NMEA_calcLatitude( const char *s, const char *NS);
114
int32_t NMEA_calcLongitude( const char *s, const char *WE);
115
void NMEA_getTime( const char *s);
116
 
117
                // READER functions: retrieving results, call isdataready() first
118
        bool NMEA_isdataready();
119
        int NMEA_getHour();
120
        int NMEA_getMinute();
121
        int NMEA_getSecond();
122
        int NMEA_getDay();
123
        int NMEA_getMonth();
124
        int NMEA_getYear();
125
        int32_t NMEA_getLatitude();
126
        int32_t NMEA_getLongitude();
127
        uint8_t NMEA_getSatellites();
128
        uint8_t NMEA_getGPSfix();
129
        int16_t NMEA_getHDOP();
130
        int16_t NMEA_getAltitude();
131
        float NMEA_getSpeed();
132
        int16_t NMEA_getBearing();
133
        uint32_t NMEA_getNMEAcounter();
134
        uint32_t NMEA_getCRCerror();
135
//      };