*/
#include "low-can-hat.hpp"
+#include "low-can-apidef.h"
#include <map>
#include <queue>
#include "../diagnostic/diagnostic-message.hpp"
#include "../utils/openxc-utils.hpp"
-
///******************************************************************************
///
/// SystemD event loop Callbacks
{
if (json_object_object_get_ex(filter, "frequency", &obj)
&& (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int)))
- {
- event_filter.frequency = (float)json_object_get_double(obj);
- ret += 1;
- }
+ {event_filter.frequency = (float)json_object_get_double(obj);}
if (json_object_object_get_ex(filter, "min", &obj)
&& (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int)))
- {
- event_filter.min = (float)json_object_get_double(obj);
- ret += 2;
- }
+ {event_filter.min = (float)json_object_get_double(obj);}
if (json_object_object_get_ex(filter, "max", &obj)
&& (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int)))
- {
- event_filter.max = (float)json_object_get_double(obj);
- ret += 4;
- }
+ {event_filter.max = (float)json_object_get_double(obj);}
}
// subscribe or unsubscribe
return ret;
}
-
-static void do_subscribe_unsubscribe(struct afb_req request, bool subscribe)
+static int process_one_subscribe_args(struct afb_req request, bool subscribe, json_object *args)
{
- int i, n, rc, rc2;
- struct json_object *args, *event, *x;
-
- args = afb_req_json(request);
- if (args == NULL || !json_object_object_get_ex(args, "event", &event))
+ int rc = 0, rc2=0;
+ json_object *x = nullptr, *event = nullptr;
+ if(args == NULL ||
+ !json_object_object_get_ex(args, "event", &event))
{
rc = one_subscribe_unsubscribe(request, subscribe, "*", args);
}
}
else
{
- rc = 0;
- n = json_object_array_length(event);
- for (i = 0 ; i < n ; i++)
+ for (int i = 0 ; i < json_object_array_length(event); i++)
{
x = json_object_array_get_idx(event, i);
rc2 = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(x), args);
rc = rc2 >= 0 ? rc + rc2 : rc2;
}
}
+ return rc;
+}
+
+static void do_subscribe_unsubscribe(struct afb_req request, bool subscribe)
+{
+ int rc = 0;
+ struct json_object *args, *x;
+
+ args = afb_req_json(request);
+ if (json_object_get_type(args) == json_type_array)
+ {
+ for(int i = 0; i < json_object_array_length(args); i++)
+ {
+ x = json_object_array_get_idx(args, i);
+ rc += process_one_subscribe_args(request, subscribe, x);
+ }
+ }
+ else
+ {
+ rc += process_one_subscribe_args(request, subscribe, args);
+ }
if (rc >= 0)
afb_req_success(request, NULL, NULL);
rc = send_frame(bus_name, cf);
}
else
- {AFB_NOTICE("%s isn't writable. Message not sent.", sig->get_name().c_str());}
+ {
+ AFB_WARNING("%s isn't writable. Message not sent.", sig->get_name().c_str());
+ return -1;
+ }
}
}
else
afb_req_fail(request, "error", NULL);
}
+
+/// @brief Initialize the binding.
+///
+/// @param[in] service Structure which represent the Application Framework Binder.
+///
+/// @return Exit code, zero if success.
+int initv2()
+{
+ can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager();
+
+ can_bus_manager.set_can_devices();
+ can_bus_manager.start_threads();
+
+ /// Initialize Diagnostic manager that will handle obd2 requests.
+ /// We pass by default the first CAN bus device to its Initialization.
+ /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus.
+ if(application_t::instance().get_diagnostic_manager().initialize())
+ return 0;
+
+ AFB_ERROR("There was something wrong with CAN device Initialization.");
+ return 1;
+}