43 #ifndef _MLAB_CANOPENNMTMASTER_H_ 44 #define _MLAB_CANOPENNMTMASTER_H_ 49 #include <boost/thread/future.hpp> 55 namespace mira {
namespace can {
81 mNMTMaster(master), mRequestID(requestID)
83 this->mFuture.swap(other);
104 bool isReady()
const {
return mFuture.is_ready(); }
116 bool hasValue()
const {
return mFuture.has_value(); }
123 void wait()
const { mFuture.wait(); }
131 template<
typename Duration>
133 return mFuture.timed_wait(relTime);
143 return mFuture.timed_wait_until(absTime);
165 boost::unique_future<CANOpenNodeStatus>
mFuture;
207 void removeHeartbeatCallback(uint32 pFuncID);
220 void startNode(uint8 iNodeID);
227 void stopNode(uint8 iNodeID);
234 void preOperationalNode(uint8 iNodeID);
241 void resetNode(uint8 iNodeID);
248 void resetCommunication(uint8 iNodeID);
269 void onDestructFuture(uint64 requestID);
275 void processNMTMessage(
const CANMessage& iMsg);
278 void processThread();
288 StatusRequest(uint8 iNode) : node(iNode) {}
289 virtual ~StatusRequest() {}
292 promise.set_value(iStatus);
294 virtual void setException(
const Exception& ex) {
295 promise.set_exception(boost::copy_exception(ex));
299 boost::promise<CANOpenNodeStatus> promise;
302 typedef boost::shared_ptr<StatusRequest> StatusRequestPtr;
303 typedef std::map<uint64, StatusRequestPtr> StatusRequestList;
305 struct HeartbeatListener {
317 std::queue<CANMessage> mMessageQueue;
318 boost::mutex mMessageMutex;
319 boost::condition_variable mMessageCondition;
322 boost::thread mProcessThread;
325 std::vector<HeartbeatListener> mHeartbeatCbs;
326 uint32 mHeartbeatCallbackNextID;
327 boost::mutex mHeartbeatMutex;
330 StatusRequestList mStatusRequests;
331 boost::mutex mStatusRequestsMutex;
bool timedWait(Duration const &relTime) const
Waits and blocks the current thread until the result of the associated status request is ready...
Definition: CANOpenNMTMaster.h:132
boost::function< void(uint8, CANOpenNodeStatus)> CANOpenHeartbeat
A callback for CANopen heartbeat message.
Definition: CANOpenNMTMaster.h:60
Abstract class for a hardware specific CAN driver.
bool isReady() const
Checks to see if the result of the status request associated with this future is set.
Definition: CANOpenNMTMaster.h:104
An implementation of a basic CANopen NMT master.
Definition: CANOpenNMTMaster.h:173
boost::shared_ptr< CANInterface > CANInterfacePtr
A shared pointer of the CANInterface.
Definition: CANInterface.h:224
CANOpenNodeStatusFuture()
Default constructor.
Definition: CANOpenNMTMaster.h:76
CANOpenNodeStatusFuture(CANOpenNodeStatusFuture &&other)
Move constructor.
Definition: CANOpenNMTMaster.h:87
Wrapper for boost::unique_future that is specialized for NMT status requests.
Definition: CANOpenNMTMaster.h:71
Global definitions of the CANopen standard.
bool timedWaitUntil(boost::system_time const &absTime) const
Waits and blocks the current thread until the result of the associated status request is ready...
Definition: CANOpenNMTMaster.h:142
CANOpenNMTMaster * mNMTMaster
Definition: CANOpenNMTMaster.h:163
boost::shared_ptr< CANOpenNMTMaster > CANOpenNMTMasterPtr
A shared pointer of the CANOpenNMTMaster.
Definition: CANOpenNMTMaster.h:335
CANOpenNodeStatusFuture & operator=(CANOpenNodeStatusFuture &&other)
Move assignment operator.
Definition: CANOpenNMTMaster.h:92
uint64 mRequestID
Definition: CANOpenNMTMaster.h:164
CANOpenNodeStatus
The different CANopen node states.
Definition: CANOpenDefs.h:154
bool hasException() const
Returns true if the status request associated with this future has finished with an exception rather ...
Definition: CANOpenNMTMaster.h:110
#define MLAB_CAN_EXPORT
Definition: CANExports.h:57
void wait() const
Waits and blocks the current thread until the result of the associated status request is ready...
Definition: CANOpenNMTMaster.h:123
A definition of a CAN message.
Definition: CANDefs.h:105
boost::unique_future< CANOpenNodeStatus > mFuture
Definition: CANOpenNMTMaster.h:165
bool hasValue() const
Returns true if the status request call associated with this future has finished with a return value ...
Definition: CANOpenNMTMaster.h:116
void swap(CANOpenNodeStatusFuture &other)
Swaps ownership of the asynchronous results associated with other and *this.
Definition: CANOpenNMTMaster.h:147
CANOpenNodeStatusFuture(boost::unique_future< CANOpenNodeStatus > other, CANOpenNMTMaster *master, uint64 requestID)
Constructor.
Definition: CANOpenNMTMaster.h:79