From: Romain Forlot <romain.forlot@iot.bzh>
Date: Thu, 1 Jun 2017 16:17:29 +0000 (+0200)
Subject: Methods to ease access to DynamicField members
X-Git-Tag: Renesas_delivery_Q2~44
X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=267e52aecd92ef7891725076bacba19d2167dac2;p=apps%2Flow-level-can-service.git

Methods to ease access to DynamicField members

Change-Id: I8974827340e3faf60a511900cbdcf117ce43fb53
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
---

diff --git a/CAN-binder/low-can-binding/utils/openxc-utils.cpp b/CAN-binder/low-can-binding/utils/openxc-utils.cpp
index 08f1c8a..1d3cd79 100644
--- a/CAN-binder/low-can-binding/utils/openxc-utils.cpp
+++ b/CAN-binder/low-can-binding/utils/openxc-utils.cpp
@@ -269,6 +269,26 @@ const openxc_DynamicField build_DynamicField(bool value)
 	return d;
 }
 
+int get_bool_from_DynamicField(const openxc_VehicleMessage& v_msg, bool* ret)
+{
+	if(v_msg.has_simple_message && v_msg.simple_message.has_value && v_msg.simple_message.value.has_boolean_value)
+		{*ret = v_msg.simple_message.value.boolean_value;}
+	else
+		{return -1;}
+}
+
+double get_numerical_from_DynamicField(const openxc_VehicleMessage& v_msg)
+{
+	return (v_msg.has_simple_message && v_msg.simple_message.has_value && v_msg.simple_message.value.has_numeric_value) ?
+		v_msg.simple_message.value.numeric_value : -1.0;
+}
+
+const std::string get_string_from_DynamicField(const openxc_VehicleMessage& v_msg)
+{
+return (v_msg.has_simple_message && v_msg.simple_message.has_value && v_msg.simple_message.value.has_string_value) ?
+		v_msg.simple_message.value.string_value : "";
+}
+
 ///
 /// @brief Extract the simple message value from an openxc_VehicleMessage
 ///  and return it. If there isn't SimpleMessage in the VehicleMessage then
diff --git a/CAN-binder/low-can-binding/utils/openxc-utils.hpp b/CAN-binder/low-can-binding/utils/openxc-utils.hpp
index 34ac3eb..83d6379 100644
--- a/CAN-binder/low-can-binding/utils/openxc-utils.hpp
+++ b/CAN-binder/low-can-binding/utils/openxc-utils.hpp
@@ -37,6 +37,9 @@ const openxc_DynamicField build_DynamicField(const std::string& value);
 const openxc_DynamicField build_DynamicField(double value);
 const openxc_DynamicField build_DynamicField(bool value);
 
+int get_bool_from_DynamicField(const openxc_VehicleMessage& v_msg, bool& ret);
+double get_numerical_from_DynamicField(const openxc_VehicleMessage& v_msg);
+const std::string get_string_from_DynamicField(const openxc_VehicleMessage& v_msg);
 const openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
 
 void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);