-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflex_can_t4_plugin.hpp
63 lines (54 loc) · 2.42 KB
/
flex_can_t4_plugin.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//================================================================================================
/// @file flex_can_t4_plugin.hpp
///
/// @brief An interface for using FlexCAN_T4 on a Teensy4/4.1 device.
/// @author Adrian Del Grosso
///
/// @copyright 2023 The Open-Agriculture Developers
//================================================================================================
#ifndef FLEX_CAN_T4_PLUGIN_HPP
#define FLEX_CAN_T4_PLUGIN_HPP
#include "FlexCAN_T4.hpp"
#include "can_hardware_plugin.hpp"
#include "can_hardware_abstraction.hpp"
#include "can_message_frame.hpp"
namespace isobus
{
/// @brief An interface for using FlexCAN_T4 on a Teensy4/4.1 device
class FlexCANT4Plugin : public CANHardwarePlugin
{
public:
/// @brief Constructor for the FlexCANT4Plugin
/// @param[in] channel The channel to use on the device
explicit FlexCANT4Plugin(std::uint8_t channel);
/// @brief The destructor for FlexCANT4Plugin
virtual ~FlexCANT4Plugin() = default;
/// @brief Returns if the connection with the hardware is valid
/// @returns `true` if connected, `false` if not connected
bool get_is_valid() const override;
/// @brief Closes the connection to the hardware
void close() override;
/// @brief Connects to the hardware you specified in the constructor's channel argument
void open() override;
/// @brief Returns a frame from the hardware (synchronous), or `false` if no frame can be read.
/// @param[in, out] canFrame The CAN frame that was read
/// @returns `true` if a CAN frame was read, otherwise `false`
bool read_frame(isobus::CANMessageFrame &canFrame) override;
/// @brief Writes a frame to the bus (synchronous)
/// @param[in] canFrame The frame to write to the bus
/// @returns `true` if the frame was written, otherwise `false`
bool write_frame(const isobus::CANMessageFrame &canFrame) override;
private:
#if defined(__IMXRT1062__)
static FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_512> can0;
static FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_512> can1;
static FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_512> can2;
#elif defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
static FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_512> can0;
static FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_512> can1;
#endif
std::uint8_t selectedChannel; ///< The channel that this plugin is assigned to
bool isOpen = false; ///< Tracks if the connection is open/connected
};
}
#endif // FLEX_CAN_T4_PLUGIN_HPP