diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-11-20 19:40:47 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-11-22 11:10:26 +0100 |
commit | 2daa033bd69b9ede497afa4355a5fdbb119895eb (patch) | |
tree | efcc773aab14a4e0bbddd445f951523bf7c406bd /low-can-binding | |
parent | 6d52fb871953e3c0219a8dd1c4a62fc3143925df (diff) |
Adds a new function to build from a json_object.
Build an openxc_DynamicField from a json_object.
Change-Id: I57033daca5fd4f198b872f015255893d9f8f9303
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding')
-rw-r--r-- | low-can-binding/utils/openxc-utils.cpp | 26 | ||||
-rw-r--r-- | low-can-binding/utils/openxc-utils.hpp | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp index 3db964d8..e454121b 100644 --- a/low-can-binding/utils/openxc-utils.cpp +++ b/low-can-binding/utils/openxc-utils.cpp @@ -181,6 +181,32 @@ const openxc_SimpleMessage build_SimpleMessage(const std::string& name, const op return s; } +/// @brief Build an openxc_DynamicField with a json object +/// +/// @param[in] value - const json_object pointer to assign to convert in an +/// openxc_DynamicField. +/// +/// @return openxc_DynamicField initialized with a json object. +/// +const openxc_DynamicField build_DynamicField(json_object* value) +{ + switch(json_object_get_type(value)) + { + case json_type_string: + return build_DynamicField(json_object_get_string(value)); + case json_type_double: + return build_DynamicField(json_object_get_double(value)); + case json_type_int: + return build_DynamicField(json_object_get_double(value)); + case json_type_boolean: + return build_DynamicField((bool)json_object_get_boolean(value)); + default: + openxc_DynamicField d; + ::memset(&d, 0, sizeof(openxc_DynamicField)); + return d; + } +} + /// /// @brief Build an openxc_DynamicField with a string value /// diff --git a/low-can-binding/utils/openxc-utils.hpp b/low-can-binding/utils/openxc-utils.hpp index 57663045..a84bc350 100644 --- a/low-can-binding/utils/openxc-utils.hpp +++ b/low-can-binding/utils/openxc-utils.hpp @@ -32,6 +32,7 @@ openxc_VehicleMessage build_VehicleMessage(); bool is_valid(const openxc_VehicleMessage& v); const openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value); +const openxc_DynamicField build_DynamicField(json_object* value); const openxc_DynamicField build_DynamicField(const char* value); const openxc_DynamicField build_DynamicField(const std::string& value); const openxc_DynamicField build_DynamicField(double value); |