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. Host Device Simulator is built on top of pw_system.
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.
pw package install nanopb
pw package install freertos
gn gen out --export-compile-commands --args="
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 = getenv("PW_PACKAGE_ROOT") + "/nanopb"
dir_pw_third_party_freertos = getenv("PW_PACKAGE_ROOT") + "/freertos"
Building and running the demo#
See //sample_project_tools/device_sim.py for a more polished example
of running a simulated device.
device_sim.py runs the simulated device
as a subprocess and then connects to it via the default socket so you just
have to pass the binary.
To build the demo application:
ninja -C out pw_system_demo
To run the demo application:
To communicate with the launched process run this in a separate shell:
pw-system-console -s default --proto-globs pw_rpc/echo.proto
Exit the console via the GUI menu or by pressing Ctrl-D twice.
To stop the
system_example app on Linux / macOS:
In the bottom-most pane labeled
Python Repl you should be able to send RPC
commands to the simulated device process.
To 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!'))
To run unit tests included on the simulated device:
You are now up and running!