34
34
35
35
#define LTE_TRX_WAIT_MS (len ) (((len + 1) * 12 * 1000) / MICROPY_LTE_UART_BAUDRATE)
36
36
#define LTE_TASK_PERIOD_MS (2)
37
- #define LTE_AT_CMD_TRIALS (20 )
37
+ #define LTE_AT_CMD_TRIALS (5 )
38
38
39
39
/******************************************************************************
40
40
DEFINE TYPES
@@ -54,6 +54,9 @@ SemaphoreHandle_t xLTE_modem_Conn_Sem;
54
54
DECLARE PRIVATE DATA
55
55
******************************************************************************/
56
56
static char lteppp_trx_buffer [LTE_UART_BUFFER_SIZE + 1 ];
57
+ #ifdef LTE_LOG
58
+ static lte_log_t lteppp_log ;
59
+ #endif
57
60
static char lteppp_queue_buffer [LTE_UART_BUFFER_SIZE ];
58
61
static uart_dev_t * lteppp_uart_reg ;
59
62
static QueueHandle_t xCmdQueue ;
@@ -142,13 +145,22 @@ void lteppp_init(void) {
142
145
xTaskCreatePinnedToCore (TASK_LTE , "LTE" , LTE_TASK_STACK_SIZE / sizeof (StackType_t ), NULL , LTE_TASK_PRIORITY , & xLTETaskHndl , 1 );
143
146
144
147
lteppp_connstatus = LTE_PPP_IDLE ;
148
+ #ifdef LTE_LOG
149
+ lteppp_log .log = heap_caps_malloc (LTE_LOG_BUFF_SIZE , MALLOC_CAP_SPIRAM );
150
+ #endif
145
151
}
146
152
147
153
void lteppp_start (void ) {
148
154
uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_CTS_RTS , 64 );
149
155
vTaskDelay (5 );
150
156
}
151
-
157
+ #ifdef LTE_LOG
158
+ char * lteppp_get_log_buff (void )
159
+ {
160
+ lteppp_log .log [lteppp_log .ptr ] = '\0' ;
161
+ return lteppp_log .log ;
162
+ }
163
+ #endif
152
164
lte_modem_conn_state_t lteppp_modem_state (void )
153
165
{
154
166
lte_modem_conn_state_t state ;
@@ -228,6 +240,20 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
228
240
if (rx_len > 0 ) {
229
241
// NULL terminate the string
230
242
lteppp_trx_buffer [rx_len ] = '\0' ;
243
+ #ifdef LTE_LOG
244
+ if (lteppp_log .ptr < LTE_LOG_BUFF_SIZE - rx_len ) {
245
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[RSP]: " , strlen ("[RSP]: " ));
246
+ lteppp_log .ptr += strlen ("[RSP]: " );
247
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), lteppp_trx_buffer , rx_len - 1 );
248
+ lteppp_log .ptr += rx_len - 1 ;
249
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
250
+ lteppp_log .ptr ++ ;
251
+ }
252
+ else
253
+ {
254
+ lteppp_log .ptr = 0 ;
255
+ }
256
+ #endif
231
257
/* Check for pause after start of response */
232
258
if (strcmp (lteppp_trx_buffer , "\r\n" ) == 0 )
233
259
{
@@ -334,20 +360,64 @@ static void TASK_LTE (void *pvParameters) {
334
360
uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_CTS_RTS , 64 );
335
361
vTaskDelay (500 /portTICK_PERIOD_MS );
336
362
// exit PPP session if applicable
337
- lteppp_send_at_cmd ("+++" , LTE_PPP_BACK_OFF_TIME_MS );
338
- while (!lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS ))
363
+ if (lteppp_send_at_cmd ("+++" , LTE_PPP_BACK_OFF_TIME_MS ))
339
364
{
340
- if (at_trials >= LTE_AT_CMD_TRIALS ) {
341
- uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_DISABLE , 0 );
342
- uart_set_rts (LTE_UART_ID , false);
343
- xSemaphoreTake (xLTESem , portMAX_DELAY );
344
- lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED ;
345
- xSemaphoreGive (xLTESem );
346
- xSemaphoreGive (xLTE_modem_Conn_Sem );
347
- at_trials = 0 ;
348
- goto modem_init ;
365
+ vTaskDelay (LTE_PPP_BACK_OFF_TIME_MS / portTICK_RATE_MS );
366
+ while (!lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS ))
367
+ {
368
+ if (at_trials >= LTE_AT_CMD_TRIALS ) {
369
+ uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_DISABLE , 0 );
370
+ uart_set_rts (LTE_UART_ID , false);
371
+ xSemaphoreTake (xLTESem , portMAX_DELAY );
372
+ lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED ;
373
+ xSemaphoreGive (xLTESem );
374
+ xSemaphoreGive (xLTE_modem_Conn_Sem );
375
+ at_trials = 0 ;
376
+ goto modem_init ;
377
+ }
378
+ at_trials ++ ;
379
+ }
380
+ }
381
+ else
382
+ {
383
+ lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS );
384
+ if (!lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS )) {
385
+ vTaskDelay (LTE_PPP_BACK_OFF_TIME_MS / portTICK_RATE_MS );
386
+ if (lteppp_send_at_cmd ("+++" , LTE_PPP_BACK_OFF_TIME_MS ))
387
+ {
388
+ while (!lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS ))
389
+ {
390
+ if (at_trials >= LTE_AT_CMD_TRIALS ) {
391
+ uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_DISABLE , 0 );
392
+ uart_set_rts (LTE_UART_ID , false);
393
+ xSemaphoreTake (xLTESem , portMAX_DELAY );
394
+ lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED ;
395
+ xSemaphoreGive (xLTESem );
396
+ xSemaphoreGive (xLTE_modem_Conn_Sem );
397
+ at_trials = 0 ;
398
+ goto modem_init ;
399
+ }
400
+ at_trials ++ ;
401
+ }
402
+ }
403
+ else
404
+ {
405
+ while (!lteppp_send_at_cmd ("AT" , LTE_RX_TIMEOUT_MIN_MS ))
406
+ {
407
+ if (at_trials >= LTE_AT_CMD_TRIALS ) {
408
+ uart_set_hw_flow_ctrl (LTE_UART_ID , UART_HW_FLOWCTRL_DISABLE , 0 );
409
+ uart_set_rts (LTE_UART_ID , false);
410
+ xSemaphoreTake (xLTESem , portMAX_DELAY );
411
+ lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED ;
412
+ xSemaphoreGive (xLTESem );
413
+ xSemaphoreGive (xLTE_modem_Conn_Sem );
414
+ at_trials = 0 ;
415
+ goto modem_init ;
416
+ }
417
+ at_trials ++ ;
418
+ }
419
+ }
349
420
}
350
- at_trials ++ ;
351
421
}
352
422
at_trials = 0 ;
353
423
// Disable char echo
@@ -436,13 +506,40 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
436
506
437
507
if (strstr (cmd , "Pycom_Dummy" ) != NULL )
438
508
{
509
+ #ifdef LTE_LOG
510
+ if (lteppp_log .ptr < (LTE_LOG_BUFF_SIZE - strlen ("[CMD]: Dummy" ) + 1 ))
511
+ {
512
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]: Dummy" , strlen ("[CMD]: Dummy" ));
513
+ lteppp_log .ptr += strlen ("[CMD]: Dummy" );
514
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
515
+ lteppp_log .ptr ++ ;
516
+ }
517
+ else
518
+ {
519
+ lteppp_log .ptr = 0 ;
520
+ }
521
+ #endif
439
522
return lteppp_wait_at_rsp (expected_rsp , timeout , false, data_rem );
440
523
}
441
524
else
442
525
{
443
526
uint32_t cmd_len = strlen (cmd );
444
527
// char tmp_buf[128];
445
-
528
+ #ifdef LTE_LOG
529
+ if (lteppp_log .ptr < (LTE_LOG_BUFF_SIZE - strlen ("[CMD]:" ) - cmd_len + 1 ))
530
+ {
531
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), "[CMD]:" , strlen ("[CMD]:" ));
532
+ lteppp_log .ptr += strlen ("[CMD]:" );
533
+ memcpy (& (lteppp_log .log [lteppp_log .ptr ]), cmd , cmd_len );
534
+ lteppp_log .ptr += cmd_len ;
535
+ lteppp_log .log [lteppp_log .ptr ] = '\n' ;
536
+ lteppp_log .ptr ++ ;
537
+ }
538
+ else
539
+ {
540
+ lteppp_log .ptr = 0 ;
541
+ }
542
+ #endif
446
543
// flush the rx buffer first
447
544
uart_flush (LTE_UART_ID );
448
545
// uart_read_bytes(LTE_UART_ID, (uint8_t *)tmp_buf, sizeof(tmp_buf), 5 / portTICK_RATE_MS);
0 commit comments