* subsciptions.
*/
if(! request)
- {
return 0;
- }
// Event doesn't exist , so let's create it
if ((ret = can_subscription->subscribe(request)) < 0)
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);
+ if (json_object_object_get_ex(filter, "promisc", &obj)
+ && (json_object_is_type(obj, json_type_boolean)))
+ event_filter.promisc = (bool)json_object_get_boolean(obj);
if (json_object_object_get_ex(filter, "rx_id", &obj)
&& (json_object_is_type(obj, json_type_int)))
event_filter.rx_id = (canid_t) json_object_get_int(obj);
static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const uint32_t& id, json_object *args)
{
- int ret = 0;
std::shared_ptr<message_definition_t> message_definition = application_t::instance().get_message_definition(id);
struct utils::signals_found sf;
if(sf.signals.empty())
{
AFB_NOTICE("No signal(s) found for %d.", id);
- ret = -1;
- }
- else
- {
- event_filter_t event_filter = generate_filter(args);
- ret = subscribe_unsubscribe_signals(request, subscribe, sf, event_filter);
+ return -1;
}
- return ret;
+ event_filter_t event_filter = generate_filter(args);
+ std::shared_ptr<low_can_subscription_t> can_subscription = std::make_shared<low_can_subscription_t>(low_can_subscription_t(event_filter));
+ can_subscription->set_message_definition(message_definition);
+
+ utils::signals_manager_t& sm = utils::signals_manager_t::instance();
+ std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
+ map_subscription& s = sm.get_subscribed_signals();
+
+ if(can_subscription->create_rx_filter(message_definition) < 0)
+ return -1;
+ if(add_to_event_loop(can_subscription) < 0)
+ return -1;
+
+ if(subscribe_unsubscribe_signal(request, subscribe, can_subscription, s) < 0)
+ return -1;
+
+ return 0;
}
do_subscribe_unsubscribe(request, false);
}
-/*
-static int send_frame(struct canfd_frame& cfd, const std::string& bus_name, socket_type type)
-{
- if(bus_name.empty())
- {
- return -1;
- }
-
- std::map<std::string, std::shared_ptr<low_can_subscription_t> >& cd = application_t::instance().get_can_devices();
-
- if( cd.count(bus_name) == 0)
- {
- cd[bus_name] = std::make_shared<low_can_subscription_t>(low_can_subscription_t());
- }
-
-
- if(type == socket_type::BCM)
- {
- return low_can_subscription_t::tx_send(*cd[bus_name], cfd, bus_name);
- }
- else if(type == socket_type::J1939)
- {
- return low_can_subscription_t::j1939_send(*cd[bus_name], cfd, bus_name);
- }
- else{
- return -1;
- }
-}
-*/
static int send_message(message_t *message, const std::string& bus_name, uint32_t flags, event_filter_t &event_filter, std::shared_ptr<signal_t> signal)
{
if(bus_name.empty())