8000 Merge pull request #167 from pycom/lte_send_at_cmd_timeout · pycom/pycom-micropython-sigfox@fdedb33 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit fdedb33

Browse files
authored
Merge pull request #167 from pycom/lte_send_at_cmd_timeout
Add timeout parameter to lte_send_at_cmd
2 parents aeabdce + 218035c commit fdedb33

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

esp32/lte/lteppp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
258258
if (timeout_cnt > 0) {
259259
timeout_cnt--;
260260
}
261-
} while (timeout_cnt > 0 && 0 == rx_len);
261+
} while ((timeout_cnt > 0 || timeout == 0) && 0 == rx_len);
262262

263263
memset(lteppp_trx_buffer, 0, LTE_UART_BUFFER_SIZE);
264264
uint16_t len_count = 0;

esp32/mods/modlte.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,8 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
12361236
lte_check_init();
12371237
lte_check_inppp();
12381238
STATIC const mp_arg_t allowed_args[] = {
1239-
{ MP_QSTR_cmd, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} },
1240-
{ MP_QSTR_delay, MP_ARG_INT, {.u_int = LTE_RX_TIMEOUT_MAX_MS} }
1239+
{ MP_QSTR_cmd, MP_ARG_OBJ, {.u_obj = mp_const_none} },
1240+
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = LTE_RX_TIMEOUT_MAX_MS} },
12411241
};
12421242
// parse args
12431243
uint32_t argLength = MP_ARRAY_SIZE(allowed_args);
@@ -1246,34 +1246,10 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
12461246
if (args[0].u_obj == mp_const_none) {
12471247
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "the command must be specified!"));
12481248
}
1249-
uint32_t timeout = LTE_RX_TIMEOUT_MAX_MS;
12501249
if (MP_OBJ_IS_STR_OR_BYTES(args[0].u_obj))
12511250
{
12521251
size_t len;
1253-
char* command = (char *)(mp_obj_str_get_data(args[0].u_obj, &len));
1254-
1255-
if(argLength > 1) {
1256-
timeout = args[1].u_int;
1257-
}
1258-
1259-
if(len <= LTE_AT_CMD_DATA_SIZE_MAX) {
1260-
lte_push_at_command_ext_cont(command, timeout, NULL, len, false);
1261-
} else {
1262-
size_t chunk_count = len / LTE_AT_CMD_DATA_SIZE_MAX;
1263-
size_t remaining_bytes = len % LTE_AT_CMD_DATA_SIZE_MAX;
1264-
1265-
bool expect_continuation = false;
1266-
char* chunk_start = command;
1267-
for(size_t i = 0; i < chunk_count; ++i) {
1268-
expect_continuation = (i < (chunk_count - 1)) || remaining_bytes;
1269-
lte_push_at_command_ext_cont(chunk_start, timeout, NULL, LTE_AT_CMD_DATA_SIZE_MAX, expect_continuation);
1270-
chunk_start += LTE_AT_CMD_DATA_SIZE_MAX;
1271-
}
1272-
1273-
if(remaining_bytes) {
1274-
lte_push_at_command_ext_cont(chunk_start, timeout, NULL, remaining_bytes, false);
1275-
}
1276-
}
1252+
lte_push_at_command_ext((char *)(mp_obj_str_get_data(args[0].u_obj, &len)), args[1].u_int, NULL, len);
12771253
}
12781254
else
12791255
{
@@ -1285,7 +1261,7 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
12851261
vstr_add_str(&vstr, modlte_rsp.data);
12861262
while(modlte_rsp.data_remaining)
12871263
{
1288-
lte_push_at_command_ext("Pycom_Dummy", LTE_RX_TIMEOUT_MAX_MS, NULL, strlen("Pycom_Dummy") );
1264+
lte_push_at_command_ext("Pycom_Dummy", args[1].u_int, NULL, strlen("Pycom_Dummy") );
12891265
vstr_add_str(&vstr, modlte_rsp.data);
12901266
}
12911267
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);

0 commit comments

Comments
 (0)
0