CARMA C++
Master.h
Go to the documentation of this file.
1 
10 #ifndef CARMA_CANBUS_MASTER_H
11 #define CARMA_CANBUS_MASTER_H
12 
13 // System includes
14 #include <pthread.h>
15 
16 // C++ Standard Library includes
17 #include <map>
18 #include <string>
19 
20 // Carma includes
21 #include "carma/canbus/CanDio.h"
22 #include "carma/util/PthreadMutex.h"
23 
24 namespace carma {
25  namespace canbus {
26 
27  // Forward dec
28  class Device;
29 
110  class Master : public CanDio {
111  public:
112 
127  Master( bool simOfflineNodes = true );
128 
150  Master(
151  int boardId,
152  bool simOfflineNodes = false,
153  bool reset = false,
154  bool terminate = true );
155 
188  Master(
189  int boardId,
190  int modulbusId,
191  bool simOfflineNodes = false,
192  bool reset = false,
193  bool terminate = true );
194 
206  Master( const ::std::vector< DevTermPair > & devTermPairs,
207  bool simOfflineNodes = false,
208  bool reset = false );
209 
216  virtual ~Master();
217 
232  void run();
233 
242  void stop();
243 
244  protected:
245 
256  void addDevice(Device *device);
257 
275  void removeDevice(apiType api, nodeType node);
276 
286  Device* getDevice(apiType api, nodeType node);
287 
292  int getOnlineNodeCount() const;
293 
298  int getOfflineNodeCount() const;
299 
313  int getUnknownPacketCount() const;
314 
326  int getDonglelessPacketCount() const;
327 
339  unsigned int getLatePacketCount();
340 
351  virtual std::map<msgType, std::string> getControls() const;
352 
367  virtual void updateStatus() = 0;
368 
381  void softwareReset();
382 
407  virtual void setTime();
408 
409  protected:
410 
411  // Undefined and inaccessible to prevent copying.
412  Master(const Master &);
413  Master &operator=(const Master &);
414 
422  void updateDevicesStates();
423 
432  static void *timerThreadEntry(void *arg);
433 
441  void runTimerThread();
442 
451  static void *readThreadEntry(void *arg);
452 
458  virtual void runReadThread();
459 
460  std::map<keyType, Device*> devices_;
461  mutable pthread_mutex_t deviceMutex_;
462  int nOnlineNodes_; // Number of nodes in !OFFLINE state
463  int nOfflineNodes_; // Number of nodes in OFFLINE state
464  int nUnknownPackets_; // Number of packets unrecognized by master
465  int nDonglelessPackets_; // Number of packets from node 512
466  pthread_t timerThreadId_;
467  pthread_t readThreadId_;
468  const int simOfflineNodes_;
469 
470  bool running_; // Is master running (needed for proper cleanup)
471  carma::util::PthreadMutex runningMutex_;
472 
473  }; // End of class Master
474  } // End namespace canbus
475 } // End namespace carma
476 #endif // End #ifndef CARMA_CANBUS_MASTER_H
virtual void setTime()
Send a time sync message.
void reset()
Reset.
void runTimerThread()
Timer thread.
Class to control the CARMA specialized Janz CAN/DIO card.
Definition: CanDio.h:48
int getOnlineNodeCount() const
Get number of online nodes.
virtual ~Master()
Master destructor.
void run()
Run the Master.
void softwareReset()
Send a software reset command to all modules.
unsigned short apiType
Carma API id type.
Definition: Types.h:64
unsigned int getLatePacketCount()
Get combined late packet count from all devices.
unsigned short nodeType
Carma Node Type id type.
Definition: Types.h:66
int getUnknownPacketCount() const
Get number of unknown packets This method returns the number of CAN packets that canbus::Master does ...
int getDonglelessPacketCount() const
Get &#39;Dongleless node&#39; packet count This routine returns the number of Dongleless node packets detecte...
Master(bool simOfflineNodes=true)
Default constructor for emulation.
static void * readThreadEntry(void *arg)
Entry point for main thread.
static void * timerThreadEntry(void *arg)
Entry point for timer thread.
Abstract base class for all CAN Bus devices.
Definition: Device.h:92
Carma Canbus Master class.
Definition: Master.h:110
void stop()
Stop running internal Master threads.
void removeDevice(apiType api, nodeType node)
Remove a device.
virtual void runReadThread()
Thread to read and process incoming CAN messages.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
virtual void updateStatus()=0
Update the status of the master.
Device * getDevice(apiType api, nodeType node)
Get pointer to a device.
void addDevice(Device *device)
Add a device to the master.
void updateDevicesStates()
Update the devices states.
int getOfflineNodeCount() const
Get number of offline nodes.
virtual std::map< msgType, std::string > getControls() const
Get controls.
Declaration of carma::canbus::CanDio class.