aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can/can-signals.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-05 18:34:48 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-05 18:42:30 +0200
commit5b66a43147af37f4ebe3429eb045900aa7323613 (patch)
tree0262af2114e8a043fc3660da54b3806c55c33d45 /CAN-binder/low-can-binding/can/can-signals.cpp
parentae74dbcb89f3d471b66e1f1d2fe4bdf33cfff388 (diff)
Improve granularity of BCM socket using one by signal
Move create_rx_filter to can_signals and adding all accessories needed to works. Change-Id: I3636fe82ce5c2e43a4992b66ce89440ff709004a Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/can/can-signals.cpp')
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/CAN-binder/low-can-binding/can/can-signals.cpp b/CAN-binder/low-can-binding/can/can-signals.cpp
index 82c62853..48c919da 100644
--- a/CAN-binder/low-can-binding/can/can-signals.cpp
+++ b/CAN-binder/low-can-binding/can/can-signals.cpp
@@ -22,7 +22,10 @@
#include "../binding/configuration.hpp"
#include "../utils/signals.hpp"
#include "can-decoder.hpp"
+#include "can-message.hpp"
+#include "can-bus.hpp"
#include "../diagnostic/diagnostic-message.hpp"
+#include "canutil/write.h"
std::string can_signal_t::prefix_ = "messages";
@@ -63,6 +66,10 @@ can_signal_t::can_signal_t(std::uint8_t message_set_id,
, last_value_{.0f}
{}
+utils::socketcan_bcm_t can_signal_t::get_socket() const
+{
+ return socket_;
+}
const can_message_definition_t& can_signal_t::get_message() const
{
@@ -184,3 +191,47 @@ void can_signal_t::set_last_value(float val)
{
last_value_ = val;
}
+
+/// @brief Create a RX_SETUP receive job using the BCM socket.
+///
+/// @return 0 if ok else -1
+int can_signal_t::create_rx_filter()
+{
+ // Make sure that socket has been opened.
+ if(! socket_)
+ socket_.open(
+ get_message().get_bus_name());
+
+ uint32_t can_id = get_message().get_id();
+
+ struct utils::simple_bcm_msg bcm_msg;
+ struct can_frame cfd;
+
+ memset(&cfd, 0, sizeof(cfd));
+ memset(&bcm_msg.msg_head, 0, sizeof(bcm_msg.msg_head));
+ float val = (float)(1 << bit_size_)-1;
+ float freq = frequency_.frequency_to_period();
+ if(freq <= 0)
+ freq = 0.000001f;
+
+ bcm_msg.msg_head.opcode = RX_SETUP;
+ bcm_msg.msg_head.can_id = can_id;
+ bcm_msg.msg_head.flags = SETTIMER;
+ bcm_msg.msg_head.ival2.tv_sec = long(freq);
+ bcm_msg.msg_head.ival2.tv_usec = (freq - (long)freq) * 1000000;
+ bcm_msg.msg_head.nframes = 1;
+ bitfield_encode_float(val,
+ bit_position_,
+ bit_size_,
+ factor_,
+ offset_,
+ cfd.data,
+ CAN_MAX_DLEN);
+
+ bcm_msg.frames = cfd;
+
+ if(socket_ << bcm_msg)
+ return 0;
+ return -1;
+}
+