• Stars
    star
    289
  • Rank 143,419 (Top 3 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created almost 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An implementation of the ISO-TP (ISO15765-2) CAN protocol in C

ISO-TP (ISO 15765-2) Support Library in C

This is a platform agnostic C library that implements the ISO 15765-2 (also known as ISO-TP) protocol, which runs over a CAN bus. Quoting Wikipedia:

ISO 15765-2, or ISO-TP, is an international standard for sending data packets over a CAN-Bus. The protocol allows for the transport of messages that exceed the eight byte maximum payload of CAN frames. ISO-TP segments longer messages into multiple frames, adding metadata that allows the interpretation of individual frames and reassembly into a complete message packet by the recipient. It can carry up to 4095 bytes of payload per message packet.

This library doesn't assume anything about the source of the ISO-TP messages or the underlying interface to CAN. It uses dependency injection to give you complete control.

The current version supports only single frame ISO-TP messages. This is fine for OBD-II diagnostic messages, for example, but this library needs some additional work before it can support sending larger messages.

Usage

First, create some shim functions to let this library use your lower level system:

// required, this must send a single CAN message with the given arbitration
// ID (i.e. the CAN message ID) and data. The size will never be more than 8
// bytes.
bool send_can(const uint32_t arbitration_id, const uint8_t* data,
        const uint8_t size) {
    ...
}

// optional, provide to receive debugging log messages
void debug(const char* format, ...) {
    ...
}


// not used in the current version
bool set_timer(uint16_t time_ms, void (*callback)) {
    ...
}

With your shims in place, create an IsoTpShims object to pass them around:

IsoTpShims shims = isotp_init_shims(debug, send_can, set_timer);

API

With your shims in hand, send an ISO-TP message:

// Optional: This is your callback that will be called when the message is
// completely sent. If it was single frame (the only type supported right
// now), this will be called immediately.
void message_sent(const IsoTpMessage* message, const bool success) {
    // You received the message! Do something with it.
}

IsoTpSendHandle handle = isotp_send(&shims, 0x100, NULL, 0, message_sent);

if(handle.completed) {
    if(!handle.success) {
        // something happened and it already failed - possibly we aren't able to
        // send CAN messages
        return;
    } else {
        // If the message fit in a single frame, it's already been sent
        // and you're done
    }
} else {
    while(true) {
        // Continue to read from CAN, passing off each message to the handle
        // this will return true when the message is completely sent (which
        // may take more than one call if it was multi frame and we're waiting
        // on flow control responses from the receiver)
        bool complete = isotp_continue_send(&shims, &handle, 0x100, data, size);

        if(complete && handle.completed) {
            if(handle.success) {
                // All frames of the message have now been sent, following
                // whatever flow control feedback it got from the receiver
            } else {
                // the message was unable to be sent and we bailed - fatal
                // error!
            }
        }
    }
}

Finally, receive an ISO-TP message:

// Optional: This is your callback for when a complete ISO-TP message is
// received at the arbitration ID you specify. The completed message is
// also returned by isotp_continue_receive, which can sometimes be more
// useful since you have more context.
void message_received(const IsoTpMessage* message) {
}

IsoTpReceiveHandle handle = isotp_receive(&shims, 0x100, message_received);
if(!handle.success) {
    // something happened and it already failed - possibly we aren't able to
    // send CAN messages
} else {
    while(true) {
        // Continue to read from CAN, passing off each message to the handle
        IsoTpMessage message = isotp_continue_receive(&shims, &handle, 0x100, data, size);

        if(message.completed && handle.completed) {
            if(handle.success) {
                // A message has been received successfully
            } else {
                // Fatal error - we weren't able to receive a message and
                // gave up trying. A message using flow control may have
                // timed out.
            }
        }
    }
}

Testing

The library includes a test suite that uses the check C unit test library.

$ make test

You can also see the test coverage if you have lcov installed and the BROWSER environment variable set to your choice of web browsers:

$ BROWSER=google-chrome-stable make coverage

Authors

License

Copyright (c) 2013 Ford Motor Company

Licensed under the BSD license.

More Repositories

1

uds-c

Unified Diagnostics Service (UDS) and OBD-II (On Board Diagnostics for Vehicles) C Library
C
617
star
2

android-webcam

Android library to access a USB webcam feed
C
323
star
3

openxc-android

Android library for accessing vehicle data from an OpenXC vehicle interface
Java
230
star
4

vi-firmware

OpenXC-compatible firmware for PIC32 and LPC1768
C++
194
star
5

openxc-python

OpenXC Python library
Python
109
star
6

openxc-message-format

Specification for the OpenXC JSON message format
C
97
star
7

bitfield-c

Bit array parsing and encoding utility library in C
C
85
star
8

AT-commander

A C library to control a device via UART that responds to an AT command set (like an RN-42)
C
75
star
9

openxc-vehicle-simulator

Python
62
star
10

openxcplatform.com

Static website for openxcplatform.com
HTML
40
star
11

reference-vi

Open Source Hardware Schematics for OpenXC Vehicle Interface
HTML
38
star
12

bluetooth-audio-passthrough

Open source schematics for Bluetooth audio passthrough
21
star
13

nxpUSBlib

Fork of NXP's USB library for all LPC microcontrollers, with bug fixes
C
20
star
14

emhashmap

This library is an implementation of a hash map in C that maps integers to void pointers
C
20
star
15

web-logging-example

Example OpenXC web application in Python for vehicle data logging
Python
17
star
16

diagnostic-tool

OpenXC Android Tool for Sending OBD-II Requests to a Vehicle Interface
Java
16
star
17

rearview-camera

Rearview camera implemented as an Android app with OpenXC
Java
16
star
18

openxc-starter

OpenXC "hello world."
Java
15
star
19

openxc-ios-framework

OpenXC iOS framework for use with the C5 BLE device. Also see the openxc-ios-app-demo.
Swift
14
star
20

trace-analyzer

JavaScript visualization of OpenXC vehicle data traces
JavaScript
12
star
21

nxp-cdl

Fork with slight modifications to NXP's Common Driver Library, for LPCxxxx Microcontrollers
C
12
star
22

nightvision

Video-based object detection for forward collision warnings with OpenXC
Java
9
star
23

emqueue

An implementation of a queue in C that can support arbirtary element types.
C
9
star
24

arduino-transfer-benchmarking

Benchmarking USB and FTDI transfer rates on Arduino-compatible microcontrollers
C
8
star
25

openxc-ios-library

OpenXC iOS framework for use with the C5 BLE device. Example contains the OpenXC demonstration app that use all of the features of the OpenXC Framework.
Swift
8
star
26

nonstandard-android-measurements

Non-standard OpenXC Measurement and Unit types for Android
Java
7
star
27

emlist

A simple linked list in C for embedded applications
C
7
star
28

openxc-ios-app-demo

OpenXC demonstration app that use all of the features of the openxc-ios-framework. This can be a starting app for any OpenXC iOS application that wishes to use the C5 BLE device.
HTML
6
star
29

OpenXCAccessory

Contents of OpenXCAccessory directory on V2X and Modem devices
Python
6
star
30

shiftknob-android

Android application to control the OpenXC-enabled Haptic Shift Knob
Java
6
star
31

mpg

Java
5
star
32

openxc-c

C library to access data from an OpenXC vehicle interface
C
5
star
33

shiftknob-3Ddesign

3D design sources for the OpenXC-enabled Haptic Shift Knob
Perl
5
star
34

simple-hud

Firmware and Java connector for a Bluetooth-connected OpenXC module
Java
4
star
35

chipkit-vehicle-interface

Assembly instructions for a chipKIT-based OpenXC Vehicle Interface
CSS
3
star
36

smart-wiper

Java
3
star
37

openxc-data-tools

Python tools for OpenXC data analysis and visualization
Python
3
star
38

vi-windows-driver

Windows driver for USB OpenXC Vehicle Interface
3
star
39

rain

Android application to provide rain detection information to Weather Underground
Java
3
star
40

shiftknob-firmware

Embedded (Arduino) firmware for OpenXC-enabled Haptic Shift Knob
Arduino
2
star
41

MLA

Microchip Library Access for use on OpenXC vi-firmware
C
2
star
42

SimCrashDetection

Crash detection library for app testing purposes, triggers an event when crash is detected (currently crude algorithm)
Java
2
star
43

validation-android

Validation app used to verify signals from VI
Java
2
star
44

pixel-openxc-android

A smart brake light prototype using the pixelart board(http://ledpixelart.com/) utilizing the OpenXC platform (http://openxcplatform.com)
Java
2
star
45

shiftknob-hardware

Electrical schematics for the OpenXC-enabled Haptic Shift Knob
Ruby
1
star
46

EV_Coach_public

Continuation of the Ford EV Coach Efficiency Application Trainer
Java
1
star
47

SignalMonitor

Application to send all OpenXC signals only when a monitored signal crosses a designated threshold
1
star
48

nxp-bsp

Fork with slight modifications to NXP's Board Support Package, for LPCxxxx Microcontrollers
C
1
star
49

io-accessory

Open source schematics for a generic I/O extension for the OpenXC platform
1
star