MIRA
CANDriver.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_CANDRIVER_H_
44 #define _MLAB_CANDRIVER_H_
45 
46 #include <factory/Factory.h>
47 
48 #include <can/CANDefs.h>
49 
50 namespace mira { namespace can {
51 
53 
58 {
60 
61 public:
64 
67  {}
68 
70  virtual ~CANDriver() {}
71 
73  template<typename Reflector>
74  void reflect(Reflector& r)
75  {
76  r.member("BaudRate", mBaudRate, "The baudrate", CAN_BAUDRATE_250K);
77  r.member("Device", mDeviceName, "The device name");
78  }
79 
81 
82 public:
85 
91  {
92  return mBaudRate;
93  }
94 
99  void setBaudRate(const CANBaudRate& baudRate)
100  {
101  mBaudRate = baudRate;
102  }
103 
108  std::string getDeviceName() const
109  {
110  return mDeviceName;
111  }
112 
117  void setDeviceName(const std::string& deviceName)
118  {
119  mDeviceName = deviceName;
120  }
121 
126  virtual std::string getDriverInfo()
127  {
128  return "No CAN-Driver information available.";
129  }
130 
132 
133 public:
136 
140  virtual void open() = 0;
141 
145  virtual void close() = 0;
146 
151  virtual CANStatusFlags getStatus() = 0;
152 
154 
155 public:
158 
163  virtual void sendMessage(const CANMessage& msg) = 0;
164 
169  virtual bool waitForNextMessage(Duration timeout) = 0;
170 
176  virtual void receiveMessage(CANMessage& oMsg, Time& oReceiveTime) = 0;
177 
179 
180 protected:
181 
182  std::string mDeviceName;
184 };
185 
186 typedef boost::shared_ptr<CANDriver> CANDriverPtr;
187 
189 
190 }} // namespaces
191 
192 #endif
CANBaudRate
An enum of the different CAN baud rates.
Definition: CANDefs.h:59
virtual ~CANDriver()
The destructor.
Definition: CANDriver.h:70
CANBaudRate getBaudRate() const
Return the current baud rate.
Definition: CANDriver.h:90
A general interface for a CAN driver.
Definition: CANDriver.h:57
void setDeviceName(const std::string &deviceName)
Set the device name.
Definition: CANDriver.h:117
boost::shared_ptr< CANDriver > CANDriverPtr
Definition: CANDriver.h:186
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
std::string getDeviceName() const
Return the device name for the CAN bus.
Definition: CANDriver.h:108
CANDriver()
The default constructor.
Definition: CANDriver.h:66
#define MLAB_CAN_EXPORT
Definition: CANExports.h:57
CANStatusFlags
CAN status enum definitions.
Definition: CANDefs.h:76
CANBaudRate mBaudRate
Used baud rate.
Definition: CANDriver.h:183
std::string mDeviceName
The device name.
Definition: CANDriver.h:182
void reflect(Reflector &r)
The reflect method.
Definition: CANDriver.h:74
virtual std::string getDriverInfo()
Get some information about the driver.
Definition: CANDriver.h:126
A definition of a CAN message.
Definition: CANDefs.h:105
Common CANbus definitions.
void setBaudRate(const CANBaudRate &baudRate)
Set the baud rate.
Definition: CANDriver.h:99
250 kBit/s
Definition: CANDefs.h:62