aboutsummaryrefslogtreecommitdiffstats
path: root/src/can/can-bus.hpp
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2017-03-08 14:47:38 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:10:39 +0100
commit9519e9d5b875b45fbf6f32267b728b1d11377276 (patch)
treefbd5c7b6c317c63920a77090676485a9e3612fc2 /src/can/can-bus.hpp
parentb4d0643afdb3ad69298dac22e4b3380038f301af (diff)
separation of can_bus_t and can_bus_dev_t and use of the new socket class.
Change-Id: I5f292ab18737fa48259f357d660fed27fb8fb4be Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'src/can/can-bus.hpp')
-rw-r--r--src/can/can-bus.hpp140
1 files changed, 52 insertions, 88 deletions
diff --git a/src/can/can-bus.hpp b/src/can/can-bus.hpp
index 4c265286..4443bf2a 100644
--- a/src/can/can-bus.hpp
+++ b/src/can/can-bus.hpp
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
* Author "Romain Forlot" <romain.forlot@iot.bzh>
+ * Author "Loïc Collignon" <loic.collignon@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +31,8 @@
#include "low-can-binding.hpp"
+#include "can-bus-dev.hpp"
+
// TODO actual max is 32 but dropped to 24 for memory considerations
#define MAX_ACCEPTANCE_FILTERS 24
// TODO this takes up a ton of memory
@@ -37,93 +40,54 @@
#define CAN_ACTIVE_TIMEOUT_S 30
-class can_bus_dev_t;
-
-/**
- * @class can_bus_t
- * @brief Object used to handle decoding and manage event queue to be pushed.
- *
- * This object is also used to initialize can_bus_dev_t object after reading
- * json conf file describing the CAN devices to use. Thus, those object will read
- * on the device the CAN frame and push them into the can_bus_t can_message_q_ queue.
- *
- * That queue will be later used to be decoded and pushed to subscribers.
- */
-class can_bus_t {
- private:
- int conf_file_; /*!< conf_file_ - configuration file handle used to initialize can_bus_dev_t objects.*/
-
- void can_decode_message();
- std::thread th_decoding_; /*!< thread that'll handle decoding a can frame */
- bool is_decoding_; /*!< boolean member controling thread while loop*/
-
- void can_event_push();
- std::thread th_pushing_; /*!< thread that'll handle pushing decoded can frame to subscribers */
- bool is_pushing_; /*!< boolean member controling thread while loop*/
-
- std::condition_variable new_can_message_cv_; /*!< condition_variable use to wait until there is a new CAN message to read*/
- std::mutex can_message_mutex_; /*!< mutex protecting the can_message_q_ queue.*/
- std::queue <can_message_t> can_message_q_; /*!< queue that'll store can_message_t to decoded */
-
- std::condition_variable new_decoded_can_message_; /*!< condition_variable use to wait until there is a new vehicle message to read from the queue vehicle_message_q_*/
- std::mutex decoded_can_message_mutex_; /*!< mutex protecting the vehicle_message_q_ queue.*/
- std::queue <openxc_VehicleMessage> vehicle_message_q_; /*!< queue that'll store openxc_VehicleMessage to pushed */
-
- std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_devices_m_; /*!< Can device map containing all can_bus_dev_t objects initialized during init_can_dev function*/
-
- public:
- can_bus_t(int conf_file);
-
- int init_can_dev();
- std::vector<std::string> read_conf();
-
-
- void start_threads();
- void stop_threads();
-
- can_message_t next_can_message();
- void push_new_can_message(const can_message_t& can_msg);
- std::mutex& get_can_message_mutex();
- std::condition_variable& get_new_can_message_cv();
-
- openxc_VehicleMessage next_vehicle_message();
- void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
-
- std::map<std::string, std::shared_ptr<can_bus_dev_t>> get_can_devices();
-};
-
-
-/**
- * @class can_bus_dev_t
- *
- * @brief Object representing a can device. Handle opening, closing and reading on the
- * socket. This is the low level object to be use by can_bus_t.
- */
-class can_bus_dev_t {
- private:
- int32_t id_; /*!< int32_t id_ - an identifier used through binding that refer to that device*/
- std::string device_name_; /*!< std::string device_name_ - name of the linux device handling the can bus. Generally vcan0, can0, etc. */
- int can_socket_; /*!< socket handler for the can device */
- bool is_fdmode_on_; /*!< boolean telling if whether or not the can socket use fdmode. */
- struct sockaddr_can txAddress_; /*!< internal member using to bind to the socket */
-
- std::thread th_reading_; /*!< Thread handling read the socket can device filling can_message_q_ queue of can_bus_t */
- bool is_running_; /*!< boolean telling whether or not reading is running or not */
- void can_reader(can_bus_t& can_bus);
-
- public:
- can_bus_dev_t(const std::string& dev_name);
-
- int open();
- int close();
-
- void start_reading(can_bus_t& can_bus);
-
- void stop_reading();
-
- std::pair<struct canfd_frame&, size_t> read();
-
- int send_can_message(can_message_t& can_msg);
+/// @brief Object used to handle decoding and manage event queue to be pushed.
+///
+/// This object is also used to initialize can_bus_dev_t object after reading
+/// json conf file describing the CAN devices to use. Thus, those object will read
+/// on the device the CAN frame and push them into the can_bus_t can_message_q_ queue.
+///
+/// That queue will be later used to be decoded and pushed to subscribers.
+class can_bus_t
+{
+private:
+ int conf_file_; /// < configuration file handle used to initialize can_bus_dev_t objects.
+
+ void can_decode_message();
+ std::thread th_decoding_; /// < thread that'll handle decoding a can frame
+ bool is_decoding_; /// < boolean member controling thread while loop
+
+ void can_event_push();
+ std::thread th_pushing_; /// < thread that'll handle pushing decoded can frame to subscribers
+ bool is_pushing_; /// < boolean member controling thread while loop
+
+ std::condition_variable new_can_message_cv_; /// < condition_variable use to wait until there is a new CAN message to read
+ std::mutex can_message_mutex_; /// < mutex protecting the can_message_q_ queue.
+ std::queue <can_message_t> can_message_q_; /// < queue that'll store can_message_t to decoded
+
+ std::condition_variable new_decoded_can_message_; /// < condition_variable use to wait until there is a new vehicle message to read from the queue vehicle_message_q_
+ std::mutex decoded_can_message_mutex_; /// < mutex protecting the vehicle_message_q_ queue.
+ std::queue <openxc_VehicleMessage> vehicle_message_q_; /// < queue that'll store openxc_VehicleMessage to pushed
+
+ std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_devices_m_; /// < Can device map containing all can_bus_dev_t objects initialized during init_can_dev function
+
+public:
+ can_bus_t(int conf_file);
+
+ int init_can_dev();
+ std::vector<std::string> read_conf();
+
+ void start_threads();
+ void stop_threads();
+
+ can_message_t next_can_message();
+ void push_new_can_message(const can_message_t& can_msg);
+ std::mutex& get_can_message_mutex();
+ std::condition_variable& get_new_can_message_cv();
+
+ openxc_VehicleMessage next_vehicle_message();
+ void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
+
+ std::map<std::string, std::shared_ptr<can_bus_dev_t>> get_can_devices();
};
/// TODO: implement this function as method into can_bus class