00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ARGPS_H
00028 #define ARGPS_H
00029
00030 #include "ariaTypedefs.h"
00031 #include "ArFunctor.h"
00032 #include "ariaUtil.h"
00033 #include <string>
00034 #include <vector>
00035
00036 class ArDeviceConnection;
00037
00078 class ArGPS {
00079
00080 public:
00081 AREXPORT ArGPS();
00082 AREXPORT virtual ~ArGPS();
00083
00085 AREXPORT void setDeviceConnection(ArDeviceConnection* deviceConn) { myDevice = deviceConn; }
00086
00088 AREXPORT ArDeviceConnection* getDeviceConnection(ArDeviceConnection* deviceConn) const { return myDevice; }
00089
00090
00100 AREXPORT virtual bool connect();
00101
00110 AREXPORT bool blockingConnect(unsigned long connectTimeout = 8000);
00111
00112
00119 typedef enum {
00120 ReadFinished = 0,
00121 ReadError = 1,
00122 ReadData = 2,
00123 ReadUpdated = 4
00124 } ReadFlags;
00125
00133 AREXPORT virtual int read();
00134
00136 AREXPORT void setIgnoreChecksum(bool ignore) { ignoreChecksum = ignore; }
00137
00139 AREXPORT void logData() const;
00140
00142 AREXPORT void printData() const;
00143
00146
00147
00148 typedef enum {
00149 NoFix, BadFix, GPSFix, DGPSFix, PPSFix,
00150 RTKinFix, FloatRTKinFix, DeadReckFix,
00151 ManualFix, SimulatedFix, UnknownFixType
00152 } FixType;
00153
00154 AREXPORT FixType getFixType() const { return myFixType; }
00155 AREXPORT const char* getFixTypeName() const;
00156
00157 AREXPORT bool havePosition() const { return myHavePosition; }
00158 AREXPORT bool haveLatitude() const { return myHavePosition; }
00159 AREXPORT bool haveLongitude() const { return myHavePosition; }
00160
00162 AREXPORT double getLatitude() const { return myLatitude; }
00163
00165 AREXPORT double getLongitude() const { return myLongitude; }
00166
00168 AREXPORT ArTime getTimeReceivedPosition() const { return myTimeGotPosition; }
00169
00170 AREXPORT bool haveSpeed() const { return myHaveSpeed; }
00171
00173 AREXPORT double getSpeed() const { return mySpeed; }
00174
00175 AREXPORT unsigned short getGPSPositionTimestamp() const { return myGPSPositionTimestamp; }
00176
00177 AREXPORT unsigned short getNumSatellitesTracked() const { return myNumSatellitesTracked; }
00178 AREXPORT bool haveDGPSStation() const { return myHaveDGPSStation; }
00179 AREXPORT unsigned short getDGPSStationID() const { return myDGPSStationID; }
00180
00182 AREXPORT bool havePositionError() const { return myHavePositionError; }
00184 AREXPORT double getPositionError() const { return myPositionError; }
00186 AREXPORT bool haveVerticalPositionError() const { return myHaveVerticalPositionError; }
00188 AREXPORT double getVerticalPositionError() const { return myVerticalPositionError; }
00189
00191 AREXPORT bool haveCompassHeading() const { return myHaveCompassHeading; }
00193 AREXPORT double getCompassHeading() const { return myCompassHeading; }
00194
00195 AREXPORT bool haveAltitude() const { return myHaveAltitude; }
00196 AREXPORT double getAltitude() const { return myAltitude; }
00197
00198 AREXPORT bool haveHDOP() const { return myHaveHDOP; }
00199 AREXPORT double getHDOP() const { return myHDOP; }
00200 AREXPORT bool haveVDOP() const { return myHaveVDOP; }
00201 AREXPORT double getVDOP() const { return myVDOP; }
00202 AREXPORT bool havePDOP() const { return myHavePDOP; }
00203 AREXPORT double getPDOP() const { return myPDOP; }
00205
00206 protected:
00207
00208 double myLatitude;
00209 double myLongitude;
00210 bool myHavePosition;
00211 ArTime myTimeGotPosition;
00212 double mySpeed;
00213 bool myHaveSpeed;
00214 unsigned short myGPSPositionTimestamp;
00215 FixType myFixType;
00216 unsigned short myNumSatellitesTracked;
00217 double myAltitude;
00218 bool myHaveAltitude;
00219 unsigned short myDGPSStationID;
00220 bool myHaveDGPSStation;
00221 double myPositionError;
00222 bool myHavePositionError;
00223 double myVerticalPositionError;
00224 bool myHaveVerticalPositionError;
00225 double myCompassHeading;
00226 bool myHaveCompassHeading;
00227 bool myHaveHDOP;
00228 double myHDOP;
00229 bool myHaveVDOP;
00230 double myVDOP;
00231 bool myHavePDOP;
00232 double myPDOP;
00233
00234
00235
00236
00237 bool readFloatFromString(std::string& str, double* target, double(*convf)(double) = NULL);
00238
00239
00240
00241
00242 bool readUShortFromString(std::string& str, unsigned short* target, unsigned short (*convf)(unsigned short) = NULL);
00243
00244
00245
00246 bool readFloatFromStringVec(std::vector<std::string>* vec, size_t i, double* target, double (*convf)(double) = NULL);
00247
00248
00249 bool readUShortFromStringVec(std::vector<std::string>* vec, size_t i, unsigned short* target, unsigned short (*convf)(unsigned short) = NULL);
00250
00251
00252 static double gpsDegminToDegrees(double degmin);
00253
00254
00255 static double knotsToMPS(double knots);
00256
00257
00258 static double mpsToMph(double mps) { return mps * 2.23693629; }
00259
00260
00261 static double metersToFeet(double m) { return m * 3.2808399; }
00262
00263
00264 static double feetToMeters(double f) { return f / 3.2808399; }
00265
00266
00267
00268 ArDeviceConnection *myDevice;
00269 bool myCreatedOwnDeviceCon;
00270 ArRetFunctorC<bool, ArGPS> myParseArgsCallback;
00271 ArArgumentParser* myArgParser;
00272
00273
00274 typedef std::vector<std::string> MessageVector;
00275
00276
00277
00278
00279 typedef ArFunctor1C<ArGPS, MessageVector*> Handler;
00280
00281
00282 typedef std::map<std::string, Handler*> HandlerMap;
00283
00284
00285 HandlerMap myHandlers;
00286
00287 void handleGPRMC(MessageVector* message);
00288 Handler myGPRMCHandler;
00289
00290 void handleGPGGA(MessageVector* message);
00291 Handler myGPGGAHandler;
00292
00293 void handlePGRME(MessageVector* message);
00294 Handler myPGRMEHandler;
00295
00296 void handlePGRMZ(MessageVector* message);
00297 Handler myPGRMZHandler;
00298
00299 void handleHCHDG(MessageVector* message);
00300 Handler myHCHDGHandler;
00301
00302 void handleGPGSA(MessageVector* message);
00303 Handler myGPGSAHandler;
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 const unsigned short MaxNumFields;
00314 const unsigned short MaxFieldSize;
00315 bool ignoreChecksum;
00316
00317 MessageVector currentMessage;
00318 std::string currentField;
00319 char checksumBuf[3];
00320 short checksumBufOffset;
00321 bool inChecksum;
00322 bool inMessage;
00323 char currentChecksum;
00324 bool gotCR;
00325
00326
00327 void beginMessage();
00328 void endMessage();
00329 void nextField();
00330 void beginChecksum();
00331
00332 };
00333
00334 #endif // ifdef ARGPS_H