aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/binding/low-can-cb.cpp
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-12-18 16:57:22 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 16:25:36 +0100
commitf52c18b5ca626c680f8f2692f4c81a5ed00cb66e (patch)
treebbaf2587458a8ef8eaa40045c547833b0695f633 /low-can-binding/binding/low-can-cb.cpp
parent744d95cffe1241c97d922b18f6e3723fff7d64fe (diff)
can-bus: process signal rework to subscribe message
This commits allows to subscribe message and have all signals in one frame. Change-Id: I95de0e46b30be09a47a04754266cb55650eeec31 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/binding/low-can-cb.cpp')
-rw-r--r--low-can-binding/binding/low-can-cb.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp
index 4be7261e..42e02653 100644
--- a/low-can-binding/binding/low-can-cb.cpp
+++ b/low-can-binding/binding/low-can-cb.cpp
@@ -364,7 +364,6 @@ static int one_subscribe_unsubscribe_events(afb_req_t request, bool subscribe, c
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;
@@ -374,15 +373,26 @@ static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const
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;
}