Enhance channel hopping by adding dynamic hop interval calculation based on observation duration

This commit is contained in:
Yaro Kasear 2025-05-06 09:04:53 -05:00
parent dcbd240bb5
commit 27d64d2bed
2 changed files with 20 additions and 6 deletions

View file

@ -169,6 +169,8 @@ for ((COUNTER = 1; COUNTER <= NUM_TESTS; COUNTER++)); do
log "Test run $COUNTER of $NUM_TESTS"
for ((i = 1; i <= NUM_SAMPLES; i++)); do
OBS_START=$(date +%s)
if [ "$LISTENER_ENABLED" -eq 1 ]; then
LISTENER_SAMPLE_FILE="${TEST_FILE%.csv}-listener-$COUNTER-$i.csv"
@ -176,12 +178,23 @@ for ((COUNTER = 1; COUNTER <= NUM_TESTS; COUNTER++)); do
READY_FILE="/tmp/listener_ready_${COUNTER}_${i}"
log "Launching listener with args: --main-iface $INTERFACE --monitor-iface $LISTEN_INTERFACE --outfile $LISTENER_SAMPLE_FILE ${LISTENER_ARGS[*]}"
ADAPTIVE_ARGS=("${LISTENER_ARGS[@]}")
if [[ " ${LISTENER_ARGS[*]} " =~ "--channel-hop" ]]; then
NUM_CHANNELS=15 # Update if your list changes
OBS_NOW=$(date +%s)
ESTIMATED_OBS_DURATION=$((OBS_NOW - OBS_START))
HOP_INTERVAL=$((ESTIMATED_OBS_DURATION / (NUM_CHANNELS + 1)))
[[ "$HOP_INTERVAL" -lt 2 ]] && HOP_INTERVAL=2 # Don't go too fast
log "Estimated observation time: ${ESTIMATED_OBS_DURATION}s → Setting hop interval: ${HOP_INTERVAL}s"
ADAPTIVE_ARGS+=("--hop-interval" "$HOP_INTERVAL")
fi
log "Launching listener with args: --main-iface $INTERFACE --monitor-iface $LISTEN_INTERFACE --outfile $LISTENER_SAMPLE_FILE ${ADAPTIVE_ARGS[*]}"
sudo "${SCRIPT_DIRECTORY}/listener.py" \
--main-iface "$INTERFACE" \
--monitor-iface "$LISTEN_INTERFACE" \
--outfile "$LISTENER_SAMPLE_FILE" \
"${LISTENER_ARGS[@]}" > >(tee "$READY_FILE") &
"${ADAPTIVE_ARGS[@]}" > >(tee "$READY_FILE") &
LISTENER_PID=$!
# Wait for the READY_FILE to contain "LISTENING_STARTED"