Ease use of openXC structures.
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 15 Mar 2017 22:18:33 +0000 (23:18 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:21:57 +0000 (17:21 +0100)
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>
src/utils/openxc-utils.cpp
src/utils/openxc-utils.hpp

index 8449acc..ae15f4d 100644 (file)
@@ -108,6 +108,33 @@ openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message)
        return v;
 }
 
+/**
+ * @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
  *
index c51fd3a..f9ccf79 100644 (file)
@@ -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);