X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fcan-bus.hpp;h=bc2bb04c2f8260b30682fc0eeba408d1826ee771;hb=7578df6fb02f05aea7fb69938f8a15a9c3e6c53a;hp=f7cb3121b83dbacb08d5323cff404c90d2ce087e;hpb=d6c1b80cdbd87df96f3f648d67ccdbba6794f957;p=apps%2Fagl-service-can-low-level.git diff --git a/src/can-bus.hpp b/src/can-bus.hpp index f7cb3121..bc2bb04c 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_q_; /*!< queue that'll store can_message_t to decoded */ @@ -84,108 +71,23 @@ class can_bus_t { std::map> 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 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> 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 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); };