Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
jazzy

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
kilted

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
rolling

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro ardent showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro bouncy showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro crystal showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro eloquent showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro dashing showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro galactic showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro foxy showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro iron showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro lunar showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro jade showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro indigo showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro hydro showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro kinetic showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro melodic showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange

No version for distro noetic showing humble. Known supported distros are highlighted in the buttons above.
Package symbol

socketcan_adapter package from socketcan_adapter repo

socketcan_adapter socketcan_adapter_ros

ROS Distro
humble

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

An Adapter Library for Socketcan using Callback Patterns

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_frame struct 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.
  • setFilters and 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_ptr for efficient memory management.
  • Together, CanFrame and SocketcanAdapter simplify 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 #include #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

CHANGELOG
No CHANGELOG found.

Package Dependencies

System Dependencies

Name
catch2

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged socketcan_adapter at Robotics Stack Exchange