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
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
# 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
echo "Starting direwolf"
echo "Waiting 20 seconds for USB"
if [ "$1" = "d" ]; then
sleep 20
echo "debug mode"
FILE=/home/pi/CubeSatSim/command_control_direwolf
if [[ $(arecord -l | grep card) ]] && [ -f "$FILE" ]; then
direwolf -c /home/pi/CubeSatSim/direwolf-cc.conf -t 0l | python3 /home/pi/CubeSatSim/aprs_in.py d
echo "Starting Direwolf DTMF and APRS Command and Control"
if [ "$1" = "d" ]; 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
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
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: "
@ -111,7 +122,7 @@ elif [ "$1" = "-i" ]; then
reboot=1
## echo "Rebooting CubeSatSim"
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-a" ]; then
echo "changing CubeSatSim to AFSK mode"
@ -120,7 +131,7 @@ elif [ "$1" = "-a" ]; then
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
# if ! grep 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
@ -128,9 +139,9 @@ elif [ "$1" = "-a" ]; then
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
## sudo stop rpitx
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-m" ]; then
@ -147,9 +158,9 @@ elif [ "$1" = "-m" ]; then
fi
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
## sudo stop rpitx
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-f" ]; then
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
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
## sudo stop rpitx
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-b" ]; then
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
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
## sudo stop rpitx
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-s" ]; then
echo "changing CubeSatSim to SSTV mode"
@ -185,9 +196,9 @@ elif [ "$1" = "-s" ]; then
fi
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
## sudo stop rpitx
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
## exit
elif [ "$1" = "-t" ]; then
@ -234,7 +245,7 @@ elif [ "$1" = "-t" ]; then
reboot=1
## sudo reboot now
# sudo systemctl restart cubesatsim
# sudo restart cubesatsim
elif [ "$1" = "-c" ]; then
@ -436,6 +447,7 @@ 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
@ -464,9 +476,9 @@ elif [ "$1" = "-T" ]; then
if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then
echo "Command and control set to OFF"
sudo rm /home/pi/CubeSatSim/command_control
reboot=1
## echo "rebooting"
## sudo systemctl stop rpitx
# reboot=1
echo "restarting command and control"
sudo systemctl restart command
## sudo reboot now
fi
@ -480,14 +492,79 @@ 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 "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"
reboot=1
## sudo systemctl stop rpitx
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
## 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" = "-R" ]; then
echo
@ -613,6 +690,14 @@ elif [ "$1" = "-q" ]; then
## sudo reboot now
# 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
@ -815,7 +900,7 @@ 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 " -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"
@ -823,11 +908,12 @@ 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"
@ -850,6 +936,7 @@ fi
if [ "$reboot" = "1" ] ; then
if [ "$noreboot" = "0" ] ; then
echo 'Reboot due to config change!' | wall
echo "Rebooting"
sudo systemctl stop rpitx
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
#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
@ -128,6 +126,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

6
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

@ -26,7 +26,6 @@
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'";
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
// voltageThreshold = 3.7;
printf("Pi Zero 2 detected\n");
pi_zero_2_offset = 500;
}
printf("\n\nCubeSatSim v1.3.2 starting...\n\n");
@ -101,6 +101,9 @@ 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 * 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);
@ -375,10 +378,13 @@ int main(int argc, char * argv[]) {
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));
}
@ -556,7 +562,7 @@ 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);
@ -569,7 +575,7 @@ int main(int argc, char * argv[]) {
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 +619,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 +649,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 +678,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 +779,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 +806,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 +820,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 +828,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,16 +848,16 @@ 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");
// fprintf(stderr, "Sleeping\n");
sleep(50);
}
@ -862,17 +871,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,14 +1191,14 @@ 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();
@ -1222,7 +1231,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 +1245,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 +1489,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 +1744,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 +1775,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 +2149,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 +2165,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);

@ -184,10 +184,12 @@ 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;

@ -17,6 +17,8 @@ def command_control_check():
global no_command
global debug_mode
global command_count
return
output(pd, 1)
output(ptt, 1)
@ -373,6 +375,8 @@ 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
@ -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(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
@ -524,11 +528,12 @@ 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")
@ -709,12 +714,12 @@ 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()
@ -736,7 +741,7 @@ if __name__ == "__main__":
sleep(1)
elif (mode == 'b'):
command_control_check()
# command_control_check()
print("BPSK")
print("turn on FM rx")
output(pd, 1)
@ -752,7 +757,7 @@ if __name__ == "__main__":
# output(txLed, txLedOn)
# sleep(0.03)
# output(txLed, txLedOff)
command_control_check()
# command_control_check()
if (command_tx == True):
output(txLed, txLedOn)
@ -772,7 +777,7 @@ if __name__ == "__main__":
# output(txLed, txLedOn)
# sleep(0.03)
# output(txLed, txLedOff)
command_control_check()
# command_control_check()
if (command_tx == True):
output(txLed, txLedOn)
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
User=root
CPUAccounting=true
CPUQuota=5%
CPUQuota=7%
[Install]
WantedBy=default.target

@ -74,6 +74,22 @@ else
echo "no changes to rpitx.service."
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
if [ ! -f "$FILE" ]; then
echo "Copying SSTV image 1."
@ -143,7 +159,7 @@ fi
cd /home/pi/pi-power-button
# git checkout reboot-mode-change
git checkout reboot-mode-change-cc
git pull --no-rebase > .updated_p
@ -203,7 +219,7 @@ git pull --no-rebase > .updated_p
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 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
@ -278,7 +294,7 @@ if [ "$noreboot" = "0" ] ; then
else
grep 'changed' /home/pi/CubeSatSim/.updated
if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then
echo "reboot"
echo "reboot due to code changes " | wall
sudo reboot -h now
# sudo systemctl restart cubesatsim
else

Loading…
Cancel
Save

Powered by TurnKey Linux.