X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fcan-utils.hpp;h=d945be4c6020dcc7e6467b52f8d6ac5e657f037c;hb=836feaecd602e86ea6d954ae018a2d7bbc04aa7a;hp=d1310a6daa1c29b8a10a05072ecccac0c93671e5;hpb=ef610b379f59f89350f6f9dd8ff11a00066e2c05;p=apps%2Fagl-service-can-low-level.git diff --git a/src/can-utils.hpp b/src/can-utils.hpp index d1310a6d..d945be4c 100644 --- a/src/can-utils.hpp +++ b/src/can-utils.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "timer.hpp" @@ -115,60 +116,29 @@ typedef struct CanMessage CanMessage; */ class can_message_t { private: - const struct afb_binding_interface *interface_; + const struct afb_binding_interface* interface_; uint32_t id_; CanMessageFormat format_; - uint8_t data_[CAN_MESSAGE_SIZE]; + uint8_t data_; uint8_t length_; public: + can_message_t(const struct afb_binding_interface* interface); + uint32_t get_id() const; int get_format() const; - uint8_t get_data() const; - uint8_t get_lenght() const; + const uint8_t* get_data() const; + uint8_t get_length() const; - void set_id(uint32_t id); - void set_format(CanMessageFormat format); - void set_data(uint8_t data); - void set_lenght(uint8_t length); + void set_id(const uint32_t new_id); + void set_format(const CanMessageFormat format); + void set_data(const uint8_t new_data); + void set_length(const uint8_t new_length); - void convert_from_canfd_frame(canfd_frame frame); + void convert_from_canfd_frame(const canfd_frame& frame); canfd_frame convert_to_canfd_frame(); }; -/** - * @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. - * - * @params[in] std::string device_name_ - name of the linux device handling the can bus. Generally vcan0, can0, etc. - */ -class can_bus_dev_t { - private: - std::string device_name_; - int can_socket_; - bool is_fdmode_on_; - struct sockaddr_can txAddress_; - - bool has_can_message_; - std::queue can_message_q_; - - std::thread th_reading_; - bool is_running_; - - public: - can_bus_dev_t(const std::string& dev_name); - - int open(const struct afb_binding_interface* interface); - int close(); - bool is_running(); - void start_reading(); - canfd_frame read(const struct afb_binding_interface *interface); - - can_message_t next_can_message(); - void push_new_can_message(const can_message_t& can_msg); - bool has_can_message() const; -}; - /** * @brief Object used to handle decoding and manage event queue to be pushed. * @@ -177,29 +147,63 @@ class can_bus_dev_t { */ class can_bus_t { private: - const struct afb_binding_interface *interface_; int conf_file_; std::thread th_decoding_; std::thread th_pushing_; + bool has_can_message_; + std::queue can_message_q_; + bool has_vehicle_message_; std::queue vehicle_message_q_; public: + const struct afb_binding_interface *interface_; + can_bus_t(const struct afb_binding_interface *itf, int& conf_file); int init_can_dev(); std::vector read_conf(); void start_threads(); - - int send_can_message(can_message_t can_msg); - openxc_VehicleMessage& next_vehicle_message(); + can_message_t next_can_message(); + void push_new_can_message(const can_message_t& can_msg); + bool has_can_message() const; + + openxc_VehicleMessage next_vehicle_message(); void push_new_vehicle_message(const openxc_VehicleMessage& v_msg); bool has_vehicle_message() const; }; +/** + * @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. + * + * @params[in] std::string device_name_ - name of the linux device handling the can bus. Generally vcan0, can0, etc. + */ +class can_bus_dev_t { + private: + std::string device_name_; + int can_socket_; + bool is_fdmode_on_; + struct sockaddr_can txAddress_; + + std::thread th_reading_; + bool is_running_; + + public: + can_bus_dev_t(const std::string& dev_name); + + int open(const struct afb_binding_interface* interface); + int close(); + bool is_running(); + void start_reading(can_bus_t& can_bus); + canfd_frame read(const struct afb_binding_interface *interface); + + int send_can_message(can_message_t& can_msg, const struct afb_binding_interface* interface); +}; + /** * @brief A state encoded (SED) signal's mapping from numerical values to * OpenXC state names. @@ -280,7 +284,7 @@ typedef struct CanSignal CanSignal; * @param[in] format - the format of the message's ID. * @param[in] clock - an optional frequency clock to control the output of this * message, if sent raw, or simply to mark the max frequency for custom - * handlers to retrieve. + * handlers to retriec++ if ? syntaxve. * @param[in] forceSendChanged - If true, regardless of the frequency, it will send CAN * message if it has changed when using raw passthrough. * @param[in] lastValue - The last received value of the message. Defaults to undefined. @@ -396,6 +400,6 @@ void logBusStatistics(can_bus_dev_t* buses, const int busCount); /** * @brief Function representing thread activated by can bus objects */ -void can_reader(can_bus_dev_t& can_bus); +void can_reader(can_bus_dev_t& can_bus_dev, can_bus_t& can_bus); void can_decode_message(can_bus_t& can_bus); void can_event_push(can_bus_t& can_bus); \ No newline at end of file