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

Commit 04af705

Browse files
author
iwahdan88
committed
esp32/modlte: updated modlte to check band support on attach based on modem HW/SW
1 parent 47fef73 commit 04af705

File tree

2 files changed

+124
-24
lines changed

2 files changed

+124
-24
lines changed

esp32/lte/lteppp.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void lteppp_send_at_command_delay (lte_task_cmd_data_t *cmd, lte_task_rsp_data_t
224224
bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem) {
225225

226226
uint32_t rx_len = 0;
227-
227+
uint32_t timeout_cnt = timeout;
228228
// wait until characters start arriving
229229
do {
230230
// being called from the MicroPython interpreter
@@ -235,22 +235,33 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
235235
vTaskDelay(1 / portTICK_RATE_MS);
236236
}
237237
uart_get_buffered_data_len(LTE_UART_ID, &rx_len);
238-
if (timeout > 0) {
239-
timeout--;
238+
if (timeout_cnt > 0) {
239+
timeout_cnt--;
240240
}
241-
} while (timeout > 0 && 0 == rx_len);
241+
} while (timeout_cnt > 0 && 0 == rx_len);
242242

243243
memset(lteppp_trx_buffer, 0, LTE_UART_BUFFER_SIZE);
244244
uint16_t len_count = 0;
245-
while (rx_len > 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)) {
246249
// 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)
247250
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);
248251
len_count += rx_len;
249252

250253
if (rx_len > 0) {
251254
// NULL terminate the string
252255
lteppp_trx_buffer[rx_len] = '\0';
253-
//printf("%s\n", lteppp_trx_buffer);
256+
/* Check for pause after start of response */
257+
if(strcmp(lteppp_trx_buffer, "\r\n") == 0)
258+
{
259+
pause = true;
260+
}
261+
else
262+
{
263+
pause = false;
264+
}
254265
if (expected_rsp != NULL) {
255266
if (strstr(lteppp_trx_buffer, expected_rsp) != NULL) {
256267
//printf("RESP: %s\n", lteppp_trx_buffer);
@@ -266,6 +277,12 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
266277
}
267278
}
268279
}
280+
else
281+
{
282+
if (timeout_cnt > 0 && pause) {
283+
timeout_cnt--;
284+
}
285+
}
269286
}
270287
if (data_rem != NULL) {
271288
*((bool *)data_rem) = false;
@@ -459,6 +476,7 @@ static void TASK_LTE (void *pvParameters) {
459476

460477

461478
static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const char *expected_rsp, void* data_rem) {
479+
462480
if(strstr(cmd, "Pycom_Dummy") != NULL)
463481
{
464482
return lteppp_wait_at_rsp(expected_rsp, timeout, false, data_rem);

esp32/mods/modlte.c

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080

8181
#define DEFAULT_PROTO_TYPE (const char*)"IP"
8282
#define DEFAULT_APN (const char*)""
83+
84+
#define SQNS_SW_FULL_BAND_SUPPORT 41000
85+
#define SQNS_SW_5_8_BAND_SUPPORT 39000
8386
/******************************************************************************
8487
DECLARE PRIVATE DATA
8588
******************************************************************************/
@@ -119,6 +122,7 @@ static void lte_pause_ppp(void);
119122
static bool lte_check_attached(bool legacy);
120123
static void lte_check_init(void);
121124
static bool lte_check_sim_present(void);
125+
static int lte_get_modem_version(void);
122126
STATIC mp_obj_t lte_suspend(mp_obj_t self_in);
123127
STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
124128

@@ -281,6 +285,31 @@ static bool lte_check_legacy_version(void) {
281285
return true;
282286
}
283287

288+
static int lte_get_modem_version(void)
289+
{
290+
lte_task_cmd_data_t cmd = { .timeout = LTE_RX_TIMEOUT_MAX_MS };
291+
292+
/* Get modem version */
293+
memcpy(cmd.data, "AT!=\"showver\"", strlen("AT!=\"showver\""));
294+
char * ver = NULL;
295+
296+
lteppp_send_at_command(&cmd, &modlte_rsp);
297+
ver = strstr(modlte_rsp.data, "Software :");
298+
299+
if(ver != NULL )
300+
{
301+
ver = strstr(ver, "[");
302+
char * ver_close = strstr(ver, "]");
303+
int v = 0;
304+
if (ver != NULL && ver_close != NULL && ver_close > ver) {
305+
ver[ver_close - ver] = '\0';
306+
ver++;
307+
v = atoi(ver);
308+
}
309+
return v;
310+
}
311+
return 0;
312+
}
284313

285314
static void lte_check_init(void) {
286315
if (!lte_obj.init) {
@@ -554,8 +583,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(lte_deinit_obj, 1, lte_deinit);
554583

555584
STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
556585
lte_check_init();
557-
bool is_new_band_support = false;
558-
586+
bool is_hw_new_band_support = false;
587+
bool is_sw_new_band_support = false;
559588
STATIC const mp_arg_t allowed_args[] = {
560589
{ MP_QSTR_band, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
561590
{ MP_QSTR_apn, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -579,27 +608,25 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
579608
if (lteppp_get_state() < E_LTE_ATTACHING) {
580609

581610
if (!lte_obj.carrier) {
582-
611+
/* Get configured bands in modem */
583612
lte_task_cmd_data_t cmd = { .timeout = LTE_RX_TIMEOUT_MAX_MS };
584613
memcpy(cmd.data, "AT+SMDD", strlen("AT+SMDD"));
585614
lteppp_send_at_command(&cmd, &modlte_rsp);
586-
587-
if(strstr(modlte_rsp.data, "17 bands") == NULL)
615+
/* Dummy command for command response > Uart buff size */
616+
memcpy(cmd.data, "Pycom_Dummy", strlen("Pycom_Dummy"));
617+
while(modlte_rsp.data_remaining)
588618
{
589-
memcpy(cmd.data, "Pycom_Dummy", strlen("Pycom_Dummy"));
590-
while(modlte_rsp.data_remaining)
619+
if((strstr(modlte_rsp.data, "17 bands") != NULL) && !is_hw_new_band_support)
591620
{
592-
lteppp_send_at_command(&cmd, &modlte_rsp);
593-
if(strstr(modlte_rsp.data, "<band p=\"5\">") != NULL)
594-
{
595-
is_new_band_support = true;
596-
break;
597-
}
621+
is_hw_new_band_support = true;
598622
}
623+
lteppp_send_at_command(&cmd, &modlte_rsp);
599624
}
600-
else
625+
int version = lte_get_modem_version();
626+
627+
if(version > 0 && version > SQNS_SW_FULL_BAND_SUPPORT)
601628
{
602-
is_new_band_support = true;
629+
is_sw_new_band_support = true;
603630
}
604631
// configuring scanning in all bands
605632
lte_push_at_command("AT!=\"clearscanconfig\"", LTE_RX_TIMEOUT_MIN_MS);
@@ -608,17 +635,58 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
608635
if (args[0].u_obj == mp_const_none) {
609636
lte_push_at_command("AT!=\"RRC::addScanBand band=3\"", LTE_RX_TIMEOUT_MIN_MS);
610637
lte_push_at_command("AT!=\"RRC::addScanBand band=4\"", LTE_RX_TIMEOUT_MIN_MS);
611-
if (is_new_band_support) {
638+
if (is_hw_new_band_support && version > SQNS_SW_5_8_BAND_SUPPORT) {
612639
lte_push_at_command("AT!=\"RRC::addScanBand band=5\"", LTE_RX_TIMEOUT_MIN_MS);
613640
lte_push_at_command("AT!=\"RRC::addScanBand band=8\"", LTE_RX_TIMEOUT_MIN_MS);
614641
}
615642
lte_push_at_command("AT!=\"RRC::addScanBand band=12\"", LTE_RX_TIMEOUT_MIN_MS);
616643
lte_push_at_command("AT!=\"RRC::addScanBand band=13\"", LTE_RX_TIMEOUT_MIN_MS);
617644
lte_push_at_command("AT!=\"RRC::addScanBand band=20\"", LTE_RX_TIMEOUT_MIN_MS);
618645
lte_push_at_command("AT!=\"RRC::addScanBand band=28\"", LTE_RX_TIMEOUT_MIN_MS);
619-
} else {
646+
}
647+
else
648+
{
620649
uint32_t band = mp_obj_get_int(args[0].u_obj);
621-
if (band == 3) {
650+
/* Check band support */
651+
switch(band)
652+
{
653+
case 5:
654+
case 8:
655+
if(!is_hw_new_band_support)
656+
{
657+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by this board hardware!", band));
658+
}
659+
else if(version < SQNS_SW_5_8_BAND_SUPPORT)
660+
{
661+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by current modem Firmware, please upgrade!", band));
662+
}
663+
break;
664+
case 1:
665+
case 2:
666+
case 14:
667+
case 17:
668+
case 18:
669+
case 19:
670+
case 25:
671+
case 26:
672+
case 66:
673+
if(!is_sw_new_band_support)
674+
{
675+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by current modem Firmware, please upgrade!", band));
676+
}
677+
if(!is_hw_new_band_support)
678+
{
679+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by this board hardware!", band));
680+
}
681+
break;
682+
default:
683+
break;
684+
}
685+
if (band == 1) {
686+
lte_push_at_command("AT!=\"RRC::addScanBand band=1\"", LTE_RX_TIMEOUT_MIN_MS);
687+
} else if (band == 2) {
688+
lte_push_at_command("AT!=\"RRC::addScanBand band=2\"", LTE_RX_TIMEOUT_MIN_MS);
689+
} else if (band == 3) {
622690
lte_push_at_command("AT!=\"RRC::addScanBand band=3\"", LTE_RX_TIMEOUT_MIN_MS);
623691
} else if (band == 4) {
624692
lte_push_at_command("AT!=\"RRC::addScanBand band=4\"", LTE_RX_TIMEOUT_MIN_MS);
@@ -630,10 +698,24 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
630698
lte_push_at_command("AT!=\"RRC::addScanBand band=12\"", LTE_RX_TIMEOUT_MIN_MS);
631699
} else if (band == 13) {
632700
lte_push_at_command("AT!=\"RRC::addScanBand band=13\"", LTE_RX_TIMEOUT_MIN_MS);
701+
} else if (band == 14) {
702+
lte_push_at_command("AT!=\"RRC::addScanBand band=14\"", LTE_RX_TIMEOUT_MIN_MS);
703+
} else if (band == 17) {
704+
lte_push_at_command("AT!=\"RRC::addScanBand band=17\"", LTE_RX_TIMEOUT_MIN_MS);
705+
} else if (band == 18) {
706+
lte_push_at_command("AT!=\"RRC::addScanBand band=18\"", LTE_RX_TIMEOUT_MIN_MS);
707+
} else if (band == 19) {
708+
lte_push_at_command("AT!=\"RRC::addScanBand band=19\"", LTE_RX_TIMEOUT_MIN_MS);
633709
} else if (band == 20) {
634710
lte_push_at_command("AT!=\"RRC::addScanBand band=20\"", LTE_RX_TIMEOUT_MIN_MS);
711+
} else if (band == 25) {
712+
lte_push_at_command("AT!=\"RRC::addScanBand band=25\"", LTE_RX_TIMEOUT_MIN_MS);
713+
} else if (band == 26) {
714+
lte_push_at_command("AT!=\"RRC::addScanBand band=26\"", LTE_RX_TIMEOUT_MIN_MS);
635715
} else if (band == 28) {
636716
lte_push_at_command("AT!=\"RRC::addScanBand band=28\"", LTE_RX_TIMEOUT_MIN_MS);
717+
} else if (band == 66) {
718+
lte_push_at_command("AT!=\"RRC::addScanBand band=66\"", LTE_RX_TIMEOUT_MIN_MS);
637719
} else {
638720
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported", band));
639721
}

0 commit comments

Comments
 (0)