summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-15 23:18:33 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:21:57 +0100
commitf886559f8a8ac1dadf4942ab2c993a6db4f53d2b (patch)
treee02a953f571bbb1d73ee861f9e1142cedd32f55d /src
parent0a9f3524f442ff055fb1075f92bd85f9b4522910 (diff)
Ease use of openXC structures.
Add some helpers functions used to check VehicleMessage validity or build default VehicleMessage struct. Change-Id: Ia1cca8b4cb3dd70a739d0f2ee9165b72fdac48d4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/utils/openxc-utils.cpp27
-rw-r--r--src/utils/openxc-utils.hpp2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/utils/openxc-utils.cpp b/src/utils/openxc-utils.cpp
index 8449acc7..ae15f4df 100644
--- a/src/utils/openxc-utils.cpp
+++ b/src/utils/openxc-utils.cpp
@@ -109,6 +109,33 @@ openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message)
}
/**
+ * @brief Build an empty VehicleMessage that isn't usable by at least the struct
+ * is initialized for the most part and can be use to check a false return value.
+ *
+ * @return A VehicleMessage with all boolean value to false.
+ */
+openxc_VehicleMessage build_VehicleMessage()
+{
+ openxc_VehicleMessage v;
+
+ ::memset(&v, 0, sizeof(openxc_VehicleMessage));
+ return v;
+}
+
+bool is_valid(const openxc_VehicleMessage& v)
+{
+ if (v.has_type == false &&
+ v.has_can_message == false &&
+ v.has_simple_message == false &&
+ v.has_diagnostic_response == false &&
+ v.has_control_command == false &&
+ v.has_command_response == false &&
+ v.has_timestamp == false)
+ return false;
+ return true;
+}
+
+/**
* @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField
*
* @param[in] name - const string reference name to assign to the created SimpleMessage
diff --git a/src/utils/openxc-utils.hpp b/src/utils/openxc-utils.hpp
index c51fd3ad..f9ccf793 100644
--- a/src/utils/openxc-utils.hpp
+++ b/src/utils/openxc-utils.hpp
@@ -27,6 +27,8 @@
openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value);
openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message);
+openxc_VehicleMessage build_VehicleMessage();
+bool is_valid(const openxc_VehicleMessage& v);
openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
openxc_DynamicField build_DynamicField(const std::string& value);