UDS Sample

This sample demonstrates comprehensive UDS (Unified Diagnostic Services) functionality using the default UDS instance.

Overview

The sample uses uds_default_instance provided by the UDS library, which automatically handles:

  • UDS instance initialization

  • CAN interface setup and configuration

  • Thread startup

  • Common handler registration (session control, ECU reset, link control)

The application only needs to:

  1. Implement service-specific handlers

  2. Optionally provide custom user context via uds_default_instance_user_context()

Test with virtual CAN on posix

  1. Add virtual can

    sudo ip link add dev vcan0 type vcan
    sudo ip link set vcan0 mtu 72
    sudo ip link set up vcan0
    sudo ip link property add dev vcan0 altname zcan0
    
  2. Build for native sim and run

    west build\
        --pristine always\
        --board native_sim/native/64\
        samples/uds
    
    ./build/zephyr/zephyr.exe
    
  3. Run test client in another terminal

    python samples/uds/client.py
    

Test with board

  1. Enable can interface

    sudo ip link set can0 type can bitrate 500000
    sudo ip link set up can0
    
  2. Run test client with can0 interface

    python samples/uds/client.py --can can0
    

    Note

    If you want to remove the error output, you can redirect stderr to /dev/null by appending 2&> /dev/null to the python command.