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);
117120static bool lte_check_attached (bool legacy );
118121static void lte_check_init (void );
119122static bool lte_check_sim_present (void );
123+ static int lte_get_modem_version (void );
120124STATIC mp_obj_t lte_suspend (mp_obj_t self_in );
121125STATIC 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
283312static 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
551580STATIC 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