MIRA
CANDriverInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MLAB_CANDRIVERINTERFACE_H_
44 #define _MLAB_CANDRIVERINTERFACE_H_
45 
46 #include <can/CANInterface.h>
47 
48 namespace mira { namespace can {
49 
51 
57 {
58 public:
61 
66  CANDriverInterface(const std::string& driver);
67 
69  virtual ~CANDriverInterface();
70 
72 
73 public:
76 
82  void open(const std::string& deviceName,
83  CANBaudRate baudRate = CAN_BAUDRATE_250K);
84 
88  void close();
89 
99  uint8 getBusLoad() const;
100 
102 
103 public:
106 
109  {
110  return mDriver;
111  }
112 
114 
115 public:
118 
119  virtual void sendMessage(const CANMessage& pMsg);
120 
122 
123 private:
124 
125  void processIncomingMessages();
126  void processOutgoingMessages();
127 
128 private:
129  bool mIsOpen;
130 
131  // outgoing messages
132  boost::mutex mOutgoingMutex;
133  boost::condition_variable mOutgoingCondition;
134  std::queue<CANMessage> mOutgoingQueue;
135 
136  // Two separate thread for handling incoming and outgoing messages
137  boost::thread mIncomingThread;
138  boost::thread mOutgoingThread;
139 
140  // time of the last load measurement
141  Time mLastLoadTime;
142  size_t mBitCount;
143  uint8 mBusLoad;
144 
145  // The used driver
146  CANDriverPtr mDriver;
147 };
148 
150 typedef boost::shared_ptr<CANDriverInterface> CANDriverInterfacePtr;
151 
153 
154 }} // namespaces
155 
156 #endif
CANBaudRate
An enum of the different CAN baud rates.
Definition: CANDefs.h:59
Abstract class for a hardware specific CAN driver.
boost::shared_ptr< CANDriver > CANDriverPtr
Definition: CANDriver.h:186
A common interface to the CAN bus.
Definition: CANDriverInterface.h:56
CANDriverPtr getDriver() const
Returns a pointer to CAN driver.
Definition: CANDriverInterface.h:108
#define MLAB_CAN_EXPORT
Definition: CANExports.h:57
A general interface for a CAN driver.
Definition: CANInterface.h:83
A definition of a CAN message.
Definition: CANDefs.h:105
boost::shared_ptr< CANDriverInterface > CANDriverInterfacePtr
A shared pointer for CANDriverInterface.
Definition: CANDriverInterface.h:150
250 kBit/s
Definition: CANDefs.h:62