Skip to content

Instantly share code, notes, and snippets.

@ericek111
Last active February 10, 2024 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericek111/e667bfc36e9c88084a21e3ad5b22c02a to your computer and use it in GitHub Desktop.
Save ericek111/e667bfc36e9c88084a21e3ad5b22c02a to your computer and use it in GitHub Desktop.
Schedule SDR recordings with a simple script.
#!/bin/bash
set -e
# This is made for libmirisdr-5, but could be adapted easily to any IQ-spewing client.
# Depends on csdr (jketterl's fork) for decimation.
if [ -z "$1" ]; then
echo "Usage: $0 (start date and time, e. g. 2024-02-10 00:10:15)"
exit 1
fi
START_DATE="$(date -d "$1" +'%s')"
if [ $? -ne 0 ]; then
echo "Invalid date format! Check usage..."
exit 1
fi
# When to stop the recording
END_DATE="$(date -d '+150 minute' +'%s')"
FREQ=3650000
SAMPLE_RATE=6048000
DECIM=16
WAV_RATE=$((SAMPLE_RATE / DECIM)) # Should be an integer.
delayTime=$(( "$START_DATE" - "$(date +'%s')" ))
echo "==================== Will start in $delayTime seconds..."
if [[ "$delayTime" -gt 0 ]]; then
sleep "$delayTime"
fi
isDone="no"
trap ctrl_c SIGINT
function ctrl_c() {
echo "==================== Ctrl+C pressed! Exiting..."
isDone="yes"
}
cd "$(dirname "$0")"
PID_FILE="./miri.pid"
MIRI_PID=""
function start_miri {
OUT_FILE="./baseband_${FREQ}_""$(date +'%Y-%m-%d_%H-%M-%S')"".raw"
echo "==================== Starting recording to $OUT_FILE"
# We need to trap again in a subshell.
( trap '' INT ; miri_sdr -f $FREQ -s $SAMPLE_RATE -G 1,0,0,15 - & echo $! >"$PID_FILE" ) \
| csdr convert -i s16 -o float \
| csdr firdecimate $DECIM 0.08 -w hamming \
| csdr convert -i float -o s16 \
> "$OUT_FILE" &
MIRI_PID="$(cat "$PID_FILE")"
rm "$PID_FILE"
}
start_miri
while true; do
if [[ "$(date +'%s')" -lt "$END_DATE" ]] && [[ "$isDone" == "no" ]]; then
# We should be still recording. Check if the process has died.
if ! kill -0 "$MIRI_PID" >/dev/null 2>&1; then
# Process stopped, restart.
start_miri
fi
sleep 1
else
echo "==================== Recording finished."
# Wait for the process to end...
while kill -0 "$MIRI_PID" >/dev/null 2>&1; do
kill "$MIRI_PID"
sleep 1
done
break
fi
done
# split -b 4000M -d -a 1 'baseband_3650000_2024-02-10_05-45-00.raw' baseband_split_
# sox -t raw -e signed-integer -b 16 -c 2 -r $WAV_RATE - ./bb.wav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment