Part 1
요약·해설
Pseudo-terminal, loopback 차단과 Python remote mock의 양방향 통신을 설명합니다.
UART bridge
Python remote mock
start_measurement · sensor_data
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
B383CBCAB7AE1B9D2F8BC2DC44C34196D86223B336756C736AD0AFA627B96DCB
.. zephyr:code-sample:: zbus-remote-mock
:name: Remote mock sample
:relevant-api: zbus_apis
Publish to a zbus instance using UART as a bridge.
Overview
********
This application demonstrates how a host script can publish to the zbus in an embedded device using the UART as a bridge.
The device sends information to the script running on a computer host. Then, the script sends back information when it would simulate a publish to some channel. Finally, the script decodes the data exchanged and prints it to the stdout.
With this approach, developers can implement tests using any language on a computer to talk directly via channels with threads running on a device. Furthermore, it gives the tests more controllability and observability since we can control and access what is sent and received by the script.
Building and Running
********************
This project outputs to the console. It can be built and executed
on :ref:`native_sim <native_sim>` as follows:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/zbus/remote_mock
:host-os: unix
:board: native_sim
:goals: run
Sample Output
=============
.. code-block:: console
-- west build: running target run
[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: [Mock Proxy] Started.
D: [Mock Proxy RX] Started.
D: [Mock Proxy RX] Found sentence
D: Channel start_measurement claimed
D: Channel start_measurement finished
D: Publishing channel start_measurement
D: START processing channel start_measurement change
D: Channel start_measurement claimed
D: discard loopback event (channel start_measurement)
D: Channel start_measurement finished
D: FINISH processing channel start_measurement change
D: START processing channel sensor_data change
D: Channel sensor_data claimed
D: sending message to host (channel sensor_data)
D: Channel sensor_data finished
D: FINISH processing channel sensor_data change
D: sending sensor data err = 0
<repeats endlessly>
Exit execution by pressing :kbd:`CTRL+C`.
The :file:`remote_mock.py` script can be executed using the following command:
.. code-block:: bash
python3.8 samples/subsys/zbus/remote_mock/remote_mock.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 remote mock (Python script), you would see something like this:
.. code-block:: shell
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 1
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 2
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 3
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 4
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 5
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 6
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 7
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 8
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 9
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 10
<continues>
Exit the remote mock script by pressing :kbd:`CTRL+C`.
Part 3
한국어 전문 번역
개요
이 application은 UART를 bridge로 사용하여 computer host에서 실행되는 script가 embedded device의 Zbus에 message를 publish하는 방법을 보여 줍니다.
Device는 먼저 host computer에서 실행되는 script로 정보를 보냅니다. Script는 특정 channel에 publish하는 상황을 흉내 내야 할 때 정보를 device로 다시 보냅니다. 마지막으로 script는 주고받은 data를 decode해 standard output에 표시합니다.
이 방식을 사용하면 개발자는 computer에서 원하는 언어로 test를 작성하고, device에서 실행 중인 thread와 channel을 통해 직접 통신할 수 있습니다. Script가 보내고 받는 값을 제어하고 확인할 수 있으므로 test의 controllability와 observability도 높아집니다.
빌드 및 실행
이 project는 console로 출력합니다. 다음 command로 native_sim에서 build하고 실행할 수 있습니다.
# From the root of the zephyr repository
west build -b native_sim samples/subsys/zbus/remote_mock
west build -t run
샘플 출력
실행하면 uart_1과 기본 UART가 pseudo-terminal에 연결되고 Mock Proxy의 송수신 worker가 시작됩니다. Host가 start_measurement를 publish하면 device는 loopback event를 버리고, sensor_data 변경을 host로 전송합니다. 이 동작은 계속 반복됩니다.
-- west build: running target run
[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: [Mock Proxy] Started.
D: [Mock Proxy RX] Started.
D: [Mock Proxy RX] Found sentence
D: Channel start_measurement claimed
D: Channel start_measurement finished
D: Publishing channel start_measurement
D: START processing channel start_measurement change
D: Channel start_measurement claimed
D: discard loopback event (channel start_measurement)
D: Channel start_measurement finished
D: FINISH processing channel start_measurement change
D: START processing channel sensor_data change
D: Channel sensor_data claimed
D: sending message to host (channel sensor_data)
D: Channel sensor_data finished
D: FINISH processing channel sensor_data change
D: sending sensor data err = 0
<repeats endlessly>
실행을 끝내려면 CTRL+C를 누릅니다.
remote_mock.py script는 다음 command로 실행합니다.
python3.8 samples/subsys/zbus/remote_mock/remote_mock.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... 형태입니다.
Remote mock Python script에서는 다음과 비슷한 출력을 볼 수 있습니다. Script가 start_measurement를 publish할 때마다 device가 증가하는 sensor_data 값을 notification으로 돌려줍니다.
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 1
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 2
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 3
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 4
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 5
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 6
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 7
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 8
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 9
Proxy PUB [start_measurement] -> start measurement
Proxy NOTIFY: [sensor_data] -> sensor value 10
<continues>
Remote mock script를 끝내려면 CTRL+C를 누릅니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.