From 52529700971da455ee4dd4134bfaa0a54130d568 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 13 Dec 2023 10:57:15 -0500 Subject: [PATCH 1/3] Update main.c read sensors in sim mode --- main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 3f5fa799..c09d269a 100644 --- a/main.c +++ b/main.c @@ -545,7 +545,7 @@ int main(int argc, char * argv[]) { get_tlm_fox(); // fill transmit buffer with reset count 0 packets that will be ignored firstTime = 1; - if (!sim_mode) +// if (!sim_mode) // always read sensors, even in sim mode { strcpy(pythonStr, pythonCmd); strcat(pythonStr, busStr); @@ -603,7 +603,42 @@ int main(int argc, char * argv[]) { printf("++++ Loop time: %5.3f sec +++++\n", (millis() - loopTime)/1000.0); fflush(stdout); loopTime = millis(); - + + { + int count1; + char * token; + fputc('\n', file1); + fgets(cmdbuffer, 1000, file1); + fprintf(stderr, "Python read Result: %s\n", cmdbuffer); + + const char space[2] = " "; + token = strtok(cmdbuffer, space); + + for (count1 = 0; count1 < 8; count1++) { + if (token != NULL) { + voltage[count1] = (float) atof(token); + #ifdef DEBUG_LOGGING +// printf("voltage: %f ", voltage[count1]); + #endif + token = strtok(NULL, space); + if (token != NULL) { + current[count1] = (float) atof(token); + if ((current[count1] < 0) && (current[count1] > -0.5)) + current[count1] *= (-1.0f); + #ifdef DEBUG_LOGGING +// printf("current: %f\n", current[count1]); + #endif + token = strtok(NULL, space); + } + } + if (voltage[map[BAT]] == 0.0) + batteryVoltage = 4.5; + else + batteryVoltage = voltage[map[BAT]]; + batteryCurrent = current[map[BAT]]; + + } + if (sim_mode) { // simulated telemetry double time = ((long int)millis() - time_start) / 1000.0; @@ -671,6 +706,9 @@ int main(int argc, char * argv[]) { // end of simulated telemetry } else { +// code moved + +/* int count1; char * token; fputc('\n', file1); @@ -697,10 +735,16 @@ int main(int argc, char * argv[]) { token = strtok(NULL, space); } } + if (voltage[map[BAT]] == 0.0) + batteryVoltage = 4.5; + else + batteryVoltage = voltage[map[BAT]]; + batteryCurrent = current[map[BAT]]; +*/ } - batteryVoltage = voltage[map[BAT]]; - batteryCurrent = current[map[BAT]]; +// batteryVoltage = voltage[map[BAT]]; +// batteryCurrent = current[map[BAT]]; if (batteryVoltage < 3.7) { SafeMode = 1; From fc81909d9e78192f900e1961ae9a666ca0e08b45 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 13 Dec 2023 11:43:27 -0500 Subject: [PATCH 2/3] Update main.c don't show voltage and current in sstv if not sensor --- main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index c09d269a..4191c9d9 100644 --- a/main.c +++ b/main.c @@ -919,9 +919,13 @@ int main(int argc, char * argv[]) { //#endif FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w"); - if (fp != NULL) { - printf("Writing telem_string.txt\n"); - fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent); + if ((fp != NULL) { + printf("Writing telem_string.txt\n"); + if (batteryVoltage != 4.5) + fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent); + else + fprintf(fp, "\n"); // don't show voltage and current if it isn't a sensor value + fclose(fp); } else printf("Error writing to telem_string.txt\n"); From b96200aff09b1234eda3a120a588c0cc8f444281 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Wed, 13 Dec 2023 11:48:42 -0500 Subject: [PATCH 3/3] Update main.c typo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 4191c9d9..ef252f27 100644 --- a/main.c +++ b/main.c @@ -919,7 +919,7 @@ int main(int argc, char * argv[]) { //#endif FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w"); - if ((fp != NULL) { + if (fp != NULL) { printf("Writing telem_string.txt\n"); if (batteryVoltage != 4.5) fprintf(fp, "BAT %4.2fV %5.1fmA\n", batteryVoltage, batteryCurrent);