diff --git a/.gitignore b/.gitignore index 220663f2..c904aa40 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,23 @@ telem.wav cw.txt cwready logr.txt +command_control +command_control_direwolf +command_count.txt +command_tx +cw0.txt +cw1.txt +cw2.txt +cw3.txt +cw4.txt +cw5.txt +cw6.txt +logc.txt +telem.txt +telem_string.txt +test +transmit_dtmf +uptime +beacon_off +battery_saver + diff --git a/command b/command new file mode 100755 index 00000000..9c3b6ad8 --- /dev/null +++ b/command @@ -0,0 +1,120 @@ +#!/bin/bash + +echo -e "\nCommand and Control script for CubeSatSim v1.3.2\n" + + FILE=/home/pi/CubeSatSim/command_control + if [ -f "$FILE" ]; then + echo "Radio command and control is ON" +# echo "Turning Command and control to OFF" +# sudo rm /home/pi/CubeSatSim/command_control +# echo "rebooting" +# sudo systemctl stop rpitx +# sudo reboot now +# fi + + else + echo "Radio command and control is OFF" + + while true + do + sleep 60 + done + +# exit 1 + fi + +if [ "$1" = "d" ]; then + + echo "debug mode" + + debug=1 + +else + + debug=0 + +fi + +echo "Waiting 20 seconds for USB" + +sleep 20 + +FILE=/home/pi/CubeSatSim/command_control_direwolf +if [[ $(arecord -l | grep "USB Audio Device") ]] && [ -f "$FILE" ]; then + + echo "Starting Direwolf DTMF and APRS Command and Control" + + if [ "$debug" = "1" ]; then + + echo "debug mode" + + direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py d + + else + + direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py + + fi +else + + if [ -f "$FILE" ]; then + + echo "Direwolf mode set but no USB soundcard detected!" + +# echo "Trying RTL-FM" + + timeout 1 rtl_test &> out.txt + if [[ $(grep "No supported" out.txt) ]] ; then + + echo "No RTL-SDR detected. Command and control is OFF" +# sleep 60 + exit + + else + + echo "RTL-SDR detected." + sudo modprobe snd-aloop + + value=`aplay -l | grep "Loopback"` + echo "$value" > /dev/null + set -- $value + + rtl_fm -M fm -f 435M -s 48k | aplay -D hw:${2:0:1},0,0 -r 48000 -t raw -f S16_LE -c 1 & + + if [ "$debug" = "1" ]; then + + echo "debug mode" + + direwolf -r 48000 -c /home/pi/CubeSatSim/groundstation/direwolf/direwolf.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py d + + else + + direwolf -r 48000 -c /home/pi/CubeSatSim/groundstation/direwolf/direwolf.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py + + fi + + sleep 5 + fi + rm out.txt + else + + echo "Starting Carrier (squelch) Command and Control" + + fi + + if [ "$1" = "d" ]; then + + echo "debug mode" + + python3 /home/pi/CubeSatSim/squelch_cc.py d + + else + + python3 /home/pi/CubeSatSim/squelch_cc.py + + fi +fi + +sudo killall -9 direwolf &>/dev/null +sudo killall -9 rtl_fm &>/dev/null + diff --git a/config b/config index 05e902d8..2f5bdeb7 100755 --- a/config +++ b/config @@ -1,14 +1,237 @@ #!/bin/bash +function transmit_command_aprs { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-aprs.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=a" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to change mode to APRS " + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + +function transmit_command_fsk { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-fsk.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=f" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to change mode to FSK" + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + +function transmit_command_bpsk { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-bpsk.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=b" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to change mode to BPSK" + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + +function transmit_command_sstv { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-sstv.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=s" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to change mode to SSTV" + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + +function transmit_command_cw { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-cw.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=m" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to change mode to CW" + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + +function transmit_command_beacon { + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + + echo "Stopping command and control" + sudo systemctl stop command + + echo "Transmit DTMF start" + gpio write 28 0 # ptt + gpio write 2 1 # tx LED + timeout 3 direwolf -c /home/pi/CubeSatSim/direwolf/direwolf-transmit-dtmf-beacon.conf -t 0l + gpio write 2 0 # tx LED + gpio write 28 1 #ptt + echo "Transmit stop" + + echo "Resuming command and control" + sudo systemctl start command + + else + + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=o" + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet to toggle Beacon" + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 3 + + fi + + exit +} + echo "CubeSatSim v1.3.2 configuration tool" echo +# echo $1 +# echo $2 +# echo -if [ "$2" = "-n" ]; then - norestart=1 +sudo modprobe snd-aloop + +# if [ "$2" = "n" ] ; then +if [ -z "$2" ] ; then + noreboot=0 else - norestart=0 + noreboot=1 + echo "Reboot disabled" fi +# echo "No reboot" +# echo $noreboot + +reboot=0 +restart=0 + if [ "$1" = "" ]; then value=`cat /home/pi/CubeSatSim/.mode` echo "$value" > /dev/null @@ -24,6 +247,16 @@ if [ "$1" = "" ]; then echo "Mode is BPSK" elif [ "$1" = "s" ]; then echo "Mode is SSTV" + elif [ "$1" = "e" ]; then + echo "Mode is Repeater" + elif [ "$1" = "n" ]; then + echo -n "Mode is Transmit Commands with " + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + echo -n "DTMF" + else + echo -n "APRS" + fi else echo fi @@ -51,7 +284,7 @@ if [ "$1" = "" ]; then echo -n "Current command count is: " cat /home/pi/CubeSatSim/command_count.txt echo - echo +# echo # echo "Current beacon transmit mode is:" # cat /home/pi/CubeSatSim/command_tx # echo @@ -62,10 +295,28 @@ if [ "$1" = "" ]; then FILE=/home/pi/CubeSatSim/command_control if [ -f "$FILE" ]; then - echo "Radio command and control is ON" + + if [[ $(arecord -l | grep card) ]]; then + FILE=/home/pi/CubeSatSim/command_control_direwolf + if [ -f "$FILE" ]; then + echo "Radio DTMF/APRS command and control is ON" + else + echo "Radio carrier command and control is ON" + fi + else + echo "Radio carrier command and control is ON" + fi else echo "Radio command and control is OFF" fi + + echo + + echo -n "RX PL code is: " + echo -n ${10} +# echo + echo -n " TX PL code is: " + echo ${11} echo FILE=/home/pi/CubeSatSim/battery_saver @@ -75,11 +326,19 @@ if [ "$1" = "" ]; then echo "Battery saver mode is OFF" fi + echo + FILE=/home/pi/CubeSatSim/beacon_off + if [ -f "$FILE" ]; then + echo "Transmit beacon telemetry is OFF" + else + echo "Transmit beacon telemetry is ON" + fi + echo echo -e "Current sim.cfg configuration file:" # echo - echo $1 $2 $3 $4 $5 $6 $7 $8 $9 + echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} echo echo "To change, include an OPTION" @@ -90,81 +349,121 @@ if [ "$1" = "" ]; then elif [ "$1" = "-i" ]; then - echo "Rebooting CubeSatSim" - sudo reboot now -# sudo systemctl restart cubesatsim - exit + + reboot=1 + elif [ "$1" = "-a" ]; then - echo "changing CubeSatSim to AFSK mode" - sudo echo "a" > /home/pi/CubeSatSim/.mode - FILE=/home/pi/CubeSatSim/battery_saver - if [ -f "$FILE" ]; then - echo "Safe Mode! Battery saver mode is ON." -# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - else - echo "Battery saver mode is OFF." -# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_aprs + + else + + echo "changing CubeSatSim to AFSK mode" + sudo echo "a" > /home/pi/CubeSatSim/.mode + if [ "$1" == "f" ] || [ "$1" == "b" ] || [ "$1" == "e" ] ; then + FILE=/home/pi/CubeSatSim/battery_saver + if [ -f "$FILE" ]; then + restart=1 + else + reboot=1 + fi + else + restart=1 + fi fi - - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now -# sudo systemctl restart cubesatsim - exit elif [ "$1" = "-m" ]; then - echo "changing CubeSatSim to CW mode" - sudo echo "m" > /home/pi/CubeSatSim/.mode - FILE=/home/pi/CubeSatSim/battery_saver - if [ -f "$FILE" ]; then - echo "Safe Mode! Battery saver mode is ON." - # if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - else - echo "Battery saver mode is OFF." - # sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_cw + + else + + echo "changing CubeSatSim to CW mode" + sudo echo "m" > /home/pi/CubeSatSim/.mode + if [ "$1" == "f" ] || [ "$1" == "b" ] || [ "$1" == "e" ] ; then + FILE=/home/pi/CubeSatSim/battery_saver + if [ -f "$FILE" ]; then + restart=1 + else + reboot=1 + fi + else + restart=1 + fi fi - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now -# sudo systemctl restart cubesatsim - exit + elif [ "$1" = "-f" ]; then - echo "changing CubeSatSim to FSK mode" - sudo echo "f" > /home/pi/CubeSatSim/.mode -# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now -# sudo systemctl restart cubesatsim - exit + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_fsk + + else + + echo "changing CubeSatSim to FSK mode" + sudo echo "f" > /home/pi/CubeSatSim/.mode + restart=1 + fi + elif [ "$1" = "-b" ]; then - echo "changing CubeSatSim to BPSK mode" - sudo echo "b" > /home/pi/CubeSatSim/.mode -# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now -# sudo systemctl restart cubesatsim - exit + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_bpsk + + else + + echo "changing CubeSatSim to BPSK mode" + sudo echo "b" > /home/pi/CubeSatSim/.mode + restart=1 + fi + elif [ "$1" = "-s" ]; then - echo "changing CubeSatSim to SSTV mode" - sudo echo "s" > /home/pi/CubeSatSim/.mode - FILE=/home/pi/CubeSatSim/battery_saver - if [ -f "$FILE" ]; then - echo "Safe Mode! Battery saver mode ON." -# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - else - echo "Battery saver mode is OFF." -# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_sstv + + else + + echo "changing CubeSatSim to SSTV mode" + sudo echo "s" > /home/pi/CubeSatSim/.mode + if [ "$1" == "f" ] || [ "$1" == "b" ] || [ "$1" == "e" ] ; then + + FILE=/home/pi/CubeSatSim/battery_saver + if [ -f "$FILE" ]; then + restart=1 + else + reboot=1 + fi + else + restart=1 + fi fi - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now -# sudo systemctl restart cubesatsim - exit elif [ "$1" = "-t" ]; then @@ -185,7 +484,7 @@ elif [ "$1" = "-t" ]; then echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} echo "Do you want Simulated Telemetry ON (y/n) " read sim @@ -202,14 +501,15 @@ elif [ "$1" = "-t" ]; then # echo echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" # echo - echo $1 $2 $3 $4 $sim $6 $7 $8 $9 - echo $1 $2 $3 $4 $sim $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg - echo - echo "Rebooting CubeSatSim with new configuration file" + echo $1 $2 $3 $4 $sim $6 $7 $8 $9 ${10} + echo $1 $2 $3 $4 $sim $6 $7 $8 $9 ${10} > /home/pi/CubeSatSim/sim.cfg echo +## echo "Rebooting CubeSatSim with new configuration file" +## echo - sudo reboot now -# sudo systemctl restart cubesatsim + reboot=1 +## sudo reboot now +# sudo restart cubesatsim elif [ "$1" = "-c" ]; then @@ -229,7 +529,7 @@ elif [ "$1" = "-c" ]; then echo $1 echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} echo "Enter callsign in all capitals: " read callsign @@ -243,17 +543,18 @@ elif [ "$1" = "-c" ]; then echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" - echo $callsign $2 $3 $4 $5 $6 $7 $8 $9 - echo $callsign $2 $3 $4 $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg + echo $callsign $2 $3 $4 $5 $6 $7 $8 $9 ${10} + echo $callsign $2 $3 $4 $5 $6 $7 $8 $9 ${10} > /home/pi/CubeSatSim/sim.cfg fi if [ "$norestart" = "1" ]; then echo else echo - echo "Rebooting CubeSatSim with new configuration file" - echo - sudo reboot now +## echo "Rebooting CubeSatSim with new configuration file" +## echo + reboot=1 +## sudo reboot now # sudo systemctl restart cubesatsim fi @@ -276,7 +577,7 @@ elif [ "$1" = "-r" ]; then echo $2 echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} echo -e "Enter Reset Count (integer): " @@ -296,17 +597,18 @@ elif [ "$1" = "-r" ]; then echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" - echo $1 $resets $3 $4 $5 $6 $7 $8 $9 - echo $1 $resets $3 $4 $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg + echo $1 $resets $3 $4 $5 $6 $7 $8 $9 ${10} + echo $1 $resets $3 $4 $5 $6 $7 $8 $9 ${10} > /home/pi/CubeSatSim/sim.cfg fi if [ "$norestart" = "1" ]; then echo else - echo - echo "Rebooting CubeSatSim with new configuration file" - echo - sudo reboot now +## echo +## echo "Rebooting CubeSatSim with new configuration file" +## echo + reboot=1 +## sudo reboot now # sudo systemctl restart cubesatsim fi @@ -330,7 +632,7 @@ elif [ "$1" = "-l" ]; then echo $3 echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} echo -e "Enter latitude (decimal degrees, positive is north): " @@ -372,16 +674,17 @@ elif [ "$1" = "-l" ]; then fi echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" - echo $1 $2 $lat $long $5 $6 $7 $8 $9 - echo $1 $2 $lat $long $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg + echo $1 $2 $lat $long $5 $6 $7 $8 $9 ${10} ${11} + echo $1 $2 $lat $long $5 $6 $7 $8 $9 ${10} ${11} > /home/pi/CubeSatSim/sim.cfg if [ "$norestart" = "1" ]; then echo else - echo - echo "Rebooting CubeSatSim with new configuration file" - echo - sudo reboot now +## echo +## echo "Rebooting CubeSatSim with new configuration file" +## echo + reboot=1 +## sudo reboot now # sudo systemctl restart cubesatsim fi @@ -408,15 +711,17 @@ elif [ "$1" = "-C" ]; then sudo systemctl stop cubesatsim sudo systemctl stop rpitx + sudo systemctl stop command sudo mv -f /home/pi/CubeSatSim/telem.txt /home/pi/CubeSatSim/telem.txt.bk sudo journalctl --rotate sudo journalctl --vacuum-time=1s - sudo systemctl reboot now + reboot=1 +## sudo systemctl reboot now - echo "rebooting" +## echo "rebooting" elif [ "$1" = "-T" ]; then @@ -434,10 +739,11 @@ elif [ "$1" = "-T" ]; then if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then echo "Command and control set to OFF" - sudo rm /home/pi/CubeSatSim/command_control - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now + sudo rm /home/pi/CubeSatSim/command_control > /dev/null 2>&1 +# reboot=1 + echo "restarting command and control" + sudo systemctl restart command +## sudo reboot now fi else @@ -450,11 +756,117 @@ elif [ "$1" = "-T" ]; then if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then echo "Command and control set to ON" sudo touch /home/pi/CubeSatSim/command_control - echo "rebooting" - sudo systemctl stop rpitx - sudo reboot now + echo "restarting command and control" +# reboot=1 + sudo systemctl restart command +## sudo reboot now + fi + + fi + +elif [ "$1" = "-d" ]; then + + echo + echo "Change command and control Direwolf state" + echo + if [[ $(arecord -l | grep card) ]]; then + : + else + echo "Note: No USB Sound Card is plugged in!" + echo "Direwolf will not run unless one is plugged in." + fi + + FILE=/home/pi/CubeSatSim/command_control_direwolf + if [ -f "$FILE" ]; then + echo "Radio command and control with Direwolf for DTMF and APRS is ON" + echo + echo "Do you want to turn Direwolf OFF and do Carrier command and control (y/n) " + read reset + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Command and control Direwolf set to OFF" + sudo rm /home/pi/CubeSatSim/command_control_direwolf > /dev/null 2>&1 +# reboot=1 +## echo "rebooting" + sudo systemctl restart command +## sudo reboot now + fi + + else + echo "Radio command and control with Direwolf for DTMF and APRS is OFF so carrier command and control is enabled" + echo + echo "Do you want to set command and control with Direwolf for DTMF and APRS to ON (y/n) " + read reset + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Command and control Direwolf set to ON" + sudo touch /home/pi/CubeSatSim/command_control_direwolf +## echo "rebooting" +# reboot=1 + sudo systemctl restart command + if [[ $(arecord -l | grep card) ]]; then + echo "restarting cubesatsim software" + sudo systemctl restart cubesatsim + fi +## sudo reboot now + fi + + fi + + FILE=/home/pi/CubeSatSim/command_control + if [ -f "$FILE" ]; then + echo + + else + echo "Radio command and control is OFF" + echo + echo "Do you want to set command and control to ON (y/n) " + read reset + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Command and control set to ON" + sudo touch /home/pi/CubeSatSim/command_control + echo "restarting command and control" +# reboot=1 + sudo systemctl restart command +## sudo reboot now + fi + + fi + +elif [ "$1" = "-D" ]; then + + echo + echo "Change Transmit Commands state" + echo + + FILE=/home/pi/CubeSatSim/transmit_dtmf + if [ -f "$FILE" ]; then + echo "Transmit Commands in DTMF is set" + echo + echo "Do you want to Transmit Commands in APRS (y/n) " + read reset + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Transmit Commands in APRS" + sudo rm /home/pi/CubeSatSim/transmit_dtmf > /dev/null 2>&1 fi + else + echo "Transmit Commands in APRS is set" + echo + echo "Do you want to Transmit Commands in DTMF (y/n) " + read reset + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Transmit Commands in DTMF" + touch /home/pi/CubeSatSim/transmit_dtmf + fi fi elif [ "$1" = "-R" ]; then @@ -472,7 +884,7 @@ elif [ "$1" = "-R" ]; then echo if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then - sudo rm /home/pi/CubeSatSim/command_count.txt + sudo rm /home/pi/CubeSatSim/command_count.txt > /dev/null 2>&1 echo "Commands count reset to 0" echo "0\n" > /home/pi/CubeSatSim/command_count.txt else @@ -501,7 +913,7 @@ elif [ "$1" = "-B" ]; then read saver echo - reboot=0 +## reboot=0 if [ "$saver" = "y" ] || [ "$saver" = "yes" ] ; then if [ "$mode" = "0" ] ; then @@ -513,7 +925,7 @@ elif [ "$1" = "-B" ]; then if [ "$mode" = "1" ] ; then echo "Safe Mode will be turned OFF. Battery saver mode will be turned OFF" - sudo rm /home/pi/CubeSatSim/battery_saver + sudo rm /home/pi/CubeSatSim/battery_saver > /dev/null 2>&1 reboot=1 fi fi @@ -524,11 +936,13 @@ elif [ "$1" = "-B" ]; then set -- $value if [ "$1" = "a" ] || [ "$1" = "s" ] || [ "$1" = "m" ] ; then - echo "rebooting" - sudo reboot now + reboot=1 +## echo "rebooting" +## sudo reboot now else - echo "restarting" - sudo systemctl restart cubesatsim + restart=1 +## echo "restarting" +## sudo systemctl restart cubesatsim fi fi @@ -548,9 +962,9 @@ elif [ "$1" = "-q" ]; then echo $6 echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} - echo -e "Enter squelch (integer 0 - 8): " + echo -e "Enter squelch (integer 1 - 8): " read sq @@ -570,13 +984,94 @@ elif [ "$1" = "-q" ]; then # echo echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" # echo - echo $1 $2 $3 $4 $5 $sq $7 $8 $9 - echo $1 $2 $3 $4 $4 $sq $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg + echo $1 $2 $3 $4 $5 $sq $7 $8 $9 ${10} ${11} + echo $1 $2 $3 $4 $4 $sq $7 $8 $9 ${10} ${11} > /home/pi/CubeSatSim/sim.cfg + echo + echo "Restarting CubeSatSim with new configuration file" +## echo + +# reboot=1 +## sudo reboot now + sudo systemctl restart rpitx + +elif [ "$1" = "-Q" ]; then + +# echo + echo "Reading current Squelch for 10 seconds" + echo "Squelch is active low (0 means squelch broken)" echo - echo "Rebooting CubeSatSim with new configuration file" + + timeout 10 bash -c -- 'while true; do (gpio read 22 && sleep 1); done' + +elif [ "$1" = "-P" ]; then + + echo + echo "Editing the PL (Private Line) CTCSS/CDCSS setting in" + echo "the configuration file for CubeSatSim" + echo + + value=`cat /home/pi/CubeSatSim/sim.cfg` + echo "$value" > /dev/null + set -- $value + + echo + echo "Current value of RX PL is" + echo ${10} + echo "Current value of TX PL is" + echo ${11} + echo + +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} + + echo -e "Enter RX PL value integer 0: None, 01-38: CTCSS (analog, 39-121:CDCSS (digital)" + + read rxpl + + if [ -z $rxpl ] ; then + + rxpl="${10}" + echo "Keeping value of" $rxpl + else + restart=1 + fi + + if ! [[ $rxpl =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]] ; then + + echo "Error: not a number!" + rxpl="${10}" + echo "Keeping value of" $rxpl + else + restart=1 + fi + + echo -e "Enter TX PL value integer 0: None, 01-38: CTCSS (analog, 39-121:CDCSS (digital)" + + read txpl + + if [ -z $txpl ] ; then + + txpl="${11}" + echo "Keeping value of" $txpl + fi + + if ! [[ $txpl =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]] ; then + + echo "Error: not a number!" + txpl="${11}" + echo "Keeping value of" $txpl + fi + +# echo + echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" +# echo + echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $rxpl $txpl + echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $rxpl $txpl > /home/pi/CubeSatSim/sim.cfg echo +## echo "Rebooting CubeSatSim with new configuration file" +## echo - sudo reboot now + reboot=1 +## sudo reboot now # sudo systemctl restart cubesatsim elif [ "$1" = "-F" ]; then @@ -600,7 +1095,7 @@ elif [ "$1" = "-F" ]; then echo $8 echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} echo "Enter tx frequency as 4XX.XXXX: " read tx @@ -623,19 +1118,72 @@ elif [ "$1" = "-F" ]; then echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" - echo $1 $2 $3 $4 $5 $6 $tx $rx $9 - echo $1 $2 $3 $4 $5 $6 $tx $rx $9 > /home/pi/CubeSatSim/sim.cfg + echo $1 $2 $3 $4 $5 $6 $tx $rx $9 ${10} ${11} + echo $1 $2 $3 $4 $5 $6 $tx $rx $9 ${10} ${11} > /home/pi/CubeSatSim/sim.cfg # fi # if [ "$norestart" = "1" ]; then # echo # else echo - echo "Rebooting CubeSatSim with new configuration file" - echo - sudo reboot now -# sudo systemctl restart cubesatsim + echo "Restarting CubeSatSim with new configuration file" +## echo +# reboot=1 +## sudo reboot now + sudo systemctl restart rpitx # fi + +elif [ "$1" = "-o" ]; then + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" == "n" ]; then + + transmit_command_beacon + + else + echo + echo "Change telemetry beacon transmit state" + echo + + FILE=/home/pi/CubeSatSim/beacon_off + if [ -f "$FILE" ]; then + echo "Transmit beacon telemetry is off" +# echo +# echo "Do you want to turn beacon telemetry ON (y/n) " +# read reset + + reset="y" + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Turn beacon telemetry ON" + sudo rm /home/pi/CubeSatSim/beacon_off > /dev/null 2>&1 + sudo systemctl restart rpitx + # sudo python3 -u /home/pi/CubeSatSim/rpitx.py s & > /dev/null 2>&1 + + # restart=1 + fi + + else + echo "Transmit beacon telemetry is on" +# echo +# echo "Do you want to turn beacon telemetry OFF (y/n) " +# read reset + reset="y" + echo + + if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then + echo "Turn beacon telemetry OFF" + touch /home/pi/CubeSatSim/beacon_off + sudo systemctl restart rpitx + # restart=1 + fi + fi + fi + elif [ "$1" = "-H" ]; then # echo @@ -655,7 +1203,7 @@ elif [ "$1" = "-H" ]; then echo -# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 +# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} echo "Do you want Balloon mode ON (y/n) " read hab @@ -672,13 +1220,14 @@ elif [ "$1" = "-H" ]; then # echo echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" # echo - echo $1 $2 $3 $4 $5 $6 $7 $8 $hab - echo $1 $2 $3 $4 $5 $6 $7 $8 $hab > /home/pi/CubeSatSim/sim.cfg - echo - echo "Rebooting CubeSatSim with new configuration file" + echo $1 $2 $3 $4 $5 $6 $7 $8 $hab ${10} ${11} + echo $1 $2 $3 $4 $5 $6 $7 $8 $hab ${10} ${11} > /home/pi/CubeSatSim/sim.cfg echo +## echo "Rebooting CubeSatSim with new configuration file" +## echo - sudo reboot now + reboot=1 +## sudo reboot now # sudo systemctl restart cubesatsim elif [ "$1" = "-p" ]; then @@ -696,7 +1245,126 @@ elif [ "$1" = "-v" ]; then echo /home/pi/CubeSatSim/telem +elif [ "$1" = "-e" ]; then + + echo "changing CubeSatSim to Repeater mode" + sudo echo "e" > /home/pi/CubeSatSim/.mode + + restart=1 + +elif [ "$1" = "-n" ]; then + + echo "changing CubeSatSim to Transmit Commands mode" + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" = "n" ]; then + echo "Turning Transmit Command and Control mode OFF" + echo "Switching to FSK mode" + sudo echo "f" > /home/pi/CubeSatSim/.mode + reboot=1 + else + echo "Turning Transmit Command and Control mode ON" + sudo echo "n" > /home/pi/CubeSatSim/.mode + restart=1 + fi + +elif [ "$1" = "-A" ]; then + + echo "Transmit APRS control packets to control another CubeSatSim" + echo + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" != "n" ]; then + + sudo systemctl stop cubesatsim + sudo systemctl stop rpitx + # sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + + sudo python3 -u /home/pi/CubeSatSim/rpitx.py x > /dev/null 2>&1 & # Force APRS mode + fi + + sim="y" + + while [ "$sim" = "y" ] + do + + echo "Enter the mode number to change: 1=APRS, 2=FSK, 3=BPSK, 4=SSTV, 5=CW" + read MODE + + case $MODE in + + 1) + echo "Mode 1 is APRS" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=a" + ;; + 2) + echo "Mode 2 is FSK" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=f" + ;; + 3) + echo "Mode 3 is BPSK" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=b" + ;; + 4) + echo "Mode 4 is SSTV" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=s" + ;; + 5) + echo "Mode 5 is CW" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=m" + ;; + *) + echo "Unknown mode" + STRING="AMSAT-11>APCSS:=3901.40N\07704.39WShi hi MODE=?" + ;; + esac + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 + echo $STRING > /home/pi/CubeSatSim/t.txt + echo + echo -n "Sending APRS packet " + echo $STRING + sudo touch /home/pi/CubeSatSim/ready + sleep 5 + sudo touch /home/pi/CubeSatSim/ready + + echo + echo "Do you want to send another APRS command packet (y/n) " + read sim + echo + done + sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1 +# sudo systemctl restart cubesatsim + + if [ "$1" != "n" ]; then + + reboot=1 + fi + +elif [ "$1" = "-L" ]; then + + echo + echo "Setting microphone level for command and control" + echo + + echo -e "Enter microphone level in percentage (integer 0 - 100): " + + read mic + + if ! [ -z $mic ] && [[ $mic =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]] ; then + echo "Updating mic level" + value=`arecord -l | grep "card"` && echo "$value" > /dev/null && set -- $value && amixer -c ${2:0:1} set Mic $mic% + else + echo "Not updating mic level" + fi + elif [ "$1" = "-h" ]; then + echo "config OPTION" echo echo "Changes CubeSatSim mode, resets, or modifies configuration file" @@ -707,7 +1375,9 @@ elif [ "$1" = "-h" ]; then echo " -f Change to FSK/DUV mode" echo " -b Change to BPSK mode" echo " -s Change to SSTV mode" - echo " -i Reboots CubeSatsim software" + echo " -n Change to Transmit Commands mode" + echo " -e Change to Repeater mode" + echo " -i Restart CubeSatsim software" echo " -c Change the CALLSIGN in the configuration file sim.cfg" echo " -t Change the Simulated Telemetry setting in sim.cfg" echo " -r Change the Resets Count in the configuration file sim.cfg" @@ -715,13 +1385,19 @@ elif [ "$1" = "-h" ]; then echo " -S Scan both I2C buses on the Raspberry Pi" echo " -C Clear logs" echo " -T Change command and control state" + echo " -d Change command and control Direwolf state" echo " -R Change the Commands Count in the file command_count.txt" echo " -B Change Safe Mode (battery saver mode) manually" echo " -q Change the Squelch setting for command receiver" - echo " -F Change the rx and tx frequency" - echo " -H Chnage the Balloon mode" + echo " -F Change the RX and TX frequency" + echo " -H Change the Balloon (HAB) mode" echo " -p Display payload sensor data" echo " -v Display voltage and current data" + echo " -P Change the PL (Private Line) CTCSS/CDCSS codes for RX and TX" + echo " -A Transmit APRS control packets to control another CubeSatSim" + echo " -D Change Transmit Commands state APRS or DTMF" + echo " -o Change telemetry beacon transmit state" + echo " -L Change microphone level for command and control" echo exit @@ -733,3 +1409,32 @@ else fi # sudo systemctl restart cubesatsim + +# echo "Checking for reboot or restart" + +# echo $noreboot + +#reboot=0 +#restart=1 + +if [ "$reboot" = "1" ] ; then + if [ "$noreboot" = "0" ] ; then + echo 'Reboot due to config change!' | wall + echo "Rebooting" + sudo systemctl stop rpitx + sudo reboot now + else + echo "Reboot needed for changes to take effect" + fi +fi + +if [ "$restart" = "1" ] ; then + if [ "$reboot" = "0" ] ; then + echo "Restarting" +# sudo systemctl stop rpitx + sudo systemctl restart cubesatsim + sudo systemctl restart rpitx + else + echo "Restart needed for changes to take effect" + fi +fi diff --git a/direwolf-cc.conf b/direwolf-cc.conf new file mode 100644 index 00000000..8419355f --- /dev/null +++ b/direwolf-cc.conf @@ -0,0 +1,2 @@ +ADEVICE hw:CARD=Device,DEV=0 default +DTMF diff --git a/direwolf/direwolf-transmit-dtmf-aprs.conf b/direwolf/direwolf-transmit-dtmf-aprs.conf new file mode 100644 index 00000000..786102cd --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-aprs.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="1 #" delay=0 diff --git a/direwolf/direwolf-transmit-dtmf-beacon.conf b/direwolf/direwolf-transmit-dtmf-beacon.conf new file mode 100644 index 00000000..6c022dea --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-beacon.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="10 #" delay=0 diff --git a/direwolf/direwolf-transmit-dtmf-bpsk.conf b/direwolf/direwolf-transmit-dtmf-bpsk.conf new file mode 100644 index 00000000..a0ae9b54 --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-bpsk.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="3 #" delay=0 diff --git a/direwolf/direwolf-transmit-dtmf-cw.conf b/direwolf/direwolf-transmit-dtmf-cw.conf new file mode 100644 index 00000000..8629754f --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-cw.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="5 #" delay=0 diff --git a/direwolf/direwolf-transmit-dtmf-fsk.conf b/direwolf/direwolf-transmit-dtmf-fsk.conf new file mode 100644 index 00000000..f197e583 --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-fsk.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="2 #" delay=0 diff --git a/direwolf/direwolf-transmit-dtmf-sstv.conf b/direwolf/direwolf-transmit-dtmf-sstv.conf new file mode 100644 index 00000000..c58cb77f --- /dev/null +++ b/direwolf/direwolf-transmit-dtmf-sstv.conf @@ -0,0 +1,5 @@ +ADEVICE hw:CARD=Loopback,DEV=0 hw:CARD=Headphones,DEV=0 +MYCALL AMSAT +CHANNEL 0 +MODEM 1200 +CBEACON dest="DTMF-3" info="4 #" delay=0 diff --git a/dtmf_aprs_cc.py b/dtmf_aprs_cc.py new file mode 100644 index 00000000..824a6258 --- /dev/null +++ b/dtmf_aprs_cc.py @@ -0,0 +1,190 @@ +import sys +from os import system +import RPi.GPIO as GPIO +from RPi.GPIO import output +from time import sleep +import logging +logging.basicConfig(format='%(message)s') +# logging.warning('CC-Warning!') + +if __name__ == "__main__": + powerPin = 16 + txLed = 27 + change_mode = False + debug_mode = False + counter = 1 + if (len(sys.argv)) > 1: +# print("There are arguments!") + if ('d' == sys.argv[1]): + debug_mode = True + + for line in sys.stdin: +# if (debug_mode): + print(line, end =" ") + logging.warning(line) + +# if '^c' == line.rstrip(): +# break + + if ((line.find("MODE=a")) > 0): + system("echo '\nAPRS Mode!!\n'") + mode = 'a' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t1#")) > 0): + system("echo '\nAPRS Mode!!\n'") + mode = 'a' + change_mode = True + if ((line.find("MODE=f")) > 0): + system("echo '\nFSK Mode!!\n'") + mode = 'f' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t2#")) > 0): + system("echo '\nFSK Mode!!\n'") + mode = 'f' + change_mode = True + if ((line.find("MODE=b")) > 0): + system("echo '\nBPSK Mode!!\n'") + mode = 'b' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t3#")) > 0): + system("echo '\nBPSK Mode!!\n'") + mode = 'b' + change_mode = True + if ((line.find("MODE=s")) > 0): + system("echo '\nSSTV Mode!!\n'") + mode = 's' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t4#")) > 0): + system("echo '\nSSTV Mode!!\n'") + mode = 's' + change_mode = True + if ((line.find("MODE=m")) > 0): + system("echo '\nCW Mode!!\n'") + mode = 'm' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t5#")) > 0): + system("echo '\nCW Mode!!\n'") + mode = 'm' + change_mode = True + if ((line.find("MODE=o")) > 0): + system("echo '\nBeacon Mode toggle!!\n'") + mode = 'o' + change_mode = True + counter = (counter + 1) % 2 + if ((line.find("DTMF>APDW15:t10#")) > 0): + system("echo '\nBeacon Mode toggle!!\n'") + mode = 'o' + change_mode = True + + if (debug_mode == False) and (change_mode == True) and (counter == 1): # skip every other APRS command since Direwolf prints them twice + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + GPIO.setup(powerPin, GPIO.OUT) + GPIO.setup(txLed, GPIO.OUT) + + if (mode == 'f'): + GPIO.output(powerPin, 0) # blink two times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 'b'): + GPIO.output(powerPin, 0) # blink three times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 's'): + GPIO.output(powerPin, 0) # blink four times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 'm'): + GPIO.output(powerPin, 0) # blink five times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1); + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + elif (mode == 'a'): + mode = 'a' + GPIO.output(powerPin, 0) # blink one time + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + try: + file = open("/home/pi/CubeSatSim/command_count.txt", "r") + string = file.read() + file.close() + command_count = int(string) + command_count += 1 + filec = open("/home/pi/CubeSatSim/command_count.txt", "w") + command_count_string = str(command_count) + print(command_count_string) + string = filec.write(command_count_string) + filec.close() + except: + print("Can't write command_count file!") + print("Command_count: ") + print(command_count) + + GPIO.output(txLed, 0) + GPIO.output(powerPin, 0) + system("sudo systemctl stop rpitx") +# system("sudo systemctl stop cubesatsim") + + print("\n/home/pi/CubeSatSim/config -" + mode) + system("/home/pi/CubeSatSim/config -" + mode) + + + change_mode = False + + print("Waiting 5 seconds to allow unplug and plug of soundcard") + sleep(5) + print("Done") + diff --git a/install b/install index b6a45720..137b2fed 100755 --- a/install +++ b/install @@ -39,22 +39,27 @@ sudo apt-get install -y git libasound2-dev i2c-tools build-essential libgd-dev l cd /tmp -wget https://project-downloads.drogon.net/wiringpi-latest.deb +# wget https://project-downloads.drogon.net/wiringpi-latest.deb -sudo dpkg -i wiringpi-latest.deb +# sudo dpkg -i wiringpi-latest.deb +cd + +git clone https://github.com/alanbjohnston/WiringPi +cd WiringPi +./build debian + +sudo dpkg -i debian-template/wiringpi-2.61-1.deb cd #changed to python3-smbus -sudo apt install -y python3-pip python3-smbus +sudo apt install -y python3-pip python3-smbus libjpeg-dev zlib1g-dev libfreetype6-dev libopenjp2-7 libtiff5 python3-pil python3-serial sudo pip3 install --upgrade setuptools sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219 - - cd ~/CubeSatSim git pull --no-rebase @@ -88,7 +93,7 @@ git clone https://github.com/alanbjohnston/pi-power-button.git cd pi-power-button -git checkout reboot-mode-change +git checkout reboot-mode-change-beta ./script/install @@ -128,6 +133,10 @@ sudo cp ~/CubeSatSim/systemd/rpitx.service /etc/systemd/system/rpitx.service sudo systemctl enable rpitx +sudo cp ~/CubeSatSim/systemd/command.service /etc/systemd/system/command.service + +sudo systemctl enable command + sudo cp /boot/config.txt /boot/config.txt.0 sudo cp /boot/cmdline.txt /boot/cmdline.txt.0 @@ -239,15 +248,17 @@ if [ -z "$6" ] ; then n6="3" ; changed=1 ; else n6=$6 ; fi # squelch if [ -z "$7" ] ; then n7="434.9000" ; changed=1 ; else n7=$7 ; fi # transmit frequency if [ -z "$8" ] ; then n8="435.0000" ; changed=1 ; else n8=$8 ; fi # receive frequency if [ -z "$9" ] ; then n9="no" ; changed=1 ; else n9=$9 ; fi # hab mode +if [ -z "$10" ] ; then n10="0" ; changed=1 ; else n10=$10 ; fi # rx pl code +if [ -z "$11" ] ; then n11="0" ; changed=1 ; else n11=$11 ; fi # tx pl code if [ $changed -eq 1 ]; then echo -e "Current sim.cfg configuration file:" echo - echo $1 $2 $3 $4 $5 $6 $7 $8 $9 + echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" echo - echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 - echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 > /home/pi/CubeSatSim/sim.cfg + echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $10 $11 + echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $10 $11 > /home/pi/CubeSatSim/sim.cfg echo fi diff --git a/log b/log index 9518703d..3ce868f7 100755 --- a/log +++ b/log @@ -5,7 +5,11 @@ echo -e "\nLog file script for CubeSatSim\n" if [ "$1" = "-r" ]; then sudo journalctl -a -u rpitx > /home/pi/CubeSatSim/logr.txt cat /home/pi/CubeSatSim/logr.txt - echo -e "\nLog file also saved as /home/pi/CubeSatSim/logr.txt" + echo -e "\nTransmit Log file also saved as /home/pi/CubeSatSim/logr.txt" +elif [ "$1" = "-c" ]; then + sudo journalctl -a -u command > /home/pi/CubeSatSim/logc.txt + cat /home/pi/CubeSatSim/logc.txt + echo -e "\nCommand and Control Log file also saved as /home/pi/CubeSatSim/logc.txt" else sudo journalctl -a -u cubesatsim > /home/pi/CubeSatSim/log.txt cat /home/pi/CubeSatSim/log.txt diff --git a/main.c b/main.c index 75e9bb2f..15a31e6d 100644 --- a/main.c +++ b/main.c @@ -19,28 +19,58 @@ * along with this program. If not, see . */ - #include "main.h" //#define HAB // uncomment to change APRS icon from Satellite to Balloon and only BAT telemetry int main(int argc, char * argv[]) { - char resbuffer[1000]; - const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; +// const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '9000'"; + const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); fprintf(stderr, "Pi test result: %s\n", resbuffer); fclose(file_test); + + FILE * uptime_file = fopen("/proc/uptime", "r"); + fscanf(uptime_file, "%f", & uptime_sec); + printf("Uptime sec: %f \n", uptime_sec); + fclose(uptime_file); fprintf(stderr, " %x ", resbuffer[0]); fprintf(stderr, " %x \n", resbuffer[1]); - if ((resbuffer[0] == '9') && (resbuffer[1] == '0')) + if ((resbuffer[0] != '9') || (resbuffer[1] != '0') || (resbuffer[2] != '0') || (resbuffer[3] != '0')) { - sleep(5); // try sleep at start to help boot // voltageThreshold = 3.7; - printf("Pi Zero 2 detected\n"); + fprintf(stderr, "Pi Zero not detected (could be Pi Zero 2)\n"); + pi_zero_2_offset = 500; + if (uptime_sec < 30.0) { + FILE * rpitx_stop = popen("sudo systemctl start rpitx", "r"); + pclose(rpitx_stop); + fprintf(stderr, "Sleep 5 sec"); + sleep(5); // try sleep at start to help boot + } + } + else { + fprintf(stderr,"Pi Zero detected\n"); + FILE * command_file = fopen("/home/pi/CubeSatSim/command_control", "r"); + if (command_file == NULL) { + pi_zero_2_offset = 500; + fprintf(stderr,"Command and control is OFF\n"); + } else { + command_file = fopen("/home/pi/CubeSatSim/command_control_direwolf", "r"); + if (command_file == NULL) { + pi_zero_2_offset = 500; + fprintf(stderr,"Command and control Carrier (squelch) is ON\n"); + } + } + if (uptime_sec < 30.0) { + FILE * rpitx_stop = popen("sudo systemctl start rpitx", "r"); + pclose(rpitx_stop); + fprintf(stderr,"Sleep 10 sec"); + sleep(10); + } } printf("\n\nCubeSatSim v1.3.2 starting...\n\n"); @@ -59,11 +89,11 @@ int main(int argc, char * argv[]) { // char * cfg_buf[100]; - fscanf(config_file, "%s %d %f %f %s %d %s %s %s", - call, & reset_count, & lat_file, & long_file, sim_yes, & squelch, tx, rx, hab_yes); + fscanf(config_file, "%s %d %f %f %s %d %s %s %s %d %d", + call, & reset_count, & lat_file, & long_file, sim_yes, & squelch, tx, rx, hab_yes, & rx_pl, & tx_pl); fclose(config_file); - fprintf(stderr,"Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s %d %s %s %s\n", - call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes); + fprintf(stderr,"Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s %d %s %s %s %d %d\n", + call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes, rx_pl, tx_pl); fprintf(stderr, "Transmit on %s Receive on %s\n", tx, rx); @@ -99,8 +129,11 @@ int main(int argc, char * argv[]) { } // FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r"); - FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r"); - pclose(rpitx_stop); +// FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r"); + + +// FILE * cc_start = popen("/home/pi/CubeSatSim/command &", "r"); +// pclose(cc_start); // FILE * file_deletes = popen("sudo rm /home/pi/CubeSatSim/ready /home/pi/CubeSatSim/cwready > /dev/null", "r"); // pclose(file_deletes); @@ -176,6 +209,12 @@ int main(int argc, char * argv[]) { } else if ( mode_string == 'm') { mode = CW; printf("Mode is CW\n"); + } else if ( mode_string == 'e') { + mode = REPEATER; + printf("Mode is Repeater\n"); + } else if ( mode_string == 'n') { + mode = TXCOMMAND; + printf("Mode is Transmit Command\n"); } else { printf("Mode is FSK\n"); } @@ -240,9 +279,23 @@ int main(int argc, char * argv[]) { pclose(file); } - txLed = 0; // defaults for vB3 board without TFB - txLedOn = LOW; - txLedOff = HIGH; + txLed = 2; + txLedOn = HIGH; + txLedOff = LOW; + vB5 = TRUE; + onLed = 27; + onLedOn = HIGH; + onLedOff = LOW; + + + pinMode(26, INPUT); + pullUpDnControl(26, PUD_UP); + + if (digitalRead(26) != HIGH) { + printf("v1 Present with UHF BPF\n"); + transmit = TRUE; + } +/* if (!ax5043) { pinMode(2, INPUT); pullUpDnControl(2, PUD_UP); @@ -306,15 +359,16 @@ int main(int argc, char * argv[]) { } } } - pinMode(txLed, OUTPUT); - digitalWrite(txLed, txLedOff); + */ +// pinMode(txLed, OUTPUT); +// digitalWrite(txLed, txLedOff); #ifdef DEBUG_LOGGING - printf("Tx LED Off\n"); +// printf("Tx LED Off\n"); #endif - pinMode(onLed, OUTPUT); - digitalWrite(onLed, onLedOn); +// pinMode(onLed, OUTPUT); +// digitalWrite(onLed, onLedOn); #ifdef DEBUG_LOGGING - printf("Power LED On\n"); +// printf("Power LED On\n"); #endif /* if (mode == SSTV) { @@ -325,7 +379,7 @@ int main(int argc, char * argv[]) { } */ config_file = fopen("sim.cfg", "w"); - fprintf(config_file, "%s %d %8.4f %8.4f %s %d %s %s %s", call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes); + fprintf(config_file, "%s %d %8.4f %8.4f %s %d %s %s %s %d %d", call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes, rx_pl, tx_pl); // fprintf(config_file, "%s %d", call, reset_count); fclose(config_file); config_file = fopen("sim.cfg", "r"); @@ -361,7 +415,7 @@ int main(int argc, char * argv[]) { char camera_present[] = "supported=1 detected=1"; // printf("strstr: %s \n", strstr( & cmdbuffer1, camera_present)); camera = (strstr( (const char *)& cmdbuffer, camera_present) != NULL) ? ON : OFF; - // printf("Camera result:%s camera: %d \n", & cmdbuffer1, camera); + printf("Camera result:%s camera: %d \n", & cmdbuffer, camera); pclose(file4); #ifdef DEBUG_LOGGING @@ -369,16 +423,19 @@ int main(int argc, char * argv[]) { #endif FILE * file5 = popen("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1", "r"); - file5 = popen("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1", "r"); + //file5 = popen("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1", "r"); pclose(file5); if (!ax5043) // don't test for payload if AX5043 is present { payload = OFF; - + fprintf(stderr,"Opening serial\n"); if ((uart_fd = serialOpen("/dev/ttyAMA0", 115200)) >= 0) { // was 9600 - printf("Serial opened to Pico\n"); -// payload = ON; + fprintf(stderr,"Serial opened to Pico\n"); +// payload = ON; + payload = get_payload_serial(FALSE); + fprintf(stderr,"Get_payload_status: %d \n", payload); // not debug + } else { fprintf(stderr, "Unable to open UART: %s\n -> Did you configure /boot/config.txt and /boot/cmdline.txt?\n", strerror(errno)); } @@ -433,11 +490,11 @@ int main(int argc, char * argv[]) { eclipse_time -= period / 2; // if starting in eclipse, shorten interval } - tx_freq_hz -= tx_channel * 50000; + // tx_freq_hz -= tx_channel * 50000; if (transmit == FALSE) { - fprintf(stderr, "\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n"); + fprintf(stderr, "\nNo CubeSatSim Low Pass Filter detected. No transmissions after the CW ID.\n"); fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } @@ -535,8 +592,7 @@ int main(int argc, char * argv[]) { other_min[i] = 1000.0; other_max[i] = -1000.0; } - - long int loopTime; + loopTime = millis(); while (loop-- != 0) { @@ -556,20 +612,16 @@ int main(int argc, char * argv[]) { uptime = (int) (uptime_sec + 0.5); // printf("Uptime sec: %f \n", uptime_sec); // #ifdef DEBUG_LOGGING - printf("INFO: Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); +// printf("INFO: Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); // #endif fclose(uptime_file); - - printf("++++ Loop time: %5.3f sec +++++\n", (millis() - loopTime)/1000.0); - fflush(stdout); - loopTime = millis(); { int count1; char * token; fputc('\n', file1); fgets(cmdbuffer, 1000, file1); - fprintf(stderr, "Python read Result: %s\n", cmdbuffer); +// fprintf(stderr, "Python read Result: %s\n", cmdbuffer); // serialPuts(uart_fd, cmdbuffer); // write INA data to Pico over serial @@ -613,20 +665,20 @@ int main(int argc, char * argv[]) { payload = get_payload_serial(FALSE); printf("get_payload_status: %d \n", payload); // not debug fflush(stdout); - printf("String: %s\n", buffer2); +// printf("String: %s\n", buffer2); fflush(stdout); strcpy(sensor_payload, buffer2); - printf(" Response from STEM Payload board: %s\n", sensor_payload); +// printf(" Response from STEM Payload board: %s\n", sensor_payload); telem_file = fopen("/home/pi/CubeSatSim/telem.txt", "a"); - printf("Writing payload string\n"); +// printf("Writing payload string\n"); time_t timeStamp; time(&timeStamp); // get timestamp // printf("Timestamp: %s\n", ctime(&timeStamp)); char timeStampNoNl[31], bat_string[31]; snprintf(timeStampNoNl, 30, "%.24s", ctime(&timeStamp)); - printf("TimeStamp: %s\n", timeStampNoNl); +// printf("TimeStamp: %s\n", timeStampNoNl); snprintf(bat_string, 30, "BAT %4.2f %5.1f", batteryVoltage, batteryCurrent); fprintf(telem_file, "%s %s %s\n", timeStampNoNl, bat_string, sensor_payload); // write telemetry string to telem.txt file fclose(telem_file); @@ -643,7 +695,7 @@ int main(int argc, char * argv[]) { if (token != NULL) { sensor[count1] = (float) atof(token); // #ifdef DEBUG_LOGGING - printf("sensor: %f ", sensor[count1]); // print sensor data +// printf("sensor: %f ", sensor[count1]); // print sensor data // #endif token = strtok(NULL, space); } @@ -672,8 +724,8 @@ int main(int argc, char * argv[]) { if ((millis() - newGpsTime) > 60000) { longitude += rnd_float(-0.05, 0.05) / 100.0; // was .05 latitude += rnd_float(-0.05, 0.05) / 100.0; - printf("GPS Location with Rnd: %f, %f \n", latitude, longitude); - printf("GPS Location with Rnd: APRS %07.2f, %08.2f \n", toAprsFormat(latitude), toAprsFormat(longitude)); +// printf("GPS Location with Rnd: %f, %f \n", latitude, longitude); +// printf("GPS Location with Rnd: APRS %07.2f, %08.2f \n", toAprsFormat(latitude), toAprsFormat(longitude)); newGpsTime = millis(); } @@ -773,7 +825,7 @@ int main(int argc, char * argv[]) { } #ifdef DEBUG_LOGGING - fprintf(stderr, "INFO: Battery voltage: %5.2f V Threshold %5.2f V Current: %6.1f mA Threshold: %6.1f mA\n", batteryVoltage, voltageThreshold, batteryCurrent, currentThreshold); +// fprintf(stderr, "INFO: Battery voltage: %5.2f V Threshold %5.2f V Current: %6.1f mA Threshold: %6.1f mA\n", batteryVoltage, voltageThreshold, batteryCurrent, currentThreshold); #endif if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode && !hab_mode) @@ -800,7 +852,11 @@ int main(int argc, char * argv[]) { fprintf(stderr, "Battery voltage too low: %f V - shutting down!\n", batteryVoltage); digitalWrite(txLed, txLedOff); digitalWrite(onLed, onLedOff); - + + FILE * file6; + file6 = popen("echo 'shutdown due to low battery voltage!' | wall", "r"); + pclose(file6); + sleep(1); digitalWrite(onLed, onLedOn); sleep(1); @@ -810,7 +866,6 @@ int main(int argc, char * argv[]) { sleep(1); digitalWrite(onLed, onLedOff); - FILE * file6; // = popen("/home/pi/CubeSatSim/log > shutdown_log.txt", "r"); file6 = popen("sudo shutdown -h now > /dev/null 2>&1", "r"); pclose(file6); sleep(10); @@ -819,7 +874,7 @@ int main(int argc, char * argv[]) { FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w"); if (fp != NULL) { - printf("Writing telem_string.txt\n"); +// printf("Writing telem_string.txt\n"); if (batteryVoltage != 4.5) fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent); else @@ -839,17 +894,17 @@ int main(int argc, char * argv[]) { if ((mode == AFSK) || (mode == CW)) { get_tlm(); sleep(25); - fprintf(stderr, "INFO: Sleeping for 25 sec\n"); +// fprintf(stderr, "INFO: Sleeping for 25 sec\n"); int rand_sleep = (int)rnd_float(0.0, 5.0); sleep(rand_sleep); - fprintf(stderr, "INFO: Sleeping for extra %d sec\n", rand_sleep); +// fprintf(stderr, "INFO: Sleeping for extra %d sec\n", rand_sleep); } else if ((mode == FSK) || (mode == BPSK)) {// FSK or BPSK get_tlm_fox(); } else { // SSTV - fprintf(stderr, "Sleeping\n"); - sleep(50); +// fprintf(stderr, "Sleeping\n"); + sleep(30); } #ifdef DEBUG_LOGGING @@ -862,17 +917,17 @@ int main(int argc, char * argv[]) { #ifdef DEBUG_LOGGING // printf("Tx LED On 1\n"); #endif - printf("Sleeping to allow BPSK transmission to finish.\n"); +// printf("Sleeping to allow BPSK transmission to finish.\n"); sleep((unsigned int)(loop_count * 5)); - printf("Done sleeping\n"); + // printf("Done sleeping\n"); // digitalWrite(txLed, txLedOff); #ifdef DEBUG_LOGGING // printf("Tx LED Off\n"); #endif } else if (mode == FSK) { - printf("Sleeping to allow FSK transmission to finish.\n"); +// printf("Sleeping to allow FSK transmission to finish.\n"); sleep((unsigned int)loop_count); - printf("Done sleeping\n"); +// printf("Done sleeping\n"); } return 0; @@ -1182,19 +1237,23 @@ void get_tlm_fox() { /**/ // while ((millis() - sampleTime) < (unsigned int)samplePeriod) int startSleep = millis(); - if ((millis() - sampleTime) < ((unsigned int)frameTime - 250)) // was 250 100 500 for FSK + if ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) // was 250 100 500 for FSK // sleep(2.0); // 0.5); // 25); // initial period sleep(1.0); // 0.5); // 25); // initial period - while ((millis() - sampleTime) < ((unsigned int)frameTime - 250)) // was 250 100 + while ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) // was 250 100 sleep(0.1); // 25); // 0.5); // 25); // sleep((unsigned int)sleepTime); /**/ - printf("Sleep period: %d\n", millis() - startSleep); + printf("Start sleep %d Sleep period: %d while period: %d\n", startSleep, millis() - startSleep, (unsigned int)frameTime - 750 + pi_zero_2_offset); fflush(stdout); sampleTime = (unsigned int) millis(); } else printf("first time - no sleep\n"); + + printf("++++ Loop time: %5.3f sec +++++\n", (millis() - loopTime)/1000.0); + fflush(stdout); + loopTime = millis(); // if (mode == FSK) { // just moved @@ -1222,7 +1281,7 @@ void get_tlm_fox() { if (mode == FSK) { if (loop % 32 == 0) { // was 8 - printf("Sending MIN frame \n"); +// printf("Sending MIN frame \n"); frm_type = 0x03; for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) { if (count1 < 3) @@ -1236,7 +1295,7 @@ void get_tlm_fox() { } } if ((loop + 16) % 32 == 0) { // was 8 - printf("Sending MAX frame \n"); +// printf("Sending MAX frame \n"); frm_type = 0x02; for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) { if (count1 < 3) @@ -1480,7 +1539,7 @@ void get_tlm_fox() { } else printf("Error opening command_count.txt!\n"); - printf("Command count: %d\n", groundCommandCount); +// printf("Command count: %d\n", groundCommandCount); int status = STEMBoardFailure + SafeMode * 2 + sim_mode * 4 + PayloadFailure1 * 8 + (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256; @@ -1735,14 +1794,14 @@ void get_tlm_fox() { // printf("Sending %d buffer bytes over socket after %d ms!\n", ctr, (long unsigned int)millis() - start); start = millis(); int sock_ret = send(sock, buffer, (unsigned int)(ctr * 2 + 2), 0); - printf("socket send 1 %d ms bytes: %d \n\n", (unsigned int)millis() - start, sock_ret); +// printf("socket send 1 %d ms bytes: %d \n\n", (unsigned int)millis() - start, sock_ret); fflush(stdout); if (sock_ret < (ctr * 2 + 2)) { // printf("Not resending\n"); sleep(0.5); sock_ret = send(sock, &buffer[sock_ret], (unsigned int)(ctr * 2 + 2 - sock_ret), 0); - printf("socket send 2 %d ms bytes: %d \n\n", millis() - start, sock_ret); +// printf("socket send 2 %d ms bytes: %d \n\n", millis() - start, sock_ret); } loop_count++; @@ -1766,7 +1825,7 @@ void get_tlm_fox() { { start = millis(); // send frame until buffer fills sock_ret = send(sock, buffer, (unsigned int)(ctr * 2 + 2), 0); - printf("socket send %d in %d ms bytes: %d \n\n",times + 2, (unsigned int)millis() - start, sock_ret); +// printf("socket send %d in %d ms bytes: %d \n\n",times + 2, (unsigned int)millis() - start, sock_ret); if ((millis() - start) > 500) { printf("Buffer over filled!\n"); @@ -2140,6 +2199,8 @@ if (setting == ON) { fprintf(stderr,"Turning Safe Mode ON\n"); fprintf(stderr,"Turning Battery saver mode ON\n"); if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { + command = popen("echo 'reboot due to turning ON Safe Mode!' | wall", "r"); + pclose(command); command = popen("sudo reboot now", "r"); pclose(command); sleep(60); @@ -2154,6 +2215,8 @@ if (setting == ON) { pclose(command); fprintf(stderr,"Turning Battery saver mode OFF\n"); if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { + command = popen("echo 'reboot due to turning OFF Safe Mode!' | wall", "r"); + pclose(command); command = popen("sudo reboot now", "r"); pclose(command); sleep(60); diff --git a/main.h b/main.h index 2f5b3fe6..eb82e27b 100644 --- a/main.h +++ b/main.h @@ -105,6 +105,8 @@ FILE *telem_file; #define BPSK 3 #define SSTV 4 #define CW 5 +#define REPEATER 11 +#define TXCOMMAND 12 int rpitxStatus = -1; @@ -132,6 +134,8 @@ char sim_yes[10]; char hab_yes[10]; int squelch = 3; // default squelch char rx[12], tx[12]; +int tx_pl = 0; +int rx_pl = 0; int bitRate, mode, bufLen, rsFrames, payloads, rsFrameLen, dataLen, headerLen, syncBits, syncWord, parityLen, samples, frameCnt, samplePeriod; float sleepTime; @@ -182,10 +186,13 @@ int start_flag_detected = FALSE; int start_flag_complete = FALSE; int end_flag_detected = FALSE; int jpeg_start = 0; -#define CAMERA_TIMEOUT 2000 // 10000 // 20000 // Payload timeout in milli seconds +#define CAMERA_TIMEOUT 2000 // 1500 // 2000 // 10000 // 20000 // Payload timeout in milli seconds void battery_saver(int setting); -int battery_saver_check(); +int battery_saver_check(); +int pi_zero_2_offset = 0; + int hab_mode = FALSE; int battery_saver_mode = FALSE; +long int loopTime; diff --git a/rpitx.py b/rpitx.py index 01be5490..92db4929 100644 --- a/rpitx.py +++ b/rpitx.py @@ -9,52 +9,7 @@ from time import sleep import sys from os import system from PIL import Image, ImageDraw, ImageFont, ImageColor -import serial - -def command_control_check(): - - global command_control - global no_command - global debug_mode - global command_count - - output(pd, 1) - output(ptt, 1) - sleep(1) - if (no_command == False and GPIO.input(squelch) == False): - print("carrier received!") - # command_tx = not command_tx -# print(command_tx) - - try: - command_count += 1 - filec = open("/home/pi/CubeSatSim/command_count.txt", "w") - command_count_string = str(command_count) - print(command_count_string) - string = filec.write(command_count_string) - filec.close() - except: - if (debug_mode == 1): - print("Can't write command_count file!") - print("Command_count: ") - print(command_count) - - increment_mode() - -# if (command_tx == True): -# print("Turning on transmit") -# system("echo > command_tx True") -# output(txLed, txLedOn) -# sleep(0.5) -# output(txLed, txLedff) -# else: -# print("Turning off transmit") -# system("echo > command_tx False") - else: - print("No carrier received!") - output(pd, 0) -# sleep(1) - +import serial def battery_saver_check(): try: @@ -188,6 +143,7 @@ ptt = 20 txc_pin = 7 squelch = 6 green = 16 +powerPin = 16 command_tx = True @@ -198,32 +154,18 @@ GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(txc_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(green, GPIO.OUT) +GPIO.output(powerPin, 1) transmit = False +txLed = 27 +txLedOn = 1 +txLedOff = 0 if GPIO.input(12) == False: - print("Version is v1 with UHF BPF") - transmit = True - txLed = 27 - txLedOn = 1 - txLedOff = 0 -elif GPIO.input(27) == False: - print("Version is TFB") + print("Version is v1 with UHF LPF") transmit = True - txLed = 22 - txLedOn = 0 - txLedOff = 1 -elif GPIO.input(13) == False: - print("Version is v1 with VHF BPF") - print("VHF transmit not implemented yet") -# transmit = True - txLed = 27 - txLedOn = 1 - txLedOff = 0 else: - print("No BPF") - txLed = 27 - txLedOn = 1 - txLedOff = 0 + print("No LPF") + # GPIO.setup(txLed, GPIO.OUT) # output(txLed, txLedOff) @@ -259,36 +201,59 @@ print(txLed) debug_mode = 0 #no debugging rpitx -if __name__ == "__main__": +skip = False +if __name__ == "__main__": + mode = "y" if (len(sys.argv)) > 1: # print("There are arguments!") if (('d' == sys.argv[1]) or ('-d' in sys.argv[1])): debug_mode = 1 + elif (('x' == sys.argv[1]) or ('-x' in sys.argv[1])): + mode = "x" + print("Forcing APRS mode") + elif (('s' == sys.argv[1]) or ('-s' in sys.argv[1])): + skip = True + print("Skipping delay and CW ID") print(transmit) + try: - file = open("/home/pi/CubeSatSim/.mode") - mode = file.read(1) + system("cat /proc/uptime > /home/pi/CubeSatSim/uptime") + file = open("/home/pi/CubeSatSim/uptime") + up = file.read().split(" ")[0] + print(up) + uptime = float(up) + print(uptime) + if (uptime < 45): + print("Uptime < 45 seconds") + else: + print("Uptime > 45 seconds") + skip = True + file.close() except: - mode = "f" - if (debug_mode == 1): - print("Can't open .mode file, defaulting to FSK") + print("Can't open /proc/uptime") + + if ( mode == "y"): + try: + file = open("/home/pi/CubeSatSim/.mode") + mode = file.read(1) + except: + mode = "f" + if (debug_mode == 1): + print("Can't open .mode file, defaulting to FSK") print("Mode is: ") print(mode) try: - file = open("/home/pi/CubeSatSim/command_tx") - char = file.read(1) - if (char == 'T'): - command_tx = True - else: - command_tx = False + file = open("/home/pi/CubeSatSim/beacon_off") + file.close() + command_tx = False except: command_tx = True if (debug_mode == 1): - print("Can't open command_tx file, defaulting to True") + print("Can't open beacon_off file, defaulting to False") print("Command_tx: ") print(command_tx) @@ -306,6 +271,12 @@ if __name__ == "__main__": file.close() print("Command_count: ") print(command_count) + + tx_value = '0' + rx_value = '0' + sq = '0' + tx = '434.9000' + rx = '435.0000' try: file = open("/home/pi/CubeSatSim/sim.cfg") @@ -314,26 +285,31 @@ if __name__ == "__main__": callsign = config[0] if len(config) > 5: sq = config[5] - else: - sq = '0' + print(sq) if len(config) > 6: -# tx = config[6] txf = float(config[6]) - print(txf) +# print(txf) # print( "{:.4f}".format(txf)) tx = "{:.4f}".format(txf) print(tx) - else: - tx = '434.9000' if len(config) > 7: -# rx = config[7] rxf = float(config[7]) - print(rxf) +# print(rxf) # print( "{:.4f}".format(rxf)) rx = "{:.4f}".format(rxf) print(rx) - else: - rx = '435.0000' + if len(config) > 9: + rxpl = float(config[9]) + # print(rxpl) + # print( "{:.0f}".format(rxpl)) + rxpl_value = "{:.0f}".format(rxpl) + print(rxpl_value) + if len(config) > 10: + txpl = float(config[10]) +# print(txpl) +# print( "{:.0f}".format(txpl)) + txpl_value = "{:.0f}".format(txpl) + print(txpl_value) print(config) print # print(callsign) @@ -362,12 +338,16 @@ if __name__ == "__main__": else: print("command and control is activated") no_command = False +# system("/home/pi/CubeSatSim/command &") + system("sudo systemctl start command") except: print("command and control not activated") no_command = True print(callsign) GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4 + print(txLed) + print(txLedOn) GPIO.setup(txLed, GPIO.OUT) print("Programming FM module!\n"); @@ -376,26 +356,31 @@ if __name__ == "__main__": try: ser = serial.Serial("/dev/ttyAMA0", 9600) print(ser.portstr) - uhf_string = "AT+DMOSETGROUP=0," + rx +"," + tx + ",0,3,0,0\r\n" +# uhf_string = "AT+DMOSETGROUP=0," + rx +"," + tx + ",0,3,0,0\r\n" + uhf_string = "AT+DMOSETGROUP=0," + rx + "," + tx + "," + rxpl_value + "," + sq + "," + txpl_value + ",0\r\n" + print(uhf_string) for i in range(6): # ser.write(b"AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n") ser.write(uhf_string.encode()) sleep(0.1) + ser.close() except: print("Error in serial write") - ser.close() output(pd, 0) - - sleep(10) # delay so cubesatsim code catches up + +# if (mode != 'x') and (skip == False): +# sleep(10) # delay so cubesatsim code catches up system("echo 'hi hi de " + callsign + "' > id.txt && gen_packets -M 20 /home/pi/CubeSatSim/id.txt -o /home/pi/CubeSatSim/morse.wav -r 48000 > /dev/null 2>&1") - command_control_check() +# command_control_check() -# if (mode != 'a') and (command_tx == True): +# if (mode != ) and (command_tx == True): # if (command_tx == True): - if (mode != 'm'): + if ((mode == 'a') or (mode == 'b') or (mode == 'f') or (mode == 's')) and (command_tx == True) and (skip == False): # battery_saver_mode + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # if (txc): # output(pd, 1) @@ -426,10 +411,20 @@ if __name__ == "__main__": # if (len(sys.argv)) > 1: # print("There are arguments!") - if (mode == 'a'): - command_control_check() -# output(pd, 1) - print("AFSK") + if (mode == 'a') or (mode == 'x') or (mode == 'n'): +# command_control_check() + output(pd, 1) + output(ptt, 1) + if (mode == 'a'): + print("AFSK") + else: + GPIO.output(powerPin, 0) + print("Transmit APRS Commands") +# while True: +# sleep(0.1) + if (mode != 'n'): + system("touch /home/pi/CubeSatSim/ready") + while True: try: f = open("/home/pi/CubeSatSim/ready") @@ -439,6 +434,8 @@ if __name__ == "__main__": system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1") system("cat /home/pi/CubeSatSim/t.txt") if (command_tx == True): + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # output(pd, 1) # output (ptt, 0) @@ -446,15 +443,16 @@ if __name__ == "__main__": # # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) sleep(0.1) # add delay before transmit output (ptt, 0) sleep(0.3) # add even more time at start system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav") sleep(0.2) # add more time at end output (ptt, 1) - output(pd, 0) - else: +# output(pd, 0) + else: + system("echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt") if (debug_mode == 1): system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3") else: @@ -472,13 +470,15 @@ if __name__ == "__main__": sleep(0.5) except: - command_control_check() +# command_control_check() sleep(1) elif (mode == 'm'): + system("touch /home/pi/CubeSatSim/cwready") print("CW") while True: - command_control_check() - +# command_control_check() + output (pd, 1) + output (ptt, 1) try: f = open("/home/pi/CubeSatSim/cwready") f.close() @@ -490,10 +490,12 @@ if __name__ == "__main__": system(command) ## chan = chan + 1 if (command_tx == True): + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) if (txc): - output (pd, 1) +# output (pd, 1) sleep(0.3) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") @@ -507,15 +509,18 @@ if __name__ == "__main__": system("cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1") output(txLed, txLedOff) - command_control_check() +# command_control_check() + sleep(2) f.close() - sleep(5) + sleep(10) except: - command_control_check() +# command_control_check() sleep(1) elif (mode == 's'): print("SSTV") - command_control_check() +# command_control_check() + output (ptt, 1) + output(pd, 1) try: # from picamera import PiCamera # from pysstv.sstv import SSTV @@ -541,19 +546,21 @@ if __name__ == "__main__": file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") print("First SSTV stored image detected") system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") - command_control_check() +# command_control_check() if (command_tx == True): print ("Sending SSTV image") + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav") output (ptt, 1) - output(pd, 0) +# output(pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3") @@ -566,7 +573,7 @@ if __name__ == "__main__": except: print("image 2 did not load - copy from CubeSatSim/sstv directory") while 1: - command_control_check() +# command_control_check() system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256") # > /dev/null 2>&1") print("Photo taken") @@ -594,24 +601,26 @@ if __name__ == "__main__": draw.text((120, 10), telem_string, font=font2, fill='white') img.save(file) - command_control_check() +# command_control_check() system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/camera_out.jpg") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1") - command_control_check() +# command_control_check() if (command_tx == True): print ("Sending SSTV image") + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") output(ptt, 1) - output (pd, 0) +# output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3") @@ -623,30 +632,32 @@ if __name__ == "__main__": # output(pd, 0) system("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1") - sleep(1) + sleep(10) else: try: - command_control_check() + # command_control_check() file = open("/home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg") print("First SSTV stored image detected") system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg") - command_control_check() +# command_control_check() if (command_tx == True): print ("Sending SSTV image") + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") output(ptt, 1) - output (pd, 0) +# output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3") @@ -660,7 +671,7 @@ if __name__ == "__main__": except: print("image 1 did not load - copy from CubeSatSim/sstv directory") try: - command_control_check() +# command_control_check() file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") print("Second SSTV stored image detected") @@ -668,19 +679,21 @@ if __name__ == "__main__": while 1: - command_control_check() +# command_control_check() if (command_tx == True): print ("Sending SSTV image") + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") output(ptt, 1) - output (pd, 0) +# output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3") @@ -690,38 +703,46 @@ if __name__ == "__main__": output(txLed, txLedOff) # output (ptt, 1) # output(pd, 0) - sleep(5) + sleep(10) except: print("image 2 did not load - copy from CubeSatSim/sstv directory") if (txc == False): if (command_tx == True): - system("(while true; do (sleep 5 && cat /home/pi/CubeSatSim/wav/sstv.wav); done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") + system("(while true; do (sleep 10 && cat /home/pi/CubeSatSim/wav/sstv.wav); done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") while 1: if (command_tx == True): - command_control_check() +# command_control_check() + + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) + # battery_saver_check() if (txc): - output(pd, 1) +# output(pd, 1) output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav") output(ptt, 1) - output (pd, 0) +# output (pd, 0) else: sleep(60) output(txLed, txLedOff) # output (ptt, 1) # output(pd, 0) - sleep(1) + sleep(10) elif (mode == 'b'): - command_control_check() +# command_control_check() print("BPSK") print("turn on FM rx") output(pd, 1) output(ptt, 1) + + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4 + GPIO.setup(txLed, GPIO.OUT) + if (command_tx == True): # system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float &") system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f " + tx + "e6 -t float &") @@ -733,16 +754,55 @@ if __name__ == "__main__": # output(txLed, txLedOn) # sleep(0.03) # output(txLed, txLedOff) - command_control_check() +# command_control_check() if (command_tx == True): + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) +# print(txLed) +# print(txLedOn) sleep(4.2) + elif (mode == 'e'): # code based on https://zr6aic.blogspot.com/2016/11/creating-2m-fm-repeater-with-raspberry.html + print("Repeater") + print("Stopping command and control") + system("sudo systemctl stop command") + print("turn on FM rx") + output(pd, 1) + output(ptt, 1) + GPIO.output(powerPin, 0) + while True: + sleep(0.5) + if (GPIO.input(squelch) == False): + print("Carrier detected, starting repeater") + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) + output(txLed, txLedOn) +# system("arecord -D hw:CARD=Device,DEV=0 | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") +## system("arecord -D hw:CARD=Device,DEV=0 -f S16_LE -r 48000 -c 1 | csdr convert_s16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") + system("sudo nc -l 8011 | csdr convert_i16_f | csdr gain_ff 16000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") + sleep(1) + system("sudo arecord -D plughw:1 -r48000 -fS16_LE -c1 | nc localhost 8011 &") + GPIO.output(powerPin, 1) + sleep(0.5) + GPIO.output(powerPin, 0) + while (GPIO.input(squelch) == False): + sleep(1) + print("No carrier detected, stopping repeater") + output(txLed, txLedOff) + system("sudo killall -9 arecord") + system("sudo killall -9 nc") + system("sudo killall -9 rpitx") + else: print("FSK") print("turn on FM rx") output(pd, 1) output(ptt, 1) + + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4 + GPIO.setup(txLed, GPIO.OUT) + if (command_tx == True): system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 &") print("Turning LED on/off and listening for carrier") @@ -753,11 +813,15 @@ if __name__ == "__main__": # output(txLed, txLedOn) # sleep(0.03) # output(txLed, txLedOff) - command_control_check() +# command_control_check() if (command_tx == True): + GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 + GPIO.setup(txLed, GPIO.OUT) output(txLed, txLedOn) +# print(txLed) +# print(txLedOn) sleep(4.2) else: - print("No Low Pass Filter so no telemetry transmit. See http://cubesatsim.org/wiki for instructions on how to build the BPF.") + print("No Low Pass Filter so no telemetry transmit. See http://cubesatsim.org/wiki for instructions on how to build the LPF.") while 1: sleep(5) diff --git a/squelch_cc.py b/squelch_cc.py new file mode 100644 index 00000000..9faa6ca8 --- /dev/null +++ b/squelch_cc.py @@ -0,0 +1,196 @@ +import RPi.GPIO as GPIO +from RPi.GPIO import output +from time import sleep +from os import system +import sys + +def command_control_check(): + +# global command_control +# global no_command + global debug_mode + command_count = 0 + global squelch + global txLed + +# output(pd, 1) +# output(ptt, 1) +# sleep(1) +# if (no_command == False and GPIO.input(squelch) == False): + if GPIO.input(squelch) == False: + print("carrier received!") + # command_tx = not command_tx +# print(command_tx) + + try: + file = open("/home/pi/CubeSatSim/command_count.txt", "r") + string = file.read() + file.close() + command_count = int(string) + command_count += 1 + filec = open("/home/pi/CubeSatSim/command_count.txt", "w") + command_count_string = str(command_count) + print(command_count_string) + string = filec.write(command_count_string) + filec.close() + except: + print("Can't write command_count file!") + print("Command_count: ") + print(command_count) + + increment_mode() + +# if (command_tx == True): +# print("Turning on transmit") +# system("echo > command_tx True") +# output(txLed, txLedOn) +# sleep(0.5) +# output(txLed, txLedff) +# else: +# print("Turning off transmit") +# system("echo > command_tx False") +## else: +## print("No carrier received!") +# output(pd, 0) +# sleep(1) + +def increment_mode(): + global debug_mode + + print("increment mode") + powerPin = 16 + try: + file = open("/home/pi/CubeSatSim/.mode") + mode = file.read(1) + except: +# mode = "f" +# if (debug_mode == 1): + print("Can't open .mode file") # , defaulting to FSK") + file.close() + print("Mode is: ") + print(mode) + if (mode == 'a'): + mode = 'f' + GPIO.output(powerPin, 0) # blink two times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 'f'): + mode = 'b' + GPIO.output(powerPin, 0) # blink three times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 'b'): + mode = 's' + GPIO.output(powerPin, 0) # blink four times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + elif (mode == 's'): + mode = 'm' + GPIO.output(powerPin, 0) # blink five times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1); + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) + GPIO.output(powerPin, 0) + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + else: + mode = 'a' + GPIO.output(powerPin, 0) # blink one time + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(1) + + try: + print("/home/pi/CubeSatSim/config -" + mode) + if (debug_mode == False): + GPIO.setwarnings(False) + GPIO.output(txLed, 0) + GPIO.output(powerPin, 0) + system("sudo systemctl stop rpitx") + system("sudo systemctl stop cubesatsim") + + system("/home/pi/CubeSatSim/config -" + mode) + print("Changing mode now") + + +# file = open("/home/pi/CubeSatSim/.mode", "w") +# count_string = str(command_count) +# file.write(mode) +# file.close() +# print(".mode file written") +# print("sudo reboot -h now") +# GPIO.setwarnings(False) +# GPIO.setup(powerPin, GPIO.OUT) +# GPIO.output(powerPin, 0); +# system("reboot -h now") +# release = True; +# system("/home/pi/CubeSatSim/config -" + mode) +# system("reboot -h now") + print(" ") +# sleep(10); + except: + print("can't change mode") + +print("Squelch Command and Control active") +debug_mode = False +if (len(sys.argv)) > 1: +# print("There are arguments!") + if ('d' == sys.argv[1]): + debug_mode = True + print("Debug mode - mode changes not made") + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +squelch = 6 +powerPin = 16 +txLed = 27 +GPIO.setup(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected +GPIO.setup(powerPin, GPIO.OUT) +GPIO.setup(txLed, GPIO.OUT) + +while True: + command_control_check() + sleep(0.5) diff --git a/systemd/command.service b/systemd/command.service new file mode 100644 index 00000000..9354154f --- /dev/null +++ b/systemd/command.service @@ -0,0 +1,14 @@ +[Unit] +Description=Command service + +[Service] +TimeoutStopSec=5 +ExecStart=/home/pi/CubeSatSim/command +WorkingDirectory=/home/pi/CubeSatSim +StandardOutput=inherit +StandardError=inherit +Restart=always +User=root + +[Install] +WantedBy=default.target diff --git a/systemd/cubesatsim.service b/systemd/cubesatsim.service index 11966c22..1101dc9e 100644 --- a/systemd/cubesatsim.service +++ b/systemd/cubesatsim.service @@ -10,7 +10,7 @@ StandardError=inherit Restart=always User=root CPUAccounting=true -CPUQuota=5% +CPUQuota=7% [Install] WantedBy=default.target diff --git a/update b/update index d39d9791..e8ef35af 100755 --- a/update +++ b/update @@ -2,13 +2,24 @@ echo -e "\nupdate script for CubeSatSim v1.3.2\n" +if [ "$1" = "n" ] ; then +# if [ -z "$2" ] ; then + noreboot=1 +else + noreboot=0 +fi + +# echo "No reboot" +# echo $noreboot + sudo rm /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/id.txt /home/pi/CubeSatSim/cw.txt > /dev/null 2>&1 if [ "$1" = "u" ]; then - sudo apt-get update && sudo apt-get dist-upgrade -y +# sudo apt-get update && sudo apt-get dist-upgrade -y + sudo apt-get update -y - sudo apt-get install -y wiringpi git libasound2-dev i2c-tools build-essential libgd-dev libmagic-dev python3-pip minicom + sudo apt-get install -y git libasound2-dev i2c-tools build-essential libgd-dev libmagic-dev python3-pip minicom fi @@ -56,6 +67,8 @@ else echo "no changes to cubesatsim.service." fi +sudo systemctl disable rpitx + if [[ $(diff systemd/rpitx.service /etc/systemd/system/rpitx.service) ]]; then echo "changed rpitx.service." sudo cp /home/pi/CubeSatSim/systemd/rpitx.service /etc/systemd/system/rpitx.service @@ -64,6 +77,24 @@ else echo "no changes to rpitx.service." fi +sudo systemctl disable rpitx + +FILE=/etc/systemd/system/command.service +if [ -f "$FILE" ]; then + if [[ $(diff systemd/command.service /etc/systemd/system/command.service) ]]; then + echo "changed command.service." + sudo cp /home/pi/CubeSatSim/systemd/command.service /etc/systemd/system/command.service + FLAG=1 + else + echo "no change to command.service." + fi +else + echo "creating command.service." + sudo cp /home/pi/CubeSatSim/systemd/command.service /etc/systemd/system/command.service + sudo systemctl enable command + FLAG=1 +fi + FILE=/home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg if [ ! -f "$FILE" ]; then echo "Copying SSTV image 1." @@ -84,7 +115,8 @@ fi if [ ! -d "/home/pi/PiSSTVpp" ]; then - sudo apt-get update && sudo apt-get dist-upgrade -y +# sudo apt-get update && sudo apt-get dist-upgrade -y + sudo apt-get update -y sudo apt-get install -y python-picamera python3-picamera build-essential libgd-dev libmagic-dev @@ -131,11 +163,66 @@ if [ ! -d "/home/pi/PiSSTVpp" ]; then fi +if [ ! -d "/home/pi/rpitx" ]; then + + cd + git clone https://github.com/alanbjohnston/rpitx.git + cd rpitx + ./install.sh + cd +else + + if [[ $(grep 'SYNCWITHPWM' /home/pi/rpitx/src/librpitx/src/fskburst.h) ]]; then + echo "rpitx already updated" + else + echo "updating rpitx" + cd /home/pi/rpitx + git pull + ./update.sh + cd + fi +fi + +if [ ! -d "/home/pi/WiringPi" ]; then + + cd + + git clone https://github.com/PinkFreud/WiringPi + cd WiringPi + ./build debian + + sudo dpkg -i debian-template/wiringpi-2.61-1.deb + + cd + + cd CubeSatSim + make debug + + FLAG=1 + + cd + +fi + cd /home/pi/pi-power-button -# git checkout reboot-mode-change +git checkout reboot-mode-change-beta > .updated_b -git pull --no-rebase > .updated_p + grep 'error' /home/pi/pi-power-button/.updated_b + if [[ $(grep 'error' /home/pi/pi-power-button/.updated_b) ]]; then + + echo "pi-power-button switching to beta branch" + + git pull + + git checkout reboot-mode-change-beta + + script/install + + FLAG=1 + fi + + git pull --no-rebase > .updated_p grep 'changed' /home/pi/pi-power-button/.updated_p if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then @@ -192,9 +279,10 @@ git pull --no-rebase > .updated_p git checkout reboot-mode-change script/install - sudo apt-get update && sudo apt-get dist-upgrade -y - sudo apt-get install -y libjpeg-dev zlib1g-dev libfreetype6-dev liblcms1-dev libopenjp2-7 libtiff5 -y - sudo pip3 install pillow +# sudo apt-get update && sudo apt-get dist-upgrade -y + sudo apt-get update -y + sudo apt-get install -y libjpeg-dev zlib1g-dev libfreetype6-dev liblcms1-dev libopenjp2-7 libtiff5 python3-pil + sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219 pillow fi @@ -231,6 +319,7 @@ git pull --no-rebase > .updated_p changed=0 value=`cat /home/pi/CubeSatSim/sim.cfg` +# echo "$value" echo "$value" > /dev/null set -- $value @@ -243,32 +332,41 @@ if [ -z "$6" ] ; then n6="3" ; changed=1 ; else n6=$6 ; fi # squelch if [ -z "$7" ] ; then n7="434.9000" ; changed=1 ; else n7=$7 ; fi # transmit frequency if [ -z "$8" ] ; then n8="435.0000" ; changed=1 ; else n8=$8 ; fi # receive frequency if [ -z "$9" ] ; then n9="no" ; changed=1 ; else n9=$9 ; fi # hab mode +if [ -z "${10}" ] ; then m1="0" ; changed=1 ; else m1=${10} ; fi # rx pl code +if [ -z "${11}" ] ; then m2="0" ; changed=1 ; else m2=${11} ; fi # tx pl code if [ $changed -eq 1 ]; then echo -e "Current sim.cfg configuration file:" echo - echo $1 $2 $3 $4 $5 $6 $7 $8 $9 - echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" + echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} + echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n" echo - echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 - echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 > /home/pi/CubeSatSim/sim.cfg + echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $m1 $m2 + echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $m1 $m2 > /home/pi/CubeSatSim/sim.cfg echo fi -if [ $FLAG -eq 1 ]; then - echo "systemctl daemon-reload and reboot" - sudo systemctl daemon-reload - sudo reboot -h now -# sudo systemctl restart cubesatsim +if [ "$noreboot" = "0" ] ; then + + if [ $FLAG -eq 1 ]; then + echo "systemctl daemon-reload and reboot" + sudo systemctl daemon-reload + sudo reboot -h now +# sudo cubesatsim + else + grep 'changed' /home/pi/CubeSatSim/.updated + if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then + echo "reboot due to code changes " | wall + sudo reboot -h now +# sudo cubesatsim + else + echo "nothing to do." + fi + fi else - grep 'changed' /home/pi/CubeSatSim/.updated - if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then - echo "reboot" - sudo reboot -h now -# sudo systemctl restart cubesatsim - else - echo "nothing to do." - fi + if [ $FLAG -eq 1 ]; then + echo "reboot needed for changes to take effect" + fi fi - - echo "CubeSatSim update complete." + +echo "CubeSatSim update complete."