00001 /* 00002 * Copyright (c) 2013, Shadow Robot Company, All rights reserved. 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 3.0 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library. 00016 */ 00017 00024 #ifndef _SR_SPI_HPP_ 00025 #define _SR_SPI_HPP_ 00026 00027 #include <ros_ethercat_hardware/ethercat_device.h> 00028 #include <realtime_tools/realtime_publisher.h> 00029 #include <sr_ronex_msgs/SPIState.h> 00030 00031 #include <sr_ronex_external_protocol/Ronex_Protocol_0x02000002_SPI_00.h> 00032 #include <sr_ronex_hardware_interface/spi_hardware_interface.hpp> 00033 00034 #include <boost/ptr_container/ptr_vector.hpp> 00035 #include <boost/scoped_ptr.hpp> 00036 #include <vector> 00037 #include <string> 00038 00039 class SrSPI : public EthercatDevice 00040 { 00041 public: 00042 virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address); 00043 virtual int initialize(hardware_interface::HardwareInterface *hw, bool allow_unprogrammed = true); 00044 00045 SrSPI(); 00046 virtual ~SrSPI(); 00047 00048 protected: 00050 static const char product_alias_[]; 00051 00053 std::string ronex_id_; 00054 00055 std::string reason_; 00056 int level_; 00057 00058 int command_base_; 00059 int status_base_; 00060 00061 ros::NodeHandle node_; 00062 00064 ronex::SPI* spi_; 00065 00070 int16_t cycle_count_; 00071 00073 int32u digital_commands_; 00074 00076 std::string device_name_; 00077 std::string serial_number_; 00078 00080 int device_offset_; 00081 00083 std::vector<bool> input_mode_; 00084 00085 void packCommand(unsigned char *buffer, bool halt, bool reset); 00086 bool unpackState(unsigned char *this_buffer, unsigned char *prev_buffer); 00087 00088 void diagnostics(diagnostic_updater::DiagnosticStatusWrapper &d, unsigned char *buffer); 00089 00091 boost::scoped_ptr<realtime_tools::RealtimePublisher<sr_ronex_msgs::SPIState> > state_publisher_; 00093 sr_ronex_msgs::SPIState state_msg_; 00094 00096 void build_topics_(); 00097 00099 int parameter_id_; 00100 }; 00101 00102 /* For the emacs weenies in the crowd. 00103 Local Variables: 00104 c-basic-offset: 2 00105 End: 00106 */ 00107 00108 #endif /* _SR_SPI_HPP_ */