X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=CAN-binder%2Flow-can-binding%2Fbinding%2Flow-can-cb.cpp;h=e3521018e673ec5f0d37e4de7fcd14f21937e9dc;hb=5206b26e1a6811d142ffbaf12daaea0731345490;hp=0671f9ebd4e55c84de1bf49780101f11fbf26ef7;hpb=2e66a10937ca8189498b540e3e28047d829021ad;p=apps%2Fagl-service-can-low-level.git diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp index 0671f9eb..e3521018 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -35,11 +35,6 @@ #include "../diagnostic/diagnostic-message.hpp" #include "../utils/openxc-utils.hpp" -extern "C" -{ - #include -}; - ///****************************************************************************** /// @@ -85,10 +80,12 @@ int read_message(sd_event_source *event_source, int fd, uint32_t revents, void * utils::socketcan_bcm_t& s = can_subscription->get_socket(); s >> cm; - push_n_notify(cm); + // Sure we got a valid CAN message ? + if(! cm.get_id() == 0 && ! cm.get_length() == 0) + {push_n_notify(cm);} } - /* check if error or hangup */ + // check if error or hangup if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0) { sd_event_source_unref(event_source); @@ -132,7 +129,7 @@ static int create_event_handle(std::shared_ptr& can_subs /// against the application framework using that event handle. static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, std::shared_ptr& can_subscription, std::map >& s) { - int ret; + int ret = -1; int sub_index = can_subscription->get_index(); if (can_subscription && s.find(sub_index) != s.end()) @@ -142,6 +139,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, NOTICE(binder_interface, "%s: Event isn't valid, no need to unsubscribed.", __FUNCTION__); ret = -1; } + ret = 0; } else { @@ -239,13 +237,13 @@ static int subscribe_unsubscribe_can_signals(struct afb_req request, bool subscr can_subscription = std::make_shared(low_can_subscription_t(event_filter)); if(can_subscription->create_rx_filter(sig) < 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;} - if(add_to_event_loop(can_subscription) < 0) - {return -1;} rets++; DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str()); }