sr_edc.h
Go to the documentation of this file.
00001 
00032 #ifndef SR_EDC_H
00033 #define SR_EDC_H
00034 
00035 #include <ethercat_hardware/ethercat_device.h>
00036 #include <sr_edc_ethercat_drivers/sr0x.h>
00037 #include <realtime_tools/realtime_publisher.h>
00038 #include <std_msgs/Int16.h>
00039 #include <std_msgs/Float64MultiArray.h>
00040 #include <sr_robot_msgs/SimpleMotorFlasher.h>
00041 #include <pthread.h>
00042 #include <bfd.h>
00043 #include <boost/smart_ptr.hpp>
00044 #include <map>
00045 #include <boost/assign.hpp>
00046 #include <boost/algorithm/string.hpp>
00047 #include <boost/algorithm/string/find_iterator.hpp>
00048 
00049 //#include <sr_robot_lib/sr_hand_lib.hpp>
00050 
00051 #include <sr_robot_msgs/EthercatDebug.h>
00052 
00053 #include <sr_external_dependencies/types_for_external.h>
00054 extern "C"
00055 {
00056   #include <sr_external_dependencies/external/common/ethercat_can_bridge_protocol.h>
00057   #include <sr_external_dependencies/external/common/common_edc_ethercat_protocol.h>
00058 }
00059 
00060 
00061 class SrEdc : public SR0X
00062 {
00063 public:
00064   SrEdc();
00065   virtual ~SrEdc();
00066 
00067   virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address);
00068   virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address, unsigned int ethercat_command_data_size, unsigned int ethercat_status_data_size, unsigned int ethercat_can_bridge_data_size,
00069                                                  unsigned int ethercat_command_data_address, unsigned int ethercat_status_data_address, unsigned int ethercat_can_bridge_data_command_address, unsigned int ethercat_can_bridge_data_status_address);
00070   virtual int  initialize(pr2_hardware_interface::HardwareInterface *hw, bool allow_unprogrammed=true);
00071 
00072   bool simple_motor_flasher(sr_robot_msgs::SimpleMotorFlasher::Request &req, sr_robot_msgs::SimpleMotorFlasher::Response &res);
00073   void build_CAN_message(ETHERCAT_CAN_BRIDGE_DATA *message);
00074   bool can_data_is_ack(ETHERCAT_CAN_BRIDGE_DATA * packet);
00075   void erase_flash();
00076   //bool read_flash(unsigned int offset, unsigned char baddrl, unsigned char baddrh, unsigned char baddru);
00077   bool read_flash(unsigned int offset, unsigned int baddr);
00078 
00079 protected:
00080   int                                                                  counter_;
00081   ros::NodeHandle                                                      nodehandle_;
00082 
00083   typedef realtime_tools::RealtimePublisher<std_msgs::Int16> rt_pub_int16_t;
00084   std::vector< boost::shared_ptr<rt_pub_int16_t> >   realtime_pub_;
00085 
00087   boost::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float64MultiArray> > extra_analog_inputs_publisher;
00088 
00089   bool                             flashing;
00090   bool                             can_packet_acked;
00091 
00093   virtual void reinitialize_boards() = 0;
00094 
00103   virtual void get_board_id_and_can_bus(int board_id, int *can_bus, unsigned int *board_can_id) = 0;
00104 private:
00105 
00106   //static const unsigned int        nb_sensors_const;
00107   static const unsigned int        max_retry;
00108   //static const unsigned short int  max_iter_const;
00109   //static const unsigned short int  ros_pub_freq_const;
00110   //static const unsigned short int  device_pub_freq_const;
00111   //static const unsigned char       nb_publish_by_unpack_const;
00112   //std::string                      firmware_file_name;
00113   pthread_mutex_t                  producing;
00114   ros::ServiceServer               serviceServer;
00115 
00116 
00117   ETHERCAT_CAN_BRIDGE_DATA         can_message_;
00118   bool                            can_message_sent;
00119   bfd_byte                        *binary_content; // buffer containing the binary content to be flashed
00120   unsigned int                     pos; // position in binary_content buffer
00121   unsigned int                     motor_being_flashed;
00122 
00123 
00125   int can_bus_;
00126 
00138   void send_CAN_msg(int8u can_bus, int16u msg_id, int8u msg_length, int8u msg_data[], int timeout, bool *timedout);
00139 
00148   bool read_back_and_check_flash(unsigned int baddr, unsigned int total_size);
00149 
00163   void find_address_range(bfd *fd, unsigned int *smallest_start_address, unsigned int *biggest_end_address);
00164 
00174   bool read_content_from_object_file(bfd *fd, bfd_byte *content, unsigned int base_addr);
00175 
00184   bool write_flash_data(unsigned int base_addr, unsigned int total_size);
00185 
00193   static inline std::string get_filename( std::string full_path )
00194   {
00195     std::vector<std::string> splitted_string;
00196     boost::split(splitted_string, full_path, boost::is_any_of("/"));
00197     return splitted_string.back();
00198   }
00199 
00200 };
00201 
00202 
00203 /* For the emacs weenies in the crowd.
00204 Local Variables:
00205    c-basic-offset: 2
00206 End:
00207 */
00208 
00209 
00210 #endif /* SR_EDC_H */


sr_edc_ethercat_drivers
Author(s): Ugo Cupcic, Yann Sionneau, Toni Oliver
autogenerated on Thu Aug 27 2015 15:16:54