CARMA C++
Telemetry.h
Go to the documentation of this file.
1 
10 #ifndef CARMA_ANTENNA_BIMA_TELEMETRY_H
11 #define CARMA_ANTENNA_BIMA_TELEMETRY_H
12 
13 // C++ Standard library includes
14 #include <map>
15 #include <string>
16 #include <vector>
17 #include <list>
18 #include <iostream>
19 #include <ostream>
20 #include <queue>
21 
22 // C includes
23 #include <time.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <sys/time.h>
27 
28 // Xerces includes
29 #include <xercesc/parsers/SAXParser.hpp>
30 #include <xercesc/validators/DTD/DTDValidator.hpp>
31 
32 // CARMA includes
33 #include "carma/util/Program.h"
34 #include "carma/util/Trace.h"
40 #include "carma/util/IPQreader.h"
41 #include "carma/util/IPQwriter.h"
42 #include "carma/services/Global.h"
43 #include "carma/util/Logger.h"
45 #include "carma/util/Time.h"
46 #include "carma/canbus/Utilities.h"
48 #include "carma/canbus/CanDio.h"
49 
50 // This needs to be defined in some sorta globals area.. See Drives.h
51 #define TILTSAMPLES 100
52 
53 #ifndef BIMA_DEBUG
54 #define BIMA_DEBUG 9
55 #endif
56 
57 #define RESOLVERSAMPLES 12
58 #define AZRESOLVER "AZRESOLV"
59 #define AZRESOLVSAMPLES "AZRSMPLS"
60 #define ELRESOLVER "ELRESOLV"
61 #define ELRESOLVSAMPLES "ELRSMPLS"
62 
63 #define ENCODERSAMPLES 12
64 #define AZCOSENC "AZCOSEN"
65 #define AZCOSENCSAMPLES "AZCESMPLS"
66 #define ELCOSENC "ELCOSEN"
67 #define ELCOSENCSAMPLES "ELCESMPLS"
68 #define AZSINENC "AZSINEN"
69 #define AZSINENCSAMPLES "AZSESMPLS"
70 #define ELSINENC "ELSINEN"
71 #define ELSINENCSAMPLES "ELSESMPLS"
72 
73 #define AZRESOLVOUT "AZROUTLRS"
74 #define ELRESOLVOUT "ELROUTLRS"
75 #define AZCOSENCOUT "AZCEOUTLRS"
76 #define AZSINENCOUT "AZSEOUTLRS"
77 #define ELCOSENCOUT "ELCEOUTLRS"
78 #define ELSINENCOUT "ELSEOUTLRS"
79 
80 /*
81  define MASSAGEENCVALUE( a ) \
82  if ( (a & 0x8000) != 0 ) a = ~(a & 0x7fff)+1; \
83 */
84 // Disable MASSAGENCVALUE FOR NOW...
85 #define MASSAGEENCVALUE( a ) ;
86 
87 
98 namespace carma {
99 
100  namespace antenna {
101 
102  namespace bima {
103 
104 
111  class Telemetry
112  {
113  public:
114 
121  Telemetry( int canbusBoardNo, int canbusSlotNo, Configuration &config, SharedMemory *shm );
122 
126  virtual ~Telemetry();
127 
135  std::map<carma::canbus::msgType, std::string> getHalfSecMonitors() const;
136 
144  std::map<carma::canbus::msgType, std::string> getSlowMonitors() const;
145 
154  double rxMJD, std::vector<carma::canbus::byteType> data, bool sim );
155 
156  // useful utility function for asserting data payload validity
157  bool assertDataAndSize( std::vector<carma::canbus::byteType> &data );
158 
173 
181 
182 
186  void resetNode( );
187 
188  void run( void );
189  static void *startReaderThread( void *arg );
190  static void *startWriterThread( void *arg );
191  static void *startEmulateReaderThread( void *arg );
192  static void *startEmulateWriterThread( void *arg );
193  void readerThread( void );
194  void writerThread( void );
195  void emulateReaderThread( void );
196  void emulateWriterThread( void );
197 
198  // Commands
199  static const carma::canbus::msgType RESET = 0x000;
200  static const carma::canbus::msgType VMEWRITE = 0x001;
201  static const carma::canbus::msgType TOGGLEBIT = 0x002;
202  static const carma::canbus::msgType WRITESPACEQRY = 0x003;
203  static const carma::canbus::msgType READSPACEQRY = 0x004;
204  static const carma::canbus::msgType TMTYDISABLE = 0x005;
205  static const carma::canbus::msgType TMTYENABLE = 0x006;
206  static const carma::canbus::msgType SETBITS = 0x007;
207  static const carma::canbus::msgType QUERYLOG = 0x3F0;
208  static const carma::canbus::msgType SERIALENABLE = 0x3F1;
209  static const carma::canbus::msgType SERIALDISABLE = 0x3F2;
210  static const carma::canbus::msgType CLEARLOG = 0x3F4;
211  static const carma::canbus::msgType DOWNLOAD = 0x3FD;
212 
213  private:
214 
215  static const carma::canbus::apiType API_ID = 144;
216 
217  // Response to Commands
218  static const carma::canbus::msgType ERROR_RECORD_1 = 0x1F0;
219  static const carma::canbus::msgType ERROR_RECORD_2 = 0x1F1;
220  static const carma::canbus::msgType WRITESPACERPY = 0x1F2;
221  static const carma::canbus::msgType READSPACERPY = 0x1F3;
222 
223  // Fast packets
224  static const carma::canbus::msgType FAST_PACKET_01 = 0x100;
225  static const carma::canbus::msgType FAST_PACKET_02 = 0x101;
226  static const carma::canbus::msgType FAST_PACKET_03 = 0x102;
227  static const carma::canbus::msgType FAST_PACKET_04 = 0x103;
228  static const carma::canbus::msgType FAST_PACKET_05 = 0x104;
229  static const carma::canbus::msgType FAST_PACKET_06 = 0x105;
230  static const carma::canbus::msgType FAST_PACKET_07 = 0x106;
231  static const carma::canbus::msgType FAST_PACKET_08 = 0x107;
232  static const carma::canbus::msgType FAST_PACKET_09 = 0x108;
233  static const carma::canbus::msgType FAST_PACKET_10 = 0x109;
234  static const carma::canbus::msgType FAST_PACKET_11 = 0x10A;
235  static const carma::canbus::msgType FAST_PACKET_12 = 0x10B;
236  static const carma::canbus::msgType FAST_PACKET_13 = 0x10C;
237  static const carma::canbus::msgType FAST_PACKET_14 = 0x10D;
238  static const carma::canbus::msgType SLOW_PACKET_01 = 0x120;
239  static const carma::canbus::msgType SLOW_PACKET_02 = 0x121;
240  static const carma::canbus::msgType SLOW_PACKET_03 = 0x122;
241  static const carma::canbus::msgType SLOW_PACKET_04 = 0x123;
242  static const carma::canbus::msgType SLOW_PACKET_05 = 0x124;
243  static const carma::canbus::msgType SLOW_PACKET_06 = 0x125;
244  static const carma::canbus::msgType SLOW_PACKET_07 = 0x126;
245  static const carma::canbus::msgType SLOW_PACKET_08 = 0x127;
246  static const carma::canbus::msgType SLOW_PACKET_09 = 0x128;
247  static const carma::canbus::msgType SLOW_PACKET_10 = 0x129;
248  static const carma::canbus::msgType SLOW_PACKET_11 = 0x12A;
249  static const carma::canbus::msgType SLOW_PACKET_12 = 0x12B;
250  static const carma::canbus::msgType SLOW_PACKET_13 = 0x12C;
251  static const carma::canbus::msgType SLOW_PACKET_14 = 0x12D;
252 
253  // Looking for other CANBus msgType definitions? Go look in telemetry.xml
254 
255  // Copy and assignment not permitted for this class.
256  Telemetry( const Telemetry & );
257  Telemetry &operator=( const Telemetry & );
258 
259  // Methods to process individual CAN messages. These routines
260  // are called by processMsg.
261  void processFastPacket( std::vector<carma::canbus::byteType> &data );
262 
263  // Methods to produce simulated CAN messages. These routines are
264  // called by simulateMsg and then placed in the CAN message queue
265  // where they will eventually be processed by processMsg above.
266 
267 
268  std::map<carma::canbus::msgType, TelemetryInfo> _msgMap;
269  std::map<unsigned short, std::string> _idMap;
270 
271  carma::util::Time _time;
272  bool _emulate;
273  log4cpp::Category &_logger;
274 
275  int _node;
276  static carma::canbus::CanDio *_canBus; // shared between threads
277  TelemetryConfigHandler *_tmConfig;
278  SemaphoreOperator *_semOp;
279  SharedMemory *_bimaShm;
281  std::ostringstream _errMsg;
282  int *_tilt1samples;
283  int _tilt1len;
284  int *_tilt2samples;
285  int _tilt2len;
286 
287  int *_azrsamples;
288  int _azrlen;
289  int *_elrsamples;
290  int _elrlen;
291  int *_azcsamples;
292  int _azclen;
293  int *_elcsamples;
294  int _elclen;
295  int *_azssamples;
296  int _azslen;
297  int *_elssamples;
298  int _elslen;
299 
300  std::string getTelemetryVersion();
301  void setTelemetryVersion( std::string ver );
302 
303 
304  int _lastByteA, _lastByteB, _lastByteC,
305  _lastByteAI, _lastByteBI, _lastByteCI,
306  _lastByteAC, _lastByteBC, _lastByteCC;
307 
308  };
309 
310  } // Namespace bima
311  } // Namespace antenna
312 } // Namespace carma
313 
314 
315 #endif // CARMA_ANTENNA_BIMA_TELEMETRY_H
carma::canbus::Message simulateMsg(carma::canbus::msgType mid)
Produce a simulated CAN message for a given msgType.
Class definition for TelemetryCommand on the BIMA antennas.
Common time functions.
Class to control the CARMA specialized Janz CAN/DIO card.
Definition: CanDio.h:48
Exception class for errors.
Class to encapsulate a CAN message.
Definition: Message.h:21
virtual ~Telemetry()
Destructor.
SAX Handler for parsing BIMA Telemetry configuration file.
unsigned short apiType
Carma API id type.
Definition: Types.h:64
Declarations of carma::canbus exceptions.
Interface file for the carma::util::Trace class and related macros.
Common parameters used CARMA-wide, both typedefs and constants such as number of antennas.
Class definition for SharedMemory on the BIMA antennas.
This class deals primarily with Frames and Times.
Definition: Time.h:74
Declarations of carma::canbus utility functions.
Telemetry Device class implementation.
Definition: Telemetry.h:111
void resetNode()
Engineering commands.
static carma::canbus::apiType getApiId()
Staticly retrieve the API Id.
void processMsg(carma::canbus::msgType mid, double rxMJD, std::vector< carma::canbus::byteType > data, bool sim)
Process a CAN message.
Telemetry(int canbusBoardNo, int canbusSlotNo, Configuration &config, SharedMemory *shm)
Constructor.
Class definition for Stepper Motors for BIMA systems.
unsigned short msgType
Carma Message id type.
Definition: Types.h:69
std::map< carma::canbus::msgType, std::string > getSlowMonitors() const
Retrieve a map of this devices slow monitor points.
Declaration of carma::canbus::CanDio class.
std::map< carma::canbus::msgType, std::string > getHalfSecMonitors() const
Retrieve a map of this devices half second monitor points.
Class definition for TelemetryClient on the BIMA antennas.