X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fcan-message.hpp;h=9f6a36dafbad690b8972772c72a6c4e9b4b91ae1;hb=7578df6fb02f05aea7fb69938f8a15a9c3e6c53a;hp=6e51d928e878540645dc4cb0ba2bd71b6016714c;hpb=65d08bdea23d81c5d639ab9fac428ccd87673c8d;p=apps%2Fagl-service-can-low-level.git diff --git a/src/can-message.hpp b/src/can-message.hpp index 6e51d928..9f6a36da 100644 --- a/src/can-message.hpp +++ b/src/can-message.hpp @@ -17,6 +17,7 @@ #pragma once +#include #include #include #include @@ -57,110 +58,35 @@ typedef struct CanMessage CanMessage; class can_message_t { private: uint32_t id_; /*!< uint32_t id - The ID of the message. */ + bool rtr_flag_; /*!< bool rtr_flag - Telling if the frame has RTR flag positionned. Then frame hasn't data field*/ uint8_t length_; /*!< uint8_t length - the length of the data array (max 8). */ + uint8_t flags_; /*!< unint8_t flags of a CAN FD frame. Needed if we catch FD frames.*/ CanMessageFormat format_; /*!< CanMessageFormat format - the format of the message's ID.*/ - uint8_t data_[CAN_MESSAGE_SIZE]; /*!< uint8_t data - The message's data field with a size of 8 which is the standard about CAN bus messages.*/ + std::vector data_; /*!< uint8_t data - The message's data field with a size of 8 which is the standard about CAN bus messages.*/ + + 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 format_ member value. - * - * @return CanMessageFormat format_ class member - */ + bool get_rtr_flag_() const; int get_format() const; - - /** - * @brief Retrieve data_ member value. - * - * @return uint8_t data_ pointer class member - */ + uint8_t get_flags() const; const uint8_t* get_data() const; - - /** - * @brief Retrieve length_ member value. - * - * @return uint8_t length_ class member - */ uint8_t get_length() const; - /** - * @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_id(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 format); - - /** - * @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 uint8_t 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_max_data_length(size_t nbytes); + void set_id_and_format(const uint32_t new_id); + void set_format(const CanMessageFormat new_format); + void set_format(const uint32_t can_id); + void set_flags(const uint8_t flags); + void set_data(const __u8* new_data); 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. - */ - void convert_from_canfd_frame(const canfd_frame& frame); - - /** - * @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. - */ + bool is_correct_to_send(); + + void convert_from_canfd_frame(const std::pairargs); canfd_frame convert_to_canfd_frame(); };