From 48314e65f62dde3c59e77d06f7ac2bd554be8db3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 15 Nov 2023 22:29:11 -0500 Subject: [PATCH 01/25] 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 02/25] 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 03/25] 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 04/25] 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 05/25] 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 06/25] 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 07/25] 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 08/25] 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 09/25] 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 10/25] 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 11/25] 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 12/25] 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 13/25] 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 14/25] 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 7c107b26e7740893c9db2165c53dc400e8f14a14 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Thu, 16 Nov 2023 11:30:38 -0500 Subject: [PATCH 15/25] 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 16/25] 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 17/25] 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 18/25] 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 19/25] 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 20/25] 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 21/25] 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 22/25] 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 23/25] 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 24/25] 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 25/25] 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");