Git Product home page Git Product logo

test-can-j1939's Introduction

CAN-J1939 on linux

The Kickstart guide is here

CAN on linux

See Wikipedia:socketcan

J1939 networking in short

  • Add addressing on top of CAN (destination address & broadcast)

  • Any (max 1780) length packets. Packets of 9 or more use Transport Protocol (fragmentation) Such packets use different CANid for the same PGN.

  • only 29bit, non-RTR CAN frames

  • CAN id is composed of

    • 0..8: SA (source address)
    • 9..26:
      • PDU1: PGN+DA (destionation address)
      • PDU2: PGN
    • 27..29: PRIO
  • SA / DA may be dynamically assigned via j1939-81
    Fixed rules of precedence in Specification, no master necessary

J1939 on SocketCAN

J1939 is just another protocol that fits in the Berkely sockets.

socket(AF_CAN, SOCK_DGRAM, CAN_J1939)

differences from CAN_RAW

addressing

SA, DA & PGN are used, not CAN id.

Berkeley socket API is used to communicate these to userspace:

PRIO is a datalink property, and irrelevant for interpretation Therefore, PRIO is not in sockname or peername.

The data that is [recv][recvfrom] or [send][sendto] is the real payload. Unlike CAN_RAW, where addressing info is data.

Packet size

J1939 handles packets of 8+ bytes with Transport Protocol fragmentation transparently. No fixed data size is necessary.

send(sock, data, 8, 0);

will emit a single CAN frame.

send(sock, data, 9, 0);

will use fragementation, emitting 1+ CAN frames.

Enable j1939 (obsolete!)

CAN has no protocol id field. The can-j1939 stack only activates when a socket opens for a network device.

The methods described here existed in earlier implementations.

netlink

ip link set can0 j1939 on

This method is obsoleted in favor of on socket connect.

procfs for legacy kernel (2.6.25)

This API is dropped for kernels with netlink support!

echo can0 > /proc/net/can-j1939/net

Using J1939

BSD socket implementation

  • socket
  • bind / connect
  • recvfrom / sendto
  • getsockname / getpeername

Modified struct sockaddr_can

struct sockaddr_can {
	sa_family_t can_family;
	int         can_ifindex;
	union {
		struct {
			__u64 name;
			__u32 pgn;
			__u8 addr;
		} j1939;
	} can_addr;
}
  • can_addr.j1939.pgn is PGN

  • can_addr.j1939.addr & can_addr.j1939.name
    determine the ECU

    • receiving address information,
      addr is always set,
      name is set when available.

    • When providing address information,
      name != 0 indicates dynamic addressing

iproute2 (obsolete!)

Older versions of can-j1939 used a modified iproute2 for manipulating the kernel lists of current addresses.

Static addressing

ip addr add j1939 0x80 dev can0

Dynamic addressing

ip addr add j1939 name 0x012345678abcdef dev can0

test-can-j1939's People

Contributors

kurt-vd avatar marckleinebudde avatar

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.