From ed3fb1a34317661d3ccdd190d6a4fd27d8a1ff18 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:16:56 -0400 Subject: [PATCH 01/36] added void read_config_file() --- cubesatsim/cubesatsim.ino | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 838e5fe2..47cece5e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -114,7 +114,7 @@ void setup() { start_payload(); // above code not working, so forcing it - read_reset_count(); + read_config_file(); /* sim_mode = FALSE; @@ -347,6 +347,54 @@ void read_reset_count() { } } +void read_config_file() { + char buff[255]; + // Open configuration file with callsign and reset count + + File config_file = LittleFS.open("/sim.cfg", "r"); +// FILE * config_file = fopen("/sim.cfg", "r"); + if (config_file == NULL) { + Serial.println("Creating config file."); + config_file = fopen("/sim.cfg", "w+"); + +// fprintf(config_file, "%s %d", " ", 100); +// sprintf(buff, "%d\n", cnt); + sprintf(buff, "%s %d", "AMSAT", 0); + config_file.write(buff, strlen(buff)); + + + config_file.close(); + + config_file = fopen("/sim.cfg", "r"); + } + +// char * cfg_buf[100]; + config_file.read((uint8_t *)buff, 255); +// sscanf(buff, "%d", &cnt); + sscanf(buff, "%s %d %f %f %s", call, & reset_count, & lat_file, & long_file, sim_yes); + config_file.close(); + + Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", call, reset_count, lat_file, long_file, sim_yes); +/* + reset_count = (reset_count + 1) % 0xffff; + + if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) { + printf("Valid latitude and longitude in config file\n"); +// convert to APRS DDMM.MM format + latitude = toAprsFormat(lat_file); + longitude = toAprsFormat(long_file); + printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); + } else { // set default + latitude = toAprsFormat(latitude); + longitude = toAprsFormat(longitude); + } + + if (strcmp(sim_yes, "yes") == 0) + sim_mode = TRUE; +*/ +} + + void send_aprs_packet() { // encode telemetry get_tlm_ao7(); From cc5fa079298371fc06f0e9bfee7b23eeefb0d102 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:17:00 -0400 Subject: [PATCH 02/36] added void read_config_file() --- cubesatsim/cubesatsim.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index fb4957b0..69b6ebe7 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -202,7 +202,8 @@ void get_serial_char(); void get_serial_clear_buffer(); void set_lat_lon(); void program_radio(); - +void read_config_file(); + #ifndef STASSID #define STASSID "Pico" #define STAPSK "picoPassword" From 572d0206052681cfe6f680536521042ebf207884 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:20:43 -0400 Subject: [PATCH 03/36] file typos --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 47cece5e..663143b0 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -353,9 +353,10 @@ void read_config_file() { File config_file = LittleFS.open("/sim.cfg", "r"); // FILE * config_file = fopen("/sim.cfg", "r"); - if (config_file == NULL) { + if (!config_file) { Serial.println("Creating config file."); - config_file = fopen("/sim.cfg", "w+"); +// config_file = fopen("/sim.cfg", "w+"); + config_file = LittleFS.open("/sim.cfg", "w+"); // fprintf(config_file, "%s %d", " ", 100); // sprintf(buff, "%d\n", cnt); From 0ce13ef1891abaf90f3de1b5e22f85d66a786713 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:22:30 -0400 Subject: [PATCH 04/36] more file stuff --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 663143b0..0aca1593 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -366,7 +366,7 @@ void read_config_file() { config_file.close(); - config_file = fopen("/sim.cfg", "r"); + config_file = LittleFS.open("/sim.cfg", "r"); } // char * cfg_buf[100]; From 10ca9c59508a6485f848cff1a14ea68a1325b0d3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:39:16 -0400 Subject: [PATCH 05/36] create write_config_file and call for callsign --- cubesatsim/cubesatsim.ino | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0aca1593..f981f205 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -376,15 +376,15 @@ void read_config_file() { config_file.close(); Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", call, reset_count, lat_file, long_file, sim_yes); -/* + reset_count = (reset_count + 1) % 0xffff; if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) { - printf("Valid latitude and longitude in config file\n"); + Serial.println("Valid latitude and longitude in config file\n"); // convert to APRS DDMM.MM format latitude = toAprsFormat(lat_file); longitude = toAprsFormat(long_file); - printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); + Serial.print("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); } else { // set default latitude = toAprsFormat(latitude); longitude = toAprsFormat(longitude); @@ -392,7 +392,28 @@ void read_config_file() { if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; -*/ + + config_file.close(); +} + +void write_config_file() { + Serial.println("Writing /sim.cfg file"); + char buff[255]; + File config_file = LittleFS.open("/sim.cfg", "w+"); + +// sprintf(buff, "%s %d", callsign, ); + + if (sim_mode) + strcpy(sim_yes, "yes"); + else + strcpy(sim_yes, "no"); + + sprintf(buff, "%s %d %f %f %s", call, reset_count, latitude, & longitude, sim_yes) + config_file.write(buff, strlen(buff)); + + config_file.close(); + Serial.println("Write complete"); + } @@ -3956,6 +3977,7 @@ void prompt_for_input() { set_callsign(callsign, destination); } Serial.println("Callsign updated!"); + write_config_file(); } else Serial.println("Callsign not updated!"); From f83b6a671926f2f9e09530f48d1e0a1dc450e1ef Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:39:42 -0400 Subject: [PATCH 06/36] add write_config_file --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 69b6ebe7..d83b8e5c 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -203,6 +203,7 @@ void get_serial_clear_buffer(); void set_lat_lon(); void program_radio(); void read_config_file(); +void write_config_file(); #ifndef STASSID #define STASSID "Pico" From 919562174f08544d5dafa1702ed6118a05418e18 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:43:04 -0400 Subject: [PATCH 07/36] fixed callsign --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f981f205..4f72b257 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -372,7 +372,7 @@ void read_config_file() { // char * cfg_buf[100]; config_file.read((uint8_t *)buff, 255); // sscanf(buff, "%d", &cnt); - sscanf(buff, "%s %d %f %f %s", call, & reset_count, & lat_file, & long_file, sim_yes); + sscanf(buff, "%s %d %f %f %s", callsign, & reset_count, & lat_file, & long_file, sim_yes); config_file.close(); Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", call, reset_count, lat_file, long_file, sim_yes); @@ -384,7 +384,7 @@ void read_config_file() { // convert to APRS DDMM.MM format latitude = toAprsFormat(lat_file); longitude = toAprsFormat(long_file); - Serial.print("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); + Serial.printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); } else { // set default latitude = toAprsFormat(latitude); longitude = toAprsFormat(longitude); @@ -408,7 +408,7 @@ void write_config_file() { else strcpy(sim_yes, "no"); - sprintf(buff, "%s %d %f %f %s", call, reset_count, latitude, & longitude, sim_yes) + sprintf(buff, "%s %d %f %f %s", callsign, reset_count, latitude, longitude, sim_yes) config_file.write(buff, strlen(buff)); config_file.close(); From 16955603c840cb884a50a9be77a70f90d80b3113 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 17:44:33 -0400 Subject: [PATCH 08/36] missing ; --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4f72b257..e4a6cd15 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -408,7 +408,7 @@ void write_config_file() { else strcpy(sim_yes, "no"); - sprintf(buff, "%s %d %f %f %s", callsign, reset_count, latitude, longitude, sim_yes) + sprintf(buff, "%s %d %f %f %s", callsign, reset_count, latitude, longitude, sim_yes); config_file.write(buff, strlen(buff)); config_file.close(); From f9405e69b8f99a0d8101a89520a19333d5303ffa Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 19:51:30 -0400 Subject: [PATCH 09/36] fixed lat lon read --- cubesatsim/cubesatsim.ino | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index e4a6cd15..fca3c567 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -382,16 +382,17 @@ void read_config_file() { if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) { Serial.println("Valid latitude and longitude in config file\n"); // convert to APRS DDMM.MM format - latitude = toAprsFormat(lat_file); - longitude = toAprsFormat(long_file); - Serial.printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); - } else { // set default - latitude = toAprsFormat(latitude); - longitude = toAprsFormat(longitude); + latitude = lat_file; // toAprsFormat(lat_file); + longitude = long_file; // toAprsFormat(long_file); + Serial.printf("Lat/Lon updated to: %f/%f\n", latitude, longitude); } +// } else { // set default +// latitude = toAprsFormat(latitude); +// longitude = toAprsFormat(longitude); +// } if (strcmp(sim_yes, "yes") == 0) - sim_mode = TRUE; + sim_mode = true; config_file.close(); } @@ -409,6 +410,8 @@ void write_config_file() { strcpy(sim_yes, "no"); sprintf(buff, "%s %d %f %f %s", callsign, reset_count, latitude, longitude, sim_yes); + Serial.println("Writing string"); + print_string(buff); config_file.write(buff, strlen(buff)); config_file.close(); @@ -4030,7 +4033,9 @@ void prompt_for_input() { Serial.println(float_result); longitude = float_result; } else - Serial.println("Longitude not updated"); + Serial.println("Longitude not updated"); + + write_config_file(); if (mode == AFSK) set_lat_lon(); From f89718926efd07d12161f794d21659826d1c03fc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 20:02:47 -0400 Subject: [PATCH 10/36] fixed callsign read --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index fca3c567..2ad8de6f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -375,7 +375,7 @@ void read_config_file() { sscanf(buff, "%s %d %f %f %s", callsign, & reset_count, & lat_file, & long_file, sim_yes); config_file.close(); - Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", call, reset_count, lat_file, long_file, sim_yes); + Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", callsign, reset_count, lat_file, long_file, sim_yes); reset_count = (reset_count + 1) % 0xffff; From b470bcc9f2a5b5fd3f621971a8042fc935e7d2ad Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 20:07:01 -0400 Subject: [PATCH 11/36] added other config settings --- cubesatsim/cubesatsim.ino | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 2ad8de6f..36a02a6a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3996,11 +3996,13 @@ void prompt_for_input() { if ((serial_string[0] == 'y') || (serial_string[0] == 'Y')) { Serial.println("Setting Simulated telemetry to on"); config_simulated_telem(); + write_config_file(); } else if ((serial_string[0] == 'n') || (serial_string[0] == 'N')) { Serial.println("Setting Simulated telemetry to off"); sim_mode = false; if (!ina219_started) start_ina219(); + write_config_file(); } else Serial.println("No change to Simulated Telemetry mode"); break; @@ -4064,14 +4066,17 @@ void prompt_for_input() { // reset_flag = 0xA07; // EEPROM.put(16, reset_flag); - reset_count = 0; + reset_count = 0; + write_config_file(); + /* EEPROM.put(20, reset_count + 1); if (EEPROM.commit()) { Serial.println("EEPROM successfully committed"); } else { Serial.println("ERROR! EEPROM commit failed"); - } - + } + +*/ } else if ((serial_string[0] == 'p') || (serial_string[0] == 'P')) { Serial.println("Resetting the Payload"); payload_command = PAYLOAD_RESET; From 86cb2e90a412976e433c8144193ea2a2efae6d2e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 20:13:42 -0400 Subject: [PATCH 12/36] added PROMPT_PAYLOAD --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index d83b8e5c..4264c4a7 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -124,6 +124,7 @@ #define PROMPT_RESTART 7 #define PROMPT_DEBUG 8 #define PROMPT_VOLTAGE 9 +#define PROMPT_PAYLOAD 10 #define PAYLOAD_QUERY 1 #define PAYLOAD_RESET 2 From 172c6e0ba268a889335de8c6f542f2cfa65b64cf Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 20:23:52 -0400 Subject: [PATCH 13/36] lots of fixes --- cubesatsim/cubesatsim.ino | 59 ++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 36a02a6a..d24ef4c5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3168,7 +3168,7 @@ void process_pushbutton() { pb_value = digitalRead(MAIN_PB_PIN); if ((pb_value == RELEASED) && (release == FALSE)) { - Serial.println("PB: Switch to FSK"); + Serial.println("PB: FSK not supported"); release = TRUE; // new_mode = FSK; // setup(); @@ -3266,7 +3266,7 @@ void process_bootsel() { // pb_value = digitalRead(MAIN_PB_PIN); if ((!BOOTSEL) && (release == FALSE)) { - Serial.println("BOOTSEL: Switch to FSK"); + Serial.println("BOOTSEL: FSK not supported"); release = TRUE; // new_mode = FSK; // setup(); @@ -3862,7 +3862,7 @@ void serial_input() { case 'f': case 'F': - Serial.println("Change to FSK/DUV mode"); + Serial.println("FSK/DUV mode not supported"); break; case 'b': @@ -3895,9 +3895,15 @@ void serial_input() { prompt = PROMPT_SIM; break; + case 'p': + case 'P': + Serial.println("Reset payload EEPROM settings"); + prompt = PROMPT_PAYLOAD; + break; + case 'r': case 'R': - Serial.println("Change the Resets Count or Reset payload and stored EEPROM values"); + Serial.println("Change the Resets Count"); prompt = PROMPT_RESET; break; @@ -3948,15 +3954,16 @@ void prompt_for_input() { Serial.println("\nChange settings by typing the letter:"); Serial.println("h Help info"); Serial.println("a AFSK/APRS mode"); - Serial.println("c CW mode"); + Serial.println("m CW mode"); Serial.println("f FSK/DUV mode"); Serial.println("b BPSK mode"); Serial.println("s SSTV mode"); Serial.println("i Restart"); Serial.println("c CALLSIGN"); Serial.println("t Simulated Telemetry"); - Serial.println("r Resets Count, or payload & EEPROM"); - Serial.println("l Lat and Long"); + Serial.println("r Resets Count"); + Serial.println("p Resets payload and stored EEPROM values"); + Serial.println("l Lat and Lon"); Serial.println("? Query sensors"); Serial.println("v Read INA219 voltage and current"); Serial.println("d Change debug mode\n"); @@ -4055,35 +4062,17 @@ void prompt_for_input() { voltage_read = true; read_ina219(); break; - - case PROMPT_RESET: - Serial.println("Do you want to Reset the Reset Count (r) or Reset the Payload (p)?"); - Serial.println("Enter r or p"); - get_serial_char(); - if ((serial_string[0] == 'r') || (serial_string[0] == 'R')) { - Serial.println("Reset count is now 0"); - Serial.println("Storing initial reset count in EEPROM"); - -// reset_flag = 0xA07; -// EEPROM.put(16, reset_flag); - reset_count = 0; - write_config_file(); - /* - EEPROM.put(20, reset_count + 1); - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed"); - } else { - Serial.println("ERROR! EEPROM commit failed"); - } - -*/ - } else if ((serial_string[0] == 'p') || (serial_string[0] == 'P')) { - Serial.println("Resetting the Payload"); - payload_command = PAYLOAD_RESET; - start_payload(); - } else - Serial.println("No action"); + + case PROMPT_PAYLOAD: + Serial.println("Resetting the Payload"); + payload_command = PAYLOAD_RESET; + start_payload(); + break; + case PROMPT_RESET: + Serial.println("Reset count is now 0"); + reset_count = 0; + write_config_file(); break; case PROMPT_RESTART: From a6d541b01bb0588b02edfa4d7d7b217a03260ab4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 20:26:56 -0400 Subject: [PATCH 14/36] write after reading config file --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d24ef4c5..a2241b4e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -395,6 +395,8 @@ void read_config_file() { sim_mode = true; config_file.close(); + + write_config_file(); } void write_config_file() { @@ -419,7 +421,6 @@ void write_config_file() { } - void send_aprs_packet() { // encode telemetry get_tlm_ao7(); From ae9863da6933d3182c24043efb3cdf41d1b64894 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:43:33 -0400 Subject: [PATCH 15/36] added read_mode and write_mode --- cubesatsim/cubesatsim.ino | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a2241b4e..59b50e62 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -69,6 +69,8 @@ extern bool start_camera(); void setup() { set_sys_clock_khz(133000, true); + + read_mode(); new_mode = mode; @@ -280,6 +282,7 @@ void loop() { sleep(0.5); config_telem(); config_radio(); + write_mode(); sampleTime = (unsigned int) millis(); } @@ -4176,3 +4179,36 @@ void program_radio() { } } + +read_mode() { + + File mode_file = LittleFS.open("/.mode", "r"); + if (!mode_file) { + Serial.println("Creating mode file"); + mode_file = LittleFS.open("/.mode", "w+"); + mode_file.write(mode); + mode_file.close(); + } else { + if (mode_file.read((uint8_t *)buff, 31)) { + Serial.println("Reading mode from .mode file"); + sscanf(buff, "%d", &mode); + mode_file.close(); + } + } +} + +write_mode() { + + char buff[32]; + Serial.println("Writing .mode file"); + File mode_file = LittleFS.open("/.mode", "w+"); + + + sprintf(buff, "%d", mode); + Serial.println("Writing string"); + print_string(buff); + mode_file.write(buff, strlen(buff)); + + mode_file.close(); + Serial.println("Write complete"); +} From ca37c5bbc766bc30a3542c0e9f7e5595aed4c40d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:44:10 -0400 Subject: [PATCH 16/36] added read and write mode --- cubesatsim/cubesatsim.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 4264c4a7..f7a3a83b 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -205,7 +205,9 @@ void set_lat_lon(); void program_radio(); void read_config_file(); void write_config_file(); - +void read_mode(); +void write_mode(); + #ifndef STASSID #define STASSID "Pico" #define STAPSK "picoPassword" From 5db9ca8724f55a88a8dca621cbfaa5316d2a435a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:45:22 -0400 Subject: [PATCH 17/36] missing void --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 59b50e62..b6704e5b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4180,7 +4180,7 @@ void program_radio() { } } -read_mode() { +void read_mode() { File mode_file = LittleFS.open("/.mode", "r"); if (!mode_file) { @@ -4197,7 +4197,7 @@ read_mode() { } } -write_mode() { +void write_mode() { char buff[32]; Serial.println("Writing .mode file"); From 7f9b25dd8e9c88f779a16069080b8b6b4b63a37d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:46:42 -0400 Subject: [PATCH 18/36] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b6704e5b..0208c3b5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4182,6 +4182,7 @@ void program_radio() { void read_mode() { + char buff[32]; File mode_file = LittleFS.open("/.mode", "r"); if (!mode_file) { Serial.println("Creating mode file"); @@ -4201,8 +4202,7 @@ void write_mode() { char buff[32]; Serial.println("Writing .mode file"); - File mode_file = LittleFS.open("/.mode", "w+"); - + File mode_file = LittleFS.open("/.mode", "w+"); sprintf(buff, "%d", mode); Serial.println("Writing string"); From 3e5eff6d646f0f117a41c307873803db5a3f0ece Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:50:15 -0400 Subject: [PATCH 19/36] fixed create mode file --- cubesatsim/cubesatsim.ino | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0208c3b5..b34e3200 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4185,10 +4185,7 @@ void read_mode() { char buff[32]; File mode_file = LittleFS.open("/.mode", "r"); if (!mode_file) { - Serial.println("Creating mode file"); - mode_file = LittleFS.open("/.mode", "w+"); - mode_file.write(mode); - mode_file.close(); + write_mode(); } else { if (mode_file.read((uint8_t *)buff, 31)) { Serial.println("Reading mode from .mode file"); From 2999187b2309fb0b2cee22e7884f706386550a5a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:54:09 -0400 Subject: [PATCH 20/36] read_mode prints --- cubesatsim/cubesatsim.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b34e3200..38fff0be 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4181,7 +4181,8 @@ void program_radio() { } void read_mode() { - + + Serial.println("Reading mode"); char buff[32]; File mode_file = LittleFS.open("/.mode", "r"); if (!mode_file) { @@ -4190,7 +4191,10 @@ void read_mode() { if (mode_file.read((uint8_t *)buff, 31)) { Serial.println("Reading mode from .mode file"); sscanf(buff, "%d", &mode); - mode_file.close(); + mode_file.close(); + Serial.print("Mode is "); + Serial.print(mode); + } } } From d2d69d17f8586822e0554d3421269c59859f76d5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 22:58:59 -0400 Subject: [PATCH 21/36] added littlefs begin, serial begin --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 38fff0be..1b73091c 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -68,14 +68,14 @@ extern bool start_camera(); void setup() { - set_sys_clock_khz(133000, true); + set_sys_clock_khz(133000, true); + Serial.begin(115200); + read_mode(); new_mode = mode; - Serial.begin(115200); - pinMode(LED_BUILTIN, OUTPUT); blinkTimes(1); @@ -4181,7 +4181,7 @@ void program_radio() { } void read_mode() { - + LittleFS.begin(); Serial.println("Reading mode"); char buff[32]; File mode_file = LittleFS.open("/.mode", "r"); From e9c12210ce4fc46982b25114c00a2bce41a96303 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 23:05:32 -0400 Subject: [PATCH 22/36] added PROMT_TEMP --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index f7a3a83b..42aabcdf 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -125,6 +125,7 @@ #define PROMPT_DEBUG 8 #define PROMPT_VOLTAGE 9 #define PROMPT_PAYLOAD 10 +#define PROMPT_TEMP 11 #define PAYLOAD_QUERY 1 #define PAYLOAD_RESET 2 From 3d06e6bc7a842eaac600e9ad34683cf578d8f42b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 23:06:41 -0400 Subject: [PATCH 23/36] added diode temp prompt --- cubesatsim/cubesatsim.ino | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1b73091c..4a241b35 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3911,6 +3911,12 @@ void serial_input() { prompt = PROMPT_RESET; break; + case 'o': + case 'O': + Serial.println("Read diode temperature"); + prompt = PROMPT_TEMP; + break; + case 'l': case 'L': Serial.println("Change the Latitude and Longitude"); @@ -3970,6 +3976,7 @@ void prompt_for_input() { Serial.println("l Lat and Lon"); Serial.println("? Query sensors"); Serial.println("v Read INA219 voltage and current"); + Serial.println("o Read diode temperature"); Serial.println("d Change debug mode\n"); break; @@ -4057,7 +4064,13 @@ void prompt_for_input() { case PROMPT_QUERY: Serial.println("Querying payload sensors"); payload_command = PAYLOAD_QUERY; - break; + break; + + case PROMPT_TEMP: + sensorValue = analogRead(TEMPERATURE_PIN); + //Serial.println(sensorValue); + Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); + break; case PROMPT_VOLTAGE: Serial.println("Querying INA219 voltage and current sensors"); From 35907a0c7723a214d8214c72d06fc79c943b1c51 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Aug 2022 23:09:43 -0400 Subject: [PATCH 24/36] display temp --- cubesatsim/cubesatsim.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4a241b35..3a38cd8b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4068,8 +4068,12 @@ void prompt_for_input() { case PROMPT_TEMP: sensorValue = analogRead(TEMPERATURE_PIN); - //Serial.println(sensorValue); + Serial.print("Raw diode voltage: "); + Serial.println(sensorValue); Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); + Serial.print("Calculated temperature: "); + Serial.print(Temp); + Serial.println(" C"); break; case PROMPT_VOLTAGE: From 044113705cd8126505c2a27590fd2f94fcc734d2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:28:55 -0400 Subject: [PATCH 25/36] added print for CW mode --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3a38cd8b..9b8ade9c 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -607,7 +607,9 @@ void config_telem() { samplePeriod = 5000; frameTime = 5000; bufLen = 1000; - } + } else if (mode == CW) { + Serial.println("Configuring for CW\n"); + } // clearing min and max values if (debug_mode) Serial.println("Clearing min and max telemetry values"); From 987318bac6b7ac2c7470dc521778d50df3c880e4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:35:01 -0400 Subject: [PATCH 26/36] add prompt in the middle of CW --- cubesatsim/cubesatsim.ino | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9b8ade9c..674c7dce 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3709,7 +3709,13 @@ void transmit_string(char *string) { else { // Serial.println("space between words"); sleep((6.0 * (float)morse_timing)/1000.0); - j++; + j++; + + if (prompt) { +// Serial.println("Need to prompt for input!"); + prompt_for_input(); + prompt = false; + } } } cw_stop = false; From 3ed34a33a0a979751cbcad423367a5e491f35654 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:35:47 -0400 Subject: [PATCH 27/36] changed mic=6 --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 674c7dce..48f8ecdd 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4200,7 +4200,7 @@ void program_radio() { // mySerial.println("AT+DMOSETGROUP=0,432.2510,432.2510,0,8,0,0\r"); mySerial.println("AT+DMOSETGROUP=0,432.2500,432.2500,0,8,0,0\r"); // sleep(0.5); - mySerial.println("AT+DMOSETMIC=3,0\r"); // was 8 + mySerial.println("AT+DMOSETMIC=6,0\r"); // was 8 } } From 91aaaf1c5cd74710c1c0196944035d670c0f4600 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:48:50 -0400 Subject: [PATCH 28/36] fixed AMSAT callsign rewrite --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 48f8ecdd..524a39aa 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -156,7 +156,7 @@ void setup() { /**/ Serial.println("Transmitting callsign"); - strcpy(callsign, call); +// strcpy(callsign, call); if (mode != CW) transmit_callsign(callsign); sleep(5.0); From 0ff1fedb7062af6ad040153b3a6f039697d20f51 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:51:33 -0400 Subject: [PATCH 29/36] removed extra aprs prints --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 524a39aa..b4b1bb9d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -435,8 +435,8 @@ void send_aprs_packet() { strcpy(str, header_str); strcpy(str, tlm_str); strcat(str, payload_str); - print_string(str); - Serial.println(strlen(str)); +// print_string(str); +// Serial.println(strlen(str)); set_status(str); From d9b46c4b9ed05f1b1610e5d70ee3a933627886e8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 06:58:55 -0400 Subject: [PATCH 30/36] added restart --- cubesatsim/cubesatsim.ino | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b4b1bb9d..7094b9cb 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -353,7 +353,7 @@ void read_reset_count() { void read_config_file() { char buff[255]; // Open configuration file with callsign and reset count - + Serial.println("Reading config file"); File config_file = LittleFS.open("/sim.cfg", "r"); // FILE * config_file = fopen("/sim.cfg", "r"); if (!config_file) { @@ -377,8 +377,8 @@ void read_config_file() { // sscanf(buff, "%d", &cnt); sscanf(buff, "%s %d %f %f %s", callsign, & reset_count, & lat_file, & long_file, sim_yes); config_file.close(); - - Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", callsign, reset_count, lat_file, long_file, sim_yes); + if (debug_mode) + Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n", callsign, reset_count, lat_file, long_file, sim_yes); reset_count = (reset_count + 1) % 0xffff; @@ -415,12 +415,13 @@ void write_config_file() { strcpy(sim_yes, "no"); sprintf(buff, "%s %d %f %f %s", callsign, reset_count, latitude, longitude, sim_yes); - Serial.println("Writing string"); - print_string(buff); +// Serial.println("Writing string"); + if (debug_mode) + print_string(buff); config_file.write(buff, strlen(buff)); config_file.close(); - Serial.println("Write complete"); +// Serial.println("Write complete"); } @@ -3891,7 +3892,7 @@ void serial_input() { case 'i': case 'I': -// Serial.println("Restart CubeSatsim software"); + Serial.println("Restart CubeSatsim software"); prompt = PROMPT_RESTART; break; @@ -4105,7 +4106,13 @@ void prompt_for_input() { break; case PROMPT_RESTART: - Serial.println("Restart not yet implemented"); +// Serial.println("Restart not yet implemented"); + if (mode != CW) + transmit_callsign(callsign); + sleep(0.5); + config_telem(); + config_radio(); + sampleTime = (unsigned int) millis(); break; case PROMPT_DEBUG: From f550fcd9071e8940e3b76d8a5fe72fe853470ab9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:02:39 -0400 Subject: [PATCH 31/36] add prompt reset at start of reset --- cubesatsim/cubesatsim.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7094b9cb..97d9a233 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4106,6 +4106,7 @@ void prompt_for_input() { break; case PROMPT_RESTART: + prompt = false; // Serial.println("Restart not yet implemented"); if (mode != CW) transmit_callsign(callsign); From 305416596de0d260d46b5d3a435fb9b4b114d099 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:07:07 -0400 Subject: [PATCH 32/36] v0.21 print --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 97d9a233..4fcd2806 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -83,7 +83,7 @@ void setup() { // otherwise, run CubeSatSim Pico code - Serial.println("CubeSatSim Pico v0.2 starting...\n"); + Serial.println("CubeSatSim Pico v0.21 starting...\n"); config_gpio(); From ab03f3a3aaef258f571510bb8079fe1616042dda Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:15:38 -0400 Subject: [PATCH 33/36] changed order in setup callsign then config --- cubesatsim/cubesatsim.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4fcd2806..166e48e5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -130,11 +130,6 @@ void setup() { if (i2c_bus3 == false) config_simulated_telem(); - config_telem(); - -// setup radio depending on mode - config_radio(); - /* if (check_for_wifi()) { wifi = true; @@ -162,6 +157,11 @@ void setup() { sleep(5.0); /**/ + config_telem(); + +// setup radio depending on mode + config_radio(); + start_button_isr(); sampleTime = (unsigned int) millis(); From 9cf1643224c5b52dfeb68bc1978c12911d6c0005 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:27:39 -0400 Subject: [PATCH 34/36] turn transmit off and on around transmit_callsign --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 166e48e5..bbd8d8da 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3690,8 +3690,9 @@ void transmit_callsign(char *callsign) { if (reset_count == 0) { program_radio(); } - - transmit_string(id); + transmit_off(); + transmit_string(id); + transmit_on(); } void transmit_string(char *string) { From c7afb2bffb3fe3a94866fa840bb1d1a0a99c56e2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:38:28 -0400 Subject: [PATCH 35/36] move all gpio pin config to config_gpio --- cubesatsim/cubesatsim.ino | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bbd8d8da..6b86ac3f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2083,6 +2083,7 @@ void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file) void config_radio() { +/* if (!wifi) pinMode(LED_BUILTIN, OUTPUT); @@ -2094,12 +2095,12 @@ void config_radio() pinMode(TEMPERATURE_PIN, INPUT); pinMode(AUDIO_IN_PIN, INPUT); - +*/ if ((mode == AFSK) || (mode == FSK) || (mode == SSTV) || (mode == CW)) { digitalWrite(PD_PIN, HIGH); // Enable SR_FRS - pinMode(AUDIO_OUT_PIN, OUTPUT); +// pinMode(AUDIO_OUT_PIN, OUTPUT); program_radio(); @@ -3403,14 +3404,20 @@ void config_gpio() { // Serial.println(digitalRead(PI_3V3_PIN)); // set anlog inputs and read + pinMode(TEMPERATURE_PIN, INPUT); Serial.print("Diode voltage (temperature): "); Serial.println(analogRead(TEMPERATURE_PIN)); - + + pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); - Serial.println(analogRead(AUDIO_IN_PIN)); - -} + Serial.println(analogRead(AUDIO_IN_PIN)); + + pinMode(PTT_PIN, OUTPUT); // PTT active LOW + digitalWrite(PTT_PIN, HIGH); + pinMode(PD_PIN, OUTPUT); // PD active HIGH + digitalWrite(PD_PIN, LOW); +} bool TimerHandler0(struct repeating_timer *t) { From 104332deaa5cb973d5a8f96fcafea335fc82c43b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 25 Aug 2022 07:43:04 -0400 Subject: [PATCH 36/36] write mode before CW ID --- cubesatsim/cubesatsim.ino | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 6b86ac3f..cae3133a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -276,13 +276,12 @@ void loop() { if (mode != new_mode) { Serial.println("Changing mode"); mode = new_mode; // change modes if button pressed - + write_mode(); if (new_mode != CW) transmit_callsign(callsign); sleep(0.5); config_telem(); config_radio(); - write_mode(); sampleTime = (unsigned int) millis(); } @@ -4230,11 +4229,11 @@ void read_mode() { write_mode(); } else { if (mode_file.read((uint8_t *)buff, 31)) { - Serial.println("Reading mode from .mode file"); +// Serial.println("Reading mode from .mode file"); sscanf(buff, "%d", &mode); mode_file.close(); - Serial.print("Mode is "); - Serial.print(mode); +// Serial.print("Mode is "); +// Serial.print(mode); } } @@ -4247,10 +4246,12 @@ void write_mode() { File mode_file = LittleFS.open("/.mode", "w+"); sprintf(buff, "%d", mode); - Serial.println("Writing string"); - print_string(buff); + if (debug_mode) { + Serial.println("Writing string"); + print_string(buff); + } mode_file.write(buff, strlen(buff)); mode_file.close(); - Serial.println("Write complete"); +// Serial.println("Write complete"); }