Skip to content

Commit 8e4d43e

Browse files
authored
Merge pull request #649 from embedcat/master
[modem]: Add ability to change ESP_MODEM_C_API_STR_MAX from Kconfig (IDFGH-13668)
2 parents 571a741 + 1790989 commit 8e4d43e

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

components/esp_modem/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ menu "esp-modem"
6363
dce_factory::Factory::create_unique_dce_from<CustomModule, DCE*>(dce_config, std::move(dte), netif)
6464
Please refer to the pppos_client example for more details.
6565

66+
config ESP_MODEM_C_API_STR_MAX
67+
int "Size in bytes for response from AT commands returning textual values (C-API)"
68+
default 128
69+
help
70+
Some AT commands returns textrual values which C-API copy as c-string to user allocated space,
71+
it also truncates the output data to this size. Increase this if some AT answers are truncated.
72+
6673
endmenu

components/esp_modem/examples/pppos_client/main/custom_module.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ DCE *esp_modem_create_custom_dce(const esp_modem_dce_config_t *dce_config, std::
5656
/**
5757
* @brief This API is only needed for extending standard C-API, since we added get_time() method to our CustomModule
5858
*
59-
* @note This header is included from esp_modem_c_api.cpp, so it could use ESP_MODEM_C_API_STR_MAX macro
59+
* @note This header is included from esp_modem_c_api.cpp, so it could use CONFIG_ESP_MODEM_C_API_STR_MAX macro
6060
* indicating maximum C-API string size
6161
*
6262
* @note In order to access the newly added API get_time(), we have to static_cast<> the GenericModule from DCE
@@ -70,10 +70,10 @@ extern "C" esp_err_t esp_modem_get_time(esp_modem_dce_t *dce_wrap, char *p_time)
7070
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
7171
return ESP_ERR_INVALID_ARG;
7272
}
73-
std::string time{ESP_MODEM_C_API_STR_MAX};
73+
std::string time{CONFIG_ESP_MODEM_C_API_STR_MAX};
7474
auto ret = command_response_to_esp_err(static_cast<SIM7600_WITH_TIME *>(dce_wrap->dce->get_module())->get_time(time));
7575
if (ret == ESP_OK && !time.empty()) {
76-
strlcpy(p_time, time.c_str(), ESP_MODEM_C_API_STR_MAX);
76+
strlcpy(p_time, time.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
7777
}
7878
return ret;
7979
}

components/esp_modem/src/esp_modem_c_api.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#include "exception_stub.hpp"
1717
#include "esp_private/c_api_wrapper.hpp"
1818

19-
#ifndef ESP_MODEM_C_API_STR_MAX
20-
#define ESP_MODEM_C_API_STR_MAX 128
21-
#endif
22-
2319
#ifndef HAVE_STRLCPY
2420
size_t strlcpy(char *dest, const char *src, size_t len);
2521
#endif
@@ -180,7 +176,7 @@ extern "C" esp_err_t esp_modem_at(esp_modem_dce_t *dce_wrap, const char *at, cha
180176
std::string at_str(at);
181177
auto ret = command_response_to_esp_err(dce_wrap->dce->at(at_str, out, timeout));
182178
if ((p_out != NULL) && (!out.empty())) {
183-
strlcpy(p_out, out.c_str(), ESP_MODEM_C_API_STR_MAX);
179+
strlcpy(p_out, out.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
184180
}
185181
return ret;
186182
}
@@ -201,7 +197,7 @@ extern "C" esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce_wrap, char *p_imsi)
201197
std::string imsi;
202198
auto ret = command_response_to_esp_err(dce_wrap->dce->get_imsi(imsi));
203199
if (ret == ESP_OK && !imsi.empty()) {
204-
strlcpy(p_imsi, imsi.c_str(), ESP_MODEM_C_API_STR_MAX);
200+
strlcpy(p_imsi, imsi.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
205201
}
206202
return ret;
207203
}
@@ -214,7 +210,7 @@ extern "C" esp_err_t esp_modem_at_raw(esp_modem_dce_t *dce_wrap, const char *cmd
214210
std::string out;
215211
auto ret = command_response_to_esp_err(dce_wrap->dce->at_raw(cmd, out, pass, fail, timeout));
216212
if ((p_out != NULL) && (!out.empty())) {
217-
strlcpy(p_out, out.c_str(), ESP_MODEM_C_API_STR_MAX);
213+
strlcpy(p_out, out.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
218214
}
219215
return ret;
220216
}
@@ -244,7 +240,7 @@ extern "C" esp_err_t esp_modem_get_imei(esp_modem_dce_t *dce_wrap, char *p_imei)
244240
std::string imei;
245241
auto ret = command_response_to_esp_err(dce_wrap->dce->get_imei(imei));
246242
if (ret == ESP_OK && !imei.empty()) {
247-
strlcpy(p_imei, imei.c_str(), ESP_MODEM_C_API_STR_MAX);
243+
strlcpy(p_imei, imei.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
248244
}
249245
return ret;
250246
}
@@ -258,7 +254,7 @@ extern "C" esp_err_t esp_modem_get_operator_name(esp_modem_dce_t *dce_wrap, char
258254
int act;
259255
auto ret = command_response_to_esp_err(dce_wrap->dce->get_operator_name(name, act));
260256
if (ret == ESP_OK && !name.empty()) {
261-
strlcpy(p_name, name.c_str(), ESP_MODEM_C_API_STR_MAX);
257+
strlcpy(p_name, name.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
262258
*p_act = act;
263259
}
264260
return ret;
@@ -272,7 +268,7 @@ extern "C" esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce_wrap, char *
272268
std::string name;
273269
auto ret = command_response_to_esp_err(dce_wrap->dce->get_module_name(name));
274270
if (ret == ESP_OK && !name.empty()) {
275-
strlcpy(p_name, name.c_str(), ESP_MODEM_C_API_STR_MAX);
271+
strlcpy(p_name, name.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX);
276272
}
277273
return ret;
278274
}

docs/esp_modem/en/api_docs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ These functions are the actual commands to communicate with the modem using AT c
4343

4444
Note that the functions which implement AT commands returning textual values use plain ``char *``
4545
pointer as the return value. The API expects the output data to point to user allocated space of at least
46-
``ESP_MODEM_C_API_STR_MAX`` (64 by default) bytes, it also truncates the output data to this size.
46+
``CONFIG_ESP_MODEM_C_API_STR_MAX`` (128 by default) bytes, it also truncates the output data to this size.
4747

4848
.. doxygenfile:: esp_modem_api_commands.h
4949

0 commit comments

Comments
 (0)