Skip to content

A simple JNI wrapper for the socketcan API provided by the Linux kernel. As it is wrapping a Linux Kernel API, it is intended for use on Linux only.

License

Notifications You must be signed in to change notification settings

mvitorovic/JavaCAN

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaCAN Maven Central

A complete implementation of Java's SelectableChannel API for CAN_RAW, CAN_BCM and CAN_ISOTP sockets.

Even though the JDK provides an epoll based Selector implementation, that implementation is unfortunately not compatible with custom Channel implementations. For that reason a custom SelectorProvider is required, that supplies an epoll based Selector compatible with CAN Channels.

What works?

  • Creating and binding CAN_RAW, CAN_BCM and CAN_ISOTP sockets
  • Sending and receiving standard CAN and CAN-FD frames with and without EFF
  • Getting and setting all supported socket options
  • Event-driven networking using a Selector
  • Rough test coverage

What is missing?

  • Support for other CAN protocols (e.g. CAN_MCNET)

Related Projects

  • obd4s: A Scala library for OBD-II communication with vehicles.
  • VirtualECU: An ECU simulator to test OBD-II clients against.

Supported Operating Systems

This project is a wrapper around SocketCAN, which is a Linux kernel module that implements CAN communication. As such, only Linux can be supported. For this reason, the custom Selector will also only use epoll (Linux API for event-driven IO), as support for other OS' is not possible anyway.

Supported Architectures

The project uses dockcross to cross-compile its native components for various Linux supported platforms.

Currently the full build process includes the following architectures:

  • x86_32
  • x86_64
  • armv7
  • aarch64

The implementation can handle word sizes up to 64 bit and is byte order aware.

How to use

CAN_RAW, CAN_BCM and CAN_ISOTP channels

  1. Compile yourself or get a compiled release from Maven Central
  2. Create a channel by calling one of the CanChannels.new...Channel() methods
  3. Create a NetworkDevice using its static lookup(String) method
  4. Bind the channel to an interface using the bind(CanDevice) method

Usage example can be found in the unit tests.

How to build

Prerequisites

For compilation:

  • Maven 3 or newer
  • A locally running docker daemon and permissions to run containers
  • Java 10 or newer installed
  • Bash

For tests:

  • The can-isotp kernel module loaded
  • can-utils installed in the PATH
  • A real or virtual CAN interface named "vcan0"

For usage:

  • A recent Linux kernel with CAN support
  • For ISOTP channels, the can-isotp kernel module must be loaded
  • Java 8 or newer installed
  • A few kilobytes of disk space to extract the native library

Building

  1. mvn clean package
  2. profit

About

A simple JNI wrapper for the socketcan API provided by the Linux kernel. As it is wrapping a Linux Kernel API, it is intended for use on Linux only.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 77.1%
  • C 22.3%
  • Shell 0.6%