Smalls improvements
[apps/agl-service-can-low-level.git] / low-can-binding / utils / openxc-utils.cpp
index 35b7d9c..c06beab 100644 (file)
@@ -34,6 +34,7 @@
 const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value)
 {
        openxc_VehicleMessage message;
+       ::memset(&message, 0, sizeof(message));
        application_t& app = application_t::instance();
 
        message.has_type = true;
@@ -98,6 +99,7 @@ const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* re
 const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message, uint64_t timestamp)
 {
        openxc_VehicleMessage v;
+       ::memset(&v, 0, sizeof(v));
 
        v.has_type = true,
        v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
@@ -120,6 +122,7 @@ const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& mes
 const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message)
 {
        openxc_VehicleMessage v;
+       ::memset(&v, 0, sizeof(v));
 
        v.has_type = true,
        v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
@@ -141,7 +144,7 @@ openxc_VehicleMessage build_VehicleMessage()
 {
        openxc_VehicleMessage v;
 
-       ::memset(&v, 0, sizeof(openxc_VehicleMessage));
+       ::memset(&v, 0, sizeof(v));
        return v;
 }
 
@@ -181,6 +184,32 @@ const openxc_SimpleMessage build_SimpleMessage(const std::string& name, const op
        return s;
 }
 
+/// @brief Build an openxc_DynamicField with a json object
+///
+/// @param[in] value - const json_object pointer to assign to convert in an
+///  openxc_DynamicField.
+///
+/// @return openxc_DynamicField initialized with a json object.
+///
+const openxc_DynamicField build_DynamicField(json_object* value)
+{
+       switch(json_object_get_type(value))
+       {
+               case json_type_string:
+                       return build_DynamicField(json_object_get_string(value));
+               case json_type_double:
+                       return build_DynamicField(json_object_get_double(value));
+               case json_type_int:
+                       return build_DynamicField(json_object_get_double(value));
+               case json_type_boolean:
+                       return build_DynamicField((bool)json_object_get_boolean(value));
+               default:
+                       openxc_DynamicField d;
+                       ::memset(&d, 0, sizeof(openxc_DynamicField));
+                       return d;
+       }
+}
+
 ///
 /// @brief Build an openxc_DynamicField with a string value
 ///
@@ -366,7 +395,7 @@ bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, json_object* json)
        {
                if(v_msg.has_timestamp)
                {
-                       json_object_object_add(json, "timestamp", json_object_new_double(v_msg.timestamp));
+                       json_object_object_add(json, "timestamp", json_object_new_int64(v_msg.timestamp));
                        return true;
                }
                return true;