aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding
diff options
context:
space:
mode:
Diffstat (limited to 'CAN-binder/low-can-binding')
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-cb.cpp53
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-hat.hpp3
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.cpp10
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.hpp1
-rw-r--r--CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp12
-rw-r--r--CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp1
6 files changed, 37 insertions, 43 deletions
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 d2987791..4faae852 100644
--- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp
+++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp
@@ -52,33 +52,50 @@ void on_no_clients(std::string message)
}
}
-int read_can_signal(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+static void push_n_notify(const can_message_t cm)
{
- can_signal_t* sig= (can_signal_t*)userdata;
- sig->read_socket();
-
- /* check if error or hangup */
- if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0)
- {
- sd_event_source_unref(s);
- sig->get_socket().close();
- sig->create_rx_filter();
- }
- return 0;
+ can_bus_t& cbm = configuration_t::instance().get_can_bus_manager();
+ std::lock_guard<std::mutex> can_message_lock(cbm.get_can_message_mutex());
+ { cbm.push_new_can_message(cm); }
+ cbm.get_new_can_message_cv().notify_one();
}
-int read_diagnostic_message(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
+ can_message_t cm;
+ can_signal_t* sig;
diagnostic_manager_t& diag_m = configuration_t::instance().get_diagnostic_manager();
- diag_m.read_socket();
+
+ if(userdata != nullptr)
+ {
+ sig = (can_signal_t*)userdata;
+ utils::socketcan_bcm_t s = sig->get_socket();
+ s >> cm;
+ }
+ else
+ {
+ utils::socketcan_bcm_t s = diag_m.get_socket();
+ s >> cm;
+ }
+
+ push_n_notify(cm);
/* check if error or hangup */
if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0)
{
sd_event_source_unref(s);
- diag_m.get_socket().close();
- diag_m.cleanup_active_requests(true);
- ERROR(binder_interface, "%s: Error on diagnostic manager socket, cancelling active requests.", __FUNCTION__);
+ if(userdata != nullptr)
+ {
+ sig->get_socket().close();
+ sig->create_rx_filter();
+ NOTICE(binder_interface, "%s: Recreated RX_SETUP BCM job for signal: %s", __FUNCTION__, sig->get_name().c_str());
+ }
+ else
+ {
+ diag_m.get_socket().close();
+ diag_m.cleanup_active_requests(true);
+ ERROR(binder_interface, "%s: Error on diagnostic manager socket, cancelling active requests.", __FUNCTION__);
+ }
return -1;
}
@@ -207,7 +224,7 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
return -1;
}
struct sd_event_source* e_source;
- sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), &e_source, sig->get_socket().socket(), EPOLLIN, read_can_signal, sig.get());
+ sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), &e_source, sig->get_socket().socket(), EPOLLIN, read_message, sig.get());
rets++;
DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
}
diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.hpp b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
index 57c0a536..b3384d77 100644
--- a/CAN-binder/low-can-binding/binding/low-can-hat.hpp
+++ b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
@@ -32,8 +32,7 @@ extern "C" struct afb_binding_interface;
extern const struct afb_binding_interface *binder_interface;
void on_no_clients(std::string message);
-int read_can_signal(sd_event_source *s, int fd, uint32_t revents, void *userdata);
-int read_diagnostic_message(sd_event_source *s, int fd, uint32_t revents, void *userdata);
+int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata);
void subscribe(struct afb_req request);
void unsubscribe(struct afb_req request); \ No newline at end of file
diff --git a/CAN-binder/low-can-binding/can/can-signals.cpp b/CAN-binder/low-can-binding/can/can-signals.cpp
index 0b589675..d196c078 100644
--- a/CAN-binder/low-can-binding/can/can-signals.cpp
+++ b/CAN-binder/low-can-binding/can/can-signals.cpp
@@ -255,13 +255,3 @@ int can_signal_t::create_rx_filter()
return 0;
return -1;
}
-
-void can_signal_t::read_socket()
-{
- can_message_t msg;
- can_bus_t& cbm = configuration_t::instance().get_can_bus_manager();
- socket_ >> msg;
- std::lock_guard<std::mutex> can_message_lock(cbm.get_can_message_mutex());
- { cbm.push_new_can_message(msg); }
- cbm.get_new_can_message_cv().notify_one();
-} \ No newline at end of file
diff --git a/CAN-binder/low-can-binding/can/can-signals.hpp b/CAN-binder/low-can-binding/can/can-signals.hpp
index 79f56dbf..1277bf36 100644
--- a/CAN-binder/low-can-binding/can/can-signals.hpp
+++ b/CAN-binder/low-can-binding/can/can-signals.hpp
@@ -157,5 +157,4 @@ public:
void set_last_value(float val);
int create_rx_filter();
- void read_socket();
}; \ No newline at end of file
diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp
index c4be28fa..4b254262 100644
--- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp
+++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp
@@ -57,16 +57,6 @@ bool diagnostic_manager_t::initialize()
return initialized_;
}
-void diagnostic_manager_t::read_socket()
-{
- can_message_t msg;
- can_bus_t& cbm = configuration_t::instance().get_can_bus_manager();
- socket_ >> msg;
- std::lock_guard<std::mutex> can_message_lock(cbm.get_can_message_mutex());
- { cbm.push_new_can_message(msg); }
- cbm.get_new_can_message_cv().notify_one();
-}
-
utils::socketcan_bcm_t& diagnostic_manager_t::get_socket()
{
return socket_;
@@ -454,7 +444,7 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos
&event_source_,
socket_.socket(),
EPOLLIN,
- read_diagnostic_message,
+ read_message,
nullptr) < 0)
{
cleanup_request(entry, true);
diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp
index bcee3dc2..894cf630 100644
--- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp
+++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp
@@ -66,7 +66,6 @@ public:
bool initialize();
- void read_socket();
utils::socketcan_bcm_t& get_socket();
std::string get_can_bus();
active_diagnostic_request_t* get_last_recurring_requests() const;