Merge pull request #307 from alanbjohnston/beta-cc

command and control fixes, cw fixes, safe mode
beta-sim
Alan Johnston 2 years ago committed by GitHub
commit cd86e1f45f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

117
config

@ -70,7 +70,7 @@ if [ "$1" = "" ]; then
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode is ON"
echo "Safe Mode! Battery saver mode is ON"
else
echo "Battery saver mode is OFF"
fi
@ -86,10 +86,10 @@ if [ "$1" = "" ]; then
echo "To see options, type config -h"
# echo
# set -- "-h"
fi
# fi
if [ "$1" = "-i" ]; then
elif [ "$1" = "-i" ]; then
echo "Rebooting CubeSatSim"
sudo reboot now
# sudo systemctl restart cubesatsim
@ -100,7 +100,7 @@ elif [ "$1" = "-a" ]; then
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "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
else
echo "Battery saver mode is OFF."
@ -119,7 +119,7 @@ elif [ "$1" = "-m" ]; then
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "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
else
echo "Battery saver mode is OFF."
@ -154,7 +154,7 @@ elif [ "$1" = "-s" ]; then
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode ON."
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."
@ -165,34 +165,6 @@ elif [ "$1" = "-s" ]; then
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-h" ]; then
echo "config OPTION"
echo
echo "Changes CubeSatSim mode, resets, or modifies configuration file"
echo
echo " -h This help info"
echo " -a Change to AFSK/APRS mode"
echo " -m Change to CW mode"
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 " -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"
echo " -l Change the Latitude and Longitude in the configuration file sim.cfg"
echo " -S Scan both I2C buses on the Raspberry Pi"
echo " -C Clear logs"
echo " -T Change command and control state"
echo " -R Change the Commands Count in the file command_count.txt"
echo " -B Change 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 " -p Display payload sensor data"
echo " -v Display voltage and current data"
echo
exit
elif [ "$1" = "-t" ]; then
@ -510,42 +482,52 @@ elif [ "$1" = "-R" ]; then
elif [ "$1" = "-B" ]; then
echo
echo "Manually setting battery saver mode"
echo "Manually setting Safe Mode (battery saver mode)"
echo
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode is ON."
echo "Safe Mode! Battery saver mode is ON."
mode=1
else
echo "Safe Mode is OFF."
echo "Battery saver mode is OFF."
mode=0
fi
echo
echo "Do you want Battery saver mode ON (y/n) "
echo "Do you want Safe Mode (battery saver mode) ON (y/n) "
read saver
echo
reboot=0
if [ "$saver" = "y" ] || [ "$saver" = "yes" ] ; then
echo "Battery saver mode is now ON"
touch /home/pi/CubeSatSim/battery_saver
# if ["$mode" = "0"] ; then sudo systemctl restart rpitx
if [ "$mode" = "0" ] ; then
echo "Safe Mode will be turned on! Battery saver will be turned ON"
sudo touch /home/pi/CubeSatSim/battery_saver
reboot=1
fi
else
echo "Battery saver mode is now OFF"
sudo rm /home/pi/CubeSatSim/battery_saver
# if ["$mode" = "1"] ; then sudo systemctl restart rpitx
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
reboot=1
fi
fi
value=`cat /home/pi/CubeSatSim/.mode`
echo "$value" > /dev/null
set -- $value
if [ "$1" = "a" ] || [ "$1" = "s" ] || [ "$1" = "m" ] ; then
echo "rebooting"
# sudo systemctl restart cubesatsim
sudo reboot now
if [ "$reboot" = "1" ] ; then
value=`cat /home/pi/CubeSatSim/.mode`
echo "$value" > /dev/null
set -- $value
if [ "$1" = "a" ] || [ "$1" = "s" ] || [ "$1" = "m" ] ; then
echo "rebooting"
# sudo systemctl restart cubesatsim
sudo reboot now
fi
fi
elif [ "$1" = "-q" ]; then
@ -712,8 +694,37 @@ elif [ "$1" = "-v" ]; then
echo
/home/pi/CubeSatSim/telem
else
elif [ "$1" = "-h" ]; then
echo "config OPTION"
echo
echo "Changes CubeSatSim mode, resets, or modifies configuration file"
echo
echo " -h This help info"
echo " -a Change to AFSK/APRS mode"
echo " -m Change to CW mode"
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 " -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"
echo " -l Change the Latitude and Longitude in the configuration file sim.cfg"
echo " -S Scan both I2C buses on the Raspberry Pi"
echo " -C Clear logs"
echo " -T Change command and control 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 " -p Display payload sensor data"
echo " -v Display voltage and current data"
echo
exit
else
# echo
echo "Unknown option. Try config -h for a list of supported options."
echo

@ -190,12 +190,12 @@ int main(int argc, char * argv[]) {
battery_saver_mode = battery_saver_check();
/*
/**/
if (battery_saver_mode == ON)
fprintf(stderr, "\nBattery_saver_mode is ON\n\n");
fprintf(stderr, "Safe Mode! Battery_saver_mode is ON\n\n");
else
fprintf(stderr, "\nBattery_saver_mode is OFF\n\n");
*/
/**/
fflush(stderr);
if (mode == AFSK)
@ -827,13 +827,14 @@ int main(int argc, char * argv[]) {
// batteryVoltage = voltage[map[BAT]];
// batteryCurrent = current[map[BAT]];
/*
if (batteryVoltage < 3.7) {
SafeMode = 1;
printf("Safe Mode!\n");
} else
SafeMode = 0;
*/
FILE * cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (cpuTempSensor) {
// double cpuTemp;
@ -929,14 +930,22 @@ int main(int argc, char * argv[]) {
if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode && !hab_mode)
{
fprintf(stderr,"Battery voltage low - switch to battery saver\n");
if (battery_saver_mode == OFF)
fprintf(stderr,"Battery voltage low\n");
if (battery_saver_mode == OFF) {
fprintf(stderr,"Switch to battery saver\n");
battery_saver(ON);
fprintf(stderr, "Safe Mode!\n");
SafeMode = 1;
}
} else if ((battery_saver_mode == ON) && (batteryCurrent < 0) && !sim_mode && !hab_mode)
{
fprintf(stderr,"Battery is being charged - switch battery saver off\n");
if (battery_saver_mode == ON)
battery_saver(OFF);
if (battery_saver_mode == ON) {
battery_saver(OFF);
fprintf(stderr, "Safe Mode off!\n");
SafeMode = 0;
}
}
if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode && !hab_mode) // currentThreshold ensures that this won't happen when running on DC power.
{
@ -1117,12 +1126,12 @@ void get_tlm(void) {
char header_str2b[30]; // for APRS coordinates
char header_lat[10];
char header_long[10];
char header_str4[] = "hi hi ";
char header_str4[] = "hi hi de ";
// char footer_str1[] = "\' > t.txt && echo \'";
char footer_str1[] = "\' > t.txt";
// char footer_str[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py
char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py
char footer_str2[] = " && touch /home/pi/CubeSatSim/ready";
char footer_str2[] = " && touch /home/pi/CubeSatSim/ready";
if (ax5043) {
strcpy(str, header_str);
@ -1159,26 +1168,38 @@ void get_tlm(void) {
printf("\n\nString is %s \n\n", header_str2b);
strcat(str, header_str2b);
} else {
} else { // CW mode
strcat(str, header_str4);
strcat(str, call);
sprintf(tlm_str, "%s' > cw0.txt", &str);
printf("CW string to execute: %s\n", &tlm_str);
FILE * cw_file = popen(tlm_str, "r");
pclose(cw_file);
}
// }
printf("Str: %s \n", str);
if (mode == CW) {
int channel;
for (channel = 1; channel < 7; channel++) {
sprintf(tlm_str, "%d%d%d %d%d%d %d%d%d %d%d%d ",
sprintf(tlm_str, "echo ' %d%d%d %d%d%d %d%d%d %d%d%d ' > cw%1d.txt",
channel, upper_digit(tlm[channel][1]), lower_digit(tlm[channel][1]),
channel, upper_digit(tlm[channel][2]), lower_digit(tlm[channel][2]),
channel, upper_digit(tlm[channel][3]), lower_digit(tlm[channel][3]),
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]));
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]), channel);
// printf("%s",tlm_str);
//#ifdef HAB
// if (mode != AFSK)
//#endif
// if ((!hab_mode) || ((hab_mode) && (mode != AFSK)))
strcat(str, tlm_str);
strcat(str, tlm_str);
printf("CW string to execute: %s\n", &tlm_str);
FILE * cw_file = popen(tlm_str, "r");
pclose(cw_file);
}
} else { // APRS
@ -1247,20 +1268,24 @@ void get_tlm(void) {
}
if (mode == CW) {
char cw_str2[1000];
char cw_header2[] = "echo '";
char cw_footer2[] = "' > id.txt && gen_packets -M 20 id.txt -o morse.wav -r 48000 > /dev/null 2>&1 && cat morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3";
// char cw_str2[1000];
// char cw_header2[] = "echo '";
// char cw_footer2[] = "' > id.txt && gen_packets -M 20 id.txt -o morse.wav -r 48000 > /dev/null 2>&1 && cat morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3";
char cw_footer3[] = "' > cw.txt && touch /home/pi/CubeSatSim/cwready"; // transmit is done by rpitx.py
char cwready[] = "touch /home/pi/CubeSatSim/cwready"; // cw frame is complete. transmit is done by rpitx.py
// printf("Str str: %s \n", str);
// fflush(stdout);
strcat(str, cw_footer3);
// strcat(str, cw_footer3);
// printf("Str: %s \n", str);
// fflush(stdout);
printf("CW string to execute: %s\n", str);
fflush(stdout);
// printf("CW string to execute:: %s\n", str);
// fflush(stdout);
FILE * cw_file = popen(str, "r");
// FILE * cw_file = popen(str, "r");
// pclose(cw_file);
FILE * cw_file = popen(cwready, "r");
pclose(cw_file);
while ((cw_file = fopen("/home/pi/CubeSatSim/cwready", "r")) != NULL) { // wait for rpitx to be done
@ -1312,7 +1337,7 @@ void get_tlm(void) {
*/
strcat(str, footer_str1);
// strcat(str, call);
if (battery_saver_mode == ON)
if (battery_saver_mode == ON)
strcat(str, footer_str); // add extra packet for rpitx transmission
else
strcat(str, footer_str2);
@ -2400,11 +2425,12 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600
int battery_saver_check() {
FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r");
if (file == NULL) {
fprintf(stderr,"Battery saver mode is OFF!\n");
// fprintf(stderr,"Battery saver mode is OFF!\n");
return(OFF);
}
fclose(file);
fprintf(stderr,"Battery saver mode is ON!\n");
// fprintf(stderr, "Safe Mode!\n");
// fprintf(stderr,"Battery saver mode is ON!\n");
return(ON);
}
@ -2414,6 +2440,7 @@ if (setting == ON) {
if (battery_saver_check() == OFF) {
FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r");
pclose(command);
fprintf(stderr,"Turning Safe Mode ON\n");
fprintf(stderr,"Turning Battery saver mode ON\n");
// command = popen("if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo force_turbo=1 >> /boot/config.txt'; fi", "r");
// pclose(command);

@ -62,9 +62,10 @@ def battery_saver_check():
f = open("/home/pi/CubeSatSim/battery_saver", "r")
f.close()
txc = False
print("Safe Mode!")
print("battery saver activated")
except:
print("not activated")
print("battery saver not activated")
# txc = True
def increment_mode():
@ -372,7 +373,6 @@ if __name__ == "__main__":
print("Programming FM module!\n");
output(pd, 1)
output (ptt, 1)
try:
ser = serial.Serial("/dev/ttyAMA0", 9600)
print(ser.portstr)
@ -384,15 +384,17 @@ if __name__ == "__main__":
except:
print("Error in serial write")
ser.close()
output(pd, 0)
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")
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()
# if (mode != 'a') and (command_tx == True):
if (command_tx == True):
# if (command_tx == True):
if (mode != 'm'):
# battery_saver_mode
output(txLed, txLedOn)
# if (txc):
@ -425,14 +427,9 @@ if __name__ == "__main__":
# if (len(sys.argv)) > 1:
# print("There are arguments!")
if (mode == 'a'):
command_control_check()
# output(pd, 1)
print("AFSK")
# sleep(5)
## try:
## file = open("/home/pi/CubeSatSim/t.txt")
## file.close()
## except:
## system("echo '" + callsign + "-11>APCSS:hi hi 100 199 199 199 298 299 299 278 380 350 300 300 439 400 400 400 500 500 500 500 600 600 600 650' > /home/pi/CubeSatSim/t.txt && echo 'AMSAT>APCSS:010101/hi hi ' >> /home/pi/CubeSatSim/t.txt")
while True:
try:
f = open("/home/pi/CubeSatSim/ready")
@ -479,70 +476,46 @@ if __name__ == "__main__":
sleep(1)
elif (mode == 'm'):
print("CW")
# sleep(4)
try:
file = open("/home/pi/CubeSatSim/cw.txt")
file.close()
except:
system("echo 'hi hi 100 199 199 199 298 299 299 278 380 350 300 300 439 400 400 400 500 500 500 500 600 600 600 650' > /home/pi/CubeSatSim/cw.txt")
output(pd, 1)
if (command_tx == True):
output(txLed, txLedOn)
# battery_saver_check()
if (txc):
output (pd, 1)
output (ptt, 0)
sleep(0.1)
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
sleep(0.1)
output (ptt, 1)
output (pd, 0)
else:
if (debug_mode == 1):
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && 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")
else:
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && 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)
# output (ptt, 1)
sleep(5)
while True:
command_control_check()
try:
f = open("/home/pi/CubeSatSim/cwready")
f.close()
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1")
system("sudo rm /home/pi/CubeSatSim/cwready")
if (command_tx == True):
output(txLed, txLedOn)
output (ptt, 0)
sleep(0.1)
# battery_saver_check()
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
else:
if (debug_mode == 1):
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && 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")
## ch = 1
for chan in range(7):
command = "gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw" + str(chan) + ".txt -r 48000 > /dev/null 2>&1"
print(command)
system(command)
## chan = chan + 1
if (command_tx == True):
output(txLed, txLedOn)
if (txc):
output (pd, 1)
sleep(0.3)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
sleep(0.1)
output (ptt, 1)
# output (pd, 0)
else:
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && 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")
sleep(0.1)
output(txLed, txLedOff)
output (ptt, 1)
if (debug_mode == 1):
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")
else:
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()
f.close()
# system("sudo rm /home/pi/CubeSatSim/cwready")
sleep(5)
except:
except:
command_control_check()
sleep(1)
elif (mode == 's'):
print("SSTV")
command_control_check()
try:
# from picamera import PiCamera
# from pysstv.sstv import SSTV
@ -568,6 +541,7 @@ 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()
if (command_tx == True):
print ("Sending SSTV image")
@ -724,7 +698,7 @@ if __name__ == "__main__":
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 &")
while 1:
if (command_tx == True):
command_control_check()
output(txLed, txLedOn)
# battery_saver_check()
@ -741,7 +715,9 @@ if __name__ == "__main__":
# output (ptt, 1)
# output(pd, 0)
sleep(1)
elif (mode == 'b'):
command_control_check()
print("BPSK")
print("turn on FM rx")
output(pd, 1)

Loading…
Cancel
Save

Powered by TurnKey Linux.