From a586edb110a66441926093c805cc94c622bca5f5 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 13 Oct 2023 20:28:34 -0400 Subject: [PATCH 01/77] Update rpitx.py add battery_saver_check each transmit --- rpitx.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index ca21fe4f..2986b35d 100644 --- a/rpitx.py +++ b/rpitx.py @@ -10,6 +10,12 @@ import sys from os import system from PIL import Image, ImageDraw, ImageFont, ImageColor +def battery_saver_check(): + try: + f = open("/home/pi/CubeSatSim/battery_saver") + close(f) + txc = False + def increment_mode(): print("increment mode") powerPin = 16 @@ -191,6 +197,7 @@ else: output(txLed, txLedOn) sleep(1) output(txLed, txLedOff) +battery_saver_check() # print(txLedOn) print(txLed) @@ -269,6 +276,7 @@ if __name__ == "__main__": output(txLed, txLedOn) sleep(0.1) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") else: @@ -312,7 +320,8 @@ if __name__ == "__main__": # output(pd, 1) output (ptt, 0) sleep(.1) - + + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav") else: @@ -381,6 +390,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output (ptt, 0) sleep(0.1) + battery_saver_check() if (txc): 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") @@ -433,6 +443,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output (ptt, 0) sleep(0.1) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") @@ -483,6 +494,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output(pd, 1) output (ptt, 0) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav") @@ -566,6 +578,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output(pd, 1) output (ptt, 0) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") @@ -592,6 +605,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output(pd, 1) output (ptt, 0) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") @@ -650,6 +664,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output(pd, 1) output (ptt, 0) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") @@ -674,6 +689,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output(pd, 1) output (ptt, 0) + battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav") From c3413618580a6dac797b2a8e50279b3644ef9287 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 13 Oct 2023 20:36:38 -0400 Subject: [PATCH 02/77] Update rpitx.py typo --- rpitx.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rpitx.py b/rpitx.py index 2986b35d..1fa19acf 100644 --- a/rpitx.py +++ b/rpitx.py @@ -15,6 +15,7 @@ def battery_saver_check(): f = open("/home/pi/CubeSatSim/battery_saver") close(f) txc = False + except: def increment_mode(): print("increment mode") From eda4fac4499e6ee683f95391a83a45a2c1557e7b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 13 Oct 2023 20:39:13 -0400 Subject: [PATCH 03/77] Update rpitx.py added pass --- rpitx.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rpitx.py b/rpitx.py index 1fa19acf..e624b772 100644 --- a/rpitx.py +++ b/rpitx.py @@ -16,6 +16,7 @@ def battery_saver_check(): close(f) txc = False except: + pass def increment_mode(): print("increment mode") From 1691bee15c1e8f6ca1e1b0b19c5a04ce48bf39fe Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 13 Oct 2023 20:47:44 -0400 Subject: [PATCH 04/77] Update rpitx.py with prints --- rpitx.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpitx.py b/rpitx.py index e624b772..887cd7ed 100644 --- a/rpitx.py +++ b/rpitx.py @@ -15,7 +15,9 @@ def battery_saver_check(): f = open("/home/pi/CubeSatSim/battery_saver") close(f) txc = False + print("battery saver activated") except: + print("not activated") pass def increment_mode(): From fec17d51c0127ef24d81b5144e58c5a16b22be7d Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 13 Oct 2023 20:53:51 -0400 Subject: [PATCH 05/77] Update rpitx.py remove close --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 887cd7ed..57466e96 100644 --- a/rpitx.py +++ b/rpitx.py @@ -13,7 +13,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor def battery_saver_check(): try: f = open("/home/pi/CubeSatSim/battery_saver") - close(f) +# close(f) txc = False print("battery saver activated") except: From c41932c9b41a22de2bf483379f21f084d1d5666e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 09:18:03 -0400 Subject: [PATCH 06/77] Update rpitx.py changed to .close --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 57466e96..8754e9cb 100644 --- a/rpitx.py +++ b/rpitx.py @@ -13,7 +13,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor def battery_saver_check(): try: f = open("/home/pi/CubeSatSim/battery_saver") -# close(f) + f.close() txc = False print("battery saver activated") except: From 4181561d651693c03b04df3127cfd6c52d08122f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 09:20:57 -0400 Subject: [PATCH 07/77] Update rpitx.py added global --- rpitx.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rpitx.py b/rpitx.py index 8754e9cb..96adeddc 100644 --- a/rpitx.py +++ b/rpitx.py @@ -12,6 +12,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor def battery_saver_check(): try: + global txc f = open("/home/pi/CubeSatSim/battery_saver") f.close() txc = False From f54751d2eeebe50606a49cbf75c5768e18e61ac0 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 09:32:09 -0400 Subject: [PATCH 08/77] Update rpitx.py txc true when off --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 96adeddc..954956b6 100644 --- a/rpitx.py +++ b/rpitx.py @@ -19,7 +19,7 @@ def battery_saver_check(): print("battery saver activated") except: print("not activated") - pass + txc = True def increment_mode(): print("increment mode") From 322f527e640e3966b3d1470890e24c2e9dbebf99 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 09:36:40 -0400 Subject: [PATCH 09/77] Update rpitx.py added rest of f.close --- rpitx.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 954956b6..6610b963 100644 --- a/rpitx.py +++ b/rpitx.py @@ -316,6 +316,7 @@ if __name__ == "__main__": while True: try: f = open("/home/pi/CubeSatSim/ready") + f.close() if (debug_mode == 1): print("Packet ready!") system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1") @@ -441,6 +442,7 @@ if __name__ == "__main__": sleep(5) try: f = open("/home/pi/CubeSatSim/cwready") + f.close() system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1") system("sudo rm /home/pi/CubeSatSim/cwready") @@ -475,7 +477,8 @@ if __name__ == "__main__": # camera = PiCamera() print("Testing for camera") 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") camera_present = 1 # camera.close() From fdaf62ee3c647232be8f7e4faf19654e967dceaa Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 15:10:08 -0400 Subject: [PATCH 10/77] Update rpitx.py not debugging rpitx --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 6610b963..1c20ffc8 100644 --- a/rpitx.py +++ b/rpitx.py @@ -209,7 +209,7 @@ print(txLed) # GPIO.setup(27, GPIO.OUT) # GPIO.output(27, 0) -debug_mode = 1 +debug_mode = 0 #no debugging rpitx if __name__ == "__main__": From d2d1658b04cbdfa54e3f41bc5e9a2028630b9961 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 15:21:08 -0400 Subject: [PATCH 11/77] Update rpitx.py force txc off --- rpitx.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rpitx.py b/rpitx.py index 1c20ffc8..a6959980 100644 --- a/rpitx.py +++ b/rpitx.py @@ -132,7 +132,7 @@ print("CubeSatSim v1.3b rpitx.py starting...") pd = 21 ptt = 20 -txc = 7 +txc_pin = 7 squelch = 6 green = 16 @@ -143,7 +143,7 @@ GPIO.setwarnings(False) GPIO.setup(13, 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(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(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected @@ -194,11 +194,13 @@ GPIO.setup(ptt, GPIO.OUT) output (ptt, 1) txc = False -if GPIO.input(7) == False: +if GPIO.input(txc_pin) == False: print("TXC is present") txc = True; else: print("TXC not present") + +txc = False # forcing it off output(txLed, txLedOn) sleep(1) output(txLed, txLedOff) From d65bdf7d28dccb82d0e3642bd3e90a3d3f5f60d4 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 16:51:39 -0400 Subject: [PATCH 12/77] Update rpitx.py use config to change modes --- rpitx.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/rpitx.py b/rpitx.py index a6959980..9a3907b0 100644 --- a/rpitx.py +++ b/rpitx.py @@ -108,21 +108,25 @@ def increment_mode(): sleep(2.5) try: - file = open("/home/pi/CubeSatSim/.mode", "w") +# file = open("/home/pi/CubeSatSim/.mode", "w") # count_string = str(command_count) - file.write(mode) - file.close() - print(".mode file written") +# file.write(mode) +# file.close() +# print(".mode file written") GPIO.setwarnings(False) GPIO.output(txLed, 0) GPIO.output(powerPin, 0) - print("sudo reboot -h now") +# print("sudo reboot -h now") GPIO.setwarnings(False) GPIO.setup(powerPin, GPIO.OUT) - GPIO.output(powerPin, 0); - system("reboot -h now") + GPIO.output(powerPin, 0); +# system("reboot -h now") # release = True; + + print("Changing mode now") + system("/home/pi/CubeSatSim/config -" + mode) + sleep(10); except: print("can't write to .mode file") From 650c46741395abb7b01f0563e45f8dac469aa5ef Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 17:06:55 -0400 Subject: [PATCH 13/77] Update config APRS setting based on battery saver mode --- config | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config b/config index 6dbc3742..ca0441de 100755 --- a/config +++ b/config @@ -68,7 +68,16 @@ if [ "$1" = "-i" ]; then elif [ "$1" = "-a" ]; then echo "changing CubeSatSim to AFSK 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 activated." + if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + else + echo "Not battery saver mode" + sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + fi + echo "rebooting" sudo reboot now # sudo systemctl restart cubesatsim From dcc3de2616a2af821db5c8e1d721848c0450b085 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 14 Oct 2023 18:55:28 -0400 Subject: [PATCH 14/77] Update rpitx.py turn of txc off forcing --- rpitx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpitx.py b/rpitx.py index 9a3907b0..a77d854c 100644 --- a/rpitx.py +++ b/rpitx.py @@ -19,7 +19,7 @@ def battery_saver_check(): print("battery saver activated") except: print("not activated") - txc = True +# txc = True def increment_mode(): print("increment mode") @@ -204,7 +204,7 @@ if GPIO.input(txc_pin) == False: else: print("TXC not present") -txc = False # forcing it off +# txc = False # forcing it off output(txLed, txLedOn) sleep(1) output(txLed, txLedOff) From 576ff98113268d4cf62dbb494c2fe2ff81992861 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 15 Oct 2023 09:00:05 -0400 Subject: [PATCH 15/77] Update rpitx.py debug mode back on --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index a77d854c..693b201c 100644 --- a/rpitx.py +++ b/rpitx.py @@ -215,7 +215,7 @@ print(txLed) # GPIO.setup(27, GPIO.OUT) # GPIO.output(27, 0) -debug_mode = 0 #no debugging rpitx +debug_mode = 1 #no debugging rpitx if __name__ == "__main__": From 725d384dbbe542e9576a99fc4f50163a6b498ca3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 10:22:43 -0500 Subject: [PATCH 16/77] Update config remove pin 18 func 2 for aprs battery saver --- config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config b/config index ca0441de..1814eabd 100755 --- a/config +++ b/config @@ -73,9 +73,11 @@ elif [ "$1" = "-a" ]; then if [ -f "$FILE" ]; then echo "Battery saver mode activated." if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt else echo "Not battery saver mode" sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi fi echo "rebooting" From 74bc31405d782c5112386f3fda86697e7889da09 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 16:12:27 -0500 Subject: [PATCH 17/77] Update config remove more from config.txt --- config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config b/config index 1814eabd..59021a5c 100755 --- a/config +++ b/config @@ -74,10 +74,12 @@ elif [ "$1" = "-a" ]; then echo "Battery saver mode activated." if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt + sudo sed -i ':a;N;$!ba;s/\ndtoverlay=audremap,enable_jack=on//g' /boot/config.txt else echo "Not battery saver mode" sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi + if ! grep -q dtoverlay=audremap,enable_jack=on /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'; fi fi echo "rebooting" From 84b81c563b0f603b1a3d6e84819a740f930fe5a4 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 16:32:07 -0500 Subject: [PATCH 18/77] Update rpitx.py don't activate FM module when txc False aprs --- rpitx.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rpitx.py b/rpitx.py index 693b201c..36227efe 100644 --- a/rpitx.py +++ b/rpitx.py @@ -282,24 +282,24 @@ if __name__ == "__main__": # if (mode != 'a') and (command_tx == True): if (command_tx == True): - output(pd, 1) - output (ptt, 0) - output(txLed, txLedOn) - sleep(0.1) - battery_saver_check() + output(txLed, txLedOn) 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: 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") 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") - sleep(0.1) output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) + sleep(1) else: print("Don't transmit CW ID since command_tx is False or APRS mode") From 3642fda98b0a930dc97066cb6d9c2e99a92371ec Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 16:38:56 -0500 Subject: [PATCH 19/77] Update rpitx.py fix aprs --- rpitx.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rpitx.py b/rpitx.py index 36227efe..1fd1996c 100644 --- a/rpitx.py +++ b/rpitx.py @@ -330,12 +330,18 @@ if __name__ == "__main__": if (command_tx == True): output(txLed, txLedOn) # output(pd, 1) - output (ptt, 0) - sleep(.1) +# output (ptt, 0) +# sleep(.1) battery_saver_check() if (txc): - system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav") + output(pd, 1) + output (ptt, 0) + sleep(0.1) + system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav") + sleep(0.1) + output (ptt, 1) + output(pd, 0) else: 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") @@ -343,7 +349,7 @@ if __name__ == "__main__": 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") sleep(0.1) - output (ptt, 1) +# output (ptt, 1) # output(pd, 0) output(txLed, txLedOff) system("sudo rm /home/pi/CubeSatSim/ready") From d9b03237699cdec8ec7bb3e76f72ed26d4fa97cc Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 16:44:57 -0500 Subject: [PATCH 20/77] Update rpitx.py fix sstv --- rpitx.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rpitx.py b/rpitx.py index 1fd1996c..a54a479b 100644 --- a/rpitx.py +++ b/rpitx.py @@ -512,12 +512,14 @@ if __name__ == "__main__": if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - output(pd, 1) - output (ptt, 0) battery_saver_check() 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") + output (ptt, 1) + output(pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") @@ -525,8 +527,7 @@ if __name__ == "__main__": 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") output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) + # sleep(1) except: print("image 2 did not load - copy from CubeSatSim/sstv directory") From 8ddce2131d9a9077ca1247bbe4060046ef7eafa2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 16:58:46 -0500 Subject: [PATCH 21/77] Update config fixed config aprs change --- config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config b/config index 59021a5c..74f13c52 100755 --- a/config +++ b/config @@ -73,13 +73,13 @@ elif [ "$1" = "-a" ]; then if [ -f "$FILE" ]; then echo "Battery saver mode activated." if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi - sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt - sudo sed -i ':a;N;$!ba;s/\ndtoverlay=audremap,enable_jack=on//g' /boot/config.txt +# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt +# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=audremap,enable_jack=on//g' /boot/config.txt else echo "Not battery saver mode" sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt - if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi - if ! grep -q dtoverlay=audremap,enable_jack=on /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'; fi +# if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi +# if ! grep -q dtoverlay=audremap,enable_jack=on /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'; fi fi echo "rebooting" From 19812e46c688330d96f3afdd7845de862c813cef Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Tue, 14 Nov 2023 17:20:03 -0500 Subject: [PATCH 22/77] Update rpitx.py more txc cleanup --- rpitx.py | 60 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/rpitx.py b/rpitx.py index a54a479b..d301e968 100644 --- a/rpitx.py +++ b/rpitx.py @@ -311,7 +311,7 @@ if __name__ == "__main__": # if (len(sys.argv)) > 1: # print("There are arguments!") if (mode == 'a'): - output(pd, 1) +# output(pd, 1) print("AFSK") # sleep(5) ## try: @@ -406,12 +406,17 @@ if __name__ == "__main__": if (command_tx == True): output(txLed, txLedOn) - output (ptt, 0) - sleep(0.1) battery_saver_check() if (txc): + output (pd, 1) + output (ptt, 0) + sleep(0.1) + system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") + sleep(0.1) + output (ptt, 1) + output (pd, 0) else: if (debug_mode == 1): system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") @@ -419,7 +424,7 @@ if __name__ == "__main__": 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") output(txLed, txLedOff) - output (ptt, 1) +# output (ptt, 1) sleep(5) while True: if (no_command == False and GPIO.input(squelch) == False): @@ -501,8 +506,8 @@ if __name__ == "__main__": # while 1: output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) +# output (ptt, 1) +# output(pd, 0) if (camera_present == 1): try: file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") @@ -597,12 +602,14 @@ if __name__ == "__main__": if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - output(pd, 1) - output (ptt, 0) battery_saver_check() if (txc): + output(pd, 1) + output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") + output(ptt, 1) + output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") @@ -610,9 +617,9 @@ if __name__ == "__main__": 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") 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") sleep(1) else: @@ -624,12 +631,15 @@ if __name__ == "__main__": print ("Sending SSTV image") output(txLed, txLedOn) - output(pd, 1) - output (ptt, 0) + battery_saver_check() 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") + output(ptt, 1) + output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") @@ -637,8 +647,8 @@ if __name__ == "__main__": 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") output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) +# output (ptt, 1) +# output(pd, 0) sleep(1) except: print("image 1 did not load - copy from CubeSatSim/sstv directory") @@ -678,17 +688,19 @@ if __name__ == "__main__": else: print("Turning off transmit") system("echo > command_tx False") - output(pd, 0) +# output(pd, 0) if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - output(pd, 1) - output (ptt, 0) battery_saver_check() 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") + output(ptt, 1) + output (pd, 0) else: if (debug_mode == 1): system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") @@ -696,8 +708,8 @@ if __name__ == "__main__": 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") output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) +# output (ptt, 1) +# output(pd, 0) sleep(5) except: print("image 2 did not load - copy from CubeSatSim/sstv directory") @@ -708,18 +720,20 @@ if __name__ == "__main__": if (command_tx == True): output(txLed, txLedOn) - output(pd, 1) - output (ptt, 0) battery_saver_check() if (txc): + output(pd, 1) + output (ptt, 0) system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav") + output(ptt, 1) + output (pd, 0) else: sleep(60) output(txLed, txLedOff) - output (ptt, 1) - output(pd, 0) +# output (ptt, 1) +# output(pd, 0) sleep(1) elif (mode == 'b'): print("BPSK") From 0fbbac2e5c88df138c0be5e5d97dc0f5559b8942 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 17:41:03 -0500 Subject: [PATCH 23/77] Update main.c added extra echo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 41dc7d9f..35088460 100644 --- a/main.c +++ b/main.c @@ -992,7 +992,7 @@ void get_tlm(void) { // char footer_str1[] = "\' > t.txt && echo \'"; char footer_str1[] = "\' > t.txt"; // char footer_str[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py - char footer_str[] = " && 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 if (ax5043) { strcpy(str, header_str); From 48314e65f62dde3c59e77d06f7ac2bd554be8db3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 22:29:11 -0500 Subject: [PATCH 24/77] Update config manual battery saver, change modes a,s,m --- config | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/config b/config index 74f13c52..40ea295d 100755 --- a/config +++ b/config @@ -73,13 +73,9 @@ elif [ "$1" = "-a" ]; then if [ -f "$FILE" ]; then echo "Battery saver mode activated." if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi -# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt -# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=audremap,enable_jack=on//g' /boot/config.txt else echo "Not battery saver mode" sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt -# if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi -# if ! grep -q dtoverlay=audremap,enable_jack=on /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'; fi fi echo "rebooting" @@ -89,7 +85,15 @@ elif [ "$1" = "-a" ]; then elif [ "$1" = "-m" ]; then echo "changing CubeSatSim to CW 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 activated." + if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + else + echo "Not battery saver mode" + sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + fi echo "rebooting" sudo reboot now # sudo systemctl restart cubesatsim @@ -113,7 +117,15 @@ elif [ "$1" = "-b" ]; then elif [ "$1" = "-s" ]; then echo "changing CubeSatSim to SSTV 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 activated." + if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + else + echo "Not battery saver mode" + sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + fi echo "rebooting" sudo reboot now # sudo systemctl restart cubesatsim @@ -138,6 +150,7 @@ elif [ "$1" = "-h" ]; then echo " -C Clear logs" echo " -T Change command state" echo " -R Change the Commands Count in the file command_count.txt" + echo " -B Change battery saver mode manually" echo exit @@ -433,6 +446,40 @@ elif [ "$1" = "-R" ]; then else echo "Commands count not reset" 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 activated." + mode=1 + else + echo "Battery saver mode is not activated." + 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 + +# sudo systemctl restart cubesatsim + fi # sudo systemctl restart cubesatsim From a3e849c11d6092d50512e8315d920b537f0ff4f3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 22:41:38 -0500 Subject: [PATCH 25/77] Update main.h add battery_saver function --- main.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.h b/main.h index 6a9057dc..bb7bd4ff 100644 --- a/main.h +++ b/main.h @@ -173,3 +173,5 @@ int end_flag_detected = FALSE; int jpeg_start = 0; #define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds +int battery_saver(); + From 63d307423d78d0693414b255dc8794a86d24f45c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 22:44:41 -0500 Subject: [PATCH 26/77] Update main.h add CHECK --- main.h | 1 + 1 file changed, 1 insertion(+) diff --git a/main.h b/main.h index bb7bd4ff..4735427c 100644 --- a/main.h +++ b/main.h @@ -54,6 +54,7 @@ #define OFF - 1 #define ON 1 +#define CHECK 0 uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; uint8_t data[1024]; From 76f300541fc90c4364691b5b15b0af3f551b056b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 22:56:05 -0500 Subject: [PATCH 27/77] Update main.c add battery_saver function --- main.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 35088460..2140cb91 100644 --- a/main.c +++ b/main.c @@ -816,8 +816,14 @@ int main(int argc, char * argv[]) { // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V /**/ -#ifndef HAB - if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. +#ifndef HAB + if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) + { + battery_saver(ON); + } else if ((battery_saver(CHECK)) && (batteryCurrent < 0)) + { + battery_saver(OFF); + } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_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); digitalWrite(txLed, txLedOff); @@ -2230,3 +2236,34 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600 serialClose(uart_fd); } + +int battery_saver(int setting) { + if (setting == CHECK) { + *FILE file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); + if (file == NULL) { + printf("Battery saver mode is OFF\n"); + fclose(file); + return(0); + } + fclose(file); + printf("Battery saver mode is ON\n"); + return(1); + + } else if (setting == ON) { + FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); + pclose(command); + printf("Turning Battery saver mode ON\n"); + return(1); + + } else if (setting == OFF) { + FILE *command = popen("sudo rm /home/pi/CubeSatSim/battery_saver", "r"); + pclose(command); + printf("Turning Battery saver mode OFF\n"); + return(1); + + } else { + printf("battery_saver function error"); + return(0); + } + return(2); +} From 5f39728cb3fbeae0eee9ff06252c0209c361269a Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:02:56 -0500 Subject: [PATCH 28/77] Update main.c typo file --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 2140cb91..21453ea4 100644 --- a/main.c +++ b/main.c @@ -2239,7 +2239,7 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600 int battery_saver(int setting) { if (setting == CHECK) { - *FILE file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); + FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { printf("Battery saver mode is OFF\n"); fclose(file); From cb54b365c39726c53cc77a14956917d2e945e51b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:13:40 -0500 Subject: [PATCH 29/77] Update main.h --- main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.h b/main.h index 4735427c..7f4d04a0 100644 --- a/main.h +++ b/main.h @@ -174,5 +174,5 @@ int end_flag_detected = FALSE; int jpeg_start = 0; #define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds -int battery_saver(); +int battery_saver(int setting); From 8e9ad630f32d57d1740d9b75f012dfdf08dd859e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:16:01 -0500 Subject: [PATCH 30/77] Update ina219.py remove signals --- ina219.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ina219.py b/ina219.py index 3fb5713e..6f1b44bd 100644 --- a/ina219.py +++ b/ina219.py @@ -7,6 +7,12 @@ import busio from adafruit_extended_bus import ExtendedI2C as I2C from adafruit_ina219 import INA219 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__": # print 'Length: ', len(sys.argv) From a8c760d85f30d493b9869ea11fb92f78315c5107 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:38:28 -0500 Subject: [PATCH 31/77] Update main.c (void) battery_saver --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 21453ea4..72d4d11f 100644 --- a/main.c +++ b/main.c @@ -819,10 +819,10 @@ int main(int argc, char * argv[]) { #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { - battery_saver(ON); + (void)battery_saver(ON); } else if ((battery_saver(CHECK)) && (batteryCurrent < 0)) { - battery_saver(OFF); + (void)battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_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); From c826869a53ffcc64b0b15e2ff29873cc9ddd74f5 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:45:32 -0500 Subject: [PATCH 32/77] Update main.c typo in HAB mode --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 72d4d11f..46f9f67b 100644 --- a/main.c +++ b/main.c @@ -68,7 +68,7 @@ int main(int argc, char * argv[]) { // sleep(2); #ifdef HAB - Serial.println("HAB mode enabled - balloon icon and BAT only telem and no low voltage shutdown"); + printf("HAB mode enabled - balloon icon and BAT only telem and no low voltage shutdown\n"); #endif // FILE * rpitx_restart = popen("sudo systemctl restart rpitx", "r"); From 1d5c4ca59578b6a2959db78107080b740e0803f2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:51:38 -0500 Subject: [PATCH 33/77] Update main.c added int battery_saver_check() --- main.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 46f9f67b..1c17c6ce 100644 --- a/main.c +++ b/main.c @@ -819,10 +819,10 @@ int main(int argc, char * argv[]) { #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { - (void)battery_saver(ON); - } else if ((battery_saver(CHECK)) && (batteryCurrent < 0)) + battery_saver(ON); + } else if ((battery_saver_check()) && (batteryCurrent < 0)) { - (void)battery_saver(OFF); + battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_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); @@ -2237,33 +2237,34 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600 serialClose(uart_fd); } -int battery_saver(int setting) { - if (setting == CHECK) { - FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); +int battery_saver_check() { + FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { - printf("Battery saver mode is OFF\n"); + printf("Battery saver mode is OFF\n"); fclose(file); return(0); - } + } fclose(file); - printf("Battery saver mode is ON\n"); + printf("Battery saver mode is ON\n"); return(1); - - } else if (setting == ON) { +} + +void battery_saver(int setting) { +if (setting == ON) { FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); printf("Turning Battery saver mode ON\n"); - return(1); + return; } else if (setting == OFF) { FILE *command = popen("sudo rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); printf("Turning Battery saver mode OFF\n"); - return(1); + return; } else { printf("battery_saver function error"); - return(0); + return; } - return(2); + return; } From 629f299be2e13d5abdae94b2f671ed0d4cddb222 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:52:17 -0500 Subject: [PATCH 34/77] Update main.h int battery_saver_check() --- main.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.h b/main.h index 7f4d04a0..53c7d63e 100644 --- a/main.h +++ b/main.h @@ -174,5 +174,6 @@ int end_flag_detected = FALSE; int jpeg_start = 0; #define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds -int battery_saver(int setting); +void battery_saver(int setting); +int battery_saver_check(); From 697c3c142127cf8f6f67a0f92fd3e464f7b38f08 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 08:57:03 -0500 Subject: [PATCH 35/77] Update main.c no sudo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 1c17c6ce..df4c03b4 100644 --- a/main.c +++ b/main.c @@ -2257,7 +2257,7 @@ if (setting == ON) { return; } else if (setting == OFF) { - FILE *command = popen("sudo rm /home/pi/CubeSatSim/battery_saver", "r"); + FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); printf("Turning Battery saver mode OFF\n"); return; From d7ccb1694ae2c69e04d0d14bc7b6b07c76933c6b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 09:04:11 -0500 Subject: [PATCH 36/77] Update main.c battery_saver(ON) do nothing --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index df4c03b4..2438be8d 100644 --- a/main.c +++ b/main.c @@ -2257,6 +2257,7 @@ if (setting == ON) { return; } else if (setting == OFF) { + return; FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); printf("Turning Battery saver mode OFF\n"); From dfed6fccbc14b85e695dcb7756983f083375ddec Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 09:07:40 -0500 Subject: [PATCH 37/77] Update main.c do nothing --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index 2438be8d..0fa6867c 100644 --- a/main.c +++ b/main.c @@ -2250,6 +2250,7 @@ int battery_saver_check() { } void battery_saver(int setting) { + return; if (setting == ON) { FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); From f8ab2ec007e7baddc5f3dbea1468bbd3b62c2fd7 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:25:22 -0500 Subject: [PATCH 38/77] Update config manual battery saver, change modes a,s,m --- config | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/config b/config index 74f13c52..40ea295d 100755 --- a/config +++ b/config @@ -73,13 +73,9 @@ elif [ "$1" = "-a" ]; then if [ -f "$FILE" ]; then echo "Battery saver mode activated." if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi -# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=pwm,pin=18,func=2//g' /boot/config.txt -# sudo sed -i ':a;N;$!ba;s/\ndtoverlay=audremap,enable_jack=on//g' /boot/config.txt else echo "Not battery saver mode" sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt -# if ! grep -q dtoverlay=pwm,pin=18,func=2 /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'; fi -# if ! grep -q dtoverlay=audremap,enable_jack=on /boot/config.txt ; then sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'; fi fi echo "rebooting" @@ -89,7 +85,15 @@ elif [ "$1" = "-a" ]; then elif [ "$1" = "-m" ]; then echo "changing CubeSatSim to CW 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 activated." + if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + else + echo "Not battery saver mode" + sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + fi echo "rebooting" sudo reboot now # sudo systemctl restart cubesatsim @@ -113,7 +117,15 @@ elif [ "$1" = "-b" ]; then elif [ "$1" = "-s" ]; then echo "changing CubeSatSim to SSTV 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 activated." + if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi + else + echo "Not battery saver mode" + sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt + fi echo "rebooting" sudo reboot now # sudo systemctl restart cubesatsim @@ -138,6 +150,7 @@ elif [ "$1" = "-h" ]; then echo " -C Clear logs" echo " -T Change command state" echo " -R Change the Commands Count in the file command_count.txt" + echo " -B Change battery saver mode manually" echo exit @@ -433,6 +446,40 @@ elif [ "$1" = "-R" ]; then else echo "Commands count not reset" 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 activated." + mode=1 + else + echo "Battery saver mode is not activated." + 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 + +# sudo systemctl restart cubesatsim + fi # sudo systemctl restart cubesatsim From 7c107b26e7740893c9db2165c53dc400e8f14a14 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:30:38 -0500 Subject: [PATCH 39/77] Update rpitx.py read open battery_saver --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index d301e968..df8df4dc 100644 --- a/rpitx.py +++ b/rpitx.py @@ -13,7 +13,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor def battery_saver_check(): try: global txc - f = open("/home/pi/CubeSatSim/battery_saver") + f = open("/home/pi/CubeSatSim/battery_saver", "r") f.close() txc = False print("battery saver activated") From 326b57db66c4d5600563b5ce0cfdb12888ee1039 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:45:29 -0500 Subject: [PATCH 40/77] Update main.c print battery_saver_chack() --- main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.c b/main.c index 0fa6867c..f24542bd 100644 --- a/main.c +++ b/main.c @@ -814,7 +814,7 @@ 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); #endif // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V - +printf("battery_saver_check() : %d \n", battery_saver_check()); /**/ #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) @@ -2250,7 +2250,6 @@ int battery_saver_check() { } void battery_saver(int setting) { - return; if (setting == ON) { FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); From 0f2c2928f474e802eea0376da7eb1a09a7ae89a2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:52:23 -0500 Subject: [PATCH 41/77] Update main.c fix conditional --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index f24542bd..e9979002 100644 --- a/main.c +++ b/main.c @@ -820,7 +820,7 @@ printf("battery_saver_check() : %d \n", battery_saver_check()); if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { battery_saver(ON); - } else if ((battery_saver_check()) && (batteryCurrent < 0)) + } else if ((battery_saver_check() == 1) && (batteryCurrent < 0)) { battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. From b2a881db97e798515c473e2732a09bb3013bbae7 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:55:46 -0500 Subject: [PATCH 42/77] Update main.c print conditional --- main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index e9979002..b09e0297 100644 --- a/main.c +++ b/main.c @@ -814,7 +814,11 @@ 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); #endif // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V -printf("battery_saver_check() : %d \n", battery_saver_check()); +printf("battery_saver_check() : %d current: %d\n", battery_saver_check(), batteryCurrent); +if ((battery_saver_check() == 1) && (batteryCurrent < 0)) + printf("Conditional true!\n"); + else + printf("Conditional false!\n"); /**/ #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) From 4d662427a872aa25ffee0ea3a357dd73794e7bf1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 12:01:19 -0500 Subject: [PATCH 43/77] Update main.c conditional test --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index b09e0297..cfba586c 100644 --- a/main.c +++ b/main.c @@ -814,11 +814,11 @@ 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); #endif // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V -printf("battery_saver_check() : %d current: %d\n", battery_saver_check(), batteryCurrent); -if ((battery_saver_check() == 1) && (batteryCurrent < 0)) - printf("Conditional true!\n"); +printf("\n\nbattery_saver_check() : %d current: %f\n", battery_saver_check(), batteryCurrent); +if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) + printf("\nConditional true!\n"); else - printf("Conditional false!\n"); + printf("\nConditional false!\n"); /**/ #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) From 422cb1e3a91819d52341e707d74b42945ffaf820 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 12:28:03 -0500 Subject: [PATCH 44/77] Update main.c added stderr to printfs --- main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index cfba586c..e883f76b 100644 --- a/main.c +++ b/main.c @@ -814,11 +814,11 @@ 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); #endif // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V -printf("\n\nbattery_saver_check() : %d current: %f\n", battery_saver_check(), batteryCurrent); +fprintf(stderr, "\n\nbattery_saver_check() : %d current: %f\n", battery_saver_check(), batteryCurrent); if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) - printf("\nConditional true!\n"); + fprintf(stderr,"\nConditional true!\n"); else - printf("\nConditional false!\n"); + fprintf(stderr,"\nConditional false!\n"); /**/ #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) @@ -2244,12 +2244,12 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600 int battery_saver_check() { FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { - printf("Battery saver mode is OFF\n"); + fprintf(stderr,"Battery saver mode is OFF\n"); fclose(file); return(0); } fclose(file); - printf("Battery saver mode is ON\n"); + fprintf(stderr,"Battery saver mode is ON\n"); return(1); } @@ -2257,18 +2257,18 @@ void battery_saver(int setting) { if (setting == ON) { FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); - printf("Turning Battery saver mode ON\n"); + fprintf(stderr,"Turning Battery saver mode ON\n"); return; } else if (setting == OFF) { return; FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); - printf("Turning Battery saver mode OFF\n"); + fprintf(stderr,"Turning Battery saver mode OFF\n"); return; } else { - printf("battery_saver function error"); + fprintf(stderr,"battery_saver function error"); return; } return; From 8b17d6c2ffb36efb0f59337d01d5e0fbb371abe9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 15:12:41 -0500 Subject: [PATCH 45/77] Update main.c removed stray off --- main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/main.c b/main.c index e883f76b..c91bfc90 100644 --- a/main.c +++ b/main.c @@ -2261,7 +2261,6 @@ if (setting == ON) { return; } else if (setting == OFF) { - return; FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); fprintf(stderr,"Turning Battery saver mode OFF\n"); From 061921a4c1cbd701b9781653015b268e3f530af4 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 15:29:37 -0500 Subject: [PATCH 46/77] Update main.c added to battery saver change mode --- main.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index c91bfc90..4cfca191 100644 --- a/main.c +++ b/main.c @@ -2255,17 +2255,33 @@ int battery_saver_check() { void battery_saver(int setting) { if (setting == ON) { - FILE *command = popen("touch /home/pi/CubeSatSim/battery_saver", "r"); - pclose(command); - fprintf(stderr,"Turning Battery saver mode ON\n"); - return; - + if ((mode == APRS) || (mode == SSTV) || (mode == CW)) { + if (battery_saver_check() == 0) { + 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 if (setting == OFF) { - FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); - pclose(command); - fprintf(stderr,"Turning Battery saver mode OFF\n"); - return; - + if ((mode == APRS) || (mode == SSTV) || (mode == CW)) { + if (battery_saver_check() == 1) { + 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/\nforce_turbo=1//g' /boot/config.txt ", "r"); + pclose(command); + *command = popen("sudo reboot now", "r"); + pclose(command); + sleep(60); + return; + } + } } else { fprintf(stderr,"battery_saver function error"); return; From 8576430d6d9bdc48be0c56daf3760f4222b5e21f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 15:36:46 -0500 Subject: [PATCH 47/77] Update main.c fixes to quotes --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4cfca191..8f7a81dc 100644 --- a/main.c +++ b/main.c @@ -2255,12 +2255,12 @@ int battery_saver_check() { void battery_saver(int setting) { if (setting == ON) { - if ((mode == APRS) || (mode == SSTV) || (mode == CW)) { + if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { if (battery_saver_check() == 0) { 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"); + *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); @@ -2269,7 +2269,7 @@ if (setting == ON) { } } } else if (setting == OFF) { - if ((mode == APRS) || (mode == SSTV) || (mode == CW)) { + if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { if (battery_saver_check() == 1) { FILE *command = popen("rm /home/pi/CubeSatSim/battery_saver", "r"); pclose(command); From 8125c9a13dfe1b1e7e1f7e67b0b75f9da304c762 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 15:37:42 -0500 Subject: [PATCH 48/77] Update main.c fixed * --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 8f7a81dc..39939601 100644 --- a/main.c +++ b/main.c @@ -2260,9 +2260,9 @@ if (setting == ON) { 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"); + 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"); + command = popen("sudo reboot now", "r"); pclose(command); sleep(60); return; @@ -2274,9 +2274,9 @@ if (setting == 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/\nforce_turbo=1//g' /boot/config.txt ", "r"); + command = popen("sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt ", "r"); pclose(command); - *command = popen("sudo reboot now", "r"); + command = popen("sudo reboot now", "r"); pclose(command); sleep(60); return; From 544b2c87e32d10c26ad23d47366e8f5977987a4b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 15:47:36 -0500 Subject: [PATCH 49/77] Update main.c add print --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 39939601..c237dc8f 100644 --- a/main.c +++ b/main.c @@ -2266,7 +2266,8 @@ if (setting == ON) { 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)) { @@ -2280,7 +2281,8 @@ if (setting == ON) { pclose(command); sleep(60); return; - } + } else + fprintf(stderr, "Nothing to do for battery_saver\n"); } } else { fprintf(stderr,"battery_saver function error"); From c03b12bc5cd4c0d85a0737280e5edc9ce32b5941 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 11:39:34 -0500 Subject: [PATCH 50/77] Update main.h added hab_mode and battery_saver_mode --- main.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.h b/main.h index 53c7d63e..4c6b69a3 100644 --- a/main.h +++ b/main.h @@ -177,3 +177,5 @@ int jpeg_start = 0; void battery_saver(int setting); int battery_saver_check(); +int hab_mode = FALSE; +int battery_saver_mode = FALSE; From 34b176ec30e3fe9e510a3a0c342feec1c42939dc Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 11:42:05 -0500 Subject: [PATCH 51/77] Update main.c added battery_saver_mode --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index c237dc8f..f0f9c825 100644 --- a/main.c +++ b/main.c @@ -177,6 +177,8 @@ int main(int argc, char * argv[]) { if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; + battery_saver_mode = battery_saver_check(); + if (mode == AFSK) { // Check for SPI and AX-5043 Digital Transceiver Board @@ -814,7 +816,7 @@ 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); #endif // 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_check() : %d current: %f\n", battery_saver_check(), batteryCurrent); +fprintf(stderr, "\n\nbattery_saver_mode : %d current: %f\n", battery_saver_mode, batteryCurrent); if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) fprintf(stderr,"\nConditional true!\n"); else @@ -824,7 +826,7 @@ if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { battery_saver(ON); - } else if ((battery_saver_check() == 1) && (batteryCurrent < 0)) + } else if ((battery_saver_mode == ON) && (batteryCurrent < 0)) { battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. @@ -2246,11 +2248,11 @@ int battery_saver_check() { if (file == NULL) { fprintf(stderr,"Battery saver mode is OFF\n"); fclose(file); - return(0); + return(ON); } fclose(file); fprintf(stderr,"Battery saver mode is ON\n"); - return(1); + return(OFF); } void battery_saver(int setting) { From 888ce415b599e5f268b557060f5ecac486d500a0 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 11:46:00 -0500 Subject: [PATCH 52/77] Update rpitx.py battery_saver_check() once at starty --- rpitx.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/rpitx.py b/rpitx.py index df8df4dc..29074e63 100644 --- a/rpitx.py +++ b/rpitx.py @@ -208,6 +208,7 @@ else: output(txLed, txLedOn) sleep(1) output(txLed, txLedOff) + battery_saver_check() # print(txLedOn) @@ -282,7 +283,7 @@ if __name__ == "__main__": # if (mode != 'a') and (command_tx == True): if (command_tx == True): - battery_saver_check() + battery_saver_mode output(txLed, txLedOn) if (txc): output(pd, 1) @@ -332,8 +333,8 @@ if __name__ == "__main__": # output(pd, 1) # output (ptt, 0) # sleep(.1) - - battery_saver_check() +# +# battery_saver_check() if (txc): output(pd, 1) output (ptt, 0) @@ -406,7 +407,7 @@ if __name__ == "__main__": if (command_tx == True): output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output (pd, 1) @@ -467,7 +468,7 @@ if __name__ == "__main__": output(txLed, txLedOn) output (ptt, 0) sleep(0.1) - battery_saver_check() +# battery_saver_check() if (txc): system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") @@ -517,7 +518,7 @@ if __name__ == "__main__": if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output(pd, 1) @@ -602,7 +603,7 @@ if __name__ == "__main__": if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output(pd, 1) @@ -632,7 +633,7 @@ if __name__ == "__main__": print ("Sending SSTV image") output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output(pd, 1) @@ -693,7 +694,7 @@ if __name__ == "__main__": if (command_tx == True): print ("Sending SSTV image") output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output(pd, 1) @@ -720,7 +721,7 @@ if __name__ == "__main__": if (command_tx == True): output(txLed, txLedOn) - battery_saver_check() +# battery_saver_check() if (txc): output(pd, 1) From 30bcd1ba442ac230aedaa9ceec4e1b7a39e2ce66 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:25:51 -0500 Subject: [PATCH 53/77] Update config add rotate to clear logs --- config | 1 + 1 file changed, 1 insertion(+) diff --git a/config b/config index 40ea295d..29cd53e5 100755 --- a/config +++ b/config @@ -393,6 +393,7 @@ elif [ "$1" = "-C" ]; then sudo systemctl stop cubesatsim sudo systemctl stop rpitx + sudo journactl --rotate sudo journalctl --vacuum-time=1s sudo systemctl reboot now From ce6fd861d16dbfe95271255dfe53b7efa938bd8c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:30:22 -0500 Subject: [PATCH 54/77] Update rpitx.py stray battery_saver_mode --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index 29074e63..f3d544bc 100644 --- a/rpitx.py +++ b/rpitx.py @@ -283,7 +283,7 @@ if __name__ == "__main__": # if (mode != 'a') and (command_tx == True): if (command_tx == True): - battery_saver_mode +# battery_saver_mode output(txLed, txLedOn) if (txc): output(pd, 1) From 1ba77180f254afb67cdb511d7687425c22b43067 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:37:28 -0500 Subject: [PATCH 55/77] Update main.c only if battery_saver_mode changes execute --- main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index f0f9c825..94e9010e 100644 --- a/main.c +++ b/main.c @@ -177,8 +177,10 @@ int main(int argc, char * argv[]) { if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; - battery_saver_mode = battery_saver_check(); - + battery_saver_mode = battery_saver_check(); + fprintf(stderr, "\nbattery_saver_mode: %d \n\n", battery_saver_mode); + fflush(stderr); + if (mode == AFSK) { // Check for SPI and AX-5043 Digital Transceiver Board @@ -817,7 +819,7 @@ int main(int argc, char * argv[]) { #endif // 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); -if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) +if ((battery_saver_mode == ON) && (batteryCurrent < 0.0)) fprintf(stderr,"\nConditional true!\n"); else fprintf(stderr,"\nConditional false!\n"); @@ -825,10 +827,12 @@ if ((battery_saver_check() == 1) && (batteryCurrent < 0.0)) #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { - battery_saver(ON); + if (battery_saver_mode == OFF) + battery_saver(ON); } else if ((battery_saver_mode == ON) && (batteryCurrent < 0)) { - battery_saver(OFF); + if (battery_saver_mode == ON) + battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_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); From be72b99c8b8f0d137951ee5611d14faabaa00585 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:38:18 -0500 Subject: [PATCH 56/77] Update main.c add ! --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 94e9010e..cbf59113 100644 --- a/main.c +++ b/main.c @@ -2250,12 +2250,12 @@ if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) { // was 9600 int battery_saver_check() { FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { - fprintf(stderr,"Battery saver mode is OFF\n"); + fprintf(stderr,"Battery saver mode is OFF!\n"); fclose(file); return(ON); } fclose(file); - fprintf(stderr,"Battery saver mode is ON\n"); + fprintf(stderr,"Battery saver mode is ON!\n"); return(OFF); } From 889d532f278b06b6d24274441e5cc2239f9661ae Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:45:48 -0500 Subject: [PATCH 57/77] Update main.c paste battery_saver_check code --- main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index cbf59113..3225af68 100644 --- a/main.c +++ b/main.c @@ -177,7 +177,21 @@ int main(int argc, char * argv[]) { if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; - battery_saver_mode = battery_saver_check(); + + FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); + if (file == NULL) { + fprintf(stderr,"Battery saver mode is OFF!\n"); + fclose(file); + battery_saver_mode = OFF; + } + else { + fclose(file); + fprintf(stderr,"Battery saver mode is ON!\n"); + battery_saver_mode = OFF; + } + +// battery_saver_mode = battery_saver_check(); + fprintf(stderr, "\nbattery_saver_mode: %d \n\n", battery_saver_mode); fflush(stderr); From 84d388bcfd8e3c770c90f2b2881041e8f5ada41e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:50:09 -0500 Subject: [PATCH 58/77] Update main.c don't close if open fails --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 3225af68..e7b514f5 100644 --- a/main.c +++ b/main.c @@ -181,7 +181,7 @@ int main(int argc, char * argv[]) { FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { fprintf(stderr,"Battery saver mode is OFF!\n"); - fclose(file); +// fclose(file); battery_saver_mode = OFF; } else { From 38926b7b4f60267cb4fe07800679180475ed3c5c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:57:00 -0500 Subject: [PATCH 59/77] Update main.c cleanup --- main.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index e7b514f5..4be5e34d 100644 --- a/main.c +++ b/main.c @@ -177,20 +177,7 @@ int main(int argc, char * argv[]) { if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; - - FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); - if (file == NULL) { - fprintf(stderr,"Battery saver mode is OFF!\n"); -// fclose(file); - battery_saver_mode = OFF; - } - else { - fclose(file); - fprintf(stderr,"Battery saver mode is ON!\n"); - battery_saver_mode = OFF; - } - -// battery_saver_mode = battery_saver_check(); + battery_saver_mode = battery_saver_check(); fprintf(stderr, "\nbattery_saver_mode: %d \n\n", battery_saver_mode); fflush(stderr); @@ -833,11 +820,7 @@ int main(int argc, char * argv[]) { #endif // 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); -if ((battery_saver_mode == ON) && (batteryCurrent < 0.0)) - fprintf(stderr,"\nConditional true!\n"); - else - fprintf(stderr,"\nConditional false!\n"); -/**/ + #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode) { @@ -2265,7 +2248,6 @@ int battery_saver_check() { FILE *file = fopen("/home/pi/CubeSatSim/battery_saver", "r"); if (file == NULL) { fprintf(stderr,"Battery saver mode is OFF!\n"); - fclose(file); return(ON); } fclose(file); From 3488cc915fc227dee0da61b4792ab15ebd33fb1d Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 12:58:06 -0500 Subject: [PATCH 60/77] Update config typo in journalctl --- config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config b/config index 29cd53e5..6b27189d 100755 --- a/config +++ b/config @@ -393,7 +393,7 @@ elif [ "$1" = "-C" ]; then sudo systemctl stop cubesatsim sudo systemctl stop rpitx - sudo journactl --rotate + sudo journalctl --rotate sudo journalctl --vacuum-time=1s sudo systemctl reboot now From 99d505f1cf606ea15f958ca3d3229cc6a13d65db Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 13:43:09 -0500 Subject: [PATCH 61/77] Update main.c fix sed for battery on --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 4be5e34d..6743f988 100644 --- a/main.c +++ b/main.c @@ -2277,7 +2277,7 @@ if (setting == 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/\nforce_turbo=1//g' /boot/config.txt ", "r"); + 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); From 86dd8f86b01cb9c55f15beffd4a3bdb97b33f53f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 13:46:41 -0500 Subject: [PATCH 62/77] Update main.c switch battery_saver_check() outputs --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 6743f988..a429858f 100644 --- a/main.c +++ b/main.c @@ -2248,11 +2248,11 @@ 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(ON); + return(OFF); } fclose(file); fprintf(stderr,"Battery saver mode is ON!\n"); - return(OFF); + return(ON); } void battery_saver(int setting) { From ed7ff129ab9da817ec2bff4129efd72946c381ac Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 13:59:35 -0500 Subject: [PATCH 63/77] Update config restart CubeSatSim after -B --- config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config b/config index 6b27189d..ab3ece53 100755 --- a/config +++ b/config @@ -479,7 +479,7 @@ elif [ "$1" = "-B" ]; then # if ["$mode" = "1"] ; then sudo systemctl restart rpitx fi -# sudo systemctl restart cubesatsim + sudo systemctl restart cubesatsim fi From f89b6c412ac3fb1e17e12ec18fcb82108e8649d1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 14:18:29 -0500 Subject: [PATCH 64/77] Update main.c add battery prints --- main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.c b/main.c index a429858f..dffeea47 100644 --- a/main.c +++ b/main.c @@ -824,10 +824,12 @@ fprintf(stderr, "\n\nbattery_saver_mode : %d current: %f\n", battery_saver_mode, #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_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)) { + fprintf(stderr,"Battery is being charged - switch battery saver off\n"); if (battery_saver_mode == ON) battery_saver(OFF); } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. From 5361a5b93df14230880d0e4defbba64d13dd99dd Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 14:30:05 -0500 Subject: [PATCH 65/77] Update main.c print battery status mode ON or OFF --- main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index dffeea47..2e8a968e 100644 --- a/main.c +++ b/main.c @@ -178,8 +178,12 @@ int main(int argc, char * argv[]) { 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"); - fprintf(stderr, "\nbattery_saver_mode: %d \n\n", battery_saver_mode); fflush(stderr); if (mode == AFSK) From 88ecd3f2f6b1a5262f03ecdf6b4eade5b0f88031 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 14:39:55 -0500 Subject: [PATCH 66/77] Update main.c fix battery saver turn off --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2e8a968e..1e705040 100644 --- a/main.c +++ b/main.c @@ -2264,7 +2264,7 @@ int battery_saver_check() { void battery_saver(int setting) { if (setting == ON) { if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { - if (battery_saver_check() == 0) { + 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"); @@ -2279,7 +2279,7 @@ if (setting == ON) { } } else if (setting == OFF) { if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { - if (battery_saver_check() == 1) { + 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"); From b8d328ec1d974df678c59d8a7f10710388b0d23a Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 18 Nov 2023 14:47:28 -0500 Subject: [PATCH 67/77] Update main.c add back in auto shutdown --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 1e705040..aa93d5a8 100644 --- a/main.c +++ b/main.c @@ -836,7 +836,8 @@ fprintf(stderr, "\n\nbattery_saver_mode : %d current: %f\n", battery_saver_mode, fprintf(stderr,"Battery is being charged - switch battery saver off\n"); if (battery_saver_mode == ON) battery_saver(OFF); - } else if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. + } + if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_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); digitalWrite(txLed, txLedOff); From c69169d8fff2e1ba73b574c5f495f85ad3f9145f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 11:15:09 -0500 Subject: [PATCH 68/77] Update main.c try removing AMSAT-11 from APRS string --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index aa93d5a8..5151ee65 100644 --- a/main.c +++ b/main.c @@ -1012,7 +1012,8 @@ void get_tlm(void) { // char footer_str1[] = "\' > t.txt && echo \'"; char footer_str1[] = "\' > t.txt"; // char footer_str[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py - char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py +// char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py + char footer_str[] = " && echo '010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py if (ax5043) { strcpy(str, header_str); From 959e3a46b4183771c3cbcc55345f7d950ce766cf Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 11:19:22 -0500 Subject: [PATCH 69/77] Update update added git --no-rebase --- update | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update b/update index 04409734..a3e72684 100755 --- a/update +++ b/update @@ -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 -git pull > .updated +git --no-rebase pull > .updated make debug @@ -135,7 +135,7 @@ cd /home/pi/pi-power-button # git checkout reboot-mode-change -git pull > .updated_p +git --no-rebase pull > .updated_p grep 'changed' /home/pi/pi-power-button/.updated_p if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then @@ -186,7 +186,7 @@ git pull > .updated_p FLAG=1 cd /home/pi/pi-power-button - git pull + git --no-rebase pull git checkout reboot-mode-change script/install From 87fbd64ef10e2cff7a5c93035982edfa006c9129 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 11:21:54 -0500 Subject: [PATCH 70/77] Update main.c add str2 but not used yet --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 5151ee65..d09ad79a 100644 --- a/main.c +++ b/main.c @@ -1012,9 +1012,9 @@ void get_tlm(void) { // char footer_str1[] = "\' > t.txt && echo \'"; char footer_str1[] = "\' > t.txt"; // char footer_str[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py -// char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py - char footer_str[] = " && echo '010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py - + char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py + char footer_str2[] = " && touch /home/pi/CubeSatSim/ready"; + if (ax5043) { strcpy(str, header_str); } else { From 3c81cdb2368b68e3cfb8c896e96871af35105163 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 13:02:00 -0500 Subject: [PATCH 71/77] Update main.c add extra APRS packet only for battery_saver_mode --- main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index d09ad79a..494d9d4a 100644 --- a/main.c +++ b/main.c @@ -1196,7 +1196,11 @@ void get_tlm(void) { strcat(str, footer_str1); // 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); printf("\n\nTelemetry string is %s \n\n", str); From 139ca31adc87a04f27a1c31f9905ec6c6c065392 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 13:06:07 -0500 Subject: [PATCH 72/77] Update update remove --no-rebase --- update | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update b/update index a3e72684..04409734 100755 --- a/update +++ b/update @@ -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 -git --no-rebase pull > .updated +git pull > .updated make debug @@ -135,7 +135,7 @@ cd /home/pi/pi-power-button # git checkout reboot-mode-change -git --no-rebase pull > .updated_p +git pull > .updated_p grep 'changed' /home/pi/pi-power-button/.updated_p if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then @@ -186,7 +186,7 @@ git --no-rebase pull > .updated_p FLAG=1 cd /home/pi/pi-power-button - git --no-rebase pull + git pull git checkout reboot-mode-change script/install From 1cf9f767c9a0ee21aa0ce780b9f07e81bd9da9d7 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 13:48:57 -0500 Subject: [PATCH 73/77] Update rpitx.py fix command --- rpitx.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/rpitx.py b/rpitx.py index f3d544bc..fb1ab782 100644 --- a/rpitx.py +++ b/rpitx.py @@ -137,7 +137,7 @@ print("CubeSatSim v1.3b rpitx.py starting...") pd = 21 ptt = 20 txc_pin = 7 -squelch = 6 + = 6 green = 16 command_tx = True @@ -150,9 +150,9 @@ GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(txc_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(green, GPIO.OUT) -GPIO.setup(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected +GPIO.setup(, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected -if GPIO.input(squelch) == False: +if GPIO.input() == False: print("squelch not set correctly, no command input!") no_command = True else: @@ -355,6 +355,8 @@ if __name__ == "__main__": output(txLed, txLedOff) system("sudo rm /home/pi/CubeSatSim/ready") f.close() + output(pd, 1) + output(ptt, 1) sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") @@ -387,7 +389,8 @@ if __name__ == "__main__": system("echo > command_tx False") else: print("No carrier received!") - + output(pd, 0) + if (debug_mode == 1): print("Ready for next packet!") @@ -428,6 +431,9 @@ if __name__ == "__main__": # output (ptt, 1) sleep(5) while True: + output(pd, 1) + output(ptt, 1) + sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") # command_tx = not command_tx @@ -458,6 +464,8 @@ if __name__ == "__main__": print("Turning off transmit") system("echo > command_tx False") sleep(5) + output(pd, 0) + try: f = open("/home/pi/CubeSatSim/cwready") f.close() @@ -568,6 +576,7 @@ if __name__ == "__main__": system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1") output(pd, 1) + output(ptt, 1) sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") @@ -660,6 +669,7 @@ if __name__ == "__main__": while 1: output(pd, 1) + output(ptt, 1) sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") @@ -689,7 +699,7 @@ if __name__ == "__main__": else: print("Turning off transmit") system("echo > command_tx False") -# output(pd, 0) + output(pd, 0) if (command_tx == True): print ("Sending SSTV image") @@ -751,6 +761,9 @@ if __name__ == "__main__": # output(txLed, txLedOn) # sleep(0.03) # output(txLed, txLedOff) + output(pd, 1) + output(ptt, 1) + sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") # command_tx = not command_tx @@ -781,6 +794,8 @@ if __name__ == "__main__": system("sudo systemctl restart rpitx") # system("sudo reboot now") sleep(60) + output(pd, 0) + if (command_tx == True): output(txLed, txLedOn) sleep(4.0) @@ -799,6 +814,9 @@ if __name__ == "__main__": # output(txLed, txLedOn) # sleep(0.03) # output(txLed, txLedOff) + output(pd, 1) + output(ptt, 1) + sleep(1) if (no_command == False and GPIO.input(squelch) == False): print("carrier received!") # command_tx = not command_tx From 85e9018585c312f14a0295a982b939a7259d5e61 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 14:18:57 -0500 Subject: [PATCH 74/77] Update config only restart on -B if a/s/m mode --- config | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config b/config index ab3ece53..96e41337 100755 --- a/config +++ b/config @@ -479,8 +479,14 @@ elif [ "$1" = "-B" ]; then # if ["$mode" = "1"] ; then sudo systemctl restart rpitx fi - sudo systemctl restart cubesatsim - + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + + if [ "$1" = "a" ] || [ "$1" = "s" ] || [ "$1" = "m" ] ; then + echo "restarting" + sudo systemctl restart cubesatsim + fi fi # sudo systemctl restart cubesatsim From edc66f9ed57d2305bb22c3102c368fe20cd22ef3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 14:20:45 -0500 Subject: [PATCH 75/77] Update update add back --no-rebase --- update | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update b/update index 04409734..8e9f3c9b 100755 --- a/update +++ b/update @@ -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 -git pull > .updated +git pull --no-rebase > .updated make debug @@ -135,7 +135,7 @@ cd /home/pi/pi-power-button # git checkout reboot-mode-change -git pull > .updated_p +git pull --no-rebase > .updated_p grep 'changed' /home/pi/pi-power-button/.updated_p if [[ $(grep 'changed' /home/pi/pi-power-button/.updated_p) ]]; then @@ -186,7 +186,7 @@ git pull > .updated_p FLAG=1 cd /home/pi/pi-power-button - git pull + git pull --no-rebase git checkout reboot-mode-change script/install From 9f15edb8fc9269948d6df231e0b910750f679656 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 14:27:40 -0500 Subject: [PATCH 76/77] Update rpitx.py added back missing squelch variable --- rpitx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpitx.py b/rpitx.py index fb1ab782..7d04a3bb 100644 --- a/rpitx.py +++ b/rpitx.py @@ -137,7 +137,7 @@ print("CubeSatSim v1.3b rpitx.py starting...") pd = 21 ptt = 20 txc_pin = 7 - = 6 +squelch = 6 green = 16 command_tx = True @@ -150,9 +150,9 @@ GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(txc_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(green, GPIO.OUT) -GPIO.setup(, 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 -if GPIO.input() == False: +if GPIO.input(squelch) == False: print("squelch not set correctly, no command input!") no_command = True else: From c0d6d0d02b57d60fd3e92ca18cec60af1d50fab9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Nov 2023 14:54:12 -0500 Subject: [PATCH 77/77] Update main.c remove extra prints --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 494d9d4a..43192904 100644 --- a/main.c +++ b/main.c @@ -178,12 +178,12 @@ int main(int argc, char * argv[]) { 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) @@ -823,7 +823,7 @@ 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); #endif // 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); +// fprintf(stderr, "\n\nbattery_saver_mode : %d current: %f\n", battery_saver_mode, batteryCurrent); #ifndef HAB if ((batteryCurrent > currentThreshold) && (batteryVoltage < (voltageThreshold + 0.15)) && !sim_mode)