Include new signals.xpp files to the compilation
[apps/agl-service-can-low-level.git] / src / openxc-utils.cpp
index 5f001d4..40745a0 100644 (file)
  * limitations under the License.
  */
 
-#include <string>
-#include <json-c/json.h>
-#include <sys/timeb.h>
-
-#include "openxc.pb.h"
 #include "openxc-utils.hpp"
 
 openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type type, const openxc_SimpleMessage& message)
@@ -72,6 +67,8 @@ openxc_DynamicField build_DynamicField(const std::string& value)
        d.type = openxc_DynamicField_Type_STRING;
        
        d.has_string_value = true;
+       d.has_numeric_value = false;
+       d.has_boolean_value = false;
        ::strncpy(d.string_value, value.c_str(), 100);
        
        return d;
@@ -83,7 +80,9 @@ openxc_DynamicField build_DynamicField(double value)
        d.has_type = true;
        d.type = openxc_DynamicField_Type_NUM;
        
+       d.has_string_value = false;
        d.has_numeric_value = true;
+       d.has_boolean_value = false;
        d.numeric_value = value;
        
        return d;
@@ -95,12 +94,23 @@ openxc_DynamicField build_DynamicField(bool value)
        d.has_type = true;
        d.type = openxc_DynamicField_Type_BOOL;
        
+       d.has_string_value = false;
+       d.has_numeric_value = false;
        d.has_boolean_value = true;
        d.boolean_value = value;
        
        return d;
 }
 
+openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg)
+{
+       if (v_msg.has_simple_message)
+               return v_msg.simple_message;
+       
+       openxc_SimpleMessage s_msg = { false, "", false, build_DynamicField(false), false, build_DynamicField(false)};
+       return s_msg;
+}
+
 void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value)
 {
        if(field.has_numeric_value)
@@ -111,22 +121,14 @@ void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value)
                json_object_object_add(value, "value", json_object_new_string(field.string_value));
 }
 
-openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg)
+bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json)
 {
-       if (v_msg.has_simple_message)
-               return v_msg.simple_message;
-}
-
-json_object* jsonify_simple(const openxc_SimpleMessage& s_msg)
-{
-       json_object *json;
-       json = nullptr;
-
        if(s_msg.has_name)
        {
-               json = json_object_new_object();
                json_object_object_add(json, "name", json_object_new_string(s_msg.name));
                jsonify_DynamicField(s_msg.value, json);
+               return true;
        }
-       return json;
+       json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));
+       return false;
 }
\ No newline at end of file