summaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils
diff options
context:
space:
mode:
Diffstat (limited to 'low-can-binding/utils')
-rw-r--r--low-can-binding/utils/converter.cpp19
-rw-r--r--low-can-binding/utils/converter.hpp1
2 files changed, 18 insertions, 2 deletions
diff --git a/low-can-binding/utils/converter.cpp b/low-can-binding/utils/converter.cpp
index c6c2f5e1..56625742 100644
--- a/low-can-binding/utils/converter.cpp
+++ b/low-can-binding/utils/converter.cpp
@@ -22,11 +22,11 @@
#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)
{
@@ -39,6 +39,21 @@ std::string converter_t::to_hex(const uint8_t data[], const size_t length)
}
/**
+ * @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
*
*
diff --git a/low-can-binding/utils/converter.hpp b/low-can-binding/utils/converter.hpp
index 45e29e9a..e8a40f5b 100644
--- a/low-can-binding/utils/converter.hpp
+++ b/low-can-binding/utils/converter.hpp
@@ -23,6 +23,7 @@ class converter_t
{
public:
static std::string to_hex(const uint8_t data[], const size_t length);
+ static std::string to_ascii(const uint8_t data[], const size_t length);
static void signal_to_bits_bytes(unsigned int bit_position,
unsigned int bit_size,
int &new_start_byte,