GithubHelp home page GithubHelp logo

davidnnaji / j1708_t4 Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 1.92 MB

J1708_T4 is a network utility library that is compatible with the Teensy 4.x. It provides a basic UART commands for displaying, measuring, and sending traffic on an SAE J1708 bus. This code was written as part of my Master's Thesis on securing legacy HD networks.

License: MIT License

C++ 100.00%
arduino teensy teensy40 teensy41 j1587 j1708 trucks

j1708_t4's Introduction

Repo Views Counter

Overview

J1708_T4 is a gateway utility library that is compatible with the Teensy 4.x. It provides basic tools for displaying, measuring, and sending traffic on an SAE J1708 bus. This code was written as part of my Master's Thesis on securing legacy HD networks.

Manual Installation

To install the library manually, you'll need to download it as a .zip file, extract it and put in the proper Arduino user library directory. The .zip file contains all you need, including a few examples on how to use it. If the library is installed properly, you should be able to see these examples in File>Examples>J1708_T4.

You can also refer to articles within Arduino forums on custom library installation if you are unfamiliar with the process.

Hardware

You'll need to incorporate a standard J1708 circuit with the Teensy 4.x to receive or transmit any messages to the serial bus. Here's a list of the minimum parts you'll need for one port.

  • (1x) Hex Inverter (NOT Gate)
  • (1x) RS485 transceiver
  • (2x) 4.7k ohm resistors
  • (2x) 47 ohm resistors
  • (Optional) LEDs

You can refer to the official standard or my own circuit implementation for inspiration.

Design

The entire library revolves around a J1708 object that is intended to represent a single port connection to the bus. This object is logically bound to a Teensy serial port on the of the users choice. All example use ports 3 and 4 by default to help avoid conflicts.

One object is enough for interacting with the bus. Two objects can be linked together to create a simple network passthrough. The example script, simplePass.ino, should provide enough information to get acquainted with instantiating an object and linking multiple objects. The following component diagram provides the exact architecture of the example script.

Gateway Architecture Component Diagram

Serial API Usage

Runtime Configuration

Help

The j1708config command is useful for adjusting the display and the device port settings during runtime. You can bring up the help page with the following command to see the available options.

j1708config <port> -h

Configuration-Help

Display Settings

For example, to adjust the display settings back to default use the following command.

j1708config <port> -s -d

Configuration-Default

Network Statistics and Errors

Basic messaging statistics are tracked by any instatiated port automatically. To view them, enter the following command:

j1708config <port> -s -s

Typical network and messaging errors are also tracked. Below is table for reference.

Error Table

Sending J1708 Messages

j1708send is useful for sending traffic to the network using a specific port during run-time. Use the -h option for more information.

Standard Message

To send a simple 4-byte message on port three, use the following command:

j1708send sp3 4 de.ed.be.ef

Configuration-Send

Transport Protocol

SAE J1587 provides rules for transporting payloads greater than 19-bytes. Every J1708 object has built-in processing and handling procedures for RTS, CTS, CDP, EOM, and Abort messages. This will only work when port processing is turned on. To send a large payload used the -T option of j1708send.

For example, to send a simple 30-byte message on port three, use the following command:

j1708send sp3 -T 30 de.ed.be.ef.de.ed.be.ef.de.ed.be.ef.de.ed.be.ef.de.ed.be.ef.de.ed.be.ef.de.ed.be.ef.de.ad

Control via Python

If the Teensy is plugged-in via USB, you can use the pyserial library to send commands to your device instead of the Arduino serial monitor. Here's an example script to get started.

import serial
myTeensy = serial.Serial('COM7',115200)
myTeensy.write(b'j1708send sp3 4 de.ed.be.ef\r\n')
myTeensy.close()

References

SAE J1708 - Official Standard

SAE J1587 - Official Standard

[MS Thesis] - (Currently embargoed. To be published 8/22/23)

Limitations

I'm a mechanical engineer doing programmer things. After writing this, I learned how to and how to not do stuff in C/C++. Bear in mind, even though my code has been unit tested, reviewed, and deployed on actual vehicle hardware, my code would certainly benefit from many more improvements. If you are interested in contributing, feel free to start an issue or reach out to me anytime!

โš ๏ธ TL;DR Be warned - the performance of this library is limited.

j1708_t4's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

systemscyber

j1708_t4's Issues

Need help understanding the TX part of the code

Hello @davidnnaji
Thank you for making this project open-source.

I am also trying to achieve the same with ESP32. connected to an RS485 Trasnreciver ic with a NOT gate on the TX pin.
As I am following your code to write the code for ESP32 but I am unable to send the MID successfully.

I am using a Simulator for the same. Which says invalid data packet length.
Can you please explain what am i doing wrong?

When I am sending a MID 0x77 the simulator is interpreting it as 0x88

Data at Simulator Side

Also, can you convert the same code for ESP32 if possible? It would be a great help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.