Merge pull request #323 from alanbjohnston/beta-pl-cc

Beta pl cc
beta-ccd
Alan Johnston 1 year ago committed by GitHub
commit 10a0de22d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,44 +0,0 @@
import sys
from os import system
if __name__ == "__main__":
change_mode = False
debug_mode = False
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 =" ")
# if '^c' == line.rstrip():
# break
if ((line.find("MODE=a")) > 0) or ((line.find("DTMF>APDW15:t1#")) > 0):
system("echo '\nAPRS Mode!!\n'")
mode = 'a'
change_mode = True
if ((line.find("MODE=f")) > 0) or ((line.find("DTMF>APDW15:t2#")) > 0):
system("echo '\nFSK Mode!!\n'")
mode = 'f'
change_mode = True
if ((line.find("MODE=b")) > 0) or ((line.find("DTMF>APDW15:t3#")) > 0):
system("echo '\nBPSK Mode!!\n'")
mode = 'b'
change_mode = True
if ((line.find("MODE=s")) > 0) or ((line.find("DTMF>APDW15:t4#")) > 0):
system("echo '\nSSTV Mode!!\n'")
mode = 's'
change_mode = True
if ((line.find("MODE=m")) > 0) or ((line.find("DTMF>APDW15:t5#")) > 0):
system("echo '\nCW Mode!!\n'")
mode = 'm'
change_mode = True
if (debug_mode == False) and (change_mode == True):
print("\n/home/pi/CubeSatSim/config -" + mode)
system("/home/pi/CubeSatSim/config -" + mode)
change_mode = False
print("Done")

@ -5,28 +5,66 @@ echo -e "\nCommand and Control script for CubeSatSim v1.3.2\n"
FILE=/home/pi/CubeSatSim/command_control FILE=/home/pi/CubeSatSim/command_control
if [ -f "$FILE" ]; then if [ -f "$FILE" ]; then
echo "Radio command and control is ON" echo "Radio command and control is ON"
echo "Turning Command and control to OFF" # echo "Turning Command and control to OFF"
sudo rm /home/pi/CubeSatSim/command_control # sudo rm /home/pi/CubeSatSim/command_control
echo "rebooting" # echo "rebooting"
sudo systemctl stop rpitx # sudo systemctl stop rpitx
sudo reboot now # sudo reboot now
# fi # fi
else else
echo "Radio command and control is OFF" echo "Radio command and control is OFF"
while true
do
sleep 60
done
# exit 1
fi fi
echo "Starting direwolf" echo "Waiting 20 seconds for USB"
sleep 20
FILE=/home/pi/CubeSatSim/command_control_direwolf
if [[ $(arecord -l | grep card) ]] && [ -f "$FILE" ]; then
echo "Starting Direwolf DTMF and APRS Command and Control"
if [ "$1" = "d" ]; then
if [ "$1" = "d" ]; then echo "debug mode"
echo "debug mode" direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py d
direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/aprs_in.py d else
direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/dtmf_aprs_cc.py
fi
else else
direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/aprs_in.py if [ -f "$FILE" ]; then
fi echo "Direwolf mode set but no USB soundcard detected!"
echo "Instead, starting Carrier (squelch) Command and Control"
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

131
config

@ -73,10 +73,21 @@ if [ "$1" = "" ]; then
FILE=/home/pi/CubeSatSim/command_control FILE=/home/pi/CubeSatSim/command_control
if [ -f "$FILE" ]; then 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 else
echo "Radio command and control is OFF" echo "Radio command and control is OFF"
fi fi
echo echo
echo -n "RX PL code is: " echo -n "RX PL code is: "
@ -111,7 +122,7 @@ elif [ "$1" = "-i" ]; then
reboot=1 reboot=1
## echo "Rebooting CubeSatSim" ## echo "Rebooting CubeSatSim"
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-a" ]; then elif [ "$1" = "-a" ]; then
echo "changing CubeSatSim to AFSK mode" echo "changing CubeSatSim to AFSK mode"
@ -120,7 +131,7 @@ elif [ "$1" = "-a" ]; then
FILE=/home/pi/CubeSatSim/battery_saver FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then if [ -f "$FILE" ]; then
echo "Safe Mode! Battery saver mode is ON." 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 # if ! grep force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
else else
echo "Battery saver mode is OFF." echo "Battery saver mode is OFF."
# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt # sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
@ -128,9 +139,9 @@ elif [ "$1" = "-a" ]; then
reboot=1 reboot=1
## echo "rebooting" ## echo "rebooting"
## sudo systemctl stop rpitx ## sudo stop rpitx
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-m" ]; then elif [ "$1" = "-m" ]; then
@ -147,9 +158,9 @@ elif [ "$1" = "-m" ]; then
fi fi
reboot=1 reboot=1
## echo "rebooting" ## echo "rebooting"
## sudo systemctl stop rpitx ## sudo stop rpitx
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-f" ]; then elif [ "$1" = "-f" ]; then
echo "changing CubeSatSim to FSK mode" echo "changing CubeSatSim to FSK mode"
@ -157,9 +168,9 @@ elif [ "$1" = "-f" ]; then
# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi # if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
reboot=1 reboot=1
## echo "rebooting" ## echo "rebooting"
## sudo systemctl stop rpitx ## sudo stop rpitx
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-b" ]; then elif [ "$1" = "-b" ]; then
echo "changing CubeSatSim to BPSK mode" echo "changing CubeSatSim to BPSK mode"
@ -167,9 +178,9 @@ elif [ "$1" = "-b" ]; then
# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi # if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
reboot=1 reboot=1
## echo "rebooting" ## echo "rebooting"
## sudo systemctl stop rpitx ## sudo stop rpitx
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-s" ]; then elif [ "$1" = "-s" ]; then
echo "changing CubeSatSim to SSTV mode" echo "changing CubeSatSim to SSTV mode"
@ -185,9 +196,9 @@ elif [ "$1" = "-s" ]; then
fi fi
reboot=1 reboot=1
## echo "rebooting" ## echo "rebooting"
## sudo systemctl stop rpitx ## sudo stop rpitx
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
## exit ## exit
elif [ "$1" = "-t" ]; then elif [ "$1" = "-t" ]; then
@ -234,7 +245,7 @@ elif [ "$1" = "-t" ]; then
reboot=1 reboot=1
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo restart cubesatsim
elif [ "$1" = "-c" ]; then elif [ "$1" = "-c" ]; then
@ -436,6 +447,7 @@ elif [ "$1" = "-C" ]; then
sudo systemctl stop cubesatsim sudo systemctl stop cubesatsim
sudo systemctl stop rpitx sudo systemctl stop rpitx
sudo systemctl stop command
sudo mv -f /home/pi/CubeSatSim/telem.txt /home/pi/CubeSatSim/telem.txt.bk sudo mv -f /home/pi/CubeSatSim/telem.txt /home/pi/CubeSatSim/telem.txt.bk
@ -464,9 +476,9 @@ elif [ "$1" = "-T" ]; then
if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then
echo "Command and control set to OFF" echo "Command and control set to OFF"
sudo rm /home/pi/CubeSatSim/command_control sudo rm /home/pi/CubeSatSim/command_control
reboot=1 # reboot=1
## echo "rebooting" echo "restarting command and control"
## sudo systemctl stop rpitx sudo systemctl restart command
## sudo reboot now ## sudo reboot now
fi fi
@ -480,14 +492,79 @@ elif [ "$1" = "-T" ]; then
if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then
echo "Command and control set to ON" echo "Command and control set to ON"
sudo touch /home/pi/CubeSatSim/command_control 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 command and control Direwolf state"
echo
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
# reboot=1
## echo "rebooting" ## echo "rebooting"
reboot=1 sudo systemctl restart command
## sudo systemctl stop rpitx
## sudo reboot now ## sudo reboot now
fi 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
## 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
fi
elif [ "$1" = "-R" ]; then elif [ "$1" = "-R" ]; then
echo echo
@ -613,6 +690,14 @@ elif [ "$1" = "-q" ]; then
## sudo reboot now ## sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
elif [ "$1" = "-Q" ]; then
# echo
echo "Reading current Squelch for 10 seconds"
echo "Squelch is active low (0 means squelch broken)"
echo
timeout 10 bash -c -- 'while true; do (gpio read 22 && sleep 1); done'
elif [ "$1" = "-P" ]; then elif [ "$1" = "-P" ]; then
@ -815,7 +900,7 @@ elif [ "$1" = "-h" ]; then
echo " -f Change to FSK/DUV mode" echo " -f Change to FSK/DUV mode"
echo " -b Change to BPSK mode" echo " -b Change to BPSK mode"
echo " -s Change to SSTV mode" echo " -s Change to SSTV mode"
echo " -i Reboots CubeSatsim software" echo " -i Restart CubeSatsim software"
echo " -c Change the CALLSIGN in the configuration file sim.cfg" echo " -c Change the CALLSIGN in the configuration file sim.cfg"
echo " -t Change the Simulated Telemetry setting in sim.cfg" echo " -t Change the Simulated Telemetry setting in sim.cfg"
echo " -r Change the Resets Count in the configuration file sim.cfg" echo " -r Change the Resets Count in the configuration file sim.cfg"
@ -823,11 +908,12 @@ elif [ "$1" = "-h" ]; then
echo " -S Scan both I2C buses on the Raspberry Pi" echo " -S Scan both I2C buses on the Raspberry Pi"
echo " -C Clear logs" echo " -C Clear logs"
echo " -T Change command and control state" 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 " -R Change the Commands Count in the file command_count.txt"
echo " -B Change Safe Mode (battery saver mode) manually" echo " -B Change Safe Mode (battery saver mode) manually"
echo " -q Change the Squelch setting for command receiver" echo " -q Change the Squelch setting for command receiver"
echo " -F Change the rx and tx frequency" echo " -F Change the RX and TX frequency"
echo " -H Chnage the Balloon mode" echo " -H Change the Balloon (HAB) mode"
echo " -p Display payload sensor data" echo " -p Display payload sensor data"
echo " -v Display voltage and current data" echo " -v Display voltage and current data"
echo " -P Change the PL (Private Line) CTCSS/CDCSS codes for RX and TX" echo " -P Change the PL (Private Line) CTCSS/CDCSS codes for RX and TX"
@ -850,6 +936,7 @@ fi
if [ "$reboot" = "1" ] ; then if [ "$reboot" = "1" ] ; then
if [ "$noreboot" = "0" ] ; then if [ "$noreboot" = "0" ] ; then
echo 'Reboot due to config change!' | wall
echo "Rebooting" echo "Rebooting"
sudo systemctl stop rpitx sudo systemctl stop rpitx
sudo reboot now sudo reboot now

@ -0,0 +1,154 @@
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
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) or ((line.find("DTMF>APDW15:t1#")) > 0):
system("echo '\nAPRS Mode!!\n'")
mode = 'a'
change_mode = True
if ((line.find("MODE=f")) > 0) or ((line.find("DTMF>APDW15:t2#")) > 0):
system("echo '\nFSK Mode!!\n'")
mode = 'f'
change_mode = True
if ((line.find("MODE=b")) > 0) or ((line.find("DTMF>APDW15:t3#")) > 0):
system("echo '\nBPSK Mode!!\n'")
mode = 'b'
change_mode = True
if ((line.find("MODE=s")) > 0) or ((line.find("DTMF>APDW15:t4#")) > 0):
system("echo '\nSSTV Mode!!\n'")
mode = 's'
change_mode = True
if ((line.find("MODE=m")) > 0) or ((line.find("DTMF>APDW15:t5#")) > 0):
system("echo '\nCW Mode!!\n'")
mode = 'm'
change_mode = True
if (debug_mode == False) and (change_mode == True):
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)
else:
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")

@ -47,14 +47,12 @@ sudo dpkg -i wiringpi-latest.deb
cd cd
#changed to python3-smbus #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 --upgrade setuptools
sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219 sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219
cd ~/CubeSatSim cd ~/CubeSatSim
git pull --no-rebase git pull --no-rebase
@ -128,6 +126,10 @@ sudo cp ~/CubeSatSim/systemd/rpitx.service /etc/systemd/system/rpitx.service
sudo systemctl enable rpitx 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/config.txt /boot/config.txt.0
sudo cp /boot/cmdline.txt /boot/cmdline.txt.0 sudo cp /boot/cmdline.txt /boot/cmdline.txt.0

6
log

@ -5,7 +5,11 @@ echo -e "\nLog file script for CubeSatSim\n"
if [ "$1" = "-r" ]; then if [ "$1" = "-r" ]; then
sudo journalctl -a -u rpitx > /home/pi/CubeSatSim/logr.txt sudo journalctl -a -u rpitx > /home/pi/CubeSatSim/logr.txt
cat /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 else
sudo journalctl -a -u cubesatsim > /home/pi/CubeSatSim/log.txt sudo journalctl -a -u cubesatsim > /home/pi/CubeSatSim/log.txt
cat /home/pi/CubeSatSim/log.txt cat /home/pi/CubeSatSim/log.txt

@ -26,7 +26,6 @@
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
char resbuffer[1000]; 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 '902120'";
FILE *file_test = sopen(testStr); // see if Pi Zero 2 FILE *file_test = sopen(testStr); // see if Pi Zero 2
@ -41,6 +40,7 @@ int main(int argc, char * argv[]) {
sleep(5); // try sleep at start to help boot sleep(5); // try sleep at start to help boot
// voltageThreshold = 3.7; // voltageThreshold = 3.7;
printf("Pi Zero 2 detected\n"); printf("Pi Zero 2 detected\n");
pi_zero_2_offset = 500;
} }
printf("\n\nCubeSatSim v1.3.2 starting...\n\n"); printf("\n\nCubeSatSim v1.3.2 starting...\n\n");
@ -102,6 +102,9 @@ int main(int argc, char * argv[]) {
FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r"); FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r");
pclose(rpitx_stop); pclose(rpitx_stop);
// 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"); // FILE * file_deletes = popen("sudo rm /home/pi/CubeSatSim/ready /home/pi/CubeSatSim/cwready > /dev/null", "r");
// pclose(file_deletes); // pclose(file_deletes);
@ -375,10 +378,13 @@ int main(int argc, char * argv[]) {
if (!ax5043) // don't test for payload if AX5043 is present if (!ax5043) // don't test for payload if AX5043 is present
{ {
payload = OFF; payload = OFF;
fprintf(stderr,"Opening serial\n");
if ((uart_fd = serialOpen("/dev/ttyAMA0", 115200)) >= 0) { // was 9600 if ((uart_fd = serialOpen("/dev/ttyAMA0", 115200)) >= 0) { // was 9600
printf("Serial opened to Pico\n"); fprintf(stderr,"Serial opened to Pico\n");
// payload = ON; // payload = ON;
payload = get_payload_serial(FALSE);
fprintf(stderr,"Get_payload_status: %d \n", payload); // not debug
} else { } else {
fprintf(stderr, "Unable to open UART: %s\n -> Did you configure /boot/config.txt and /boot/cmdline.txt?\n", strerror(errno)); fprintf(stderr, "Unable to open UART: %s\n -> Did you configure /boot/config.txt and /boot/cmdline.txt?\n", strerror(errno));
} }
@ -556,7 +562,7 @@ int main(int argc, char * argv[]) {
uptime = (int) (uptime_sec + 0.5); uptime = (int) (uptime_sec + 0.5);
// printf("Uptime sec: %f \n", uptime_sec); // printf("Uptime sec: %f \n", uptime_sec);
// #ifdef DEBUG_LOGGING // #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 // #endif
fclose(uptime_file); fclose(uptime_file);
@ -569,7 +575,7 @@ int main(int argc, char * argv[]) {
char * token; char * token;
fputc('\n', file1); fputc('\n', file1);
fgets(cmdbuffer, 1000, 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 // serialPuts(uart_fd, cmdbuffer); // write INA data to Pico over serial
@ -613,20 +619,20 @@ int main(int argc, char * argv[]) {
payload = get_payload_serial(FALSE); payload = get_payload_serial(FALSE);
printf("get_payload_status: %d \n", payload); // not debug printf("get_payload_status: %d \n", payload); // not debug
fflush(stdout); fflush(stdout);
printf("String: %s\n", buffer2); // printf("String: %s\n", buffer2);
fflush(stdout); fflush(stdout);
strcpy(sensor_payload, buffer2); 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"); telem_file = fopen("/home/pi/CubeSatSim/telem.txt", "a");
printf("Writing payload string\n"); // printf("Writing payload string\n");
time_t timeStamp; time_t timeStamp;
time(&timeStamp); // get timestamp time(&timeStamp); // get timestamp
// printf("Timestamp: %s\n", ctime(&timeStamp)); // printf("Timestamp: %s\n", ctime(&timeStamp));
char timeStampNoNl[31], bat_string[31]; char timeStampNoNl[31], bat_string[31];
snprintf(timeStampNoNl, 30, "%.24s", ctime(&timeStamp)); 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); 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 fprintf(telem_file, "%s %s %s\n", timeStampNoNl, bat_string, sensor_payload); // write telemetry string to telem.txt file
fclose(telem_file); fclose(telem_file);
@ -643,7 +649,7 @@ int main(int argc, char * argv[]) {
if (token != NULL) { if (token != NULL) {
sensor[count1] = (float) atof(token); sensor[count1] = (float) atof(token);
// #ifdef DEBUG_LOGGING // #ifdef DEBUG_LOGGING
printf("sensor: %f ", sensor[count1]); // print sensor data // printf("sensor: %f ", sensor[count1]); // print sensor data
// #endif // #endif
token = strtok(NULL, space); token = strtok(NULL, space);
} }
@ -672,8 +678,8 @@ int main(int argc, char * argv[]) {
if ((millis() - newGpsTime) > 60000) { if ((millis() - newGpsTime) > 60000) {
longitude += rnd_float(-0.05, 0.05) / 100.0; // was .05 longitude += rnd_float(-0.05, 0.05) / 100.0; // was .05
latitude += rnd_float(-0.05, 0.05) / 100.0; latitude += rnd_float(-0.05, 0.05) / 100.0;
printf("GPS Location with Rnd: %f, %f \n", latitude, 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)); // printf("GPS Location with Rnd: APRS %07.2f, %08.2f \n", toAprsFormat(latitude), toAprsFormat(longitude));
newGpsTime = millis(); newGpsTime = millis();
} }
@ -773,7 +779,7 @@ int main(int argc, char * argv[]) {
} }
#ifdef DEBUG_LOGGING #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 #endif
if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode && !hab_mode) if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode && !hab_mode)
@ -801,6 +807,10 @@ int main(int argc, char * argv[]) {
digitalWrite(txLed, txLedOff); digitalWrite(txLed, txLedOff);
digitalWrite(onLed, onLedOff); digitalWrite(onLed, onLedOff);
FILE * file6;
file6 = popen("echo 'shutdown due to low battery voltage!' | wall", "r");
pclose(file6);
sleep(1); sleep(1);
digitalWrite(onLed, onLedOn); digitalWrite(onLed, onLedOn);
sleep(1); sleep(1);
@ -810,7 +820,6 @@ int main(int argc, char * argv[]) {
sleep(1); sleep(1);
digitalWrite(onLed, onLedOff); 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"); file6 = popen("sudo shutdown -h now > /dev/null 2>&1", "r");
pclose(file6); pclose(file6);
sleep(10); sleep(10);
@ -819,7 +828,7 @@ int main(int argc, char * argv[]) {
FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w"); FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w");
if (fp != NULL) { if (fp != NULL) {
printf("Writing telem_string.txt\n"); // printf("Writing telem_string.txt\n");
if (batteryVoltage != 4.5) if (batteryVoltage != 4.5)
fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent); fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent);
else else
@ -839,16 +848,16 @@ int main(int argc, char * argv[]) {
if ((mode == AFSK) || (mode == CW)) { if ((mode == AFSK) || (mode == CW)) {
get_tlm(); get_tlm();
sleep(25); 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); int rand_sleep = (int)rnd_float(0.0, 5.0);
sleep(rand_sleep); 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 } else if ((mode == FSK) || (mode == BPSK)) {// FSK or BPSK
get_tlm_fox(); get_tlm_fox();
} else { // SSTV } else { // SSTV
fprintf(stderr, "Sleeping\n"); // fprintf(stderr, "Sleeping\n");
sleep(50); sleep(50);
} }
@ -862,17 +871,17 @@ int main(int argc, char * argv[]) {
#ifdef DEBUG_LOGGING #ifdef DEBUG_LOGGING
// printf("Tx LED On 1\n"); // printf("Tx LED On 1\n");
#endif #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)); sleep((unsigned int)(loop_count * 5));
printf("Done sleeping\n"); // printf("Done sleeping\n");
// digitalWrite(txLed, txLedOff); // digitalWrite(txLed, txLedOff);
#ifdef DEBUG_LOGGING #ifdef DEBUG_LOGGING
// printf("Tx LED Off\n"); // printf("Tx LED Off\n");
#endif #endif
} else if (mode == FSK) { } 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); sleep((unsigned int)loop_count);
printf("Done sleeping\n"); // printf("Done sleeping\n");
} }
return 0; return 0;
@ -1182,14 +1191,14 @@ void get_tlm_fox() {
/**/ /**/
// while ((millis() - sampleTime) < (unsigned int)samplePeriod) // while ((millis() - sampleTime) < (unsigned int)samplePeriod)
int startSleep = millis(); 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(2.0); // 0.5); // 25); // initial period
sleep(1.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(0.1); // 25); // 0.5); // 25);
// sleep((unsigned int)sleepTime); // 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); fflush(stdout);
sampleTime = (unsigned int) millis(); sampleTime = (unsigned int) millis();
@ -1222,7 +1231,7 @@ void get_tlm_fox() {
if (mode == FSK) if (mode == FSK)
{ {
if (loop % 32 == 0) { // was 8 if (loop % 32 == 0) { // was 8
printf("Sending MIN frame \n"); // printf("Sending MIN frame \n");
frm_type = 0x03; frm_type = 0x03;
for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) { for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) {
if (count1 < 3) if (count1 < 3)
@ -1236,7 +1245,7 @@ void get_tlm_fox() {
} }
} }
if ((loop + 16) % 32 == 0) { // was 8 if ((loop + 16) % 32 == 0) { // was 8
printf("Sending MAX frame \n"); // printf("Sending MAX frame \n");
frm_type = 0x02; frm_type = 0x02;
for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) { for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) {
if (count1 < 3) if (count1 < 3)
@ -1480,7 +1489,7 @@ void get_tlm_fox() {
} else } else
printf("Error opening command_count.txt!\n"); 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 + 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; (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256;
@ -1735,14 +1744,14 @@ void get_tlm_fox() {
// printf("Sending %d buffer bytes over socket after %d ms!\n", ctr, (long unsigned int)millis() - start); // printf("Sending %d buffer bytes over socket after %d ms!\n", ctr, (long unsigned int)millis() - start);
start = millis(); start = millis();
int sock_ret = send(sock, buffer, (unsigned int)(ctr * 2 + 2), 0); 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); fflush(stdout);
if (sock_ret < (ctr * 2 + 2)) { if (sock_ret < (ctr * 2 + 2)) {
// printf("Not resending\n"); // printf("Not resending\n");
sleep(0.5); sleep(0.5);
sock_ret = send(sock, &buffer[sock_ret], (unsigned int)(ctr * 2 + 2 - sock_ret), 0); 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++; loop_count++;
@ -1766,7 +1775,7 @@ void get_tlm_fox() {
{ {
start = millis(); // send frame until buffer fills start = millis(); // send frame until buffer fills
sock_ret = send(sock, buffer, (unsigned int)(ctr * 2 + 2), 0); 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) { if ((millis() - start) > 500) {
printf("Buffer over filled!\n"); printf("Buffer over filled!\n");
@ -2140,6 +2149,8 @@ if (setting == ON) {
fprintf(stderr,"Turning Safe Mode ON\n"); fprintf(stderr,"Turning Safe Mode ON\n");
fprintf(stderr,"Turning Battery saver mode ON\n"); fprintf(stderr,"Turning Battery saver mode ON\n");
if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { 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"); command = popen("sudo reboot now", "r");
pclose(command); pclose(command);
sleep(60); sleep(60);
@ -2154,6 +2165,8 @@ if (setting == ON) {
pclose(command); pclose(command);
fprintf(stderr,"Turning Battery saver mode OFF\n"); fprintf(stderr,"Turning Battery saver mode OFF\n");
if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { 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"); command = popen("sudo reboot now", "r");
pclose(command); pclose(command);
sleep(60); sleep(60);

@ -184,10 +184,12 @@ int start_flag_detected = FALSE;
int start_flag_complete = FALSE; int start_flag_complete = FALSE;
int end_flag_detected = FALSE; int end_flag_detected = FALSE;
int jpeg_start = 0; 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); void battery_saver(int setting);
int battery_saver_check(); int battery_saver_check();
int pi_zero_2_offset = 0;
int hab_mode = FALSE; int hab_mode = FALSE;
int battery_saver_mode = FALSE; int battery_saver_mode = FALSE;

@ -18,6 +18,8 @@ def command_control_check():
global debug_mode global debug_mode
global command_count global command_count
return
output(pd, 1) output(pd, 1)
output(ptt, 1) output(ptt, 1)
sleep(1) sleep(1)
@ -373,6 +375,8 @@ if __name__ == "__main__":
else: else:
print("command and control is activated") print("command and control is activated")
no_command = False no_command = False
# system("/home/pi/CubeSatSim/command &")
system("sudo systemctl start command")
except: except:
print("command and control not activated") print("command and control not activated")
no_command = True no_command = True
@ -394,9 +398,9 @@ if __name__ == "__main__":
# ser.write(b"AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n") # ser.write(b"AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n")
ser.write(uhf_string.encode()) ser.write(uhf_string.encode())
sleep(0.1) sleep(0.1)
ser.close()
except: except:
print("Error in serial write") print("Error in serial write")
ser.close()
output(pd, 0) output(pd, 0)
sleep(10) # delay so cubesatsim code catches up sleep(10) # delay so cubesatsim code catches up
@ -525,10 +529,11 @@ if __name__ == "__main__":
output(txLed, txLedOff) output(txLed, txLedOff)
command_control_check() command_control_check()
sleep(2)
f.close() f.close()
sleep(5) sleep(10)
except: except:
command_control_check() # command_control_check()
sleep(1) sleep(1)
elif (mode == 's'): elif (mode == 's'):
print("SSTV") print("SSTV")
@ -709,12 +714,12 @@ if __name__ == "__main__":
output(txLed, txLedOff) output(txLed, txLedOff)
# output (ptt, 1) # output (ptt, 1)
# output(pd, 0) # output(pd, 0)
sleep(5) sleep(10)
except: except:
print("image 2 did not load - copy from CubeSatSim/sstv directory") print("image 2 did not load - copy from CubeSatSim/sstv directory")
if (txc == False): if (txc == False):
if (command_tx == True): 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: while 1:
if (command_tx == True): if (command_tx == True):
command_control_check() command_control_check()
@ -736,7 +741,7 @@ if __name__ == "__main__":
sleep(1) sleep(1)
elif (mode == 'b'): elif (mode == 'b'):
command_control_check() # command_control_check()
print("BPSK") print("BPSK")
print("turn on FM rx") print("turn on FM rx")
output(pd, 1) output(pd, 1)
@ -752,7 +757,7 @@ if __name__ == "__main__":
# output(txLed, txLedOn) # output(txLed, txLedOn)
# sleep(0.03) # sleep(0.03)
# output(txLed, txLedOff) # output(txLed, txLedOff)
command_control_check() # command_control_check()
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
@ -772,7 +777,7 @@ if __name__ == "__main__":
# output(txLed, txLedOn) # output(txLed, txLedOn)
# sleep(0.03) # sleep(0.03)
# output(txLed, txLedOff) # output(txLed, txLedOff)
command_control_check() # command_control_check()
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
sleep(4.2) sleep(4.2)

@ -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)

@ -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

@ -10,7 +10,7 @@ StandardError=inherit
Restart=always Restart=always
User=root User=root
CPUAccounting=true CPUAccounting=true
CPUQuota=5% CPUQuota=7%
[Install] [Install]
WantedBy=default.target WantedBy=default.target

@ -74,6 +74,22 @@ else
echo "no changes to rpitx.service." echo "no changes to rpitx.service."
fi fi
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 FILE=/home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg
if [ ! -f "$FILE" ]; then if [ ! -f "$FILE" ]; then
echo "Copying SSTV image 1." echo "Copying SSTV image 1."
@ -143,7 +159,7 @@ fi
cd /home/pi/pi-power-button cd /home/pi/pi-power-button
# git checkout reboot-mode-change git checkout reboot-mode-change-cc
git pull --no-rebase > .updated_p git pull --no-rebase > .updated_p
@ -203,7 +219,7 @@ git pull --no-rebase > .updated_p
script/install script/install
sudo apt-get update && sudo apt-get dist-upgrade -y 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 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 sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219 pillow
fi fi
@ -278,7 +294,7 @@ if [ "$noreboot" = "0" ] ; then
else else
grep 'changed' /home/pi/CubeSatSim/.updated grep 'changed' /home/pi/CubeSatSim/.updated
if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then
echo "reboot" echo "reboot due to code changes " | wall
sudo reboot -h now sudo reboot -h now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
else else

Loading…
Cancel
Save

Powered by TurnKey Linux.