dascubed/CubeBuffer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of dascubed.
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: 2011-03-23
00021 **  Authors:
00022 **    Marc Wathelet (LGIT, Grenoble, France)
00023 **
00024 ***************************************************************************/
00025 
00026 #ifndef CUBEBUFFER_H
00027 #define CUBEBUFFER_H
00028 
00029 #include <time.h>
00030 
00031 #include <GpCoreTools.h>
00032 #include <WaranCore.h>
00033 
00034 #define NUMBER_OF_CHANNELS 3
00035 
00036 class CubeTcpServer;
00037 class CubeDevice;
00038 
00039 class CubeBuffer: public DynamicBuffer
00040 {
00041 public:
00042   CubeBuffer(int fd, CubeTcpServer * server, CubeDevice * device);
00043   ~CubeBuffer();
00044 
00045   void sequenceNotAvailable(unsigned int sequenceNumber);
00046 
00047   bool isRunning() const {return _running;}
00048   unsigned long int runningTime() const;
00049 
00050   unsigned int frequency() const {return _frequency;}
00051   unsigned int hardwareGain() const {return _hardGain;}
00052   unsigned int softwareGain() const {return _softGain;}
00053   unsigned int timeMode() const {return _timeMode;}
00054 protected:
00055   virtual int bytesAvailable(char * buffer, int bytesCount);
00056 private:
00057   void read(unsigned char msgClass, unsigned char msgId,
00058             unsigned short length, char * payload);
00059   void readCorrupted(unsigned char msgClass, unsigned char msgId,
00060                      unsigned short length, char * payload);
00061 
00062   void getFrequency(char * payload, unsigned short length);
00063   void getGains(char * payload, unsigned short length);
00064   void getTimeMode(char * payload, unsigned short length);
00065 
00066   void getOk(char * payload, unsigned short length);
00067   void getError(char * payload, unsigned short length);
00068   void getHardVersion(char * payload, unsigned short length);
00069   void getSoftVersion(char * payload, unsigned short length);
00070   void getBattery(char * payload, unsigned short length);
00071   void getTemperature(char * payload, unsigned short length);
00072 
00073   void getData(char * payload, unsigned short length);
00074   void getCorruptedData(char * payload, unsigned short length);
00075 
00076   void displayParameters();
00077   bool checkSampleIndexOverFlow(unsigned int sampleIndex);
00078   void addMissingSequence(unsigned int sequenceNumber);
00079   void requestMissingSequence(unsigned int sequenceNumber);
00080   bool receivedMissingSequence(unsigned int sequenceNumber);
00081 
00082   CubeTcpServer * _server;
00083   CubeDevice * _device;
00084 
00085   unsigned int _frequency, _period;
00086   bool _running;
00087   unsigned int _timeMode;
00088   const char ** _seedlinkChannelNames;
00089   static const char * _allChannelNames[33];
00090   unsigned int _softGain, _hardGain, _adcMode;
00091   unsigned int _ppsBegin, _maxPpsBegin;
00092   float _deviceNoiseLevel;
00093   bool _sensorConnected;
00094 
00095   unsigned int _nextSequence;
00096   std::list<unsigned int> _missingSequences;
00097 
00098   time_t _startTime;
00099   unsigned int _sampleIndex;
00100   unsigned int _missingSamples;
00101   unsigned int _sampleIndexOverflowCount;
00102   int _restartCount;
00103 
00104   MovingStatistics _statistics[NUMBER_OF_CHANNELS];
00105 };
00106 
00107 #endif // CUBEBUFFER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines