X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Futils%2Fopenxc-utils.cpp;h=68c8a6578039a6adfcc5958cf93b98ca5e0215b8;hb=9e23caa4c56259044604c38f107f7c637001b846;hp=3db964d869afbad5fa2ec8454cd1f55b43956e87;hpb=4af423a2a09683acf0a9ad1e0a77bc45c2c843d9;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp index 3db964d8..68c8a657 100644 --- a/low-can-binding/utils/openxc-utils.cpp +++ b/low-can-binding/utils/openxc-utils.cpp @@ -17,9 +17,10 @@ */ #include "openxc-utils.hpp" - +#include "converter.hpp" #include "../binding/application.hpp" + /// /// @brief Build a specific VehicleMessage containing a DiagnosticResponse. /// @@ -34,6 +35,7 @@ const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value) { openxc_VehicleMessage message; + ::memset(&message, 0, sizeof(message)); application_t& app = application_t::instance(); message.has_type = true; @@ -98,6 +100,7 @@ const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* re const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message, uint64_t timestamp) { openxc_VehicleMessage v; + ::memset(&v, 0, sizeof(v)); v.has_type = true, v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE; @@ -120,6 +123,7 @@ const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& mes const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message) { openxc_VehicleMessage v; + ::memset(&v, 0, sizeof(v)); v.has_type = true, v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE; @@ -141,7 +145,7 @@ openxc_VehicleMessage build_VehicleMessage() { openxc_VehicleMessage v; - ::memset(&v, 0, sizeof(openxc_VehicleMessage)); + ::memset(&v, 0, sizeof(v)); return v; } @@ -181,6 +185,63 @@ 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; + } +} + +const openxc_DynamicField build_DynamicField(std::vector &array) +{ + openxc_DynamicField d; + d.has_type = true; + d.type = openxc_DynamicField_Type_BYTES; + + d.has_string_value = false; + d.has_numeric_value = false; + d.has_boolean_value = false; + d.has_bytes_value = true; + + + size_t size = array.size(); + + if(size > 2040) + { + AFB_ERROR("Error to generate array dynamic field, too large data"); + return d; + } + else + { + d.length_array = (uint32_t) size; + } + + for(int i=0;i sig, json_object* json) { if(jsonify_simple(get_simple_message(v_msg), json)) { + if(sig != nullptr && sig->get_unit() != "") + json_object_object_add(json, "unit", json_object_new_string(sig->get_unit().c_str())); + if(v_msg.has_timestamp) - { json_object_object_add(json, "timestamp", json_object_new_int64(v_msg.timestamp)); - return true; - } + return true; } json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));