From fe2334dfa2fb94c8833f0d587d87a11dc6cd23d1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 2 Sep 2022 22:15:15 -0400 Subject: [PATCH 001/134] stop SSTV if need to prompt, print config file with help, log callsign in CW --- cubesatsim/cubesatsim.ino | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b3ad0d25..1f10c340 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.22 starting...\n"); + Serial.println("CubeSatSim Pico v0.23 starting...\n"); config_gpio(); @@ -198,6 +198,7 @@ void loop() { if (mode == AFSK) { send_aprs_packet(); } else if (mode == CW) { + Serial.printf("HI HI DE %s ", callsign); send_cw(); } } @@ -3975,6 +3976,9 @@ void serial_input() { break; } + if ((mode == SSTV) && prompt) // stop SSTV if need to prompt for input + sstv_end(); + if (new_mode != mode) transmit_off(); sleep(2.0); @@ -4008,7 +4012,10 @@ void prompt_for_input() { 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"); + Serial.println("d Change debug mode\n"); + + Serial.printf("\nConfig file /sim.cfg contains %s %d %f %f %s\n", callsign, reset_count, lat_file, long_file, sim_yes); + break; case PROMPT_CALLSIGN: From 5fb8a3efd8f7233e732a633d24a0efaa20cabcc5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 3 Sep 2022 07:46:21 -0400 Subject: [PATCH 002/134] minor edits --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1f10c340..fb97d1ea 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -198,7 +198,7 @@ void loop() { if (mode == AFSK) { send_aprs_packet(); } else if (mode == CW) { - Serial.printf("HI HI DE %s ", callsign); + Serial.printf("DE %s \n", callsign); send_cw(); } } @@ -4014,7 +4014,7 @@ void prompt_for_input() { Serial.println("o Read diode temperature"); Serial.println("d Change debug mode\n"); - Serial.printf("\nConfig file /sim.cfg contains %s %d %f %f %s\n", callsign, reset_count, lat_file, long_file, sim_yes); + Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n\n", callsign, reset_count, lat_file, long_file, sim_yes); break; From d05473cf6b28910cc5ef5767ecd0c441e0614333 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:06:29 -0400 Subject: [PATCH 003/134] added camera_present --- cubesatsim/pico-get-jpeg-serial.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cubesatsim/pico-get-jpeg-serial.cpp b/cubesatsim/pico-get-jpeg-serial.cpp index 833b4719..661a2833 100644 --- a/cubesatsim/pico-get-jpeg-serial.cpp +++ b/cubesatsim/pico-get-jpeg-serial.cpp @@ -70,7 +70,19 @@ bool start_camera() { #endif LittleFS.begin(); - return(get_camera_image()); + bool camera_present = false; + int tries = 0; + while ((tries++ < 5) && !camera_present) { + if (get_camera_image()) { + camera_present = true; + Serial.println("Camera detected!"); + } + } + if !camera_present { + Serial.println("No camera detected!"); + } + + return(camera_present); } void show_dir2() { From 980527f3dc5632870cd1f7c0e6bc911e6d1bf1d1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:07:19 -0400 Subject: [PATCH 004/134] better start_camera --- cubesatsim/cubesatsim.ino | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index fb97d1ea..1edfd229 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -139,13 +139,7 @@ void setup() { start_button_isr(); setup_sstv(); - if (start_camera()) { - camera_detected = true; - Serial.println("Camera detected!"); - } else { - camera_detected = false; - Serial.println("No camera detected!"); - } + camera_detected = start_camera(); start_isr(); start_pwm(); From 42ab6e5851456cf9983be6e769b7b73a258ec231 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:08:40 -0400 Subject: [PATCH 005/134] Delete pico-get-jpeg-serial.cpp --- .../pico-get-jpeg-serial.cpp | 212 ------------------ 1 file changed, 212 deletions(-) delete mode 100644 cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.cpp diff --git a/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.cpp b/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.cpp deleted file mode 100644 index 12d83125..00000000 --- a/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include "pico-get-jpeg-serial.h" - -/* -void setup() { - - // put your setup code here, to run once: - -if (PICOW) - led_pin = STEM_LED2_PIN; - - Serial.begin(115200); - - delay(5000); - - pinMode(led_pin, OUTPUT); - - digitalWrite(led_pin, LOW); - delay(500); - digitalWrite(led_pin, HIGH); - delay(500); - digitalWrite(led_pin, LOW); - delay(500); - digitalWrite(led_pin, HIGH); - delay(500); - if (PICOW) - digitalWrite(led_pin, LOW); - - delay(2000); - - Serial2.setRX(9); - delay(100); - Serial2.setTX(8); - delay(100); - Serial2.begin(115200); - - Serial.println("Starting"); - - LittleFS.begin(); -} - -void show_dir() { - int count = 0; - Dir dir = LittleFS.openDir("/"); -// or Dir dir = LittleFS.openDir("/data"); - Serial.println(">"); - while (dir.next()) { - count++; - Serial.print(count); - Serial.print(" "); - Serial.print(dir.fileName()); - // if(dir.fileSize()) { - File f = dir.openFile("r"); - Serial.print(" "); - Serial.println(f.size()); - // } else - // Serial.println(" "); - } - Serial.println(">"); -} -*/ - -void write_jpg() { -/* - Serial.println("---------------"); - Serial.println(buffer[jpeg_start], HEX); - Serial.println(buffer[jpeg_start + 1], HEX); - Serial.println(buffer[jpeg_start + 2], HEX); - Serial.println(buffer[jpeg_start + 3], HEX); -*/ - if ((buffer[jpeg_start] == 0xff) && (buffer[jpeg_start + 1] == 0xd8) - && (buffer[index1 - 2] == 0xff) && (buffer[index1 - 1] == 0xd9)) { - - Serial.println("Received a JPEG! Writing to file."); - File i = LittleFS.open("/cam.jpg", "w+"); - if (i) { - i.write(&buffer[jpeg_start], (size_t) (index1 - jpeg_start)); - finished = true; - } else - Serial.println("Error opening cam.jpg"); - -// Serial.println("---------------"); - i.close(); -// } - } else - Serial.println("Not a JPEG"); - - show_dir(); -/* - delay(2000); - - char read_values[2]; - File i = LittleFS.open("/cam.jpg", "r"); - while (i.available()) { - i.readBytes(read_values, 1); - char hexValue[5]; - sprintf(hexValue, "%02X", read_values[0]); - Serial.print(hexValue); - } - i.close(); - Serial.println("\n\n finished read"); - - */ -} - -/* -void loop() { - - char input_file[] = "/cam.jpg"; - char output_file[] = "/cam.bin"; - - get_image_file(); - - Serial.println("Got image from ESP-32-CAM!"); - - delay(1000); - -} -*/ - -void get_image_file() { - finished = false; - while (!finished) { - // put your main code here, to run repeatedly: - if (Serial2.available()) { // If anything comes in Serial2 - byte octet = Serial2.read(); - - if (start_flag_complete) { -// Serial.println("Start flag complete detected"); - buffer[index1++] = octet; - if (octet == end_flag[flag_count]) { // looking for end flag -// if (end_flag_detected) { - flag_count++; -// Serial.println("Found part of end flag!"); - if (flag_count >= strlen(end_flag)) { // complete image -/// buffer[index1++] = octet; - Serial.println("\nFound end flag"); -// Serial.println(octet, HEX); - while(!Serial2.available()) { } // Wait for another byte -// octet = Serial2.read(); -// buffer[index1++] = octet; -// Serial.println(octet, HEX); -// while(!Serial2.available()) { } // Wait for another byte - int received_crc = Serial2.read(); -// buffer[index1++] = octet; - - Serial.print("\nFile length: "); - Serial.println(index1 - (int)strlen(end_flag)); -// index1 -= 1; // 40; -// Serial.println(buffer[index1 - 1], HEX); -// int received_crc = buffer[index1]; -// index1 -= 1; - - uint8_t * data = (uint8_t *) &buffer[0]; -#ifdef DEBUG - Serial.println("\nCRC cacluation data:"); - Serial.println(buffer[0], HEX); - Serial.println(buffer[index1 - 1], HEX); - Serial.println(index1); - Serial.println(received_crc, HEX); - #endif - int calculated_crc = CRC8.smbus(data, index1); - // Serial.println(calculated_crc, HEX); - if (received_crc == calculated_crc) - Serial.println("CRC check succeeded!"); - else - Serial.println("CRC check failed!"); - - index1 -= 40; - write_jpg(); - index1 = 0; - start_flag_complete = false; - start_flag_detected = false; // get ready for next image - end_flag_detected = false; - flag_count = 0; -// delay(6000); - } - } else { - flag_count = 0; - } - /// buffer[index1++] = octet; - -#ifdef DEBUG - char hexValue[5]; - if (octet != 0x66) { - sprintf(hexValue, "%02X", octet); - Serial.print(hexValue); - } else { -// Serial.println("\n********************************************* Got a 66!"); - Serial.print("66"); - } -// Serial.write(octet); -#endif - if (index1 > 100000) - index1 = 0; -// } - } else if (octet == start_flag[flag_count]) { // looking for start flag - start_flag_detected = true; - flag_count++; -// Serial.println("Found part of start flag! "); - if (flag_count >= strlen(start_flag)) { - flag_count = 0; - start_flag_complete = true; - Serial.println("Found start flag!\n"); - } - } else { // not the flag, keep looking - start_flag_detected = false; - flag_count = 0; - // Serial.println("Resetting. Not start flag."); - } - } - } -} From 6a07d4333d9128cb579aee0ba241a0fc53ae2c6b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:08:52 -0400 Subject: [PATCH 006/134] Delete pico-get-jpeg-serial.h --- .../pico-get-jpeg-serial.h | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.h diff --git a/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.h b/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.h deleted file mode 100644 index c8363370..00000000 --- a/cubesatsim/pico-get-jpeg-serial/pico-get-jpeg-serial.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -bool finished = false; - -//char buffer[100001]; -int index1 = 0; -char start_flag[] = "3d99de816e5ad7742b61a37c39141783"; -char end_flag[] = "f681a5c52351befe0e3524eb1a40f14b7803317a"; -int flag_count = 0; -int start_flag_detected = false; -int start_flag_complete = false; -int end_flag_detected = false; -int jpeg_start = 0; -FastCRC8 CRC8; - -//#define DEBUG - -//#define PICOW true -int led_pin = LED_BUILTIN; - -void get_image_file(); From 6325ebe28e4f05b788e7f600ac88aa5724a06dab Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:09:12 -0400 Subject: [PATCH 007/134] Delete pico-get-jpeg-serial.ino --- .../examples/pico-get-jpeg-serial.ino | 228 ------------------ 1 file changed, 228 deletions(-) delete mode 100644 cubesatsim/pico-get-jpeg-serial/examples/pico-get-jpeg-serial.ino diff --git a/cubesatsim/pico-get-jpeg-serial/examples/pico-get-jpeg-serial.ino b/cubesatsim/pico-get-jpeg-serial/examples/pico-get-jpeg-serial.ino deleted file mode 100644 index 925cdec4..00000000 --- a/cubesatsim/pico-get-jpeg-serial/examples/pico-get-jpeg-serial.ino +++ /dev/null @@ -1,228 +0,0 @@ -#include -#include - -bool finished = false; - -char buffer[100001]; -int index1 = 0; -char start_flag[] = "3d99de816e5ad7742b61a37c39141783"; -char end_flag[] = "f681a5c52351befe0e3524eb1a40f14b7803317a"; -int flag_count = 0; -int start_flag_detected = false; -int start_flag_complete = false; -int end_flag_detected = false; -int jpeg_start = 0; -FastCRC8 CRC8; - -//#define DEBUG - -#define PICOW true -int led_pin = LED_BUILTIN; - -void setup() { - - // put your setup code here, to run once: - -if (PICOW) - led_pin = STEM_LED2_PIN; - - Serial.begin(115200); - - delay(5000); - - pinMode(led_pin, OUTPUT); - - digitalWrite(led_pin, LOW); - delay(500); - digitalWrite(led_pin, HIGH); - delay(500); - digitalWrite(led_pin, LOW); - delay(500); - digitalWrite(led_pin, HIGH); - delay(500); - if (PICOW) - digitalWrite(led_pin, LOW); - - delay(2000); - - Serial2.setRX(9); - delay(100); - Serial2.setTX(8); - delay(100); - Serial2.begin(115200); - - Serial.println("Starting"); - - LittleFS.begin(); -} - -void show_dir() { - int count = 0; - Dir dir = LittleFS.openDir("/"); -// or Dir dir = LittleFS.openDir("/data"); - Serial.println(">"); - while (dir.next()) { - count++; - Serial.print(count); - Serial.print(" "); - Serial.print(dir.fileName()); - // if(dir.fileSize()) { - File f = dir.openFile("r"); - Serial.print(" "); - Serial.println(f.size()); - // } else - // Serial.println(" "); - } - Serial.println(">"); -} - -void write_jpg() { -/* - Serial.println("---------------"); - Serial.println(buffer[jpeg_start], HEX); - Serial.println(buffer[jpeg_start + 1], HEX); - Serial.println(buffer[jpeg_start + 2], HEX); - Serial.println(buffer[jpeg_start + 3], HEX); -*/ - if ((buffer[jpeg_start] == 0xff) && (buffer[jpeg_start + 1] == 0xd8) - && (buffer[index1 - 2] == 0xff) && (buffer[index1 - 1] == 0xd9)) { - - Serial.println("Received a JPEG! Writing to file."); - File i = LittleFS.open("/cam.jpg", "w+"); - if (i) { - i.write(&buffer[jpeg_start], (size_t) (index1 - jpeg_start)); - finished = true; - } else - Serial.println("Error opening cam.jpg"); - -// Serial.println("---------------"); - i.close(); -// } - } else - Serial.println("Not a JPEG"); - - show_dir(); -/* - delay(2000); - - char read_values[2]; - File i = LittleFS.open("/cam.jpg", "r"); - while (i.available()) { - i.readBytes(read_values, 1); - char hexValue[5]; - sprintf(hexValue, "%02X", read_values[0]); - Serial.print(hexValue); - } - i.close(); - Serial.println("\n\n finished read"); - - */ -} - -void loop() { - - char input_file[] = "/cam.jpg"; - char output_file[] = "/cam.bin"; - - get_image_file(); - - Serial.println("Got image from ESP-32-CAM!"); - - delay(1000); - -} - - -void get_image_file() { - finished = false; - while (!finished) { - // put your main code here, to run repeatedly: - if (Serial2.available()) { // If anything comes in Serial2 - byte octet = Serial2.read(); - - if (start_flag_complete) { -// Serial.println("Start flag complete detected"); - buffer[index1++] = octet; - if (octet == end_flag[flag_count]) { // looking for end flag -// if (end_flag_detected) { - flag_count++; -// Serial.println("Found part of end flag!"); - if (flag_count >= strlen(end_flag)) { // complete image -/// buffer[index1++] = octet; - Serial.println("\nFound end flag"); -// Serial.println(octet, HEX); - while(!Serial2.available()) { } // Wait for another byte -// octet = Serial2.read(); -// buffer[index1++] = octet; -// Serial.println(octet, HEX); -// while(!Serial2.available()) { } // Wait for another byte - int received_crc = Serial2.read(); -// buffer[index1++] = octet; - - Serial.print("\nFile length: "); - Serial.println(index1 - (int)strlen(end_flag)); -// index1 -= 1; // 40; -// Serial.println(buffer[index1 - 1], HEX); -// int received_crc = buffer[index1]; -// index1 -= 1; - - uint8_t * data = (uint8_t *) &buffer[0]; -#ifdef DEBUG - Serial.println("\nCRC cacluation data:"); - Serial.println(buffer[0], HEX); - Serial.println(buffer[index1 - 1], HEX); - Serial.println(index1); - Serial.println(received_crc, HEX); - #endif - int calculated_crc = CRC8.smbus(data, index1); - // Serial.println(calculated_crc, HEX); - if (received_crc == calculated_crc) - Serial.println("CRC check succeeded!"); - else - Serial.println("CRC check failed!"); - - index1 -= 40; - write_jpg(); - index1 = 0; - start_flag_complete = false; - start_flag_detected = false; // get ready for next image - end_flag_detected = false; - flag_count = 0; -// delay(6000); - } - } else { - flag_count = 0; - } - /// buffer[index1++] = octet; - -#ifdef DEBUG - char hexValue[5]; - if (octet != 0x66) { - sprintf(hexValue, "%02X", octet); - Serial.print(hexValue); - } else { -// Serial.println("\n********************************************* Got a 66!"); - Serial.print("66"); - } -// Serial.write(octet); -#endif - if (index1 > 100000) - index1 = 0; -// } - } else if (octet == start_flag[flag_count]) { // looking for start flag - start_flag_detected = true; - flag_count++; -// Serial.println("Found part of start flag! "); - if (flag_count >= strlen(start_flag)) { - flag_count = 0; - start_flag_complete = true; - Serial.println("Found start flag!\n"); - } - } else { // not the flag, keep looking - start_flag_detected = false; - flag_count = 0; - // Serial.println("Resetting. Not start flag."); - } - } - } -} From ea4f02ab3e71c92d6df9d8f567a107fc92afc408 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 08:14:54 -0400 Subject: [PATCH 008/134] missing () --- cubesatsim/pico-get-jpeg-serial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/pico-get-jpeg-serial.cpp b/cubesatsim/pico-get-jpeg-serial.cpp index 661a2833..19774cac 100644 --- a/cubesatsim/pico-get-jpeg-serial.cpp +++ b/cubesatsim/pico-get-jpeg-serial.cpp @@ -78,7 +78,7 @@ bool start_camera() { Serial.println("Camera detected!"); } } - if !camera_present { + if (!camera_present) { Serial.println("No camera detected!"); } From 669d62b56467c53983cb284fcb13dbfc2a3a54ee Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 11:25:17 -0400 Subject: [PATCH 009/134] fixed transmit on/off for BPSK --- cubesatsim/cubesatsim.ino | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1edfd229..560e26ac 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -489,6 +489,8 @@ void transmit_off() { digitalWrite(MAIN_LED_BLUE, LOW); // ITimer0.stopTimer(); // stop BPSK ISR timer if (mode == BPSK) { + digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); } @@ -2997,8 +2999,10 @@ void start_pwm() { pwm_config_set_output_polarity( &config, true, false); pwm_init(bpsk_pin_slice_A, &config, true); pwm_init(bpsk_pin_slice_B, &config, true); - pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); - pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); +// pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); +// pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); + pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); // start with off + pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); } /* void pwm_interrupt_handler() { @@ -3494,7 +3498,9 @@ void start_isr() { Serial.println("Starting ISR for BPSK"); pinMode(BPSK_CONTROL_A, OUTPUT); - pinMode(BPSK_CONTROL_B, OUTPUT); + pinMode(BPSK_CONTROL_B, OUTPUT); + digitalWrite(BPSK_CONTROL_A, LOW); // start with off + digitalWrite(BPSK_CONTROL_B, LOW); // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) From a38731763d5cb910ac96bebaa96a63686973dd22 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 15:14:42 -0400 Subject: [PATCH 010/134] removed BPSK overlap --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 560e26ac..0e4540e4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3433,13 +3433,13 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { - digitalWrite(BPSK_CONTROL_A, HIGH); + digitalWrite(BPSK_CONTROL_A, LOW); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, HIGH); } else { - digitalWrite(BPSK_CONTROL_B, HIGH); + digitalWrite(BPSK_CONTROL_B, LOW); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, HIGH); } /* tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; From e58601341a7d61f52db24cebeecc268da0c57f7d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 15:17:32 -0400 Subject: [PATCH 011/134] added 1 us delay in BPSK --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0e4540e4..bfb9cf12 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3434,11 +3434,11 @@ bool TimerHandler0(struct repeating_timer *t) { micro_timer2 = micros(); if (buffer[wav_position++] > 0) { digitalWrite(BPSK_CONTROL_A, LOW); -// delayMicroseconds(2); + delayMicroseconds(1); digitalWrite(BPSK_CONTROL_B, HIGH); } else { digitalWrite(BPSK_CONTROL_B, LOW); -// delayMicroseconds(2); + delayMicroseconds(1); digitalWrite(BPSK_CONTROL_A, HIGH); } /* From 683c0296af21f579b1896c1a284244d1ac0c0d39 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 15:20:03 -0400 Subject: [PATCH 012/134] 2 us --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bfb9cf12..d49cb3b1 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3434,11 +3434,11 @@ bool TimerHandler0(struct repeating_timer *t) { micro_timer2 = micros(); if (buffer[wav_position++] > 0) { digitalWrite(BPSK_CONTROL_A, LOW); - delayMicroseconds(1); + delayMicroseconds(2); digitalWrite(BPSK_CONTROL_B, HIGH); } else { digitalWrite(BPSK_CONTROL_B, LOW); - delayMicroseconds(1); + delayMicroseconds(2); digitalWrite(BPSK_CONTROL_A, HIGH); } /* From 4b5d51d0efea07d597a2e11f2588ca892e17abcf Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Sep 2022 15:25:51 -0400 Subject: [PATCH 013/134] back to overlap on BPSK --- cubesatsim/cubesatsim.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d49cb3b1..560e26ac 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3433,13 +3433,13 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { - digitalWrite(BPSK_CONTROL_A, LOW); - delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, HIGH); + digitalWrite(BPSK_CONTROL_A, HIGH); +// delayMicroseconds(2); + digitalWrite(BPSK_CONTROL_B, LOW); } else { - digitalWrite(BPSK_CONTROL_B, LOW); - delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, HIGH); + digitalWrite(BPSK_CONTROL_B, HIGH); +// delayMicroseconds(2); + digitalWrite(BPSK_CONTROL_A, LOW); } /* tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; From fa46a12bf72b966806948d661c8d7387f209bfeb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 08:56:09 -0400 Subject: [PATCH 014/134] skip first time for SSTV --- cubesatsim/cubesatsim.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b3ad0d25..74faffab 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -203,6 +203,7 @@ void loop() { } else if (mode == SSTV) { + first_time_sstv = false; char image_file[128]; if (first_time_sstv) { // if (false) { // turn this off for now @@ -228,6 +229,7 @@ void loop() { char output_file[] = "/cam.bin"; jpeg_decode(image_file, output_file, debug_mode); + rotate if (debug_mode) Serial.println("Start transmit!!!"); From ac8d1e69aff4528354e5392420af237198251ab4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 08:59:35 -0400 Subject: [PATCH 015/134] fixed rotate --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 74faffab..8e14a405 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -229,7 +229,8 @@ void loop() { char output_file[] = "/cam.bin"; jpeg_decode(image_file, output_file, debug_mode); - rotate + char telem_display[] = " Battery: Status: "; + rotate_image(output_file, output_file, telem_display); if (debug_mode) Serial.println("Start transmit!!!"); From e3a4cee8514b19f04c9c16a48712fef161ddebb8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 09:25:56 -0400 Subject: [PATCH 016/134] removed unneeded and made bytes --- cubesatsim/cubesatsim.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index dd7eb8eb..15482d55 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -33,7 +33,7 @@ #include "hardware/pwm.h" // pwm #include "hardware/sync.h" // wait for interrupt #include "RPi_Pico_TimerInterrupt.h" -#include +//#include #include "hardware/gpio.h" #include "hardware/adc.h" #include @@ -137,7 +137,7 @@ char serial_string[128]; //#define WAV_DATA_LENGTH (50000 * 8) uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint8_t data[1024]; +//uint8_t data[1024]; uint32_t tx_channel = 0; //ax5043_conf_t hax5043; @@ -231,7 +231,8 @@ long time_start; //char cmdbuffer[1000]; //FILE * file1;// #define BUFFER_SIZE 5841 //970 // (970 * 2) // * 2) -short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK +//short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK +byte buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK //short int buffer[(WAV_DATA_LENGTH/8)]; //FILE *sopen(const char *program); char tlm_str[1000]; @@ -372,7 +373,8 @@ bool timer0_on = false; char callsign[20]; int morse_timing = 60; // ms for a dit int morse_freq = 1800; // Hz -int morse_table[44][6] = { // 0-9, A-Z only by (ASCII - 48) +//int morse_table[44][6] = { // 0-9, A-Z only by (ASCII - 48) +byte morse_table[44][6] = { // 0-9, A-Z only by (ASCII - 48) { 3, 3, 3, 3, 3, 0 }, // 0 { 1, 3, 3, 3, 3, 0 }, // 1 { 1, 1, 3, 3, 3, 0 }, // 2 From 09a32195922948a45ab5a980c706379677c055bd Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 09:31:39 -0400 Subject: [PATCH 017/134] removed all wifi code --- cubesatsim/cubesatsim.ino | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 8e14a405..2b006290 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -36,7 +36,7 @@ #include "hardware/sync.h" // wait for interrupt #include "RPi_Pico_ISR_Timer.h" #include "RPi_Pico_TimerInterrupt.h" -#include +//#include #include "hardware/gpio.h" #include "hardware/adc.h" #include "SSTV-Arduino-Scottie1-Library.h" @@ -55,8 +55,8 @@ Adafruit_INA219 ina219_2_0x41(0x41); Adafruit_INA219 ina219_2_0x44(0x44); Adafruit_INA219 ina219_2_0x45(0x45); -WiFiServer server(port); -WiFiClient client; +//WiFiServer server(port); +//WiFiClient client; //#define PICO_W // define if Pico W board. Otherwise, compilation fail for Pico or runtime fail if compile as Pico W @@ -235,7 +235,7 @@ void loop() { if (debug_mode) Serial.println("Start transmit!!!"); digitalWrite(PTT_PIN, LOW); // start transmit - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); digitalWrite(MAIN_LED_BLUE, HIGH); @@ -244,7 +244,7 @@ void loop() { if (debug_mode) Serial.println("Stop transmit!"); digitalWrite(PTT_PIN, HIGH); // stop transmit - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); digitalWrite(MAIN_LED_BLUE, LOW); @@ -263,14 +263,14 @@ void loop() { // test_radio(); if ((mode == FSK) || (mode == BPSK)) { - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, LOW); digitalWrite(MAIN_LED_BLUE, LOW); // delay(3000); sleep(0.2); // 2.845); // 3.0); - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); digitalWrite(MAIN_LED_BLUE, HIGH); } @@ -311,7 +311,7 @@ bool TimerHandler1(struct repeating_timer *t) { if (BOOTSEL) // boot selector button is pressed on Pico process_bootsel(); - if (wifi) +// if (wifi) check_for_browser(); return(true); @@ -2637,6 +2637,7 @@ void read_payload() // delay(100); } +/* void payload_OK_only() { payload_str[0] = '\0'; // clear the payload string @@ -2824,7 +2825,8 @@ void payload_OK_only() delay(100); } - + +*/ /* void eeprom_word_write(int addr, int val) { @@ -3151,7 +3153,7 @@ void process_pushbutton() { // return; /// just skip for now - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); // make sure built in LED is on before starting to blink sleep(1.0); @@ -3249,7 +3251,7 @@ void process_bootsel() { int release = FALSE; - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); // make sure built in LED is on before blinking sleep(1.0); @@ -3344,11 +3346,11 @@ void process_bootsel() { void blinkTimes(int blinks) { for (int i = 0; i < blinks; i++) { digitalWrite(MAIN_LED_GREEN, LOW); - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, LOW); sleep(0.1); digitalWrite(MAIN_LED_GREEN, HIGH); - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, HIGH); sleep(0.1); } @@ -3372,7 +3374,7 @@ void config_gpio() { pinMode(AUDIO_OUT_PIN, OUTPUT); // set LEDs and blink once - if (!wifi) +// if (!wifi) pinMode(LED_BUILTIN, OUTPUT); // Set LED pin to output pinMode(MAIN_LED_GREEN, OUTPUT); // Set Main Green LED pin to output blink_pin(MAIN_LED_GREEN, 150); @@ -3548,6 +3550,7 @@ void client_print_string(char *string) client.println(" "); } +/* bool check_for_wifi() { #ifndef PICO_W @@ -3631,13 +3634,13 @@ void check_for_browser() { } } } -/* + Serial.println(" "); print_string(var); print_string(val); Serial.println(" "); Serial.println(strlen(val)); -*/ + if (!strcmp(var, "call") && (strlen(val) > 0)) { Serial.print("Changing callsign to "); print_string(val); @@ -3680,9 +3683,10 @@ void configure_wifi() { server.begin(); } } - +*/ + void transmit_cw(int freq, float duration) { // freq in Hz, duration in milliseconds - if (!wifi) + // if (!wifi) digitalWrite(LED_BUILTIN, HIGH); // Transmit LED on digitalWrite(MAIN_LED_BLUE, HIGH); @@ -3697,7 +3701,7 @@ void transmit_cw(int freq, float duration) { // freq in Hz, duration in millise sleep(min(time_left, period_us) / 1.0E6); } digitalWrite(AUDIO_OUT_PIN, LOW); - if (!wifi) +// if (!wifi) digitalWrite(LED_BUILTIN, LOW); // Transmit LED off digitalWrite(MAIN_LED_BLUE, LOW); } From 591cff4b0d9bee39a95a9d2c0b4c20ea88abdac6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 09:34:02 -0400 Subject: [PATCH 018/134] fixed write_wave --- cubesatsim/cubesatsim.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 2b006290..7d196612 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1333,7 +1333,8 @@ void get_tlm_fox() { } } -void write_wave(int i, short int *buffer) +//void write_wave(int i, short int *buffer) +void write_wave(int i, byte *buffer) { if (mode == FSK) { @@ -3539,7 +3540,8 @@ void start_button_isr() { Serial.println(F("Can't set ITimer1. Select another Timer, freq. or timer")); } - + +/* void client_print_string(char *string) { int count = 0; @@ -3550,7 +3552,6 @@ void client_print_string(char *string) client.println(" "); } -/* bool check_for_wifi() { #ifndef PICO_W From 1280379e7227898f32c495cfe89057bef706530a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 09:39:08 -0400 Subject: [PATCH 019/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7d196612..5e566df4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -312,7 +312,7 @@ bool TimerHandler1(struct repeating_timer *t) { process_bootsel(); // if (wifi) - check_for_browser(); +// check_for_browser(); return(true); } From ba9f3a90465ce3e1aa02a3ac2345a974c5797da6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:10:37 -0400 Subject: [PATCH 020/134] added rotate code --- .../esp32-cam-send-jpeg-serial.ino | 720 ++++++++++++++++++ 1 file changed, 720 insertions(+) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 71449d30..860894ee 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -25,6 +25,7 @@ #include #include "FS.h" #include "SPIFFS.h" +#include // some info: https://visualgdb.com/tutorials/esp32/camera/ @@ -461,3 +462,722 @@ void send_image_serial(char *filename) } Serial.println("File sent!"); } + +void print_hex(byte octet) { + char hexValue[5]; + sprintf(hexValue, "%02X", octet); + Serial.print(hexValue); +} + +char img_block[320][8][3]; // 320 pixels per row, 8 rows, 3 values (RGB) per. + +bool get_block(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) +{ +#ifdef DEBUG + Serial.println("\nBlock callback"); + Serial.println(x); + Serial.println(y); + Serial.println(w); + Serial.println(h); +#endif + +// return 1; + + uint16_t pixel_value; + uint16_t *pixel; + bool last_block = ((x == (320 - w)) & (y == (240 - h))); +// char buffer[16 * 8 * 3]; + int counter = 0; + //int x_block = (x / w) % w; + //int y_block = (y / h) % h; + +/* + if (((y % h) == 0) && ((x % w) == 0)) { + Serial.print("\nStart of row! x = "); + Serial.print(x); + Serial.print(" y = "); + Serial.println(y); + } +*/ + pixel = bitmap; + uint32_t total_pixels = w * h; + +// while (total_pixels--) { + while (counter < total_pixels) { + pixel_value = *pixel; + + int y_rel = counter / w; + int x_rel = counter % w; // - y_rel * w; +/* + Serial.print("Relative x + x = "); + Serial.print(x_rel + x); + Serial.print(" y + y = "); + Serial.print(y_rel); + Serial.print(" counter = "); + Serial.println(counter); +*/ + /* + if ((x == 0) && (y == 0)) { + Serial.print(" "); + Serial.print(pixel_value, HEX); + Serial.print(" "); + } +*/ +// buffer[counter++] = pixel_value >> 8; +// buffer[counter++] = pixel_value; + + byte red = (pixel_value & 0b1111100000000000) >> 8; + byte green = (pixel_value & 0b0000011111100000) >> 3; + byte blue = (pixel_value & 0b0000000000011111) << 3; + +// buffer[counter++] = red; +// buffer[counter++] = green; +// buffer[counter++] = blue; + + img_block[x_rel + x][y_rel][0] = red; + img_block[x_rel + x][y_rel][1] = green; + img_block[x_rel + x][y_rel][2] = blue; + +#ifdef DEBUG + Serial.print("\npixel_value: "); + Serial.print(pixel_value); + Serial.print("\nRGB: "); + print_hex(red); + print_hex(green); + print_hex(blue); + + Serial.println("\n img_block: "); + for (int k = 0; k < 3; k ++) + print_hex(*(&img_block[x_rel + x][y_rel][0] + k)); +#endif + /* + if (counter >= 155000) { + Serial.println("Resetting counter****************************************\n"); + counter = 0; + } +*/ + counter++; + pixel++; + } + +// Serial.println("\nWriting block to file"); +// Serial.print("Sizeof buffer: "); +// Serial.println(sizeof(buffer)); + if (x == 304) { + if (outFile) { + Serial.println("********************************************* Writing block!"); + outFile.write(&img_block[0][0][0], sizeof(img_block)); + } else + Serial.println("Problem writing block"); + counter = 0; + } + if (last_block) { + Serial.println("Complete!\n\n"); + } +/* + for (int i = 0; i < counter; i++) { +// Serial.print(buffer[i], HEX); + char hexValue[5]; + sprintf(hexValue, "%02X", buffer[i]); + Serial.print(hexValue); + } + */ + +// Serial.print("\n\n Size: "); +// Serial.println(counter); + +// write_complete = true; +// } + +// delay(1000); + + blocks++; + + return 1; +} + +int JpegDec_i; +int JpegDec_j; +int JpegDec_height = 240; +int JpegDec_width = 320; +byte JpegDec_sortBuf[15360]; //320(px)*16(lines)*3(bytes) // Header buffer +int JpegDec_pxSkip; +uint8_t *JpegDec_pImg; +int JpegDec_x, JpegDec_y, JpegDec_bx, JpegDec_by; +int JpegDec_comps = 3; + +bool merged_get_block(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) +{ +#ifdef DEBUG + Serial.println("\nBlock callback"); + Serial.println(x); + Serial.println(y); + Serial.println(w); + Serial.println(h); +#endif + int JpegDec_MCUx = x; + int JpegDec_MCUy = y; + int JpegDec_MCUHeight = h; + int JpegDec_MCUWidth = w; + +// JpegDec_pImg = bitmap; + +// JpegDec_pImg = JpegDec_pImage; + for(JpegDec_by=0; JpegDec_by> 8; + byte green = (pixel_value & 0b0000011111100000) >> 3; + byte blue = (pixel_value & 0b0000000000011111) << 3; + + JpegDec_sortBuf[(3 * JpegDec_pxSkip) + 0] = red; // JpegDec_pImg[0]; + JpegDec_sortBuf[(3 * JpegDec_pxSkip) + 1] = green; // JpegDec_pImg[1]; + JpegDec_sortBuf[(3 * JpegDec_pxSkip) + 2] = blue; // JpegDec_pImg[2]; +#ifdef DEBUG + Serial.print("sortBuf index = "); + Serial.println((3 * JpegDec_pxSkip)); +#endif + JpegDec_i++; + if(JpegDec_i == 5120){ //320(px)x16(lines) +#ifdef DEBUG + Serial.println("Writing lines!"); +#endif + // for(k = 0; k < 15360; k++){ +// imgFile.write(sortBuf[k]); +// } + outFile.write(JpegDec_sortBuf, sizeof(JpegDec_sortBuf)); + JpegDec_i = 0; + JpegDec_j++; //15(sections) + } + } + } +// JpegDec_pImg += JpegDec_comps ; + bitmap++; + } + } +#ifdef DEBUG + Serial.println("Block processed!"); +#endif + return 1; +} + +void jpeg_decode(char* filename, char* fileout, bool debug){ + uint8_t *pImg; +// uint16_t *pImg; + int x,y, bx,by; + byte sortBuf[15360]; //320(px)*16(lines)*3(bytes) // Header buffer + int i,j,k; + int pxSkip; + + // Open the file for writing +// File imgFile = SD.open(fileout, FILE_WRITE); + outFile = LittleFS.open(fileout, "w+"); + + if (outFile) { + if (debug) + Serial.println("Output opened"); + } + else + Serial.println("Failed to open output"); + + for(i = 0; i < 15360; i++){ // Cleaning Header Buffer array + sortBuf[i] = 0xFF; + } + + for(i = 0; i < 12; i++){ + byte fontNumber; + char ch; + ch = charId[i]; + for(y = 0; y < 11; y++){ + for(x = 0; x < 8; x++){ + pxSkip = 16 + (320 * (y + 3)) + (3 * 8 * i) + (3 * x); //Width: x3 + + uint8_t mask; + mask = pow(2, 7 - x); + + if(ch >= 65 && ch <= 90){ // A to Z + fontNumber = ch - 65; + } + else if(ch >= 48 && ch <= 57){ //0 to 9 + fontNumber = ch - 22; + } + else if(ch == '/'){fontNumber = 36;} + else if(ch == '-'){fontNumber = 37;} + else if(ch == '.'){fontNumber = 38;} + else if(ch == '?'){fontNumber = 39;} + else if(ch == '!'){fontNumber = 40;} + else if(ch == ':'){fontNumber = 41;} + else if(ch == ' '){fontNumber = 42;} + else {fontNumber = 42;} + + if((b_fonts[fontNumber][y] & mask) != 0){ + for(j = 0; j < 9; j++){ + sortBuf[(3 * pxSkip) + j] = 0x00; + } + } + } + } + } + +// for(k = 0; k < 15360; k++){ // Adding header to the binary file +// imgFile.write(sortBuf[k]); +// } + outFile.write(sortBuf, sizeof(sortBuf)); + +// writeFooter(&outFile); //Writing first 10560 bytes (11*320*3) // write footer after rotate + + // Decoding start + + if (debug) + Serial.println("Starting jpeg decode"); + + JpegDec_i = 0; + JpegDec_j = 0; + + uint16_t w = 0, h = 0; + // TJpgDec.getFsJpgSize(&w, &h, "/cam.jpg", LittleFS); // Note name preceded with "/" + TJpgDec.getFsJpgSize(&w, &h, filename, LittleFS); // Note name preceded with "/" + + if (debug) { + Serial.print("Width = "); + Serial.print(w); + Serial.print(", height = "); + Serial.println(h); + } + + if ((w == 0) && (h == 0)) { + Serial.println("Failed to open jpeg input"); + return; + } +// counter = 0; +// write_complete = false; + + TJpgDec.setJpgScale(1); + TJpgDec.setSwapBytes(false); // was true +// TJpgDec.setCallback(get_block); + TJpgDec.setCallback(merged_get_block); + //TJpgDec.drawFsJpg(0, 0, "/cam.jpg", LittleFS); + TJpgDec.drawFsJpg(0, 0, filename, LittleFS); + + if (debug) + Serial.println("Draw complete"); + +// while (!write_complete) { Serial.println("Waiting..."); delay(500);} + +/* + JpegDec.decodeFile(filename); + // Image Information + Serial.print("Width :"); + Serial.println(JpegDec.width); + Serial.print("Height :"); + Serial.println(JpegDec.height); + Serial.print("Components:"); + Serial.println(JpegDec.comps); + Serial.print("MCU / row :"); + Serial.println(JpegDec.MCUSPerRow); + Serial.print("MCU / col :"); + Serial.println(JpegDec.MCUSPerCol); + Serial.print("Scan type :"); + Serial.println(JpegDec.scanType); + Serial.print("MCU width :"); + Serial.println(JpegDec.MCUWidth); + Serial.print("MCU height:"); + Serial.println(JpegDec.MCUHeight); + Serial.println(""); +*/ + if (debug) + Serial.println("Writing bin to FS"); + +// imgFile.write(JpegDec.pImage, sizeof(JpegDec.pImage)); + +/* + i = 0; + j = 0; + while(JpegDec.read()){ + pImg = JpegDec.pImage ; + for(by=0; by 0) { + // read 32 bytes at a time; + uint8_t *buffer; + uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups! + buffer = cam.readPicture(bytesToRead); + imgFile.write(buffer, bytesToRead); + if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up + Serial.print('.'); + wCount = 0; + } + //Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes"); + jpglen -= bytesToRead; + } + imgFile.close(); + time = millis() - time; + Serial.println("done!"); + Serial.print(time); Serial.println(" ms elapsed"); + +*/ +//} + +/** Write on a file with 11 lines the values of the GPS + * @param dst Given an opened File stream then write data to dst. + * @param latitude Floating point latitude value in degrees/min as received from the GPS (DDMM.MMMM) + * @param lat N/S + * @param longitude Floating point longitude value in degrees/min as received from the GPS (DDMM.MMMM) + * @param lon E/W + * @param altitude Altitude in meters above MSL + */ + +/* +//void writeFooter(File* dst, nmea_float_t latitude, char lat, nmea_float_t longitude, char lon, nmea_float_t altitude){ //Write 16 lines with values +void writeFooter(File* dst){ + int x,y; + byte sortBuf[10560]; //320(px)*11(lines)*3(bytes) // Header buffer + int i,j,k; + int pxSkip; + char res[51] = "LAT: 1234.1234N LONG: 1234.1234W ALT:10000"; + for(i = 0; i < 10560; i++){ // Cleaning Header Buffer array + sortBuf[i] = 0xFF; + } + for(i = 0; i < sizeof(res); i++){ + byte fontNumber; + char ch; + ch = res[i]; + for(y = 0; y < 5; y++){ + for(x = 0; x < 4; x++){ + //pxSkip = HORIZONTALOFFSET + VERSTICALOFFSET + (BITSPERWORD * i); + //pxSkip = 16 + (320 * (y + 3)) + (4 * 2 * i) + (2 * x); Width: x2 + pxSkip = 16 + (320 * (y + 3)) + (4 * i) + x; + // If ch is pair mask is: 11110000, if no 00001111 + uint8_t sl = (ch % 2)? 3 : 7 ; + uint8_t mask = pow(2, sl - x); + if(ch >= 48 && ch <=91){ + fontNumber = (ch-48)/2; + } + else { + fontNumber = 22; + } + if((l_fonts[fontNumber][y] & mask) != 0){ + for(j = 0; j < 3; j++){ + sortBuf[(3 * pxSkip) + j] = 0x00; + } + } + } + } + } +// for(k = 0; k < 10560; k++){ // Adding header to the binary file +// dst->write(sortBuf[k]); + dst->write(sortBuf, sizeof(sortBuf)); +// } +} +*/ + +void raw_decode(char* filename, char* fileout){ // used to decode .raw files in RGB565 format + +// Open the input file for reading + inFile = LittleFS.open(filename, "r"); + + if (inFile) + Serial.println("Input opened"); + else { + Serial.println("Failed to open input"); + return; + } +// Open the output file for writing + outFile = LittleFS.open(fileout, "w+"); + + if (outFile) + Serial.println("Output opened"); + else { + Serial.println("Failed to open output"); + return; + } + char buff[2]; + char buffer[3]; + + int i = 0; +// int redx = 128; +// int greenx = 128; +// int bluex = 128; + +// while (i++ < (320 * 240 * 3)) { + while (i++ < (320 * 240 * 1.49)) { + inFile.readBytes(buff, 2); + +#ifdef DEBUG + print_hex(buff[0]); + print_hex(buff[1]); +#endif + + int pixel_value = (buff[0] << 8) + buff[1]; // endian for raw + + byte red = (pixel_value & 0b1111100000000000) >> 8; + byte green = (pixel_value & 0b0000011111100000) >> 3; + byte blue = (pixel_value & 0b0000000000011111) << 3; + +#ifdef TEST_PATTERN + int size = 5; // 46; + int y = (int)( i / 320 ); + int x = (int)( i - y * 320 ); + int box = (int)(x/size) + (int)(y/size); + + if (y < 10) { // 20) { + red = 0; + green = 255; + blue = 0; + } + else if ( box == ( (int)(box / 2) * 2)) { +// Serial.println(x); +// Serial.println(y); +// Serial.println(box); +// Serial.println(" "); + red = 255; //(100 + x) % 256; + green = 0; // ; + blue = 0; + } else { +// Serial.println(x); +// Serial.println(y); +// Serial.println(box); +// Serial.println(" "); + red = 0; + green = 0; + blue = 255; //(100 + y) % 256; + } +#endif + + buffer[0] = red; + buffer[1] = green; + buffer[2] = blue; +/* + if (y < 20) { // 20) { + buffer[0] = 0; + buffer[1] = 255; + buffer[2] = 0; + } else { + + buffer[0] = redx; + buffer[1] = greenx; + buffer[2] = bluex; + } + */ + + int bytes = outFile.write(buffer, 3); +// Serial.println(bytes); + if (bytes < 3) + Serial.println("Error writing output file"); + + #ifdef DEBUG + print_hex(red); + print_hex(green); + print_hex(blue); + +// delay(100); + #endif + } + inFile.close(); + outFile.close(); +} + +/* +//void writeFooter(File* dst, nmea_float_t latitude, char lat, nmea_float_t longitude, char lon, nmea_float_t altitude){ //Write 16 lines with values +void writeFooter(File* dst, char *telemetry){ + int x,y; + byte sortBuf[10560]; //320(px)*11(lines)*3(bytes) // Header buffer + int i,j,k; + int pxSkip; + + char res[51]; // = "LAT: 1234.1234N LONG: 1234.1234W ALT:10000"; + + if (strlen(telemetry) > 50) + telemetry[50] = '\0'; + strcpy(res, telemetry); + + for(i = 0; i < 10560; i++){ // Cleaning Header Buffer array + sortBuf[i] = 0xFF; + } + + for(i = 0; i < sizeof(res); i++){ + byte fontNumber; + char ch; + ch = res[i]; + for(y = 0; y < 5; y++){ + for(x = 0; x < 4; x++){ + //pxSkip = HORIZONTALOFFSET + VERSTICALOFFSET + (BITSPERWORD * i); + //pxSkip = 16 + (320 * (y + 3)) + (4 * 2 * i) + (2 * x); Width: x2 + pxSkip = 16 + (320 * (y + 3)) + (4 * i) + x; + + // If ch is pair mask is: 11110000, if no 00001111 + uint8_t sl = (ch % 2)? 3 : 7 ; + uint8_t mask = pow(2, sl - x); + + if(ch >= 48 && ch <=91){ + fontNumber = (ch-48)/2; + } + else { + fontNumber = 22; + } + + if((l_fonts[fontNumber][y] & mask) != 0){ + for(j = 0; j < 3; j++){ + sortBuf[(3 * pxSkip) + j] = 0x00; + } + } + } + } + } + + for(k = 0; k < 10560; k++){ // Adding header to the binary file + dst->write(sortBuf[k]); + } +} + +*/ + +void rotate_image(char *file_input, char *file_output, char *telemetry) { + + File input_file = LittleFS.open(file_input, "r"); + + char pixel[3]; + int side = (320 - 240)/2; + for (int y = 0; y < 240; y++) { + for (int x = 0; x < 320; x++) { + input_file.readBytes(pixel, sizeof(pixel)); + if (( x >= side) && (x < (320 - side))) { + input_buffer[y][x - side][0] = pixel[0]; + input_buffer[y][x - side][1] = pixel[1]; + input_buffer[y][x - side][2] = pixel[2]; + } + } + } + input_file.close(); + + LittleFS.remove(file_input); + + Serial.println("Input file read and deleted"); + Serial.println(side); + + input_file = LittleFS.open(file_input, "w+"); + + //writeFooter(&input_file, telemetry); + + char side_pixel[] = { 0xff, 0xff, 0xff }; + for (int y = 0; y < 240; y++) { + Serial.println(" "); + for (int x = 0; x < 320; x++) { + if (( x >= side) && (x < (320 - side))) { + Serial.print("+"); +// Serial.print(x - side); +// Serial.print(" "); + pixel[0] = input_buffer[x - side][y][0]; + pixel[1] = input_buffer[x - side][y][1]; + pixel[2] = input_buffer[x - side][y][2]; + if (input_file.write(pixel, sizeof(pixel)) < 3) + Serial.println("Error writing to file"); + } else { + Serial.print("-"); + if (input_file.write(side_pixel, sizeof(side_pixel)) < 3) + Serial.println("Error writing to file"); + } + } + } + + input_file.close(); +} From 506eb47db8866661e562479354750d1448782667 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:14:26 -0400 Subject: [PATCH 021/134] removed LittleFS --- .../esp32-cam-send-jpeg-serial.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 860894ee..48e71b35 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -686,7 +686,7 @@ void jpeg_decode(char* filename, char* fileout, bool debug){ // Open the file for writing // File imgFile = SD.open(fileout, FILE_WRITE); - outFile = LittleFS.open(fileout, "w+"); + outFile = SPIFFS.open(fileout, "w+"); if (outFile) { if (debug) @@ -751,7 +751,7 @@ void jpeg_decode(char* filename, char* fileout, bool debug){ uint16_t w = 0, h = 0; // TJpgDec.getFsJpgSize(&w, &h, "/cam.jpg", LittleFS); // Note name preceded with "/" - TJpgDec.getFsJpgSize(&w, &h, filename, LittleFS); // Note name preceded with "/" + TJpgDec.getFsJpgSize(&w, &h, filename, SPIFFS); // Note name preceded with "/" if (debug) { Serial.print("Width = "); @@ -772,7 +772,7 @@ void jpeg_decode(char* filename, char* fileout, bool debug){ // TJpgDec.setCallback(get_block); TJpgDec.setCallback(merged_get_block); //TJpgDec.drawFsJpg(0, 0, "/cam.jpg", LittleFS); - TJpgDec.drawFsJpg(0, 0, filename, LittleFS); + TJpgDec.drawFsJpg(0, 0, filename, SPIFFS); if (debug) Serial.println("Draw complete"); @@ -973,7 +973,7 @@ void writeFooter(File* dst){ void raw_decode(char* filename, char* fileout){ // used to decode .raw files in RGB565 format // Open the input file for reading - inFile = LittleFS.open(filename, "r"); + inFile = SPIFFS.open(filename, "r"); if (inFile) Serial.println("Input opened"); @@ -982,7 +982,7 @@ void raw_decode(char* filename, char* fileout){ // used to decode .raw files in return; } // Open the output file for writing - outFile = LittleFS.open(fileout, "w+"); + outFile = SPIFFS.open(fileout, "w+"); if (outFile) Serial.println("Output opened"); @@ -1133,7 +1133,7 @@ void writeFooter(File* dst, char *telemetry){ void rotate_image(char *file_input, char *file_output, char *telemetry) { - File input_file = LittleFS.open(file_input, "r"); + File input_file = SPIFFS.open(file_input, "r"); char pixel[3]; int side = (320 - 240)/2; @@ -1149,12 +1149,12 @@ void rotate_image(char *file_input, char *file_output, char *telemetry) { } input_file.close(); - LittleFS.remove(file_input); + SPIFFS.remove(file_input); Serial.println("Input file read and deleted"); Serial.println(side); - input_file = LittleFS.open(file_input, "w+"); + input_file = SPIFFS.open(file_input, "w+"); //writeFooter(&input_file, telemetry); From 0afe24541fe10081d5166ff623ac87ad0366c0da Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:18:52 -0400 Subject: [PATCH 022/134] added LittleFS for compile error --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 48e71b35..564d5ccb 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -25,6 +25,7 @@ #include #include "FS.h" #include "SPIFFS.h" +#include #include // some info: https://visualgdb.com/tutorials/esp32/camera/ From 894cdff38e4f46a8820ccf77f6133fbc46d27af2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:22:51 -0400 Subject: [PATCH 023/134] removed LittleFS, try changing TJpg user config file to enable SD --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 564d5ccb..48e71b35 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -25,7 +25,6 @@ #include #include "FS.h" #include "SPIFFS.h" -#include #include // some info: https://visualgdb.com/tutorials/esp32/camera/ From 59bf48fe01afab0a2b741f5ed8ce42b19c2da335 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:29:22 -0400 Subject: [PATCH 024/134] added outfIle and inFile --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 48e71b35..06ca3b44 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -50,6 +50,8 @@ char file_buf[50000]; int file_len; bool file_flag = false; camera_fb_t *pic; +File inFile; +File outFile; // example code from https://github.com/espressif/arduino-esp32/blob/master/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino // From e48301b56d64c190d8f2e9fb4e47c79cba1a357a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:32:36 -0400 Subject: [PATCH 025/134] added variables --- .../esp32-cam-send-jpeg-serial.ino | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 06ca3b44..97273f03 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -32,6 +32,81 @@ //#define DEBUG #define FORMAT_SPIFFS_IF_FAILED true +//FONTS +const uint8_t b_fonts[43][11] = { + {0x00, 0x18, 0x24, 0x62, 0x62, 0x62, 0x7E, 0x62, 0x62, 0x62, 0x00}, //00: A + {0x00, 0x7C, 0x32, 0x32, 0x32, 0x3C, 0x32, 0x32, 0x32, 0x7C, 0x00}, //01: B + {0x00, 0x3C, 0x62, 0x62, 0x60, 0x60, 0x60, 0x62, 0x62, 0x3C, 0x00}, //02: C + {0x00, 0x7C, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x7C, 0x00}, //03: D + {0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x7E, 0x00}, //04: E + {0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x00}, //05: F + {0x00, 0x3C, 0x62, 0x62, 0x60, 0x60, 0x66, 0x62, 0x62, 0x3C, 0x00}, //06: G + {0x00, 0x62, 0x62, 0x62, 0x62, 0x7E, 0x62, 0x62, 0x62, 0x62, 0x00}, //07: H + {0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00}, //08: I + {0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x4C, 0x4C, 0x4C, 0x38, 0x00}, //09: J + {0x00, 0x62, 0x64, 0x68, 0x70, 0x68, 0x64, 0x62, 0x62, 0x62, 0x00}, //10: K + {0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00}, //11: L + {0x00, 0x42, 0x62, 0x76, 0x6A, 0x62, 0x62, 0x62, 0x62, 0x62, 0x00}, //12: M + {0x00, 0x42, 0x62, 0x72, 0x6A, 0x66, 0x62, 0x62, 0x62, 0x62, 0x00}, //13: N + {0x00, 0x3C, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x3C, 0x00}, //14: O + {0x00, 0x7C, 0x62, 0x62, 0x62, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x00}, //15: P + {0x00, 0x3C, 0x62, 0x62, 0x62, 0x62, 0x62, 0x6A, 0x6A, 0x3C, 0x08}, //16: Q + {0x00, 0x7C, 0x62, 0x62, 0x62, 0x7C, 0x68, 0x64, 0x62, 0x62, 0x00}, //17: R + {0x00, 0x3C, 0x62, 0x60, 0x60, 0x3C, 0x06, 0x06, 0x46, 0x3C, 0x00}, //18: S + {0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, //19: T + {0x00, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x3C, 0x00}, //20: U + {0x00, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x22, 0x14, 0x08, 0x00}, //21: V + {0x00, 0x62, 0x62, 0x62, 0x62, 0x62, 0x6A, 0x76, 0x62, 0x42, 0x00}, //22: W + {0x00, 0x42, 0x62, 0x74, 0x38, 0x1C, 0x2E, 0x46, 0x42, 0x42, 0x00}, //23: X + {0x00, 0x42, 0x62, 0x74, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, //24: Y + {0x00, 0x7E, 0x06, 0x0E, 0x0C, 0x18, 0x30, 0x70, 0x60, 0x7E, 0x00}, //25: Z + {0x00, 0x3C, 0x62, 0x62, 0x66, 0x6A, 0x72, 0x62, 0x62, 0x3C, 0x00}, //26: 0 + {0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, //27: 1 + {0x00, 0x3C, 0x46, 0x06, 0x06, 0x1C, 0x20, 0x60, 0x60, 0x7E, 0x00}, //28: 2 + {0x00, 0x3C, 0x46, 0x06, 0x06, 0x1C, 0x06, 0x06, 0x46, 0x3C, 0x00}, //29: 3 + {0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x4C, 0x7E, 0x0C, 0x0C, 0x0C, 0x00}, //30: 4 + {0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, 0x06, 0x06, 0x46, 0x3C, 0x00}, //31: 5 + {0x00, 0x3C, 0x62, 0x60, 0x60, 0x7C, 0x62, 0x62, 0x62, 0x3C, 0x00}, //32: 6 + {0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00}, //33: 7 + {0x00, 0x3C, 0x62, 0x62, 0x62, 0x3C, 0x62, 0x62, 0x62, 0x3C, 0x00}, //34: 8 + {0x00, 0x3C, 0x46, 0x46, 0x46, 0x3E, 0x06, 0x06, 0x46, 0x3C, 0x00}, //35: 9 + {0x00, 0x00, 0x02, 0x06, 0x0E, 0x1C, 0x38, 0x70, 0x60, 0x40, 0x00}, //36: / + {0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00}, //37: - + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00}, //38: . + {0x00, 0x3C, 0x46, 0x06, 0x06, 0x0C, 0x10, 0x00, 0x30, 0x30, 0x00}, //39: ? + {0x00, 0x18, 0x18, 0x18, 0x18, 0x10, 0x10, 0x00, 0x18, 0x18, 0x00}, //40: ! + {0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00}, //41: : + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} //42: space +}; + +// Nibble font table +const uint8_t l_fonts[23][5] = { + { 0xE2, 0xA6, 0xA2, 0xA2, 0xE2 }, // 0: 01 + { 0xEE, 0x22, 0xE6, 0x82, 0xEE }, // 1: 23 + { 0xAE, 0xA8, 0xEE, 0x22, 0x2E }, // 2: 45 + { 0x8E, 0x82, 0xE2, 0xA2, 0xE2 }, // 3: 67 + { 0xEE, 0xAA, 0xEE, 0xA2, 0xE2 }, // 4: 89 + { 0x00, 0x22, 0x00, 0x22, 0x04 }, // 5: :; + { 0x20, 0x4E, 0x80, 0x4E, 0x20 }, // 6: <= + { 0x8E, 0x42, 0x26, 0x40, 0x84 }, // 7: >? + { 0x64, 0x9A, 0xBE, 0x8A, 0x7A }, // 8: @A + { 0xC6, 0xA8, 0xC8, 0xA8, 0xC6 }, // 9: BC + { 0xCE, 0xA8, 0xAC, 0xA8, 0xCE }, // 10: DE + { 0xE6, 0x88, 0xCE, 0x8A, 0x86 }, // 11: FG + { 0xA4, 0xA4, 0xE4, 0xA4, 0xA4 }, // 12: HI + { 0x69, 0x2A, 0x2C, 0x2A, 0x49 }, // 13: JK + { 0x8A, 0x8E, 0x8E, 0x8A, 0xEA }, // 14: LM + { 0x04, 0x9A, 0xDA, 0xBA, 0x94 }, // 15: NO + { 0xC4, 0xAA, 0xCA, 0x8E, 0x86 }, // 16: PQ + { 0xC6, 0xA8, 0xC4, 0xA2, 0xAC }, // 17: RS + { 0xE0, 0x4A, 0x4A, 0x4A, 0x44 }, // 18: TU + { 0x09, 0xA9, 0xA9, 0x6F, 0x26 }, // 19: vW (sort of..) + { 0x0A, 0xAA, 0x46, 0xA2, 0x04 }, // 20: XY + { 0xE6, 0x24, 0x44, 0x84, 0xE6 }, // 21: Z[ + { 0x00, 0x00, 0x00, 0x00, 0x00 } // 22: SPACE +}; + + void app_main(); void send_image_serial(char *filename); void save_camera_image(char* filename); @@ -52,6 +127,9 @@ bool file_flag = false; camera_fb_t *pic; File inFile; File outFile; +int blocks = 0; +//int counter = 0; +bool write_complete = false; // example code from https://github.com/espressif/arduino-esp32/blob/master/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino // From aea5795f0b2434f339d17798ea64342e43820d30 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:36:49 -0400 Subject: [PATCH 026/134] removed text at the start --- .../esp32-cam-send-jpeg-serial.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 97273f03..9852e806 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -774,7 +774,8 @@ void jpeg_decode(char* filename, char* fileout, bool debug){ } else Serial.println("Failed to open output"); - + + /* for(i = 0; i < 15360; i++){ // Cleaning Header Buffer array sortBuf[i] = 0xFF; } @@ -818,7 +819,8 @@ void jpeg_decode(char* filename, char* fileout, bool debug){ // imgFile.write(sortBuf[k]); // } outFile.write(sortBuf, sizeof(sortBuf)); - +*/ + // writeFooter(&outFile); //Writing first 10560 bytes (11*320*3) // write footer after rotate // Decoding start From 1f47e189b55876aee1304fb87cbbb4211233f1c8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 10:38:38 -0400 Subject: [PATCH 027/134] try removing FS.h --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 9852e806..df1074d0 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -23,7 +23,7 @@ #include #include "esp_camera.h" #include -#include "FS.h" +//#include "FS.h" #include "SPIFFS.h" #include From 7a2451e4b54ef5a0b8c1711b4be3d2a300f088a3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 11:26:28 -0400 Subject: [PATCH 028/134] added const uint8_t* --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index df1074d0..e4c00d0b 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -646,7 +646,7 @@ bool get_block(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) if (x == 304) { if (outFile) { Serial.println("********************************************* Writing block!"); - outFile.write(&img_block[0][0][0], sizeof(img_block)); + outFile.write((const uint8_t*)&img_block[0][0][0], sizeof(img_block)); } else Serial.println("Problem writing block"); counter = 0; From e163763a47eb0933699412b46dbf33c04dbf5a77 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 11:29:59 -0400 Subject: [PATCH 029/134] fixed rest, added input_buffer --- .../esp32-cam-send-jpeg-serial.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index e4c00d0b..6818a09c 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -106,6 +106,7 @@ const uint8_t l_fonts[23][5] = { { 0x00, 0x00, 0x00, 0x00, 0x00 } // 22: SPACE }; +char input_buffer[240][240][3]; void app_main(); void send_image_serial(char *filename); @@ -1141,7 +1142,7 @@ void raw_decode(char* filename, char* fileout){ // used to decode .raw files in } */ - int bytes = outFile.write(buffer, 3); + int bytes = outFile.write((const uint8_t*)buffer, 3); // Serial.println(bytes); if (bytes < 3) Serial.println("Error writing output file"); @@ -1251,11 +1252,11 @@ void rotate_image(char *file_input, char *file_output, char *telemetry) { pixel[0] = input_buffer[x - side][y][0]; pixel[1] = input_buffer[x - side][y][1]; pixel[2] = input_buffer[x - side][y][2]; - if (input_file.write(pixel, sizeof(pixel)) < 3) + if (input_file.write((const uint8_t*)pixel, sizeof(pixel)) < 3) Serial.println("Error writing to file"); } else { Serial.print("-"); - if (input_file.write(side_pixel, sizeof(side_pixel)) < 3) + if (input_file.write((const uint8_t*)side_pixel, sizeof(side_pixel)) < 3) Serial.println("Error writing to file"); } } From b07af3a1a07b03d2c5256cd43ce677e6a47425ed Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 15:39:18 -0400 Subject: [PATCH 030/134] removed sstv2.h --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 5e566df4..33a3e6a4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -44,7 +44,7 @@ // jpg files to be stored in flash storage on Pico (FS 512kB setting) #include "sstv1.h" -#include "sstv2.h" +//#include "sstv2.h" Adafruit_INA219 ina219_1_0x40; Adafruit_INA219 ina219_1_0x41(0x41); @@ -217,7 +217,7 @@ void loop() { char camera_file[] = "/cam.jpg"; strcpy(image_file, camera_file); } else - strcpy(image_file, sstv2_filename); // 2nd stored image + strcpy(image_file, sstv1_filename); // 2nd stored image } if (debug_mode) { Serial.print("\nSending SSTV image "); From 0e511c526a538df17fddc8f47a4f145cbf96b4d3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 15:40:57 -0400 Subject: [PATCH 031/134] fully removed sstv image 2 --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 33a3e6a4..bb0eedb6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3838,7 +3838,7 @@ void load_files() { } f.close(); } - +/* f = LittleFS.open("sstv_image_2_320_x_240.jpg", "r"); if (f) { Serial.println("Image sstv_image_2_320_x_240.jpg already in FS"); @@ -3852,7 +3852,7 @@ void load_files() { } f.close(); } - +*/ show_dir(); } From 546760144b0c4067e55d073dbebd53c8b53e2a15 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 16:57:44 -0400 Subject: [PATCH 032/134] rotate_image files must be different, cam2.bin and cam.bin --- cubesatsim/cubesatsim.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bb0eedb6..98671948 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -227,10 +227,11 @@ void loop() { // send_sstv(image_file); - char output_file[] = "/cam.bin"; - jpeg_decode(image_file, output_file, debug_mode); + char output_file2[] = "/cam2.bin"; + jpeg_decode(image_file, output_file2, debug_mode); char telem_display[] = " Battery: Status: "; - rotate_image(output_file, output_file, telem_display); + char output_file[] = "/cam.bin"; + rotate_image(output_file2, output_file, telem_display); if (debug_mode) Serial.println("Start transmit!!!"); From 091f6fc58fab7289cf211d4aceb65c0f3db2779a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 22:11:17 -0400 Subject: [PATCH 033/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 98671948..436b2d03 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -228,7 +228,7 @@ void loop() { // send_sstv(image_file); char output_file2[] = "/cam2.bin"; - jpeg_decode(image_file, output_file2, debug_mode); + jpeg_decode(image_file, output_file2, true); // debug_mode); char telem_display[] = " Battery: Status: "; char output_file[] = "/cam.bin"; rotate_image(output_file2, output_file, telem_display); From 51eb3f13017829761acd9074e3ee170d395c68b4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 22:21:21 -0400 Subject: [PATCH 034/134] dir --- cubesatsim/cubesatsim.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 436b2d03..91ab7eba 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -227,12 +227,15 @@ void loop() { // send_sstv(image_file); + show_dir(); char output_file2[] = "/cam2.bin"; jpeg_decode(image_file, output_file2, true); // debug_mode); + show_dir(); char telem_display[] = " Battery: Status: "; char output_file[] = "/cam.bin"; rotate_image(output_file2, output_file, telem_display); - + show_dir(); + if (debug_mode) Serial.println("Start transmit!!!"); digitalWrite(PTT_PIN, LOW); // start transmit From bf922baa7c9d8752c72017a9c6b059c67ecfeea6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 22:28:35 -0400 Subject: [PATCH 035/134] delete cam.bin --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 91ab7eba..049ddffd 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -226,7 +226,7 @@ void loop() { // send_sstv("/cam.raw"); // send_sstv(image_file); - + LittleFS.remove("/cam.bin"); show_dir(); char output_file2[] = "/cam2.bin"; jpeg_decode(image_file, output_file2, true); // debug_mode); From 75e308d47520f73bf793ef00e4cfcf0f6e94f59d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 5 Sep 2022 22:37:07 -0400 Subject: [PATCH 036/134] don't delete cam.bin --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 049ddffd..a83babb7 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -226,7 +226,7 @@ void loop() { // send_sstv("/cam.raw"); // send_sstv(image_file); - LittleFS.remove("/cam.bin"); +// LittleFS.remove("/cam.bin"); show_dir(); char output_file2[] = "/cam2.bin"; jpeg_decode(image_file, output_file2, true); // debug_mode); From 74986c322c72a322389e9f696e7266e1fa5055ea Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 6 Sep 2022 09:43:01 -0400 Subject: [PATCH 037/134] added PD High and PTT low to program_radio --- cubesatsim/cubesatsim.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a83babb7..703ef5e0 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4231,6 +4231,9 @@ void set_lat_lon() { void program_radio() { + digitalWrite(PD_PIN, HIGH); // enable SR_FRS + digitalWrite(PTT_PIN, HIGH); // stop transmit + DumbTXSWS mySerial(SWTX_PIN); // TX pin mySerial.begin(9600); From 98d2a98b1f4994624475364afea8c26619efc3ef Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 6 Sep 2022 09:47:34 -0400 Subject: [PATCH 038/134] force no camera --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 703ef5e0..464da019 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -139,7 +139,8 @@ void setup() { start_button_isr(); setup_sstv(); - if (start_camera()) { +// if (start_camera()) { + if (false) { camera_detected = true; Serial.println("Camera detected!"); } else { From 068907fe28b7484eb38fd5b2a89d3259f4fb5dbc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 6 Sep 2022 11:33:14 -0400 Subject: [PATCH 039/134] PTT off, telem display upper case only --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 464da019..f6889c50 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -232,8 +232,9 @@ void loop() { char output_file2[] = "/cam2.bin"; jpeg_decode(image_file, output_file2, true); // debug_mode); show_dir(); - char telem_display[] = " Battery: Status: "; - char output_file[] = "/cam.bin"; + char telem_display[] = " BATT: STATUS: TEMP: "; + char output_file[] = "/cam.bin"; + digitalWrite(PTT_PIN, HIGH); // shouldn't need this but rotate_image(output_file2, output_file, telem_display); show_dir(); From 63daa1f540f90a1a0f6905b051bac42b32f2b783 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 6 Sep 2022 16:33:21 -0400 Subject: [PATCH 040/134] allow camera detection --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f6889c50..4eb0d0d3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -139,8 +139,8 @@ void setup() { start_button_isr(); setup_sstv(); -// if (start_camera()) { - if (false) { + if (start_camera()) { +// if (false) { camera_detected = true; Serial.println("Camera detected!"); } else { From 354c7304fc3225eb6f25fe87857d6092eec4a900 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 6 Sep 2022 21:24:20 -0400 Subject: [PATCH 041/134] added config_camera with horizontal and vertical flip --- .../esp32-cam-send-jpeg-serial.ino | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 6818a09c..15fc9d5f 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -181,6 +181,8 @@ void setup() { Serial.begin(112500); initialize_camera(); + + config_camera(); Serial.println("ESP32-CAM Camera initialized"); @@ -316,9 +318,22 @@ static esp_err_t init_camera() // ESP_LOGE(TAG, "Camera Init Failed"); return err; } + + return ESP_OK; } +void config_camera() { + + sensor_t * s = esp_camera_sensor_get(); + + s->set_brightness(s, 2); // -2 to 2 +// s->set_contrast(s, 0); // -2 to 2 + s->set_saturation(s, 1); // -2 to 2 + s->set_hmirror(s, 1); // 0 = disable , 1 = enable + s->set_vflip(s, 1); +} + void initialize_camera() { if (ESP_OK != init_camera()) { Serial.println("Failed to initialize camera!"); From 31b500cc9213802712cf59a3f208cd8708267056 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 7 Sep 2022 15:12:20 -0400 Subject: [PATCH 042/134] remove config_camera --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 15fc9d5f..187fc0f4 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -178,11 +178,11 @@ void setup() { delay(5000); - Serial.begin(112500); + Serial.begin(115200); initialize_camera(); - config_camera(); +// config_camera(); Serial.println("ESP32-CAM Camera initialized"); From ca4e3798a4c6195fa8e475fc91e938035ae17977 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 7 Sep 2022 15:14:34 -0400 Subject: [PATCH 043/134] only h and v flip --- .../esp32-cam-send-jpeg-serial.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 187fc0f4..e2ddfb65 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -182,7 +182,7 @@ void setup() { initialize_camera(); -// config_camera(); + config_camera(); Serial.println("ESP32-CAM Camera initialized"); @@ -327,9 +327,9 @@ void config_camera() { sensor_t * s = esp_camera_sensor_get(); - s->set_brightness(s, 2); // -2 to 2 +// s->set_brightness(s, 2); // -2 to 2 // s->set_contrast(s, 0); // -2 to 2 - s->set_saturation(s, 1); // -2 to 2 +// s->set_saturation(s, 1); // -2 to 2 s->set_hmirror(s, 1); // 0 = disable , 1 = enable s->set_vflip(s, 1); } From 08c5548121aad9b5c55745b5b9b77c3f2027da17 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 7 Sep 2022 15:19:40 -0400 Subject: [PATCH 044/134] just vertical flip --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index e2ddfb65..79b33663 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -330,7 +330,7 @@ void config_camera() { // s->set_brightness(s, 2); // -2 to 2 // s->set_contrast(s, 0); // -2 to 2 // s->set_saturation(s, 1); // -2 to 2 - s->set_hmirror(s, 1); // 0 = disable , 1 = enable +// s->set_hmirror(s, 1); // 0 = disable , 1 = enable s->set_vflip(s, 1); } From 5d7f54c4cf1d682fd10fa74d2f8243ad832adcb2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 7 Sep 2022 15:26:09 -0400 Subject: [PATCH 045/134] just mirror --- .../esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino index 79b33663..fcb62e9d 100644 --- a/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino +++ b/cubesatsim/esp32-cam-send-jpeg-serial/esp32-cam-send-jpeg-serial.ino @@ -330,8 +330,8 @@ void config_camera() { // s->set_brightness(s, 2); // -2 to 2 // s->set_contrast(s, 0); // -2 to 2 // s->set_saturation(s, 1); // -2 to 2 -// s->set_hmirror(s, 1); // 0 = disable , 1 = enable - s->set_vflip(s, 1); + s->set_hmirror(s, 1); // 0 = disable , 1 = enable +// s->set_vflip(s, 1); } void initialize_camera() { From 9d34c3e2965eaf20569d3cb14c1942e1e1f9815c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:14:50 -0400 Subject: [PATCH 046/134] added clockgen instead of PWM --- cubesatsim/cubesatsim.ino | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 8084baa4..0994f5e2 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -41,6 +41,7 @@ #include "hardware/adc.h" #include "SSTV-Arduino-Scottie1-Library.h" #include "LittleFS.h" +#include // jpg files to be stored in flash storage on Pico (FS 512kB setting) #include "sstv1.h" @@ -55,6 +56,8 @@ Adafruit_INA219 ina219_2_0x41(0x41); Adafruit_INA219 ina219_2_0x44(0x44); Adafruit_INA219 ina219_2_0x45(0x45); +Adafruit_SI5351 clockgen = Adafruit_SI5351(); + //WiFiServer server(port); //WiFiClient client; @@ -143,7 +146,8 @@ void setup() { camera_detected = start_camera(); start_isr(); - start_pwm(); +// start_pwm(); + start_clockgen(); /**/ Serial.println("Transmitting callsign"); @@ -481,8 +485,9 @@ void transmit_on() { else if (mode == BPSK) { if (debug_mode) Serial.println("Transmit on!"); - pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); - pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); +// pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); +// pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); + clockgen.enableOutputs(true); } else if (mode == CW) { // Serial.println("Transmit on!"); @@ -501,8 +506,9 @@ void transmit_off() { if (mode == BPSK) { digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, LOW); - pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); - pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); +// pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); +// pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); + clockgen.enableOutputs(true); } else if (mode == SSTV) sstv_end(); @@ -3446,13 +3452,15 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { - digitalWrite(BPSK_CONTROL_A, HIGH); +// digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, LOW); +// digitalWrite(BPSK_CONTROL_B, LOW); + clockgen.enableOutputOnly(1); } else { - digitalWrite(BPSK_CONTROL_B, HIGH); +// digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, LOW); +// digitalWrite(BPSK_CONTROL_A, LOW); + clockgen.enableOutputOnly(0); } /* tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; @@ -4295,3 +4303,17 @@ void write_mode() { mode_file.close(); // Serial.println("Write complete"); } + +void start_clockgen() { + + if (clockgen.begin() != ERROR_NONE) + { + /* There was a problem detecting the IC ... check your connections */ + Serial.print("No Si5351 detected ... Check your wiring or I2C ADDR!"); + return; + } + + clockgen.setClockBuilderData(); + clockgen.enableOutputs(false); + +} From 2aa1175a185a10c869122b369676bee3cc7a6833 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:21:49 -0400 Subject: [PATCH 047/134] added start_clockgen --- cubesatsim/cubesatsim.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 15482d55..bcdbd378 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -208,6 +208,8 @@ void read_config_file(); void write_config_file(); void read_mode(); void write_mode(); +void start_clockgen(); + #ifndef STASSID #define STASSID "Pico" From b85e408a0b1c042e0508084558b89c0d619acd2b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:23:54 -0400 Subject: [PATCH 048/134] transmit_off disable clock outputs --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0994f5e2..5dbc9b79 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -508,7 +508,7 @@ void transmit_off() { digitalWrite(BPSK_CONTROL_B, LOW); // pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); // pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); - clockgen.enableOutputs(true); + clockgen.enableOutputs(false); } else if (mode == SSTV) sstv_end(); @@ -4313,6 +4313,8 @@ void start_clockgen() { return; } + Serial.println("Starting clockgen"); + clockgen.setClockBuilderData(); clockgen.enableOutputs(false); From 959ecb98ae3938206753f2cac05c1b6a9611e732 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:30:07 -0400 Subject: [PATCH 049/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 5dbc9b79..d004fa20 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -484,10 +484,10 @@ void transmit_on() { } else if (mode == BPSK) { if (debug_mode) - Serial.println("Transmit on!"); -// pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); -// pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); - clockgen.enableOutputs(true); + Serial.println("Transmit on!!!"); +// pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); +// pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); + clockgen.enableOutputs(true); } else if (mode == CW) { // Serial.println("Transmit on!"); From 3654affdc199f9f5f2942f2813e1d28b962a2f0c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:39:40 -0400 Subject: [PATCH 050/134] prints --- cubesatsim/cubesatsim.ino | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d004fa20..c6c4a8d6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -90,6 +90,8 @@ void setup() { config_gpio(); + start_clockgen(); + EEPROM.begin(512); #ifndef ARDUINO_ARCH_RP2040 @@ -147,7 +149,6 @@ void setup() { start_isr(); // start_pwm(); - start_clockgen(); /**/ Serial.println("Transmitting callsign"); @@ -3446,22 +3447,22 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); - while ((micros() - micro_timer2) < 832) { } - busy_wait_at_least_cycles(51); // 300 ns + while ((micros() - micro_timer2) < 832) { } + busy_wait_at_least_cycles(51); // 300 ns // if ((micros() - micro_timer2) > 834) // Serial.println(micros() - micro_timer2); - micro_timer2 = micros(); - if (buffer[wav_position++] > 0) { + micro_timer2 = micros(); + if (buffer[wav_position++] > 0) { // digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); // digitalWrite(BPSK_CONTROL_B, LOW); - clockgen.enableOutputOnly(1); - } else { + clockgen.enableOutputOnly(1); + } else { // digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); // digitalWrite(BPSK_CONTROL_A, LOW); - clockgen.enableOutputOnly(0); - } + clockgen.enableOutputOnly(0); + } /* tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; @@ -3480,12 +3481,12 @@ bool TimerHandler0(struct repeating_timer *t) { pwm_init(bpsk_pin_slice, &config, true); pwm_set_gpio_level(BPSK_PWM_PIN, (config.top + 1) * 0.5); */ - if (wav_position > bufLen) { // 300) { + if (wav_position > bufLen) { // 300) { wav_position = wav_position - bufLen; // Serial.print("\nR"); // Serial.print(" "); // Serial.println(millis()); -/* +/**/ if ((micros() - micro_timer)/bufLen > 835) { if (bufLen != 0) { Serial.print("R Microseconds: "); @@ -3493,7 +3494,7 @@ bool TimerHandler0(struct repeating_timer *t) { } } micro_timer = micros(); -*/ +/**/ } else { // Serial.print("R' Microseconds: "); // Serial.println(micros() - micro_timer2); From 69884aab4aafa6df8f2c26f9a9f97f2f660e3626 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:45:40 -0400 Subject: [PATCH 051/134] prints and 400us --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c6c4a8d6..40c14815 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3456,11 +3456,13 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); // digitalWrite(BPSK_CONTROL_B, LOW); + Serial.print("-"); clockgen.enableOutputOnly(1); } else { // digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); // digitalWrite(BPSK_CONTROL_A, LOW); + Serial.print("_"); clockgen.enableOutputOnly(0); } /* @@ -3526,7 +3528,7 @@ void start_isr() { // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) - if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was was 828 (841) and 828 + if (ITimer0.attachInterruptInterval(400, TimerHandler0)) // was 800 // was was 828 (841) and 828 // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From ca1a97f928041e998b21389f5e0d50f2aa31ec5f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 15:56:04 -0400 Subject: [PATCH 052/134] try 100 --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 40c14815..65e5ddf2 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3528,7 +3528,7 @@ void start_isr() { // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) - if (ITimer0.attachInterruptInterval(400, TimerHandler0)) // was 800 // was was 828 (841) and 828 + if (ITimer0.attachInterruptInterval(100, TimerHandler0)) // was 800 // was was 828 (841) and 828 // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From 2a37b56ce1e40aa8e9f8aafa2640a08e3f716c51 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 16:01:03 -0400 Subject: [PATCH 053/134] back to 400 --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 65e5ddf2..40c14815 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3528,7 +3528,7 @@ void start_isr() { // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) - if (ITimer0.attachInterruptInterval(100, TimerHandler0)) // was 800 // was was 828 (841) and 828 + if (ITimer0.attachInterruptInterval(400, TimerHandler0)) // was 800 // was was 828 (841) and 828 // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From bf37b72bbd7490eba2cccd34f7b3fc6d62e66fca Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 16:46:22 -0400 Subject: [PATCH 054/134] clockgen signals now controlled through analog switches --- cubesatsim/cubesatsim.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 40c14815..9ec37ded 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3453,17 +3453,17 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { -// digitalWrite(BPSK_CONTROL_A, HIGH); + digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); -// digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); Serial.print("-"); - clockgen.enableOutputOnly(1); +// clockgen.enableOutputOnly(1); } else { -// digitalWrite(BPSK_CONTROL_B, HIGH); + digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); -// digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, LOW); Serial.print("_"); - clockgen.enableOutputOnly(0); +// clockgen.enableOutputOnly(0); } /* tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; From a6a0a29e5bf2cd8f69898b18fe1445f22d8232d0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 16:48:36 -0400 Subject: [PATCH 055/134] back to 800us --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9ec37ded..8fc7608b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3528,7 +3528,7 @@ void start_isr() { // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) - if (ITimer0.attachInterruptInterval(400, TimerHandler0)) // was 800 // was was 828 (841) and 828 + if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was 800 // was was 828 (841) and 828 // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From b010b82a824c47bcf4e1b83164f36f4865934d97 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 16:51:27 -0400 Subject: [PATCH 056/134] removed -_ prints --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 8fc7608b..bcde5155 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3456,13 +3456,13 @@ bool TimerHandler0(struct repeating_timer *t) { digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); digitalWrite(BPSK_CONTROL_B, LOW); - Serial.print("-"); +// Serial.print("-"); // clockgen.enableOutputOnly(1); } else { digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); digitalWrite(BPSK_CONTROL_A, LOW); - Serial.print("_"); +// Serial.print("_"); // clockgen.enableOutputOnly(0); } /* From 1a05730fcfdd8b622b142d7ebd24d09fdc9c673f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 17:00:22 -0400 Subject: [PATCH 057/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bcde5155..f9bd747f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1372,8 +1372,8 @@ void write_wave(int i, byte *buffer) if (ctr > bufLen) { ctr = ctr - bufLen; if (debug_mode) { -// Serial.print("\r"); -// Serial.print(" "); + Serial.print("\r"); + Serial.print(" "); Serial.println(millis()); } } @@ -3453,15 +3453,15 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { - digitalWrite(BPSK_CONTROL_A, HIGH); + digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { - digitalWrite(BPSK_CONTROL_B, HIGH); + digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, LOW); // Serial.print("_"); // clockgen.enableOutputOnly(0); } @@ -4316,7 +4316,7 @@ void start_clockgen() { return; } - Serial.println("Starting clockgen"); + Serial.println("Starting clockgen frequency 434.896 MHz"); clockgen.setClockBuilderData(); clockgen.enableOutputs(false); From c49e3bcbb6c54b254605f514c15833df74320599 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 17:05:04 -0400 Subject: [PATCH 058/134] buffer short int --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index bcdbd378..f4e6818f 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -234,7 +234,7 @@ long time_start; //FILE * file1;// #define BUFFER_SIZE 5841 //970 // (970 * 2) // * 2) //short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK -byte buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK +short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK //short int buffer[(WAV_DATA_LENGTH/8)]; //FILE *sopen(const char *program); char tlm_str[1000]; From e4ccc6109435115c1c71dc57f38117308af6e11f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 17:06:12 -0400 Subject: [PATCH 059/134] fixed buffer error --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f9bd747f..c0688a72 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1352,7 +1352,7 @@ void write_wave(int i, byte *buffer) // if ((ctr - flip_ctr) < smaller) // No wave shaping // buffer[ctr++] = (short int)(0.1 * phase * (ctr - flip_ctr) / smaller); // else - buffer[ctr++] = (short int)(0.25 * amplitude * phase); + buffer[ctr++] = (byte)(0.25 * amplitude * phase); // Serial.print(buffer[ctr - 1]); // Serial.print(" "); } @@ -1364,7 +1364,7 @@ void write_wave(int i, byte *buffer) // else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); // buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - buffer[ctr++] = (short int)(phase); + buffer[ctr++] = (byte)(phase); } // printf("%d %d \n", i, buffer[ctr - 1]); // if (ctr > BUFFER_SIZE) { From 50b0e789ca863216777c4f5e5c243e60894ee017 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 17:06:45 -0400 Subject: [PATCH 060/134] back to byte --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index f4e6818f..bcdbd378 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -234,7 +234,7 @@ long time_start; //FILE * file1;// #define BUFFER_SIZE 5841 //970 // (970 * 2) // * 2) //short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK -short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK +byte buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK //short int buffer[(WAV_DATA_LENGTH/8)]; //FILE *sopen(const char *program); char tlm_str[1000]; From 1f475ffc1990d02a81d7b10f23b06adbd5a8a4eb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 21:49:47 -0400 Subject: [PATCH 061/134] changed write_wave to byte buffer --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index bcdbd378..6cf3db8a 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -263,7 +263,7 @@ int ctr = 0; int rd = 0; int nrd; void write_to_buffer(int i, int symbol, int val); -void write_wave(int i, short int * buffer); +void write_wave(int i, byte * buffer); void sleep(float time); int uart_fd; From 2ae7b3067b9c4ab86236969da1060abf3c077981 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 21:55:53 -0400 Subject: [PATCH 062/134] wav_position modulo instead of - length --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c0688a72..ce0bf7a4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3484,7 +3484,7 @@ bool TimerHandler0(struct repeating_timer *t) { pwm_set_gpio_level(BPSK_PWM_PIN, (config.top + 1) * 0.5); */ if (wav_position > bufLen) { // 300) { - wav_position = wav_position - bufLen; + wav_position = wav_position % bufLen; // Serial.print("\nR"); // Serial.print(" "); // Serial.println(millis()); From 7ffb0a8134e49486b86c2160c88065418299dbd8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 22:05:43 -0400 Subject: [PATCH 063/134] print buffer --- cubesatsim/cubesatsim.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ce0bf7a4..dbf0bedd 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1377,6 +1377,8 @@ void write_wave(int i, byte *buffer) Serial.println(millis()); } } + Serial.printf(" c: b: %d is %d ", ctr - 1, buffer[ctr - 1]); + } int encodeA(short int *b, int index, int val) { From 5060aa3cf609fb5701df1b2c2e66793b5c54d61d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 22:14:02 -0400 Subject: [PATCH 064/134] fixed phase to byte conversion --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index dbf0bedd..827fafa6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1364,7 +1364,7 @@ void write_wave(int i, byte *buffer) // else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); // buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - buffer[ctr++] = (byte)(phase); + buffer[ctr++] = (byte)(phase == 1); } // printf("%d %d \n", i, buffer[ctr - 1]); // if (ctr > BUFFER_SIZE) { @@ -1377,7 +1377,7 @@ void write_wave(int i, byte *buffer) Serial.println(millis()); } } - Serial.printf(" c: b: %d is %d ", ctr - 1, buffer[ctr - 1]); + Serial.printf(" b: %d ", buffer[ctr - 1]); } From b29749cf514cbc08aa8b9fdcc83ef6104c95260a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 22:23:24 -0400 Subject: [PATCH 065/134] removed b printout --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 827fafa6..c8643a51 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1377,7 +1377,7 @@ void write_wave(int i, byte *buffer) Serial.println(millis()); } } - Serial.printf(" b: %d ", buffer[ctr - 1]); +// Serial.printf(" b: %d ", buffer[ctr - 1]); } @@ -3490,13 +3490,13 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print("\nR"); // Serial.print(" "); // Serial.println(millis()); -/**/ +/**/ if ((micros() - micro_timer)/bufLen > 835) { if (bufLen != 0) { Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } - } + } micro_timer = micros(); /**/ } else { From a92fc9c0929e9548887eab6963c11cc8eb19e218 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 8 Sep 2022 22:37:24 -0400 Subject: [PATCH 066/134] reverted back one --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c8643a51..827fafa6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1377,7 +1377,7 @@ void write_wave(int i, byte *buffer) Serial.println(millis()); } } -// Serial.printf(" b: %d ", buffer[ctr - 1]); + Serial.printf(" b: %d ", buffer[ctr - 1]); } @@ -3490,13 +3490,13 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print("\nR"); // Serial.print(" "); // Serial.println(millis()); -/**/ +/**/ if ((micros() - micro_timer)/bufLen > 835) { if (bufLen != 0) { Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } - } + } micro_timer = micros(); /**/ } else { From 1b4000fa9d6938c67d48bdacf8ba8ce0b8d1146d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 9 Sep 2022 21:03:24 -0400 Subject: [PATCH 067/134] removed b: print --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 827fafa6..281c8dc3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1377,7 +1377,7 @@ void write_wave(int i, byte *buffer) Serial.println(millis()); } } - Serial.printf(" b: %d ", buffer[ctr - 1]); +// Serial.printf(" b: %d ", buffer[ctr - 1]); } From 9540e244584a97dee4428b0256000d7630b9d693 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 9 Sep 2022 21:34:57 -0400 Subject: [PATCH 068/134] added back FSK --- cubesatsim/cubesatsim.ino | 89 ++++++++++++++------------------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 281c8dc3..67bd1bc3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -483,7 +483,7 @@ void transmit_on() { digitalWrite(MAIN_LED_BLUE, HIGH); digitalWrite(PTT_PIN, LOW); } - else if (mode == BPSK) { + else if ((mode == BPSK) || (mode == FSK)) { if (debug_mode) Serial.println("Transmit on!!!"); // pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); @@ -504,7 +504,7 @@ void transmit_off() { Serial.println("Transmit off!"); digitalWrite(MAIN_LED_BLUE, LOW); // ITimer0.stopTimer(); // stop BPSK ISR timer - if (mode == BPSK) { + if ((mode == BPSK) || (mode = FSK)) { digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, LOW); // pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); @@ -534,7 +534,7 @@ void config_telem() { if (mode == FSK) { Serial.println("Configuring for FSK\n"); bitRate = 200; - delay_time = (1.0 / 200.0); + delay_time = 1E6 / bitRate; rsFrames = 1; payloads = 1; rsFrameLen = 64; @@ -563,7 +563,7 @@ void config_telem() { Serial.println("Configuring for BPSK\n"); bitRate = 1200; // delay_time = (1.0 / 1200.0); - delay_time = (1.0 / 200.0); + delay_time = 1E6 / bitRate; rsFrames = 3; payloads = 6; rsFrameLen = 159; @@ -1282,19 +1282,14 @@ void get_tlm_fox() { data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d sync bit %d = %d \n", // ctr/SAMPLES, i, frames, bit, (data > 0) ); - if (mode == FSK) { - phase = ((data != 0) * 2) - 1; + /// if (mode == FSK) { + /// phase = ((data != 0) * 2) - 1; // printf("Sending a %d\n", phase); - } else { + /// } else { if (data == 0) { phase *= -1; -// if ((ctr - smaller) > 0) { -// for (int j = 1; j <= smaller; j++) -// buffer[ctr - j] = buffer[ctr - j] * 0.4; - // } -// flip_ctr = ctr; } - } + /// } } } /// #ifdef DEBUG_LOGGING @@ -1314,10 +1309,10 @@ void get_tlm_fox() { // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); // Serial.print(data, BIN); // Debugging print!!! // Serial.print(" "); - if (mode == FSK) { - phase = ((data != 0) * 2) - 1; +/// if (mode == FSK) { +/// phase = ((data != 0) * 2) - 1; // printf("Sending a %d\n", phase); - } else { +/// } else { if (data == 0) { phase *= -1; // if ((ctr - smaller) > 0) { @@ -1326,7 +1321,7 @@ void get_tlm_fox() { // } // flip_ctr = ctr; } - } +/// } // Serial.println("AA"); } // Serial.println("BB"); @@ -1347,36 +1342,15 @@ void get_tlm_fox() { //void write_wave(int i, short int *buffer) void write_wave(int i, byte *buffer) { - if (mode == FSK) - { -// if ((ctr - flip_ctr) < smaller) // No wave shaping -// buffer[ctr++] = (short int)(0.1 * phase * (ctr - flip_ctr) / smaller); -// else - buffer[ctr++] = (byte)(0.25 * amplitude * phase); -// Serial.print(buffer[ctr - 1]); -// Serial.print(" "); - } - else - { -// if ((ctr - flip_ctr) < smaller) - // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); -// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); -// else - // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); -// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - buffer[ctr++] = (byte)(phase == 1); - } - // printf("%d %d \n", i, buffer[ctr - 1]); -// if (ctr > BUFFER_SIZE) { -// ctr = ctr - BUFFER_SIZE; - if (ctr > bufLen) { - ctr = ctr - bufLen; - if (debug_mode) { - Serial.print("\r"); - Serial.print(" "); - Serial.println(millis()); - } + buffer[ctr++] = (byte)(phase == 1); + if (ctr > bufLen) { + ctr = ctr - bufLen; + if (debug_mode) { + Serial.print("\r"); + Serial.print(" "); + Serial.println(millis()); } + } // Serial.printf(" b: %d ", buffer[ctr - 1]); } @@ -3198,10 +3172,9 @@ void process_pushbutton() { pb_value = digitalRead(MAIN_PB_PIN); if ((pb_value == RELEASED) && (release == FALSE)) { - Serial.println("PB: FSK not supported"); + Serial.println("PB: Switch to FSK"); release = TRUE; -// new_mode = FSK; -// setup(); + new_mode = FSK; } if (release == FALSE) { @@ -3296,10 +3269,9 @@ void process_bootsel() { // pb_value = digitalRead(MAIN_PB_PIN); if ((!BOOTSEL) && (release == FALSE)) { - Serial.println("BOOTSEL: FSK not supported"); + Serial.println("BOOTSEL: Switch to FSK"); release = TRUE; -// new_mode = FSK; -// setup(); + new_mode = FSK; } if (release == FALSE) { @@ -3445,12 +3417,13 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); - if (mode == BPSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future + if ((mode == BPSK) || (mode == FSK)) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); - while ((micros() - micro_timer2) < 832) { } - busy_wait_at_least_cycles(51); // 300 ns + while ((micros() - micro_timer2) < delay_time) { } + if (mode == BPSK) + busy_wait_at_least_cycles(51); // 300 ns // if ((micros() - micro_timer2) > 834) // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); @@ -3491,7 +3464,7 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print(" "); // Serial.println(millis()); /**/ - if ((micros() - micro_timer)/bufLen > 835) { + if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { if (bufLen != 0) { Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); @@ -3530,7 +3503,9 @@ void start_isr() { // if (ITimer0.attachInterruptInterval(833, TimerHandler0)) // if (ITimer0.attachInterruptInterval(804, TimerHandler0)) - if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was 800 // was was 828 (841) and 828 +// if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was 800 // was was 828 (841) and 828 + + if (ITimer0.attachInterruptInterval(delay_time - 32, TimerHandler0)) // was 800 // was was 828 (841) and 828 // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From 154042652f565c2ebe1588811793c8dc5ff21a8b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 9 Sep 2022 21:35:04 -0400 Subject: [PATCH 069/134] delay_time int for FSK --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 6cf3db8a..87c2c4c9 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -339,7 +339,7 @@ int pwm_amplitude = 50; //50 //100; int pwm_value; int tx_bit = 1; */ -float delay_time; +unsigned long delay_time; bool polarity = true; pwm_config config; int bpsk_pin_slice_A; From ad63516a3dd244b54e45c1286074b0015a52b8b2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 9 Sep 2022 21:47:46 -0400 Subject: [PATCH 070/134] updated for setClockFSK and BPSK --- cubesatsim/cubesatsim.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 67bd1bc3..2b05a156 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2086,7 +2086,7 @@ void config_radio() pinMode(TEMPERATURE_PIN, INPUT); pinMode(AUDIO_IN_PIN, INPUT); */ - if ((mode == AFSK) || (mode == FSK) || (mode == SSTV) || (mode == CW)) { + if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { digitalWrite(PD_PIN, HIGH); // Enable SR_FRS @@ -2098,12 +2098,14 @@ void config_radio() // transmit_on(); } else if (mode == BPSK) { // start_pwm(); -// start_isr(); +// start_isr(); + clockgen.setClockBPSK(); transmit_on(); } if ((mode == FSK)) // || (mode == SSTV)) // start_isr(); + clockgen.setClockBPSK(); transmit_on(); } @@ -4295,7 +4297,7 @@ void start_clockgen() { Serial.println("Starting clockgen frequency 434.896 MHz"); - clockgen.setClockBuilderData(); + clockgen.setClockFSK(); // default to FSK clockgen.enableOutputs(false); } From dec58808c957285cb3f6365ec1778c9efccfbc6c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:06:37 -0400 Subject: [PATCH 071/134] = instead of == --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 2b05a156..d6955f3e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -86,7 +86,7 @@ void setup() { // otherwise, run CubeSatSim Pico code - Serial.println("CubeSatSim Pico v0.23 starting...\n"); + Serial.println("CubeSatSim Pico v0.24 starting...\n"); config_gpio(); @@ -145,7 +145,7 @@ void setup() { setup_sstv(); - camera_detected = start_camera(); + camera_detected = false; // start_camera(); start_isr(); // start_pwm(); @@ -504,7 +504,7 @@ void transmit_off() { Serial.println("Transmit off!"); digitalWrite(MAIN_LED_BLUE, LOW); // ITimer0.stopTimer(); // stop BPSK ISR timer - if ((mode == BPSK) || (mode = FSK)) { + if ((mode == BPSK) || (mode == FSK)) { digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, LOW); // pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); From 33c9d85f1685e315b3750597595cc8b84ee71cc0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:12:48 -0400 Subject: [PATCH 072/134] print delay_time --- cubesatsim/cubesatsim.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d6955f3e..2513e01b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -535,6 +535,7 @@ void config_telem() { Serial.println("Configuring for FSK\n"); bitRate = 200; delay_time = 1E6 / bitRate; + Serial.println(delay_time); rsFrames = 1; payloads = 1; rsFrameLen = 64; @@ -564,6 +565,7 @@ void config_telem() { bitRate = 1200; // delay_time = (1.0 / 1200.0); delay_time = 1E6 / bitRate; + Serial.println(delay_time); rsFrames = 3; payloads = 6; rsFrameLen = 159; @@ -3466,12 +3468,12 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print(" "); // Serial.println(millis()); /**/ - if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { +// if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { if (bufLen != 0) { Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } - } +// } micro_timer = micros(); /**/ } else { From 4f7e20d436a589fd87bf1204a057e244c4c6f806 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:18:04 -0400 Subject: [PATCH 073/134] print phase --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 2513e01b..a8be7dbd 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1313,7 +1313,7 @@ void get_tlm_fox() { // Serial.print(" "); /// if (mode == FSK) { /// phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); + printf("Sending a %d\n", phase); /// } else { if (data == 0) { phase *= -1; From 5a33d279cd4f69a7957b81ecac406802bd65bb5d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:21:55 -0400 Subject: [PATCH 074/134] add serial config FSK --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a8be7dbd..1109998b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3905,7 +3905,8 @@ void serial_input() { case 'f': case 'F': - Serial.println("FSK/DUV mode not supported"); + Serial.println("Change to FSK mode"); + new_mode = FSK; break; case 'b': From df8f45fd30ce921a5b2319fa2b01169896221ede Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:43:32 -0400 Subject: [PATCH 075/134] fixed print --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1109998b..4bf59c2a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1313,7 +1313,7 @@ void get_tlm_fox() { // Serial.print(" "); /// if (mode == FSK) { /// phase = ((data != 0) * 2) - 1; - printf("Sending a %d\n", phase); + Serial.printf("Sending a %d\n", phase); /// } else { if (data == 0) { phase *= -1; From 3dd49a550193c3fe7730fde2aaa2ee2c5e24b6d6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:46:31 -0400 Subject: [PATCH 076/134] print buffer --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4bf59c2a..310e858d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1344,7 +1344,8 @@ void get_tlm_fox() { //void write_wave(int i, short int *buffer) void write_wave(int i, byte *buffer) { - buffer[ctr++] = (byte)(phase == 1); + buffer[ctr++] = (byte)(phase == 1); + Serial.printf("buffer is %d \n", buffer[ctr - 1]); if (ctr > bufLen) { ctr = ctr - bufLen; if (debug_mode) { From cdb31c1ac9a35a7376c314c721450d0c0010cbce Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:49:07 -0400 Subject: [PATCH 077/134] delay_time volatile --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 87c2c4c9..8462eca7 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -339,7 +339,7 @@ int pwm_amplitude = 50; //50 //100; int pwm_value; int tx_bit = 1; */ -unsigned long delay_time; +volatile unsigned long delay_time; bool polarity = true; pwm_config config; int bpsk_pin_slice_A; From f58966f384418d61581c596e8f1548c0fe9d2eaa Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:49:16 -0400 Subject: [PATCH 078/134] print in handler --- cubesatsim/cubesatsim.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 310e858d..4b147341 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1313,7 +1313,7 @@ void get_tlm_fox() { // Serial.print(" "); /// if (mode == FSK) { /// phase = ((data != 0) * 2) - 1; - Serial.printf("Sending a %d\n", phase); +// Serial.printf("Sending a %d\n", phase); /// } else { if (data == 0) { phase *= -1; @@ -1345,7 +1345,7 @@ void get_tlm_fox() { void write_wave(int i, byte *buffer) { buffer[ctr++] = (byte)(phase == 1); - Serial.printf("buffer is %d \n", buffer[ctr - 1]); +// Serial.printf("buffer is %d \n", buffer[ctr - 1]); if (ctr > bufLen) { ctr = ctr - bufLen; if (debug_mode) { @@ -3423,9 +3423,9 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); if ((mode == BPSK) || (mode == FSK)) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future -// Serial.print("l1 "); -// Serial.print(wav_position); -// Serial.print(" "); + Serial.print("l1 "); + Serial.print(wav_position); + Serial.print(" "); while ((micros() - micro_timer2) < delay_time) { } if (mode == BPSK) busy_wait_at_least_cycles(51); // 300 ns From 6e6d1153bf00ae50bb03fc0407d5035a6ec7f6d0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:52:57 -0400 Subject: [PATCH 079/134] move start_isr --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4b147341..ad094d99 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -147,7 +147,6 @@ void setup() { camera_detected = false; // start_camera(); - start_isr(); // start_pwm(); /**/ @@ -160,6 +159,8 @@ void setup() { config_telem(); + start_isr(); + // setup radio depending on mode config_radio(); From fa25ff91614e0c7b0242ab8ef78dac800b1f1f5e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 10 Sep 2022 08:57:29 -0400 Subject: [PATCH 080/134] remove prints in handler --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ad094d99..54031051 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3424,9 +3424,9 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); if ((mode == BPSK) || (mode == FSK)) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future - Serial.print("l1 "); - Serial.print(wav_position); - Serial.print(" "); +// Serial.print("l1 "); +// Serial.print(wav_position); +// Serial.print(" "); while ((micros() - micro_timer2) < delay_time) { } if (mode == BPSK) busy_wait_at_least_cycles(51); // 300 ns From 97af49c67cba3c8e6293969a199986f05303f697 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 11 Sep 2022 08:35:33 -0400 Subject: [PATCH 081/134] switch order of switch control --- cubesatsim/cubesatsim.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 54031051..0d189c1e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3434,15 +3434,17 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { + digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, LOW); +// digitalWrite(BPSK_CONTROL_B, LOW); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { + digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, LOW); +// digitalWrite(BPSK_CONTROL_A, LOW); // Serial.print("_"); // clockgen.enableOutputOnly(0); } From 724a82222b75e5efb0b3c36f7bbde34035c0eb9c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 11 Sep 2022 08:46:04 -0400 Subject: [PATCH 082/134] print bufLen --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0d189c1e..662fe4b3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -551,7 +551,7 @@ void config_telem() { samples = sample_rate / bitRate; // Serial.println(samples); bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); -// Serial.println(bufLen); + Serial.println(bufLen); samplePeriod = (int) (((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen)))) / (float) bitRate) * 1000 - 500); sleepTime = 0.1; // Serial.println(samplePeriod); From 6cf63a6a221f08bad1eb253807268ebe4bbc7bbe Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 11 Sep 2022 08:49:44 -0400 Subject: [PATCH 083/134] switch controls back --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 662fe4b3..0b9aa842 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3434,17 +3434,17 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); if (buffer[wav_position++] > 0) { - digitalWrite(BPSK_CONTROL_B, LOW); +// digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_A, HIGH); // delayMicroseconds(2); -// digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { - digitalWrite(BPSK_CONTROL_A, LOW); +// digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, HIGH); // delayMicroseconds(2); -// digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, LOW); // Serial.print("_"); // clockgen.enableOutputOnly(0); } From a72c4ff9d4b1816d4bc19df2cd766ffaffc68ce9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 11 Sep 2022 08:58:28 -0400 Subject: [PATCH 084/134] print ctr reset --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0b9aa842..66c4a5ed 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1349,11 +1349,11 @@ void write_wave(int i, byte *buffer) // Serial.printf("buffer is %d \n", buffer[ctr - 1]); if (ctr > bufLen) { ctr = ctr - bufLen; - if (debug_mode) { - Serial.print("\r"); - Serial.print(" "); +// if (debug_mode) { + Serial.print("ctr reset "); +// Serial.print(" "); Serial.println(millis()); - } +// } } // Serial.printf(" b: %d ", buffer[ctr - 1]); From 999f9e1148fdfc0abbcce7cae371e13eb09dfd26 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 11 Sep 2022 09:02:53 -0400 Subject: [PATCH 085/134] bufLen 2000 --- cubesatsim/cubesatsim.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 66c4a5ed..bd97ee68 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -551,6 +551,7 @@ void config_telem() { samples = sample_rate / bitRate; // Serial.println(samples); bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); + bufLen = 2000; Serial.println(bufLen); samplePeriod = (int) (((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen)))) / (float) bitRate) * 1000 - 500); sleepTime = 0.1; From 660115e9e3c414e50b2002081be617943dce04af Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 09:32:13 -0400 Subject: [PATCH 086/134] add RR --- cubesatsim/cubesatsim.ino | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bd97ee68..7956ab1d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -58,6 +58,8 @@ Adafruit_INA219 ina219_2_0x45(0x45); Adafruit_SI5351 clockgen = Adafruit_SI5351(); +unsigned long micros3; + //WiFiServer server(port); //WiFiClient client; @@ -1352,8 +1354,15 @@ void write_wave(int i, byte *buffer) ctr = ctr - bufLen; // if (debug_mode) { Serial.print("ctr reset "); + if (bufLen != 0) { + Serial.print("RR Microseconds: "); + Serial.println((float)(micros() - micros3)/(float)bufLen); + } +// } + micros3 = micros(); + // Serial.print(" "); - Serial.println(millis()); +// Serial.println(millis()); // } } // Serial.printf(" b: %d ", buffer[ctr - 1]); From 4e839aaa4a682a406af804a2f4bcdfda86faa4ac Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 09:40:30 -0400 Subject: [PATCH 087/134] bufLen 970 --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7956ab1d..4acb6ade 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -553,7 +553,7 @@ void config_telem() { samples = sample_rate / bitRate; // Serial.println(samples); bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); - bufLen = 2000; + bufLen = 970; // 2000; Serial.println(bufLen); samplePeriod = (int) (((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen)))) / (float) bitRate) * 1000 - 500); sleepTime = 0.1; From b85196b27e2fb55b07120568d34185e8a3ad0fde Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 09:47:05 -0400 Subject: [PATCH 088/134] setClockFSK --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4acb6ade..8e214af3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2119,7 +2119,7 @@ void config_radio() if ((mode == FSK)) // || (mode == SSTV)) // start_isr(); - clockgen.setClockBPSK(); + clockgen.setClockFSK(); transmit_on(); } From 47a7c1c0eb4ebaf2751a7d76102a3a4e6d20e2e2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 13:44:44 -0400 Subject: [PATCH 089/134] fixed FSK bit encoding --- cubesatsim/cubesatsim.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 8e214af3..c0af84ba 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1288,14 +1288,15 @@ void get_tlm_fox() { data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d sync bit %d = %d \n", // ctr/SAMPLES, i, frames, bit, (data > 0) ); - /// if (mode == FSK) { - /// phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - /// } else { + if (mode == FSK) { + phase = ((data != 0) * 2) - 1; + } else { if (data == 0) { phase *= -1; - } - /// } + } + // printf("Sending a %d\n", phase); + + } } } /// #ifdef DEBUG_LOGGING From 18dd0df2257902b748f1f848cc780777013b3bdb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 14:02:38 -0400 Subject: [PATCH 090/134] fixed FSK bit in other place --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c0af84ba..ffe3fff1 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1316,16 +1316,16 @@ void get_tlm_fox() { // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); // Serial.print(data, BIN); // Debugging print!!! // Serial.print(" "); -/// if (mode == FSK) { -/// phase = ((data != 0) * 2) - 1; + if (mode == FSK) { + phase = ((data != 0) * 2) - 1; // Serial.printf("Sending a %d\n", phase); -/// } else { + } else { if (data == 0) { phase *= -1; // if ((ctr - smaller) > 0) { // for (int j = 1; j <= smaller; j++) // buffer[ctr - j] = buffer[ctr - j] * 0.4; -// } + } // flip_ctr = ctr; } /// } From 6dfcb0a9e3cb4c1b72fb511645ef97d741c33ad5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 14:11:14 -0400 Subject: [PATCH 091/134] print frameTime --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ffe3fff1..475f00e8 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -560,7 +560,7 @@ void config_telem() { // Serial.println(samplePeriod); frameTime = ((float)((float)bufLen / (samples * frameCnt * bitRate))) * 1000; // frame time in ms -// Serial.println(frameTime); + Serial.println(frameTime); // printf("\n FSK Mode, %d bits per frame, %d bits per second, %d ms per frame, %d ms sample period\n", // bufLen / (samples * frameCnt), bitRate, frameTime, samplePeriod); memset(buffer, 0xa5, sizeof(buffer)); From d244ed7f1ba8225204583cfd0e64e162d2c7ae69 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 14:16:20 -0400 Subject: [PATCH 092/134] don't read payload --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 475f00e8..d1d9c230 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -121,7 +121,7 @@ void setup() { // pinMode(PI_3V3_PIN, OUTPUT); // digitalWrite(PI_3V3_PIN, HIGH); - start_payload(); // above code not working, so forcing it +// start_payload(); // above code not working, so forcing it read_config_file(); @@ -191,7 +191,7 @@ void loop() { // query INA219 sensors and Payload sensors read_ina219(); - read_payload(); +// read_payload(); // encode as digits (APRS or CW mode) or binary (DUV FSK) if ((mode == BPSK) || (mode == FSK)) { From 55518089aed89b4b73e3ccf102c09c899e4aa231 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 15:04:35 -0400 Subject: [PATCH 093/134] 2 us no signal between bits --- cubesatsim/cubesatsim.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d1d9c230..0f94c7e7 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3446,16 +3446,16 @@ bool TimerHandler0(struct repeating_timer *t) { micro_timer2 = micros(); if (buffer[wav_position++] > 0) { // digitalWrite(BPSK_CONTROL_B, LOW); - digitalWrite(BPSK_CONTROL_A, HIGH); -// delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); + delayMicroseconds(2); + digitalWrite(BPSK_CONTROL_A, HIGH); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { // digitalWrite(BPSK_CONTROL_A, LOW); - digitalWrite(BPSK_CONTROL_B, HIGH); -// delayMicroseconds(2); - digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, LOW); + delayMicroseconds(2); + digitalWrite(BPSK_CONTROL_B, HIGH); // Serial.print("_"); // clockgen.enableOutputOnly(0); } From 54802c1df18bd8293e8c71ca05b8ed2b589bbba8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 15:06:59 -0400 Subject: [PATCH 094/134] 10 us --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0f94c7e7..0f13ec3e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3447,14 +3447,14 @@ bool TimerHandler0(struct repeating_timer *t) { if (buffer[wav_position++] > 0) { // digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_B, LOW); - delayMicroseconds(2); + delayMicroseconds(10); digitalWrite(BPSK_CONTROL_A, HIGH); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { // digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_A, LOW); - delayMicroseconds(2); + delayMicroseconds(10); digitalWrite(BPSK_CONTROL_B, HIGH); // Serial.print("_"); // clockgen.enableOutputOnly(0); From ccdf01d0a1d0bfdf924f22bc434f0d85b9873024 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 15:09:15 -0400 Subject: [PATCH 095/134] 0us --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0f13ec3e..7077d6a5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3447,14 +3447,14 @@ bool TimerHandler0(struct repeating_timer *t) { if (buffer[wav_position++] > 0) { // digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_B, LOW); - delayMicroseconds(10); +// delayMicroseconds(10); digitalWrite(BPSK_CONTROL_A, HIGH); // Serial.print("-"); // clockgen.enableOutputOnly(1); } else { // digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_A, LOW); - delayMicroseconds(10); +// delayMicroseconds(10); digitalWrite(BPSK_CONTROL_B, HIGH); // Serial.print("_"); // clockgen.enableOutputOnly(0); From cbe388a787c7d3adc300954d574a55dc96a2df60 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 15:29:48 -0400 Subject: [PATCH 096/134] frameTime sleep reduced to 0.01 to increase accuracy --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7077d6a5..e7f73a92 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -266,7 +266,7 @@ void loop() { // while ((millis() - sampleTime) < ((unsigned int)samplePeriod)) // - 250)) // was 250 100 while ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 250)) // was 250 100 - sleep(0.1); // 25); // 0.5); // 25); + sleep(0.01); // was 0.1 sec sampleTime = (unsigned int) millis(); // delay(2000); From 57edfc8ed39a99349e66ba55fc8bb1ad95bce236 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 15:52:01 -0400 Subject: [PATCH 097/134] added setInterval for ISR when change between FSK and BPSK modes --- cubesatsim/cubesatsim.ino | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index e7f73a92..a17b004d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2114,13 +2114,29 @@ void config_radio() } else if (mode == BPSK) { // start_pwm(); // start_isr(); - clockgen.setClockBPSK(); + clockgen.setClockBPSK(); + if (ITimer0.setInterval(delay_time - 32, TimerHandler0)) + { + if (debug_mode) + Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros()); + } + else + Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer")); + transmit_on(); } if ((mode == FSK)) // || (mode == SSTV)) // start_isr(); - clockgen.setClockFSK(); + clockgen.setClockFSK(); + if (ITimer0.setInterval(delay_time - 32, TimerHandler0)) + { + if (debug_mode) + Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros()); + } + else + Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer")); + transmit_on(); } From 3d77b0e3b09fc7c9cfa0d1768b1d02a05c7a509b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:07:33 -0400 Subject: [PATCH 098/134] added ITimer2 --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 8462eca7..746b237d 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -369,6 +369,7 @@ const char sstv2_filename[] = "/sstv_image_2_320_x_240.jpg"; bool TimerHandler0(struct repeating_timer *t); RPI_PICO_Timer ITimer0(0); RPI_PICO_Timer ITimer1(1); +RPI_PICO_Timer ITimer2(2); bool timer0_on = false; From 4dc8a9cd900133f245ace5f50fd66bb5642ea903 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:07:44 -0400 Subject: [PATCH 099/134] added ITimer2 for FSK --- cubesatsim/cubesatsim.ino | 118 ++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a17b004d..3dcbe0bc 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2115,28 +2115,12 @@ void config_radio() // start_pwm(); // start_isr(); clockgen.setClockBPSK(); - if (ITimer0.setInterval(delay_time - 32, TimerHandler0)) - { - if (debug_mode) - Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros()); - } - else - Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer")); - transmit_on(); } if ((mode == FSK)) // || (mode == SSTV)) // start_isr(); - clockgen.setClockFSK(); - if (ITimer0.setInterval(delay_time - 32, TimerHandler0)) - { - if (debug_mode) - Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros()); - } - else - Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer")); - + clockgen.setClockFSK(); transmit_on(); } @@ -3450,13 +3434,12 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); - if ((mode == BPSK) || (mode == FSK)) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future + if (mode == BPSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); while ((micros() - micro_timer2) < delay_time) { } - if (mode == BPSK) - busy_wait_at_least_cycles(51); // 300 ns + busy_wait_at_least_cycles(51); // 300 ns // if ((micros() - micro_timer2) > 834) // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); @@ -3474,25 +3457,65 @@ bool TimerHandler0(struct repeating_timer *t) { digitalWrite(BPSK_CONTROL_B, HIGH); // Serial.print("_"); // clockgen.enableOutputOnly(0); + } + if (wav_position > bufLen) { // 300) { + wav_position = wav_position % bufLen; +// Serial.print("\nR"); +// Serial.print(" "); +// Serial.println(millis()); +/**/ +// if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { + if (bufLen != 0) { + Serial.print("R0 Microseconds: "); + Serial.println((float)(micros() - micro_timer)/(float)bufLen); } +// } + micro_timer = micros(); +/**/ + } else { +// Serial.print("R' Microseconds: "); +// Serial.println(micros() - micro_timer2); +// while ((micros() - micro_timer2) < 832) { } +// micro_timer2 = micros(); + } +} /* - tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; - - digitalWrite(AUDIO_OUT_PIN, tx_bit); - - tx_bit = (buffer[wav_position++] > 0) ? true: false; -*/ -/* - if (tx_bit) - Serial.print("-"); - else - Serial.print("_"); + if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed + process_pushbutton(); + if (BOOTSEL) // boot selector button is pressed on Pico + process_bootsel(); */ -/* - pwm_config_set_output_polarity( &config, tx_bit, tx_bit); - pwm_init(bpsk_pin_slice, &config, true); - pwm_set_gpio_level(BPSK_PWM_PIN, (config.top + 1) * 0.5); -*/ + + return true; +} + +bool TimerHandler2(struct repeating_timer *t) { + +// digitalWrite(STEM_LED_GREEN, !green_led_counter++); + + if (mode == FSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future +// Serial.print("l1 "); +// Serial.print(wav_position); +// Serial.print(" "); + while ((micros() - micro_timer2) < delay_time) { } +// if ((micros() - micro_timer2) > 834) +// Serial.println(micros() - micro_timer2); + micro_timer2 = micros(); + if (buffer[wav_position++] > 0) { +// digitalWrite(BPSK_CONTROL_B, LOW); + digitalWrite(BPSK_CONTROL_B, LOW); +// delayMicroseconds(10); + digitalWrite(BPSK_CONTROL_A, HIGH); +// Serial.print("-"); +// clockgen.enableOutputOnly(1); + } else { +// digitalWrite(BPSK_CONTROL_A, LOW); + digitalWrite(BPSK_CONTROL_A, LOW); +// delayMicroseconds(10); + digitalWrite(BPSK_CONTROL_B, HIGH); +// Serial.print("_"); +// clockgen.enableOutputOnly(0); + } if (wav_position > bufLen) { // 300) { wav_position = wav_position % bufLen; // Serial.print("\nR"); @@ -3501,7 +3524,7 @@ bool TimerHandler0(struct repeating_timer *t) { /**/ // if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { if (bufLen != 0) { - Serial.print("R Microseconds: "); + Serial.print("R2 Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } // } @@ -3535,13 +3558,8 @@ void start_isr() { pinMode(BPSK_CONTROL_B, OUTPUT); digitalWrite(BPSK_CONTROL_A, LOW); // start with off digitalWrite(BPSK_CONTROL_B, LOW); - -// if (ITimer0.attachInterruptInterval(833, TimerHandler0)) -// if (ITimer0.attachInterruptInterval(804, TimerHandler0)) -// if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was 800 // was was 828 (841) and 828 - if (ITimer0.attachInterruptInterval(delay_time - 32, TimerHandler0)) // was 800 // was was 828 (841) and 828 -// if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) + if (ITimer0.attachInterruptInterval(833 - 32, TimerHandler0)) { if (debug_mode) Serial.print(F("Starting ITimer0 OK, micros() = ")); Serial.println(micros()); @@ -3550,10 +3568,22 @@ void start_isr() { else Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer")); + Serial.println("Starting ISR for FSK"); + + if (ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) +// if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) + { + if (debug_mode) + Serial.print(F("Starting ITimer2 OK, micros() = ")); Serial.println(micros()); + timer2_on = true; + } + else + Serial.println(F("Can't set ITimer2. Select another Timer, freq. or timer")); + } else { // ITimer0.restartTimer(); // Serial.println("Restarting ITimer0 for BPSK"); - Serial.println("Don't restart ITimer0 for BPSK"); + Serial.println("Don't restart ITimer0 for BPSK and ITimer2 for FSK"); } } From 7d5429468e4a260297267359db540d315e3f30e3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:08:12 -0400 Subject: [PATCH 100/134] added timer2_on --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 746b237d..52635916 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -372,6 +372,7 @@ RPI_PICO_Timer ITimer1(1); RPI_PICO_Timer ITimer2(2); bool timer0_on = false; +bool timer2_on = false; char callsign[20]; int morse_timing = 60; // ms for a dit From 7316204870fec84834e135f8752e42df33aa5c45 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:26:12 -0400 Subject: [PATCH 101/134] enable and disable timer0 and timer2 --- cubesatsim/cubesatsim.ino | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3dcbe0bc..a8a830d5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2114,13 +2114,21 @@ void config_radio() } else if (mode == BPSK) { // start_pwm(); // start_isr(); - clockgen.setClockBPSK(); + clockgen.setClockBPSK(); + + disable(timer2_number); + enable(timer0_number); + transmit_on(); } if ((mode == FSK)) // || (mode == SSTV)) // start_isr(); - clockgen.setClockFSK(); + clockgen.setClockFSK(); + + disable(timer0_number); + enable(timer2_number); + transmit_on(); } @@ -3559,7 +3567,7 @@ void start_isr() { digitalWrite(BPSK_CONTROL_A, LOW); // start with off digitalWrite(BPSK_CONTROL_B, LOW); - if (ITimer0.attachInterruptInterval(833 - 32, TimerHandler0)) + if (timer0_number = ITimer0.attachInterruptInterval(833 - 32, TimerHandler0)) { if (debug_mode) Serial.print(F("Starting ITimer0 OK, micros() = ")); Serial.println(micros()); @@ -3570,7 +3578,7 @@ void start_isr() { Serial.println("Starting ISR for FSK"); - if (ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) + if (timer2_number = ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) // if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) From 150d71055a7452abaeff51b8af0f84e84fa21c26 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:26:55 -0400 Subject: [PATCH 102/134] added timer0 and timer2 number --- cubesatsim/cubesatsim.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 52635916..ddda843d 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -373,6 +373,8 @@ RPI_PICO_Timer ITimer2(2); bool timer0_on = false; bool timer2_on = false; +int timer0_number = NULL; +int timer2_number = NULL; char callsign[20]; int morse_timing = 60; // ms for a dit From 447839a9057d276f4665ad48bb3a937f0648d431 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:28:48 -0400 Subject: [PATCH 103/134] added ITimer0 or 2 --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a8a830d5..4eed4c7e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - disable(timer2_number); - enable(timer0_number); + ITimer2.disable(timer2_number); + ITimer0.enable(timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - disable(timer0_number); - enable(timer2_number); + ITimer0.disable(timer0_number); + ITimer2.enable(timer2_number); transmit_on(); } From d6469b03fd813fd7dda9bccf6abfb1c3b280e309 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:35:39 -0400 Subject: [PATCH 104/134] RPI_PICO_ISR_Timer --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4eed4c7e..ff70fc2d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - ITimer2.disable(timer2_number); - ITimer0.enable(timer0_number); + RPI_PICO_ISR_Timer.disable(timer2_number); + RPI_PICO_ISR_Timer.enable(timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - ITimer0.disable(timer0_number); - ITimer2.enable(timer2_number); + RPI_PICO_ISR_Timer.disable(timer0_number); + RPI_PICO_ISR_Timer.enable(timer2_number); transmit_on(); } From bcf94b33d2e8497ec8df260735b492955f1a5f2f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:39:22 -0400 Subject: [PATCH 105/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ff70fc2d..8450f2ae 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3579,7 +3579,7 @@ void start_isr() { Serial.println("Starting ISR for FSK"); if (timer2_number = ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) -// if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) +// if (dia.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) Serial.print(F("Starting ITimer2 OK, micros() = ")); Serial.println(micros()); From 619fd1fef611d6d9fb45ae5b542c60bc5c57f6f1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:41:03 -0400 Subject: [PATCH 106/134] added ITimer0:: --- cubesatsim/cubesatsim.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 8450f2ae..522b5d80 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - RPI_PICO_ISR_Timer.disable(timer2_number); - RPI_PICO_ISR_Timer.enable(timer0_number); + ITimer2::disable(timer2_number); + ITimer0::enable(timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - RPI_PICO_ISR_Timer.disable(timer0_number); - RPI_PICO_ISR_Timer.enable(timer2_number); + ITimer0::disable(timer0_number); + ITimer2::enable(timer2_number); transmit_on(); } @@ -3579,7 +3579,7 @@ void start_isr() { Serial.println("Starting ISR for FSK"); if (timer2_number = ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) -// if (dia.attachInterruptInterval(1667, TimerHandler0)) +// if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) { if (debug_mode) Serial.print(F("Starting ITimer2 OK, micros() = ")); Serial.println(micros()); From 2051f9f1aad233c8ff1ddcbe18602d5e68fac41a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:42:58 -0400 Subject: [PATCH 107/134] RPI_PICO_ISR_Timer:: --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 522b5d80..682dc5c9 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - ITimer2::disable(timer2_number); - ITimer0::enable(timer0_number); + RPI_PICO_ISR_Timer::disable(timer2_number); + RPI_PICO_ISR_Timer::enable(timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - ITimer0::disable(timer0_number); - ITimer2::enable(timer2_number); + RPI_PICO_ISR_Timer::disable(timer0_number); + RPI_PICO_ISR_Timer::enable(timer2_number); transmit_on(); } From 30da6e411aca4892521f7fc21df479c3a6f832d7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:45:06 -0400 Subject: [PATCH 108/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 682dc5c9..88cc0d50 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - RPI_PICO_ISR_Timer::disable(timer2_number); - RPI_PICO_ISR_Timer::enable(timer0_number); + RPI_PICO_ISR_Timer::disable(*timer2_number); + RPI_PICO_ISR_Timer::enable(*timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - RPI_PICO_ISR_Timer::disable(timer0_number); - RPI_PICO_ISR_Timer::enable(timer2_number); + RPI_PICO_ISR_Timer::disable(*timer0_number); + RPI_PICO_ISR_Timer::enable(*timer2_number); transmit_on(); } From bfd56c8c5fd56db8e1f8df8a9c26d6eb39ac5be4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 16:46:04 -0400 Subject: [PATCH 109/134] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 88cc0d50..1877735d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2116,8 +2116,8 @@ void config_radio() // start_isr(); clockgen.setClockBPSK(); - RPI_PICO_ISR_Timer::disable(*timer2_number); - RPI_PICO_ISR_Timer::enable(*timer0_number); + RPI_PICO_ISR_Timer::disable(&timer2_number); + RPI_PICO_ISR_Timer::enable(&timer0_number); transmit_on(); } @@ -2126,8 +2126,8 @@ void config_radio() // start_isr(); clockgen.setClockFSK(); - RPI_PICO_ISR_Timer::disable(*timer0_number); - RPI_PICO_ISR_Timer::enable(*timer2_number); + RPI_PICO_ISR_Timer::disable(&timer0_number); + RPI_PICO_ISR_Timer::enable(&timer2_number); transmit_on(); } From 2fde9c660eea9b1279b4ded493bc7fe58a7fe634 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:33:05 -0400 Subject: [PATCH 110/134] added timer_counter --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index ddda843d..82d7933f 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -375,6 +375,7 @@ bool timer0_on = false; bool timer2_on = false; int timer0_number = NULL; int timer2_number = NULL; +int timer_counter; char callsign[20]; int morse_timing = 60; // ms for a dit From 270e28cff6b40c2256aebf418327ad1054e4d5f1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:37:35 -0400 Subject: [PATCH 111/134] added timer_counter modulo 6 for FSK --- cubesatsim/cubesatsim.ino | 106 +++++--------------------------------- 1 file changed, 12 insertions(+), 94 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1877735d..6843fc72 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -506,7 +506,6 @@ void transmit_off() { if (debug_mode) Serial.println("Transmit off!"); digitalWrite(MAIN_LED_BLUE, LOW); -// ITimer0.stopTimer(); // stop BPSK ISR timer if ((mode == BPSK) || (mode == FSK)) { digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, LOW); @@ -2103,32 +2102,18 @@ void config_radio() */ if ((mode == AFSK) || (mode == SSTV) || (mode == CW)) { - digitalWrite(PD_PIN, HIGH); // Enable SR_FRS - + digitalWrite(PD_PIN, HIGH); // Enable SR_FRS // pinMode(AUDIO_OUT_PIN, OUTPUT); - program_radio(); - -// } else if (mode == FSK) { // moved to below -// transmit_on(); + } else if (mode == BPSK) { -// start_pwm(); -// start_isr(); - clockgen.setClockBPSK(); - - RPI_PICO_ISR_Timer::disable(&timer2_number); - RPI_PICO_ISR_Timer::enable(&timer0_number); + clockgen.setClockBPSK(); transmit_on(); - } - - if ((mode == FSK)) // || (mode == SSTV)) -// start_isr(); - clockgen.setClockFSK(); - - RPI_PICO_ISR_Timer::disable(&timer0_number); - RPI_PICO_ISR_Timer::enable(&timer2_number); + } + else if ((mode == FSK)) // || (mode == SSTV)) + clockgen.setClockFSK(); transmit_on(); } @@ -3441,8 +3426,8 @@ void config_gpio() { bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); - - if (mode == BPSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future + timer_counter = (timer_counter++) % 6 + if (mode == BPSK) || ((mode == FSK) && !timer_counter) { // only do this if BPSK mode or every 6 times in FSK mode // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); @@ -3497,71 +3482,15 @@ bool TimerHandler0(struct repeating_timer *t) { return true; } -bool TimerHandler2(struct repeating_timer *t) { - -// digitalWrite(STEM_LED_GREEN, !green_led_counter++); - - if (mode == FSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future -// Serial.print("l1 "); -// Serial.print(wav_position); -// Serial.print(" "); - while ((micros() - micro_timer2) < delay_time) { } -// if ((micros() - micro_timer2) > 834) -// Serial.println(micros() - micro_timer2); - micro_timer2 = micros(); - if (buffer[wav_position++] > 0) { -// digitalWrite(BPSK_CONTROL_B, LOW); - digitalWrite(BPSK_CONTROL_B, LOW); -// delayMicroseconds(10); - digitalWrite(BPSK_CONTROL_A, HIGH); -// Serial.print("-"); -// clockgen.enableOutputOnly(1); - } else { -// digitalWrite(BPSK_CONTROL_A, LOW); - digitalWrite(BPSK_CONTROL_A, LOW); -// delayMicroseconds(10); - digitalWrite(BPSK_CONTROL_B, HIGH); -// Serial.print("_"); -// clockgen.enableOutputOnly(0); - } - if (wav_position > bufLen) { // 300) { - wav_position = wav_position % bufLen; -// Serial.print("\nR"); -// Serial.print(" "); -// Serial.println(millis()); -/**/ -// if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { - if (bufLen != 0) { - Serial.print("R2 Microseconds: "); - Serial.println((float)(micros() - micro_timer)/(float)bufLen); - } -// } - micro_timer = micros(); -/**/ - } else { -// Serial.print("R' Microseconds: "); -// Serial.println(micros() - micro_timer2); -// while ((micros() - micro_timer2) < 832) { } -// micro_timer2 = micros(); - } -} -/* - if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed - process_pushbutton(); - if (BOOTSEL) // boot selector button is pressed on Pico - process_bootsel(); -*/ - - return true; -} void start_isr() { // return; if (!timer0_on) { // if (true) { // always start ISR handler - Serial.println("Starting ISR for BPSK"); - + Serial.println("Starting ISR for BPSK/FSK"); + + timer_counter = 0; pinMode(BPSK_CONTROL_A, OUTPUT); pinMode(BPSK_CONTROL_B, OUTPUT); digitalWrite(BPSK_CONTROL_A, LOW); // start with off @@ -3575,18 +3504,7 @@ void start_isr() { } else Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer")); - - Serial.println("Starting ISR for FSK"); - - if (timer2_number = ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2)) -// if (ITimer0.attachInterruptInterval(1667, TimerHandler0)) - { - if (debug_mode) - Serial.print(F("Starting ITimer2 OK, micros() = ")); Serial.println(micros()); - timer2_on = true; - } - else - Serial.println(F("Can't set ITimer2. Select another Timer, freq. or timer")); + } else { // ITimer0.restartTimer(); From 7eaff4c6036d2adcad5c5330259953c6dffda476 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:39:38 -0400 Subject: [PATCH 112/134] volatile timer_counter --- cubesatsim/cubesatsim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 82d7933f..6c8b4978 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -375,7 +375,7 @@ bool timer0_on = false; bool timer2_on = false; int timer0_number = NULL; int timer2_number = NULL; -int timer_counter; +volatile int timer_counter; char callsign[20]; int morse_timing = 60; // ms for a dit From ec981d18bcfd8d76c5763cfddc3e1a621bbdd936 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:39:42 -0400 Subject: [PATCH 113/134] missing ; --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 6843fc72..83d6530d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3426,13 +3426,14 @@ void config_gpio() { bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); - timer_counter = (timer_counter++) % 6 + timer_counter = (timer_counter++) % 6; if (mode == BPSK) || ((mode == FSK) && !timer_counter) { // only do this if BPSK mode or every 6 times in FSK mode // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); while ((micros() - micro_timer2) < delay_time) { } - busy_wait_at_least_cycles(51); // 300 ns + if (mode == BPSK) + busy_wait_at_least_cycles(51); // 300 ns // if ((micros() - micro_timer2) > 834) // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); From 2c8a8cd325fa78c9e740a3af4d8fc6f785e160b0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:41:04 -0400 Subject: [PATCH 114/134] fixed () --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 83d6530d..d91bea2f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3427,7 +3427,7 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); timer_counter = (timer_counter++) % 6; - if (mode == BPSK) || ((mode == FSK) && !timer_counter) { // only do this if BPSK mode or every 6 times in FSK mode + if ((mode == BPSK) || ((mode == FSK) && !timer_counter)) { // only do this if BPSK mode or every 6 times in FSK mode // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); From 7bd6d21fa71c8c2b28c81befc7883b6289a63744 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:49:22 -0400 Subject: [PATCH 115/134] removed ITimer2 --- cubesatsim/cubesatsim.h | 1 - 1 file changed, 1 deletion(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 6c8b4978..74e1c3de 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -369,7 +369,6 @@ const char sstv2_filename[] = "/sstv_image_2_320_x_240.jpg"; bool TimerHandler0(struct repeating_timer *t); RPI_PICO_Timer ITimer0(0); RPI_PICO_Timer ITimer1(1); -RPI_PICO_Timer ITimer2(2); bool timer0_on = false; bool timer2_on = false; From 0afa248b4900aae58a20541e669bd2cd75ff9a76 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:55:09 -0400 Subject: [PATCH 116/134] % 5 not 6 --- cubesatsim/cubesatsim.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d91bea2f..628b601e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3426,8 +3426,8 @@ void config_gpio() { bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); - timer_counter = (timer_counter++) % 6; - if ((mode == BPSK) || ((mode == FSK) && !timer_counter)) { // only do this if BPSK mode or every 6 times in FSK mode + timer_counter = (timer_counter++) % 5; + if ((mode == BPSK) || ((mode == FSK) && (timer_counter == 0)) { // only do this if BPSK mode or every 6 times in FSK mode // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); @@ -3460,7 +3460,7 @@ bool TimerHandler0(struct repeating_timer *t) { /**/ // if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { if (bufLen != 0) { - Serial.print("R0 Microseconds: "); + Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } // } @@ -3497,7 +3497,7 @@ void start_isr() { digitalWrite(BPSK_CONTROL_A, LOW); // start with off digitalWrite(BPSK_CONTROL_B, LOW); - if (timer0_number = ITimer0.attachInterruptInterval(833 - 32, TimerHandler0)) + if (ITimer0.attachInterruptInterval(833 - 32, TimerHandler0)) { if (debug_mode) Serial.print(F("Starting ITimer0 OK, micros() = ")); Serial.println(micros()); @@ -3510,7 +3510,7 @@ void start_isr() { } else { // ITimer0.restartTimer(); // Serial.println("Restarting ITimer0 for BPSK"); - Serial.println("Don't restart ITimer0 for BPSK and ITimer2 for FSK"); + Serial.println("Don't start ITimer0 for BPSK and FSK"); } } From 528c2f581ad888243ca4beea801a1259efa3e7d2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:57:45 -0400 Subject: [PATCH 117/134] missing ) --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 628b601e..3af0971e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3427,7 +3427,7 @@ bool TimerHandler0(struct repeating_timer *t) { // digitalWrite(STEM_LED_GREEN, !green_led_counter++); timer_counter = (timer_counter++) % 5; - if ((mode == BPSK) || ((mode == FSK) && (timer_counter == 0)) { // only do this if BPSK mode or every 6 times in FSK mode + if ((mode == BPSK) || ((mode == FSK) && (timer_counter == 0))) { // only do this if BPSK mode or every 6 times in FSK mode // Serial.print("l1 "); // Serial.print(wav_position); // Serial.print(" "); From f2cf355caafcc9740c9de25fd7ed2f6001080f57 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 18:58:15 -0400 Subject: [PATCH 118/134] removed timer variables --- cubesatsim/cubesatsim.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 74e1c3de..8801e904 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -371,9 +371,6 @@ RPI_PICO_Timer ITimer0(0); RPI_PICO_Timer ITimer1(1); bool timer0_on = false; -bool timer2_on = false; -int timer0_number = NULL; -int timer2_number = NULL; volatile int timer_counter; char callsign[20]; From 2dc8b8e19915f45cc1ee1758455f67e9a4d7d3f2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 19:24:15 -0400 Subject: [PATCH 119/134] print --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3af0971e..4543ba3c 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1313,8 +1313,8 @@ void get_tlm_fox() { data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); -// Serial.print(data, BIN); // Debugging print!!! -// Serial.print(" "); + Serial.print(data, BIN); // Debugging print!!! + Serial.print(" "); if (mode == FSK) { phase = ((data != 0) * 2) - 1; // Serial.printf("Sending a %d\n", phase); From b09c9b29d698dc4dd28511a595cdd1b69ac30d54 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 19:27:34 -0400 Subject: [PATCH 120/134] print str --- cubesatsim/cubesatsim.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4543ba3c..6ed6b304 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1313,8 +1313,8 @@ void get_tlm_fox() { data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - Serial.print(data, BIN); // Debugging print!!! - Serial.print(" "); +// Serial.print(data, BIN); // Debugging print!!! +// Serial.print(" "); if (mode == FSK) { phase = ((data != 0) * 2) - 1; // Serial.printf("Sending a %d\n", phase); @@ -1349,7 +1349,10 @@ void get_tlm_fox() { void write_wave(int i, byte *buffer) { buffer[ctr++] = (byte)(phase == 1); -// Serial.printf("buffer is %d \n", buffer[ctr - 1]); +// Serial.printf("buffer is %d \n", buffer[ctr - 1]); + Serial.print(ctr); + Serial.print(" "); + if (ctr > bufLen) { ctr = ctr - bufLen; // if (debug_mode) { From 8a658b6dbd2428dd8dbbd92e6617969fc70c5d7e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 19:32:47 -0400 Subject: [PATCH 121/134] set ctr = 0 in FoxTelem --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 6ed6b304..9fc94b5e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -867,10 +867,12 @@ void get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; - short int buffer_test[bufLen]; + //short int buffer_test[bufLen]; int buffSize; buffSize = (int) sizeof(buffer_test); + ctr = 0; + parse_payload(); // for (int n = 0; n < 17; n++) From 642ea2a6e7b0a6601f3958dfd217bd5bd3f53509 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 19:35:02 -0400 Subject: [PATCH 122/134] remove buffSize --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9fc94b5e..1f238379 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -868,8 +868,8 @@ void get_tlm_fox() { int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; //short int buffer_test[bufLen]; - int buffSize; - buffSize = (int) sizeof(buffer_test); + //int buffSize; + //buffSize = (int) sizeof(buffer_test); ctr = 0; From 4b6c08cb0b15a669eaf9cbd822a3ce25533e3dff Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 17 Sep 2022 19:39:59 -0400 Subject: [PATCH 123/134] remove prints --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1f238379..d5384255 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1352,8 +1352,8 @@ void write_wave(int i, byte *buffer) { buffer[ctr++] = (byte)(phase == 1); // Serial.printf("buffer is %d \n", buffer[ctr - 1]); - Serial.print(ctr); - Serial.print(" "); +// Serial.print(ctr); +// Serial.print(" "); if (ctr > bufLen) { ctr = ctr - bufLen; From 43e892aae6af35809e7683e1ba7d7717d1a0186c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 09:43:19 -0400 Subject: [PATCH 124/134] added payload code back in --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d5384255..0299ed0b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -88,7 +88,7 @@ void setup() { // otherwise, run CubeSatSim Pico code - Serial.println("CubeSatSim Pico v0.24 starting...\n"); + Serial.println("CubeSatSim Pico v0.25 starting...\n"); config_gpio(); @@ -121,7 +121,7 @@ void setup() { // pinMode(PI_3V3_PIN, OUTPUT); // digitalWrite(PI_3V3_PIN, HIGH); -// start_payload(); // above code not working, so forcing it + start_payload(); // above code not working, so forcing it read_config_file(); @@ -191,7 +191,7 @@ void loop() { // query INA219 sensors and Payload sensors read_ina219(); -// read_payload(); + read_payload(); // encode as digits (APRS or CW mode) or binary (DUV FSK) if ((mode == BPSK) || (mode == FSK)) { From 3a5a259bcafbe7d1fbe3684f4b679892e65b11d5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 10:04:40 -0400 Subject: [PATCH 125/134] removed BPSK ns delay, R and r prints --- cubesatsim/cubesatsim.ino | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0299ed0b..03630036 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1358,10 +1358,13 @@ void write_wave(int i, byte *buffer) if (ctr > bufLen) { ctr = ctr - bufLen; // if (debug_mode) { - Serial.print("ctr reset "); - if (bufLen != 0) { - Serial.print("RR Microseconds: "); - Serial.println((float)(micros() - micros3)/(float)bufLen); +// Serial.print("ctr reset "); + if (bufLen != 0) { + float avg_time = (float)(micros() - micros3)/(float)bufLen; + if ((avg_time > (delay_time * 1.15)) || debug_mode) { + Serial.print("r Microseconds: "); + Serial.println(avg_time); + } } // } micros3 = micros(); @@ -3437,8 +3440,8 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.print(wav_position); // Serial.print(" "); while ((micros() - micro_timer2) < delay_time) { } - if (mode == BPSK) - busy_wait_at_least_cycles(51); // 300 ns +// if (mode == BPSK) +// busy_wait_at_least_cycles(51); // 300 ns // if ((micros() - micro_timer2) > 834) // Serial.println(micros() - micro_timer2); micro_timer2 = micros(); @@ -3464,11 +3467,20 @@ bool TimerHandler0(struct repeating_timer *t) { // Serial.println(millis()); /**/ // if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { +/* if (bufLen != 0) { Serial.print("R Microseconds: "); Serial.println((float)(micros() - micro_timer)/(float)bufLen); } -// } +// } +*/ + if (bufLen != 0) { + float avg_time = (float)(micros() - micro_timer)/(float)bufLen; + if ((avg_time > (delay_time * 1.15)) || debug_mode) { + Serial.print("R Microseconds: "); + Serial.println(avg_time); + } + } micro_timer = micros(); /**/ } else { From 04edceb86d5752f02cbefabdca603dc6d14084ab Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 10:20:30 -0400 Subject: [PATCH 126/134] changed to 434.91 MHz --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 03630036..fa9d744f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4251,9 +4251,10 @@ void program_radio() { // mySerial.println("AT+DMOSETGROUP=0,434.9000,434.9000,1,2,1,1\r"); // mySerial.println("AT+DMOSETGROUP=0,434.9000,434.9000,0,8,0,0\r"); // 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"); +// mySerial.println("AT+DMOSETGROUP=0,432.2500,432.2500,0,8,0,0\r"); + mySerial.println("AT+DMOSETGROUP=0,434.9100,434.9100,0,8,0,0\r"); // sleep(0.5); - mySerial.println("AT+DMOSETMIC=6,0\r"); // was 8 + mySerial.println("AT+DMOSETMIC=8,0\r"); // was 8 } } From 368f09f27f8961fefa4ec46b2fef7a9f84a1a96b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 10:24:07 -0400 Subject: [PATCH 127/134] 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 fa9d744f..b1928e18 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1361,10 +1361,10 @@ void write_wave(int i, byte *buffer) // Serial.print("ctr reset "); if (bufLen != 0) { float avg_time = (float)(micros() - micros3)/(float)bufLen; - if ((avg_time > (delay_time * 1.15)) || debug_mode) { +// if ((avg_time > (delay_time * 1.15)) || debug_mode) { Serial.print("r Microseconds: "); Serial.println(avg_time); - } +// } } // } micros3 = micros(); From 7f5d8cf855f034783888912750ef792fb4c19791 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 10:50:01 -0400 Subject: [PATCH 128/134] detect camera each time --- cubesatsim/cubesatsim.ino | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b1928e18..2f36927e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -147,7 +147,7 @@ void setup() { setup_sstv(); - camera_detected = false; // start_camera(); + camera_detected = start_camera(); // start_pwm(); @@ -215,9 +215,8 @@ void loop() { strcpy(image_file, sstv1_filename); first_time_sstv = false; } else { - if (camera_detected) { - Serial.println("Getting image file"); - get_camera_image(); + if (camera_detected = get_camera_image()) { + Serial.println("Getting image file"); // Serial.println("Got image file"); char camera_file[] = "/cam.jpg"; strcpy(image_file, camera_file); @@ -3346,7 +3345,7 @@ void process_bootsel() { } if (new_mode != mode) transmit_off(); - sleep(2.0); +// sleep(2.0); } void blinkTimes(int blinks) { @@ -3994,7 +3993,7 @@ void serial_input() { if (new_mode != mode) transmit_off(); - sleep(2.0); +// sleep(2.0); } } } From a1a60d95f7d872e758d05c1f18248254eb0e058f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:01:31 -0400 Subject: [PATCH 129/134] changed camera to camera_detected in fox tlm --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 2f36927e..f5177fe9 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -1158,7 +1158,7 @@ void get_tlm_fox() { encodeB(b, 49 + head_offset, (int)(sensor[XS2] * 10 + 0.5) + 2048); // Serial.println("D"); int status = STEMBoardFailure + SafeMode * 2 + sim_mode * 4 + PayloadFailure1 * 8 + - (i2c_bus0 == false) * 16 + (i2c_bus1 == false) * 32 + (i2c_bus3 == false) * 64 + (camera == OFF) * 128 + groundCommandCount * 256; + (i2c_bus0 == false) * 16 + (i2c_bus1 == false) * 32 + (i2c_bus3 == false) * 64 + (camera_detected == OFF) * 128 + groundCommandCount * 256; encodeA(b, 51 + head_offset, status); encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2); // Serial.println("E"); From c292ac4ed8ad44c2efbcc971eefb2dc49ee03ed5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:11:45 -0400 Subject: [PATCH 130/134] clock prints --- cubesatsim/cubesatsim.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f5177fe9..9b43caf4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -490,6 +490,7 @@ void transmit_on() { Serial.println("Transmit on!!!"); // pwm_set_gpio_level(BPSK_PWM_A_PIN, (config.top + 1) * 0.5); // pwm_set_gpio_level(BPSK_PWM_B_PIN, (config.top + 1) * 0.5); + Serial.println("Enable clock outputs"); clockgen.enableOutputs(true); } else if (mode == CW) { @@ -510,6 +511,7 @@ void transmit_off() { digitalWrite(BPSK_CONTROL_B, LOW); // pwm_set_gpio_level(BPSK_PWM_A_PIN, 0); // pwm_set_gpio_level(BPSK_PWM_B_PIN, 0); + Serial.println("Disable clock outputs"); clockgen.enableOutputs(false); } else if (mode == SSTV) @@ -2115,12 +2117,14 @@ void config_radio() } else if (mode == BPSK) { - clockgen.setClockBPSK(); + clockgen.setClockBPSK(); + Serial.println("Config clock for BPSK"); transmit_on(); } else if ((mode == FSK)) // || (mode == SSTV)) clockgen.setClockFSK(); + Serial.println("Config clock for FSK"); transmit_on(); } From 033e260c5a7c313baac8a83573085ad695f5c436 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:16:45 -0400 Subject: [PATCH 131/134] added config radio print --- cubesatsim/cubesatsim.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9b43caf4..54b4c2de 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2096,6 +2096,7 @@ void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file) void config_radio() { + Serial.println("Configuring radio"); /* if (!wifi) pinMode(LED_BUILTIN, OUTPUT); From 78a41c030fe8c8fa18836d3a7bd386d77125c2e4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:24:17 -0400 Subject: [PATCH 132/134] missing {} --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 54b4c2de..b5dc63c0 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2122,11 +2122,12 @@ void config_radio() Serial.println("Config clock for BPSK"); transmit_on(); } - else if ((mode == FSK)) // || (mode == SSTV)) + else if (mode == FSK) {// || (mode == SSTV)) clockgen.setClockFSK(); Serial.println("Config clock for FSK"); transmit_on(); + } } void test_radio() From ed91f37e737733d737a1cfd525938e2f864cd7d5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:27:44 -0400 Subject: [PATCH 133/134] transmit_on not used at end of transmit_callsign --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b5dc63c0..6b8354de 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3731,7 +3731,7 @@ void transmit_callsign(char *callsign) { } transmit_off(); transmit_string(id); - transmit_on(); +// transmit_on(); } void transmit_string(char *string) { From 1b6cb2f36a98676ffd0be3cc2715e7e91e93639d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 18 Sep 2022 11:43:17 -0400 Subject: [PATCH 134/134] don't configure clocks in start_clockgen --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 6b8354de..a482dfdd 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4309,9 +4309,9 @@ void start_clockgen() { return; } - Serial.println("Starting clockgen frequency 434.896 MHz"); + Serial.println("Starting clockgen frequency 434.9 MHz"); - clockgen.setClockFSK(); // default to FSK +// clockgen.setClockFSK(); // default to FSK clockgen.enableOutputs(false); }