sr_ronex_utilities.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 #pragma once
00026 
00027 #include <sstream>
00028 #include <bitset>
00029 #include <ros/ros.h>
00030 #include <boost/lexical_cast.hpp>
00031 
00032 namespace ronex
00033 {
00042   static inline bool check_bit(uint16_t data, size_t index)
00043   {
00044     // x8 because sizeof returns size in bytes not bits
00045     return std::bitset<sizeof(uint16_t)*8>(data).test(index);
00046   }
00047 
00055   static inline void set_bit(uint32_t &data, size_t index, bool value)
00056   {
00057     //x8 because sizeof returns size in bytes not bits
00058     std::bitset<sizeof(uint32_t)*8> tmp(data);
00059     tmp.set(index, value);
00060     data = static_cast<uint32_t>(tmp.to_ulong());
00061   }
00062 
00070   static inline void set_bit(uint16_t &data, size_t index, bool value)
00071   {
00072     //x8 because sizeof returns size in bytes not bits
00073     std::bitset<sizeof(uint16_t)*8> tmp(data);
00074     tmp.set(index, value);
00075     data = static_cast<uint16_t>(tmp.to_ulong());
00076   }
00077 
00096   static inline int get_ronex_param_id(std::string ronex_id)
00097   {
00098     std::string param;
00099 
00100     int ronex_parameter_id = 0;
00101     while( true )
00102     {
00103       std::stringstream ss;
00104       ss << "/ronex/devices/" << ronex_parameter_id << "/ronex_id";
00105       if(ros::param::get(ss.str(), param) )
00106       {
00107         if( ronex_id.compare("") != 0 )
00108         {
00109           if( ronex_id.compare(param) == 0)
00110           {
00111             return ronex_parameter_id;
00112           }
00113         }
00114         ++ronex_parameter_id;
00115       }
00116       else
00117       {
00118         if( ronex_id.compare("") != 0)
00119         {
00120           //we were looking for a specific ronex and didn't find it -> return -1
00121           return -1;
00122         }
00123         return ronex_parameter_id;
00124       }
00125     }
00126 
00127     return -1;
00128   }
00129 
00137    static inline std::string get_ronex_devices_string(int ronex_parameter_id, std::string part)
00138    {
00139      std::string key("/ronex/devices/");
00140      key += boost::lexical_cast<std::string>(ronex_parameter_id);
00141      key += "/";
00142      key += part;
00143      return key;
00144    }
00145 }
00146 
00147 /* For the emacs weenies in the crowd.
00148    Local Variables:
00149    c-basic-offset: 2
00150    End:
00151 */


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