From 1ee0ee87a75f04a71b86a301c06e7c311464d546 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 08:11:45 -0500 Subject: [PATCH 01/15] removed board version check was interfering with Blue Tx LED --- telem.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/telem.c b/telem.c index eff6ba50..4f2c158d 100644 --- a/telem.c +++ b/telem.c @@ -14,6 +14,9 @@ int main(int argc, char *argv[]) { debug = ON; } } + +/* + wiringPiSetup (); printf("\n"); @@ -40,7 +43,7 @@ int main(int argc, char *argv[]) { printf("vB4 Present\n"); map[BAT] = BUS; map[BUS] = BAT; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0)); + snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0)); // strcpy(busStr,"1 0"); } else @@ -68,6 +71,15 @@ int main(int argc, char *argv[]) { } } } +*/ + + printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n"); + map[MINUS_X] = MINUS_Y; + map[PLUS_Z] = MINUS_X; + map[MINUS_Y] = PLUS_Z; + snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3)); + + // Reading I2C voltage and current sensors // printf("Starting\n"); @@ -127,7 +139,8 @@ int main(int argc, char *argv[]) { printf("-Y | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); printf("-Z | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); printf("Bat | % 4.2f V % 5.0f mA \n", voltage[map[BAT]], current[map[BAT]]); - printf("Bus | % 4.2f V % 5.0f mA \n\n", voltage[map[BUS]], current[map[BUS]]); + printf("Bus | % 4.2f V % 5.0f mA \n\n", voltage[map[BUS]], current[map[BUS]]); + fclose(file1); return 0; } @@ -141,7 +154,7 @@ int test_i2c_bus(int bus) strcat (busDev, busS); // printf("Bus Dev String: %s \n", busDev); - if (access(busDev, W_OK | R_OK) >= 0) { // Test if I2C Bus is present + if (access(busDev, W_OK | R_OK) >= 0) { // Test if I2C Bus is present // printf("bus is present\n\n"); char result[128]; const char command_start[] = "timeout 10 i2cdetect -y "; @@ -161,7 +174,7 @@ int test_i2c_bus(int bus) { printf("ERROR: %d bus has a problem \n Check I2C wiring and pullup resistors \n", bus); output = -1; - } + } } else { printf("ERROR: %d bus has a problem \n Check software to see if enabled \n", bus); From 19c9f45432b4bda00572b84f9b34ca9e1a81f87f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 08:14:03 -0500 Subject: [PATCH 02/15] added sleep at start during boot to delay battery read --- main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 8b0c8835..948d7496 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,8 @@ #include "main.h" int main(int argc, char * argv[]) { + + sleep(5); // try sleep at start to help boot printf("\n\nCubeSatSim v1.1 starting...\n\n"); @@ -723,6 +725,8 @@ 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 + +/**/ 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); @@ -745,7 +749,7 @@ int main(int argc, char * argv[]) { pclose(file6); sleep(10); } - +/**/ // sleep(1); // Delay 1 second ctr = 0; #ifdef DEBUG_LOGGING From e459ec5f0a15b94217d5949bf5252c20137c5a23 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 08:15:19 -0500 Subject: [PATCH 03/15] changed battery voltage threshold --- main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.h b/main.h index f26913ec..0c409141 100644 --- a/main.h +++ b/main.h @@ -128,7 +128,7 @@ unsigned int sampleTime = 0; int frames_sent = 0; int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; -float voltageThreshold = 3.5, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; +float voltageThreshold = 3.55, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; float latitude = 39.027702f, longitude = -77.078064f; float lat_file, long_file; double cpuTemp; From aa78a0fdbbaa7831093b72865aee873bf3101520 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:27:44 -0500 Subject: [PATCH 04/15] added Pi Zero 2 test --- main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.c b/main.c index 948d7496..7a91a88c 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,12 @@ #include "main.h" int main(int argc, char * argv[]) { + + testStr = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; + FILE *file_test = sopen(testStr); // see if Pi Zero 2 + fgets(resbuffer, 1000, file_test); + fprintf(stderr, "test result: %s\n", resbuffer); + fclose(file_test); sleep(5); // try sleep at start to help boot From 9136ef93cd172046eacc12dd09fe284a50fc83e5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:31:27 -0500 Subject: [PATCH 05/15] added declarations --- main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 7a91a88c..a1ff16db 100644 --- a/main.c +++ b/main.c @@ -22,8 +22,9 @@ #include "main.h" int main(int argc, char * argv[]) { - - testStr = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; + + char resbuffer[1000]; + constant char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); fprintf(stderr, "test result: %s\n", resbuffer); From bde5043cd5d21024752af98be18f69b846b68c9f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:32:46 -0500 Subject: [PATCH 06/15] typo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index a1ff16db..8958674c 100644 --- a/main.c +++ b/main.c @@ -24,7 +24,7 @@ int main(int argc, char * argv[]) { char resbuffer[1000]; - constant char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; + const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); fprintf(stderr, "test result: %s\n", resbuffer); From 894d91db9c0dcfbff6ef414c7ac756e4c6c145c4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:36:47 -0500 Subject: [PATCH 07/15] changed threshold back to 3.5 V --- main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.h b/main.h index 0c409141..f26913ec 100644 --- a/main.h +++ b/main.h @@ -128,7 +128,7 @@ unsigned int sampleTime = 0; int frames_sent = 0; int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; -float voltageThreshold = 3.55, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; +float voltageThreshold = 3.5, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; float latitude = 39.027702f, longitude = -77.078064f; float lat_file, long_file; double cpuTemp; From 88041efa1a60f1700b20fbc36b12d2011a36feae Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:36:53 -0500 Subject: [PATCH 08/15] added conditional for sleep and change of threshold --- main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 8958674c..abd27944 100644 --- a/main.c +++ b/main.c @@ -27,10 +27,15 @@ int main(int argc, char * argv[]) { const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); - fprintf(stderr, "test result: %s\n", resbuffer); +// fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - - sleep(5); // try sleep at start to help boot + + if (resbuffer <> NULL) + { + sleep(5); // try sleep at start to help boot + voltageThreshold = 3.7; + printf("Pi Zero 2 detected"); + } printf("\n\nCubeSatSim v1.1 starting...\n\n"); From 149542a2221cbbd1bf70519d4e0a6d6b3918eb52 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:38:32 -0500 Subject: [PATCH 09/15] typo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index abd27944..b81e9421 100644 --- a/main.c +++ b/main.c @@ -30,7 +30,7 @@ int main(int argc, char * argv[]) { // fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - if (resbuffer <> NULL) + if (resbuffer != NULL) { sleep(5); // try sleep at start to help boot voltageThreshold = 3.7; From 15c3ee8aa15fc61385ae7751c6425541f326a67c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:48:02 -0500 Subject: [PATCH 10/15] sizeof --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index b81e9421..5a34ffef 100644 --- a/main.c +++ b/main.c @@ -30,7 +30,8 @@ int main(int argc, char * argv[]) { // fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - if (resbuffer != NULL) + fprintf(stderr, sizeof(resbuffer)); + if (sizeof(resbuffer) != 0) { sleep(5); // try sleep at start to help boot voltageThreshold = 3.7; From 5c13f624d27daaee6387b247901ea518240b6bf1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:50:06 -0500 Subject: [PATCH 11/15] strlen --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 5a34ffef..69ddeda3 100644 --- a/main.c +++ b/main.c @@ -30,8 +30,8 @@ int main(int argc, char * argv[]) { // fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - fprintf(stderr, sizeof(resbuffer)); - if (sizeof(resbuffer) != 0) + fprintf(stderr, strlen(resbuffer)); + if (strlen(resbuffer) != 0) { sleep(5); // try sleep at start to help boot voltageThreshold = 3.7; From df86c76fdd06d877883e445db5e019149a081799 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:52:18 -0500 Subject: [PATCH 12/15] test first char --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 69ddeda3..04d45798 100644 --- a/main.c +++ b/main.c @@ -30,8 +30,8 @@ int main(int argc, char * argv[]) { // fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - fprintf(stderr, strlen(resbuffer)); - if (strlen(resbuffer) != 0) +// fprintf(stderr, strlen(resbuffer)); + if (resbuffer[0] != 0) { sleep(5); // try sleep at start to help boot voltageThreshold = 3.7; From 25beaa2d7b69b9abadacd30291b0b56c537804f7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:54:49 -0500 Subject: [PATCH 13/15] added printf --- main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 04d45798..7c2e06db 100644 --- a/main.c +++ b/main.c @@ -27,10 +27,11 @@ int main(int argc, char * argv[]) { const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); -// fprintf(stderr, "test result: %s\n", resbuffer); + fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); -// fprintf(stderr, strlen(resbuffer)); + fprintf(stderr, " %x ", resbuffer[0]); + fprintf(stderr, " %x ", resbuffer[1]); if (resbuffer[0] != 0) { sleep(5); // try sleep at start to help boot From f44a1a21e6c18b6a4dda2c4d913fba7d81373f6c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 2 Mar 2022 13:57:15 -0500 Subject: [PATCH 14/15] check for null in response for no Pi Zero 2 --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 7c2e06db..8164df6d 100644 --- a/main.c +++ b/main.c @@ -27,12 +27,12 @@ int main(int argc, char * argv[]) { const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'"; FILE *file_test = sopen(testStr); // see if Pi Zero 2 fgets(resbuffer, 1000, file_test); - fprintf(stderr, "test result: %s\n", resbuffer); +// fprintf(stderr, "test result: %s\n", resbuffer); fclose(file_test); - fprintf(stderr, " %x ", resbuffer[0]); - fprintf(stderr, " %x ", resbuffer[1]); - if (resbuffer[0] != 0) +// fprintf(stderr, " %x ", resbuffer[0]); +// fprintf(stderr, " %x ", resbuffer[1]); + if (resbuffer[1] != 0) { sleep(5); // try sleep at start to help boot voltageThreshold = 3.7; From e6f335fbe0345a84c8b85d9e41d2c6286332aaff Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Mar 2022 17:39:56 -0500 Subject: [PATCH 15/15] cleanup --- telem.c | 70 +++++---------------------------------------------------- 1 file changed, 5 insertions(+), 65 deletions(-) diff --git a/telem.c b/telem.c index 4f2c158d..6c60b0fa 100644 --- a/telem.c +++ b/telem.c @@ -15,71 +15,11 @@ int main(int argc, char *argv[]) { } } -/* - - wiringPiSetup (); - - printf("\n"); - - pinMode (2, INPUT); - pullUpDnControl (2, PUD_UP); - - if (digitalRead(2) != HIGH) - { - printf("vB3 with TFB Present\n"); - map[BUS] = MINUS_Z; - map[BAT] = BUS; - map[PLUS_Z] = BAT; - map[MINUS_Z] = PLUS_Z; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0)); - } - else - { - pinMode (3, INPUT); - pullUpDnControl (3, PUD_UP); - - if (digitalRead(3) != HIGH) - { - printf("vB4 Present\n"); - map[BAT] = BUS; - map[BUS] = BAT; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0)); - // strcpy(busStr,"1 0"); - } - else - { - pinMode (26, INPUT); - pullUpDnControl (26, PUD_UP); - - if (digitalRead(26) != HIGH) - { - // if (debug == ON) - printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n"); - map[MINUS_X] = MINUS_Y; - map[PLUS_Z] = MINUS_X; - map[MINUS_Y] = PLUS_Z; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3)); - } - else - { - printf("VB3 Present\n"); - map[BUS] = MINUS_Z; - map[BAT] = BUS; - map[PLUS_Z] = BAT; - map[MINUS_Z] = PLUS_Z; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0)); - } - } - } -*/ - - printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n"); - map[MINUS_X] = MINUS_Y; - map[PLUS_Z] = MINUS_X; - map[MINUS_Y] = PLUS_Z; - snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3)); - - + printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n"); + map[MINUS_X] = MINUS_Y; + map[PLUS_Z] = MINUS_X; + map[MINUS_Y] = PLUS_Z; + snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3)); // Reading I2C voltage and current sensors // printf("Starting\n");