Merge pull request #428 from alanbjohnston/fiabv4-auto-tune-p

Pi 4 Changes and Other PacSat Fixes
master-b
Alan Johnston 5 days ago committed by GitHub
commit b55fdec26e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -355,14 +355,14 @@ if [ "$1" = "" ]; then
txc=0
fi
timeout 1 rtl_test &> out.txt
if [[ $(grep "No supported" out.txt) ]] ; then
# timeout 1 rtl_test &> out.txt
# if [[ $(grep "No supported" out.txt) ]] ; then
# echo "No RTL-SDR detected"
rtl=0
else
echo "RTL-SDR detected"
rtl=1
fi
# rtl=0
# else
# echo "RTL-SDR detected"
# rtl=1
# fi
echo
echo -e "Current sim.cfg configuration file:"

@ -0,0 +1,93 @@
from rtlsdr import RtlSdr
import numpy as np
import matplotlib.pyplot as plt
import sys
if __name__ == "__main__":
graph = 'n'
center_frequency = 434.7e6
if (len(sys.argv)) > 0:
# print("There are arguments!")
center_frequency = float(sys.argv[1]) - 200e3
if (center_frequency == 0):
center_frequency = 434.7e6
if (len(sys.argv)) > 1:
# print("There are more arguments")
if (sys.argv[2] == 'g') or (sys.argv[2] == '-g'):
graph = 'y'
sampling_rate = 1024e3 # 250e3 # Hz
duration = 65536/sampling_rate # 1 # seconds
try:
sdr = RtlSdr()
# configure device
sdr.sample_rate = sampling_rate # 250e3 # 2.4e6
#center_frequency = 434.8e6
sdr.center_freq = center_frequency
sdr.gain = 47
sdr.direct_sampling = False
# signal = sdr.read_samples(64*1024) #256
signal = sdr.read_samples(duration*sampling_rate).real #256
# print(f"Center frequency is {center_frequency}")
sdr.close()
# Compute the FFT
fft_result = np.fft.fft(signal)
# Calculate the frequencies corresponding to the FFT output
n = len(signal)
frequencies = np.fft.fftfreq(n, d=1/sampling_rate)
# Take the absolute value for amplitude spectrum and consider only the positive frequencies
positive_frequencies_indices = np.where(frequencies >= 0)
positive_frequencies = frequencies[positive_frequencies_indices]
amplitude_spectrum = 2/n * np.abs(fft_result[positive_frequencies_indices]) # Normalize for amplitude
if (graph == 'y'):
# Plotting the results
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(t, signal)
plt.title('Time Domain Signal')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.subplot(1, 2, 2)
plt.stem(positive_frequencies, amplitude_spectrum, markerfmt=" ", basefmt="-b")
plt.title('Frequency Domain (FFT)')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.tight_layout()
plt.show()
# print(amplitude_spectrum)
x = amplitude_spectrum
# print(x)
min_value = min(x)
max_value = max(x) * 100
#freq_min = np.argmax(min_value)
# print(np.argmax(x))
# print(np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
# print(sampling_rate)
# print(center_frequency)
offset = (np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
freq_max = center_frequency + offset + 2000
except: # if no RTL-SDR or in use, stop scanning with high max value and center frequency
max_value = 100
freq_max = center_frequency + 200e3 # should be 434900000
print(f" {freq_max:.0f} {max_value:.0f}")

@ -80,8 +80,9 @@ else
echo
fi
autotune=0
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=180 --title="FUNcube Telem Decoding" --text="Choose the frequency for FUNcube decoding:" --column="kHz" --column="Use" 434900 "CubeSatSim" Other "Choose another frequency")
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=220 --title="FUNcube Telem Decoding" --text="Choose the frequency for FUNcube decoding:" --column="kHz" --column="Use" 434900 "CubeSatSim" Auto-tune "CubeSatSim Auto-tune" Other "Choose another frequency")
echo $frequency
@ -96,6 +97,11 @@ if [ "$frequency" = "434900" ]; then
frequency=434900000
elif [ "$frequency" = "Auto-tune" ]; then
frequency=434900000
autotune=1
elif [ "$frequency" = "Other" ]; then
echo
@ -110,6 +116,39 @@ elif [ "$frequency" = "Other" ]; then
fi
if [ "$autotune" = "1" ]; then
threshold=1
delay=5
retries=5
echo "Starting Auto-tune scanning"
echo "Scan will stop when confidence exceeds threshold value of" $threshold "or after" $retries "retries"
tries=0
confidence=0
delay=$((delay-2)) # subtract 2 second built in delay
while [ $tries -le $retries ] && [ "$confidence" -le "$threshold" ]; do
sleep $delay
source /home/pi/venv/bin/activate
python3 /home/pi/CubeSatSim/groundstation/auto-tune.py 434900000 n 2> null > /home/pi/CubeSatSim/groundstation/auto-tune.txt
# echo "auto-tune.txt"
# cat /home/pi/CubeSatSim/groundstation/auto-tune.txt
confidence=$(awk '{print $2}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune confidence:" $confidence
tries=$((tries+1))
done
if [ "$confidence" -gt "$threshold" ]; then
frequency=$(awk '{print $1}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune frequency:" $frequency
else
echo "Auto tune failed, frequency unchanged"
fi
sleep 5
fi
echo "Frequency is" $frequency
echo
echo "If your CubeSatSim is transmitting in FUNcube mode (mode 7) you should get some frames after 30 seconds"

@ -39,7 +39,9 @@ sudo /etc/init.d/alsa-utils start
echo
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=360 --title="Packet Decoding with Direwolf" --text="Choose the frequency for packet decoding" --column="kHz" --column="Application" 144390 "APRS US 2m" 434900 "CubeSatSim" 144800 "APRS European 2m" 145175 "APRS Australian 2m" Other "Choose another frequency" 145825 "APRS on ISS" APRS "Test APRS decoding with CubeSatSim WAV file")
autotune=0
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=400 --title="Packet Decoding with Direwolf" --text="Choose the frequency for packet decoding" --column="kHz" --column="Application" 144390 "APRS US 2m" 434900 "CubeSatSim" Auto-tune "CubeSatSim Auto-tune" 144800 "APRS European 2m" 145175 "APRS Australian 2m" Other "Choose another frequency" 145825 "APRS on ISS" APRS "Test APRS decoding with CubeSatSim WAV file")
#echo $frequency
@ -77,6 +79,11 @@ elif [ "$choice" = "2" ] || [ "$frequency" = "434900" ] ; then
echo "If your CubeSatSim is transmitting in APRS mode (mode 1) then you should see packets."
echo
elif [ "$frequency" = "Auto-tune" ] ; then
frequency=434900000
autotune=1
elif [ "$choice" = "3" ] || [ "$frequency" = "144800" ]; then
frequency=144800000
@ -157,7 +164,41 @@ echo
#fi
sleep 5
#sleep 5
if [ "$autotune" = "1" ]; then
threshold=1
delay=1
retries=30
echo "Starting Auto-tune scanning"
echo "Scan will stop when confidence exceeds threshold value of " $threshold " or after " $retries " retries"
tries=0
confidence=0
while [ $tries -le $retries ] && [ "$confidence" -le "$threshold" ]; do
# sleep $delay
source /home/pi/venv/bin/activate
python3 /home/pi/CubeSatSim/groundstation/auto-tune.py 434900000 n 2> null > /home/pi/CubeSatSim/groundstation/auto-tune.txt
# echo "auto-tune.txt"
# cat /home/pi/CubeSatSim/groundstation/auto-tune.txt
confidence=$(awk '{print $2}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune confidence: " $confidence
tries=$((tries+1))
done
if [ "$confidence" -gt "$threshold" ]; then
frequency=$(awk '{print $1}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune frequency: " $frequency
else
echo "Auto tune failed, frequency unchanged"
fi
echo
echo "If your CubeSatSim is transmitting in APRS mode (mode 1) then you should see packets."
echo
fi
value=`aplay -l | grep "Loopback"`
echo "$value" > /dev/null

@ -78,7 +78,7 @@ sudo killall -9 direwolf &>/dev/null
fi
sudo killall -9 direwolf &>/dev/null
# sudo killall -9 direwolf &>/dev/null
sleep 10

@ -43,7 +43,6 @@ if [[ $(gpio -g read 7 | grep 0) ]] ; then
else
echo "TXC not present"
txc=0
fi
timeout 1 rtl_test &> out.txt
if [[ $(grep "No supported" out.txt) ]] ; then
@ -54,6 +53,10 @@ else
rtl=1
fi
sudo killall -9 rtl_test &>/dev/null
fi
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
@ -108,6 +111,12 @@ elif [ "$loopback" = "1" ] ; then
unzip PacSatGround.zip -d PacSatGroundLoop
sudo rm PacSatGround.zip
mkdir PacSatGroundLoop/spacecraft
mv PacSatGroundLoop/PacSatGround/spacecraft/PacSatSim.properties PacSatGroundLoop/spacecraft/PacSatSim.properties
mv PacSatGroundLoop/PacSatGround/stp.dat PacSatGroundLoop/stp.dat
mv PacSatGroundLoop/PacSatGround/seq.dat PacSatGroundLoop/seq.dat
mv PacSatGroundLoop/PacSatGround/PacSatGround.properties PacSatGroundLoop/PacSatGround.properties
sudo sed -i 's/logfile_dir=\/home\/pi\/PacSatGround/logfile_dir=\/home\/pi\/PacSatGroundLoop/g' /home/pi/PacSatGroundLoop/PacSatGround.properties
FILE=/home/pi/Desktop/PacsatGround/spacecraft/PacSatSim.properties
@ -133,7 +142,7 @@ else
cd
sudo rm PacSatGround.zip &>/dev/null
wget https://github.com/alanbjohnston/CubeSatSim/raw/refs/heads/master-b/spacecraft/PacSatGround_0.46o/PacSatGround.zip
unzip PacSatGround.zip -d PacSatGround
unzip PacSatGround.zip
sudo rm PacSatGround.zip
FILE=/home/pi/Desktop/PacsatGround/spacecraft/PacSatSim.properties
@ -307,6 +316,8 @@ else
fi
sudo killall -9 rtl_test &>/dev/null
sleep 10
#echo "Stopping Pacsatsim"

@ -59,7 +59,7 @@ sudo systemctl restart openwebrx
sleep 10
setsid chromium-browser --check-for-update-interval=1 --simulate-critical-update --noerrdialogs --disable-infobars --app=http://localhost:8073 &>/dev/null &
setsid chromium-browser --password-store=basic --check-for-update-interval=1 --simulate-critical-update --noerrdialogs --disable-infobars --app=http://localhost:8073 &>/dev/null &
sleep 10

@ -39,7 +39,9 @@ sudo killall -9 rtl_fm &>/dev/null
#echo "s" >> .mode
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=220 --title="SSTV Decoding using QSSTV" --text="Choose the frequency for SSTV decoding:" --column="kHz" --column="Use" 145800 "ISS" 434900 "CubeSatSim" Other "Choose another frequency" SSTV "Test SSTV decoding with WAV file")
autotune=0
frequency=$(zenity --timeout=10 --list 2>/dev/null --width=410 --height=270 --title="SSTV Decoding using QSSTV" --text="Choose the frequency for SSTV decoding:" --column="kHz" --column="Use" 145800 "ISS" 434900 "CubeSatSim" Auto-tune "CubeSatSim Auto-tune" Other "Choose another frequency" SSTV "Test SSTV decoding with WAV file")
echo $frequency
@ -75,6 +77,11 @@ echo
echo "If your CubeSatSim is transmitting in SSTV mode (mode 4) you should get images."
echo "Note: if you see and hear an SSTV signal but don't get any images, the CubeSatSim signal might have a frequency offset. Try rebooting the CubeSatSim to fix."
elif [ "$frequency" = "Auto-tune" ]; then
frequency=434900000
autotune=1
elif [ "$choice" = "3" ] || [ "$frequency" = "Other" ]; then
echo
@ -120,14 +127,48 @@ echo
echo -e "Auto decoding SSTV on $frequency Hz"
sleep 2
#sleep 2
setsid qsstv &
sleep 5
#sleep 5
if [ "$autotune" = "1" ]; then
threshold=1
delay=5
retries=5
echo "Starting Auto-tune scanning"
echo "Scan will stop when confidence exceeds threshold value of" $threshold "or after" $retries "retries"
tries=0
confidence=0
delay=$((delay-2)) # subtract 2 second built in delay
while [ $tries -le $retries ] && [ "$confidence" -le "$threshold" ]; do
sleep $delay
source /home/pi/venv/bin/activate
python3 /home/pi/CubeSatSim/groundstation/auto-tune.py 434900000 n 2> null > /home/pi/CubeSatSim/groundstation/auto-tune.txt
# echo "auto-tune.txt"
# cat /home/pi/CubeSatSim/groundstation/auto-tune.txt
confidence=$(awk '{print $2}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune confidence:" $confidence
tries=$((tries+1))
done
if [ "$confidence" -gt "$threshold" ]; then
frequency=$(awk '{print $1}' /home/pi/CubeSatSim/groundstation/auto-tune.txt)
echo "Auto tune frequency:" $frequency
else
echo "Auto tune failed, frequency unchanged"
fi
echo
echo "If your CubeSatSim is transmitting in SSTV mode (mode 4) you should get images."
echo
#sudo systemctl restart cubesatsim
fi
#sudo systemctl restart cubesatsim
value=`aplay -l | grep "Loopback"`
echo "$value" > /dev/null

@ -404,12 +404,21 @@ fi
sudo systemctl disable gpsd
sudo systemctl disable gpsd.socket
if [ ! -d "/home/pi/WiringPi" ]; then
#if [ ! -d "/home/pi/WiringPi" ]; then
# cd
# git clone https://github.com/alanbjohnston/WiringPi
# cd WiringPi
# ./build debian
# sudo dpkg -i debian-template/wiringpi-2.61-1.deb
#fi
if [ ! -d "/home/pi/WiringPi3" ]; then
cd
git clone https://github.com/alanbjohnston/WiringPi
cd WiringPi
git clone https://github.com/WiringPi/WiringPi.git WiringPi3
cd WiringPi3
./build debian
sudo dpkg -i debian-template/wiringpi-2.61-1.deb
mv debian-template/wiringpi*.deb .
sudo apt install ./wiringpi*.deb
fi
cd
@ -611,6 +620,7 @@ fi
if [ ! -d "/home/pi/rpitx" ]; then
sudo apt install -y libraspberrypi-dev
cd
git clone https://github.com/alanbjohnston/rpitx.git
cd rpitx

@ -50,14 +50,14 @@ else
txc=0
fi
timeout 1 rtl_test &> out.txt
if [[ $(grep "No supported" out.txt) ]] ; then
echo "No RTL-SDR detected"
rtl=0
else
echo "RTL-SDR detected."
rtl=1
fi
#timeout 1 rtl_test &> out.txt
#if [[ $(grep "No supported" out.txt) ]] ; then
# echo "No RTL-SDR detected"
# rtl=0
#else
# echo "RTL-SDR detected."
# rtl=1
#fi
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null

Loading…
Cancel
Save

Powered by TurnKey Linux.