aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/binding/low-can-cb.cpp
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-08-28 10:36:40 +0200
committerArthur Guyader <arthur.guyader@iot.bzh>2019-08-30 15:08:52 +0200
commitd4899192ccda96a8ee328bad3e16efdc98c2a856 (patch)
tree91d0723c2600db860f8af779edde50e022e75546 /low-can-binding/binding/low-can-cb.cpp
parentb9b4580d5d55f81ce2cdc47d652b1aa3304ad772 (diff)
Change vector to list to allow to remove signal.
This commit allows to remove signals. We need that because subscription to an iso tp message needs to be individual. Bug-AGL : SPEC-2779 Change-Id: I1d6410ebfc8ea82d33addf1bb828d9cd810b006a Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh>
Diffstat (limited to 'low-can-binding/binding/low-can-cb.cpp')
-rw-r--r--low-can-binding/binding/low-can-cb.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp
index 2c6e2be3..6c8a1ee0 100644
--- a/low-can-binding/binding/low-can-cb.cpp
+++ b/low-can-binding/binding/low-can-cb.cpp
@@ -194,7 +194,7 @@ static int add_to_event_loop(std::shared_ptr<low_can_subscription_t>& can_subscr
static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request,
bool subscribe,
- std::vector<std::shared_ptr<diagnostic_message_t> > diagnostic_messages,
+ std::list<std::shared_ptr<diagnostic_message_t> > diagnostic_messages,
struct event_filter_t& event_filter,
std::map<int, std::shared_ptr<low_can_subscription_t> >& s,
bool perm_rec_diag_req)
@@ -259,7 +259,7 @@ static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request,
static int subscribe_unsubscribe_signals(afb_req_t request,
bool subscribe,
- std::vector<std::shared_ptr<signal_t> > signals,
+ std::list<std::shared_ptr<signal_t> > signals,
struct event_filter_t& event_filter,
std::map<int, std::shared_ptr<low_can_subscription_t> >& s)
{
@@ -353,6 +353,22 @@ static int one_subscribe_unsubscribe_events(afb_req_t request, bool subscribe, c
// subscribe or unsubscribe
openxc_DynamicField search_key = build_DynamicField(tag);
sf = utils::signals_manager_t::instance().find_signals(search_key);
+
+
+#ifdef USE_FEATURE_ISOTP
+ if(sf.signals.size() > 1)
+ {
+ sf.signals.remove_if([](std::shared_ptr<signal_t> x){
+ bool isotp = x->get_message()->is_isotp();
+ if(isotp)
+ {
+ AFB_NOTICE("ISO TP messages need to be subscribed one by one (rx, tx)");
+ }
+ return isotp;
+ });
+ }
+#endif
+
if (sf.signals.empty() && sf.diagnostic_messages.empty())
{
AFB_NOTICE("No signal(s) found for %s.", tag.c_str());
@@ -374,7 +390,7 @@ static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const
if(message_definition)
{
- sf.signals = message_definition->get_signals();
+ sf.signals = std::list<std::shared_ptr<signal_t>>(message_definition->get_signals().begin(),message_definition->get_signals().end());
}
if(sf.signals.empty())
@@ -571,10 +587,10 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess
if( !sf.signals.empty() )
{
- AFB_DEBUG("ID WRITE RAW : %d",sf.signals[0]->get_message()->get_id());
+ AFB_DEBUG("ID WRITE RAW : %d",sf.signals.front()->get_message()->get_id());
if(flags&BCM_PROTOCOL)
{
- if(sf.signals[0]->get_message()->is_fd())
+ if(sf.signals.front()->get_message()->is_fd())
{
AFB_DEBUG("CANFD_MAX_DLEN");
message->set_flags(CAN_FD_FRAME);
@@ -586,7 +602,7 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess
message->set_maxdlen(CAN_MAX_DLEN);
}
- if(sf.signals[0]->get_message()->is_isotp())
+ if(sf.signals.front()->get_message()->is_isotp())
{
flags = ISOTP_PROTOCOL;
message->set_maxdlen(MAX_ISOTP_FRAMES * message->get_maxdlen());
@@ -632,7 +648,7 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess
return;
}
- if(! send_message(message, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name), flags, event_filter, sf.signals[0]))
+ if(! send_message(message, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name), flags, event_filter, sf.signals.front()))
{
afb_req_success(request, nullptr, "Message correctly sent");
}
@@ -703,7 +719,7 @@ static void write_signal(afb_req_t request, const std::string& name, json_object
return;
}
- std::shared_ptr<signal_t> sig = sf.signals[0];
+ std::shared_ptr<signal_t> sig = sf.signals.front();
if(! sig->get_writable())
{
afb_req_fail_f(request, "%s isn't writable. Message not sent.", sig->get_name().c_str());