CARMA C++
CanDevice.h
Go to the documentation of this file.
1 #ifndef SZA_ANTENNA_CANBUS_CANDEVICE_H
2 #define SZA_ANTENNA_CANBUS_CANDEVICE_H
3 
13 
15 
16 #include "carma/szautil/Rx.h"
17 
18 #include "carma/canbus/Device.h"
19 
20 #include <string>
21 #include <vector>
22 
23 // The maximum number of characters which can be returned from a CAN
24 // node in an ASCII character std::string.
25 
26 #define CAN_MAX_CHAR 8
27 
28 // The maximum number of error log entries maintained by a node.
29 
30 #define CAN_MAX_ERROR_LOG_ENTRY 64
31 
32 // Define a handler for a CAN status message
33 
34 #define CAN_STATUS_MSG_HANDLER(fn) void (fn)(void* arg1, unsigned arg2)
35 
36 namespace sza {
37  namespace antenna {
38 
39  // Forward declaration of SzaShare lets us use it without defining
40  // it
41 
42  namespace control {
43  class SzaShare;
44  }
45 
46  namespace canbus {
47 
56  class CanDevice :
57  public carma::canbus::Device,
59 
60  public:
61 
81  std::string boardName,
85 
90  virtual ~CanDevice();
91 
96  virtual void enableMonitorPackets(bool timeStampEnable,
97  bool blankingFrameEnable,
98  bool slowMonitorEnable);
99 
103  virtual void sendTimeStamp();
104 
109 
110  CanMonitorPoint* findMonitorPoint(char* name);
111 
112  // Maintain information about the receiver currently selected
113 
114  virtual void setRxId(sza::util::Rx::Id rxId);
115 
116  std::vector<carma::canbus::Message> sendDummyMsg(bool send);
117 
118  protected:
119 
120  // All SZA CAN devices will have these members.
121 
122  CanMonitor monitor_;
123 
124  sza::util::Rx::Id rxId_;
125 
126  // A struct to encapsulate a status-message/handler
127  // association
128 
129  struct HandlerInfo
130  {
131  CAN_STATUS_MSG_HANDLER(*handler_);
133  void* arg1_;
134  unsigned arg2_;
135 
136  HandlerInfo(carma::canbus::msgType mid,
137  CAN_STATUS_MSG_HANDLER(*handler),
138  void* arg1, unsigned arg2)
139  {
140  mid_ = mid;
141  handler_ = handler;
142  arg1_ = arg1;
143  arg2_ = arg2;
144  }
145  };
146 
147  // A vector of handlers for status messages
148 
149  std::vector<HandlerInfo> handlers_;
150 
151  // Install a handler for a given message id
152 
153  void installHandler(carma::canbus::msgType mid,
154  CAN_STATUS_MSG_HANDLER(*handler),
155  void* arg1,
156  unsigned arg2);
157 
161  void initRegs();
162 
166  void registerReceived(unsigned id, bool isSim);
167 
168  //------------------------------------------------------------
169  // Overloaded methods from the base class.
170  //------------------------------------------------------------
171 
172  //------------------------------------------------------------
173  // Device control
174 
178  std::map<carma::canbus::msgType, std::string>
179  getControls();
180 
184  std::map<carma::canbus::msgType, std::string>
186 
190  virtual std::map<carma::canbus::msgType, std::string>
191  getSpecificControls() const;
192 
197  virtual std::string controlPrefix();
198 
202  virtual std::map<carma::canbus::msgType, std::string>
203  getHalfSecMonitors() const;
204 
208  virtual std::map<carma::canbus::msgType, std::string>
209  getSlowMonitors() const;
210 
214  virtual std::map<carma::canbus::msgType, std::string>
215  getEngineeringMonitors() const;
216 
220  virtual std::map<carma::canbus::msgType, std::string>
221  getStatusMessages() const;
222 
227  carma::canbus::idType createId(bool host,
229 
230  carma::canbus::idType createDummyId();
231 
238 
244 
249  std::vector<carma::canbus::byteType>& data);
250 
255  void postDummyMessage();
256 
261  std::vector<carma::canbus::byteType>& data);
262 
268  std::vector<carma::canbus::byteType>& data);
269 
275  carma::canbus::Message dummyMessage();
276 
282  std::vector<carma::canbus::byteType>& data);
283 
289  std::vector<carma::canbus::byteType>& data);
290 
296 
297  //------------------------------------------------------------
298  // Host commands common to all CAN devices
299  //------------------------------------------------------------
300 
301  enum commonHostCommands
302  {
303  HOSTCMD_RESET = 0x000, // Reset
304  HOSTCMD_SET_TIME = 0x001, // Set the time (MJD)
305  HOSTCMD_STOP_CHAN1 = 0x002, // Stop channel 1 fast sampling
306  HOSTCMD_STOP_CHAN2 = 0x003, // Stop channel 2 fast sampling
307  HOSTCMD_START_CHAN1 = 0x004, // Start channel 1 fast sampling
308  HOSTCMD_START_CHAN2 = 0x005, // Start channel 2 fast sampling
309  };
310 
311  //------------------------------------------------------------
312  // Engineering commands common to all CAN devices.
313  //------------------------------------------------------------
314 
315  enum commonEngineeringCommands
316  {
317  ENGCMD_ERROR_LOG = 0x3F0,
318  ENGCMD_ERROR_CLEAR = 0x3F4,
319  ENGCMD_MONITOR_ENABLE = 0x3FB,
320  ENGCMD_ID_REQUEST = 0x3FC,
321  ENGCMD_START_DOWNLOAD = 0x3FD,
322  ENGCMD_ASCII_STRING = 0x3FF
323  };
324 
328  virtual void retrieveErrorLogEntry(unsigned short recordNo);
329 
333  virtual void clearErrorLog();
334 
338  virtual void requestId();
339 
343  virtual void startDownLoad();
344 
348  virtual void sendAsciiString(std::string sendStr);
349 
350  //============================================================
351  // Message processing methods.
352  //============================================================
353 
357  virtual void processMsg(carma::canbus::msgType messageId,
358  std::vector<carma::canbus::byteType>& data,
359  bool isSim);
360 
365 
366  //------------------------------------------------------------
367  // Blanking frame (2 Hz) monitor packets
368  //------------------------------------------------------------
369 
375  MONITOR_PACKET_1 = 0x0E0,
376  MONITOR_PACKET_2 = 0x0E1,
377  MONITOR_PACKET_3 = 0x0E2,
378  MONITOR_PACKET_4 = 0x0E3,
379  MONITOR_PACKET_5 = 0x0E4,
380  MONITOR_PACKET_6 = 0x0E5,
381  MONITOR_PACKET_7 = 0x0E6,
382  MONITOR_PACKET_8 = 0x0E7,
383  MONITOR_PACKET_9 = 0x0E8,
384  MONITOR_PACKET_10 = 0x0E9,
385  MONITOR_PACKET_11 = 0x0EA,
386  };
387 
393 
398 
403 
407  virtual void
409  std::vector<carma::canbus::byteType>&
410  data, bool isSim);
411 
415  virtual void
416  processBlankingFrameMonitor1(std::vector<carma::canbus::byteType>&
417  data, bool isSim) {};
418  virtual void
419  processBlankingFrameMonitor2(std::vector<carma::canbus::byteType>&
420  data, bool isSim) {};
421  virtual void
422  processBlankingFrameMonitor3(std::vector<carma::canbus::byteType>&
423  data, bool isSim) {};
424  virtual void
425  processBlankingFrameMonitor4(std::vector<carma::canbus::byteType>&
426  data, bool isSim) {};
427  virtual void
428  processBlankingFrameMonitor5(std::vector<carma::canbus::byteType>&
429  data, bool isSim) {};
430  virtual void
431  processBlankingFrameMonitor6(std::vector<carma::canbus::byteType>&
432  data, bool isSim) {};
433  virtual void
434  processBlankingFrameMonitor7(std::vector<carma::canbus::byteType>&
435  data, bool isSim) {};
436  virtual void
437  processBlankingFrameMonitor8(std::vector<carma::canbus::byteType>&
438  data, bool isSim) {};
439  virtual void
440  processBlankingFrameMonitor9(std::vector<carma::canbus::byteType>&
441  data, bool isSim) {};
442  virtual void
443  processBlankingFrameMonitor10(std::vector<carma::canbus::byteType>&
444  data, bool isSim) {};
445  virtual void
446  processBlankingFrameMonitor11(std::vector<carma::canbus::byteType>&
447  data, bool isSim) {};
448 
452  virtual carma::canbus::Message
454 
455  virtual carma::canbus::Message simulateBlankingFrameMonitor1();
456  virtual carma::canbus::Message simulateBlankingFrameMonitor2();
457  virtual carma::canbus::Message simulateBlankingFrameMonitor3();
458  virtual carma::canbus::Message simulateBlankingFrameMonitor4();
459  virtual carma::canbus::Message simulateBlankingFrameMonitor5();
460  virtual carma::canbus::Message simulateBlankingFrameMonitor6();
461  virtual carma::canbus::Message simulateBlankingFrameMonitor7();
462  virtual carma::canbus::Message simulateBlankingFrameMonitor8();
463  virtual carma::canbus::Message simulateBlankingFrameMonitor9();
464  virtual carma::canbus::Message simulateBlankingFrameMonitor10();
465  virtual carma::canbus::Message simulateBlankingFrameMonitor11();
466 
470  virtual carma::canbus::Message
472 
473  //------------------------------------------------------------
474  // Slow monitor packets
475  //------------------------------------------------------------
476 
481  SLOW_MONITOR_1 = 0x120,
482  SLOW_MONITOR_2 = 0x121,
483  SLOW_MONITOR_3 = 0x122,
484  SLOW_MONITOR_4 = 0x123,
485  SLOW_MONITOR_5 = 0x124
486  };
487 
488  //------------------------------------------------------------
489  // Members to do with slow monitors common to all CAN
490  // devices.
491  //------------------------------------------------------------
492 
493  unsigned short moduleSerialNo_;
494 
495  unsigned int initRequest_;
496  unsigned int rxErrors_;
497  unsigned int txErrors_;
498  unsigned int memoryErrors_;
499  unsigned int systemErrors_;
500  unsigned short schedulerOverflowCount_;
501  unsigned short timedSchedulerOverflowCount_;
502 
503  unsigned char softwareMajorVersion_;
504  unsigned char softwareMinorVersion_;
505  unsigned char softwareTestVersion_;
506  unsigned int swVersionStr_[3];
507 
508  unsigned short communicationErrorCount_;
509  unsigned short timeErrorCount_;
510  unsigned short softwareErrorCount_;
511  unsigned short hardwareErrorCount_;
512  short timeOffset_;
513  short timeStampInterval_;
514  short timeStampDelta_;
515 
520 
524  virtual void
526  std::vector<carma::canbus::byteType>& data,
527  bool isSim);
528 
532  virtual void
533  processSlowMonitor1(std::vector<carma::canbus::byteType>& data, bool isSim);
534 
538  virtual void
539  processSlowMonitor2(std::vector<carma::canbus::byteType>& data, bool isSim);
540 
544  virtual void
545  processSlowMonitor3(std::vector<carma::canbus::byteType>& data, bool isSim);
546 
550  virtual void
551  processSlowMonitor4(std::vector<carma::canbus::byteType>& data, bool isSim);
552 
556  virtual void
557  processSlowMonitor5(std::vector<carma::canbus::byteType>& data, bool isSim);
558 
559  //============================================================
560  // Engineering monitor packets
561  //============================================================
562 
567  ENG_MONITOR_1 = 0x1F0, // Error record 1
568  ENG_MONITOR_2 = 0x1F1, // Error record 2
569  ENG_MONITOR_3 = 0x3FC, // ID request
570  ENG_MONITOR_4 = 0x3FF // ASCII string
571  };
572 
573  //------------------------------------------------------------
574  // Members to do with engineering monitor members common to
575  // all CAN devices.
576  //------------------------------------------------------------
577 
578  unsigned int errLog_;
579  unsigned int mjd_;
580  unsigned int mjdTime_;
581  unsigned int errCode_;
582  unsigned int errCnt_;
583  unsigned int serialNo_;
584  unsigned int errData_;
585  unsigned int moduleType_;
586 
587  unsigned short apiNo_;
588  unsigned short dongleId_;
589 
590  unsigned char asciiString_[CAN_MAX_CHAR+1];
591 
596 
600  virtual void
602  std::vector<carma::canbus::byteType>& data,
603  bool isSim);
604 
605  // Engineering monitor process methods
606 
607  virtual void
608  processEngineeringMonitor1(std::vector<carma::canbus::byteType>& data, bool isSim);
609 
610  virtual void
611  processEngineeringMonitor2(std::vector<carma::canbus::byteType>& data, bool isSim);
612 
613  virtual void
614  processEngineeringMonitor3(std::vector<carma::canbus::byteType>& data, bool isSim);
615 
616  virtual void
617  processEngineeringMonitor4(std::vector<carma::canbus::byteType>& data, bool isSim);
618 
619  //------------------------------------------------------------
620  // Status messages
621  //------------------------------------------------------------
622 
628 
633 
637  virtual void
639 
640  // Stub out methods for processing up to three status messages
641 
642  virtual void processStatusMessage1(bool isSim);
643  virtual void processStatusMessage2(bool isSim);
644  virtual void processStatusMessage3(bool isSim);
645  virtual void processGenericStatusMessage(bool isSim);
646 
647  //------------------------------------------------------------
648  // Utilities.
649  //------------------------------------------------------------
650 
654  void skipByte(std::vector<carma::canbus::byteType>& data,
655  unsigned short nByte);
656 
657  std::string monthDayYearToString(unsigned int month, unsigned int day, unsigned year);
658 
659 
660  }; // End class CanDevice
661 
662  }; // End namespace canbus
663  }; // End namespace antenna
664 }; // End namespace sza
665 
666 #endif // End #ifndef
667 
668 
Tagged: Sat Oct 23 22:31:40 PDT 2004.
void postEngMessage(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data)
Post a message for this device.
bool isEngineeringMonitor(carma::canbus::msgType mid)
Return true if this is a valid Engineering packet.
virtual carma::canbus::Message simulateBlankingFrameMonitor(carma::canbus::msgType mid)
Simulate blanking frame monitor packets.
virtual void processBlankingFrameMonitor(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data, bool isSim)
Process a blanking frame monitor packet.
carma::canbus::Message nodeMessage(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data)
Get an initialized node message.
engineeringMonitors
Engineering monitor packets.
Definition: CanDevice.h:566
bool isSlowMonitor(carma::canbus::msgType mid)
Return true if this is a slow monitor packet.
Class to encapsulate a CAN message.
Definition: Message.h:21
virtual void requestId()
Request the module ID.
virtual void processStatusMessage(carma::canbus::msgType mid, bool isSim)
Process an status message.
bool isStatusMessage(carma::canbus::msgType mid)
Return true if this is a valid status message for this device.
slowMonitors
Slow monitor packets will be the same for all CAN nodes.
Definition: CanDevice.h:480
carma::canbus::idType createId(bool host, carma::canbus::msgType mid)
Return a CAN message ID constructed from the api, node and command ID.
virtual void processEngineeringMonitor(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data, bool isSim)
Process an engineering monitor packet.
virtual std::map< carma::canbus::msgType, std::string > getSlowMonitors() const
Return a map of slow monitor points.
virtual carma::canbus::Message simulateMsg(carma::canbus::msgType mid)
Simulate messages to this device.
carma::canbus::Message nodeEngMessage(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data)
Get an initialized engineering node message.
void skipByte(std::vector< carma::canbus::byteType > &data, unsigned short nByte)
Skip a number of bytes in the data array.
virtual carma::canbus::Message simulateGenericBlankingFrameMonitor(carma::canbus::msgType mid)
Simulate a generic monitor packet.
virtual void processSlowMonitor1(std::vector< carma::canbus::byteType > &data, bool isSim)
Process the first slow monitor packet.
virtual void processMsg(carma::canbus::msgType messageId, std::vector< carma::canbus::byteType > &data, bool isSim)
Process a message for this device.
virtual void startDownLoad()
Start downloading a new program.
unsigned short apiType
Carma API id type.
Definition: Types.h:64
CanDevice(sza::antenna::control::SzaShare *share, std::string boardName, carma::canbus::apiType api, carma::canbus::nodeType node, carma::canbus::CanOutput &io)
Constructor.
virtual void processSlowMonitor4(std::vector< carma::canbus::byteType > &data, bool isSim)
Process the fourth slow monitor packet.
virtual void processBlankingFrameMonitor1(std::vector< carma::canbus::byteType > &data, bool isSim)
Stubs for processing up to 10 monitor packets.
Definition: CanDevice.h:416
virtual std::map< carma::canbus::msgType, std::string > getHalfSecMonitors() const
Return a map of devices half second monitor points.
bool isBlankingFrameMonitor(carma::canbus::msgType mid)
Return true if this is a valid blanking frame monitor packet.
unsigned short nodeType
Carma Node Type id type.
Definition: Types.h:66
virtual std::map< carma::canbus::msgType, std::string > getSpecificControls() const
Get module-specific controls.
A class for encapsulating devices for the SZA which will be attached to a CAN bus.
Definition: CanDevice.h:56
virtual void sendTimeStamp()
Send the current mjd.
std::map< carma::canbus::msgType, std::string > getControls()
Return a map of device controls.
virtual std::map< carma::canbus::msgType, std::string > getStatusMessages() const
Return a map of status messages.
defaultHalfSecMonitors
Blanking frame monitor packets are generally the same for all CAN nodes.
Definition: CanDevice.h:374
unsigned idOfBlankingFrameMonitorMsgType(carma::canbus::msgType mid)
Return a standard enumerator for monitor packets.
virtual void processSlowMonitor2(std::vector< carma::canbus::byteType > &data, bool isSim)
Process the second slow monitor packet.
void postMessage(carma::canbus::Message msg)
Post a fully constructed message to this device.
virtual void processSlowMonitor3(std::vector< carma::canbus::byteType > &data, bool isSim)
Process the third slow monitor packet.
A class which encapsulates resources of a board of the shared register map.
Definition: Board.h:24
virtual std::map< carma::canbus::msgType, std::string > getEngineeringMonitors() const
Return a map of engineering monitor points.
virtual std::string controlPrefix()
Return an inheritor-specific prefix to use when constructing monitor points.
unsigned idOfStatusMessageMsgType(carma::canbus::msgType mid)
......................................................................
Abstract base class for all CAN Bus devices.
Definition: Device.h:92
carma::canbus::Message hostMessage(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data)
Get an initialized host message.
std::map< carma::canbus::msgType, std::string > getCommonControls()
A map of controls common to all devices.
void initRegs()
Init registers common to all CAN devices.
virtual void processSlowMonitor5(std::vector< carma::canbus::byteType > &data, bool isSim)
Process the fifth slow monitor packet.
virtual void retrieveErrorLogEntry(unsigned short recordNo)
Retrieve a numbered error log entry.
unsigned int idType
Type for full 29 bit CAN id.
Definition: Types.h:60
carma::canbus::idType createEngId(bool host, carma::canbus::msgType mid)
Return a CAN message ID constructed from the api, node and command ID.
Declaration of carma::canbus::Device class.
virtual void sendAsciiString(std::string sendStr)
Send a std::string of up to 8 characters to the CAN node.
virtual void processSlowMonitor(carma::canbus::msgType mid, std::vector< carma::canbus::byteType > &data, bool isSim)
Process a slow monitor packet.
virtual ~CanDevice()
Destructor.
unsigned short busIdType
Carma Bus Id type.
Definition: Types.h:70
virtual void enableMonitorPackets(bool timeStampEnable, bool blankingFrameEnable, bool slowMonitorEnable)
Enable/Disable monitor packets.
unsigned short msgType
Carma Message id type.
Definition: Types.h:69
void registerReceived(unsigned id, bool isSim)
Register receipt of this monitor packet.
carma::canbus::msgType msgTypeOfBlankingFrameMonitorId(unsigned int id)
Return the message id corresponding to a standard enumerator.
virtual void clearErrorLog()
Clear the error log.
CanOutput interface.
Definition: CanOutput.h:26
Tagged: Sat Oct 23 22:15:09 PDT 2004.
Tagged: Thu Nov 13 16:53:34 UTC 2003.
An instance of this class is created by AntennaMaster and passed to the constructors of other tasks...
Definition: Share.h:38
carma::canbus::busIdType getBusId()
Return a CAN bus ID suitable for passing to Message constructor.