| AgIsoStack++
    A control-function-focused implementation of the major ISOBUS and J1939 protocols | 
A CAN Driver for the MCP2515 CAN controller. More...
#include <mcp2515_can_interface.hpp>
| Public Member Functions | |
| MCP2515CANInterface (SPIHardwarePlugin *transactionHandler, const std::uint8_t cfg1, const std::uint8_t cfg2, const std::uint8_t cfg3) | |
| Constructor for the socket CAN driver. | |
| virtual | ~MCP2515CANInterface () | 
| The destructor for SocketCANInterface. | |
| bool | get_is_valid () const override | 
| Returns if the socket connection is valid. | |
| void | close () override | 
| Closes the socket. | |
| void | open () override | 
| Connects to the socket. | |
| bool | reset () | 
| Resets the MCP2515. | |
| bool | read_frame (isobus::CANMessageFrame &canFrame) override | 
| Returns a frame from the hardware (synchronous), or falseif no frame can be read. | |
| bool | write_frame (const isobus::CANMessageFrame &canFrame) override | 
| Writes a frame to the bus (synchronous) | |
| Private Types | |
| enum class | MCPInstruction : std::uint8_t { WRITE = 0x02 , READ = 0x03 , BITMOD = 0x05 , RX_STATUS = 0xB0 , READ_STATUS = 0xA0 , RESET = 0xC0 } | 
| Some essential instructions of the MCP2515.  More... | |
| enum class | MCPRegister : std::uint8_t { CANSTAT = 0x0E , CANCTRL = 0x0F , CNF3 = 0x28 , CNF2 = 0x29 , CNF1 = 0x2A , CANINTE = 0x2B , CANINTF = 0x2C , TXB0CTRL = 0x30 , TXB0SIDH = 0x31 , TXB1CTRL = 0x40 , TXB1SIDH = 0x41 , TXB2CTRL = 0x50 , TXB2SIDH = 0x51 , RXB0CTRL = 0x60 , RXB0DATA = 0x66 , RXB1CTRL = 0x70 , RXB1DATA = 0x76 } | 
| Some essential registers of the MCP2515.  More... | |
| enum class | MCPMode : std::uint8_t { NORMAL = 0x00 , SLEEP = 0x20 , LOOPBACK = 0x40 , LISTEN_ONLY = 0x60 , CONFIG = 0x80 } | 
| The different modes of the MCP2515 associated with their internal bits.  More... | |
| Private Member Functions | |
| bool | get_read_status (std::uint8_t &status) | 
| Read the rx status of the mcp2515. | |
| bool | read_register (const MCPRegister address, std::uint8_t &data) | 
| read a single byte register of the mcp2515 | |
| bool | read_register (const MCPRegister address, std::uint8_t *data, const std::size_t length) | 
| read multiple byte register of the mcp2515 | |
| bool | modify_register (const MCPRegister address, const std::uint8_t mask, const std::uint8_t data) | 
| modify a register of the mcp2515 | |
| bool | write_register (const MCPRegister address, const std::uint8_t data) | 
| write a single byte register of the mcp2515 | |
| bool | write_register (const MCPRegister address, const std::uint8_t data[], const std::size_t length) | 
| write multiple byte register of the mcp2515 | |
| bool | write_reset () | 
| Reset the mcp2515 internally. | |
| bool | set_mode (const MCPMode mode) | 
| set the mode of the mcp2515 | |
| bool | read_frame (isobus::CANMessageFrame &canFrame, const MCPRegister ctrlRegister, const MCPRegister dataRegister, const std::uint8_t intfMask) | 
| Read a frame from a buffer on the mcp2515. | |
| bool | write_frame (const isobus::CANMessageFrame &canFrame, const MCPRegister ctrlRegister, const MCPRegister sidhRegister) | 
| Write a frame to a buffer on the mcp2515. | |
| Private Attributes | |
| SPIHardwarePlugin * | transactionHandler | 
| The SPI transaction handler. | |
| std::uint8_t | rxIndex = 0 | 
| The index of the rx buffer to read from next. | |
| std::uint8_t | txIndex = 2 | 
| The index of the tx buffer to write to next, start with 2 as it is the buffer with the highest priority. | |
| std::uint8_t | txPriority = 3 | 
| The priority of the next tx frame. | |
| const std::uint8_t | cfg1 | 
| Configuration value for CFG1 register. | |
| const std::uint8_t | cfg2 | 
| Configuration value for CFG2 register. | |
| const std::uint8_t | cfg3 | 
| Configuration value for CFG3 register. | |
| bool | initialized = false | 
| If the mcp2515 has been initialized and no errors have occurred. | |
| Static Private Attributes | |
| static constexpr std::uint32_t | RECEIVE_MESSAGE_READ_RATE = 10 | 
| Hardcoded time in ms between polling the MCP2515 module for new messages, mostly arbitrary. | |
A CAN Driver for the MCP2515 CAN controller.
Definition at line 29 of file mcp2515_can_interface.hpp.
| 
 | strongprivate | 
Some essential instructions of the MCP2515.
Definition at line 68 of file mcp2515_can_interface.hpp.
| 
 | strongprivate | 
The different modes of the MCP2515 associated with their internal bits.
Definition at line 101 of file mcp2515_can_interface.hpp.
| 
 | strongprivate | 
Some essential registers of the MCP2515.
Definition at line 79 of file mcp2515_can_interface.hpp.
| isobus::MCP2515CANInterface::MCP2515CANInterface | ( | SPIHardwarePlugin * | transactionHandler, | 
| const std::uint8_t | cfg1, | ||
| const std::uint8_t | cfg2, | ||
| const std::uint8_t | cfg3 ) | 
Constructor for the socket CAN driver.
| [in] | transactionHandler | The SPI transaction handler | 
| [in] | cfg1 | The configuration value for CFG register 1 | 
| [in] | cfg2 | The configuration value for CFG register 2 | 
| [in] | cfg3 | The configuration value for CFG register 3 | 
Definition at line 19 of file mcp2515_can_interface.cpp.
| 
 | virtual | 
The destructor for SocketCANInterface.
Definition at line 27 of file mcp2515_can_interface.cpp.
| 
 | overridevirtual | 
Closes the socket.
Implements isobus::CANHardwarePlugin.
Definition at line 37 of file mcp2515_can_interface.cpp.
| 
 | overridevirtual | 
Returns if the socket connection is valid.
true if connected, false if not connected Implements isobus::CANHardwarePlugin.
Definition at line 32 of file mcp2515_can_interface.cpp.
| 
 | private | 
Read the rx status of the mcp2515.
| [out] | status | The status that was read | 
Definition at line 78 of file mcp2515_can_interface.cpp.
| 
 | private | 
modify a register of the mcp2515
| [in] | address | The address of the register to modify | 
| [in] | mask | The mask to apply to the register | 
| [in] | data | The data to write to the register | 
Definition at line 136 of file mcp2515_can_interface.cpp.
| 
 | overridevirtual | 
Connects to the socket.
Implements isobus::CANHardwarePlugin.
Definition at line 42 of file mcp2515_can_interface.cpp.
| 
 | overridevirtual | 
Returns a frame from the hardware (synchronous), or false if no frame can be read. 
| [in,out] | canFrame | The CAN frame that was read | 
true if a CAN frame was read, otherwise false Implements isobus::CANHardwarePlugin.
Definition at line 263 of file mcp2515_can_interface.cpp.
| 
 | private | 
Read a frame from a buffer on the mcp2515.
| [in,out] | canFrame | The frame that was read | 
| [in] | ctrlRegister | The control register of the buffer to read from | 
| [in] | dataRegister | The data register of the buffer to read from | 
| [in] | intfMask | The interrupt flag of the buffer to reset after reading | 
Definition at line 224 of file mcp2515_can_interface.cpp.
| 
 | private | 
read a single byte register of the mcp2515
| [in] | address | The address of the register to read | 
| [out] | data | The data that was read | 
Definition at line 95 of file mcp2515_can_interface.cpp.
| 
 | private | 
read multiple byte register of the mcp2515
| [in] | address | The address of the register to read | 
| [out] | data | The data that was read | 
| [in] | length | The length of the data to read | 
Definition at line 116 of file mcp2515_can_interface.cpp.
| bool isobus::MCP2515CANInterface::reset | ( | ) | 
Resets the MCP2515.
true if the reset was successful, otherwise false Definition at line 61 of file mcp2515_can_interface.cpp.
| 
 | private | 
set the mode of the mcp2515
| [in] | mode | The mode to set the mcp2515 to | 
Definition at line 201 of file mcp2515_can_interface.cpp.
| 
 | overridevirtual | 
Writes a frame to the bus (synchronous)
| [in] | canFrame | The frame to write to the bus | 
true if the frame was written, otherwise false Implements isobus::CANHardwarePlugin.
Definition at line 360 of file mcp2515_can_interface.cpp.
| 
 | private | 
Write a frame to a buffer on the mcp2515.
| [in] | canFrame | The frame to write | 
| [in] | ctrlRegister | The control register of the buffer to write to | 
| [in] | sidhRegister | The sidh register of the buffer to write to | 
Definition at line 297 of file mcp2515_can_interface.cpp.
| 
 | private | 
write a single byte register of the mcp2515
| [in] | address | The address of the register to write | 
| [in] | data | The data to write to the register | 
Definition at line 167 of file mcp2515_can_interface.cpp.
| 
 | private | 
write multiple byte register of the mcp2515
| [in] | address | The address of the register to write | 
| [in] | data | The data to write to the register | 
| [in] | length | The length of the data to write to the register | 
Definition at line 183 of file mcp2515_can_interface.cpp.
| 
 | private | 
Reset the mcp2515 internally.
Definition at line 153 of file mcp2515_can_interface.cpp.
| 
 | private | 
Configuration value for CFG1 register.
Definition at line 178 of file mcp2515_can_interface.hpp.
| 
 | private | 
Configuration value for CFG2 register.
Definition at line 179 of file mcp2515_can_interface.hpp.
| 
 | private | 
Configuration value for CFG3 register.
Definition at line 180 of file mcp2515_can_interface.hpp.
| 
 | private | 
If the mcp2515 has been initialized and no errors have occurred.
Definition at line 181 of file mcp2515_can_interface.hpp.
| 
 | staticconstexprprivate | 
Hardcoded time in ms between polling the MCP2515 module for new messages, mostly arbitrary.
Definition at line 110 of file mcp2515_can_interface.hpp.
| 
 | private | 
The index of the rx buffer to read from next.
Definition at line 175 of file mcp2515_can_interface.hpp.
| 
 | private | 
The SPI transaction handler.
Definition at line 174 of file mcp2515_can_interface.hpp.
| 
 | private | 
The index of the tx buffer to write to next, start with 2 as it is the buffer with the highest priority.
Definition at line 176 of file mcp2515_can_interface.hpp.
| 
 | private | 
The priority of the next tx frame.
Definition at line 177 of file mcp2515_can_interface.hpp.