aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can
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
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')
-rw-r--r--CAN-binder/low-can-binding/can/can-bus-dev.cpp34
-rw-r--r--CAN-binder/low-can-binding/can/can-bus-dev.hpp1
-rw-r--r--CAN-binder/low-can-binding/can/can-bus.cpp9
-rw-r--r--CAN-binder/low-can-binding/can/can-bus.hpp2
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.cpp51
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.hpp10
6 files changed, 58 insertions, 49 deletions
diff --git a/CAN-binder/low-can-binding/can/can-bus-dev.cpp b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
index 601881db..0a2cd308 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
@@ -124,40 +124,6 @@ can_message_t can_bus_dev_t::read()
return can_message_t::convert_from_frame(cfd, nbytes);
}
-/// @brief Create a RX_SETUP receive job using the BCM socket.
-///
-/// @return 0 if ok else -1
-int can_bus_dev_t::create_rx_filter(const can_signal_t& s)
-{
- uint32_t can_id = s.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));
- uint8_t bit_size = s.get_bit_size();
- float val = (float)(1 << bit_size)-1;
-
- bcm_msg.msg_head.opcode = RX_SETUP;
- bcm_msg.msg_head.can_id = can_id;
- bcm_msg.msg_head.flags = 0;
- bcm_msg.msg_head.nframes = 1;
- bitfield_encode_float(val,
- s.get_bit_position(),
- bit_size,
- s.get_factor(),
- s.get_offset(),
- cfd.data,
- CAN_MAX_DLEN);
-
- bcm_msg.frames = cfd;
-
- if(can_socket_ << bcm_msg)
- return 0;
- return -1;
-}
-
/// @brief start reading threads and set flag is_running_
/// @param[in] can_bus reference can_bus_t. it will be passed to the thread to allow using can_bus_t queue.
void can_bus_dev_t::start_reading(can_bus_t& can_bus)
diff --git a/CAN-binder/low-can-binding/can/can-bus-dev.hpp b/CAN-binder/low-can-binding/can/can-bus-dev.hpp
index e9c2d207..2ddc1ff0 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.hpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.hpp
@@ -58,7 +58,6 @@ public:
void stop_reading();
can_message_t read();
- int create_rx_filter(const can_signal_t& s);
int send(can_message_t& can_msg);
bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size);
diff --git a/CAN-binder/low-can-binding/can/can-bus.cpp b/CAN-binder/low-can-binding/can/can-bus.cpp
index d9703f2e..bca9d031 100644
--- a/CAN-binder/low-can-binding/can/can-bus.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus.cpp
@@ -391,15 +391,6 @@ void can_bus_t::push_new_vehicle_message(const openxc_VehicleMessage& v_msg)
vehicle_message_q_.push(v_msg);
}
-/// @brief Create a RX_SETUP receive job for the BCM socket of a CAN signal.
-///
-/// @return 0 if ok -1 if not.
- int can_bus_t::create_rx_filter(const can_signal_t& s)
- {
- const std::string& bus = s.get_message().get_bus_name();
- return can_bus_t::can_devices_[bus]->create_rx_filter(s);
- }
-
/// @brief Return a map with the can_bus_dev_t initialized
///
/// @return map can_bus_dev_m_ map
diff --git a/CAN-binder/low-can-binding/can/can-bus.hpp b/CAN-binder/low-can-binding/can/can-bus.hpp
index f6a3745e..94fa0a58 100644
--- a/CAN-binder/low-can-binding/can/can-bus.hpp
+++ b/CAN-binder/low-can-binding/can/can-bus.hpp
@@ -94,8 +94,6 @@ public:
openxc_VehicleMessage next_vehicle_message();
void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
- int create_rx_filter(const can_signal_t& signal);
-
const std::map<std::string, std::shared_ptr<can_bus_dev_t>>& get_can_devices() const;
static std::shared_ptr<can_bus_dev_t> get_can_device(std::string bus);
};
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;
+}
+
diff --git a/CAN-binder/low-can-binding/can/can-signals.hpp b/CAN-binder/low-can-binding/can/can-signals.hpp
index 50eb4ec5..f21cab49 100644
--- a/CAN-binder/low-can-binding/can/can-signals.hpp
+++ b/CAN-binder/low-can-binding/can/can-signals.hpp
@@ -25,6 +25,7 @@
#include "openxc.pb.h"
#include "../utils/timer.hpp"
+#include "../utils/socketcan-bcm.hpp"
#include "can-message.hpp"
#include "can-message-definition.hpp"
#include "../diagnostic/diagnostic-message.hpp"
@@ -75,15 +76,16 @@ typedef uint64_t (*SignalEncoder)(can_signal_t* signal,
class can_signal_t
{
private:
- std::uint8_t message_set_id_;
- std::uint8_t message_id_;
+ utils::socketcan_bcm_t socket_; /*!< socket_ - Specific BCM socket that filter the signal read from CAN device */
+ std::uint8_t message_set_id_; ///< message_set_id_ - Index number to the message_set_id container object
+ std::uint8_t message_id_; ///< message_id_ - Index number to the message_definition_t container object
std::string generic_name_; /*!< generic_name_ - The name of the signal to be output.*/
static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
* which make easier to sort message when the come in.*/
uint8_t bit_position_; /*!< bitPosition_ - The starting bit of the signal in its CAN message (assuming
* non-inverted bit numbering, i.e. the most significant bit of
* each byte is 0) */
- uint8_t bit_size_; /*!< bitSize_ - The width of the bit field in the CAN message. */
+ uint8_t bit_size_; /*!< bit_size_ - The width of the bit field in the CAN message. */
float factor_; /*!< factor_ - The final value will be multiplied by this factor. Use 1 if you
* don't need a factor. */
float offset_; /*!< offset_ - The final value will be added to this offset. Use 0 if you
@@ -129,6 +131,7 @@ public:
SignalEncoder encoder,
bool received);
+ utils::socketcan_bcm_t get_socket() const;
const can_message_definition_t& get_message() const;
const std::string& get_generic_name() const;
const std::string get_name() const;
@@ -154,4 +157,5 @@ public:
void set_prefix(std::string val);
void set_received(bool r);
void set_last_value(float val);
+ int create_rx_filter();
}; \ No newline at end of file