|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |
Launch files
Messages
Services
Plugins
Recent questions tagged socketcan_adapter at Robotics Stack Exchange
|
socketcan_adapter package from socketcan_adapter reposocketcan_adapter socketcan_adapter_ros |
ROS Distro
|
Package Summary
| Version | 0.1.0 |
| License | Apache-2.0 |
| Build type | AMENT_CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/polymathrobotics/socketcan_adapter.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-03-09 |
| Dev Status | MAINTAINED |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Polymath Engineering
Authors
- Zeerek Ahmad
socketcan_adapter
A C++ SocketCAN driver library for Linux-based systems. This library provides a high-level interface to Linux SocketCAN without any ROS dependencies.
Classes of Note
CanFrame
CanFrame Class - This class wraps the C-level can_frame structure, encapsulating CAN message details like the CAN ID, data, timestamp, and frame type (DATA, ERROR, or REMOTE). By providing a robust API for creating and managing CAN frames, CanFrame simplifies interaction with raw CAN data and offers utilities like ID masking, setting error types, and timestamp management.
Example highlights:
- Flexible constructors for
can_framestruct and raw data inputs. - Functions to modify frame type, ID type (standard/extended), and length.
- Helper methods to access CAN frame data, ID.
Does not implement CanFD yet.
SocketcanAdapter
SocketcanAdapter Class - The SocketcanAdapter abstracts and manages socket operations for CAN communication. It initializes and configures the socket, applies filters, and handles CAN frame transmission and reception. The adapter offers error handling, thread-safe operations, and optional callback functions for asynchronous frame and error processing.
Key features:
- Configurable receive timeout and threading for reception.
-
setFiltersand setErrorMaskOverwrite to apply CAN filters and error masks. - A callback-based system for handling received frames and errors asynchronously.
- Supports multiple send and receive methods, including
std::shared_ptrfor efficient memory management. - Together,
CanFrameandSocketcanAdaptersimplify interaction with CAN networks, allowing developers to focus on high-level application logic instead of low-level socket and data handling.
Build
This package can be built with the ROS2 ament toolchain or as a standalone CMake project.
ROS2 Build
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter
Build:
colcon build --packages-select socketcan_adapter
Standalone CMake Build
mkdir build && cd build
cmake ..
make
Sample Usage
```c++
#include “socketcan_adapter/socketcan_adapter.hpp”
#include “socketcan_adapter/can_frame.hpp”
#include
using namespace polymath::socketcan;
int main() { // Initialize SocketcanAdapter with the CAN interface name (e.g., “can0”) SocketcanAdapter adapter(“can0”);
// Open the CAN socket
if (!adapter.openSocket()) {
std::cerr << "Failed to open CAN socket!" << std::endl;
return -1;
}
// Step 1: Set up a filter to allow only messages with ID 0x123
std::vector<struct can_filter> filters = {{0x123, CAN_SFF_MASK}};
if (auto error = adapter.setFilters(filters)) {
std::cerr << "Error setting filters: " << *error << std::endl;
return -1;
}
// Step 2: Set up a callback function to handle received CAN frames
adapter.setOnReceiveCallback([](std::unique_ptr<const CanFrame> frame) {
std::cout << "Received CAN frame with ID: " << std::hex << frame->get_id() << std::endl;
auto data = frame->get_data();
std::cout << "Data: ";
for (const auto& byte : data) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
});
// Step 3: Start the reception thread
if (!adapter.startReceptionThread()) {
std::cerr << "Failed to start reception thread!" << std::endl;
adapter.closeSocket();
return -1;
}
// Step 4: Prepare a CAN frame to send
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| socketcan_adapter_ros |