Host Device Simulator#
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.
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
package to build for the
stm32f429i-disc1: STM32Cube target at the same
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\" "
Instead of the
gn gen out with args set on the command line above you can
gn args out
Then add the following lines to that text file:
dir_pw_third_party_nanopb = pw_env_setup_PACKAGE_ROOT + "/nanopb" dir_pw_third_party_freertos = pw_env_setup_PACKAGE_ROOT + "/freertos" dir_pw_third_party_stm32cube_f4 = pw_env_setup_PACKAGE_ROOT + "/stm32cube_f4"
Building and Running the Demo#
This target has an associated demo application that can be built and then run with the following commands:
ninja -C out pw_system_demo
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
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:
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!