@@ -241,23 +241,30 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
241
241
242
242
memset (lteppp_trx_buffer , 0 , LTE_UART_BUFFER_SIZE );
243
243
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
+ }
250
255
len_count += rx_len ;
251
256
252
257
if (rx_len > 0 ) {
253
258
// NULL terminate the string
254
- lteppp_trx_buffer [rx_len ] = '\0' ;
259
+ lteppp_trx_buffer [len_count ] = '\0' ;
255
260
#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 ;
261
268
lteppp_log .log [lteppp_log .ptr ] = '\n' ;
262
269
lteppp_log .ptr ++ ;
263
270
}
@@ -267,35 +274,57 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
267
274
lteppp_log .truncated = true;
268
275
}
269
276
#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 ) {
280
279
if (strstr (lteppp_trx_buffer , expected_rsp ) != NULL ) {
281
280
//printf("RESP: %s\n", lteppp_trx_buffer);
282
281
return true;
283
282
}
284
283
}
284
+
285
285
uart_get_buffered_data_len (LTE_UART_ID , & rx_len );
286
+
286
287
if ((len_count + rx_len ) >= (LTE_UART_BUFFER_SIZE - 2 ))
287
288
{
288
289
if (data_rem != NULL ) {
289
290
* ((bool * )data_rem ) = true;
290
291
return true;
291
292
}
292
293
}
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
+ }
293
324
}
294
325
else
295
326
{
296
- if (timeout_cnt > 0 && pause ) {
297
- timeout_cnt -- ;
298
- }
327
+ // Do Nothing
299
328
}
300
329
}
301
330
if (data_rem != NULL ) {
@@ -520,7 +549,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
520
549
if (strstr (cmd , "Pycom_Dummy" ) != NULL )
521
550
{
522
551
#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 ))
524
553
{
525
554
memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]: Dummy" , strlen ("[CMD]: Dummy" ));
526
555
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
540
569
uint32_t cmd_len = strlen (cmd );
541
570
// char tmp_buf[128];
542
571
#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 ))
544
573
{
545
574
memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]:" , strlen ("[CMD]:" ));
546
575
lteppp_log .ptr += strlen ("[CMD]:" );
0 commit comments