This commit allow if the unit is defined to display it
in the json emmits by low-can.
Change-Id: Ia09d4d9614eba6de93292ffab351fa1f4e612b73
Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh>
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
if(s.find(v_message.first) != s.end() && afb_event_is_valid(s[v_message.first]->get_event()))
{
jo = json_object_new_object();
if(s.find(v_message.first) != s.end() && afb_event_is_valid(s[v_message.first]->get_event()))
{
jo = json_object_new_object();
- jsonify_vehicle(v_message.second, jo);
+ jsonify_vehicle(v_message.second, s[v_message.first]->get_signal(), jo);
if(afb_event_push(s[v_message.first]->get_event(), jo) == 0)
{
if(v_message.second.has_diagnostic_response)
if(afb_event_push(s[v_message.first]->get_event(), jo) == 0)
{
if(v_message.second.has_diagnostic_response)
///
/// @param[in] v_msg - const reference to an openxc_VehicleMessage
/// struct to convert into a json object.
///
/// @param[in] v_msg - const reference to an openxc_VehicleMessage
/// struct to convert into a json object.
+/// @param[in] sig - signal reference to the subscription of openxc_VehicleMessage,
+/// to get more informations about it
/// @param[out] json - pointer with the DynamicField converted into json object
///
/// @return True if VehicleMessage has been transformed into json object
/// and false if not. In such case, a json object is returned { "error": "error msg"}
///
/// @param[out] json - pointer with the DynamicField converted into json object
///
/// @return True if VehicleMessage has been transformed into json object
/// and false if not. In such case, a json object is returned { "error": "error msg"}
///
-bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, json_object* json)
+bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, std::shared_ptr<signal_t> sig, json_object* json)
{
if(jsonify_simple(get_simple_message(v_msg), 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()));
+
json_object_object_add(json, "timestamp", json_object_new_int64(v_msg.timestamp));
json_object_object_add(json, "timestamp", json_object_new_int64(v_msg.timestamp));
return true;
}
json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));
return true;
}
json_object_object_add(json, "error", json_object_new_string("openxc_SimpleMessage doesn't have name'"));
#include <sys/timeb.h>
#include "openxc.pb.h"
#include <sys/timeb.h>
#include "openxc.pb.h"
+#include "../can/signals.hpp"
#include "../diagnostic/active-diagnostic-request.hpp"
const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value);
#include "../diagnostic/active-diagnostic-request.hpp"
const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value);
bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);
bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);
-bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, json_object* json);
+bool jsonify_vehicle(const openxc_VehicleMessage& v_msg, std::shared_ptr<signal_t> sig, json_object* json);