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

Commit 82658b6

Browse files
author
iwahdan88
committed
esp32/modlte: updated modlte to check band support on attach based on modem HW/SW
1 parent 9843037 commit 82658b6

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
******************************************************************************/
@@ -117,6 +120,7 @@ static void lte_pause_ppp(void);
117120
static bool lte_check_attached(bool legacy);
118121
static void lte_check_init(void);
119122
static bool lte_check_sim_present(void);
123+
static int lte_get_modem_version(void);
120124
STATIC mp_obj_t lte_suspend(mp_obj_t self_in);
121125
STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
122126

@@ -279,6 +283,31 @@ static bool lte_check_legacy_version(void) {
279283
return true;
280284
}
281285

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

283312
static void lte_check_init(void) {
284313
if (!lte_obj.init) {
@@ -550,8 +579,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(lte_deinit_obj, 1, lte_deinit);
550579

551580
STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
552581
lte_check_init();
553-
bool is_new_band_support = false;
554-
582+
bool is_hw_new_band_support = false;
583+
bool is_sw_new_band_support = false;
555584
STATIC const mp_arg_t allowed_args[] = {
556585
{ MP_QSTR_band, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
557586
{ MP_QSTR_apn, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -575,27 +604,25 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
575604
if (lteppp_get_state() < E_LTE_ATTACHING) {
576605

577606
if (!lte_obj.carrier) {
578-
607+
/* Get configured bands in modem */
579608
lte_task_cmd_data_t cmd = { .timeout = LTE_RX_TIMEOUT_MAX_MS };
580609
memcpy(cmd.data, "AT+SMDD", strlen("AT+SMDD"));
581610
lteppp_send_at_command(&cmd, &modlte_rsp);
582-
583-
if(strstr(modlte_rsp.data, "17 bands") == NULL)
611+
/* Dummy command for command response > Uart buff size */
612+
memcpy(cmd.data, "Pycom_Dummy", strlen("Pycom_Dummy"));
613+
while(modlte_rsp.data_remaining)
584614
{
585-
memcpy(cmd.data, "Pycom_Dummy", strlen("Pycom_Dummy"));
586-
while(modlte_rsp.data_remaining)
615+
if((strstr(modlte_rsp.data, "17 bands") != NULL) && !is_hw_new_band_support)
587616
{
588-
lteppp_send_at_command(&cmd, &modlte_rsp);
589-
if(strstr(modlte_rsp.data, "<band p=\"5\">") != NULL)
590-
{
591-
is_new_band_support = true;
592-
break;
593-
}
617+
is_hw_new_band_support = true;
594618
}
619+
lteppp_send_at_command(&cmd, &modlte_rsp);
595620
}
596-
else
621+
int version = lte_get_modem_version();
622+
623+
if(version > 0 && version > SQNS_SW_FULL_BAND_SUPPORT)
597624
{
598-
is_new_band_support = true;
625+
is_sw_new_band_support = true;
599626
}
600627
// configuring scanning in all bands
601628
lte_push_at_command("AT!=\"clearscanconfig\"", LTE_RX_TIMEOUT_MIN_MS);
@@ -604,17 +631,58 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
604631
if (args[0].u_obj == mp_const_none) {
605632
lte_push_at_command("AT!=\"RRC::addScanBand band=3\"", LTE_RX_TIMEOUT_MIN_MS);
606633
lte_push_at_command("AT!=\"RRC::addScanBand band=4\"", LTE_RX_TIMEOUT_MIN_MS);
607-
if (is_new_band_support) {
634+
if (is_hw_new_band_support && version > SQNS_SW_5_8_BAND_SUPPORT) {
608635
lte_push_at_command("AT!=\"RRC::addScanBand band=5\"", LTE_RX_TIMEOUT_MIN_MS);
609636
lte_push_at_command("AT!=\"RRC::addScanBand band=8\"", LTE_RX_TIMEOUT_MIN_MS);
610637
}
611638
lte_push_at_command("AT!=\"RRC::addScanBand band=12\"", LTE_RX_TIMEOUT_MIN_MS);
612639
lte_push_at_command("AT!=\"RRC::addScanBand band=13\"", LTE_RX_TIMEOUT_MIN_MS);
613640
lte_push_at_command("AT!=\"RRC::addScanBand band=20\"", LTE_RX_TIMEOUT_MIN_MS);
614641
lte_push_at_command("AT!=\"RRC::addScanBand band=28\"", LTE_RX_TIMEOUT_MIN_MS);
615-
} else {
642+
}
643+
else
644+
{
616645
uint32_t band = mp_obj_get_int(args[0].u_obj);
617-
if (band == 3) {
646+
/* Check band support */
647+
switch(band)
648+
{
649+
case 5:
650+
case 8:
651+
if(!is_hw_new_band_support)
652+
{
653+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by this board hardware!", band));
654+
}
655+
else if(version < SQNS_SW_5_8_BAND_SUPPORT)
656+
{
657+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by current modem Firmware, please upgrade!", band));
658+
}
659+
break;
660+
case 1:
661+
case 2:
662+
case 14:
663+
case 17:
664+
case 18:
665+
case 19:
666+
case 25:
667+
case 26:
668+
case 66:
669+
if(!is_sw_new_band_support)
670+
{
671+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by current modem Firmware, please upgrade!", band));
672+
}
673+
if(!is_hw_new_band_support)
674+
{
675+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported by this board hardware!", band));
676+
}
677+
break;
678+
default:
679+
break;
680+
}
681+
if (band == 1) {
682+
lte_push_at_command("AT!=\"RRC::addScanBand band=1\"", LTE_RX_TIMEOUT_MIN_MS);
683+
} else if (band == 2) {
684+
lte_push_at_command("AT!=\"RRC::addScanBand band=2\"", LTE_RX_TIMEOUT_MIN_MS);
685+
} else if (band == 3) {
618686
lte_push_at_command("AT!=\"RRC::addScanBand band=3\"", LTE_RX_TIMEOUT_MIN_MS);
619687
} else if (band == 4) {
620688
lte_push_at_command("AT!=\"RRC::addScanBand band=4\"", LTE_RX_TIMEOUT_MIN_MS);
@@ -626,10 +694,24 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
626694
lte_push_at_command("AT!=\"RRC::addScanBand band=12\"", LTE_RX_TIMEOUT_MIN_MS);
627695
} else if (band == 13) {
628696
lte_push_at_command("AT!=\"RRC::addScanBand band=13\"", LTE_RX_TIMEOUT_MIN_MS);
697+
} else if (band == 14) {
698+
lte_push_at_command("AT!=\"RRC::addScanBand band=14\"", LTE_RX_TIMEOUT_MIN_MS);
699+
} else if (band == 17) {
700+
lte_push_at_command("AT!=\"RRC::addScanBand band=17\"", LTE_RX_TIMEOUT_MIN_MS);
701+
} else if (band == 18) {
702+
lte_push_at_command("AT!=\"RRC::addScanBand band=18\"", LTE_RX_TIMEOUT_MIN_MS);
703+
} else if (band == 19) {
704+
lte_push_at_command("AT!=\"RRC::addScanBand band=19\"", LTE_RX_TIMEOUT_MIN_MS);
629705
} else if (band == 20) {
630706
lte_push_at_command("AT!=\"RRC::addScanBand band=20\"", LTE_RX_TIMEOUT_MIN_MS);
707+
} else if (band == 25) {
708+
lte_push_at_command("AT!=\"RRC::addScanBand band=25\"", LTE_RX_TIMEOUT_MIN_MS);
709+
} else if (band == 26) {
710+
lte_push_at_command("AT!=\"RRC::addScanBand band=26\"", LTE_RX_TIMEOUT_MIN_MS);
631711
} else if (band == 28) {
632712
lte_push_at_command("AT!=\"RRC::addScanBand band=28\"", LTE_RX_TIMEOUT_MIN_MS);
713+
} else if (band == 66) {
714+
lte_push_at_command("AT!=\"RRC::addScanBand band=66\"", LTE_RX_TIMEOUT_MIN_MS);
633715
} else {
634716
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "band %d not supported", band));
635717
}

0 commit comments

Comments
 (0)