Host Device Simulator#
Pigweed AI summary: The Host Device Simulator is a Pigweed target that simulates the behavior of an embedded device. It runs executables that continuously run until they crash or are terminated. Communication with the process is done through an RPC server hosted on a local socket. To use this target, Pigweed must be set up to use nanopb and FreeRTOS. The required source repositories can be downloaded using the "pw package" command, and the build must be configured to point to the downloaded repositories. The target also has
This Pigweed target simulates the behavior of an embedded device, spawning threads for facilities like RPC and logging. Executables built by this target will perpetually run until they crash or are explicitly terminated. All communications with the process are over the RPC server hosted on a local socket rather than by directly interacting with the terminal via standard I/O.
Setup#
Pigweed AI summary: To use this target, Pigweed must be set up to use nanopb and FreeRTOS. The required source repositories can be downloaded via pw package, and then the build must be manually configured to point to the location the repository was downloaded to using gn args. Optionally, the stm32cube_f4 package can be included to build for the stm32f429i-disc1: STM32Cube target at the same time. Instead of running "gn gen out" with args set on the command line
To use this target, Pigweed must be set up to use nanopb and FreeRTOS. The
required source repositories can be downloaded via pw package
, and then the
build must be manually configured to point to the location the repository was
downloaded to using gn args. Optionally you can include the stm32cube_f4
package to build for the
stm32f429i-disc1: STM32Cube target at the same
time.
pw package install nanopb
pw package install freertos
pw package install stm32cube_f4
gn gen out --export-compile-commands --args="
dir_pw_third_party_nanopb=\"$PW_PROJECT_ROOT/environment/packages/nanopb\"
dir_pw_third_party_freertos=\"$PW_PROJECT_ROOT/environment/packages/freertos\"
dir_pw_third_party_stm32cube_f4=\"$PW_PROJECT_ROOT/environment/packages/stm32cube_f4\"
"
Tip
Instead of the gn gen out
with args set on the command line above you can
run:
gn args out
Then add the following lines to that text file:
dir_pw_third_party_nanopb = getenv("PW_PACKAGE_ROOT") + "/nanopb"
dir_pw_third_party_freertos = getenv("PW_PACKAGE_ROOT") + "/freertos"
dir_pw_third_party_stm32cube_f4 = getenv("PW_PACKAGE_ROOT") + "/stm32cube_f4"
Building and Running the Demo#
Pigweed AI summary: This section provides instructions for building and running a demo application associated with a target. The demo application can be launched with specific commands, and communication with the launched process can be done through a separate shell. The section also includes tips for running the system_example app in the background and stopping it. The bottom-most pane labeled "Python Repl" allows for sending RPC commands to the simulated device process and running unit tests. The section concludes by directing readers to the pw_console User Guide for more information on using
This target has an associated demo application that can be built and then run with the following commands:
ninja -C out pw_system_demo
./out/host_device_simulator.speed_optimized/obj/pw_system/bin/system_example
To communicate with the launched process run this in a separate shell:
pw-system-console -s default --proto-globs pw_rpc/echo.proto \
--token-databases out/host_device_simulator.speed_optimized/obj/pw_system/bin/system_example
Tip
Alternatively you can run the system_example app in the background, then launch the console on the same line with:
./out/host_device_simulator.speed_optimized/obj/pw_system/bin/system_example
& \
pw-system-console -s default --proto-globs pw_rpc/echo.proto \
--token-databases \
out/host_device_simulator.speed_optimized/obj/pw_system/bin/system_example
Exit the console via the menu or pressing Ctrl-d twice. Then stop the system_example app with:
killall system_example
In the bottom-most pane labeled Python Repl
you should be able to send RPC
commands to the simulated device process. For example, you can send an RPC
message that will be echoed back:
>>> device.rpcs.pw.rpc.EchoService.Echo(msg='Hello, world!')
(Status.OK, pw.rpc.EchoMessage(msg='Hello, world!'))
Or run unit tests included on the simulated device:
>>> device.run_tests()
True
You are now up and running!
See also
The pw_console User Guide for more info on using the the pw_console UI.