samples/subsys/zbus/uart_bridge/README.html · samples/subsys/zbus/uart_bridge/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Zbus

Zbus UART Bridge

Bridge가 channel을 claim해 raw payload를 serial script로 내보냅니다.

Official pathsamples/subsys/zbus/uart_bridge/README.html
Source filesamples/subsys/zbus/uart_bridge/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

native_sim pseudo-terminal과 Python decoder의 event 출력 흐름을 설명합니다.

Direction

Device to host

Decoder

decoder.py

Events

All channel publications

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 A7809CF112EF8942CE61F6521E80F8A7F0FA052B152C76CC13AD3B1675CBE8CF
.. 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`.

Part 3

한국어 전문 번역

개요

이 간단한 application은 모든 Zbus channel event를 UART를 통해 host로 redirect하는 방법을 보여 줍니다. Device가 computer host에서 실행 중인 script로 정보를 보내면, script가 이를 decode해 standard output에 표시합니다.

빌드 및 실행

이 project는 console로 출력합니다. 다음 command로 native_sim에서 build하고 실행할 수 있습니다.

# From the root of the zephyr repository
west build -b native_sim samples/subsys/zbus/uart_bridge
west build -t run

샘플 출력

실행하면 uart_1과 기본 UART가 pseudo-terminal에 연결됩니다. Core가 상태 0과 1을 번갈아 start_measurement channel로 보내고 peripheral이 sensor_data를 publish합니다. Bridge는 두 channel을 claim해 message를 UART host로 전달한 뒤 channel 처리를 끝냅니다. 이 동작은 계속 반복됩니다.

[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>

실행을 끝내려면 CTRL+C를 누릅니다.

decoder.py script는 다음 command로 실행합니다.

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

앞의 run command가 pseudo-terminal port 값을 출력하는 이유는 native_sim에서 실행되기 때문입니다. uart_1 connected to pseudotty: /dev/pts/2 줄을 확인하십시오. 실제 port는 환경마다 다를 수 있습니다. Hardware board에서는 board 문서에 나온 올바른 port를 사용해야 하며, Linux에서는 보통 /dev/tty..., Windows에서는 COM... 형태입니다.

Serial decoder Python script에서는 다음과 비슷한 출력을 볼 수 있습니다. sensor_data의 byte payload가 변하는 동안 start_measurement 값은 0과 1을 번갈아 나타냅니다.

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'

Decoder script를 끝내려면 CTRL+C를 누릅니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.