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

Commit 8f74728

Browse files
author
iwahdan88
committed
[PYFW-331] Fix issue in modem version detection
1 parent 91d9bf4 commit 8f74728

File tree

1 file changed

+56
-27
lines changed

1 file changed

+56
-27
lines changed

esp32/lte/lteppp.c

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,30 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
241241

242242
memset(lteppp_trx_buffer, 0, LTE_UART_BUFFER_SIZE);
243243
uint16_t len_count = 0;
244-
/* reset timeout to 1000ms to account for pause in response */
245-
timeout_cnt = 1000;
246-
bool pause = false;
247-
while (rx_len > 0 || (pause && timeout_cnt > 0)) {
248-
// 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)
249-
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);
244+
245+
while (rx_len > 0) {
246+
if (len_count == 0) {
247+
// 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)
248+
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);
249+
}
250+
else
251+
{
252+
// 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)
253+
rx_len = uart_read_bytes(LTE_UART_ID, (uint8_t *)(&(lteppp_trx_buffer[len_count])), LTE_UART_BUFFER_SIZE - len_count - 2, LTE_TRX_WAIT_MS(LTE_UART_BUFFER_SIZE) / portTICK_RATE_MS);
254+
}
250255
len_count += rx_len;
251256

252257
if (rx_len > 0) {
253258
// NULL terminate the string
254-
lteppp_trx_buffer[rx_len] = '\0';
259+
lteppp_trx_buffer[len_count] = '\0';
255260
#ifdef LTE_DEBUG_BUFF
256-
if (lteppp_log.ptr < LTE_LOG_BUFF_SIZE - rx_len - 1) {
257-
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[RSP]: ", strlen("[RSP]: "));
258-
lteppp_log.ptr += strlen("[RSP]: ");
259-
memcpy(&(lteppp_log.log[lteppp_log.ptr]), lteppp_trx_buffer, rx_len-1);
260-
lteppp_log.ptr += rx_len-1;
261+
if (lteppp_log.ptr < LTE_LOG_BUFF_SIZE - rx_len) {
262+
if (len_count == rx_len) {
263+
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[RSP]: ", strlen("[RSP]: "));
264+
lteppp_log.ptr += strlen("[RSP]: ");
265+
}
266+
memcpy(&(lteppp_log.log[lteppp_log.ptr]), lteppp_trx_buffer, rx_len);
267+
lteppp_log.ptr += rx_len;
261268
lteppp_log.log[lteppp_log.ptr] = '\n';
262269
lteppp_log.ptr++;
263270
}
@@ -267,35 +274,57 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
267274
lteppp_log.truncated = true;
268275
}
269276
#endif
270-
/* Check for pause after start of response */
271-
if(strcmp(lteppp_trx_buffer, "\r\n") == 0)
272-
{
273-
pause = true;
274-
}
275-
else
276-
{
277-
pause = false;
278-
}
279-
if ((expected_rsp != NULL) && !pause) {
277+
278+
if (expected_rsp != NULL) {
280279
if (strstr(lteppp_trx_buffer, expected_rsp) != NULL) {
281280
//printf("RESP: %s\n", lteppp_trx_buffer);
282281
return true;
283282
}
284283
}
284+
285285
uart_get_buffered_data_len(LTE_UART_ID, &rx_len);
286+
286287
if((len_count + rx_len) >= (LTE_UART_BUFFER_SIZE - 2))
287288
{
288289
if (data_rem != NULL) {
289290
*((bool *)data_rem) = true;
290291
return true;
291292
}
292293
}
294+
else if(rx_len == 0)
295+
{
296+
uint8_t timeout_buff = 10;
297+
while((!strstr(lteppp_trx_buffer,"\r\nOK\r\n")) && (!strstr(lteppp_trx_buffer,"\r\nERROR\r\n")) && (!strstr(lteppp_trx_buffer,"+SYSSTART")) && (!strstr(lteppp_trx_buffer,"\r\nCONNECT\r\n")) &&
298+
rx_len == 0 && timeout_buff > 0)
299+
{
300+
#ifdef LTE_DEBUG_BUFF
301+
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[Waiting]:\n", strlen("[Waiting]:\n"));
302+
lteppp_log.ptr += strlen("[Waiting]:\n");
303+
#endif
304+
305+
uart_get_buffered_data_len(LTE_UART_ID, &rx_len);
306+
307+
if (from_mp) {
308+
mp_hal_delay_ms(100);
309+
}
310+
else {
311+
vTaskDelay(100 / portTICK_RATE_MS);
312+
}
313+
timeout_buff--;
314+
}
315+
//check size again
316+
if((len_count + rx_len) >= (LTE_UART_BUFFER_SIZE - 2))
317+
{
318+
if (data_rem != NULL) {
319+
*((bool *)data_rem) = true;
320+
return true;
321+
}
322+
}
323+
}
293324
}
294325
else
295326
{
296-
if (timeout_cnt > 0 && pause) {
297-
timeout_cnt--;
298-
}
327+
// Do Nothing
299328
}
300329
}
301330
if (data_rem != NULL) {
@@ -520,7 +549,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
520549
if(strstr(cmd, "Pycom_Dummy") != NULL)
521550
{
522551
#ifdef LTE_DEBUG_BUFF
523-
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]: Dummy") - 1))
552+
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]: Dummy") + 1))
524553
{
525554
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[CMD]: Dummy", strlen("[CMD]: Dummy"));
526555
lteppp_log.ptr += strlen("[CMD]: Dummy");
@@ -540,7 +569,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
540569
uint32_t cmd_len = strlen(cmd);
541570
// char tmp_buf[128];
542571
#ifdef LTE_DEBUG_BUFF
543-
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]:") - cmd_len - 1))
572+
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]:") - cmd_len + 1))
544573
{
545574
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[CMD]:", strlen("[CMD]:"));
546575
lteppp_log.ptr += strlen("[CMD]:");

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