00001 /* 00002 Copyright (c) 2010 Les Newell. All rights reserved 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 /* 00019 To configure use the following: 00020 #define GPS_PORT Serial2 00021 #define GPS_BAUD 38500 00022 //Update rate in samples/second 00023 #define GPS_RATE 10 00024 //Any initialization strings that need to be sent. Note you need to supply your own 00025 //line end characters (if needed) 00026 static const char gpsInit[]="$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n"; 00027 #include "gpsNMEA.h" 00028 00029 */ 00030 00032 00038 #include "gps.h" 00039 #include "tinygps.h" 00040 00041 //define the module. 00042 class GPSNMEA : public GPS 00043 { 00044 DECLARE_MODULE(GPSNMEA,GPS) 00045 00046 00047 //Only use this to expose sockets and parameters. Do most of your 00048 //initialisastion in Init() 00049 GPSNMEA() 00050 { 00051 } 00052 00053 //A parameter has changed. This happens at bootup if the EEPROM 00054 //contains valid data and at run-time if the user changes a 00055 //parameter over the serial link 00056 virtual void ParamChanged(Socket * param) 00057 { 00058 } 00059 00060 //Initialise the module 00061 //set up hardware etc 00062 virtual void Init() 00063 { 00064 GPS_PORT.begin(GPS_BAUD); 00065 //we need to poll at this rate to guarantee the rx buffer never overruns 00066 int loopRate = 500/((GPS_BAUD / 9)/ 128); 00067 SetInterval(loopRate); 00068 m_timeout = (4000 / GPS_RATE) / loopRate; //Miss up to 4 samples before we signal an error 00069 m_countDown = 1; 00070 SetPriority (10); 00071 } 00072 00073 //Here is where you do your work. It is called at the rate defined by SetInterval 00074 virtual void Loop(const unsigned long& interval) 00075 { 00076 if(m_countDown) 00077 { 00078 m_countDown --; 00079 if(!m_countDown) 00080 { 00081 m_ok = false; 00082 } 00083 } 00084 return; 00085 while(GPS_PORT.available()) 00086 { 00087 GPS_PORT.read(); 00088 if(false && m_gps.encode(GPS_PORT.read())) 00089 { 00090 m_gps.f_get_position(m_latitude.GetPointer(),m_longitude.GetPointer()); 00091 m_altitude = m_gps.f_altitude(); 00092 m_heading = m_gps.f_course(); 00093 m_speed = m_gps.f_speed_mps(); 00094 m_ok = true; 00095 } 00096 } 00097 } 00098 00099 private: 00100 TinyGPS m_gps; 00101 int m_countDown; 00102 int m_timeout; 00103 00104 }; 00105 00106 GPSNMEA g_GPSNMEA; 00107 00108
1.7.0