Skip to content

Development tool to read and write CAN/LIN/flexray and other buses using gRPC which allows usage of preferred language.

License

Notifications You must be signed in to change notification settings

AleksandarFilipov/signalbroker-server

 
 

Repository files navigation

Signalbroker

Build Status Development tool to read and write CAN/LIN and other buses using gRPC which allows usage of preferred language.

Sample scenarios:

Disclaimer

Documentation is still ongoing, Project is operational out of the box, but custom dbc/ldf/human files are recomended to get the most out of it.

Teaser

Components

Components

Components

Components

keep reading...

Get started

To get you started all you need to do is:

  • Open a terminal/console window.
  • Clone this repo:
    $ git clone git@github.com:AleksandarFilipov/signalbroker-server.git
  • Move to the new folder:
    $ cd signalbroker-server
  • Use docker-compose "up" for linux:
    docker-compose up
  • and for OSX:
    docker-compose -f docker-compose.macos.yml up

That's it! Signal Broker will be running after the first build.

For more information about:

  • docker-compose follow this link.
  • Other ways to start the server read this.
  • how to configure the server read this

Hardware

The software can execute on any Linux with SocketCAN. On hosts without hardware CAN interfaces, virtual CAN be configured using:

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ifconfig vcan0 up

System is configured using interfaces.json

Extensive reference can be found here link

Real deal

In order to access real CAN the following hardware can be used.

Suggested hardware

Works is ongoing for CAN-FD support which is in experimental stage.

Accessing the server

Signalbroker is headless but can be accessed using the grpc-web frontend

To get aquainted to the system the easiest way to get going is by checking out the simple telnet guide

However, the preferred way of accessing the system is by using grpc. Follow this link to find the protofiles, and browse the examples to get inspiration

Additional access possibilities

Configuring the server

The configuration of the server can be done with configuration/interfaces.json. This location is the default but if you are using docker-compose you can add an .env file to change it. In this case the configuration folder can be place outside of the repo to avoid adding configuration files by accident. If you add this line to the .env file the configuration will be place outside the repository.

CONFIG_FOLDER=../configuration/

Starting the server (for docker skip down)

  • Install elixir.
  • Clone this repository.
  • Make sure your configuration/interfaces.json makes sense (or try out of the box).
  • Start the software by doing.
mix deps.get
iex -S mix

Start with prebuild images using docker - recommended

prebuilt images are available for intel and arm

to run with docker-compose using .env:

If you add a file named .env with this:

# Custom tag name
# This tag can be used for version control
TAG=v1

# This is the IP of the host PC  
# in the network interface you are using to communicate 
DOCKER_HOST_IP=127.0.0.1

# Path to the configuration folder 
# relative to the root of the signalbroker-server
CONFIG_FOLDER=../configuration/

# Custom command to use template files
CUSTOM_COMMAND=bash -c "ls /"

you can change the default values used by docker compose. To read more about "Variable substitution in docker-compose follow this link

to run with your configuration:

  • Clone this repository (to get the a valid configuration folder), then;
docker run --rm -it --privileged=true --net=host -v $PWD/configuration/:/signalbroker/_build/prod/rel/signal_server/configuration aleksandarf/signalbroker-server:travis-12-amd64

If you are in MacOS or Windows --net=host is not available and you need to do the port mapping:

docker run --rm -it --privileged=true -p 4040:4040 -p 50051:50051 -p 2000:2000/udp -p 2001:2001/udp -v $PWD/configuration/:/signalbroker/_build/prod/rel/signal_server/configuration aleksandarf/signalbroker-server:travis-12-amd64

or run it with sample configuration:

docker run --rm -it --privileged=true --net=host -p 4040:4040 -p 50051:50051 -p 2000:2000/udp -p 2001:2001/udp aleksandarf/signalbroker-server:travis-12-amd64

Remember to pick your tag including architecture. this is done by replacing travis-12-amd64 with appropriate tag [travis-12-amd64 | travis-12-arm64 | travis-12-arm32]

Find propriate tag here.

Alternatively; start using docker

Clone this repository, then;

  • Clone this repository, then;
docker build -t signalbroker:v1 -f ./docker/Dockerfile .

to run with your configuration:

docker run --rm -it --privileged=true --net=host -v $PWD/configuration/:/signalbroker/_build/prod/rel/signal_server/configuration signalbroker:v1

If you are in OSX or Windows --net=host is not available and you need to do the port mapping:

docker run -it --network="bridge" -p 127.0.0.1:4040:4040 -p 127.0.0.1:50051:50051 -p 127.0.0.1:2000:2000/udp -p 127.0.0.1:2001:2001/udp -v $PWD/configuration:/signalbroker/_build/prod/rel/signal_server/configuration signalbroker:v1

or run it with sample configuration:

docker run --rm -it --privileged=true --net=host signalbroker:v1

If you are in OSX or Windows --net=host is not available and you need to do the port mapping:

docker run --rm -it -p 4040:4040 -p 50051:50051 -p 2000:2000/udp -p 2001:2001/udp signalbroker:v1

you should be able to do above on intel or arm32/arm64.

Playback for off line purposes

On your Linux computer, install the following.

apt-get install can-utils

Record can from a real network:

candump -L can0 > myfile.log

Once you configured your interfaces.json to use virtual CAN interfaces by setting using vcan0 instead of can0 just play back your recorded file:

canplayer vcan0=can0 -I myfile.log

Running examples with fake data

Install can-utils as described above the generate fake data using:

cangen vcan0  -v -g 1

Running examples with fake data without socketcan (particulary useful for mac/osx)

Interfaces contains a namespace "UDPCanInterface" this accepts data over UDP.

A: Playback candump file (for dev environment)

iex -S mix
FakeCanConnection.start_link(:fake_generator_1, :UDPCanInterface, "data/candump/candump.log")

you can start any number of generators

the data will be correctly formated if recorded using candump -L can0

B: or by sending single messages

to simulate can traffic from your host:

echo -n '00000040080102030405060708' | xxd -r -p | nc -w 1 -u 127.0.0.1 2001

or wrap it with watch to keep it repeating the command

watch -n 0 "echo -n '00000040080102030405060708' | xxd -r -p | nc -w 1 -u 127.0.0.1 2001"

format is id::size(32), payload_length::size(8), payload::(64) Size is ignored if "fixed_payload_size": 8 in interfaces.json file is set.

A or B check that messages are sent through

Above command will produce a message on id 0x40 where BenchC_a signal resides in the default sample configuration. You can verify this by doing

telnet 127.0.0.1 4040
{"command": "subscribe", "signals": ["BenchC_d_8","BenchC_d_2","BenchC_c_5","BenchC_c_1","BenchC_c_6","BenchC_d_7","BenchC_d_1","BenchC_c_7","BenchC_a","BenchC_d_4","BenchC_c_2","BenchC_d_6","BenchC_d_5","BenchC_c_8","BenchC_d_3","BenchC_c_4","BenchC_b","BenchC_c_3"], "namespace" : "UDPCanInterface"}

if you now send using strategy A or B you should receive something like

{"timestamp":1569247543145471,"signals":{"BenchC_a":72623859790382856}}

ODB diagnostics

https://en.wikipedia.org/wiki/OBD-II_PIDs is a set of predifined queries which many vehicle supports. For this scenario you can start by using the predefiend dbc. Start by running queries using the frontend or check out the diagnostics sample.

Advanced usage

  • Signalbroker can be used to dispatch arbitrary messages between any clients by defining virtual networks. Example here
  • Signal reflection (reflector). When CAN networks share frames (in dbc files), interfaces.json can be configured to forward frames automatically. Filtering can be applied to avoid forwarding specific frames. Example configuration can be found here
  • Lin arbitration (header) signal is exposed to the client as any signal. This allows client to Signalbroker when configured as a slave to act on arbitration. Alternatively the client can act as master thus implement a custom arbitration scheme. In the latter case the schedule_autostart should be disabled. Arbitration example is avaliable here
  • Don't forget to browse examples

Statistics and usage

In order to understand usage of the product and it's enviroment it will try and send system information based on your interfaces.json and it's execution enviroment on start. The data is anonymized and it not distributed to any other party. Its sole purpose is the make the software better.

This is not mandatoy and can be disabled, however to keep us motivated we would please urge you not to disable this feature.

For mac/osx developers

For dev purpose this project builds on mac with the following limations

  • socket can. Since the is no kernel support for socket can dependency ng_can can is removed.
  • all can and vcan references needs to be removed for starters use the following interfaces.json

To successfully build you need to install gcc. Background here

brew install gcc49
export CC=/usr/local/bin/gcc-4.9
iex -S mix

Feed your Signalbroker with data over udp as described as above

TODO - help appreciated

  • Provide pre build docker image.
  • Add default configuration.
  • Add gRPC sample code.
  • Publish repository for creating custom LIN hardware.
  • Add sample dbc files.
  • Re-enable test suite.
  • Make code (branch) runnable on mac where SocketCan is missing fixed with fakecan
  • Add example on how to feed server with (can) traffic over udp. Enables traffic simulation on osx/mac.
  • Add bash/py script which playbacks recorded can traffic using udp
  • Add inspirational video
  • Parse signal meta data and fill in appropriate fields in the
  • Elixir module that dumps data to InfluxDB alternatively to Riak TS, which can be visualized by Grafana.
  • Promote your .dbc and .ldf files
  • Add reflection sample or documentation.
  • Add lin arbitration (header) example.

Help us improve!

The Signalbroker is in active development and would appreciate your feature suggestions or bug reports. File them as issues in this repository :)

About

Development tool to read and write CAN/LIN/flexray and other buses using gRPC which allows usage of preferred language.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 88.4%
  • C 10.8%
  • Other 0.8%