summaryrefslogtreecommitdiffstats
path: root/src/openxc-utils.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-21 17:16:59 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-22 12:15:12 +0100
commitcddc9c28e3e1a242e55f68c9971d0710ada30e9f (patch)
tree007eff68d56578400ed2ce39b9eec7cbfe7d6850 /src/openxc-utils.cpp
parentc535c3bb2d73327772c1bb72c9fcca3f8a7f8204 (diff)
Fix: decoder_t class decodeSignal method signature
Change-Id: Id7ef4fe3b8d3f5b14fd447cf05865ba494862792 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/openxc-utils.cpp')
-rw-r--r--src/openxc-utils.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/openxc-utils.cpp b/src/openxc-utils.cpp
index bdc772e7..5f001d41 100644
--- a/src/openxc-utils.cpp
+++ b/src/openxc-utils.cpp
@@ -16,19 +16,26 @@
* 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)
{
struct timeb t_msec;
long long int timestamp_msec;
- openxc_VehicleMessage v = {0};
+ openxc_VehicleMessage v;
- if(!ftime(&t_msec))
+ if(!::ftime(&t_msec))
{
timestamp_msec = ((long long int) t_msec.time) * 1000ll +
(long long int) t_msec.millitm;
- v.has_type = true:
+ v.has_type = true;
v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
v.has_simple_message = true;
v.simple_message = message;
@@ -48,7 +55,7 @@ openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicFiel
openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value)
{
- openxc_SimpleMessage s = {0};
+ openxc_SimpleMessage s;
s.has_name = true;
::strncpy(s.name, name.c_str(), 100);
@@ -60,41 +67,41 @@ openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_D
openxc_DynamicField build_DynamicField(const std::string& value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_STRING;
d.has_string_value = true;
- ::strncpy(d.string_value, value.c_tr(), 100);
+ ::strncpy(d.string_value, value.c_str(), 100);
return d;
}
openxc_DynamicField build_DynamicField(double value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_NUM;
d.has_numeric_value = true;
- d.numeric_value = field;
+ d.numeric_value = value;
return d;
}
openxc_DynamicField build_DynamicField(bool value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_BOOL;
d.has_boolean_value = true;
- d.boolean_value = field;
+ d.boolean_value = value;
return d;
}
-void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& value)
+void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value)
{
if(field.has_numeric_value)
json_object_object_add(value, "value", json_object_new_double(field.numeric_value));
@@ -102,25 +109,24 @@ void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& v
json_object_object_add(value, "value", json_object_new_boolean(field.boolean_value));
else if(field.has_string_value)
json_object_object_add(value, "value", json_object_new_string(field.string_value));
-
- return value;
}
openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg)
{
- return v_msg.has_simple_message ? v_msg.simple_message : {0};
+ if (v_msg.has_simple_message)
+ return v_msg.simple_message;
}
-json_object jsonify_simple(const openxc_SimpleMessage& s_msg)
+json_object* jsonify_simple(const openxc_SimpleMessage& s_msg)
{
json_object *json;
json = nullptr;
- if(s_msg->has_name)
+ 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);
+ json_object_object_add(json, "name", json_object_new_string(s_msg.name));
+ jsonify_DynamicField(s_msg.value, json);
}
return json;
} \ No newline at end of file