zephyr/samples/subsys/zbus/uart_bridge
Alberto Escolar Piedras 1c3edca8d8 samples/subsys/zbus/uart_bridge: Add missing overlays for native_sim
During the hwmv1->v2 transition, overlays from a base
board were made to be shared with the variants.
So at that time all overlays for variants which were
just copies of the base overlay were removed.
After that in
https://github.com/zephyrproject-rtos/zephyr/pull/71149
this shared/merged overlay behaviour was reverted,
but not all tests were fixed.

This is one of those. Let's fix it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-04-18 12:20:14 +02:00
..
boards samples/subsys/zbus/uart_bridge: Add missing overlays for native_sim 2024-04-18 12:20:14 +02:00
src
CMakeLists.txt
decoder.py treewide: Disable automatic argparse argument shortening 2023-01-26 20:12:36 +09:00
prj.conf
README.rst samples zbus: Swap native_posix with native_sim 2023-11-20 12:02:48 +01:00
sample.yaml tests: samples: cleanup test tags, add integration_platforms 2023-06-02 04:47:06 -04:00

.. zephyr:code-sample:: zbus-uart-bridge
   :name: UART bridge
   :relevant-api: zbus_apis

   Redirect channel events to the host over UART.

Overview
********

This simple application demonstrates a UART redirection of all channel events to the host.
The device sends information to the script running on a computer host. The script decodes it and prints it to the stdout.

Building and Running
********************

This project outputs to the console. It can be built and executed
on native_sim as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/zbus/uart_bridge
   :host-os: unix
   :board: native_sim
   :goals: run

Sample Output
=============

.. code-block:: console

    [0/1] cd .../zephyr/build/zephyr/zephyr.exe
    uart_1 connected to pseudotty: /dev/pts/2
    uart connected to pseudotty: /dev/pts/3
    *** Booting Zephyr OS build zephyr-v3.1.0 ***
    D: Core sending start measurement with status 0
    D: START processing channel start_measurement change
    D: FINISH processing channel start_measurement change
    D: Peripheral sending sensor data
    D: START processing channel sensor_data change
    D: FINISH processing channel sensor_data change
    D: Bridge Started
    D: Channel start_measurement claimed
    D: Channel start_measurement finished
    D: Bridge send start_measurement
    D: Channel sensor_data claimed
    D: Channel sensor_data finished
    D: Bridge send sensor_data
    D: Core sending start measurement with status 1
    D: START processing channel start_measurement change
    D: FINISH processing channel start_measurement change
    D: Channel start_measurement claimed
    D: Channel start_measurement finished
    D: Bridge send start_measurement
    D: Peripheral sending sensor data
    D: START processing channel sensor_data change
    D: FINISH processing channel sensor_data change
    D: Channel sensor_data claimed
    D: Channel sensor_data finished
    D: Bridge send sensor_data

    <repeats endlessly>

Exit execution by pressing :kbd:`CTRL+C`.

The :file:`decoder.py` script can be executed using the following command:

.. code-block:: bash

    python3.8 samples/subsys/zbus/uart_bridge/decoder.py /dev/pts/2


Note the run command above prints the value of pts port because it is running in
:ref:`native_sim <native_sim>`.
Look at the line indicating ``uart_1 connected to pseudotty: /dev/pts/2``.
It can be different in your case. If you are using a board, read the documentation to get the
correct port destination (in Linux is something like ``/dev/tty...`` or in Windows ``COM...``).

From the serial decoder (Python script), you would see something like this:

.. code-block:: shell

    PUB [sensor_data] -> b'\xc5\x01\x00\x00\xb2\x11\x00\x00'
    PUB [start_measurement] -> b'\x00'
    PUB [sensor_data] -> b'\xc6\x01\x00\x00\xbc\x11\x00\x00'
    PUB [start_measurement] -> b'\x01'
    PUB [sensor_data] -> b'\xc7\x01\x00\x00\xc6\x11\x00\x00'
    PUB [start_measurement] -> b'\x00'
    PUB [sensor_data] -> b'\xc8\x01\x00\x00\xd0\x11\x00\x00'
    PUB [start_measurement] -> b'\x01'
    PUB [sensor_data] -> b'\xc9\x01\x00\x00\xda\x11\x00\x00'
    PUB [start_measurement] -> b'\x00'
    PUB [sensor_data] -> b'\xca\x01\x00\x00\xe4\x11\x00\x00'
    PUB [start_measurement] -> b'\x01'
    PUB [sensor_data] -> b'\xcb\x01\x00\x00\xee\x11\x00\x00'
    PUB [start_measurement] -> b'\x00'
    PUB [sensor_data] -> b'\xcc\x01\x00\x00\xf8\x11\x00\x00'
    PUB [start_measurement] -> b'\x01'
    PUB [sensor_data] -> b'\xcd\x01\x00\x00\x02\x12\x00\x00'
    PUB [start_measurement] -> b'\x00'
    PUB [sensor_data] -> b'\xce\x01\x00\x00\x0c\x12\x00\x00'
    PUB [start_measurement] -> b'\x01'
    PUB [sensor_data] -> b'\xcf\x01\x00\x00\x16\x12\x00\x00'
    PUB [start_measurement] -> b'\x00'

Exit the decoder script by pressing :kbd:`CTRL+C`.