Parse CAN Hardware And Circuit Identifiers

CAN interface hardware IDs and circuit IDs exist independently of a CAN sensor, and are required parameters for all CAN-based sensor nodes defined in the SDF Configurator. PolySync Core supports Kvaser and SocketCAN-enabled hardware devices. Each device has a different method to identify the USB and/or PCIe CAN interfaces. Kvaser hardware uses the `linuxcan` libraries to communicate with CAN hardware on Linux. All other off-the-shelf hardware uses `SocketCAN` libraries to communicate with CAN hardware on Linux. ### 1. Kvaser This will parse out the hardware and circuit IDs for any connected Kvaser CAN interfaces. ```bash $ /usr/src/linuxcan/canlib/examples/listChannels Found 1 channel. channel 0 = Kvaser Leaf Light v2, 73-30130-00685-0, (0)21718, 3.3.0.769 ``` The **hardware identifier** is printed near the end, in this case it's **21718**. The **circuit identifier** is an index for multi-channel CAN hardware interfaces. The `(0)` preceding the hardware identifier represents the circuit ID. For single-channel CAN interfaces, the circuit identifier will always be **0**. In the following example, `channel 0` has **hardware identifier** 28373 and circuit identifier 0. `channel 1` has **hardware identifier** 28373 and circuit identifier 1. ```bash $ /usr/src/linuxcan/canlib/examples/listChannels Found 2 channels. channel 0 = Kvaser Leaf Light v2, 73-30130-00685-0, (0)28373, 3.3.0.769 channel 1 = Kvaser Leaf Light v2, 73-30130-00685-0, (1)28373, 3.3.0.769 ``` ### 2. SocketCAN SocketCAN enumerates CAN interfaces just as if it were an Ethernet socket. In PolySync, only the hardware identifier is needed when using SocketCAN CAN interfaces. Available devices can be queried from the system with `ifconfig -a`, and are typically represented as `can0`, `can1`, etc. The devices map to the following values in PolySync: | SocketCAN Channel | PolySync HW ID | | ----------------- | -------------- | | `can0` | 1 | | `can1` | 2 | | `can2` | 3 | | `canN` | N+1 |