All Projects → tonyrog → Can

tonyrog / Can

CAN driver and router

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Can

Libcanard
A compact implementation of the UAVCAN/CAN protocol in C for high-integrity real-time embedded systems
Stars: ✭ 151 (+387.1%)
Mutual labels:  embedded, can-bus
Awesome Canbus
🚛 A curated list of awesome CAN bus tools, hardware and resources
Stars: ✭ 73 (+135.48%)
Mutual labels:  embedded, can-bus
Robot Software
CVRA monorepo - All software running on our bots lives here
Stars: ✭ 39 (+25.81%)
Mutual labels:  embedded, can-bus
bxcan
bxCAN peripheral driver for STM32 chips
Stars: ✭ 22 (-29.03%)
Mutual labels:  embedded, can-bus
Arduino Pro Ide
The Arduino IDE for advanced users and developers. Experimental alpha version.
Stars: ✭ 917 (+2858.06%)
Mutual labels:  embedded
Thingsboard Gateway
Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
Stars: ✭ 796 (+2467.74%)
Mutual labels:  can-bus
Gorocksdb
gorocksdb is a Go wrapper for RocksDB
Stars: ✭ 753 (+2329.03%)
Mutual labels:  embedded
Swupdate
Software Update for Embedded Systems
Stars: ✭ 711 (+2193.55%)
Mutual labels:  embedded
Micro Xrce Dds Client
Micro XRCE-DDS Client repository
Stars: ✭ 30 (-3.23%)
Mutual labels:  embedded
Meta Balena
A collection of Yocto layers used to build balenaOS images
Stars: ✭ 863 (+2683.87%)
Mutual labels:  embedded
X11ui
Simple UI framework using github.com/BurntSushi/xgbutil package using Go.
Stars: ✭ 18 (-41.94%)
Mutual labels:  embedded
Fprime
F' - A flight software and embedded systems framework
Stars: ✭ 8,642 (+27777.42%)
Mutual labels:  embedded
Ninjaterm
A serial port terminal that's got your back.
Stars: ✭ 24 (-22.58%)
Mutual labels:  embedded
Raylib
A simple and easy-to-use library to enjoy videogames programming
Stars: ✭ 8,169 (+26251.61%)
Mutual labels:  embedded
Easyntpclient
Library to read time from Network Time Protocol (NTP) servers.
Stars: ✭ 20 (-35.48%)
Mutual labels:  embedded
Blinker Py
Blinker python library for hardware. Works with Raspberry Pi, Banan Pi, Linux devices
Stars: ✭ 680 (+2093.55%)
Mutual labels:  embedded
Avrd
Embedded Systems in D - Port of avr-libc headers and most avr-gcc processor defines
Stars: ✭ 17 (-45.16%)
Mutual labels:  embedded
Cantools
CAN bus tools.
Stars: ✭ 935 (+2916.13%)
Mutual labels:  can-bus
Paho.mqtt.embedded C
Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
Stars: ✭ 887 (+2761.29%)
Mutual labels:  embedded
Awesome Embedded
A curated list of awesome embedded programming.
Stars: ✭ 831 (+2580.65%)
Mutual labels:  embedded

can

CAN binding for Erlang

CAN or Controller Area Network for short, is a two wire serial protcol for industrial applications.

This implementation currently supports three different backends:

  • can_usb: CANUSB is a USB dongle from LAWICEL AB.
  • can_udp: This is my own invention. A simple repackaging of CAN frames into UDP/IP datagrams sent over local multicast channel.
  • can_sock: A binding to linux SocketCAN interface.

Any number of backend interfaces may be started and attached to the can_router, which is the main interface to receice and send CAN frames.
An application will typically call can_router:attach() and then receive CAN frames from any of the interfaces. To send a frame then simple call can:send/n, this will pass the CAN frame to all the interfaces and connected local applications in the Erlang node.

Dependencies

To build can you will need a working installation of Erlang R15B (or later).
Information on building and installing Erlang/OTP can be found here (more info).

can is built using rebar that can be found here, with building instructions here. rebar's dynamic configuration mechanism, described here, is used so the environment variable REBAR_DEPS should be set to the directory where your erlang applications are located.

can also requires the following applications to be installed:

  • dthread - https://github.com/tonyrog/dthread
  • uart - https://github.com/tonyrog/uart
  • lager - https://github.com/basho/lager

Downloading

Clone the repository in a suitable location:

$ git clone git://github.com/tonyrog/can.git

Configurating

Interfaces can be added and remove dynamically, but can also be initialized in the environment like:

{can, [{interfaces,
         [{can_udp, 1, []},
          {can_udp, 2, [{ttl,0}]},
      {can_usb, 1, [{device, "/dev/tty.usbserial-LWQ6UYOM"},
                        {bitrate, 125000}]},
          {can_usb, 2, [{device, "/dev/tty.usbserial-LWQ8CA1K"},
                        {bitrate, 250000}]},
          {can_sock, "can0", []},
          {can_sock, "vcan0", []}]}]}

There is a special "wakeup" frame that can be enabled by setting wakeup to true. This together with wakeup_timeout will make sure that the can bus gets a "dummy" frame sent before the real message when neccesary.

If wakeup_timeout milliseconds (15s) has passed since the interface saw some input frames or no frames where sent from that interface, then the wakeup frame is sent.

{can, [{wakeup, true},
       {wakeup_timeout, 15000},
   {interfaces,[
      {can_usb, 1, [{device, "/dev/tty.usbserial-LWQ8CA1K"},
                        {bitrate, 250000}]}
      {can_usb, 2, [{device, "/dev/tty.usbserial-LWQ6UYOM"},
                        {bitrate, 250000}]}
    ]}]}.

The wakeup frame looks like this ( maybe configure per interface ? ):

<<16#80,16#2802:16/little,0:8,1:32/little>>

And is sent to the PDO_TX1 for the current target node.

The interfaces in the environment will get under supervision.

Concepts

Linux ( virtual ) can driver

load the virtual can driver

$ sudo modprobe vcan

Create a virtual CAN network interface called 'vcan0'

$ sudo ip link add dev vcan0 type vcan

Activate a virtual CAN network interface called 'vcan0'

$ sudo ifconfig vcan0 up

Remove a (virtual) CAN network interface 'vcan0'

$ sudo ip link del vcan0

Set bitrate on interface can0 to 250000

 $ sudo ip link set can0 down
 $ sudo ip link set dev can0 type can bitrate 250000
 $ sudo ip link set can0 up

Create a virtual CAN network interface (vcan1)

$ sudo ip link add type vcan

...

Files

...

Building

Rebar will compile all needed dependencies.
Compile:

$ cd can
$ rebar compile
...
==> can (compile)

Running

$ erl -pa <path>/can/ebin
>can_router:start().

(Instead of specifing the path to the ebin directory you can set the environment ERL_LIBS.)

Stop:

>halt().


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].