Sign inSign up

royratcliffe/j1939acd

By royratcliffe

•Updated 7 months ago

Lightweight J1939 Address-Claim Super-Daemon Bridge

Image
Networking
0

1.0K

royratcliffe/j1939acd repository overview

⁠Lightweight J1939 Address-Claim Super-Daemon Bridge

On one side: a CAN J1939 network. On the other: a Redis instance. This super-daemon listens for address claims on the J1939 network and updates Redis with the claimed addresses, so that other parts of the system can easily query which addresses are in use and which J1939 controller applications have claimed them.

The daemon is implemented in SWI-Prolog, which provides powerful pattern matching and backtracking capabilities that are well-suited for parsing the J1939 messages and handling the asynchronous nature of the address claim process. It uses Redis streams to publish claimed addresses and a Redis hash for quick lookup of claimed addresses by other components.

Address claiming sub-daemons need to remain running and responsive, so the implementation prioritises robustness and efficiency. It uses a repeat-fail loop to continuously read from the Redis stream of address claims, and it handles potential issues like the J1939 network not being available at startup or Redis keys having unexpected types.

The container operates a primary Prolog process for the main logic and zero-or-more secondary processes that tail the J1939 address claiming logs, parsing them for address claim messages and feeding them into the main process via Redis. This separation allows for better fault tolerance and easier debugging.

⁠Runtime Flow

The super-daemon starts up and initialises the Prolog environment, connecting to Redis. It then enters a loop where it listens for new address claim messages on the j1939:address:claim Redis stream by ECU name with optional address range and preferred address. The main loop detaches a worker thread for the ECU name which handles the address claim process by launching a j1939acd sub-daemon with the appropriate parameters.

When a new claim is received, the worker thread parses the address claim log to extract the claimed address and updates the Redis hash with the new claim; it also publishes the claim to the j1939:address:claimed Redis stream. Other components can subscribe to the Redis stream or query the hash to get real-time updates on which addresses are claimed by which ECU on the J1939 network.

Tag summary

Content type

Image

Digest

sha256:ee4547a7b…

Size

13 MB

Last updated

7 months ago

docker pull royratcliffe/j1939acd