-
-
-/**
- * @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);
-};
-
-/** TODO: implement this function as method into can_bus class
- * @fn void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
- * @brief Pre initialize actions made before CAN bus initialization
- *
- * @param[in] can_bus_dev_t bus - A CanBus struct defining the bus's metadata
- * @param[in] bool writable - configure the controller in a writable mode. If false, it will be
- * configured as "listen only" and will not allow writes or even CAN ACKs.
- * @param[in] buses - An array of all CAN buses.
- * @param[in] int busCount - The length of the buses array.
- */
-void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
-
-/** TODO: implement this function as method into can_bus class
- * @fn void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
- * @brief Post-initialize actions made after CAN bus initialization
- *
- * @param[in] bus - A CanBus struct defining the bus's metadata
- * @param[in] writable - configure the controller in a writable mode. If false, it will be
- * configured as "listen only" and will not allow writes or even CAN ACKs.
- * @param[in] buses - An array of all CAN buses.
- * @param[in] busCount - The length of the buses array.
- */
-void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
-
-/** TODO: implement this function as method into can_bus class
- * @fn bool isBusActive(can_bus_dev_t* bus);
- * @brief Check if the device is connected to an active CAN bus, i.e. it's
- * received a message in the recent past.
- *
- * @return true if a message was received on the CAN bus within
- * CAN_ACTIVE_TIMEOUT_S seconds.
- */
-bool isBusActive(can_bus_dev_t* bus);
-
-/** TODO: implement this function as method into can_bus class
- *
- * @fn void logBusStatistics(can_bus_dev_t* buses, const int busCount);
- * @brief Log transfer statistics about all active CAN buses to the debug log.
- *
- * @param[in] buses - an array of active CAN buses.
- * @param[in] busCount - the length of the buses array.
- */
-void logBusStatistics(can_bus_dev_t* buses, const int busCount);
\ No newline at end of file