* limitations under the License.
*/
-#include "low-can-hat.hpp"
-
#include "low-can-subscription.hpp"
#include "application.hpp"
#include "canutil/write.h"
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_;
{
event_filter_.max = max;
}
-/// @brief Based upon which object is subscribed CAN signal or diagnostic message
-/// this will open the socket with the required CAN bus device name.
+/// @brief Based upon which object is a subscribed CAN signal or diagnostic message
+/// it will open the socket with the required CAN bus device name.
///
-/// @return INVALID_SOCKET on failure else positive integer
+/// @return INVALID_SOCKET on failure, else positive integer
int low_can_socket_t::open_socket(const std::string& bus_name)
{
int ret = 0;
return ret;
}
-/// @brief Build a BCM message head but don't set can_frame.
+/// @brief Builds a BCM message head but doesn't set can_frame.
///
-/// @return a simple_bcm_msg with the msg_head parts set and can_frame
+/// @returns a simple_bcm_msg with the msg_head parts set and can_frame
/// zeroed.
struct utils::simple_bcm_msg low_can_socket_t::make_bcm_head(uint32_t opcode, uint32_t can_id, uint32_t flags, const struct timeval& timeout, const struct timeval& frequency_thinning) const
{
return bcm_msg;
}
-/// @brief Take an existing simple_bcm_msg struct and add a can_frame to it.
-/// Only possible for now to add 1 uniq can_frame, it isn't possible to build
+/// @brief Take an existing simple_bcm_msg struct and add a can_frame.
+/// Currently only 1 uniq can_frame can be added, it's not possible to build
/// a multiplexed message with several can_frame.
void low_can_socket_t::add_bcm_frame(const struct can_frame& cf, struct utils::simple_bcm_msg& bcm_msg) const
{
- for(int i=0; i < CAN_MAX_DLEN; i++)
- {
- if(cf.data[i] != 0)
- {
- bcm_msg.msg_head.nframes = 1;
- bcm_msg.frames = cf;
- return;
- }
- }
+ bcm_msg.msg_head.nframes++;
+ bcm_msg.frames = cf;
}
-/// @brief Create a RX_SETUP receive job used by the BCM socket for a CAN signal
+/// @brief Create a RX_SETUP receive job to be used by the BCM socket for a CAN signal
/// subscription
///
/// @return 0 if ok else -1
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);
return create_rx_filter(bcm_msg);
}
-/// @brief Create a RX_SETUP receive job used by the BCM socket for a
+/// @brief Create a RX_SETUP receive job to be used by the BCM socket for a
/// diagnostic message subscription.
///
/// @return 0 if ok else -1
}
/// @brief Create a RX_SETUP receive job used by the BCM socket directly from
-/// a simple_bcm_msg. You will not use this method directly but rather use the
+/// a simple_bcm_msg. The method should not be used directly but rather through the
/// two previous method with can_signal_t or diagnostic_message_t object.
///
/// If the CAN arbitration ID is the OBD2 functional broadcast id the subscribed
/// @return 0 if ok else -1
int low_can_socket_t::create_rx_filter(utils::simple_bcm_msg& bcm_msg)
{
- // Make sure that socket has been opened.
+ // Make sure that socket is opened.
if(open_socket() < 0)
{return -1;}
- // If it isn't an OBD2 CAN ID then just add a simple RX_SETUP job
+ // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job
// else monitor all standard 8 CAN OBD2 ID response.
if(bcm_msg.msg_head.can_id != OBD2_FUNCTIONAL_BROADCAST_ID)
{
return 0;
}
-/// @brief Create a TX_SEND job used by the BCM socket to
-/// simply send message
-///
-/// @return 0 if ok else -1
-int low_can_socket_t::tx_send(const struct can_frame& cf, std::shared_ptr<can_signal_t> sig)
-{
- can_signal_ = sig;
-
- utils::simple_bcm_msg bcm_msg = make_bcm_head(TX_SEND);
- add_bcm_frame(cf, bcm_msg);
-
- if(open_socket() < 0)
- {return -1;}
-
- socket_ << bcm_msg;
- if(! socket_)
- return -1;
-
- return 0;
-}
-
-/// @brief Create a TX_SEND job used by the BCM socket to
-/// simply send message
+/// @brief Creates a TX_SEND job that is used by the BCM socket to
+/// send a message
///
/// @return 0 if ok else -1
int low_can_socket_t::tx_send(const struct can_frame& cf, const std::string& bus_name)