Fixes sim800l (#678)

* Fix receive message quickly

* fix case

* lint
This commit is contained in:
Guillermo Ruffino 2019-08-31 14:45:34 -03:00 committed by Otto Winter
parent 4c03cebef3
commit b6920025b2

View file

@ -67,12 +67,18 @@ void Sim800LComponent::parse_cmd_(std::string message) {
}
switch (this->state_) {
case STATE_INIT:
if (message.compare(0, 6, "+CMTI:") == 0) {
case STATE_INIT: {
// While we were waiting for update to check for messages, this notifies a message
// is available. Grab it quickly
this->state_ = STATE_CHECK_SMS;
// is available.
bool message_available = message.compare(0, 6, "+CMTI:") == 0;
if (!message_available)
break;
// Else fall thru ...
}
case STATE_CHECK_SMS:
send_cmd_("AT+CMGL=\"ALL\"");
this->state_ = STATE_PARSE_SMS;
this->parse_index_ = 0;
break;
case STATE_DISABLE_ECHO:
send_cmd_("ATE0");
@ -95,7 +101,6 @@ void Sim800LComponent::parse_cmd_(std::string message) {
if (registered) {
if (!this->registered_)
ESP_LOGD(TAG, "Registered OK");
send_cmd_("AT+CSQ");
this->state_ = STATE_CSQ;
this->expect_ack_ = true;
} else {
@ -113,6 +118,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
break;
}
case STATE_CSQ:
send_cmd_("AT+CSQ");
this->state_ = STATE_CSQ_RESPONSE;
break;
case STATE_CSQ_RESPONSE:
@ -123,6 +129,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
ESP_LOGD(TAG, "RSSI: %d", this->rssi_);
}
}
this->expect_ack_ = true;
this->state_ = STATE_CHECK_SMS;
break;
case STATE_PARSE_SMS:
@ -209,12 +216,6 @@ void Sim800LComponent::parse_cmd_(std::string message) {
ESP_LOGD(TAG, "Unhandled: %s - %d", message.c_str(), this->state_);
break;
}
if (this->state_ == STATE_CHECK_SMS) {
send_cmd_("AT+CMGL=\"ALL\"");
this->state_ = STATE_PARSE_SMS;
this->parse_index_ = 0;
this->expect_ack_ = true;
}
}
void Sim800LComponent::loop() {