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

Commit 91d9bf4

Browse files
author
iwahdan88
committed
[PYFW-331] LTE refactoring
1 parent 7bd04db commit 91d9bf4

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

esp32/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ endif #ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
104104

105105
# Enable or Disable LTE_LOG_BUFF
106106
ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
107-
ifeq ($(LTE_LOG_BUFF),1)
108-
CFLAGS += -DLTE_LOG
107+
ifeq ($(LTE_DEBUG_BUFF),1)
108+
CFLAGS += -DLTE_DEBUG_BUFF
109109
endif #ifeq ($(LTE_LOG_BUFF),1)
110110
endif #ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
111111

esp32/lte/lteppp.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SemaphoreHandle_t xLTE_modem_Conn_Sem;
5454
DECLARE PRIVATE DATA
5555
******************************************************************************/
5656
static char lteppp_trx_buffer[LTE_UART_BUFFER_SIZE + 1];
57-
#ifdef LTE_LOG
57+
#ifdef LTE_DEBUG_BUFF
5858
static lte_log_t lteppp_log;
5959
#endif
6060
static char lteppp_queue_buffer[LTE_UART_BUFFER_SIZE];
@@ -145,7 +145,7 @@ void lteppp_init(void) {
145145
xTaskCreatePinnedToCore(TASK_LTE, "LTE", LTE_TASK_STACK_SIZE / sizeof(StackType_t), NULL, LTE_TASK_PRIORITY, &xLTETaskHndl, 1);
146146

147147
lteppp_connstatus = LTE_PPP_IDLE;
148-
#ifdef LTE_LOG
148+
#ifdef LTE_DEBUG_BUFF
149149
lteppp_log.log = heap_caps_malloc(LTE_LOG_BUFF_SIZE, MALLOC_CAP_SPIRAM);
150150
#endif
151151
}
@@ -154,10 +154,22 @@ void lteppp_start (void) {
154154
uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64);
155155
vTaskDelay(5);
156156
}
157-
#ifdef LTE_LOG
157+
#ifdef LTE_DEBUG_BUFF
158158
char* lteppp_get_log_buff(void)
159159
{
160-
lteppp_log.log[lteppp_log.ptr] = '\0';
160+
if(lteppp_log.truncated)
161+
{
162+
if(lteppp_log.ptr < LTE_LOG_BUFF_SIZE - strlen("\n********BUFFER WRAPAROUND********\n") - 1)
163+
{
164+
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "\n********BUFFER WRAPAROUND********\n", strlen("\n********BUFFER WRAPAROUND********\n"));
165+
lteppp_log.ptr += strlen("\n********BUFFER WRAPAROUND********\n");
166+
}
167+
lteppp_log.log[LTE_LOG_BUFF_SIZE - 1] = '\0';
168+
}
169+
else
170+
{
171+
lteppp_log.log[lteppp_log.ptr] = '\0';
172+
}
161173
return lteppp_log.log;
162174
}
163175
#endif
@@ -240,8 +252,8 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
240252
if (rx_len > 0) {
241253
// NULL terminate the string
242254
lteppp_trx_buffer[rx_len] = '\0';
243-
#ifdef LTE_LOG
244-
if (lteppp_log.ptr < LTE_LOG_BUFF_SIZE - rx_len) {
255+
#ifdef LTE_DEBUG_BUFF
256+
if (lteppp_log.ptr < LTE_LOG_BUFF_SIZE - rx_len - 1) {
245257
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[RSP]: ", strlen("[RSP]: "));
246258
lteppp_log.ptr += strlen("[RSP]: ");
247259
memcpy(&(lteppp_log.log[lteppp_log.ptr]), lteppp_trx_buffer, rx_len-1);
@@ -252,6 +264,7 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
252264
else
253265
{
254266
lteppp_log.ptr = 0;
267+
lteppp_log.truncated = true;
255268
}
256269
#endif
257270
/* Check for pause after start of response */
@@ -263,7 +276,7 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
263276
{
264277
pause = false;
265278
}
266-
if (expected_rsp != NULL) {
279+
if ((expected_rsp != NULL) && !pause) {
267280
if (strstr(lteppp_trx_buffer, expected_rsp) != NULL) {
268281
//printf("RESP: %s\n", lteppp_trx_buffer);
269282
return true;
@@ -506,8 +519,8 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
506519

507520
if(strstr(cmd, "Pycom_Dummy") != NULL)
508521
{
509-
#ifdef LTE_LOG
510-
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]: Dummy") + 1))
522+
#ifdef LTE_DEBUG_BUFF
523+
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]: Dummy") - 1))
511524
{
512525
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[CMD]: Dummy", strlen("[CMD]: Dummy"));
513526
lteppp_log.ptr += strlen("[CMD]: Dummy");
@@ -517,6 +530,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
517530
else
518531
{
519532
lteppp_log.ptr = 0;
533+
lteppp_log.truncated = true;
520534
}
521535
#endif
522536
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);
@@ -525,8 +539,8 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
525539
{
526540
uint32_t cmd_len = strlen(cmd);
527541
// char tmp_buf[128];
528-
#ifdef LTE_LOG
529-
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]:") - cmd_len + 1))
542+
#ifdef LTE_DEBUG_BUFF
543+
if (lteppp_log.ptr < (LTE_LOG_BUFF_SIZE - strlen("[CMD]:") - cmd_len - 1))
530544
{
531545
memcpy(&(lteppp_log.log[lteppp_log.ptr]), "[CMD]:", strlen("[CMD]:"));
532546
lteppp_log.ptr += strlen("[CMD]:");
@@ -538,6 +552,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
538552
else
539553
{
540554
lteppp_log.ptr = 0;
555+
lteppp_log.truncated = true;
541556
}
542557
#endif
543558
// flush the rx buffer first

esp32/lte/lteppp.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define LTE_MUTEX_TIMEOUT (5050 / portTICK_RATE_MS)
3131
#define LTE_TASK_STACK_SIZE (3072)
3232
#define LTE_TASK_PRIORITY (6)
33-
#ifdef LTE_LOG
33+
#ifdef LTE_DEBUG_BUFF
3434
#define LTE_LOG_BUFF_SIZE (20 * 1024)
3535
#endif
3636

@@ -62,10 +62,11 @@ typedef enum {
6262
E_LTE_MODEM_CONNECTING,
6363
E_LTE_MODEM_DISCONNECTED
6464
} lte_modem_conn_state_t;
65-
#ifdef LTE_LOG
65+
#ifdef LTE_DEBUG_BUFF
6666
typedef struct {
6767
char* log;
6868
uint16_t ptr;
69+
bool truncated;
6970
} lte_log_t;
7071
#endif
7172
typedef struct {
@@ -123,7 +124,7 @@ extern bool ltepp_is_ppp_conn_up(void);
123124
extern void lteppp_suspend(void);
124125

125126
extern void lteppp_resume(void);
126-
#ifdef LTE_LOG
127+
#ifdef LTE_DEBUG_BUFF
127128
extern char* lteppp_get_log_buff(void);
128129
#endif
129130

esp32/mods/modlte.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,14 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
390390
return mp_const_none;
391391
}
392392
modem_state = lteppp_modem_state();
393-
394393
switch(modem_state)
395394
{
396395
case E_LTE_MODEM_DISCONNECTED:
397396
// Notify the LTE thread to start
398397
modlte_start_modem();
398+
MP_THREAD_GIL_EXIT();
399399
xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY);
400+
MP_THREAD_GIL_ENTER();
400401
if (E_LTE_MODEM_DISCONNECTED == lteppp_modem_state()) {
401402
xSemaphoreGive(xLTE_modem_Conn_Sem);
402403
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem!"));
@@ -619,6 +620,7 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
619620
lteppp_send_at_command(&cmd, &modlte_rsp);
620621
/* Dummy command for command response > Uart buff size */
621622
memcpy(cmd.data, "Pycom_Dummy", strlen("Pycom_Dummy"));
623+
MP_THREAD_GIL_EXIT();
622624
while(modlte_rsp.data_remaining)
623625
{
624626
if (!is_hw_new_band_support) {
@@ -629,6 +631,7 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
629631
}
630632
lteppp_send_at_command(&cmd, &modlte_rsp);
631633
}
634+
MP_THREAD_GIL_ENTER();
632635
int version = lte_get_modem_version();
633636

634637
if(version > 0 && version > SQNS_SW_FULL_BAND_SUPPORT)
@@ -970,12 +973,11 @@ STATIC mp_obj_t lte_resume(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
970973
lteppp_set_state(E_LTE_ATTACHED);
971974
lte_check_attached(lte_legacyattach_flag);
972975
return lte_connect(n_args, pos_args, kw_args);
973-
//nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
974976
}
975977
} else if (lteppp_get_state() == E_LTE_PPP) {
976978
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "modem already connected"));
977979
} else {
978-
//nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "modem not attached"));
980+
//Do Nothing
979981
}
980982
return mp_const_none;
981983
}
@@ -1044,12 +1046,13 @@ STATIC mp_obj_t lte_send_at_cmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
10441046
vstr_t vstr;
10451047
vstr_init(&vstr, 0);
10461048
vstr_add_str(&vstr, modlte_rsp.data);
1049+
MP_THREAD_GIL_EXIT();
10471050
while(modlte_rsp.data_remaining)
10481051
{
10491052
lte_push_at_command_delay("Pycom_Dummy", LTE_RX_TIMEOUT_MAX_MS, args[1].u_int);
10501053
vstr_add_str(&vstr, modlte_rsp.data);
10511054
}
1052-
1055+
MP_THREAD_GIL_ENTER();
10531056
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
10541057
}
10551058
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(lte_send_at_cmd_obj, 1, lte_send_at_cmd);
@@ -1257,15 +1260,15 @@ STATIC mp_obj_t lte_upgrade_mode(void) {
12571260
return mp_const_none;
12581261
}
12591262
STATIC MP_DEFINE_CONST_FUN_OBJ_0(lte_upgrade_mode_obj, lte_upgrade_mode);
1260-
#ifdef LTE_LOG
1261-
STATIC mp_obj_t lte_log(void) {
1263+
#ifdef LTE_DEBUG_BUFF
1264+
STATIC mp_obj_t lte_debug_buff(void) {
12621265
vstr_t vstr;
12631266
char* str_log = lteppp_get_log_buff();
12641267
vstr_init_len(&vstr, strlen(str_log));
12651268
strcpy(vstr.buf, str_log);
12661269
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
12671270
}
1268-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(lte_log_obj, lte_log);
1271+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(lte_debug_buff_obj, lte_debug_buff);
12691272
#endif
12701273
STATIC mp_obj_t lte_reconnect_uart (void) {
12711274
connect_lte_uart();
@@ -1296,8 +1299,8 @@ STATIC const mp_map_elem_t lte_locals_dict_table[] = {
12961299
{ MP_OBJ_NEW_QSTR(MP_QSTR_modem_upgrade_mode), (mp_obj_t)&lte_upgrade_mode_obj },
12971300
{ MP_OBJ_NEW_QSTR(MP_QSTR_reconnect_uart), (mp_obj_t)&lte_reconnect_uart_obj },
12981301
{ MP_OBJ_NEW_QSTR(MP_QSTR_ue_coverage), (mp_obj_t)&lte_ue_coverage_obj },
1299-
#ifdef LTE_LOG
1300-
{ MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&lte_log_obj },
1302+
#ifdef LTE_DEBUG_BUFF
1303+
{ MP_OBJ_NEW_QSTR(MP_QSTR_debug_buff), (mp_obj_t)&lte_debug_buff_obj },
13011304
#endif
13021305

13031306
// class constants

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