# CAN development

**see also**

* [can playground repo](https://gitlab.com/roxautomation/playground/canbus)


## Virtual can

A virtual can adapter can be created for testing and development without actual hardware.


create virtual `vcan0` interface with

```bash
# create a vritual can device
modprobe vcan
ip link add dev vcan0 type vcan
ip link set up vcan0
```

test `vcan0`

- terminal 1: `candump vcan0`
- terminal 2: `cansend vcan0 123#1122334455667788`

!!! note
    to create `vcan0` on system startup, a service can be installed.
    `install/setup_vcan_service.sh` is a script that creates a service called
    `create_vcan0`. This is an easy way to to create virtial adapter. It can always be
    disabled by stopping or disabling the service.


## References

- [python-can](https://python-can.readthedocs.io/en/v4.2.2/index.html)



## Can viewer

`python3 -m can.viewer -c "vcan0" -i "socketcan"`

        Shortcuts:
        +---------+-------------------------------+
        |   Key   |       Description             |
        +---------+-------------------------------+
        | ESQ/q   | Exit the viewer               |
        | c       | Clear the stored frames       |
        | s       | Sort the stored frames        |
        | h       | Toggle highlight byte changes |
        | SPACE   | Pause the viewer              |
        | UP/DOWN | Scroll the viewer             |
        +---------+-------------------------------+


data below is generated by `tools/gen_dbc_docs.py`

## Cantools

dump & decode:

`candump vcan0 | cantools decode --single-line odrive-cansimple.dbc`
