WPILibC++ 2023.4.3
|
High level class for interfacing with CAN devices conforming to the standard CAN spec. More...
#include <frc/CAN.h>
Public Member Functions | |
CAN (int deviceId) | |
Create a new CAN communication interface with the specific device ID. More... | |
CAN (int deviceId, int deviceManufacturer, int deviceType) | |
Create a new CAN communication interface with a specific device ID, manufacturer and device type. More... | |
~CAN () | |
Closes the CAN communication. More... | |
CAN (CAN &&)=default | |
CAN & | operator= (CAN &&)=default |
void | WritePacket (const uint8_t *data, int length, int apiId) |
Write a packet to the CAN device with a specific ID. More... | |
void | WritePacketRepeating (const uint8_t *data, int length, int apiId, int repeatMs) |
Write a repeating packet to the CAN device with a specific ID. More... | |
void | WriteRTRFrame (int length, int apiId) |
Write an RTR frame to the CAN device with a specific ID. More... | |
int | WritePacketNoError (const uint8_t *data, int length, int apiId) |
Write a packet to the CAN device with a specific ID. More... | |
int | WritePacketRepeatingNoError (const uint8_t *data, int length, int apiId, int repeatMs) |
Write a repeating packet to the CAN device with a specific ID. More... | |
int | WriteRTRFrameNoError (int length, int apiId) |
Write an RTR frame to the CAN device with a specific ID. More... | |
void | StopPacketRepeating (int apiId) |
Stop a repeating packet with a specific ID. More... | |
bool | ReadPacketNew (int apiId, CANData *data) |
Read a new CAN packet. More... | |
bool | ReadPacketLatest (int apiId, CANData *data) |
Read a CAN packet. More... | |
bool | ReadPacketTimeout (int apiId, int timeoutMs, CANData *data) |
Read a CAN packet. More... | |
Static Public Attributes | |
static constexpr HAL_CANManufacturer | kTeamManufacturer = HAL_CAN_Man_kTeamUse |
static constexpr HAL_CANDeviceType | kTeamDeviceType |
High level class for interfacing with CAN devices conforming to the standard CAN spec.
No packets that can be sent gets blocked by the RoboRIO, so all methods work identically in all robot modes.
All methods are thread save, however the buffer objects passed in by the user need to not be modified for the duration of their calls.
|
explicit |
Create a new CAN communication interface with the specific device ID.
This uses the team manufacturer and device types. The device ID is 6 bits (0-63)
deviceId | The device id |
frc::CAN::CAN | ( | int | deviceId, |
int | deviceManufacturer, | ||
int | deviceType | ||
) |
Create a new CAN communication interface with a specific device ID, manufacturer and device type.
The device ID is 6 bits, the manufacturer is 8 bits, and the device type is 5 bits.
deviceId | The device ID |
deviceManufacturer | The device manufacturer |
deviceType | The device type |
frc::CAN::~CAN | ( | ) |
Closes the CAN communication.
|
default |
bool frc::CAN::ReadPacketLatest | ( | int | apiId, |
CANData * | data | ||
) |
Read a CAN packet.
The will continuously return the last packet received, without accounting for packet age.
apiId | The API ID to read. |
data | Storage for the received data. |
bool frc::CAN::ReadPacketNew | ( | int | apiId, |
CANData * | data | ||
) |
Read a new CAN packet.
This will only return properly once per packet received. Multiple calls without receiving another packet will return false.
apiId | The API ID to read. |
data | Storage for the received data. |
bool frc::CAN::ReadPacketTimeout | ( | int | apiId, |
int | timeoutMs, | ||
CANData * | data | ||
) |
Read a CAN packet.
The will return the last packet received until the packet is older then the requested timeout. Then it will return false.
apiId | The API ID to read. |
timeoutMs | The timeout time for the packet |
data | Storage for the received data. |
void frc::CAN::StopPacketRepeating | ( | int | apiId | ) |
Stop a repeating packet with a specific ID.
This ID is 10 bits.
apiId | The API ID to stop repeating |
void frc::CAN::WritePacket | ( | const uint8_t * | data, |
int | length, | ||
int | apiId | ||
) |
Write a packet to the CAN device with a specific ID.
This ID is 10 bits.
data | The data to write (8 bytes max) |
length | The data length to write |
apiId | The API ID to write. |
int frc::CAN::WritePacketNoError | ( | const uint8_t * | data, |
int | length, | ||
int | apiId | ||
) |
Write a packet to the CAN device with a specific ID.
This ID is 10 bits.
data | The data to write (8 bytes max) |
length | The data length to write |
apiId | The API ID to write. |
void frc::CAN::WritePacketRepeating | ( | const uint8_t * | data, |
int | length, | ||
int | apiId, | ||
int | repeatMs | ||
) |
Write a repeating packet to the CAN device with a specific ID.
This ID is 10 bits. The RoboRIO will automatically repeat the packet at the specified interval
data | The data to write (8 bytes max) |
length | The data length to write |
apiId | The API ID to write. |
repeatMs | The period to repeat the packet at. |
int frc::CAN::WritePacketRepeatingNoError | ( | const uint8_t * | data, |
int | length, | ||
int | apiId, | ||
int | repeatMs | ||
) |
Write a repeating packet to the CAN device with a specific ID.
This ID is 10 bits. The RoboRIO will automatically repeat the packet at the specified interval
data | The data to write (8 bytes max) |
length | The data length to write |
apiId | The API ID to write. |
repeatMs | The period to repeat the packet at. |
void frc::CAN::WriteRTRFrame | ( | int | length, |
int | apiId | ||
) |
Write an RTR frame to the CAN device with a specific ID.
This ID is 10 bits. The length by spec must match what is returned by the responding device
length | The length to request (0 to 8) |
apiId | The API ID to write. |
int frc::CAN::WriteRTRFrameNoError | ( | int | length, |
int | apiId | ||
) |
Write an RTR frame to the CAN device with a specific ID.
This ID is 10 bits. The length by spec must match what is returned by the responding device
length | The length to request (0 to 8) |
apiId | The API ID to write. |
|
staticconstexpr |
|
staticconstexpr |