*/
#include "openxc-utils.hpp"
-
+#include "converter.hpp"
#include "../binding/application.hpp"
+
///
/// @brief Build a specific VehicleMessage containing a DiagnosticResponse.
///
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;
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;
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;
{
openxc_VehicleMessage v;
- ::memset(&v, 0, sizeof(openxc_VehicleMessage));
+ ::memset(&v, 0, sizeof(v));
return v;
}
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<uint8_t> &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<size;i++)
+ d.bytes_value[i] = array[i];
+
+ return d;
+}
+
+
///
/// @brief Build an openxc_DynamicField with a string value
///
d.has_string_value = true;
d.has_numeric_value = false;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
::strncpy(d.string_value, value, 100);
return d;
d.has_string_value = true;
d.has_numeric_value = false;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
::strncpy(d.string_value, value.c_str(), 100);
return d;
d.has_string_value = false;
d.has_numeric_value = true;
d.has_boolean_value = false;
+ d.has_bytes_value = false;
d.numeric_value = value;
return d;
d.has_string_value = false;
d.has_numeric_value = false;
d.has_boolean_value = true;
+ d.has_bytes_value = false;
d.boolean_value = value;
+
return d;
}
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));
+ }
else if(field.has_boolean_value)
+ {
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));
+ }
+ else if(field.has_bytes_value)
+ {
+ std::string s = converter_t::to_hex(field.bytes_value, field.length_array);
+
+ json_object_object_add(value, "value", json_object_new_string(s.c_str()));
+ }
}
///