spi_hardware_interface.hpp
Go to the documentation of this file.
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 
00025 #ifndef _SPI_HARDWARE_INTERFACE_H_
00026 #define _SPI_HARDWARE_INTERFACE_H_
00027 
00028 #include <ros_ethercat_model/hardware_interface.hpp>
00029 #include <sr_ronex_external_protocol/Ronex_Protocol_0x02000002_SPI_00.h>
00030 #include <vector>
00031 #include <sr_ronex_utilities/sr_ronex_utilities.hpp>
00032 
00033 namespace ronex
00034 {
00045   class SPI
00046     : public ros_ethercat_model::CustomHW
00047   {
00048   public:
00049     SPI()
00050     {
00051       state_.reset(new RONEX_STATUS_02000002());
00052       command_.reset(new RONEX_COMMAND_02000002());
00053     }
00054 
00055     boost::shared_ptr<RONEX_STATUS_02000002> state_;
00056     boost::shared_ptr<RONEX_COMMAND_02000002> command_;
00057 
00058     inline void nullify_command(size_t spi_index)
00059     {
00060       command_->command_type = RONEX_COMMAND_02000002_COMMAND_TYPE_NORMAL;
00061 
00062       //set allocated CS pins to high (pre and post)
00063       switch( spi_index )
00064       {
00065       case 0:
00066         command_->pin_output_states_pre |= PIN_OUTPUT_STATE_CS_0;
00067         command_->pin_output_states_post |= PIN_OUTPUT_STATE_CS_0;
00068         break;
00069 
00070       case 1:
00071         command_->pin_output_states_pre |= PIN_OUTPUT_STATE_CS_1;
00072         command_->pin_output_states_post |= PIN_OUTPUT_STATE_CS_1;
00073         break;
00074 
00075       case 2:
00076         command_->pin_output_states_pre |= PIN_OUTPUT_STATE_CS_2;
00077         command_->pin_output_states_post |= PIN_OUTPUT_STATE_CS_2;
00078         break;
00079 
00080       case 3:
00081         command_->pin_output_states_pre |= PIN_OUTPUT_STATE_CS_3;
00082         command_->pin_output_states_post |= PIN_OUTPUT_STATE_CS_3;
00083         break;
00084       }
00085 
00086       //setting num bytes to 0 for each SPI outputs
00087       command_->spi_out[spi_index].num_bytes = 0;
00088     };
00089   };
00090 }
00091 /* For the emacs weenies in the crowd.
00092 Local Variables:
00093    c-basic-offset: 2
00094 End:
00095 */
00096 
00097 #endif /* _SPI_HARDWARE_INTERFACE_H_ */


sr_ronex_hardware_interface
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Fri Aug 28 2015 13:12:17