diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-06 19:08:32 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-06 19:14:49 +0100 |
commit | 7578df6fb02f05aea7fb69938f8a15a9c3e6c53a (patch) | |
tree | b8958f0c207638c31f97bca731871a7d76d7caa5 /src | |
parent | d6c1b80cdbd87df96f3f648d67ccdbba6794f957 (diff) |
Comment pass to cpp file instead of hpp
Change-Id: I13f3b3d81485ec59a636f11140074d9f25f87428
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r-- | src/can-bus.cpp | 138 | ||||
-rw-r--r-- | src/can-bus.hpp | 164 | ||||
-rw-r--r-- | src/can-message.cpp | 106 | ||||
-rw-r--r-- | src/can-message.hpp | 123 |
4 files changed, 245 insertions, 286 deletions
diff --git a/src/can-bus.cpp b/src/can-bus.cpp index b35bc31..d46092b 100644 --- a/src/can-bus.cpp +++ b/src/can-bus.cpp @@ -42,12 +42,26 @@ extern "C" * can_bus_t method implementation * *********************************************************************************/ - +/** +* @brief Class constructor +* +* @param struct afb_binding_interface *interface between daemon and binding +* @param int file handle to the json configuration file. +*/ can_bus_t::can_bus_t(int conf_file) : conf_file_{conf_file} { } +/** +* @brief thread to decoding raw CAN messages. +* +* @desc It will take from the can_message_q_ queue the next can message to process then it will search +* about signal subscribed if there is a valid afb_event for it. We only decode signal for which a +* subscription has been made. Can message will be decoded using translateSignal that will pass it to the +* corresponding decoding function if there is one assigned for that signal. If not, it will be the default +* noopDecoder function that will operate on it. +*/ void can_bus_t::can_decode_message() { can_message_t can_message; @@ -94,6 +108,10 @@ void can_bus_t::can_decode_message() } } +/** +* @brief thread to push events to suscribers. It will read subscribed_signals map to look +* which are events that has to be pushed. +*/ void can_bus_t::can_event_push() { openxc_VehicleMessage v_message; @@ -120,9 +138,13 @@ void can_bus_t::can_event_push() } } +/** + * @brief Will initialize threads that will decode + * and push subscribed events. + */ void can_bus_t::start_threads() { - is_decoding_ = true; + v_ = true; th_decoding_ = std::thread(&can_bus_t::can_decode_message, this); if(!th_decoding_.joinable()) is_decoding_ = false; @@ -133,12 +155,21 @@ void can_bus_t::start_threads() is_pushing_ = false; } +/** +* @brief Will stop all threads holded by can_bus_t object +* which are decoding and pushing then will wait that's +* they'll finish their job. +*/ void can_bus_t::stop_threads() { is_decoding_ = false; is_pushing_ = false; } +/** +* @brief Will initialize can_bus_dev_t objects after reading +* the configuration file passed in the constructor. +*/ int can_bus_t::init_can_dev() { std::vector<std::string> devices_name; @@ -173,6 +204,12 @@ int can_bus_t::init_can_dev() return 1; } +/** +* @brief read the conf_file_ and will parse json objects +* in it searching for canbus objects devices name. +* +* @return Vector of can bus device name string. +*/ std::vector<std::string> can_bus_t::read_conf() { std::vector<std::string> ret; @@ -194,7 +231,15 @@ std::vector<std::string> can_bus_t::read_conf() jo = json_tokener_parse(fd_conf_content.c_str()); if (jo == NULL || !json_object_object_get_ex(jo, "canbus", &canbus)) - { + {/** +* @brief Telling if the pushing thread is running +* This is the boolean value on which the while loop +* take its condition. Set it to false will stop the +* according thread. +* +* @return true if pushing thread is running, false if not. +*/ + ERROR(binder_interface, "Can't find canbus node in the configuration file. Please review it."); ret.clear(); } @@ -217,16 +262,31 @@ std::vector<std::string> can_bus_t::read_conf() return ret; } -std::condition_variable& can_bus_t::get_new_can_message() +/** +* @brief return new_can_message_ member +* +* @return return new_can_message_ member +*/ +std::condition_variable& can_bus_t::get_new_can_message_cv() { - return new_can_message_; + return new_can_message_cv_; } +/** +* @brief return can_message_mutex_ member +* +* @return return can_message_mutex_ member +*/ std::mutex& can_bus_t::get_can_message_mutex() { return can_message_mutex_; } +/** +* @brief Return first can_message_t on the queue +* +* @return a can_message_t +*/ can_message_t can_bus_t::next_can_message() { can_message_t can_msg; @@ -243,11 +303,21 @@ can_message_t can_bus_t::next_can_message() return can_msg; } +/** +* @brief Push a can_message_t into the queue +* +* @param the const reference can_message_t object to push into the queue +*/ void can_bus_t::push_new_can_message(const can_message_t& can_msg) { can_message_q_.push(can_msg); } +/** +* @brief Return first openxc_VehicleMessage on the queue +* +* @return a openxc_VehicleMessage containing a decoded can message +*/ openxc_VehicleMessage can_bus_t::next_vehicle_message() { openxc_VehicleMessage v_msg; @@ -263,11 +333,21 @@ openxc_VehicleMessage can_bus_t::next_vehicle_message() return v_msg; } +/** +* @brief Push a openxc_VehicleMessage into the queue +* +* @param the const reference openxc_VehicleMessage object to push into the queue +*/ void can_bus_t::push_new_vehicle_message(const openxc_VehicleMessage& v_msg) { vehicle_message_q_.push(v_msg); } +/** +* @brief Return a map with the can_bus_dev_t initialized +* +* @return map can_bus_dev_m_ map +*/ std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_bus_t::get_can_devices() { return can_devices_m_; @@ -278,12 +358,21 @@ std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_bus_t::get_can_devices * can_bus_dev_t method implementation * *********************************************************************************/ - +/** +* @brief Class constructor +* +* @param const string representing the device name into the linux /dev tree +*/ can_bus_dev_t::can_bus_dev_t(const std::string &dev_name) : device_name_{dev_name}, can_socket_{-1} { } +/** +* @brief Open the can socket and returning it +* +* @return +*/ int can_bus_dev_t::open() { const int canfd_on = 1; @@ -339,6 +428,11 @@ int can_bus_dev_t::open() return -1; } +/** + * @brief Open the can socket and returning it + * + * @return + */ int can_bus_dev_t::close() { ::close(can_socket_); @@ -346,6 +440,12 @@ int can_bus_dev_t::close() return can_socket_; } +/** +* @brief Read the can socket and retrieve canfd_frame +* +* @param const struct afb_binding_interface* interface pointer. Used to be able to log +* using application framework logger. +*/ std::pair<struct canfd_frame&, size_t> can_bus_dev_t::read() { ssize_t nbytes; @@ -375,6 +475,12 @@ std::pair<struct canfd_frame&, size_t> can_bus_dev_t::read() return std::pair<struct canfd_frame&, size_t>(cfd, nbytes); } +/** +* @brief start reading threads and set flag is_running_ +* +* @param can_bus_t 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) { DEBUG(binder_interface, "Launching reading thread"); @@ -384,11 +490,22 @@ void can_bus_dev_t::start_reading(can_bus_t& can_bus) is_running_ = false; } +/** +* @brief stop the reading thread setting flag is_running_ to false and +* and wait that the thread finish its job. +*/ void can_bus_dev_t::stop_reading() { is_running_ = false; } +/** +* +* @brief Thread function used to read the can socket. +* +* @param[in] can_bus_dev_t object to be used to read the can socket +* @param[in] can_bus_t object used to fill can_message_q_ queue +*/ void can_bus_dev_t::can_reader(can_bus_t& can_bus) { can_message_t can_message; @@ -401,10 +518,17 @@ void can_bus_dev_t::can_reader(can_bus_t& can_bus) std::lock_guard<std::mutex> can_message_lock(can_bus.get_can_message_mutex()); can_bus.push_new_can_message(can_message); } - can_bus.get_new_can_message().notify_one(); + can_bus.get_new_can_message_cv_().notify_one(); } } +/** +* @brief Send a can message from a can_message_t object. +* +* @param const can_message_t& can_msg: the can message object to send +* @param const struct afb_binding_interface* interface pointer. Used to be able to log +* using application framework logger. +*/ int can_bus_dev_t::send_can_message(can_message_t& can_msg) { ssize_t nbytes; diff --git a/src/can-bus.hpp b/src/can-bus.hpp index f7cb312..bc2bb04 100644 --- a/src/can-bus.hpp +++ b/src/can-bus.hpp @@ -52,28 +52,15 @@ class can_bus_t { private: int conf_file_; /*!< conf_file_ - configuration file handle used to initialize can_bus_dev_t objects.*/ - /** - * @brief thread to decoding raw CAN messages. - * - * @desc It will take from the can_message_q_ queue the next can message to process then it will search - * about signal subscribed if there is a valid afb_event for it. We only decode signal for which a - * subscription has been made. Can message will be decoded using translateSignal that will pass it to the - * corresponding decoding function if there is one assigned for that signal. If not, it will be the default - * noopDecoder function that will operate on it. - */ 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*/ - /** - * @brief thread to push events to suscribers. It will read subscribed_signals map to look - * which are events that has to be pushed. - */ 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_; /*!< condition_variable use to wait until there is a new CAN message to read*/ + 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 */ @@ -84,108 +71,23 @@ class can_bus_t { 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: - /** - * @brief Class constructor - * - * @param struct afb_binding_interface *interface between daemon and binding - * @param int file handle to the json configuration file. - */ can_bus_t(int conf_file); - - /** - * @brief Will initialize can_bus_dev_t objects after reading - * the configuration file passed in the constructor. - */ - int init_can_dev(); - /** - * @brief read the conf_file_ and will parse json objects - * in it searching for canbus objects devices name. - * - * @return Vector of can bus device name string. - */ + int init_can_dev(); std::vector<std::string> read_conf(); - /** - * @brief Will initialize threads that will decode - * and push subscribed events. - */ - void start_threads(); - /** - * @brief Will stop all threads holded by can_bus_t object - * which are decoding and pushing then will wait that's - * they'll finish their job. - */ + void start_threads(); void stop_threads(); - /** - * @brief Telling if the decoding thread is running. - * This is the boolean value on which the while loop - * take its condition. Set it to false will stop the - * according thread. - * - * @return true if decoding thread is running, false if not. - */ - bool is_decoding(); - - /** - * @brief Telling if the pushing thread is running - * This is the boolean value on which the while loop - * take its condition. Set it to false will stop the - * according thread. - * - * @return true if pushing thread is running, false if not. - */ - bool is_pushing(); - - /** - * @brief Return first can_message_t on the queue - * - * @return a can_message_t - */ can_message_t next_can_message(); - - /** - * @brief Push a can_message_t into the queue - * - * @param the const reference can_message_t object to push into the queue - */ void push_new_can_message(const can_message_t& can_msg); - - /** - * @brief return can_message_mutex_ member - * - * @return return can_message_mutex_ member - */ std::mutex& get_can_message_mutex(); - - /** - * @brief return new_can_message_ member - * - * @return return new_can_message_ member - */ - std::condition_variable& get_new_can_message(); + std::condition_variable& get_new_can_message_cv_(); - /** - * @brief Return first openxc_VehicleMessage on the queue - * - * @return a openxc_VehicleMessage containing a decoded can message - */ openxc_VehicleMessage next_vehicle_message(); - - /** - * @brief Push a openxc_VehicleMessage into the queue - * - * @param the const reference openxc_VehicleMessage object to push into the queue - */ void push_new_vehicle_message(const openxc_VehicleMessage& v_msg); - /** - * @brief Return a map with the can_bus_dev_t initialized - * - * @return map can_bus_dev_m_ map - */ std::map<std::string, std::shared_ptr<can_bus_dev_t>> get_can_devices(); }; @@ -198,6 +100,7 @@ class 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. */ @@ -206,76 +109,21 @@ class can_bus_dev_t { 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 */ - /** - * - * @brief Thread function used to read the can socket. - * - * @param[in] can_bus_dev_t object to be used to read the can socket - * @param[in] can_bus_t object used to fill can_message_q_ queue - */ void can_reader(can_bus_t& can_bus); public: - /** - * @brief Class constructor - * - * @param const string representing the device name into the linux /dev tree - */ can_bus_dev_t(const std::string& dev_name); - /** - * @brief Open the can socket and returning it - * - * @return - */ int open(); - - /** - * @brief Open the can socket and returning it - * - * @return - */ int close(); - /** - * @brief Telling if the reading thread is running - * This is the boolean value on which the while loop - * take its condition. Set it to false will stop the - * according thread. - * - * @return true if reading thread is running, false if not. - */ - bool is_running(); - - /** - * @brief start reading threads and set flag is_running_ - * - * @param can_bus_t reference can_bus_t. it will be passed to the thread - * to allow using can_bus_t queue. - */ + void start_reading(can_bus_t& can_bus); - /** - * @brief stop the reading thread setting flag is_running_ to false and - * and wait that the thread finish its job. - */ void stop_reading(); - /** - * @brief Read the can socket and retrieve canfd_frame - * - * @param const struct afb_binding_interface* interface pointer. Used to be able to log - * using application framework logger. - */ std::pair<struct canfd_frame&, size_t> read(); - /** - * @brief Send a can message from a can_message_t object. - * - * @param const can_message_t& can_msg: the can message object to send - * @param const struct afb_binding_interface* interface pointer. Used to be able to log - * using application framework logger. - */ int send_can_message(can_message_t& can_msg); }; diff --git a/src/can-message.cpp b/src/can-message.cpp index 5d01880..ad03202 100644 --- a/src/can-message.cpp +++ b/src/can-message.cpp @@ -26,21 +26,40 @@ * CanMessage method implementation * *********************************************************************************/ - +/** +* @brief Class constructor +* +* Constructor about can_message_t class. +*/ can_message_t::can_message_t() : id_{0}, rtr_flag_{false}, length_{0}, flags_{0}, format_{CanMessageFormat::ERROR} {} +/** +* @brief Retrieve id_ member value. +* +* @return uint32_t id_ class member +*/ uint32_t can_message_t::get_id() const { return id_; } +/** +* @brief Retrieve RTR flag member. +* +* @return bool rtr_flags_ class member +*/ bool can_message_t::get_rtr_flag_() const { return rtr_flag_; } +/** +* @brief Retrieve format_ member value. +* +* @return CanMessageFormat format_ class member +*/ int can_message_t::get_format() const { if (format_ != CanMessageFormat::STANDARD || format_ != CanMessageFormat::EXTENDED) @@ -48,16 +67,32 @@ int can_message_t::get_format() const return format_; } +/** +* @brief Retrieve format_ member value. +* +* @return CanMessageFormat format_ class member +*/ uint8_t can_message_t::get_flags() const { return flags_; } +/** +* @brief Retrieve data_ member value. +* +* @return uint8_t data_ pointer to the first element +* of class member data_ +*/ const uint8_t* can_message_t::get_data() const { return data_.data(); } +/** +* @brief Retrieve length_ member value. +* +* @return uint8_t length_ class member +*/ uint8_t can_message_t::get_length() const { return length_; @@ -83,6 +118,12 @@ void can_message_t::set_max_data_length(size_t nbytes) } } +/** +* @brief Control whether the object is correctly initialized +* to be sent over the CAN bus +* +* @return true if object correctly initialized and false if not... +*/ bool can_message_t::is_correct_to_send() { if (id_ != 0 && length_ != 0 && format_ != CanMessageFormat::ERROR) @@ -95,6 +136,14 @@ bool can_message_t::is_correct_to_send() return false; } +/** +* @brief Set id_ member value. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param uint32_t id_ class member +*/ void can_message_t::set_id_and_format(const uint32_t new_id) { set_format(new_id); @@ -115,6 +164,14 @@ void can_message_t::set_id_and_format(const uint32_t new_id) } } +/** +* @brief Set format_ member value. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param CanMessageFormat format_ class member +*/ void can_message_t::set_format(const CanMessageFormat new_format) { if(new_format == CanMessageFormat::STANDARD || new_format == CanMessageFormat::EXTENDED || new_format == CanMessageFormat::ERROR) @@ -123,6 +180,15 @@ void can_message_t::set_format(const CanMessageFormat new_format) ERROR(binder_interface, "ERROR: Can set format, wrong format chosen"); } +/** +* @brief Set format_ member value. Deducing from the can_id +* of a canfd_frame. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param uint32_t can_id integer from a canfd_frame +*/ void can_message_t::set_format(const uint32_t can_id) { if (can_id & CAN_ERR_FLAG) @@ -133,11 +199,27 @@ void can_message_t::set_format(const uint32_t can_id) format_ = CanMessageFormat::STANDARD; } +/** +* @brief Set format_ member value. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param CanMessageFormat format_ class member +*/ void can_message_t::set_flags(const uint8_t flags) { flags_ = flags & 0xF; } +/** +* @brief Set length_ member value. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param uint8_t length_ array with a max size of 8 elements. +*/ void can_message_t::set_length(const uint8_t new_length) { if(rtr_flag_) @@ -148,6 +230,14 @@ void can_message_t::set_length(const uint8_t new_length) } } +/** +* @brief Set data_ member value. +* +* Preferred way to initialize these members by using +* convert_from_canfd_frame method. +* +* @param uint8_t data_ array with a max size of 8 elements. +*/ void can_message_t::set_data(const __u8* new_data) { int i; @@ -160,6 +250,13 @@ void can_message_t::set_data(const __u8* new_data) } } +/** +* @brief Take a canfd_frame struct to initialize class members +* +* This is the preferred way to initialize class members. +* +* @param canfd_frame struct read from can bus device. +*/ void can_message_t::convert_from_canfd_frame(const std::pair<struct canfd_frame&, size_t>args) { // May be it's overkill to assign member of the pair... May be it will change... @@ -191,6 +288,13 @@ void can_message_t::convert_from_canfd_frame(const std::pair<struct canfd_frame& data_[0], data_[1], data_[2], data_[3], data_[4], data_[5], data_[6], data_[7]); } +/** +* @brief Take all initialized class's members and build an +* canfd_frame struct that can be use to send a CAN message over +* the bus. +* +* @return canfd_frame struct built from class members. +*/ canfd_frame can_message_t::convert_to_canfd_frame() { canfd_frame frame; diff --git a/src/can-message.hpp b/src/can-message.hpp index efae17f..9f6a36d 100644 --- a/src/can-message.hpp +++ b/src/can-message.hpp @@ -67,143 +67,26 @@ class can_message_t { uint8_t maxdlen_; public: - /** - * @brief Class constructor - * - * Constructor about can_message_t class. - */ can_message_t(); - /** - * @brief Retrieve id_ member value. - * - * @return uint32_t id_ class member - */ uint32_t get_id() const; - - /** - * @brief Retrieve RTR flag member. - * - * @return bool rtr_flags_ class member - */ bool get_rtr_flag_() const; - - /** - * @brief Retrieve format_ member value. - * - * @return CanMessageFormat format_ class member - */ int get_format() const; - - /** - * @brief Retrieve format_ member value. - * - * @return CanMessageFormat format_ class member - */ uint8_t get_flags() const; - - /** - * @brief Retrieve data_ member value. - * - * @return uint8_t data_ pointer to the first element - * of class member data_ - */ const uint8_t* get_data() const; - - /** - * @brief Retrieve length_ member value. - * - * @return uint8_t length_ class member - */ uint8_t get_length() const; - - void set_max_data_length(size_t nbytes); - /** - * @brief Control whether the object is correctly initialized - * to be sent over the CAN bus - * - * @return true if object correctly initialized and false if not... - */ - bool is_correct_to_send(); - - /** - * @brief Set id_ member value. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param uint32_t id_ class member - */ + void set_max_data_length(size_t nbytes); void set_id_and_format(const uint32_t new_id); - - /** - * @brief Set format_ member value. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param CanMessageFormat format_ class member - */ void set_format(const CanMessageFormat new_format); - - /** - * @brief Set format_ member value. Deducing from the can_id - * of a canfd_frame. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param uint32_t can_id integer from a canfd_frame - */ void set_format(const uint32_t can_id); - - /** - * @brief Set format_ member value. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param CanMessageFormat format_ class member - */ void set_flags(const uint8_t flags); - - /** - * @brief Set data_ member value. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param uint8_t data_ array with a max size of 8 elements. - */ void set_data(const __u8* new_data); - - /** - * @brief Set length_ member value. - * - * Preferred way to initialize these members by using - * convert_from_canfd_frame method. - * - * @param uint8_t length_ array with a max size of 8 elements. - */ void set_length(const uint8_t new_length); - /** - * @brief Take a canfd_frame struct to initialize class members - * - * This is the preferred way to initialize class members. - * - * @param canfd_frame struct read from can bus device. - */ + bool is_correct_to_send(); + void convert_from_canfd_frame(const std::pair<struct canfd_frame&, size_t>args); - - /** - * @brief Take all initialized class's members and build an - * canfd_frame struct that can be use to send a CAN message over - * the bus. - * - * @return canfd_frame struct built from class members. - */ canfd_frame convert_to_canfd_frame(); }; |