12 #include <boost/thread/condition_variable.hpp> 13 #include <boost/chrono/system_clocks.hpp> 14 #include <boost/lexical_cast.hpp> 20 inline time_point
get_abs_time(
const time_duration& timeout) {
return boost::chrono::high_resolution_clock::now() + timeout; }
21 inline time_point
get_abs_time() {
return boost::chrono::high_resolution_clock::now(); }
49 void abort(uint32_t reason);
71 bool read(uint8_t* b,
const size_t len);
72 void write(
const uint8_t* b,
const size_t len);
77 Buffer(
const size_t sz) : size(sz), dirty(false), empty(true), buffer(sz) {}
89 void parse_and_set_mapping(
const ObjectStorageSharedPtr &storage,
const uint16_t &com_index,
const uint16_t &map_index,
const bool &read,
const bool &write);
99 TPDOSharedPtr tpdo(
new TPDO(interface));
100 if(!tpdo->init(storage, com_index, map_index))
115 RPDOSharedPtr rpdo(
new RPDO(interface));
116 if(!rpdo->init(storage, com_index, map_index))
131 boost::unordered_set<RPDO::RPDOSharedPtr>
rpdos_;
132 boost::unordered_set<TPDO::TPDOSharedPtr>
tpdos_;
178 virtual void addNode(
void *
const ptr) = 0;
179 virtual void removeNode(
void *
const ptr) = 0;
187 Unknown = 255, BootUp = 0, Stopped = 4, Operational = 5 , PreOperational = 127
192 const State getState();
193 void enterState(
const State &s);
208 return state_dispatcher_.createListener(s);
212 return getStorage()->entry<T>(k).
get();
225 template<
typename T>
int wait_for(
const State &s,
const T &timeout);
229 boost::condition_variable
cond;
240 void switchState(
const uint8_t &s);
249 bool checkHeartbeat();
256 void call(
void (T::*func)(
void)){
257 typename std::vector<MemberSharedPtr>::iterator it = elements.begin();
258 while(it != elements.end()){
263 template<
typename V>
void call(
void (T::*func)(
const V&),
const std::vector<V> &vs){
264 typename std::vector<MemberSharedPtr>::iterator it = elements.begin();
265 typename std::vector<V>::const_iterator it_v = vs.begin();
266 while(it_v != vs.end() && it != elements.end()){
267 ((**it).*func)(*it_v);
271 template<
typename V>
void call(
void (T::*func)(V&), std::vector<V> &vs){
272 vs.resize(elements.size());
274 typename std::vector<MemberSharedPtr>::iterator it = elements.begin();
275 typename std::vector<V>::iterator it_v = vs.begin();
276 while(it_v != vs.end() && it != elements.end()){
277 ((**it).*func)(*it_v);
281 void add(MemberSharedPtr t){
282 elements.push_back(t);
291 void start() { this->call(&T::start); }
292 void stop() { this->call(&T::stop); }
293 void reset() { this->call(&T::reset); }
306 virtual SyncLayerSharedPtr getSync(
const SyncProperties &properties) = 0;
321 template <
typename T> T
get_optional(
const std::string &n,
const T& def)
const {
323 if(!getRepr(n, repr)){
326 return boost::lexical_cast<T>(repr);
328 template <
typename T>
bool get(
const std::string &n, T& val)
const {
330 if(!getRepr(n, repr))
return false;
331 val = boost::lexical_cast<T>(repr);
336 virtual bool getRepr(
const std::string &n, std::string & repr)
const = 0;
static RPDOSharedPtr create(const can::CommInterfaceSharedPtr interface, const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
boost::shared_ptr< SyncCounter > SyncCounterSharedPtr
boost::shared_ptr< Buffer > BufferSharedPtr
const SyncProperties properties
ObjectStorage::Entry< ObjectStorage::DataType< ObjectDict::DEFTYPE_UNSIGNED16 >::type > heartbeat_
const can::CommInterfaceSharedPtr interface_
const ObjectDict::Entry & desc() const
ObjectStorage::Entry< uint8_t > num_errors_
SyncCounter(const SyncProperties &p)
boost::shared_ptr< T > MemberSharedPtr
const can::Header header_
can::FrameListenerConstSharedPtr listener_
FrameOverlay(const Header &h)
boost::atomic< bool > has_error_
can::BufferedReader reader_
StateListenerConstSharedPtr addStateListener(const StateDelegate &s)
bool operator==(const SyncProperties &p) const
RPDO(const can::CommInterfaceSharedPtr interface)
boost::array< value_type, 8 > data
StateListener::ListenerConstSharedPtr StateListenerConstSharedPtr
void call(void(T::*func)(V &), std::vector< V > &vs)
boost::shared_ptr< CommInterface > CommInterfaceSharedPtr
const can::CommInterfaceSharedPtr interface_
boost::shared_ptr< TPDO > TPDOSharedPtr
can::Listener< const StateDelegate, const State & > StateListener
can::FrameListenerConstSharedPtr emcy_listener_
boost::chrono::high_resolution_clock::time_point time_point
const SyncCounterSharedPtr sync_
boost::chrono::high_resolution_clock::duration time_duration
SyncLayer(const SyncProperties &p)
const can::CommInterfaceSharedPtr interface_
const std::vector< typename Chain< T >::MemberSharedPtr > & getElements()
boost::shared_ptr< Node > NodeSharedPtr
ObjectDict::ObjectDictSharedPtr ObjectDictSharedPtr
const ObjectStorageSharedPtr getStorage()
std::vector< BufferSharedPtr > buffers
FrameOverlay(const can::Frame &f)
const canopen::ObjectDict::Entry * current_entry
std::vector< MemberSharedPtr > elements
void call(void(T::*func)(const V &), const std::vector< V > &vs)
const can::CommInterfaceSharedPtr interface_
boost::chrono::high_resolution_clock::time_point heartbeat_timeout_
uint8_t transmission_type
CommInterface::FrameListenerConstSharedPtr FrameListenerConstSharedPtr
fastdelegate::FastDelegate1< const State & > StateDelegate
uint16_t getHeartbeatInterval()
boost::shared_ptr< Master > MasterSharedPtr
std::vector< char > buffer
SyncProperties(const can::Header &h, const uint16_t &p, const uint8_t &o)
const ObjectStorageSharedPtr storage_
const can::CommInterfaceSharedPtr interface_
void call(void(T::*func)(void))
can::FrameListenerConstSharedPtr nmt_listener_
Master::MasterSharedPtr MasterSharedPtr
void setHeartbeatInterval()
ObjectStorage::Entry< uint8_t > error_register_
static TPDOSharedPtr create(const can::CommInterfaceSharedPtr interface, const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
boost::condition_variable cond
boost::unordered_set< TPDO::TPDOSharedPtr > tpdos_
boost::shared_ptr< const Listener > ListenerConstSharedPtr
TPDO(const can::CommInterfaceSharedPtr interface)
T get_optional(const std::string &n, const T &def) const
time_point get_abs_time(const time_duration &timeout)
boost::shared_ptr< SyncLayer > SyncLayerSharedPtr
const uint16_t period_ms_
boost::shared_ptr< RPDO > RPDOSharedPtr
void add(MemberSharedPtr t)
ObjectStorage::ObjectStorageSharedPtr ObjectStorageSharedPtr
can::SimpleDispatcher< StateListener > state_dispatcher_
const ObjectStorageSharedPtr storage_
SDOClient(const can::CommInterfaceSharedPtr interface, const ObjectDictSharedPtr dict, uint8_t node_id)
boost::unordered_set< RPDO::RPDOSharedPtr > rpdos_