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);
119122static bool lte_check_attached (bool legacy );
120123static void lte_check_init (void );
121124static bool lte_check_sim_present (void );
125+ static int lte_get_modem_version (void );
122126STATIC mp_obj_t lte_suspend (mp_obj_t self_in );
123127STATIC 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
285314static 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
555584STATIC 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