* 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)
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;
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;
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)
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