summaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-08-27 15:40:55 +0200
committerArthur Guyader <arthur.guyader@iot.bzh>2019-08-30 15:41:22 +0200
commit491c4d4d0bc418c1fbc6e3a1af8093e4049d8b87 (patch)
tree0e3ce68915a5c6a8104d888249afbce6e6d7b0e6 /low-can-binding/utils
parent96232f8f7cf8b93f1a3ef3ed9a4816c575cefe87 (diff)
Add new decoders bytes for signal of long size
This commit adds the decoder bytes. It allows to return a sequence of bytes in hexadecimal form. Bug-AGL : SPEC-2780 Change-Id: I27180774f044c48a9d7baa2739b15a2e85b8b2e2 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh>
Diffstat (limited to 'low-can-binding/utils')
-rw-r--r--low-can-binding/utils/openxc-utils.cpp54
-rw-r--r--low-can-binding/utils/openxc-utils.hpp1
2 files changed, 54 insertions, 1 deletions
diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp
index c06beabb..db19d1f3 100644
--- a/low-can-binding/utils/openxc-utils.cpp
+++ b/low-can-binding/utils/openxc-utils.cpp
@@ -17,9 +17,10 @@
*/
#include "openxc-utils.hpp"
-
+#include "converter.hpp"
#include "../binding/application.hpp"
+
///
/// @brief Build a specific VehicleMessage containing a DiagnosticResponse.
///
@@ -210,6 +211,40 @@ const openxc_DynamicField build_DynamicField(json_object* value)
}
}
+const openxc_DynamicField build_DynamicField(std::vector<uint8_t> &array)
+{
+ openxc_DynamicField d;
+ d.has_type = true;
+ d.type = openxc_DynamicField_Type_BYTES;
+
+ d.has_string_value = false;
+ d.has_numeric_value = false;
+ d.has_boolean_value = false;
+ d.has_bytes_value = true;
+
+
+ size_t size = array.size();
+
+ if(size > 2040)
+ {
+ AFB_ERROR("Error to generate array dynamic field, too large data");
+ return d;
+ }
+ else
+ {
+ d.length_array = (uint32_t) size;
+ }
+
+
+ for(int i=0;i<size;i++)
+ {
+ d.bytes_value[i] = array[i];
+ }
+
+ return d;
+}
+
+
///
/// @brief Build an openxc_DynamicField with a string value
///
@@ -227,6 +262,7 @@ const openxc_DynamicField build_DynamicField(const char* value)
d.has_string_value = true;
d.has_numeric_value = false;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
::strncpy(d.string_value, value, 100);
return d;
@@ -249,6 +285,7 @@ const openxc_DynamicField build_DynamicField(const std::string& value)
d.has_string_value = true;
d.has_numeric_value = false;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
::strncpy(d.string_value, value.c_str(), 100);
return d;
@@ -272,6 +309,7 @@ const openxc_DynamicField build_DynamicField(double value)
d.has_string_value = false;
d.has_numeric_value = true;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
d.numeric_value = value;
return d;
@@ -293,8 +331,10 @@ const openxc_DynamicField build_DynamicField(bool value)
d.has_string_value = false;
d.has_numeric_value = false;
d.has_boolean_value = true;
+ d.has_bytes_value = false;
d.boolean_value = value;
+
return d;
}
@@ -350,11 +390,23 @@ const openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg
void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value)
{
if(field.has_numeric_value)
+ {
json_object_object_add(value, "value", json_object_new_double(field.numeric_value));
+ }
else if(field.has_boolean_value)
+ {
json_object_object_add(value, "value", json_object_new_boolean(field.boolean_value));
+ }
else if(field.has_string_value)
+ {
json_object_object_add(value, "value", json_object_new_string(field.string_value));
+ }
+ else if(field.has_bytes_value)
+ {
+ std::string s = converter_t::to_hex(field.bytes_value,field.length_array);
+
+ json_object_object_add(value, "value", json_object_new_string(s.c_str()));
+ }
}
///
diff --git a/low-can-binding/utils/openxc-utils.hpp b/low-can-binding/utils/openxc-utils.hpp
index a84bc350..61f365b0 100644
--- a/low-can-binding/utils/openxc-utils.hpp
+++ b/low-can-binding/utils/openxc-utils.hpp
@@ -37,6 +37,7 @@ const openxc_DynamicField build_DynamicField(const char* value);
const openxc_DynamicField build_DynamicField(const std::string& value);
const openxc_DynamicField build_DynamicField(double value);
const openxc_DynamicField build_DynamicField(bool value);
+const openxc_DynamicField build_DynamicField(std::vector<uint8_t> &array);
int get_bool_from_DynamicField(const openxc_VehicleMessage& v_msg, bool& ret);
double get_numerical_from_DynamicField(const openxc_VehicleMessage& v_msg);