aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils/openxc-utils.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-13 11:14:01 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-09-13 11:15:48 +0200
commite08e9bc89e78b3937f84a8dbf47968159521a7ea (patch)
tree6bb98523c173ce7c75c1e41bbcb0ed2caed90ddc /low-can-binding/utils/openxc-utils.cpp
parent05d31a77fb2742d4aedd26a13454b21b5df83b20 (diff)
Add timestamp val to returned json object on event
Change-Id: Ibfb514eb27c0378dba7e302755e5f6f95b0ca242 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/utils/openxc-utils.cpp')
-rw-r--r--low-can-binding/utils/openxc-utils.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp
index 3b404f09..35b7d9c9 100644
--- a/low-can-binding/utils/openxc-utils.cpp
+++ b/low-can-binding/utils/openxc-utils.cpp
@@ -349,3 +349,28 @@ bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json)
json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));
return false;
}
+
+///
+/// @brief Make a JSON object from a VehicleMessage
+///
+/// @param[in] v_msg - const reference to an openxc_VehicleMessage
+/// struct to convert into a json object.
+/// @param[out] json - pointer with the DynamicField converted into json object
+///
+/// @return True if VehicleMessage has been transformed into json object
+/// and false if not. In such case, a json object is returned { "error": "error msg"}
+///
+bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, json_object* json)
+{
+ if(jsonify_simple(get_simple_message(v_msg), json))
+ {
+ if(v_msg.has_timestamp)
+ {
+ json_object_object_add(json, "timestamp", json_object_new_double(v_msg.timestamp));
+ return true;
+ }
+ return true;
+ }
+ json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));
+ return false;
+}