warangpsd/UbxDevice.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of warangpsd.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created : 2009-06-26
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef UBXDEVICE_H
00028 #define UBXDEVICE_H
00029 
00030 #include <GpCoreTools.h>
00031 #include <WaranCore.h>
00032 
00033 #include "NavigationTimer.h"
00034 
00035 #define MONITOR_DRIFT_MODE
00036 
00037 class GpsServer;
00038 class GpsBuffer;
00039 
00040 class UbxDevice : public PThread
00041 {
00042 public:
00043   enum Mode {Off=0, Track=1, Stack=2};
00044 
00045   UbxDevice(const std::string& stationName, const std::string& basePath,
00046             const std::string& devicePath, GpsServer * server);
00047   ~UbxDevice();
00048 
00049 #ifdef MONITOR_DRIFT_MODE
00050   void setMonitorDriftMode(bool m) {_monitorDriftMode=m;}
00051   bool monitorDriftMode() const {return _monitorDriftMode;}
00052 #endif
00053 
00054   void startBroadcast();
00055   void startRecording();
00056   void stopRecording();
00057   bool requestNavigation();
00058 
00059   void sendState(GpsBuffer * client);
00060   unsigned long int recordingTime();
00061   void sendRaw(GpsBuffer * client);
00062 
00063   enum TimeStatus {NoLock, GpsLock, PpsLock, LostPpsLock, LostGpsLock, RecoverLockAfterPpsLost, RecoverLockAfterGpsLost};
00064   void setTimeStatus(TimeStatus s);
00065   TimeStatus timeStatus();
00066 
00067   void resetGpsDrift();
00068   bool isResetGpsDrift();
00069 
00070   void resetPpsDrift();
00071   bool isResetPpsDrift();
00072 
00073   void setSatelliteCount(int c) {_satelliteCount=c;}
00074   void setGpsDriftCount(int c) {_gpsDriftCount=c;}
00075   void setPpsDriftCount(int c) {_ppsDriftCount=c;}
00076 
00077   FILE * lockFixStream() {pthread_mutex_lock(&_fixStreamMutex); return _fixStream;}
00078   void unlockFixStream() {pthread_mutex_unlock(&_fixStreamMutex);}
00079   FILE * lockRawStream() {pthread_mutex_lock(&_rawStreamMutex); return _rawStream;}
00080   void unlockRawStream() {pthread_mutex_unlock(&_rawStreamMutex);}
00081 private:
00082   const char * timeStamp(char * buffer32);
00083   bool openFixFile();
00084   void closeFixFile();
00085   bool openRawFile();
00086   void closeRawFile();
00087   virtual void run();
00088   void sendSeismic(const char * cmd);
00089 
00090   std::string _basePath;
00091   std::string _stationName;
00092   pthread_mutex_t _fixStreamMutex;
00093   pthread_mutex_t _rawStreamMutex;
00094   std::string _fixFileName;
00095   std::string _rawFileName;
00096   FILE * _rawStream;
00097   FILE * _fixStream;
00098   time_t _startRecordingTime;
00099   Serial * _serial;
00100   GpsServer * _server;
00101   NavigationTimer _navigationTimer;
00102   pthread_mutex_t _timeStatusMutex;
00103   TimeStatus _timeStatus:3;
00104   int _satelliteCount, _gpsDriftCount, _ppsDriftCount;
00105   bool _resetGpsDrift:1;
00106   bool _resetPpsDrift:1;
00107 #ifdef MONITOR_DRIFT_MODE
00108   bool _monitorDriftMode;
00109 #endif
00110 };
00111 
00112 #endif // UBXDEVICE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines