diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index d5e6ee9c..26373e7f 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -82,10 +82,10 @@ #define TRUE 1 #define FALSE 0 -#define A 1 -#define B 2 -#define C 3 -#define D 4 +#define A_ 1 +#define B_ 2 +#define C_ 3 +#define D_ 4 #define PLUS_X 0 #define PLUS_Y 1 #define BAT 2 @@ -108,7 +108,7 @@ #define XS2 15 #define XS3 16 -#define RSSI 0 +#define RSSI_ 0 #define IHU_TEMP 2 #define SPIN 1 @@ -129,6 +129,8 @@ #define PROMPT_FORMAT 12 #define PROMPT_REBOOT 13 #define PROMPT_I2CSCAN 14 +#define PROMPT_WIFI 15 +#define PROMPT_CAMERA 16 #define PAYLOAD_QUERY 1 #define PAYLOAD_RESET 2 @@ -294,6 +296,8 @@ float lat_file, long_file; double cpuTemp; int frameTime; +bool debug_camera = false; + float axis[3], angle[3], volts_max[3], amps_max[3], batt, rotation_speed, period, tempS, temp_max, temp_min, eclipse; int i2c_bus0 = OFF, i2c_bus1 = OFF, i2c_bus3 = OFF, camera = OFF, sim_mode = FALSE, SafeMode = FALSE, rxAntennaDeployed = 0, txAntennaDeployed = 0; double eclipse_time; @@ -366,6 +370,8 @@ bool ina219_started = false; bool camera_detected = false; bool rotate_flag = true; +int led_builtin_pin; + #define PRESSED 0 #define HELD 0 #define RELEASED 1 diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 173ff180..a41ff6e5 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" @@ -45,6 +45,8 @@ #include "picosstvpp.h" #include "pico/bootrom.h" #include "hardware/watchdog.h" +#include + // jpg files to be stored in flash storage on Pico (FS 512kB setting) #include "sstv1.h" @@ -65,13 +67,15 @@ unsigned long micros3; //WiFiServer server(port); //WiFiClient client; +WiFiClient net; +MQTTClient client; -//#define PICO_W // define if Pico W board. Otherwise, compilation fail for Pico or runtime fail if compile as Pico W +#define PICO_W // define if Pico W board. Otherwise, compilation fail for Pico or runtime fail if compile as Pico W byte green_led_counter = 0; char call[] = "AMSAT"; // put your callsign here -extern bool get_camera_image(); +extern bool get_camera_image(bool debug); extern bool start_camera(); void setup() { @@ -91,14 +95,26 @@ void setup() { new_mode = mode; - pinMode(LED_BUILTIN, OUTPUT); +// pinMode(LED_BUILTIN, OUTPUT); // blinkTimes(1); /// sleep(5.0); // otherwise, run CubeSatSim Pico code - Serial.println("CubeSatSim Pico v0.35 starting...\n"); + Serial.println("CubeSatSim Pico v0.36 starting...\n"); + +/**/ + if (check_for_wifi()) { + wifi = true; + led_builtin_pin = LED_BUILTIN; // use default GPIO for Pico W +// pinMode(LED_BUILTIN, OUTPUT); +// configure_wifi(); + } else + led_builtin_pin = 25; // manually set GPIO 25 for Pico board +// pinMode(25, OUTPUT); + pinMode(led_builtin_pin, OUTPUT); +/**/ config_gpio(); @@ -121,10 +137,11 @@ void setup() { Serial.print("Pi 3.3V: "); Serial.println(digitalRead(PI_3V3_PIN)); if (digitalRead(PI_3V3_PIN) == HIGH) { +// { Serial.print("Pi Zero present, so running Payload OK code instead of CubeSatSim code."); start_payload(); while(true) { - payload_OK_only(); +// payload_OK_only(); } } */ @@ -152,12 +169,6 @@ void setup() { // if ((i2c_bus3 == false) || (mode == FSK)) // force simulated telemetry mode for FSK config_simulated_telem(); -/* - if (check_for_wifi()) { - wifi = true; - configure_wifi(); - } -*/ start_button_isr(); // setup_sstv(); @@ -202,6 +213,14 @@ void setup() { Serial.print(" "); Serial.println(millis()); */ + +/* +//SSID of your network +char ssid[] = "CubeSatSim"; +//password of your WPA Network +char pass[] = "amsatao7"; + WiFi.begin(ssid, pass); +*/ } void loop() { @@ -240,7 +259,7 @@ void loop() { load_sstv_image_1_as_cam_dot_jpg(); first_time_sstv = false; } else { - if (camera_detected = get_camera_image()) { + if (camera_detected = get_camera_image(debug_camera)) { Serial.println("Getting image file"); // Serial.println("Got image file"); // char camera_file[] = "/cam.jpg"; @@ -722,29 +741,29 @@ void get_tlm_ao7() { int tlm[7][5]; memset(tlm, 0, sizeof tlm); - tlm[1][A] = (int)(voltage[mapping[BUS]] / 15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int)(99.5 - current[mapping[PLUS_X]] / 10.0) % 100; // +X current [4] - tlm[1][C] = (int)(99.5 - current[mapping[MINUS_X]] / 10.0) % 100; // X- current [10] - tlm[1][D] = (int)(99.5 - current[mapping[PLUS_Y]] / 10.0) % 100; // +Y current [7] + tlm[1][A_] = (int)(voltage[mapping[BUS]] / 15.0 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][B_] = (int)(99.5 - current[mapping[PLUS_X]] / 10.0) % 100; // +X current [4] + tlm[1][C_] = (int)(99.5 - current[mapping[MINUS_X]] / 10.0) % 100; // X- current [10] + tlm[1][D_] = (int)(99.5 - current[mapping[PLUS_Y]] / 10.0) % 100; // +Y current [7] - tlm[2][A] = (int)(99.5 - current[mapping[MINUS_Y]] / 10.0) % 100; // -Y current [10] - tlm[2][B] = (int)(99.5 - current[mapping[PLUS_Z]] / 10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int)(99.5 - current[mapping[MINUS_Z]] / 10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + current[mapping[BAT]] / 10.0) % 100; // NiMH Battery current + tlm[2][A_] = (int)(99.5 - current[mapping[MINUS_Y]] / 10.0) % 100; // -Y current [10] + tlm[2][B_] = (int)(99.5 - current[mapping[PLUS_Z]] / 10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][C_] = (int)(99.5 - current[mapping[MINUS_Z]] / 10.0) % 100; // -Z current (was timestamp) + tlm[2][D_] = (int)(50.5 + current[mapping[BAT]] / 10.0) % 100; // NiMH Battery current // tlm[3][A] = abs((int)((voltage[mapping[BAT]] * 10.0) - 65.5) % 100); if (voltage[mapping[BAT]] > 4.6) - tlm[3][A] = (int)((voltage[mapping[BAT]] * 10.0) - 65.5) % 100; // 7.0 - 10.0 V for old 9V battery + tlm[3][A_] = (int)((voltage[mapping[BAT]] * 10.0) - 65.5) % 100; // 7.0 - 10.0 V for old 9V battery else - tlm[3][A] = (int)((voltage[mapping[BAT]] * 10.0) + 44.5) % 100; // 0 - 4.5 V for new 3 cell battery + tlm[3][A_] = (int)((voltage[mapping[BAT]] * 10.0) + 44.5) % 100; // 0 - 4.5 V for new 3 cell battery - tlm[3][B] = (int)(voltage[mapping[BUS]] * 10.0) % 100; // 5V supply to Pi + tlm[3][B_] = (int)(voltage[mapping[BUS]] * 10.0) % 100; // 5V supply to Pi // tlm[4][A] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet - tlm[4][A] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet + tlm[4][A_] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet - tlm[6][B] = 0; - tlm[6][D] = 49 + rand() % 3; + tlm[6][B_] = 0; + tlm[6][D_] = 49 + rand() % 3; /* // Display tlm @@ -1127,7 +1146,7 @@ void get_tlm_fox() { encodeA(b_max, 30 + head_offset, (int)(voltage_max[mapping[BUS]] * 100)); encodeB(b_max, 46 + head_offset, (int)(current_max[mapping[BUS]] + 0.5) + 2048); - encodeB(b_max, 37 + head_offset, (int)(other_max[RSSI] + 0.5) + 2048); + encodeB(b_max, 37 + head_offset, (int)(other_max[RSSI_] + 0.5) + 2048); encodeA(b_max, 39 + head_offset, (int)(other_max[IHU_TEMP] * 10 + 0.5)); encodeB(b_max, 31 + head_offset, ((int)(other_max[SPIN] * 10)) + 2048); @@ -1176,7 +1195,7 @@ void get_tlm_fox() { encodeB(b_min, 46 + head_offset, (int)(current_min[mapping[BUS]] + 0.5) + 2048); encodeB(b_min, 31 + head_offset, ((int)(other_min[SPIN] * 10)) + 2048); - encodeB(b_min, 37 + head_offset, (int)(other_min[RSSI] + 0.5) + 2048); + encodeB(b_min, 37 + head_offset, (int)(other_min[RSSI_] + 0.5) + 2048); encodeA(b_min, 39 + head_offset, (int)(other_min[IHU_TEMP] * 10 + 0.5)); if (sensor_min[0] != 1000.0) // make sure values are valid @@ -1212,7 +1231,7 @@ void get_tlm_fox() { encodeA(b, 33 + head_offset, (int)(sensor[PRES] + 0.5)); // Pressure encodeB(b, 34 + head_offset, (int)(sensor[ALT] * 10.0 + 0.5)); // Altitude encodeA(b, 36 + head_offset, Resets); - encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5) + 2048); + encodeB(b, 37 + head_offset, (int)(other[RSSI_] + 0.5) + 2048); encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); encodeB(b, 40 + head_offset, (int)(sensor[GYRO_X] + 0.5) + 2048); encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 0.5) + 2048); @@ -2877,7 +2896,7 @@ void read_payload() // delay(100); } -/* +/**/ void payload_OK_only() { payload_str[0] = '\0'; // clear the payload string @@ -3066,7 +3085,7 @@ void payload_OK_only() delay(100); } -*/ +/**/ /* void eeprom_word_write(int addr, int val) { @@ -3099,11 +3118,11 @@ void blink_setup() void blink(int length) { - digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON + digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON sleep(length/1000.0); // delay(length); // wait for a lenth of time - digitalWrite(LED_BUILTIN, LOW); // set the built-in LED off + digitalWrite(led_builtin_pin, LOW); // set the built-in LED off } void led_set(int ledPin, bool state) @@ -3389,7 +3408,7 @@ void process_pushbutton() { // return; /// just skip for now // if (!wifi) - digitalWrite(LED_BUILTIN, HIGH); // make sure built in LED is on before starting to blink + digitalWrite(led_builtin_pin, HIGH); // make sure built in LED is on before starting to blink sleep(1.0); @@ -3479,7 +3498,7 @@ void process_pushbutton() { transmit_off(); sleep(2.0); - digitalWrite(LED_BUILTIN, LOW); // make sure built-in LED is off + digitalWrite(led_builtin_pin, LOW); // make sure built-in LED is off } void process_bootsel() { @@ -3489,7 +3508,7 @@ void process_bootsel() { int release = FALSE; // if (!wifi) - digitalWrite(LED_BUILTIN, HIGH); // make sure built in LED is on before blinking + digitalWrite(led_builtin_pin, HIGH); // make sure built in LED is on before blinking sleep(1.0); @@ -3578,18 +3597,18 @@ void process_bootsel() { transmit_off(); // sleep(2.0); - digitalWrite(LED_BUILTIN, LOW); // make sure built-in LED is off + digitalWrite(led_builtin_pin, LOW); // make sure built-in LED is off } void blinkTimes(int blinks) { for (int i = 0; i < blinks; i++) { digitalWrite(MAIN_LED_GREEN, LOW); // if (!wifi) - digitalWrite(LED_BUILTIN, LOW); + digitalWrite(led_builtin_pin, LOW); sleep(0.1); digitalWrite(MAIN_LED_GREEN, HIGH); // if (!wifi) - digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(led_builtin_pin, HIGH); sleep(0.1); } } @@ -3608,13 +3627,30 @@ void config_gpio() { for (int i = 6; i < 29; i++) { pinMode(i, INPUT); } + + pinMode(PI_3V3_PIN, INPUT); + Serial.print("Pi 3.3V: "); + Serial.println(digitalRead(PI_3V3_PIN)); + if (digitalRead(PI_3V3_PIN) == HIGH) { +// { + Serial.print("Pi Zero present, so running Payload OK code instead of CubeSatSim code."); + start_payload(); + while(true) { +// Serial.println("waiting"); +// sleep(3.0); + payload_OK_only(); + } + } + // set audio out to TXC board pinMode(AUDIO_OUT_PIN, OUTPUT); - + // set LEDs and blink once // if (!wifi) Serial.println("Blinking pins"); - pinMode(LED_BUILTIN, OUTPUT); // Set LED pin to output + pinMode(led_builtin_pin, OUTPUT); // Set LED pin to output + blink_pin(led_builtin_pin, 150); +// digitalWrite(led_builtin_pin, HIGH); // Leave Pico LED on pinMode(MAIN_LED_GREEN, OUTPUT); // Set Main Green LED pin to output blink_pin(MAIN_LED_GREEN, 150); digitalWrite(MAIN_LED_GREEN, HIGH); // Leave Green LED on @@ -3662,7 +3698,11 @@ void config_gpio() { pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); Serial.println(analogRead(AUDIO_IN_PIN)); - + + pinMode(29, INPUT); + Serial.print("ADC3: "); + Serial.println(analogRead(29)); + pinMode(PTT_PIN, OUTPUT); // PTT active LOW digitalWrite(PTT_PIN, HIGH); @@ -3795,25 +3835,29 @@ void client_print_string(char *string) } client.println(" "); } - +*/ bool check_for_wifi() { #ifndef PICO_W - + + Serial.println("WiFi disabled in software"); return(false); // skip check if not Pico W board or compilation will fail #endif // stdio_init_all(); - adc_init(); - adc_gpio_init(29); - adc_select_input(3); +// adc_init(); +// adc_gpio_init(29); + pinMode(29, INPUT); +// adc_select_input(3); const float conversion_factor = 3.3f / (1 << 12); - uint16_t result = adc_read(); +// uint16_t result = adc_read(); + uint16_t result = analogRead(29); // Serial.printf("ADC3 value: 0x%03x, voltage: %f V\n", result, result * conversion_factor); - if (result < 0x100) { +// if (result < 0x100) { + if (result < 0x10) { Serial.println("\nPico W detected!\n"); return(true); } @@ -3823,7 +3867,7 @@ bool check_for_wifi() { } } - +/* void check_for_browser() { if (!wifi) return; @@ -3931,8 +3975,15 @@ void configure_wifi() { */ void transmit_cw(int freq, float duration) { // freq in Hz, duration in milliseconds - // if (!wifi) +// if (!wifi) +/* + if (wifi) digitalWrite(LED_BUILTIN, HIGH); // Transmit LED on + else + digitalWrite(25, HIGH); // Transmit LED on +*/ + digitalWrite(led_builtin_pin, HIGH); + digitalWrite(MAIN_LED_BLUE, HIGH); unsigned long duration_us = duration * 1000; @@ -3959,9 +4010,15 @@ void transmit_cw(int freq, float duration) { // freq in Hz, duration in millise digitalWrite(BPSK_CONTROL_A, LOW); clockgen.enableOutputs(false); } - + // if (!wifi) +/* + if (wifi) digitalWrite(LED_BUILTIN, LOW); // Transmit LED off + else + digitalWrite(25, LOW); // Transmit LED on +*/ + digitalWrite(led_builtin_pin, LOW); digitalWrite(MAIN_LED_BLUE, LOW); } @@ -4179,22 +4236,7 @@ void serial_input() { case 'h': case 'H': // Serial.println("Help"); - prompt = PROMPT_HELP; - /* - Serial.println("\nChange settings by typing the letter:"); - Serial.println("h Help info"); - Serial.println("a AFSK/APRS mode"); - Serial.println("c CW mode"); - Serial.println("f FSK/DUV mode"); - Serial.println("b BPSK mode"); - Serial.println("s SSTV mode"); - Serial.println("i Restart"); - Serial.println("c CALLSIGN"); - Serial.println("t Simulated Telemetry"); - Serial.println("r Resets Count, or payload & EEPROM"); - Serial.println("l Lat and Long"); - Serial.println("? Query sensors\n"); -*/ + prompt = PROMPT_HELP; break; case 'a': @@ -4241,10 +4283,15 @@ void serial_input() { break; case 'c': - case 'C': Serial.println("Change the CALLSIGN"); prompt = PROMPT_CALLSIGN; break; + + case 'C': + Serial.println("Debug camera"); + debug_camera = true; + prompt = PROMPT_CAMERA; + break; case 't': case 'T': @@ -4292,6 +4339,12 @@ void serial_input() { prompt = PROMPT_DEBUG; break; + case 'w': + Serial.println(wifi); + Serial.println("Connect to WiFi"); + prompt = PROMPT_WIFI; + break; + default: Serial.println("Not a command\n"); @@ -4322,22 +4375,48 @@ void prompt_for_input() { Serial.println("a AFSK/APRS mode"); Serial.println("m CW mode"); Serial.println("f FSK/DUV mode"); + Serial.println("F Format flash memory"); Serial.println("b BPSK mode"); Serial.println("s SSTV mode"); Serial.println("S I2C scan"); Serial.println("i Restart"); - Serial.println("c CALLSIGN"); + Serial.println("c Change CALLSIGN"); + Serial.println("C Debug Camera"); Serial.println("t Simulated Telemetry"); - Serial.println("r Resets Count"); - Serial.println("p Resets payload and stored EEPROM values"); - Serial.println("l Lat and Lon"); + Serial.println("r Reset Count"); + Serial.println("p Reset payload and stored EEPROM values"); + Serial.println("l Change Lat and Lon"); Serial.println("? Query sensors"); Serial.println("v Read INA219 voltage and current"); Serial.println("o Read diode temperature"); - Serial.println("d Change debug mode\n"); + Serial.println("d Change debug mode"); + Serial.println("w Connect to WiFi\n"); Serial.printf("Config file /sim.cfg contains %s %d %f %f %s\n\n", callsign, reset_count, lat_file, long_file, sim_yes); + switch(mode) { + + case(AFSK): + Serial.println("AFSK mode"); + break; + + case(FSK): + Serial.println("FSK mode"); + break; + + case(BPSK): + Serial.println("BPSK mode"); + break; + + case(SSTV): + Serial.println("SSTV mode"); + break; + + case(CW): + Serial.println("CW mode"); + break; + } + break; case PROMPT_CALLSIGN: @@ -4426,6 +4505,12 @@ void prompt_for_input() { payload_command = PAYLOAD_QUERY; break; + case PROMPT_CAMERA: + show_dir(); + get_camera_image(debug_camera); + show_dir(); + break; + case PROMPT_TEMP: sensorValue = analogRead(TEMPERATURE_PIN); Serial.print("Raw diode voltage: "); @@ -4492,7 +4577,47 @@ void prompt_for_input() { else Serial.println("off"); break; - + + case PROMPT_WIFI: + Serial.println(wifi); + if (wifi) { + char ssid[30], pass[30]; + Serial.println("Enter the credentials for your WiFi network"); + + Serial.print("Enter WiFi SSID: "); + get_serial_string(); + + print_string(serial_string); + + if (strlen(serial_string) > 0) { + strcpy(ssid, serial_string); + Serial.print("Enter WiFi password: "); + get_serial_string(); + if (strlen(serial_string) > 0) { + strcpy(pass, serial_string); + Serial.println("Connecting to Wifi"); +// Serial.printf("%s%s\n",ssid, pass); + + WiFi.begin(ssid, pass); + + unsigned int elapsed_timer = (unsigned int) millis(); + while ((WiFi.status() != WL_CONNECTED) && ((millis() - elapsed_timer) < 10000)) { + Serial.print("."); + delay(500); + } + if (((millis() - elapsed_timer) > 10000)) + Serial.println("Failed to connect!"); + else + Serial.println("Connected to WiFi!"); + } else + Serial.println("No password entered."); + } else + Serial.println("No SSID entered."); + } else + Serial.println("WiFi not available"); + + break; + case PROMPT_I2CSCAN: Serial.print("I2C scan"); @@ -4810,7 +4935,7 @@ void get_input() { void transmit_led(bool status) { if(filter_present) { // if (!wifi) - digitalWrite(LED_BUILTIN, status); + digitalWrite(led_builtin_pin, status); digitalWrite(MAIN_LED_BLUE, status); } } diff --git a/cubesatsim/pico-get-jpeg-serial.cpp b/cubesatsim/pico-get-jpeg-serial.cpp index 530e2f20..de073ec6 100644 --- a/cubesatsim/pico-get-jpeg-serial.cpp +++ b/cubesatsim/pico-get-jpeg-serial.cpp @@ -31,7 +31,7 @@ FastCRC8 CRC8; //#define PICOW true int led_pin = LED_BUILTIN; -bool get_camera_image(); +bool get_camera_image(bool debug_camera); bool start_camera(); bool start_camera() { @@ -67,14 +67,14 @@ bool start_camera() { delay(100); Serial2.begin(115200); #ifdef GET_IMAGE_DEBUG - Serial.println("Started Serial2 to camera v0.2"); + Serial.println("Started Serial2 to camera v0.3"); #endif LittleFS.begin(); bool camera_present = false; // int tries = 0; // while ((tries++ < 5) && !camera_present) { - if (get_camera_image()) { + if (get_camera_image(false)) { camera_present = true; Serial.println("Camera detected!"); } @@ -166,7 +166,7 @@ void loop() { } */ -bool get_camera_image() { +bool get_camera_image(bool debug_camera) { index1 = 0; flag_count = 0; @@ -175,14 +175,16 @@ bool get_camera_image() { end_flag_detected = false; jpeg_start = 0; -#ifdef GET_IMAGE_DEBUG - Serial.println("Starting get_image_file"); - #endif - finished = false; - Serial.println("Enabling ESP32-CAM"); pinMode(ESP32_CAM_ENABLE_PIN, OUTPUT); digitalWrite(ESP32_CAM_ENABLE_PIN, HIGH); + +// #ifdef GET_IMAGE_DEBUG + if (debug_camera) + Serial.println("Received from ESP32-CAM hex encoded:\n"); + // #endif + finished = false; + unsigned long time_start = millis(); while ((!finished) && ((millis() - time_start) < CAMERA_TIMEOUT)) { @@ -195,7 +197,8 @@ bool get_camera_image() { if (octet == end_flag[flag_count]) { // looking for end flag // if (end_flag_detected) { flag_count++; -#ifdef GET_IMAGE_DEBUG +#ifdef GET_IMAGE_DEBUG +// if (debug_camera) Serial.println("Found part of end flag!"); #endif if (flag_count >= strlen(end_flag)) { // complete image @@ -210,7 +213,7 @@ bool get_camera_image() { int received_crc = Serial2.read(); // buffer2[index1++] = octet; - Serial.print("File length: "); + Serial.print("\nFile length: "); Serial.println(index1 - (int)strlen(end_flag)); // index1 -= 1; // 40; // Serial.println(buffer2[index1 - 1], HEX); @@ -219,12 +222,15 @@ bool get_camera_image() { uint8_t * data = (uint8_t *) &buffer2[0]; #ifdef GET_IMAGE_DEBUG - Serial.println("\nCRC cacluation data:"); - Serial.println(buffer2[0], HEX); + Serial.println(buffer2[0], HEX); Serial.println(buffer2[index1 - 1], HEX); - Serial.println(index1); - Serial.println(received_crc, HEX); - #endif + Serial.println(index1); + #endif + if (debug_camera) { + Serial.print("\nCRC received:"); + Serial.println(received_crc, HEX); + } + int calculated_crc = CRC8.smbus(data, index1); // Serial.println(calculated_crc, HEX); if (received_crc == calculated_crc) @@ -246,7 +252,8 @@ bool get_camera_image() { } /// buffer2[index1++] = octet; -#ifdef GET_IMAGE_DEBUG +//#ifdef GET_IMAGE_DEBUG + if (debug_camera) { char hexValue[5]; if (octet != 0x66) { sprintf(hexValue, "%02X", octet); @@ -256,7 +263,8 @@ bool get_camera_image() { Serial.print("66"); } // Serial.write(octet); -#endif + } +//#endif if (index1 > 100000) index1 = 0; // } @@ -277,6 +285,8 @@ bool get_camera_image() { } // Serial.println("writing to Serial2"); } + if (debug_camera) + Serial.print("\nCamera complete\n"); digitalWrite(ESP32_CAM_ENABLE_PIN, LOW); return(finished); }