26 #include <boost/shared_ptr.hpp> 31 namespace canopen_schunk{
58 const size_t T_size =
sizeof(T) * 8;
59 std::bitset<T_size> bs(num);
93 const std::string& category =
"error_codes");
103 template <
typename T>
106 std::vector<uint8_t> out_vec;
107 if (boost::is_fundamental<T>::value)
110 size_t num_bytes =
sizeof(T);
115 std::memcpy(&cast_int, &value, num_bytes);
116 for (
size_t i = 0; i < num_bytes; ++i)
118 int32_t unary = cast_int & full_byte;
119 out_vec.push_back(static_cast<uint8_t>( unary >> i*8));
120 full_byte = full_byte << 8;
125 LOGGING_ERROR (CanOpen,
"The given data is too large. The maximum datatype size is 4 bytes." <<
endl);
126 throw std::bad_cast();
131 LOGGING_ERROR (CanOpen,
"Only fundamental datatypes can be casted with the help of " <<
"this function. Fundamental types include integral, floating point and void types." <<
endl);
132 throw std::bad_cast();
146 template <
typename T>
150 size_t num_bytes =
sizeof(T);
151 if (boost::is_fundamental<T>::value && vec.size() == num_bytes)
153 std::memcpy(&ret_val, &vec[0], num_bytes);
157 LOGGING_ERROR (CanOpen,
"Only fundamental datatypes can be casted with the help of " <<
"this function. Fundamental types include integral, floating point and void types." <<
endl);
158 throw std::bad_cast();
std::string hexArrayToString(const unsigned char *msg, const uint8_t length)
Transforms an array of unsigned chars into a string of Hex representations of those chars...
std::vector< uint8_t > convertToCharVector(const T value)
This little helper transforms any datatype that has a size of at most 4 Bytes into a vector of uint8_...
boost::shared_ptr< CanOpenReceiveThread > CanOpenReceiveThreadPtr
#define LOGGING_ERROR(streamname, arg)
unsigned __int64 uint64_t
boost::shared_ptr< icl_hardware::can::tCanDevice > CanDevPtr
ThreadStream & endl(ThreadStream &stream)
T convertFromCharVector(const std::vector< uint8_t > &vec)
This converts a vector of uint8_t entries into another datatype with a matching byte length...
std::string binaryString(const uint64_t num)
std::map< uint32_t, std::string > getErrorMapFromConfigFile(const std::string &filename, const std::string &category)
Creates an error map from a given INI file.
std::string sanitizeString(const std::string &text)
This function removes all non-graphical characters from the given string.
std::string hexToString(const uint64_t num)
Converts a hexadecimal number into its string representation 0xXX.
icl_hardware::can::tCanMessage CanMsg