Add "at" api for custom commands

This commit is contained in:
Bruno Binet
2022-05-31 14:22:41 +02:00
parent 51a50db0fd
commit 0cf08fb676
3 changed files with 31 additions and 2 deletions

View File

@ -67,6 +67,14 @@ ESP_MODEM_DECLARE_DCE_COMMAND(store_profile, command_result, 0) \
*/\ */\
ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, STRING_IN(p1, pin)) \ ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, STRING_IN(p1, pin)) \
\ \
/**
* @brief Execute the supplied AT command
* @param[in] at AT command
* @param[out] out Command output string
* @return OK, FAIL or TIMEOUT
*/\
ESP_MODEM_DECLARE_DCE_COMMAND(at, command_result, 2, STRING_IN(p1, cmd), STRING_OUT(p2, out)) \
\
/** /**
* @brief Checks if the SIM needs a PIN * @brief Checks if the SIM needs a PIN
* @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock * @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock

View File

@ -184,6 +184,20 @@ extern "C" esp_err_t esp_modem_set_pin(esp_modem_dce_t *dce_wrap, const char *pi
return command_response_to_esp_err(dce_wrap->dce->set_pin(pin_str)); return command_response_to_esp_err(dce_wrap->dce->set_pin(pin_str));
} }
extern "C" esp_err_t esp_modem_at(esp_modem_dce_t *dce_wrap, const char *at, char *p_out)
{
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
return ESP_ERR_INVALID_ARG;
}
std::string out;
std::string at_str(at);
auto ret = command_response_to_esp_err(dce_wrap->dce->at(at_str, out));
if ((p_out != NULL) && (!out.empty())) {
strlcpy(p_out, out.c_str(), ESP_MODEM_C_API_STR_MAX);
}
return ret;
}
extern "C" esp_err_t esp_modem_get_signal_quality(esp_modem_dce_t *dce_wrap, int *rssi, int *ber) extern "C" esp_err_t esp_modem_get_signal_quality(esp_modem_dce_t *dce_wrap, int *rssi, int *ber)
{ {
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {

View File

@ -379,6 +379,13 @@ command_result set_pin(CommandableIf *t, const std::string &pin)
return generic_command_common(t, set_pin_command); return generic_command_common(t, set_pin_command);
} }
command_result at(CommandableIf *t, const std::string &cmd, std::string &out)
{
ESP_LOGV(TAG, "%s", __func__ );
std::string at_command = cmd + "\r";
return generic_get_string(t, at_command, out);
}
command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber) command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber)
{ {
ESP_LOGV(TAG, "%s", __func__ ); ESP_LOGV(TAG, "%s", __func__ );