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

Commit 607078e

Browse files
author
iwahdan88
committed
esp32/lte: add support for modem responses greater than UART buff size
1 parent 6247077 commit 607078e

File tree

3 files changed

+76
-47
lines changed

3 files changed

+76
-47
lines changed

esp32/lte/lteppp.c

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern TaskHandle_t xLTETaskHndl;
5252
/******************************************************************************
5353
DECLARE PRIVATE DATA
5454
******************************************************************************/
55-
static char lteppp_trx_buffer[LTE_UART_BUFFER_SIZE];
55+
static char lteppp_trx_buffer[LTE_UART_BUFFER_SIZE + 1];
5656
static char lteppp_queue_buffer[LTE_UART_BUFFER_SIZE];
5757
static uart_dev_t* lteppp_uart_reg;
5858
static QueueHandle_t xCmdQueue;
@@ -80,7 +80,7 @@ static ltepppconnstatus_t lteppp_connstatus = LTE_PPP_IDLE;
8080
DECLARE PRIVATE FUNCTIONS
8181
******************************************************************************/
8282
static void TASK_LTE (void *pvParameters);
83-
static bool lteppp_send_at_cmd_exp(const char *cmd, uint32_t timeout, const char *expected_rsp);
83+
static bool lteppp_send_at_cmd_exp(const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem);
8484
static bool lteppp_send_at_cmd(const char *cmd, uint32_t timeout);
8585
static bool lteppp_check_sim_present(void);
8686
static void lteppp_status_cb (ppp_pcb *pcb, int err_code, void *ctx);
@@ -154,7 +154,7 @@ void lteppp_init(void) {
154154
lteppp_lte_state = E_LTE_INIT;
155155

156156
xCmdQueue = xQueueCreate(LTE_CMD_QUEUE_SIZE_MAX, sizeof(lte_task_cmd_data_t));
157-
xRxQueue = xQueueCreate(LTE_RSP_QUEUE_SIZE_MAX, LTE_AT_RSP_SIZE_MAX);
157+
xRxQueue = xQueueCreate(LTE_RSP_QUEUE_SIZE_MAX, LTE_AT_RSP_SIZE_MAX + 1);
158158

159159
xLTESem = xSemaphoreCreateMutex();
160160

@@ -221,7 +221,7 @@ void lteppp_send_at_command_delay (lte_task_cmd_data_t *cmd, lte_task_rsp_data_t
221221
xQueueReceive(xRxQueue, rsp, (TickType_t)portMAX_DELAY);
222222
}
223223

224-
bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp) {
224+
bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem) {
225225

226226
uint32_t rx_len = 0;
227227

@@ -240,10 +240,13 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
240240
}
241241
} while (timeout > 0 && 0 == rx_len);
242242

243-
memset(lteppp_trx_buffer, 0, sizeof(lteppp_trx_buffer));
243+
memset(lteppp_trx_buffer, 0, LTE_UART_BUFFER_SIZE);
244+
uint16_t len_count = 0;
244245
while (rx_len > 0) {
245246
// try to read up to the size of the buffer minus null terminator (minus 2 because we store the OK status in the last byte)
246-
rx_len = uart_read_bytes(LTE_UART_ID, (uint8_t *)lteppp_trx_buffer, sizeof(lteppp_trx_buffer) - 2, LTE_TRX_WAIT_MS(sizeof(lteppp_trx_buffer)) / portTICK_RATE_MS);
247+
rx_len = uart_read_bytes(LTE_UART_ID, (uint8_t *)lteppp_trx_buffer, LTE_UART_BUFFER_SIZE - 2, LTE_TRX_WAIT_MS(LTE_UART_BUFFER_SIZE) / portTICK_RATE_MS);
248+
len_count += rx_len;
249+
247250
if (rx_len > 0) {
248251
// NULL terminate the string
249252
lteppp_trx_buffer[rx_len] = '\0';
@@ -255,8 +258,18 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
255258
}
256259
}
257260
uart_get_buffered_data_len(LTE_UART_ID, &rx_len);
261+
if((len_count + rx_len) >= (LTE_UART_BUFFER_SIZE - 2))
262+
{
263+
if (data_rem != NULL) {
264+
*((bool *)data_rem) = true;
265+
return true;
266+
}
267+
}
258268
}
259269
}
270+
if (data_rem != NULL) {
271+
*((bool *)data_rem) = false;
272+
}
260273
return false;
261274
}
262275

@@ -318,6 +331,7 @@ static void TASK_LTE (void *pvParameters) {
318331
lte_task_cmd_data_t *lte_task_cmd = (lte_task_cmd_data_t *)lteppp_trx_buffer;
319332
lte_task_rsp_data_t *lte_task_rsp = (lte_task_rsp_data_t *)lteppp_trx_buffer;
320333

334+
321335
connect_lte_uart();
322336

323337
while (!lteppp_enabled)
@@ -405,7 +419,7 @@ static void TASK_LTE (void *pvParameters) {
405419
for (;;) {
406420
vTaskDelay(LTE_TASK_PERIOD_MS);
407421
if (xQueueReceive(xCmdQueue, lteppp_trx_buffer, 0)) {
408-
lteppp_send_at_cmd_exp(lte_task_cmd->data, lte_task_cmd->timeout, NULL);
422+
lteppp_send_at_cmd_exp(lte_task_cmd->data, lte_task_cmd->timeout, NULL, &(lte_task_rsp->data_remaining));
409423
xQueueSend(xRxQueue, (void *)lte_task_rsp, (TickType_t)portMAX_DELAY);
410424
} else {
411425
lte_state_t state = lteppp_get_state();
@@ -428,8 +442,8 @@ static void TASK_LTE (void *pvParameters) {
428442
uart_get_buffered_data_len(LTE_UART_ID, &rx_len);
429443
if (rx_len > 0) {
430444
// try to read up to the size of the buffer
431-
rx_len = uart_read_bytes(LTE_UART_ID, (uint8_t *)lteppp_trx_buffer, sizeof(lteppp_trx_buffer),
432-
LTE_TRX_WAIT_MS(sizeof(lteppp_trx_buffer)) / portTICK_RATE_MS);
445+
rx_len = uart_read_bytes(LTE_UART_ID, (uint8_t *)lteppp_trx_buffer, LTE_UART_BUFFER_SIZE,
446+
LTE_TRX_WAIT_MS(LTE_UART_BUFFER_SIZE) / portTICK_RATE_MS);
433447
if (rx_len > 0) {
434448
pppos_input_tcpip(lteppp_pcb, (uint8_t *)lteppp_trx_buffer, rx_len);
435449
}
@@ -444,26 +458,33 @@ static void TASK_LTE (void *pvParameters) {
444458
}
445459

446460

447-
static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const char *expected_rsp) {
448-
uint32_t cmd_len = strlen(cmd);
449-
// char tmp_buf[128];
450-
451-
// flush the rx buffer first
452-
uart_flush(LTE_UART_ID);
453-
// uart_read_bytes(LTE_UART_ID, (uint8_t *)tmp_buf, sizeof(tmp_buf), 5 / portTICK_RATE_MS);
454-
// then send the command
455-
uart_write_bytes(LTE_UART_ID, cmd, cmd_len);
456-
if (strcmp(cmd, "+++")) {
457-
uart_write_bytes(LTE_UART_ID, "\r\n", 2);
461+
static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem) {
462+
if(strstr(cmd, "Pycom_Dummy") != NULL)
463+
{
464+
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);
458465
}
459-
uart_wait_tx_done(LTE_UART_ID, LTE_TRX_WAIT_MS(cmd_len) / portTICK_RATE_MS);
460-
vTaskDelay(2 / portTICK_RATE_MS);
466+
else
467+
{
468+
uint32_t cmd_len = strlen(cmd);
469+
// char tmp_buf[128];
470+
471+
// flush the rx buffer first
472+
uart_flush(LTE_UART_ID);
473+
// uart_read_bytes(LTE_UART_ID, (uint8_t *)tmp_buf, sizeof(tmp_buf), 5 / portTICK_RATE_MS);
474+
// then send the command
475+
uart_write_bytes(LTE_UART_ID, cmd, cmd_len);
476+
if (strcmp(cmd, "+++")) {
477+
uart_write_bytes(LTE_UART_ID, "\r\n", 2);
478+
}
479+
uart_wait_tx_done(LTE_UART_ID, LTE_TRX_WAIT_MS(cmd_len) / portTICK_RATE_MS);
480+
vTaskDelay(2 / portTICK_RATE_MS);
461481

462-
return lteppp_wait_at_rsp(expected_rsp, timeout, false);
482+
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);
483+
}
463484
}
464485

465486
static bool lteppp_send_at_cmd(const char *cmd, uint32_t timeout) {
466-
return lteppp_send_at_cmd_exp (cmd, timeout, LTE_OK_RSP);
487+
return lteppp_send_at_cmd_exp (cmd, timeout, LTE_OK_RSP, NULL);
467488
}
468489

469490
static bool lteppp_check_sim_present(void) {

esp32/lte/lteppp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ typedef struct {
5858
uint32_t timeout;
5959
char data[LTE_AT_CMD_SIZE_MAX - 4];
6060
} lte_task_cmd_data_t;
61-
61+
#pragma pack(1)
6262
typedef struct {
6363
char data[LTE_UART_BUFFER_SIZE];
64+
bool data_remaining;
6465
} lte_task_rsp_data_t;
66+
#pragma pack()
6567

6668
/******************************************************************************
6769
DECLARE PUBLIC FUNCTIONS
@@ -91,7 +93,7 @@ extern void lteppp_send_at_command (lte_task_cmd_data_t *cmd, lte_task_rsp_data_
9193

9294
extern void lteppp_send_at_command_delay (lte_task_cmd_data_t *cmd, lte_task_rsp_data_t *rsp, TickType_t delay);
9395

94-
extern bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp);
96+
extern bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem);
9597

9698
extern bool lteppp_task_ready(void);
9799

esp32/mods/modlte.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
394394
if (!strstr(modlte_rsp.data, carrier)) {
395395
sprintf(at_cmd, "AT+SQNCTM=\"%s\"", carrier);
396396
lte_push_at_command(at_cmd, LTE_RX_TIMEOUT_MAX_MS);
397-
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true);
397+
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
398398
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
399-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
400-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
399+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
400+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
401401
}
402402
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
403403
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
@@ -496,10 +496,10 @@ STATIC mp_obj_t lte_deinit(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
496496
if (lte_check_sim_present()) {
497497
if (args[1].u_bool) {
498498
if (lte_push_at_command("AT+CFUN=4,1", LTE_RX_TIMEOUT_MAX_MS)) {
499-
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true);
499+
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
500500
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
501-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
502-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
501+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
502+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
503503
}
504504
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
505505
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
@@ -516,10 +516,10 @@ STATIC mp_obj_t lte_deinit(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
516516
} else {
517517
if (args[1].u_bool) {
518518
if (lte_push_at_command("AT+CFUN=0,1", LTE_RX_TIMEOUT_MAX_MS)) {
519-
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true);
519+
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
520520
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
521-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
522-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
521+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
522+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
523523
}
524524
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
525525
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
@@ -676,10 +676,10 @@ mp_obj_t lte_detach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
676676
if (lte_check_sim_present()) {
677677
if (args[0].u_bool) {
678678
if (lte_push_at_command("AT+CFUN=4,1", LTE_RX_TIMEOUT_MAX_MS)) {
679-
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true);
679+
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
680680
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
681-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
682-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
681+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
682+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
683683
}
684684
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
685685
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
@@ -696,10 +696,10 @@ mp_obj_t lte_detach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
696696
} else {
697697
if (args[0].u_bool) {
698698
if (lte_push_at_command("AT+CFUN=0,1", LTE_RX_TIMEOUT_MAX_MS)) {
699-
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true);
699+
lteppp_wait_at_rsp("+S", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
700700
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
701-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
702-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
701+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
702+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
703703
}
704704
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
705705
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
@@ -922,8 +922,14 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
922922
const char *cmd = mp_obj_str_get_str(args[0].u_obj);
923923
lte_push_at_command_delay((char *)cmd, LTE_RX_TIMEOUT_MAX_MS, args[1].u_int);
924924
vstr_t vstr;
925-
vstr_init_len(&vstr, strlen(modlte_rsp.data));
926-
strcpy(vstr.buf, modlte_rsp.data);
925+
vstr_init(&vstr, 0);
926+
vstr_add_str(&vstr, modlte_rsp.data);
927+
while(modlte_rsp.data_remaining)
928+
{
929+
lte_push_at_command_delay("Pycom_Dummy", LTE_RX_TIMEOUT_MAX_MS, args[1].u_int);
930+
vstr_add_str(&vstr, modlte_rsp.data);
931+
}
932+
927933
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
928934
}
929935
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(lte_send_at_cmd_obj, 1, lte_send_at_cmd);
@@ -1015,8 +1021,8 @@ STATIC mp_obj_t lte_reset(mp_obj_t self_in) {
10151021
lte_push_at_command("AT^RESET", LTE_RX_TIMEOUT_MAX_MS);
10161022
lteppp_set_state(E_LTE_IDLE);
10171023
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
1018-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
1019-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
1024+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
1025+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
10201026
}
10211027
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
10221028
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
@@ -1036,8 +1042,8 @@ STATIC mp_obj_t lte_factory_reset(mp_obj_t self_in) {
10361042
lte_push_at_command("AT^RESET", LTE_RX_TIMEOUT_MAX_MS);
10371043
lteppp_set_state(E_LTE_IDLE);
10381044
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
1039-
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true)) {
1040-
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true);
1045+
if (!lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL)) {
1046+
lteppp_wait_at_rsp("+SYSSTART", LTE_RX_TIMEOUT_MAX_MS, true, NULL);
10411047
}
10421048
lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS);
10431049
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy