14#include "isobus/utility/to_string.hpp"
47 long tempHandle = CanalOpen(
name.c_str(), 0);
56 LOG_CRITICAL(
"[TouCAN]: Error trying to connect to TouCAN probe. Check your device ID and serial number.");
62 long result = CANAL_ERROR_GENERIC;
63 structCanalMsg CANMsg = { 0 };
65 result = CanalReceive(
handle, &CANMsg);
67 if (CANAL_ERROR_SUCCESS == result)
70 memcpy(canFrame.
data, CANMsg.data,
sizeof(canFrame.
data));
72 canFrame.
isExtendedFrame = (0 != (CANAL_IDFLAG_EXTENDED & CANMsg.flags));
77 std::this_thread::sleep_for(std::chrono::milliseconds(1));
79 return (CANAL_ERROR_SUCCESS == result);
84 std::uint32_t result = CANAL_ERROR_SUCCESS;
85 structCanalMsg msgCanMessage;
89 msgCanMessage.flags = canFrame.
isExtendedFrame ? CANAL_IDFLAG_EXTENDED : CANAL_IDFLAG_STANDARD;
92 result = CanalSend(
handle, &msgCanMessage);
94 return (CANAL_ERROR_SUCCESS == result);
116 std::string deviceConfigString;
117 std::string serialString;
118 constexpr std::uint32_t MAX_SERIAL_LENGTH = 999999999;
119 constexpr std::size_t SERIAL_NUMBER_CHARACTER_REQUIREMENT = 8;
121 if (serialNumber > MAX_SERIAL_LENGTH)
123 LOG_CRITICAL(
"[TouCAN]: Invalid serial number. Must be 8 digits max.");
127 serialString = isobus::to_string(serialNumber);
129 if (SERIAL_NUMBER_CHARACTER_REQUIREMENT > serialString.length())
131 serialString.insert(0, SERIAL_NUMBER_CHARACTER_REQUIREMENT - serialString.length(),
'0');
134 deviceConfigString += isobus::to_string(deviceID) +
';';
135 deviceConfigString += serialString +
';';
136 deviceConfigString += isobus::to_string(baudRate) +
';';
137 name = deviceConfigString;
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
A CAN frame for interfacing with a hardware layer, like socket CAN or other interface.
std::uint8_t dataLength
The length of the data used in the frame.
std::uint32_t identifier
The 32 bit identifier of the frame.
std::uint64_t timestamp_us
A microsecond timestamp.
bool isExtendedFrame
Denotes if the frame is extended format.
std::uint8_t data[8]
The data payload of the frame.
virtual ~TouCANPlugin()
The destructor for TouCANPlugin.
std::uint32_t currentlyConfiguredSerialNumber
The serial number of the device that is being used.
void close() override
Closes the connection to the hardware.
TouCANPlugin(std::int16_t deviceID, std::uint32_t serialNumber, std::uint16_t baudRate=250)
Constructor for a TouCAN hardware plugin object.
std::string name
A configuration string that is used to connect to the hardware through the CANAL api.
bool write_frame(const isobus::CANMessageFrame &canFrame) override
Writes a frame to the bus (synchronous)
std::uint32_t handle
The handle that the driver returns to us for the open hardware.
void open() override
Connects to the hardware.
void generate_device_name(std::int16_t deviceID, std::uint32_t serialNumber, std::uint16_t baudRate)
Generates a device name string for the TouCAN device.
std::uint32_t openResult
Stores the result of the call to begin CAN communication. Used for is_valid check later.
std::uint32_t get_serial_number() const
Returns the currently configured serial number of the device which will be used to connect to the har...
bool reconfigure(std::int16_t deviceID, std::uint32_t serialNumber, std::uint16_t baudRate=250)
Changes previously set configuration parameters. Only works if the device is not open.
bool read_frame(isobus::CANMessageFrame &canFrame) override
Returns a frame from the hardware (synchronous), or false if no frame can be read.
bool get_is_valid() const override
Returns if the connection with the hardware is valid.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
An interface for using a Rusoku TouCAN device via the VSCP CANAL api.