Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / ezdop / src / host / hunter / src / gps.h
1 /*
2  Copyright 2006 Johnathan Corgan.
3  
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License version 2
6  as published by the Free Software Foundation.
7  
8  This software is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with GNU Radio; see the file COPYING.  If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street,
16  Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __GPS_H__
20 #define __GPS_H__
21
22 // Autoconf generated configure options
23 #if HAVE_CONFIG_H
24     #include "config.h"
25 #endif
26
27 // Application level includes
28 #include "spherical.h"
29
30 // wxWidgets includes
31 #include <wx/event.h>
32
33 // System level includes
34 #include <math.h>  // For some reason, <cmath> doesn't include modf needed in gps.cpp
35
36 class GPRMC;
37
38 class GPSUpdate : public wxNotifyEvent
39 {
40 public:
41     GPSUpdate(const wxEventType &event, GPRMC *gprmc);
42     virtual wxEvent *Clone() const { return new GPSUpdate(*this); }
43     GPRMC *m_gprmc;
44 };
45
46 extern const wxEventType wxEVT_GPS_UPDATE;
47
48 typedef void(wxEvtHandler::*GPSUpdateFunction)(GPSUpdate&);
49
50 #define EVT_GPS_UPDATE(fn) \
51         DECLARE_EVENT_TABLE_ENTRY( \
52             wxEVT_GPS_UPDATE, -1, -1, \
53             (wxObjectEventFunction)(wxEventFunction)(GPSUpdateFunction)&fn, \
54             (wxObject *)NULL \
55         ),
56
57 class NMEA
58 {
59 public:
60     static bool Checksum(char *sentence);
61     static char *Field(char *sentence, int num);
62     static double Coord(char *sentence, int num);
63 };
64
65 class GPRMC : public NMEA
66 {
67 public:
68     GPRMC(char *sentence);
69     void AsString(char *buf);
70         
71     time_t m_stamp;
72     bool   m_valid;
73     Spherical m_fix;
74     float m_speed;
75     float m_heading;
76     float m_magnetic;
77     unsigned char m_mode;
78 };
79
80 class GPS;
81 class SerialPort;
82
83 class GPSBackground : public wxThread
84 {
85 public:
86     GPSBackground(GPS *gps);
87     virtual ExitCode Entry();
88     bool IsRunning() { return m_running; }
89
90 private:
91     void PerLoop();
92
93     bool m_running;
94     GPS *m_gps;
95     SerialPort *m_port;
96 };
97
98 class wxString;
99
100 class GPS
101 {
102 public:
103     GPS(wxEvtHandler *dest);
104     ~GPS();
105     
106     bool Start(wxString &port);
107     bool Stop();
108     SerialPort *GetPort() { return m_port; }
109     void RxData(char *buffer);
110     
111 private:
112     void RxGPRMC(char *buffer);
113
114     GPSBackground *m_thread;
115     wxEvtHandler *m_dest;
116     SerialPort *m_port;
117 };
118
119 #endif // __GPS_H__