8000 Merge pull request #164 from pycom/long_at · pycom/pycom-micropython-sigfox@499e857 · 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 499e857

Browse files
authored
Merge pull request #164 from pycom/long_at
Long at
2 parents a97b4f8 + 1df6dbf commit 499e857

File tree

3 files changed

+69
-19
lines changed

3 files changed

+69
-19
lines changed

esp32/lte/lteppp.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static bool lte_uart_break_evt = false;
9292
******************************************************************************/
9393
static void TASK_LTE (void *pvParameters);
9494
static void TASK_UART_EVT (void *pvParameters);
95-
static bool lteppp_send_at_cmd_exp(const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem, size_t len);
95+
static bool lteppp_send_at_cmd_exp(const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem, size_t len, bool expect_continuation);
9696
static bool lteppp_send_at_cmd(const char *cmd, uint32_t timeout);
9797
static bool lteppp_check_sim_present(void);
9898
static void lteppp_status_cb (ppp_pcb *pcb, int err_code, void *ctx);
@@ -236,7 +236,9 @@ void lteppp_disconnect(void) {
236236

237237
void lteppp_send_at_command (lte_task_cmd_data_t *cmd, lte_task_rsp_data_t *rsp) {
238238
xQueueSend(xCmdQueue, (void *)cmd, (TickType_t)portMAX_DELAY);
239-
xQueueReceive(xRxQueue, rsp, (TickType_t)portMAX_DELAY);
239+
240+
if(!cmd->expect_continuation)
241+
xQueueReceive(xRxQueue, rsp, (TickType_t)portMAX_DELAY);
240242
}
241243

242244
bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem) {
@@ -529,8 +531,10 @@ static void TASK_LTE (void *pvParameters) {
529531
xSemaphoreGive(xLTESem);
530532
state = lteppp_get_state();
531533
if (xQueueReceive(xCmdQueue, lteppp_trx_buffer, 0)) {
532-
lteppp_send_at_cmd_exp(lte_task_cmd->data, lte_task_cmd->timeout, NULL, &(lte_task_rsp->data_remaining), lte_task_cmd->dataLen);
533-
xQueueSend(xRxQueue, (void *)lte_task_rsp, (TickType_t)portMAX_DELAY);
534+
bool expect_continuation = lte_task_cmd->expect_continuation;
535+
lteppp_send_at_cmd_exp(lte_task_cmd->data, lte_task_cmd->timeout, NULL, &(lte_task_rsp->data_remaining), lte_task_cmd->dataLen, lte_task_cmd->expect_continuation);
536+
if(!expect_continuation)
537+
xQueueSend(xRxQueue, (void *)lte_task_rsp, (TickType_t)portMAX_DE 8000 LAY);
534538
}
535539
else if(state == E_LTE_PPP && lte_uart_break_evt)
536540
{
@@ -616,7 +620,7 @@ static void TASK_UART_EVT (void *pvParameters)
616620
}
617621

618622

619-
static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem, size_t len) {
623+
static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem, size_t len, bool expect_continuation) {
620624

621625
if(strstr(cmd, "Pycom_Dummy") != NULL)
622626
{
@@ -657,22 +661,34 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
657661
}
658662
#endif
659663
// flush the rx buffer first
660-
uart_flush(LTE_UART_ID);
664+
if(!expect_continuation || (len >= 2 && cmd[0] == 'A' && cmd[1] == 'T')) // starts with AT
665+
{
666+
uart_flush(LTE_UART_ID);
667+
}
661668
// uart_read_bytes(LTE_UART_ID, (uint8_t *)tmp_buf, sizeof(tmp_buf), 5 / portTICK_RATE_MS);
662669
// then send the command
663670
uart_write_bytes(LTE_UART_ID, cmd, cmd_len);
664-
if (strcmp(cmd, "+++")) {
665-
uart_write_bytes(LTE_UART_ID, "\r", 1);
671+
672+
if(expect_continuation)
673+
{
674+
return true;
666675
}
667-
uart_wait_tx_done(LTE_UART_ID, LTE_TRX_WAIT_MS(cmd_len) / portTICK_RATE_MS);
668-
vTaskDelay(2 / portTICK_RATE_MS);
676+
else {
677+
if (strcmp(cmd, "+++"))
678+
{
679+
uart_write_bytes(LTE_UART_ID, "\r", 1);
680+
}
669681

670-
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);
682+
uart_wait_tx_done(LTE_UART_ID, LTE_TRX_WAIT_MS(cmd_len) / portTICK_RATE_MS);
683+
vTaskDelay(2 / portTICK_RATE_MS);
684+
685+
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);
686+
}
671687
}
672688
}
673689

674690
static bool lteppp_send_at_cmd(const char *cmd, uint32_t timeout) {
675-
return lteppp_send_at_cmd_exp (cmd, timeout, LTE_OK_RSP, NULL, strlen(cmd) );
691+
return lteppp_send_at_cmd_exp (cmd, timeout, LTE_OK_RSP, NULL, strlen(cmd), false);
676692
}
677693

678694
static bool lteppp_check_sim_present(void) {

esp32/lte/lteppp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define LTE_CMD_QUEUE_SIZE_MAX (1)
2020
#define LTE_RSP_QUEUE_SIZE_MAX (1)
2121
#define LTE_AT_CMD_SIZE_MAX (128)
22+
#define LTE_AT_CMD_DATA_SIZE_MAX (LTE_AT_CMD_SIZE_MAX - 4)
2223
#define LTE_AT_RSP_SIZE_MAX (LTE_UART_BUFFER_SIZE)
2324

2425
#define LTE_OK_RSP "OK"
@@ -71,8 +72,9 @@ typedef struct {
7172
#endif
7273
typedef struct {
7374
uint32_t timeout;
74-
char data[LTE_AT_CMD_SIZE_MAX - 4];
75+
char data[LTE_AT_CMD_DATA_SIZE_MAX];
7576
size_t dataLen;
77+
bool expect_continuation;
7678
} lte_task_cmd_data_t;
7779
#pragma pack(1)
7880
typedef struct {

esp32/mods/modlte.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ extern TaskHandle_t xLTETaskHndl;
136136
/******************************************************************************
137137
DECLARE PRIVATE FUNCTIONS
138138
******************************************************************************/
139+
static bool lte_push_at_command_ext_cont (char *cmd_str, uint32_t timeout, const char *expected_rsp, size_t len, bool continuation);
139140
static bool lte_push_at_command_ext (char *cmd_str, uint32_t timeout, const char *expected_rsp, size_t len);
140141
static bool lte_push_at_command (char *cmd_str, uint32_t timeout);
141142 F438
static void lte_pause_ppp(void);
@@ -192,14 +193,15 @@ static void lte_callback_handler(void* arg)
192193
}
193194
}
194195

195-
static bool lte_push_at_command_ext(char *cmd_str, uint32_t timeout, const char *expected_rsp, size_t len) {
196-
lte_task_cmd_data_t cmd = { .timeout = timeout, .dataLen = len};
196+
static bool lte_push_at_command_ext_cont (char *cmd_str, uint32_t timeout, const char *expected_rsp, size_t len, bool continuation)
197+
{
198+
lte_task_cmd_data_t cmd = { .timeout = timeout, .dataLen = len, .expect_continuation = continuation};
197199
memcpy(cmd.data, cmd_str, len);
198200
uint32_t start = mp_hal_ticks_ms();
199201
if (lte_debug)
200202
printf("[AT] %u %s\n", start, cmd_str);
201203
lteppp_send_at_command(&cmd, &modlte_rsp);
202-
if ((expected_rsp == NULL) || (strstr(modlte_rsp.data, expected_rsp) != NULL)) {
204+
if (continuation || (expected_rsp == NULL) || (strstr(modlte_rsp.data, expected_rsp) != NULL)) {
203205
if (lte_debug)
204206
printf("[AT-OK] +%u %s\n", mp_hal_ticks_ms()-start, modlte_rsp.data);
205207
return true;
@@ -209,6 +211,10 @@ static bool lte_push_at_command_ext(char *cmd_str, uint32_t timeout, const char
209211
return false;
210212
}
211213

214+
static bool lte_push_at_command_ext(char *cmd_str, uint32_t timeout, const char *expected_rsp, size_t len) {
215+
return lte_push_at_command_ext_cont(cmd_str, timeout, expected_rsp, len, false);
216+
}
217+
212218
static bool lte_push_at_command (char *cmd_str, uint32_t timeout) {
213219
return lte_push_at_command_ext(cmd_str, timeout, LTE_OK_RSP, strlen(cmd_str));
214220
}
@@ -1230,18 +1236,44 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
12301236
lte_check_init();
12311237
lte_check_inppp();
12321238
STATIC const mp_arg_t allowed_args[] = {
1233-
{ MP_QSTR_cmd, MP_ARG_OBJ, {.u_obj = mp_const_none} },
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} }
12341241
};
12351242
// parse args
1236-
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
1243+
uint32_t argLength = MP_ARRAY_SIZE(allowed_args);
1244+
mp_arg_val_t args[argLength];
12371245
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
12381246
if (args[0].u_obj == mp_const_none) {
12391247
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "the command must be specified!"));
12401248
}
1249+
uint32_t timeout = LTE_RX_TIMEOUT_MAX_MS;
12411250
if (MP_OBJ_IS_STR_OR_BYTES(args[0].u_obj))
12421251
{
12431252
size_t len;
1244-
lte_push_at_command_ext((char *)(mp_obj_str_get_data(args[0].u_obj, &len)), LTE_RX_TIMEOUT_MAX_MS, NULL, 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+
}
12451277
}
12461278
else
12471279
{

0 commit comments

Comments
 (0)
0