This commit is contained in:
oarcher 2024-08-06 00:41:17 +02:00
parent af3b3c93ef
commit 9fa6db28eb

View file

@ -66,14 +66,6 @@ std::string ModemComponent::send_at(const std::string &cmd) {
return result; return result;
} }
// float ModemComponent::get_signal_strength() {
// // signal strength from rssi in percent
// float rssi = float(this->modem_status_.rssi);
// if (rssi >= 99.)
// return std::nanf("");
// return (rssi * 100) / 31;
// }
bool ModemComponent::get_imei(std::string &result) { bool ModemComponent::get_imei(std::string &result) {
// wrapper around this->dce->get_imei() that check that the result is valid // wrapper around this->dce->get_imei() that check that the result is valid
// (so it can be used to check if the modem is responding correctly (a simple 'AT' cmd is sometime not enough)) // (so it can be used to check if the modem is responding correctly (a simple 'AT' cmd is sometime not enough))
@ -131,9 +123,8 @@ bool ModemComponent::modem_ready(bool force_check) {
} }
std::string imei; std::string imei;
if (this->get_imei(imei)) { if (this->get_imei(imei)) {
// we are sure that the modem is on and synced // we are sure that the modem is on
this->internal_state_.powered_on = true; this->internal_state_.powered_on = true;
this->internal_state_.modem_synced = true;
return true; return true;
} }
} }
@ -271,13 +262,14 @@ void ModemComponent::loop() {
break; break;
case ModemPowerState::TONUART: case ModemPowerState::TONUART:
this->internal_state_.power_transition = false; this->internal_state_.power_transition = false;
ESP_LOGD(TAG, "TONUART check sync");
if (!this->modem_sync_()) { if (!this->modem_sync_()) {
ESP_LOGE(TAG, "Unable to power on the modem"); ESP_LOGE(TAG, "Unable to power on the modem");
this->internal_state_.powered_on = false; this->internal_state_.powered_on = false;
} else { } else {
ESP_LOGI(TAG, "Modem powered ON"); ESP_LOGI(TAG, "Modem powered ON");
this->internal_state_.powered_on = true; this->internal_state_.powered_on = true;
this->internal_state_.modem_synced = false; // this->internal_state_.modem_synced = false;
this->watchdog_.reset(); this->watchdog_.reset();
} }
break; break;
@ -527,8 +519,7 @@ bool ModemComponent::modem_sync_() {
uint32_t start_ms = millis(); uint32_t start_ms = millis();
uint32_t elapsed_ms; uint32_t elapsed_ms;
bool was_synced = this->internal_state_.modem_synced; ESP_LOGV(TAG, "Checking if the modem is synced...");
bool status = this->modem_ready(true); bool status = this->modem_ready(true);
if (!status) { if (!status) {
// Try to exit CMUX_MANUAL_DATA or DATA_MODE, if any // Try to exit CMUX_MANUAL_DATA or DATA_MODE, if any
@ -566,8 +557,9 @@ bool ModemComponent::modem_sync_() {
} }
} }
if (status && !was_synced) { if (status && !this->internal_state_.modem_synced) {
// First time the modem is synced, or modem recovered // First time the modem is synced, or modem recovered
this->internal_state_.modem_synced = true;
if (!this->prepare_sim_()) { if (!this->prepare_sim_()) {
// fatal error // fatal error
this->disable(); this->disable();
@ -583,6 +575,8 @@ bool ModemComponent::modem_sync_() {
this->internal_state_.modem_synced = status; this->internal_state_.modem_synced = status;
ESP_LOGVV(TAG, "Sync end status: %d", this->internal_state_.modem_synced);
return status; return status;
} }
@ -625,7 +619,7 @@ void ModemComponent::send_init_at_() {
ESP_LOGI(TAG, "'init_at' '%s' result: %s", cmd.c_str(), result.c_str()); ESP_LOGI(TAG, "'init_at' '%s' result: %s", cmd.c_str(), result.c_str());
} }
delay(this->command_delay_); delay(this->command_delay_);
yield(); App.feed_wdt();
} }
} }