00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00003 // This file is part of the SCHUNK Canopen Driver suite. 00004 // 00005 // This program is free software licensed under the LGPL 00006 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3). 00007 // You can find a copy of this license in LICENSE folder in the top 00008 // directory of the source code. 00009 // 00010 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany 00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // -- END LICENSE BLOCK ------------------------------------------------ 00013 //---------------------------------------------------------------------- 00020 //---------------------------------------------------------------------- 00021 00022 #ifndef HEARTBEATMONITOR_H 00023 #define HEARTBEATMONITOR_H 00024 00025 #include <boost/thread.hpp> 00026 #include <boost/shared_ptr.hpp> 00027 #include <map> 00028 00029 #include <icl_core/TimeStamp.h> 00030 00031 namespace icl_hardware{ 00032 namespace canopen_schunk{ 00033 00034 class HeartBeatMonitor 00035 { 00036 public: 00038 typedef boost::shared_ptr<HeartBeatMonitor> Ptr; 00040 typedef boost::shared_ptr<const HeartBeatMonitor> ConstPtr; 00041 00042 HeartBeatMonitor(); 00043 00044 ~HeartBeatMonitor(); 00045 00052 void addHeartbeat(const uint8_t node_id); 00053 00054 00059 void registerErrorCallback(const boost::function<void()>& f); 00060 00069 uint16_t getHeartBeatCycleTime () const { return m_period_time_ms; } 00070 00079 void setHeartBeatCycleTime (const uint16_t heartbeat_cycle_time_ms) { m_period_time_ms = heartbeat_cycle_time_ms; } 00080 00085 void reset(); 00086 00087 private: 00093 void workerFunction(); 00094 00096 void stop(); 00097 00099 void start(); 00100 00101 00102 std::map<uint8_t, icl_core::TimeStamp> m_timestamp_record; 00103 00105 uint16_t m_period_time_ms; 00106 00108 boost::thread m_thread; 00109 00110 boost::function<void()> m_error_function; 00111 00112 bool m_running; 00113 }; 00114 00115 }} // End of NS 00116 00117 #endif // HEARTBEATMONITOR_H