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


sr_ronex_utilities
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Thu Jun 6 2019 21:21:58