diff --git a/ESP32_AP-Flasher/include/commstructs.h b/ESP32_AP-Flasher/include/commstructs.h index c6c1cb1a..ac73dd81 100644 --- a/ESP32_AP-Flasher/include/commstructs.h +++ b/ESP32_AP-Flasher/include/commstructs.h @@ -13,6 +13,12 @@ struct espXferComplete { uint8_t src[8]; } __packed; +struct espSetChannelPower { + uint8_t checksum; + uint8_t channel; + uint8_t power; +} __packed; + struct blockData { uint16_t size; uint16_t checksum; diff --git a/ESP32_AP-Flasher/include/serial.h b/ESP32_AP-Flasher/include/serial.h index 76ed03a1..bc597799 100644 --- a/ESP32_AP-Flasher/include/serial.h +++ b/ESP32_AP-Flasher/include/serial.h @@ -5,4 +5,6 @@ void zbsRxTask(void* parameter); void sendCancelPending(struct pendingData* pending); void sendDataAvail(struct pendingData* pending); -void Ping(); \ No newline at end of file +void Ping(); + +bool sendChannelPower(struct espSetChannelPower* scp); \ No newline at end of file diff --git a/ESP32_AP-Flasher/src/serial.cpp b/ESP32_AP-Flasher/src/serial.cpp index 26e9c15e..29a5549b 100644 --- a/ESP32_AP-Flasher/src/serial.cpp +++ b/ESP32_AP-Flasher/src/serial.cpp @@ -144,23 +144,42 @@ sdasend: void sendCancelPending(struct pendingData* pending) { if (!txStart()) return; addCRC(pending, sizeof(struct pendingData)); - addCRC(pending, sizeof(struct pendingData)); for (uint8_t attempt = 0; attempt < 5; attempt++) { cmdReplyValue = CMD_REPLY_WAIT; AP_SERIAL_PORT.print("CXD>"); for (uint8_t c = 0; c < sizeof(struct pendingData); c++) { AP_SERIAL_PORT.write(((uint8_t*)pending)[c]); } - if (waitCmdReply()) goto cxdsend; + if (waitCmdReply()) goto cxdsent; AP_SERIAL_PORT.printf("CXD send failed in try %d\n", attempt); } AP_SERIAL_PORT.print("CXD failed to send...\n"); txEnd(); return; -cxdsend: +cxdsent: txEnd(); } +bool sendChannelPower(struct espSetChannelPower* scp) { + if (!txStart()) return false; + addCRC(scp, sizeof(struct espSetChannelPower)); + for (uint8_t attempt = 0; attempt < 5; attempt++) { + cmdReplyValue = CMD_REPLY_WAIT; + AP_SERIAL_PORT.print("SCP>"); + for (uint8_t c = 0; c < sizeof(struct espSetChannelPower); c++) { + AP_SERIAL_PORT.write(((uint8_t*)scp)[c]); + } + if (waitCmdReply()) goto scpSent; + AP_SERIAL_PORT.printf("SCP send failed in try %d\n", attempt); + } + AP_SERIAL_PORT.print("SCP failed to send...\n"); + txEnd(); + return false; +scpSent: + txEnd(); + return true; +} + uint64_t waitingForVersion = 0; uint8_t crashcounter = 0; uint16_t version; @@ -372,6 +391,7 @@ void zbsRxTask(void* parameter) { Serial.println("Performing firmware flash in about 10 seconds"); vTaskDelay(10000 / portTICK_PERIOD_MS); performDeviceFlash(); + //findOriginalFirmwareVersion(); } else { Serial.println("I wasn't able to connect to a ZBS tag, trying to reboot the tag."); rampTagPower(FLASHER_AP_POWER, false); @@ -401,6 +421,12 @@ void zbsRxTask(void* parameter) { } } else if (!fsversion) { Serial.println("No ZBS/Zigbee FW binary found on SPIFFS, please upload a zigbeebase000X.bin - format binary to enable flashing"); + + struct espSetChannelPower scp; + scp.channel = 20; + scp.power = 8; + sendChannelPower(&scp); + } firstrun = false; }