<commit_before>#! /bin/bash

# number of actors
ACTORS=2
# number of sensors
SENSORS=2

usage() {
    PROGRAM=$(basename $0)
    echo "Creates a net of sensors and actors running on RIOT native nodes." >&2
    echo "" >&2
    echo "Usage: $PROGRAM [options]" >&2
    echo "" >&2
    echo "Default behaviour:"
    echo "    If no options are given, $ACTORS actors and $SENSORS sensors will be created." >&2
    echo "" >&2
    echo "Options" >&2
    echo "    -a <num>, --actors <num>:   Create <num> actors" >&2
    echo "    -s <num, --sensors <num>:   Create <num> sensors" >&2
    echo "    -h, --help:                 Print this text" >&2
}


# parse arguments
while [[ $# > 0 ]]
do

opt="$1"

case $opt in

    -a|--actors)
    case "$2" in
        ""|*[!0-9]*)
            usage
            exit 1 ;;
        *)
            ACTORS="$2"
            shift ;;
    esac ;;

    -s|--sensors)
        case "$2" in
        ""|*[!0-9]*)
            usage
            exit 1 ;;
        *)
            SENSORS="$2"
            shift ;;
    esac ;;

    -h|--help)
    usage
    exit ;;

    *)
    usage
    exit 1 ;;
esac
shift
done

TOTAL_NODES=$(($ACTORS + $SENSORS))

# Check if tmux is installed
if ! [ -x "$(command -v tmux)" ]; then
  echo "tmux is not installed.\nPlease install tmux if you want to use this script."
  exit 1
fi

# determine paths of the smart environment project and RIOT
SMART_ENVIRONMENT_PATH=$(readlink -f "$(dirname $(readlink -f $0))/..")
SMART_ENV_ACTOR_PATH=$(readlink -f $SMART_ENVIRONMENT_PATH/actor)
SMART_ENV_SENSOR_PATH=$(readlink -f $SMART_ENVIRONMENT_PATH/sensor)
RIOT_PATH=$(readlink -f "$SMART_ENVIRONMENT_PATH/../RIOT")

# tapsetup
TAPSETUP="$RIOT_PATH/dist/tools/tapsetup/tapsetup"

if ! [ -e $TAPSETUP ]; then
    echo "tapsetup is not present. Please check your project setup."
    exit 1
fi

$TAPSETUP -d
$TAPSETUP -c $TOTAL_NODES

# make the actors
cd $SMART_ENV_ACTOR_PATH
make all
# and the sensors
cd $SMART_ENV_SENSOR_PATH
make all

tmux new-session -d -s smartenv
tmux rename-window 'Smart Environment'

# start actor sessions
for i in $(seq 0 $(($ACTORS-1)))
do
    if [ $i -gt 0 ]; then
        tmux split-window -h -t $(($i-1))
    fi
    tmux send-keys "cd $SMART_ENV_ACTOR_PATH" 'C-m' "make term PORT=tap$i" 'C-m'
done

# start sensor sessions
for j in $(seq $ACTORS $(($TOTAL_NODES-1)))
do
    if [ $j -gt 0 ]; then
        tmux split-window -h -t $(($j-1))
    fi
    tmux send-keys "cd $SMART_ENV_SENSOR_PATH" 'C-m' "make term PORT=tap$j" 'C-m'
done

# arrange sessions horizontally
tmux select-layout even-horizontal

# finally attach to the tmux session
tmux -2 attach-session -t smartenv<commit_msg>Setup script now makes the first actor the RPL root node<commit_after>#! /bin/bash

# number of actors
ACTORS=2
# number of sensors
SENSORS=2

usage() {
    PROGRAM=$(basename $0)
    echo "Creates a net of sensors and actors running on RIOT native nodes." >&2
    echo "" >&2
    echo "Usage: $PROGRAM [options]" >&2
    echo "" >&2
    echo "Default behaviour:"
    echo "    If no options are given, $ACTORS actors and $SENSORS sensors will be created." >&2
    echo "" >&2
    echo "Options" >&2
    echo "    -a <num>, --actors <num>:   Create <num> actors" >&2
    echo "    -s <num, --sensors <num>:   Create <num> sensors" >&2
    echo "    -h, --help:                 Print this text" >&2
}


# parse arguments
while [[ $# > 0 ]]
do

opt="$1"

case $opt in

    -a|--actors)
    case "$2" in
        ""|*[!0-9]*)
            usage
            exit 1 ;;
        *)
            ACTORS="$2"
            shift ;;
    esac ;;

    -s|--sensors)
        case "$2" in
        ""|*[!0-9]*)
            usage
            exit 1 ;;
        *)
            SENSORS="$2"
            shift ;;
    esac ;;

    -h|--help)
    usage
    exit ;;

    *)
    usage
    exit 1 ;;
esac
shift
done

TOTAL_NODES=$(($ACTORS + $SENSORS))

# Check if tmux is installed
if ! [ -x "$(command -v tmux)" ]; then
  echo "tmux is not installed.\nPlease install tmux if you want to use this script."
  exit 1
fi

# determine paths of the smart environment project and RIOT
SMART_ENVIRONMENT_PATH=$(readlink -f "$(dirname $(readlink -f $0))/..")
SMART_ENV_ACTOR_PATH=$(readlink -f $SMART_ENVIRONMENT_PATH/actor)
SMART_ENV_SENSOR_PATH=$(readlink -f $SMART_ENVIRONMENT_PATH/sensor)
RIOT_PATH=$(readlink -f "$SMART_ENVIRONMENT_PATH/../RIOT")

# tapsetup
TAPSETUP="$RIOT_PATH/dist/tools/tapsetup/tapsetup"

if ! [ -e $TAPSETUP ]; then
    echo "tapsetup is not present. Please check your project setup."
    exit 1
fi

$TAPSETUP -d
$TAPSETUP -c $TOTAL_NODES

# make the actors
cd $SMART_ENV_ACTOR_PATH
make all
# and the sensors
cd $SMART_ENV_SENSOR_PATH
make all

tmux new-session -d -s smartenv
tmux rename-window 'Smart Environment'

# start actor sessions
for i in $(seq 0 $(($ACTORS-1)))
do
    if [ $i -gt 0 ]; then
        tmux split-window -h -t $(($i-1))
    fi
    tmux send-keys "cd $SMART_ENV_ACTOR_PATH" 'C-m' "make term PORT=tap$i" 'C-m'
    if [ $i -eq 0 ]; then
        tmux send-keys 'mkroot' 'C-m'
    fi
done

# start sensor sessions
for j in $(seq $ACTORS $(($TOTAL_NODES-1)))
do
    if [ $j -gt 0 ]; then
        tmux split-window -h -t $(($j-1))
    fi
    tmux send-keys "cd $SMART_ENV_SENSOR_PATH" 'C-m' "make term PORT=tap$j" 'C-m'
done

# arrange sessions horizontally
tmux select-layout even-horizontal

# finally attach to the tmux session
tmux -2 attach-session -t smartenv
{'fraction_non_alphanumeric': 0.14004416635995584, 'fraction_numerical': 0.013801987486198012, 'mean_word_length': 2.466198979591837, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '463227', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1981, 'n_words': 627}