diff options
Diffstat (limited to 'low-can-binding/utils')
-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); |