aboutsummaryrefslogtreecommitdiffstats
path: root/src/openxc-utils.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-22 13:06:24 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-22 15:28:12 +0100
commit836feaecd602e86ea6d954ae018a2d7bbc04aa7a (patch)
tree4bb43361e8fe8a58505a64fd50ade04000c18d60 /src/openxc-utils.cpp
parent747d58ad84d230f6cf11ac818bab65019df83611 (diff)
Change way to convert simplemessage into a json
object. Improve doxygen comments Change-Id: I794bdc10f9e1ce66ebd4e68dbd6e0c465e3ca5c4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/openxc-utils.cpp')
-rw-r--r--src/openxc-utils.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/openxc-utils.cpp b/src/openxc-utils.cpp
index cef86811..bbea968d 100644
--- a/src/openxc-utils.cpp
+++ b/src/openxc-utils.cpp
@@ -96,6 +96,15 @@ openxc_DynamicField build_DynamicField(bool 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)
@@ -106,25 +115,15 @@ 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;
-
- openxc_SimpleMessage s_msg = { true, "", false, build_DynamicField(false), false, build_DynamicField(false)};
- return s_msg;
-}
-
-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