Skip to content

Commit

Permalink
Update handshake to support AP mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mill1000 committed Jan 9, 2024
1 parent 8531fb1 commit 155f826
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
42 changes: 39 additions & 3 deletions components/winix_c545/winix_c545.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion components/winix_c545/winix_c545.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 155f826

Please sign in to comment.