diff --git a/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp b/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp index 3947d70e..3c30253e 100644 --- a/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp +++ b/managed_components/espressif__esp_modem/src/esp_modem_command_library.cpp @@ -89,6 +89,22 @@ command_result generic_get_string(CommandableIf *t, const std::string &command, return ret; } +command_result generic_get_custom_string(CommandableIf *t, const std::string &command, std::string &output, uint32_t timeout_ms = 500) +{ + ESP_LOGV(TAG, "%s", __func__); + + return t->command(command, [&](uint8_t *data, size_t len) { + output.assign(reinterpret_cast(data), len); + + if (output.find("OK") != std::string::npos) { + return command_result::OK; + } else if (output.find("ERROR") != std::string::npos) { + return command_result::FAIL; + } + + return command_result::TIMEOUT; + }, timeout_ms); +} command_result generic_command_common(CommandableIf *t, const std::string &command, uint32_t timeout_ms) { @@ -385,8 +401,7 @@ command_result set_pin(CommandableIf *t, const std::string &pin) command_result at(CommandableIf *t, const std::string &cmd, std::string &out, int timeout = 500) { ESP_LOGV(TAG, "%s", __func__ ); - std::string at_command = cmd + "\r"; - return generic_get_string(t, at_command, out, timeout); + return generic_get_custom_string(t, cmd, out, timeout); } command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber) @@ -575,3 +590,4 @@ command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode) } } // esp_modem::dce_commands +