#!/run/current-system/sw/bin/bash

# Configuration
DURATION=1           # Record 1 second per step
SAMPLE_RATE=20000000 # 20 MHz bandwidth
AMP=1                # RF Amp on
IF_GAIN=32
BB_GAIN=20
KEEP_MINUTES=5       # Automatically delete files older than 5 minutes

# Create a dedicated directory to organize files
mkdir -p nothing_capture
cd nothing_capture

# The 5 center frequencies in Hz
FREQUENCIES=(2410000000 2430000000 2450000000 2470000000 2490000000)

echo "Starting saved 2.4GHz IQ sweep. Press [CTRL+C] to stop."
echo "Keeping a rolling $KEEP_MINUTES minutes of history..."

while true; do
    for FREQ in "${FREQUENCIES[@]}"; do
        # Create a unique timestamp (YearMonthDay_HourMinuteSecond)
        TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
        FILENAME="capture_${FREQ}_${TIMESTAMP}.iq"
        
        echo "Saving 1s of $FREQ Hz -> $FILENAME"
        
        # Run capture
        timeout $DURATION hackrf_transfer \
            -r "$FILENAME" \
            -f $FREQ \
            -s $SAMPLE_RATE \
            -a $AMP \
            -l $IF_GAIN \
            -g $BB_GAIN > /dev/null 2>&1
            
        # Clean up files older than the specified minutes
        find . -name "capture_*.iq" -mmin +$KEEP_MINUTES -delete
    done
done

