@@ -53,6 +53,9 @@ extern TaskHandle_t xLTETaskHndl;
53
53
DECLARE PRIVATE DATA
54
54
******************************************************************************/
55
55
static char lteppp_trx_buffer [LTE_UART_BUFFER_SIZE + 1 ];
56
+ #ifdef LTE_DEBUG_BUFF
57
+ static lte_log_t lteppp_log ;
58
+ #endif
56
59
static char lteppp_queue_buffer [LTE_UART_BUFFER_SIZE ];
57
60
static uart_dev_t * lteppp_uart_reg ;
58
61
static QueueHandle_t xCmdQueue ;
@@ -166,13 +169,34 @@ void lteppp_init(void) {
166
169
xTaskCreatePinnedToCore (TASK_LTE , "LTE" , LTE_TASK_STACK_SIZE / sizeof (StackType_t ), NULL , LTE_TASK_PRIORITY , & xLTETaskHndl , 1 );
167
170
168
171
lteppp_connstatus = LTE_PPP_IDLE ;
172
+ #ifdef LTE_DEBUG_BUFF
173
+ lteppp_log .log = heap_caps_malloc (LTE_LOG_BUFF_SIZE , MALLOC_CAP_SPIRAM );
174
+ #endif
169
175
}
170
176
171
177
void lteppp_start (void ) {
172
178
uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_CTS_RTS , 64 );
173
179
vTaskDelay (5 );
174
180
}
175
-
181
+ #ifdef LTE_DEBUG_BUFF
182
+ char * lteppp_get_log_buff (void )
183
+ {
184
+ if (lteppp_log .truncated )
185
+ {
186
+ if (lteppp_log .ptr < LTE_LOG_BUFF_SIZE - strlen ("\n********BUFFER WRAPAROUND********\n" ) - 1 )
187
+ {
188
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "\n********BUFFER WRAPAROUND********\n" , strlen ("\n********BUFFER WRAPAROUND********\n" ));
189
+ lteppp_log .ptr += strlen ("\n********BUFFER WRAPAROUND********\n" );
190
+ }
191
+ lteppp_log .log [LTE_LOG_BUFF_SIZE - 1 ] = '\0' ;
192
+ }
193
+ else
194
+ {
195
+ lteppp_log .log [lteppp_log .ptr ] = '\0' ;
196
+ }
197
+ return lteppp_log .log ;
198
+ }
199
+ #endif
176
200
void lteppp_connect_modem (void ) {
177
201
178
202
lteppp_enabled = true;
@@ -242,46 +266,90 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
242
266
243
267
memset (lteppp_trx_buffer , 0 , LTE_UART_BUFFER_SIZE );
244
268
uint16_t len_count = 0 ;
245
- /* reset timeout to 1000ms to account for pause in response */
246
- timeout_cnt = 1000 ;
247
- bool pause = false;
248
- while (rx_len > 0 || (pause && timeout_cnt > 0 )) {
249
- // 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)
250
- 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 );
269
+
270
+ while (rx_len > 0 ) {
271
+ if (len_count == 0 ) {
272
+ // 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)
273
+ 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 );
274
+ }
275
+ else
276
+ {
277
+ // 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)
278
+ 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 );
279
+ }
251
280
len_count += rx_len ;
252
281
253
282
if (rx_len > 0 ) {
254
283
// NULL terminate the string
255
- lteppp_trx_buffer [rx_len ] = '\0' ;
256
- /* Check for pause after start of response */
257
- if (strcmp (lteppp_trx_buffer , "\r\n" ) == 0 )
258
- {
259
- pause = true;
284
+ lteppp_trx_buffer [len_count ] = '\0' ;
285
+ #ifdef LTE_DEBUG_BUFF
286
+ if (lteppp_log .ptr < LTE_LOG_BUFF_SIZE - rx_len ) {
287
+ if (len_count == rx_len ) {
288
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[RSP]: " , strlen ("[RSP]: " ));
289
+ lteppp_log .ptr += strlen ("[RSP]: " );
290
+ }
291
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), lteppp_trx_buffer , rx_len );
292
+ lteppp_log .ptr += rx_len ;
293
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
294
+ lteppp_log .ptr ++ ;
260
295
}
261
296
else
262
297
{
263
- pause = false;
298
+ lteppp_log .ptr = 0 ;
299
+ lteppp_log .truncated = true;
264
300
}
301
+ #endif
302
+
265
303
if (expected_rsp != NULL ) {
266
304
if (strstr (lteppp_trx_buffer , expected_rsp ) != NULL ) {
267
305
//printf("RESP: %s\n", lteppp_trx_buffer);
268
306
return true;
269
307
}
270
308
}
309
+
271
310
uart_get_buffered_data_len (LTE_UART_ID , & rx_len );
311
+
272
312
if ((len_count + rx_len ) >= (LTE_UART_BUFFER_SIZE - 2 ))
273
313
{
274
314
if (data_rem != NULL ) {
275
315
* ((bool * )data_rem ) = true;
276
316
return true;
277
317
}
278
318
}
319
+ else if (rx_len == 0 )
320
+ {
321
+ uint8_t timeout_buff = 10 ;
322
+ 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" )) &&
323
+ rx_len == 0 && timeout_buff > 0 )
324
+ {
325
+ #ifdef LTE_DEBUG_BUFF
326
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[Waiting]:\n" , strlen ("[Waiting]:\n" ));
327
+ lteppp_log .ptr += strlen ("[Waiting]:\n" );
328
+ #endif
329
+
330
+ uart_get_buffered_data_len (LTE_UART_ID , & rx_len );
331
+
332
+ if (from_mp ) {
333
+ mp_hal_delay_ms (100 );
334
+ }
335
+ else {
336
+ vTaskDelay (100 / portTICK_RATE_MS );
337
+ }
338
+ timeout_buff -- ;
339
+ }
340
+ //check size again
341
+ if ((len_count + rx_len ) >= (LTE_UART_BUFFER_SIZE - 2 ))
342
+ {
343
+ if (data_rem != NULL ) {
344
+ * ((bool * )data_rem ) = true;
345
+ return true;
346
+ }
347
+ }
348
+ }
279
349
}
280
350
else
281
351
{
282
- if (timeout_cnt > 0 && pause ) {
283
- timeout_cnt -- ;
284
- }
352
+ // Do Nothing
285
353
}
286
354
}
287
355
if (data_rem != NULL ) {
@@ -479,13 +547,42 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
479
547
480
548
if (strstr (cmd , "Pycom_Dummy" ) != NULL )
481
549
{
550
+ #ifdef LTE_DEBUG_BUFF
551
+ if (lteppp_log .ptr < (LTE_LOG_BUFF_SIZE - strlen ("[CMD]: Dummy" ) + 1 ))
552
+ {
553
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]: Dummy" , strlen ("[CMD]: Dummy" ));
554
+ lteppp_log .ptr += strlen ("[CMD]: Dummy" );
555
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
556
+ lteppp_log .ptr ++ ;
557
+ }
558
+ else
559
+ {
560
+ lteppp_log .ptr = 0 ;
561
+ lteppp_log .truncated = true;
562
+ }
563
+ #endif
482
564
return lteppp_wait_at_rsp (expected_rsp , timeout , false, data_rem );
483
565
}
484
566
else
485
567
{
486
568
uint32_t cmd_len = strlen (cmd );
487
569
// char tmp_buf[128];
488
-
570
+ #ifdef LTE_DEBUG_BUFF
571
+ if (lteppp_log .ptr < (LTE_LOG_BUFF_SIZE - strlen ("[CMD]:" ) - cmd_len + 1 ))
572
+ {
573
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]:" , strlen ("[CMD]:" ));
574
+ lteppp_log .ptr += strlen ("[CMD]:" );
575
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), cmd , cmd_len );
576
+ lteppp_log .ptr += cmd_len ;
577
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
578
+ lteppp_log .ptr ++ ;
579
+ }
580
+ else
581
+ {
582
+ lteppp_log .ptr = 0 ;
583
+ lteppp_log .truncated = true;
584
+ }
585
+ #endif
489
586
// flush the rx buffer first
490
587
uart_flush (LTE_UART_ID );
491
588
// uart_read_bytes(LTE_UART_ID, (uint8_t *)tmp_buf, sizeof(tmp_buf), 5 / portTICK_RATE_MS);
0 commit comments