CARMA C++
TipperControlThread.h
Go to the documentation of this file.
1 
11 #ifndef CARMA_TIPPER_TIPPERCONTROL_H
12 #define CARMA_TIPPER_TIPPERCONTROL_H
13 
14 // UNIX system related
15 #include <termios.h>
16 
17 #include <string>
18 
19 // CARMA includes
20 #include "carma/util/Program.h"
21 #include "carma/util/Trace.h"
22 #include "carma/util/ExceptionUtils.h"
25 #include "carma/util/Logger.h"
26 #include "carma/util/Time.h"
27 #include "carma/util/ScopedPthreadMutexLock.h"
28 
29 #include "carma/tipper/TipData.h"
30 #include "carma/monitor/OpacityMonitorSubsystem.h"
31 
32 namespace carma
33 {
34  namespace tipper
35  {
36  class TipperControlThread
37  {
38 
39  public:
40  TipperControlThread( ::std::string device, ::std::string dataDir,
41  double autoWriterDelayInS, bool emulate );
42 
43  typedef enum
44  {
45  STEP,
46  TIP_STARTED,
47  PORT_ERROR,
48  DIRECT,
49  GO_ZENITH,
50  IDLE,
51  OPEN_PORT,
52  INTEGRATING
53  } TipperStatus;
54 
55  typedef enum
56  {
57  CLOCKWISE,
58  COUNTER_CLOCKWISE
59  } TipperDirection;
60 
61  struct TipperAngles
62  {
63  int steps;
64  float angle;
65  };
66 
67  static const int _numAirmasses = 12;
68  static const TipperAngles _tipAngles[_numAirmasses];
69 
70  void doTip();
71  void openPort( ::std::string device );
72  void setDirection( TipperDirection dir );
73  void goToZenith();
74  void doStep( int numsteps );
75  void readAllChannels( TipData &tipData );
76  void convertAndScaleChannels( TipData &tipData );
77 
78  protected:
79  void sendTipperCommand();
80  void sendTipperPrefix();
81  void doMeasurement( TipData *tipData );
82  void getCurrentFileName( ::std::string &theName );
83  void writeToFile( TipData *tipData );
84  void readOneChannel( char channel, float &chanData );
85  void doAvgSignalRef( TipData &tipData );
86 
87  TipperStatus getStatus() { return _status; };
88  void setStatus( TipperStatus status );
89 
90  void openPort();
91  void setPortTimeout( int seconds );
92  void clearReadBuffer();
93  void closePort();
94 
95  enum Parity {
96  EVEN,
97  ODD
98  };
99 
100  void setParity( enum Parity );
101  void write( const char * buff, size_t count );
102 
103  private:
104 
105  ::std::string _portDevName;
106  ::std::string _dataDir;
107  int _numTips;
108  double _autoWriterDelayInS;
109  ::std::auto_ptr< ::carma::monitor::OpacityMonitorSubsystem > _monitor;
110  bool _emulate;
111  log4cpp::Category &_logger;
112 
113  char _loDataByte, _command[4];
114  int _portFD;
115  struct termios _tios;
116  struct termios _oldtios;
117 
118  TipperStatus _status;
119 
120  carma::util::PthreadMutex _tipMeasurementLock;
121 
122  }; // class TipperControlThread
123  } // namespace antenna
124 } // namespace carma
125 
126 ::std::ostream& operator<<( ::std::ostream& os,
127  ::carma::tipper::TipperControlThread& tControl );
128 
129 #endif // CARMA_TIPPER_TIPPERCONTROL_H
130 
131 // vim: set expandtab sw=2 ts=2 cindent :
std::ostream & operator<<(::std::ostream &os, const carma::dbms::Table &table)
Common time functions.
Exception class for errors.
Interface file for the carma::util::Trace class and related macros.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
This is the interface file for extra APIs for program logging.