diff --git a/components/winix_c545/winix_c545.cpp b/components/winix_c545/winix_c545.cpp index 4b4fae9..7899a3f 100644 --- a/components/winix_c545/winix_c545.cpp +++ b/components/winix_c545/winix_c545.cpp @@ -271,11 +271,20 @@ void WinixC545Component::parse_sentence_(char *sentence) { // Handle MCU_READY message if (strncmp(sentence, "MCU_READY", strlen("MCU_READY")) == 0) { - this->handshake_state_ = HandshakeState::McuReady; - this->last_handshake_event_ = millis(); - ESP_LOGI(TAG, "MCU_READY"); this->write_sentence_("MCU_READY:OK"); + + if (this->handshake_state_ == HandshakeState::ApDeviceReady) { + this->handshake_state_ = HandshakeState::ApStart; + this->last_handshake_event_ = millis(); + + ESP_LOGI(TAG, "AP START"); + this->write_sentence_("AP_STARTED:OK"); + } else { + this->handshake_state_ = HandshakeState::McuReady; + this->last_handshake_event_ = millis(); + } + return; } @@ -298,6 +307,9 @@ void WinixC545Component::parse_sentence_(char *sentence) { // Handle SMODE messages if (strncmp(sentence, "SMODE", strlen("SMODE")) == 0) { + this->handshake_state_ = HandshakeState::ApReboot; + this->last_handshake_event_ = millis(); + ESP_LOGI(TAG, "SMODE:OK"); this->write_sentence_("SMODE:OK"); return; @@ -369,6 +381,30 @@ void WinixC545Component::update_handshake_state_() { break; } + case HandshakeState::ApReboot: { + // AP mode requested, pretend to reboot into AP + this->handshake_state_ = HandshakeState::ApDeviceReady; + this->last_handshake_event_ = millis(); + + ESP_LOGI(TAG, "AP DEVICEREADY"); + this->write_sentence_("DEVICEREADY"); + break; + } + + case HandshakeState::ApStart: { + // Exit AP mode + this->handshake_state_ = HandshakeState::ApStop; + this->last_handshake_event_ = millis(); + + ESP_LOGI(TAG, "AP STOP"); + this->write_sentence_("AP_STOPED:OK"); + this->write_sentence_("ASSOCIATED:0"); + // TODO could get real network info but I don't think it matters + this->write_sentence_("IPALLOCATED:10.100.1.250 255.255.255.0 10.100.1.1 10.100.1.6"); + this->write_sentence_("AWS_IND:CONNECT OK"); + break; + } + default: { // If in an intermediate state and no activity occurs for a while reset the state machine if ((millis() - this->last_handshake_event_) < 10000) diff --git a/components/winix_c545/winix_c545.h b/components/winix_c545/winix_c545.h index 8e968d2..601ee11 100644 --- a/components/winix_c545/winix_c545.h +++ b/components/winix_c545/winix_c545.h @@ -93,9 +93,13 @@ class WinixC545Component : public uart::UARTDevice, public Component { enum class HandshakeState { Reset, DeviceReady, - MIB, McuReady, + MIB, Connected, + ApReboot, + ApDeviceReady, + ApStart, + ApStop, }; HandshakeState handshake_state_{HandshakeState::Reset};