converter : Add "0x" for hex data
[apps/agl-service-can-low-level.git] / low-can-binding / utils / converter.cpp
index c6c2f5e..56f3a44 100644 (file)
 #include <climits>
 
 /**
- * @brief Convert hex data to string
+ * @brief Convert data to hex string
  *
  * @param data An array of data
  * @param length The length of the data
- * @return std::string The string data
+ * @return std::string The hex string
  */
 std::string converter_t::to_hex(const uint8_t data[], const size_t length)
 {
        std::stringstream stream;
        stream << std::hex << std::setfill('0');
+       stream << "0x";
        for(int i = 0; i < length; i++)
                stream << std::setfill('0') << std::setw(2) << std::hex << ((int) data[i]);
 
        return stream.str();
 }
 
+/**
+ * @brief Convert data to ascii string
+ *
+ * @param data An array of data
+ * @param length The length of the data
+ * @return std::string The ascii string
+ */
+std::string converter_t::to_ascii(const uint8_t data[], const size_t length)
+{
+       std::stringstream stream;
+       for(int i = 0; i < length; i++)
+               stream << ((char) data[i]);
+       return stream.str();
+}
+
 /**
  * @brief Translate bit_position and bit_size
  *
@@ -84,5 +100,5 @@ uint32_t converter_t::bit_position_swap(unsigned int msg_length, unsigned int bi
  */
 uint32_t converter_t::continental_bit_position_mess(unsigned int msg_length, unsigned int bit_position, unsigned int bit_size)
 {
-       return bit_position + (CHAR_BIT - bit_position % CHAR_BIT) - bit_size;
+       return bit_position + CHAR_BIT - 2 * (bit_position % CHAR_BIT) - bit_size;
 }