Merge pull request #291 from alanbjohnston/beta-v1.3.1.1

Beta v1.3.1.1
beta-v1.3.2
Alan Johnston 2 years ago committed by GitHub
commit de4f487dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,9 +36,9 @@ To get the software follow these steps:
`cd CubeSatSim` `cd CubeSatSim`
`git checkout beta-v1.3.1` `git checkout beta-v1.3.1.1`
You are now ready to install the software using this script in the CubeSatSim directory: `# You are now ready to install the software using this script in the CubeSatSim directory:`
`./install` `./install`

310
config

@ -39,19 +39,39 @@ if [ "$1" = "" ]; then
# sim="no" # sim="no"
echo "Simulated Telemetry is OFF" echo "Simulated Telemetry is OFF"
fi fi
echo
if [ "$9" = "yes" ] || [ "$9" = "y" ]; then
echo "Balloon mode is ON"
else
echo "Balloon mode is OFF"
fi
echo echo
echo "Current command count is:" echo -n "Current command count is: "
cat /home/pi/CubeSatSim/command_count.txt cat /home/pi/CubeSatSim/command_count.txt
echo echo
echo echo
echo "Current beacon transmit mode is:" # echo "Current beacon transmit mode is:"
cat /home/pi/CubeSatSim/command_tx # cat /home/pi/CubeSatSim/command_tx
# echo
echo -n "Squelch level is: "
echo $6
echo echo
echo -e "Current sim.cfg configuration file:"
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode is ON"
else
echo "Battery saver mode is OFF"
fi
echo echo
echo -e "Current sim.cfg configuration file:"
# echo
echo $1 $2 $3 $4 $5 echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo echo
echo "To change, include an OPTION" echo "To change, include an OPTION"
@ -68,40 +88,71 @@ if [ "$1" = "-i" ]; then
elif [ "$1" = "-a" ]; then elif [ "$1" = "-a" ]; then
echo "changing CubeSatSim to AFSK mode" echo "changing CubeSatSim to AFSK mode"
sudo echo "a" > /home/pi/CubeSatSim/.mode sudo echo "a" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "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 os OFF."
# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
fi
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
exit exit
elif [ "$1" = "-m" ]; then elif [ "$1" = "-m" ]; then
echo "changing CubeSatSim to CW mode" echo "changing CubeSatSim to CW mode"
sudo echo "m" > /home/pi/CubeSatSim/.mode sudo echo "m" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode is ON."
# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
else
echo "Battery saver mode is OFF."
# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
fi
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
exit exit
elif [ "$1" = "-f" ]; then elif [ "$1" = "-f" ]; then
echo "changing CubeSatSim to FSK mode" echo "changing CubeSatSim to FSK mode"
sudo echo "f" > /home/pi/CubeSatSim/.mode sudo echo "f" > /home/pi/CubeSatSim/.mode
if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi # if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
exit exit
elif [ "$1" = "-b" ]; then elif [ "$1" = "-b" ]; then
echo "changing CubeSatSim to BPSK mode" echo "changing CubeSatSim to BPSK mode"
sudo echo "b" > /home/pi/CubeSatSim/.mode sudo echo "b" > /home/pi/CubeSatSim/.mode
if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi # if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
exit exit
elif [ "$1" = "-s" ]; then elif [ "$1" = "-s" ]; then
echo "changing CubeSatSim to SSTV mode" echo "changing CubeSatSim to SSTV mode"
sudo echo "s" > /home/pi/CubeSatSim/.mode sudo echo "s" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode ON."
# if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
else
echo "Battery saver mode is OFF."
# sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
fi
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim
exit exit
@ -125,6 +176,10 @@ elif [ "$1" = "-h" ]; then
echo " -C Clear logs" echo " -C Clear logs"
echo " -T Change command state" echo " -T Change command 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 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 echo
exit exit
@ -147,7 +202,7 @@ elif [ "$1" = "-t" ]; then
echo echo
# echo $1 $2 $3 $4 # echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo "Do you want Simulated Telemetry ON (y/n) " echo "Do you want Simulated Telemetry ON (y/n) "
read sim read sim
@ -161,13 +216,13 @@ elif [ "$1" = "-t" ]; then
echo "Simulated Telemetry is OFF" echo "Simulated Telemetry is OFF"
fi fi
# echo
echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
# echo
echo $1 $2 $3 $4 $sim $6 $7 $8 $9
echo $1 $2 $3 $4 $sim $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg
echo echo
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" echo "Restarting CubeSatSim with new configuration file"
echo
echo $1 $2 $3 $4 $sim
echo $1 $2 $3 $4 $sim > /home/pi/CubeSatSim/sim.cfg
echo
echo "Restarting CubeSatSim with new configuraation file"
echo echo
sudo systemctl restart cubesatsim sudo systemctl restart cubesatsim
@ -190,7 +245,7 @@ elif [ "$1" = "-c" ]; then
echo $1 echo $1
echo echo
# echo $1 $2 $3 $4 $5 # echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo "Enter callsign in all capitals: " echo "Enter callsign in all capitals: "
read callsign read callsign
@ -202,17 +257,17 @@ elif [ "$1" = "-c" ]; then
norestart=1 norestart=1
else else
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
echo $callsign $2 $3 $4 $5 echo $callsign $2 $3 $4 $5 $6 $7 $8 $9
echo $callsign $2 $3 $4 $5 > /home/pi/CubeSatSim/sim.cfg echo $callsign $2 $3 $4 $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg
fi fi
if [ "$norestart" = "1" ]; then if [ "$norestart" = "1" ]; then
echo echo
else else
echo echo
echo "Restarting CubeSatSim with new configuraation file" echo "Restarting CubeSatSim with new configuration file"
echo echo
sudo systemctl restart cubesatsim sudo systemctl restart cubesatsim
fi fi
@ -236,7 +291,7 @@ elif [ "$1" = "-r" ]; then
echo $2 echo $2
echo echo
# echo $1 $2 $3 $4 $5 # echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo -e "Enter Reset Count (integer): " echo -e "Enter Reset Count (integer): "
@ -254,17 +309,17 @@ elif [ "$1" = "-r" ]; then
norestart=1 norestart=1
else else
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
echo $1 $resets $3 $4 $5 echo $1 $resets $3 $4 $5 $6 $7 $8 $9
echo $1 $resets $3 $4 $5 > /home/pi/CubeSatSim/sim.cfg echo $1 $resets $3 $4 $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg
fi fi
if [ "$norestart" = "1" ]; then if [ "$norestart" = "1" ]; then
echo echo
else else
echo echo
echo "Restarting CubeSatSim with new configuraation file" echo "Restarting CubeSatSim with new configuration file"
echo echo
sudo systemctl restart cubesatsim sudo systemctl restart cubesatsim
fi fi
@ -289,7 +344,7 @@ elif [ "$1" = "-l" ]; then
echo $3 echo $3
echo echo
# echo $1 $2 $3 $4 $5 # echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo -e "Enter latitude (decimal degrees, positive is north): " echo -e "Enter latitude (decimal degrees, positive is north): "
@ -330,15 +385,15 @@ elif [ "$1" = "-l" ]; then
echo "Keeping value of" $long echo "Keeping value of" $long
fi fi
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n" echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
echo $1 $2 $lat $long $5 echo $1 $2 $lat $long $5 $6 $7 $8 $9
echo $1 $2 $lat $long $5 > /home/pi/CubeSatSim/sim.cfg echo $1 $2 $lat $long $5 $6 $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg
if [ "$norestart" = "1" ]; then if [ "$norestart" = "1" ]; then
echo echo
else else
echo echo
echo "Restarting CubeSatSim with new configuraation file" echo "Restarting CubeSatSim with new configuration file"
echo echo
sudo systemctl restart cubesatsim sudo systemctl restart cubesatsim
fi fi
@ -367,6 +422,7 @@ elif [ "$1" = "-C" ]; then
sudo systemctl stop cubesatsim sudo systemctl stop cubesatsim
sudo systemctl stop rpitx sudo systemctl stop rpitx
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s sudo journalctl --vacuum-time=1s
sudo systemctl reboot now sudo systemctl reboot now
@ -391,11 +447,13 @@ elif [ "$1" = "-T" ]; then
sudo sed -i 's/False/True/g' /home/pi/CubeSatSim/command_tx sudo sed -i 's/False/True/g' /home/pi/CubeSatSim/command_tx
echo "Command state set to True to enable beacon" echo "Command state set to True to enable beacon"
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
else else
sudo sed -i 's/True/False/g' /home/pi/CubeSatSim/command_tx sudo sed -i 's/True/False/g' /home/pi/CubeSatSim/command_tx
echo "Command state set to False to disable beacon" echo "Command state set to False to disable beacon"
echo "rebooting" echo "rebooting"
sudo systemctl stop rpitx
sudo reboot now sudo reboot now
fi fi
@ -420,6 +478,194 @@ elif [ "$1" = "-R" ]; then
else else
echo "Commands count not reset" echo "Commands count not reset"
fi fi
elif [ "$1" = "-B" ]; then
echo
echo "Manually setting battery saver mode"
echo
FILE=/home/pi/CubeSatSim/battery_saver
if [ -f "$FILE" ]; then
echo "Battery saver mode is ON."
mode=1
else
echo "Battery saver mode is OFF."
mode=0
fi
echo
echo "Do you want Battery saver mode ON (y/n) "
read saver
echo
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
else
echo "Battery saver mode is now OFF"
sudo rm /home/pi/CubeSatSim/battery_saver
# if ["$mode" = "1"] ; then sudo systemctl restart rpitx
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
fi
elif [ "$1" = "-q" ]; then
echo
echo "Editing the Squelch setting in"
echo "the configuration file for CubeSatSim"
echo
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
echo
echo "Current value of squelch is"
echo $6
echo
# echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo -e "Enter squelch (integer 0 - 8): "
read sq
if [ -z $sq ] ; then
sq="$6"
echo "Keeping value of" $lat
fi
if ! [[ $sq =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]] ; then
echo "Error: not a number!"
sq="$6"
echo "Keeping value of" $sq
fi
# echo
echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
# echo
echo $1 $2 $3 $4 $5 $sq $7 $8 $9
echo $1 $2 $3 $4 $4 $sq $7 $8 $9 > /home/pi/CubeSatSim/sim.cfg
echo
echo "Restarting CubeSatSim with new configuration file"
echo
sudo systemctl restart cubesatsim
elif [ "$1" = "-F" ]; then
echo
echo "Editing the tx and rx frequency in the"
echo "configuration file for CubeSatSim"
echo
echo "Return keeps current value."
# echo -e "Current sim.cfg configuration file:"
# echo
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
echo "Current value of tx is"
echo $7
echo
echo "Current value of rx is"
echo $8
echo
# echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo "Enter tx frequency as 4XX.XXXX: "
read tx
if [ -z $tx ] ; then
tx="$7"
echo "Keeping value of" $tx
fi
echo "Enter rx frequency as 4XX.XXXX: "
read rx
if [ -z $rx ] ; then
rx="$8"
echo "Keeping value of" $rx
fi
# else
echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
echo $1 $2 $3 $4 $5 $6 $tx $rx $9
echo $1 $2 $3 $4 $5 $6 $tx $rx $9 > /home/pi/CubeSatSim/sim.cfg
# fi
# if [ "$norestart" = "1" ]; then
# echo
# else
echo
echo "Restarting CubeSatSim with new configuration file"
echo
sudo systemctl restart cubesatsim
# fi
elif [ "$1" = "-H" ]; then
# echo
echo "Editing the Balloon mode setting in"
echo "the configuration file for CubeSatSim"
echo
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
if [ "$9" = "yes" ] || [ "$9" = "y" ]; then
echo "Balloon mode is ON"
else
echo "Balloon mode is OFF"
fi
echo
# echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo "Do you want Balloon mode ON (y/n) "
read hab
echo
if [ "$hab" = "y" ] || [ "$hab" = "yes" ] ; then
hab="yes"
echo "Balloon mode is ON"
else
hab="no"
echo "Balloon mode is OFF"
fi
# echo
echo -e "\nCubeSatSim configuration sim.cfg file updated to: \n"
# echo
echo $1 $2 $3 $4 $5 $6 $7 $8 $hab
echo $1 $2 $3 $4 $5 $6 $7 $8 $hab > /home/pi/CubeSatSim/sim.cfg
echo
echo "Restarting CubeSatSim with new configuration file"
echo
sudo systemctl restart cubesatsim
fi fi
# sudo systemctl restart cubesatsim # sudo systemctl restart cubesatsim

@ -7,6 +7,12 @@ import busio
from adafruit_extended_bus import ExtendedI2C as I2C from adafruit_extended_bus import ExtendedI2C as I2C
from adafruit_ina219 import INA219 from adafruit_ina219 import INA219
from adafruit_ina219 import ADCResolution, BusVoltageRange from adafruit_ina219 import ADCResolution, BusVoltageRange
import signal
# Don't turn these signal into exceptions, just die.
# https://stackoverflow.com/questions/26692284/how-to-prevent-brokenpipeerror-when-doing-a-flush-in-python
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
if __name__ == "__main__": if __name__ == "__main__":
# print 'Length: ', len(sys.argv) # print 'Length: ', len(sys.argv)

@ -57,7 +57,7 @@ sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circui
cd ~/CubeSatSim cd ~/CubeSatSim
git pull git pull --no-rebase
make debug make debug
@ -66,7 +66,7 @@ if [ -f "$FILE" ]; then
echo "$FILE exists." echo "$FILE exists."
else else
echo "creating $FILE" echo "creating $FILE"
echo "ARG1=s" > .mode echo "f" > .mode
fi fi
cd cd
@ -221,8 +221,36 @@ sudo raspi-config nonint do_legacy 0
sudo sh -c 'echo "\nboot_delay=0" >> /boot/config.txt' sudo sh -c 'echo "\nboot_delay=0" >> /boot/config.txt'
fi fi
if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
sudo sh -c 'echo "\n" >> /boot/config.txt' sudo sh -c 'echo "\n" >> /boot/config.txt'
changed=0
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
if [ -z "$1" ] ; then n1="AMSAT" ; changed=1 ; else n1=$1 ; fi # callsign
if [ -z "$2" ] ; then n2="0" ; changed=1 ; else n2=$2 ; fi # reset count
if [ -z "$3" ] ; then n3="0" ; changed=1 ; else n3=$3 ; fi # lat
if [ -z "$4" ] ; then n4="0" ; changed=1 ; else n4=$4 ; fi # lon
if [ -z "$5" ] ; then n5="no" ; changed=1 ; else n5=$5 ; fi # sim mode
if [ -z "$6" ] ; then n6="3" ; changed=1 ; else n6=$6 ; fi # squelch
if [ -z "$7" ] ; then n7="434.9000" ; changed=1 ; else n7=$7 ; fi # transmit frequency
if [ -z "$8" ] ; then n8="436.0000" ; changed=1 ; else n8=$8 ; fi # receive frequency
if [ -z "$9" ] ; then n9="no" ; changed=1 ; else n9=$9 ; fi # hab mode
if [ $changed -eq 1 ]; then
echo -e "Current sim.cfg configuration file:"
echo
echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n"
echo
echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9
echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 > /home/pi/CubeSatSim/sim.cfg
echo
fi
echo "Would you like to reboot to complete the installation (y/n)?" echo "Would you like to reboot to complete the installation (y/n)?"
read -r ANS read -r ANS

318
main.c

@ -45,9 +45,57 @@ int main(int argc, char * argv[]) {
printf("\n\nCubeSatSim v1.3b starting...\n\n"); printf("\n\nCubeSatSim v1.3b starting...\n\n");
wiringPiSetup(); wiringPiSetup();
// Open configuration file with callsign and reset count
FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r");
if (config_file == NULL) {
printf("Creating config file.");
config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "w");
fprintf(config_file, "%s %d", " ", 100);
fclose(config_file);
config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r");
}
// char * cfg_buf[100];
fscanf(config_file, "%s %d %f %f %s %d %s %s %s",
call, & reset_count, & lat_file, & long_file, sim_yes, & squelch, tx, rx, hab_yes);
fclose(config_file);
fprintf(stderr,"Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s %d %s %s %s\n",
call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes);
fprintf(stderr, "Transmit on %s Receive on %s\n", tx, rx);
// program_radio(); // do in rpitx instead
program_radio(); reset_count = (reset_count + 1) % 0xffff;
if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) {
fprintf(stderr, "Valid latitude and longitude in config file\n");
// convert to APRS DDMM.MM format
// latitude = toAprsFormat(lat_file);
// longitude = toAprsFormat(long_file);
latitude = lat_file;
longitude = long_file;
fprintf(stderr, "Lat/Long %f %f\n", latitude, longitude);
fprintf(stderr, "Lat/Long in APRS DDMM.MM format: %07.2f/%08.2f\n", toAprsFormat(latitude), toAprsFormat(longitude));
newGpsTime = millis();
} else { // set default
// latitude = toAprsFormat(latitude);
// longitude = toAprsFormat(longitude);
newGpsTime = millis();
}
if (strcmp(sim_yes, "yes") == 0) {
sim_mode = TRUE;
fprintf(stderr, "Sim mode is ON\n");
}
if (strcmp(hab_yes, "yes") == 0) {
hab_mode = TRUE;
fprintf(stderr, "HAB mode is ON\n");
}
// FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r"); // FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r");
FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r"); FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r");
@ -67,9 +115,10 @@ int main(int argc, char * argv[]) {
// sleep(2); // sleep(2);
#ifdef HAB //#ifdef HAB
Serial.println("HAB mode enabled - balloon icon and BAT only telem and no low voltage shutdown"); if (hab_mode)
#endif fprintf(stderr, "HAB mode enabled - in APRS balloon icon and no battery saver or low voltage shutdown\n");
//#endif
// FILE * rpitx_restart = popen("sudo systemctl restart rpitx", "r"); // FILE * rpitx_restart = popen("sudo systemctl restart rpitx", "r");
// pclose(rpitx_restart); // pclose(rpitx_restart);
@ -139,44 +188,16 @@ int main(int argc, char * argv[]) {
fclose(telem_file); fclose(telem_file);
printf("Opened telem file\n"); printf("Opened telem file\n");
// Open configuration file with callsign and reset count
FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r");
if (config_file == NULL) {
printf("Creating config file.");
config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "w");
fprintf(config_file, "%s %d", " ", 100);
fclose(config_file);
config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r");
}
// char * cfg_buf[100];
fscanf(config_file, "%s %d %f %f %s", call, & reset_count, & lat_file, & long_file, sim_yes);
fclose(config_file);
printf("Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s\n", call, reset_count, lat_file, long_file, sim_yes);
reset_count = (reset_count + 1) % 0xffff;
if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) {
printf("Valid latitude and longitude in config file\n");
// convert to APRS DDMM.MM format
// latitude = toAprsFormat(lat_file);
// longitude = toAprsFormat(long_file);
latitude = lat_file;
longitude = long_file;
printf("Lat/Long %f %f\n", latitude, longitude);
printf("Lat/Long in APRS DDMM.MM format: %07.2f/%08.2f\n", toAprsFormat(latitude), toAprsFormat(longitude));
newGpsTime = millis();
} else { // set default
// latitude = toAprsFormat(latitude);
// longitude = toAprsFormat(longitude);
newGpsTime = millis();
}
if (strcmp(sim_yes, "yes") == 0)
sim_mode = TRUE;
battery_saver_mode = battery_saver_check();
/*
if (battery_saver_mode == ON)
fprintf(stderr, "\nBattery_saver_mode is ON\n\n");
else
fprintf(stderr, "\nBattery_saver_mode is OFF\n\n");
*/
fflush(stderr);
if (mode == AFSK) if (mode == AFSK)
{ {
// Check for SPI and AX-5043 Digital Transceiver Board // Check for SPI and AX-5043 Digital Transceiver Board
@ -298,7 +319,7 @@ int main(int argc, char * argv[]) {
} }
*/ */
config_file = fopen("sim.cfg", "w"); config_file = fopen("sim.cfg", "w");
fprintf(config_file, "%s %d %8.4f %8.4f %s", call, reset_count, lat_file, long_file, sim_yes); fprintf(config_file, "%s %d %8.4f %8.4f %s %d %s %s %s", call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx, hab_yes);
// fprintf(config_file, "%s %d", call, reset_count); // fprintf(config_file, "%s %d", call, reset_count);
fclose(config_file); fclose(config_file);
config_file = fopen("sim.cfg", "r"); config_file = fopen("sim.cfg", "r");
@ -407,7 +428,7 @@ int main(int argc, char * argv[]) {
sim_mode = TRUE; sim_mode = TRUE;
printf("Simulated telemetry mode!\n"); fprintf(stderr, "Simulated telemetry mode!\n");
srand((unsigned int)time(0)); srand((unsigned int)time(0));
@ -524,7 +545,7 @@ int main(int argc, char * argv[]) {
get_tlm_fox(); // fill transmit buffer with reset count 0 packets that will be ignored get_tlm_fox(); // fill transmit buffer with reset count 0 packets that will be ignored
firstTime = 1; firstTime = 1;
if (!sim_mode) // if (!sim_mode) // always read sensors, even in sim mode
{ {
strcpy(pythonStr, pythonCmd); strcpy(pythonStr, pythonCmd);
strcat(pythonStr, busStr); strcat(pythonStr, busStr);
@ -582,7 +603,42 @@ int main(int argc, char * argv[]) {
printf("++++ Loop time: %5.3f sec +++++\n", (millis() - loopTime)/1000.0); printf("++++ Loop time: %5.3f sec +++++\n", (millis() - loopTime)/1000.0);
fflush(stdout); fflush(stdout);
loopTime = millis(); loopTime = millis();
{
int count1;
char * token;
fputc('\n', file1);
fgets(cmdbuffer, 1000, file1);
fprintf(stderr, "Python read Result: %s\n", cmdbuffer);
const char space[2] = " ";
token = strtok(cmdbuffer, space);
for (count1 = 0; count1 < 8; count1++) {
if (token != NULL) {
voltage[count1] = (float) atof(token);
#ifdef DEBUG_LOGGING
// printf("voltage: %f ", voltage[count1]);
#endif
token = strtok(NULL, space);
if (token != NULL) {
current[count1] = (float) atof(token);
if ((current[count1] < 0) && (current[count1] > -0.5))
current[count1] *= (-1.0f);
#ifdef DEBUG_LOGGING
// printf("current: %f\n", current[count1]);
#endif
token = strtok(NULL, space);
}
}
if (voltage[map[BAT]] == 0.0)
batteryVoltage = 4.5;
else
batteryVoltage = voltage[map[BAT]];
batteryCurrent = current[map[BAT]];
}
if (sim_mode) { // simulated telemetry if (sim_mode) { // simulated telemetry
double time = ((long int)millis() - time_start) / 1000.0; double time = ((long int)millis() - time_start) / 1000.0;
@ -650,6 +706,9 @@ int main(int argc, char * argv[]) {
// end of simulated telemetry // end of simulated telemetry
} }
else { else {
// code moved
/*
int count1; int count1;
char * token; char * token;
fputc('\n', file1); fputc('\n', file1);
@ -676,12 +735,18 @@ int main(int argc, char * argv[]) {
token = strtok(NULL, space); token = strtok(NULL, space);
} }
} }
if (voltage[map[BAT]] == 0.0)
batteryVoltage = 4.5;
else
batteryVoltage = voltage[map[BAT]];
batteryCurrent = current[map[BAT]];
*/
} }
batteryVoltage = voltage[map[BAT]]; // batteryVoltage = voltage[map[BAT]];
batteryCurrent = current[map[BAT]]; // batteryCurrent = current[map[BAT]];
if (batteryVoltage < 3.6) { if (batteryVoltage < 3.7) {
SafeMode = 1; SafeMode = 1;
printf("Safe Mode!\n"); printf("Safe Mode!\n");
} else } else
@ -814,10 +879,22 @@ int main(int argc, char * argv[]) {
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 ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V
// fprintf(stderr, "\n\nbattery_saver_mode : %d current: %f\n", battery_saver_mode, batteryCurrent);
/**/ //#ifndef HAB
#ifndef HAB
if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. 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)
battery_saver(ON);
} 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 ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode && !hab_mode) // currentThreshold ensures that this won't happen when running on DC power.
{ {
fprintf(stderr, "Battery voltage too low: %f V - shutting down!\n", batteryVoltage); fprintf(stderr, "Battery voltage too low: %f V - shutting down!\n", batteryVoltage);
digitalWrite(txLed, txLedOff); digitalWrite(txLed, txLedOff);
@ -839,11 +916,19 @@ int main(int argc, char * argv[]) {
pclose(file6); pclose(file6);
sleep(10); sleep(10);
} }
#endif //#endif
FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w"); FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w");
printf("Writing telem_string.txt\n"); if (fp != NULL) {
fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent); printf("Writing telem_string.txt\n");
fclose(fp); if (batteryVoltage != 4.5)
fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent);
else
fprintf(fp, "\n"); // don't show voltage and current if it isn't a sensor value
fclose(fp);
} else
printf("Error writing to telem_string.txt\n");
/**/ /**/
// sleep(1); // Delay 1 second // sleep(1); // Delay 1 second
@ -992,8 +1077,9 @@ void get_tlm(void) {
// char footer_str1[] = "\' > t.txt && echo \'"; // char footer_str1[] = "\' > t.txt && echo \'";
char footer_str1[] = "\' > t.txt"; 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[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py
char footer_str[] = " && 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";
if (ax5043) { if (ax5043) {
strcpy(str, header_str); strcpy(str, header_str);
} else { } else {
@ -1019,11 +1105,13 @@ void get_tlm(void) {
if (ax5043) if (ax5043)
sprintf(header_str2b, "=%s%c%sShi hi ", header_lat, 0x5c, header_long); // add APRS lat and long sprintf(header_str2b, "=%s%c%sShi hi ", header_lat, 0x5c, header_long); // add APRS lat and long
else else
#ifdef HAB //#ifdef HAB
sprintf(header_str2b, "=%s%c%sOhi hi ", header_lat, 0x2f, header_long); // add APRS lat and long with Balloon HAB icon if (hab_mode)
#else sprintf(header_str2b, "=%s%c%sOhi hi ", header_lat, 0x2f, header_long); // add APRS lat and long with Balloon HAB icon
sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long with Satellite icon //#else
#endif else
sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long with Satellite icon
//#endif
printf("\n\nString is %s \n\n", header_str2b); printf("\n\nString is %s \n\n", header_str2b);
strcat(str, header_str2b); strcat(str, header_str2b);
@ -1032,7 +1120,7 @@ void get_tlm(void) {
} }
// } // }
printf("Str: %s \n", str); printf("Str: %s \n", str);
if (mode == CW) {
int channel; int channel;
for (channel = 1; channel < 7; 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, "%d%d%d %d%d%d %d%d%d %d%d%d ",
@ -1042,18 +1130,23 @@ void get_tlm(void) {
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4])); channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]));
// printf("%s",tlm_str); // printf("%s",tlm_str);
#ifdef HAB //#ifdef HAB
if (mode != AFSK) // if (mode != AFSK)
#endif //#endif
// if ((!hab_mode) || ((hab_mode) && (mode != AFSK)))
strcat(str, tlm_str); strcat(str, tlm_str);
} }
#ifdef HAB } else { // APRS
if (mode == AFSK) { //#ifdef HAB
sprintf(tlm_str, "BAT %4.2f %5.1f ", batteryVoltage, batteryCurrent); // if ((mode == AFSK) && (hab_mode)) {
// sprintf(tlm_str, "BAT %4.2f %5.1f ", batteryVoltage, batteryCurrent);
sprintf(tlm_str, "BAT %4.2f %5.1f ", voltage[map[BAT]] , current[map[BAT]] );
strcat(str, tlm_str); strcat(str, tlm_str);
} // } else
#endif // strcat(str, tlm_str); // Is this needed???
}
//#endif
// read payload sensor if available // read payload sensor if available
/* /*
char sensor_payload[500]; char sensor_payload[500];
@ -1175,7 +1268,11 @@ void get_tlm(void) {
strcat(str, footer_str1); strcat(str, footer_str1);
// strcat(str, call); // strcat(str, call);
strcat(str, footer_str); if (battery_saver_mode == ON)
strcat(str, footer_str); // add extra packet for rpitx transmission
else
strcat(str, footer_str2);
fprintf(stderr, "String to execute: %s\n", str); fprintf(stderr, "String to execute: %s\n", str);
printf("\n\nTelemetry string is %s \n\n", str); printf("\n\nTelemetry string is %s \n\n", str);
@ -1543,9 +1640,10 @@ void get_tlm_fox() {
char count_string[10]; char count_string[10];
if ( (fgets(count_string, 10, command_count_file)) != NULL) if ( (fgets(count_string, 10, command_count_file)) != NULL)
groundCommandCount = atoi(count_string); groundCommandCount = atoi(count_string);
fclose(command_count_file);
} else } else
printf("Error opening command_count.txt!\n"); printf("Error opening command_count.txt!\n");
fclose(command_count_file);
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 +
@ -2205,8 +2303,27 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600
// mySerial.println("AT+DMOSETGROUP=0,144.3900,144.3900,0,3,0,0\r"); // can change to 144.39 for standard APRS // mySerial.println("AT+DMOSETGROUP=0,144.3900,144.3900,0,3,0,0\r"); // can change to 144.39 for standard APRS
// mySerial.println("AT+DMOSETGROUP=0,145.0000,145.0000,0,3,0,0\r"); // can change to 145 for testing ASPRS // mySerial.println("AT+DMOSETGROUP=0,145.0000,145.0000,0,3,0,0\r"); // can change to 145 for testing ASPRS
//#else //#else
char uhf_string[] = "AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n"; char uhf_string[] = "AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n";
serialPrintf(uart_fd, uhf_string); char uhf_string1a[] = "AT+DMOSETGROUP=0,"; // changed frequency to verify
char comma[] = ",";
char uhf_string1b[] = ",0,"; // changed frequency to verify
char uhf_string1[] = "AT+DMOSETGROUP=0,435.0000,434.9000,0,"; // changed frequency to verify
char uhf_string2[] = ",0,0\r\n";
char sq_string[2];
sq_string[0] = '0' + squelch;
sq_string[1] = 0;
// serialPrintf(uart_fd, uhf_string);
/**/
serialPrintf(uart_fd, uhf_string1a);
serialPrintf(uart_fd, rx);
serialPrintf(uart_fd, comma);
serialPrintf(uart_fd, tx);
serialPrintf(uart_fd, uhf_string1b);
serialPrintf(uart_fd, sq_string);
serialPrintf(uart_fd, uhf_string2);
/**/
// mySerial.println("AT+DMOSETGROUP=0,435.1000,434.9900,0,3,0,0\r"); // squelch set to 3 // mySerial.println("AT+DMOSETGROUP=0,435.1000,434.9900,0,3,0,0\r"); // squelch set to 3
//#endif //#endif
sleep(1); sleep(1);
@ -2230,3 +2347,52 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600
serialClose(uart_fd); serialClose(uart_fd);
} }
int battery_saver_check() {
FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r");
if (file == NULL) {
fprintf(stderr,"Battery saver mode is OFF!\n");
return(OFF);
}
fclose(file);
fprintf(stderr,"Battery saver mode is ON!\n");
return(ON);
}
void battery_saver(int setting) {
if (setting == ON) {
if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) {
if (battery_saver_check() == OFF) {
FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r");
pclose(command);
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);
command = popen("sudo reboot now", "r");
pclose(command);
sleep(60);
return;
} else
fprintf(stderr, "Nothing to do for battery_saver\n");
}
} else if (setting == OFF) {
if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) {
if (battery_saver_check() == ON) {
FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r");
pclose(command);
fprintf(stderr,"Turning Battery saver mode OFF\n");
// command = popen("sudo sed -i ':a;N;$!ba;s/\'$'\n''force_turbo=1//g' /boot/config.txt", "r");
// pclose(command);
command = popen("sudo reboot now", "r");
pclose(command);
sleep(60);
return;
} else
fprintf(stderr, "Nothing to do for battery_saver\n");
}
} else {
fprintf(stderr,"battery_saver function error");
return;
}
return;
}

@ -54,6 +54,7 @@
#define OFF - 1 #define OFF - 1
#define ON 1 #define ON 1
#define CHECK 0
uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET;
uint8_t data[1024]; uint8_t data[1024];
@ -123,6 +124,9 @@ float uptime_sec = 0;
long int uptime; long int uptime;
char call[5]; char call[5];
char sim_yes[10]; char sim_yes[10];
char hab_yes[10];
int squelch = 3; // default squelch
char rx[12], tx[12];
int bitRate, mode, bufLen, rsFrames, payloads, rsFrameLen, dataLen, headerLen, syncBits, syncWord, parityLen, samples, frameCnt, samplePeriod; int bitRate, mode, bufLen, rsFrames, payloads, rsFrameLen, dataLen, headerLen, syncBits, syncWord, parityLen, samples, frameCnt, samplePeriod;
float sleepTime; float sleepTime;
@ -173,3 +177,8 @@ int end_flag_detected = FALSE;
int jpeg_start = 0; int jpeg_start = 0;
#define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds #define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds
void battery_saver(int setting);
int battery_saver_check();
int hab_mode = FALSE;
int battery_saver_mode = FALSE;

@ -9,7 +9,19 @@ from time import sleep
import sys import sys
from os import system from os import system
from PIL import Image, ImageDraw, ImageFont, ImageColor from PIL import Image, ImageDraw, ImageFont, ImageColor
import serial
def battery_saver_check():
try:
global txc
f = open("/home/pi/CubeSatSim/battery_saver", "r")
f.close()
txc = False
print("battery saver activated")
except:
print("not activated")
# txc = True
def increment_mode(): def increment_mode():
print("increment mode") print("increment mode")
powerPin = 16 powerPin = 16
@ -20,6 +32,7 @@ def increment_mode():
# mode = "f" # mode = "f"
if (debug_mode == 1): if (debug_mode == 1):
print("Can't open .mode file") # , defaulting to FSK") print("Can't open .mode file") # , defaulting to FSK")
file.close()
print("Mode is: ") print("Mode is: ")
print(mode) print(mode)
if (mode == 'a'): if (mode == 'a'):
@ -98,7 +111,7 @@ def increment_mode():
try: try:
file = open("/home/pi/CubeSatSim/.mode", "w") file = open("/home/pi/CubeSatSim/.mode", "w")
# count_string = str(command_count) count_string = str(command_count)
file.write(mode) file.write(mode)
file.close() file.close()
print(".mode file written") print(".mode file written")
@ -109,9 +122,14 @@ def increment_mode():
print("sudo reboot -h now") print("sudo reboot -h now")
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setup(powerPin, GPIO.OUT) GPIO.setup(powerPin, GPIO.OUT)
GPIO.output(powerPin, 0); GPIO.output(powerPin, 0);
system("reboot -h now") # system("reboot -h now")
# release = True; # release = True;
print("Changing mode now")
# system("/home/pi/CubeSatSim/config -" + mode)
system("reboot -h now")
sleep(10); sleep(10);
except: except:
print("can't write to .mode file") print("can't write to .mode file")
@ -121,7 +139,7 @@ print("CubeSatSim v1.3b rpitx.py starting...")
pd = 21 pd = 21
ptt = 20 ptt = 20
txc = 7 txc_pin = 7
squelch = 6 squelch = 6
green = 16 green = 16
@ -132,7 +150,7 @@ GPIO.setwarnings(False)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(txc_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(green, GPIO.OUT) GPIO.setup(green, GPIO.OUT)
GPIO.setup(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected GPIO.setup(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected
@ -183,21 +201,25 @@ GPIO.setup(ptt, GPIO.OUT)
output (ptt, 1) output (ptt, 1)
txc = False txc = False
if GPIO.input(7) == False: if GPIO.input(txc_pin) == False:
print("TXC is present") print("TXC is present")
txc = True; txc = True;
else: else:
print("TXC not present") print("TXC not present")
# txc = False # forcing it off
output(txLed, txLedOn) output(txLed, txLedOn)
sleep(1) sleep(1)
output(txLed, txLedOff) output(txLed, txLedOff)
battery_saver_check()
# print(txLedOn) # print(txLedOn)
print(txLed) print(txLed)
# GPIO.setup(27, GPIO.OUT) # GPIO.setup(27, GPIO.OUT)
# GPIO.output(27, 0) # GPIO.output(27, 0)
debug_mode = 1 debug_mode = 0 #no debugging rpitx
if __name__ == "__main__": if __name__ == "__main__":
@ -249,14 +271,67 @@ if __name__ == "__main__":
try: try:
file = open("/home/pi/CubeSatSim/sim.cfg") file = open("/home/pi/CubeSatSim/sim.cfg")
callsign = file.readline().split(" ")[0] # callsign = file.readline().split(" ")[0]
config = file.readline().split()
callsign = config[0]
if len(config) > 5:
sq = config[5]
else:
sq = '0'
if len(config) > 6:
# tx = config[6]
txf = float(config[6])
print(txf)
# print( "{:.4f}".format(txf))
tx = "{:.4f}".format(txf)
print(tx)
else:
tx = '434.9000'
if len(config) > 7:
# rx = config[7]
rxf = float(config[7])
print(rxf)
# print( "{:.4f}".format(rxf))
rx = "{:.4f}".format(rxf)
print(rx)
else:
rx = '435.0000'
print(config)
print
# print(callsign)
print(sq)
if sq == '8':
print("squelch set to 8, no command input!")
no_command = True
else:
no_command = False
print(no_command)
except: except:
callsign = "AMSAT" callsign = "AMSAT"
if (debug_mode == 1): if (debug_mode == 1):
print("Can't read callsign from sim.cfg file, defaulting to AMSAT") print("Can't read callsign from sim.cfg file, defaulting to AMSAT")
file.close()
print(callsign) print(callsign)
GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4 GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4
GPIO.setup(txLed, GPIO.OUT) GPIO.setup(txLed, GPIO.OUT)
print("Programming FM module!\n");
output(pd, 1)
output (ptt, 1)
try:
ser = serial.Serial("/dev/ttyAMA0", 9600)
print(ser.portstr)
uhf_string = "AT+DMOSETGROUP=0," + rx +"," + tx + ",0,3,0,0\r\n"
for i in range(6):
# ser.write(b"AT+DMOSETGROUP=0,435.0000,434.9000,0,3,0,0\r\n")
ser.write(uhf_string.encode())
sleep(0.1)
except:
print("Error in serial write")
ser.close()
output(pd, 0)
sleep(10) # delay so cubesatsim code catches up sleep(10) # delay so cubesatsim code catches up
@ -264,23 +339,26 @@ if __name__ == "__main__":
# if (mode != 'a') and (command_tx == True): # if (mode != 'a') and (command_tx == True):
if (command_tx == True): if (command_tx == True):
output(pd, 1) # battery_saver_mode
output (ptt, 0) output(txLed, txLedOn)
output(txLed, txLedOn)
sleep(0.1)
if (txc): if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") output(pd, 1)
output (ptt, 0)
sleep(0.1)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
sleep(0.1)
output (ptt, 1)
output(pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 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 && 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 434.9e3") # 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 && 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 434.9e3")
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 && 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: else:
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 && 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 434.9e3 > /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 && 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 434.9e3 > /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 && 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(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
sleep(1) sleep(1)
else: else:
print("Don't transmit CW ID since command_tx is False or APRS mode") print("Don't transmit CW ID since command_tx is False or APRS mode")
@ -292,7 +370,7 @@ if __name__ == "__main__":
# if (len(sys.argv)) > 1: # if (len(sys.argv)) > 1:
# print("There are arguments!") # print("There are arguments!")
if (mode == 'a'): if (mode == 'a'):
output(pd, 1) # output(pd, 1)
print("AFSK") print("AFSK")
# sleep(5) # sleep(5)
## try: ## try:
@ -303,6 +381,7 @@ if __name__ == "__main__":
while True: while True:
try: try:
f = open("/home/pi/CubeSatSim/ready") f = open("/home/pi/CubeSatSim/ready")
f.close()
if (debug_mode == 1): if (debug_mode == 1):
print("Packet ready!") print("Packet ready!")
system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1") system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1")
@ -310,23 +389,32 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
# output(pd, 1) # output(pd, 1)
output (ptt, 0) # output (ptt, 0)
sleep(.1) # sleep(.1)
#
# battery_saver_check()
if (txc): if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav") output(pd, 1)
output (ptt, 0)
sleep(0.2) # add more time at start
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav")
sleep(0.1)
output (ptt, 1)
output(pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 1):
system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3")
else: else:
system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1")
sleep(0.1) sleep(0.1)
output (ptt, 1) # output (ptt, 1)
# output(pd, 0) # output(pd, 0)
output(txLed, txLedOff) output(txLed, txLedOff)
system("sudo rm /home/pi/CubeSatSim/ready") system("sudo rm /home/pi/CubeSatSim/ready")
f.close() f.close()
output(pd, 1)
output(ptt, 1)
sleep(1) sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
@ -359,7 +447,8 @@ if __name__ == "__main__":
system("echo > command_tx False") system("echo > command_tx False")
else: else:
print("No carrier received!") print("No carrier received!")
output(pd, 0)
if (debug_mode == 1): if (debug_mode == 1):
print("Ready for next packet!") print("Ready for next packet!")
@ -379,21 +468,30 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
output (ptt, 0) # battery_saver_check()
sleep(0.1)
if (txc): 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") 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: else:
if (debug_mode == 1): 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 434.9e3") 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: 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 434.9e3 > /dev/null 2>&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 > /dev/null 2>&1")
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
sleep(5) sleep(5)
while True: while True:
output(pd, 1)
output(ptt, 1)
sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
# command_tx = not command_tx # command_tx = not command_tx
@ -424,8 +522,11 @@ if __name__ == "__main__":
print("Turning off transmit") print("Turning off transmit")
system("echo > command_tx False") system("echo > command_tx False")
sleep(5) sleep(5)
output(pd, 0)
try: try:
f = open("/home/pi/CubeSatSim/cwready") 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("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") system("sudo rm /home/pi/CubeSatSim/cwready")
@ -433,14 +534,15 @@ if __name__ == "__main__":
output(txLed, txLedOn) output(txLed, txLedOn)
output (ptt, 0) output (ptt, 0)
sleep(0.1) sleep(0.1)
# battery_saver_check()
if (txc): if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
else: else:
if (debug_mode == 1): 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 434.9e3") 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: 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 434.9e3 > /dev/null 2>&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 > /dev/null 2>&1")
sleep(0.1) sleep(0.1)
output(txLed, txLedOff) output(txLed, txLedOff)
@ -459,7 +561,8 @@ if __name__ == "__main__":
# camera = PiCamera() # camera = PiCamera()
print("Testing for camera") print("Testing for camera")
system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256") system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256")
f = open("/home/pi/CubeSatSim/camera_out.jpg") f = open("/home/pi/CubeSatSim/camera_out.jpg")
f.close()
print("Camera present") print("Camera present")
camera_present = 1 camera_present = 1
# camera.close() # camera.close()
@ -470,8 +573,8 @@ if __name__ == "__main__":
# while 1: # while 1:
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
output(pd, 0) # output(pd, 0)
if (camera_present == 1): if (camera_present == 1):
try: try:
file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg")
@ -481,20 +584,22 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
print ("Sending SSTV image") print ("Sending SSTV image")
output(txLed, txLedOn) output(txLed, txLedOn)
output(pd, 1) # battery_saver_check()
output (ptt, 0)
if (txc): if (txc):
output(pd, 1)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav")
output (ptt, 1)
output(pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 1):
system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3")
else: else:
system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1")
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
# sleep(1) # sleep(1)
except: except:
print("image 2 did not load - copy from CubeSatSim/sstv directory") print("image 2 did not load - copy from CubeSatSim/sstv directory")
@ -529,6 +634,7 @@ if __name__ == "__main__":
system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1")
output(pd, 1) output(pd, 1)
output(ptt, 1)
sleep(1) sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
@ -564,21 +670,24 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
print ("Sending SSTV image") print ("Sending SSTV image")
output(txLed, txLedOn) output(txLed, txLedOn)
output(pd, 1) # battery_saver_check()
output (ptt, 0)
if (txc): if (txc):
output(pd, 1)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav")
output(ptt, 1)
output (pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 1):
system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3")
else: else:
system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1")
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
output(pd, 0) # output(pd, 0)
system("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1")
sleep(1) sleep(1)
else: else:
@ -590,20 +699,24 @@ if __name__ == "__main__":
print ("Sending SSTV image") print ("Sending SSTV image")
output(txLed, txLedOn) output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0) # battery_saver_check()
if (txc): if (txc):
output(pd, 1)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
output(ptt, 1)
output (pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 1):
system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3")
else: else:
system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1")
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
output(pd, 0) # output(pd, 0)
sleep(1) sleep(1)
except: except:
print("image 1 did not load - copy from CubeSatSim/sstv directory") print("image 1 did not load - copy from CubeSatSim/sstv directory")
@ -614,6 +727,7 @@ if __name__ == "__main__":
while 1: while 1:
output(pd, 1) output(pd, 1)
output(ptt, 1)
sleep(1) sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
@ -648,41 +762,47 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
print ("Sending SSTV image") print ("Sending SSTV image")
output(txLed, txLedOn) output(txLed, txLedOn)
output(pd, 1) # battery_saver_check()
output (ptt, 0)
if (txc): if (txc):
output(pd, 1)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
output(ptt, 1)
output (pd, 0)
else: else:
if (debug_mode == 1): if (debug_mode == 1):
system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3")
else: else:
system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1")
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
output(pd, 0) # output(pd, 0)
sleep(5) sleep(5)
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 434.9e3 &") 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: while 1:
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
output(pd, 1) # battery_saver_check()
output (ptt, 0)
if (txc): if (txc):
output(pd, 1)
output (ptt, 0)
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav") system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav")
output(ptt, 1)
output (pd, 0)
else: else:
sleep(60) sleep(60)
output(txLed, txLedOff) output(txLed, txLedOff)
output (ptt, 1) # output (ptt, 1)
output(pd, 0) # output(pd, 0)
sleep(1) sleep(1)
elif (mode == 'b'): elif (mode == 'b'):
print("BPSK") print("BPSK")
@ -690,7 +810,8 @@ if __name__ == "__main__":
output(pd, 1) output(pd, 1)
output(ptt, 1) output(ptt, 1)
if (command_tx == True): if (command_tx == True):
system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float &") # system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float &")
system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f " + tx + "e6 -t float &")
print("Turning LED on/off and listening for carrier") print("Turning LED on/off and listening for carrier")
while 1: while 1:
output(txLed, txLedOff) output(txLed, txLedOff)
@ -699,6 +820,9 @@ if __name__ == "__main__":
# output(txLed, txLedOn) # output(txLed, txLedOn)
# sleep(0.03) # sleep(0.03)
# output(txLed, txLedOff) # output(txLed, txLedOff)
output(pd, 1)
output(ptt, 1)
sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
# command_tx = not command_tx # command_tx = not command_tx
@ -722,13 +846,15 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
print("Turning on transmit") print("Turning on transmit")
system("echo > command_tx True") system("echo > command_tx True")
system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float &") system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f " + tx + "e6 -t float &")
else: else:
print("Turning off transmit") # and rebooting") print("Turning off transmit") # and rebooting")
system("echo > command_tx False") system("echo > command_tx False")
system("sudo systemctl restart rpitx") system("sudo systemctl restart rpitx")
# system("sudo reboot now") # system("sudo reboot now")
sleep(60) sleep(60)
output(pd, 0)
if (command_tx == True): if (command_tx == True):
output(txLed, txLedOn) output(txLed, txLedOn)
sleep(4.0) sleep(4.0)
@ -738,7 +864,7 @@ if __name__ == "__main__":
output(pd, 1) output(pd, 1)
output(ptt, 1) output(ptt, 1)
if (command_tx == True): if (command_tx == True):
system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 &") system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 &")
print("Turning LED on/off and listening for carrier") print("Turning LED on/off and listening for carrier")
while 1: while 1:
output(txLed, txLedOff) output(txLed, txLedOff)
@ -747,6 +873,9 @@ if __name__ == "__main__":
# output(txLed, txLedOn) # output(txLed, txLedOn)
# sleep(0.03) # sleep(0.03)
# output(txLed, txLedOff) # output(txLed, txLedOff)
output(pd, 1)
output(ptt, 1)
sleep(1)
if (no_command == False and GPIO.input(squelch) == False): if (no_command == False and GPIO.input(squelch) == False):
print("carrier received!") print("carrier received!")
# command_tx = not command_tx # command_tx = not command_tx
@ -770,7 +899,7 @@ if __name__ == "__main__":
if (command_tx == True): if (command_tx == True):
print("Turning on transmit") print("Turning on transmit")
system("echo > command_tx True") system("echo > command_tx True")
system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 &") system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 &")
else: else:
print("Turning of transmit and rebooting") print("Turning of transmit and rebooting")
system("echo > command_tx False") system("echo > command_tx False")

@ -113,7 +113,7 @@ void setup() {
// otherwise, run CubeSatSim Pico code // otherwise, run CubeSatSim Pico code
Serial.println("CubeSatSim Pico Payload v0.2 starting...\n"); Serial.println("CubeSatSim Pico Payload v0.3 starting...\n");
/**/ /**/
if (check_for_wifi()) { if (check_for_wifi()) {
@ -157,6 +157,9 @@ void loop() {
} }
void config_gpio() { void config_gpio() {
pinMode(0, INPUT);
pinMode(1, INPUT);
// set all Pico GPIO connected pins to input // set all Pico GPIO connected pins to input
for (int i = 6; i < 22; i++) { for (int i = 6; i < 22; i++) {
@ -459,13 +462,13 @@ void payload_OK_only()
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
Serial.print(" XS2 "); Serial.print(" GPS ");
Serial.print(Sensor1,4); Serial.print(Sensor1,4);
Serial.print(" "); Serial.print(" ");
Serial.print(Sensor2,4); Serial.print(Sensor2,4);
Serial.print(" "); Serial.print(" ");
Serial.print(Sensor3,2); Serial.print(Sensor3,2);
Serial.print(" MQ "); Serial.print(" AN ");
Serial.println(sensorValue); // ,0); Serial.println(sensorValue); // ,0);
if (mpuPresent) { if (mpuPresent) {
@ -607,13 +610,13 @@ void payload_OK_only()
//Serial.println(sensorValue); //Serial.println(sensorValue);
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
Serial1.print(" XS2 "); Serial1.print(" GPS ");
Serial1.print(Sensor1,4); Serial1.print(Sensor1,4);
Serial1.print(" "); Serial1.print(" ");
Serial1.print(Sensor2,4); Serial1.print(Sensor2,4);
Serial1.print(" "); Serial1.print(" ");
Serial1.print(Sensor3,2); Serial1.print(Sensor3,2);
Serial1.print(" MQ "); Serial1.print(" AN ");
Serial1.print(sensorValue); //,0); Serial1.print(sensorValue); //,0);
// Serial1.println("END_FLAG"); // Serial1.println("END_FLAG");
Serial1.println(sensor_end_flag); Serial1.println(sensor_end_flag);

@ -26,7 +26,7 @@ sudo sed -i 's/console=tty1 r/console=tty1 maxcpus=1 r/g' /boot/cmdline.txt # si
cd /home/pi/CubeSatSim cd /home/pi/CubeSatSim
git pull > .updated git pull --no-rebase > .updated
make debug make debug
@ -135,7 +135,7 @@ cd /home/pi/pi-power-button
# git checkout reboot-mode-change # git checkout reboot-mode-change
git pull > .updated_p git pull --no-rebase > .updated_p
grep 'changed' /home/pi/pi-power-button/.updated_p grep 'changed' /home/pi/pi-power-button/.updated_p
if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then
@ -143,20 +143,22 @@ git pull > .updated_p
echo "updating pi-power-button." echo "updating pi-power-button."
script/install script/install
FLAG=1
echo "You need to reboot to complete this update. Reboot now (y/n)?" # echo "You need to reboot to complete this update. Reboot now (y/n)?"
read -r ANS # read -r ANS
if [ "$ANS" = "y" ]; then # if [ "$ANS" = "y" ]; then
sudo reboot now # sudo reboot now
else # else
echo "The CubeSatSim software may not work correctly until you reboot." # echo "The CubeSatSim software may not work correctly until you reboot."
fi # fi
else else
echo "nothing to do for pi-power-button." echo "nothing to do for pi-power-button."
@ -186,7 +188,7 @@ git pull > .updated_p
FLAG=1 FLAG=1
cd /home/pi/pi-power-button cd /home/pi/pi-power-button
git pull git pull --no-rebase
git checkout reboot-mode-change git checkout reboot-mode-change
script/install script/install
@ -212,6 +214,11 @@ git pull > .updated_p
FLAG=1 FLAG=1
fi fi
if ! grep -q force_turbo=1 /boot/config.txt ; then
sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'
FLAG=1
fi
#if [ ! -f "/home/pi/CubeSatSim/telem_string.txt" ]; then #if [ ! -f "/home/pi/CubeSatSim/telem_string.txt" ]; then
# sudo apt-get update && sudo apt-get dist-upgrade -y # sudo apt-get update && sudo apt-get dist-upgrade -y
@ -222,6 +229,31 @@ git pull > .updated_p
#fi #fi
changed=0
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
if [ -z "$1" ] ; then n1="AMSAT" ; changed=1 ; else n1=$1 ; fi # callsign
if [ -z "$2" ] ; then n2="0" ; changed=1 ; else n2=$2 ; fi # reset count
if [ -z "$3" ] ; then n3="0" ; changed=1 ; else n3=$3 ; fi # lat
if [ -z "$4" ] ; then n4="0" ; changed=1 ; else n4=$4 ; fi # lon
if [ -z "$5" ] ; then n5="no" ; changed=1 ; else n5=$5 ; fi # sim mode
if [ -z "$6" ] ; then n6="3" ; changed=1 ; else n6=$6 ; fi # squelch
if [ -z "$7" ] ; then n7="434.9000" ; changed=1 ; else n7=$7 ; fi # transmit frequency
if [ -z "$8" ] ; then n8="436.0000" ; changed=1 ; else n8=$8 ; fi # receive frequency
if [ -z "$9" ] ; then n9="no" ; changed=1 ; else n9=$9 ; fi # hab mode
if [ $changed -eq 1 ]; then
echo -e "Current sim.cfg configuration file:"
echo
echo $1 $2 $3 $4 $5 $6 $7 $8 $9
echo -e "\nCubeSatSim configuraation sim.cfg file updated to: \n"
echo
echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9
echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 > /home/pi/CubeSatSim/sim.cfg
echo
fi
if [ $FLAG -eq 1 ]; then if [ $FLAG -eq 1 ]; then
echo "systemctl daemon-reload and reboot" echo "systemctl daemon-reload and reboot"

Loading…
Cancel
Save

Powered by TurnKey Linux.