From cfee590f01fb7d841c67ee50ec022a09424cf8f6 Mon Sep 17 00:00:00 2001 From: Jelmer Date: Sun, 7 May 2023 15:42:49 +0200 Subject: [PATCH] Added the option to run an AP from another port --- ESP32_AP-Flasher/include/flasher.h | 8 +----- ESP32_AP-Flasher/include/settings.h | 10 ++++++++ ESP32_AP-Flasher/src/flasher.cpp | 11 ++++----- ESP32_AP-Flasher/src/main.cpp | 2 -- ESP32_AP-Flasher/src/serialap.cpp | 38 +++++++++++++++++++++++------ 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ESP32_AP-Flasher/include/flasher.h b/ESP32_AP-Flasher/include/flasher.h index 57f46a18..b3ed704e 100644 --- a/ESP32_AP-Flasher/include/flasher.h +++ b/ESP32_AP-Flasher/include/flasher.h @@ -5,10 +5,4 @@ bool checkForcedAPFlash(); bool doForcedAPFlash(); bool doAPFlash(); bool doAPUpdate(uint8_t type); -bool doTagFlash(); - -#define FLASHER_AP_PORT 0 -#ifdef OPENEPAPERLINK_PCB -#define FLASHER_EXT_PORT 1 -#define FLASHER_ALTRADIO_PORT 2 -#endif \ No newline at end of file +bool doTagFlash(); \ No newline at end of file diff --git a/ESP32_AP-Flasher/include/settings.h b/ESP32_AP-Flasher/include/settings.h index 22a539ea..947683f7 100644 --- a/ESP32_AP-Flasher/include/settings.h +++ b/ESP32_AP-Flasher/include/settings.h @@ -1,5 +1,11 @@ #include +#define FLASHER_AP_PORT 0 +#ifdef OPENEPAPERLINK_PCB +#define FLASHER_EXT_PORT 1 +#define FLASHER_ALTRADIO_PORT 2 +#endif + // how long the we should keep the transfer metadata #define PENDING_TIMEOUT 24 * 3600 // this determines how long images will be cached; @@ -7,6 +13,10 @@ // maximum time (in minutes) that a tag is put to sleep if no update is expected. #define MIN_RESPONSE_TIME 10 +// Which port we should use for the AP process +// (useful for testing, can only be FLASHER_AP_PORT for any other board than the OpenEPaperLinkPCB board) +#define AP_PROCESS_PORT FLASHER_AP_PORT + // flasher options #define CUSTOM_MAC_HDR 0x0000 diff --git a/ESP32_AP-Flasher/src/flasher.cpp b/ESP32_AP-Flasher/src/flasher.cpp index 34f8d76b..65da0b08 100644 --- a/ESP32_AP-Flasher/src/flasher.cpp +++ b/ESP32_AP-Flasher/src/flasher.cpp @@ -119,7 +119,7 @@ bool flasher::connectTag(uint8_t port) { Serial.printf("Tried to connect to port %d, but this port isn't available. Some dev borked it up, probably Jelmer.\n", port); return false; } - if (!result) Serial.printf("I tried connecting to port, but I couldn't establish a link to the tag. That's all I know.\n"); + if (!result) Serial.printf("I tried connecting to port %d, but I couldn't establish a link to the tag. That's all I know.\n", port); return result; } @@ -499,7 +499,7 @@ bool checkForcedAPFlash() { bool doForcedAPFlash() { Serial.printf("Doing a forced AP Flash!\n"); class flasher *f = new flasher(); - if (!f->connectTag(0)) { + if (!f->connectTag(AP_PROCESS_PORT)) { Serial.printf("Sorry, failed to connect to this tag...\n"); delete f; return false; @@ -525,7 +525,7 @@ bool doForcedAPFlash() { bool doAPFlash() { // This function expects a tag in stock configuration, to be used as an AP. It can also work with 'dead' AP's. class flasher *f = new flasher(); - if (!f->connectTag(0)) { + if (!f->connectTag(AP_PROCESS_PORT)) { Serial.printf("Sorry, failed to connect to this tag...\n"); delete f; return false; @@ -557,7 +557,7 @@ bool doAPFlash() { bool doAPUpdate(uint8_t type) { // this function expects the tag to be already flashed with some version of the OpenEpaperLink Firmware, and that it correctly reported its type class flasher *f = new flasher(); - if (!f->connectTag(0)) { + if (!f->connectTag(AP_PROCESS_PORT)) { Serial.printf("Sorry, failed to connect to this tag...\n"); delete f; return false; @@ -578,7 +578,6 @@ bool doAPUpdate(uint8_t type) { f->findTagByType(type); f->writeInfoBlock(); } - // TODO: DO THE ACTUAL FLASHING! bool res = f->writeFlashFromPack("/AP_FW_Pack.bin", f->tagtype); if(res)f->zbs->reset(); delete f; @@ -588,7 +587,7 @@ bool doAPUpdate(uint8_t type) { // perform device flash, save mac, everything bool doTagFlash() { class flasher *f = new flasher(); - if (!f->connectTag(1)) { + if (!f->connectTag(FLASHER_EXT_PORT)) { Serial.printf("Sorry, failed to connect to this tag...\n"); return false; } diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index 85aa2270..8c21590b 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -2,10 +2,8 @@ #include #include #include - #include "contentmanager.h" #include "flasher.h" -// #include "hal/wdt_hal.h" #include "makeimage.h" #include "serialap.h" #include "settings.h" diff --git a/ESP32_AP-Flasher/src/serialap.cpp b/ESP32_AP-Flasher/src/serialap.cpp index cb641f09..03928df0 100644 --- a/ESP32_AP-Flasher/src/serialap.cpp +++ b/ESP32_AP-Flasher/src/serialap.cpp @@ -108,17 +108,31 @@ bool waitCmdReply() { return false; } + +#if (AP_PROCESS_PORT == FLASHER_AP_PORT) +#define AP_RESET_PIN FLASHER_AP_RESET +#define AP_POWER_PIN FLASHER_AP_POWER +#endif +#if (AP_PROCESS_PORT == FLASHER_EXT_PORT) +#define AP_RESET_PIN FLASHER_EXT_RESET +#define AP_POWER_PIN FLASHER_EXT_POWER +#endif +#if (AP_PROCESS_PORT == FLASHER_ALTRADIO_PORT) +#define AP_RESET_PIN FLASHER_ALT_RESET +#define AP_POWER_PIN FLASHER_ALT_POWER +#endif + // Reset the tag void APTagReset() { - pinMode(FLASHER_AP_RESET, OUTPUT); - digitalWrite(FLASHER_AP_RESET, LOW); + pinMode(AP_RESET_PIN, OUTPUT); + digitalWrite(AP_RESET_PIN, LOW); vTaskDelay(10 / portTICK_PERIOD_MS); - rampTagPower(FLASHER_AP_POWER, false); + rampTagPower(AP_POWER_PIN, false); vTaskDelay(100 / portTICK_PERIOD_MS); - rampTagPower(FLASHER_AP_POWER, true); + rampTagPower(AP_POWER_PIN, true); vTaskDelay(10 / portTICK_PERIOD_MS); - digitalWrite(FLASHER_AP_RESET, HIGH); - rampTagPower(FLASHER_AP_POWER, true); + digitalWrite(AP_RESET_PIN, HIGH); + rampTagPower(AP_POWER_PIN, true); vTaskDelay(10 / portTICK_PERIOD_MS); } @@ -534,11 +548,21 @@ void APTask(void* parameter) { xTaskCreate(rxCmdProcessor, "rxCmdProcessor", 10000, NULL, configMAX_PRIORITIES - 10, NULL); xTaskCreate(rxSerialTask, "rxSerialTask", 4000, NULL, configMAX_PRIORITIES - 4, NULL); +#if (AP_PROCESS_PORT == FLASHER_AP_PORT) AP_SERIAL_PORT.begin(115200, SERIAL_8N1, FLASHER_AP_RXD, FLASHER_AP_TXD); +#endif +#if (AP_PROCESS_PORT == FLASHER_EXT_PORT) + AP_SERIAL_PORT.begin(115200, SERIAL_8N1, FLASHER_EXT_RXD, FLASHER_EXT_TXD); +#endif +#if (AP_PROCESS_PORT == FLASHER_ALTRADIO_PORT) + AP_SERIAL_PORT.begin(115200, SERIAL_8N1, FLASHER_AP_RXD, FLASHER_AP_TXD); +#endif vTaskDelay(3000 / portTICK_PERIOD_MS); - if(checkForcedAPFlash())doForcedAPFlash(); + if (checkForcedAPFlash()){ + doForcedAPFlash(); + } if (bringAPOnline()) { // AP works