1#!/usr/bin/env bash
2# Copyright (c) 2024 Nordic Semiconductor
3# SPDX-License-Identifier: Apache-2.0
4
5set -e
6set -u
7
8if [ $# -eq 0 ]; then
9    echo "Usage: run.sh <number_of_devices> [exe_image]"
10    shift
11fi
12
13if [ $# -gt 2 ]; then
14    echo "Too many args"
15    shift
16fi
17
18echo "Starting simulation. Hit Ctrl-C to exit."
19
20# Build it with e.g.
21# cd $ZEPHYR_BASE/tests/bluetooth/shell
22# west build -d build -b nrf52_bsim -S xterm-native-shell $ZEPHYR_BASE/tests/bluetooth/shell
23default_image=${ZEPHYR_BASE}/tests/bluetooth/shell/build/zephyr/zephyr.exe
24
25num_devices=$1
26image="${2:-"${default_image}"}"
27
28# Cleanup all existing sims
29$BSIM_OUT_PATH/components/common/stop_bsim.sh
30
31# Force sim to real-time
32pushd $BSIM_OUT_PATH/components/device_handbrake
33./bs_device_handbrake -s=shell-sim -r=10 -d=0 &
34popd
35
36for dev_id in $(seq 1 ${num_devices}); do
37    echo "Start device $dev_id"
38    $image -s=shell-sim -d=$dev_id -RealEncryption=1 -rs=$dev_id -attach_uart -wait_uart &
39done
40
41# Start the PHY
42pushd $BSIM_OUT_PATH/bin
43$BSIM_OUT_PATH/bin/bs_2G4_phy_v1 -s=shell-sim -D=$((num_devices+=1))
44