aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--low-can-binding/binding/low-can-cb.cpp5
-rw-r--r--low-can-binding/binding/low-can-socket.cpp7
-rw-r--r--low-can-binding/binding/low-can-socket.hpp6
-rw-r--r--low-can-binding/can/can-bus.cpp4
4 files changed, 15 insertions, 7 deletions
diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp
index edf464b..16e31d1 100644
--- a/low-can-binding/binding/low-can-cb.cpp
+++ b/low-can-binding/binding/low-can-cb.cpp
@@ -188,7 +188,7 @@ static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request,
for(const auto& sig : diagnostic_messages)
{
DiagnosticRequest* diag_req = new DiagnosticRequest(sig->build_diagnostic_request());
- event_filter.frequency = std::isnan(event_filter.frequency) ? sig->get_frequency() : event_filter.frequency;
+ event_filter.frequency = event_filter.frequency == 0 ? sig->get_frequency() : event_filter.frequency;
std::shared_ptr<low_can_subscription_t> can_subscription;
auto it = std::find_if(s.begin(), s.end(), [&sig](std::pair<int, std::shared_ptr<low_can_subscription_t> > sub){ return (! sub.second->get_diagnostic_message().empty());});
@@ -233,7 +233,6 @@ static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request,
return rets;
}
-// TODO: Create separate subscrition object if event_filter isn't the same.
static int subscribe_unsubscribe_can_signals(struct afb_req request,
bool subscribe,
std::vector<std::shared_ptr<can_signal_t> > can_signals,
@@ -243,7 +242,7 @@ static int subscribe_unsubscribe_can_signals(struct afb_req request,
int rets = 0;
for(const auto& sig: can_signals)
{
- auto it = std::find_if(s.begin(), s.end(), [&sig](std::pair<int, std::shared_ptr<low_can_subscription_t> > sub){ return sub.second->get_can_signal() == sig; });
+ auto it = std::find_if(s.begin(), s.end(), [&sig, &event_filter](std::pair<int, std::shared_ptr<low_can_subscription_t> > sub){ return sub.second->is_signal_subscription_corresponding(sig, event_filter) ; });
std::shared_ptr<low_can_subscription_t> can_subscription;
if(it != s.end())
{
diff --git a/low-can-binding/binding/low-can-socket.cpp b/low-can-binding/binding/low-can-socket.cpp
index c479a0a..8a8efbf 100644
--- a/low-can-binding/binding/low-can-socket.cpp
+++ b/low-can-binding/binding/low-can-socket.cpp
@@ -62,6 +62,11 @@ const std::shared_ptr<can_signal_t> low_can_socket_t::get_can_signal() const
return can_signal_;
}
+bool low_can_socket_t::is_signal_subscription_corresponding(const std::shared_ptr<can_signal_t> can_signal, const struct event_filter_t& event_filter) const
+{
+ return can_signal_ == can_signal && event_filter_ == event_filter;
+}
+
const std::vector<std::shared_ptr<diagnostic_message_t> > low_can_socket_t::get_diagnostic_message() const
{
return diagnostic_message_;
@@ -235,7 +240,7 @@ int low_can_socket_t::create_rx_filter(std::shared_ptr<can_signal_t> sig)
CAN_MAX_DLEN);
struct timeval freq, timeout = {0, 0};
- frequency_clock_t f = std::isnan(event_filter_.frequency) ? can_signal_->get_frequency() : frequency_clock_t(event_filter_.frequency);
+ frequency_clock_t f = event_filter_.frequency == 0 ? can_signal_->get_frequency() : frequency_clock_t(event_filter_.frequency);
freq = f.get_timeval_from_period();
utils::simple_bcm_msg bcm_msg = make_bcm_head(RX_SETUP, can_signal_->get_message()->get_id(), SETTIMER|RX_NO_AUTOTIMER, timeout, freq);
diff --git a/low-can-binding/binding/low-can-socket.hpp b/low-can-binding/binding/low-can-socket.hpp
index 018b307..71731b3 100644
--- a/low-can-binding/binding/low-can-socket.hpp
+++ b/low-can-binding/binding/low-can-socket.hpp
@@ -32,7 +32,10 @@ struct event_filter_t
float frequency; ///< frequency - Maximum frequency which will be received and pushed a subscribed event.
float min; ///< min - Minimum value that the signal don't have to go below to be pushed.
float max; ///< max - Maximum value that the signal don't have to go above to be pushed.
- event_filter_t() : frequency{NAN}, min{NAN}, max{NAN} {}
+ event_filter_t() : frequency{0}, min{-__FLT_MAX__}, max{__FLT_MAX__} {};
+ bool operator==(const event_filter_t& ext) const {
+ return frequency == ext.frequency && min == ext.min && max == ext.max;
+ }
};
/// @brief An object storing socket to CAN to be used to write on it.
@@ -62,6 +65,7 @@ public:
int get_index() const;
const std::shared_ptr<can_signal_t> get_can_signal() const;
+ bool is_signal_subscription_corresponding(const std::shared_ptr<can_signal_t>, const struct event_filter_t& event_filter) const;
const std::shared_ptr<diagnostic_message_t> get_diagnostic_message(uint32_t pid) const;
const std::vector<std::shared_ptr<diagnostic_message_t> > get_diagnostic_message() const;
const std::shared_ptr<diagnostic_message_t> get_diagnostic_message(const std::string& name) const;
diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp
index 9a98547..377728a 100644
--- a/low-can-binding/can/can-bus.cpp
+++ b/low-can-binding/can/can-bus.cpp
@@ -53,8 +53,8 @@ bool can_bus_t::apply_filter(const openxc_VehicleMessage& vehicle_message, std::
bool send = false;
if(is_valid(vehicle_message))
{
- float min = std::isnan(can_subscription->get_min()) ? -INFINITY : can_subscription->get_min();
- float max = std::isnan(can_subscription->get_max()) ? INFINITY : can_subscription->get_max();
+ float min = can_subscription->get_min();
+ float max = can_subscription->get_max();
double value = get_numerical_from_DynamicField(vehicle_message);
send = (value < min || value > max) ? false : true;
}