1
- /*
1
+ /*
2
2
* Copyright (c) 2017, Pycom Limited and its licensors.
3
3
*
4
4
* This software is licensed under the GNU GPL version 3 or any later version,
@@ -90,6 +90,8 @@ uart_dev_t* uart_driver_lte = &UART2;
90
90
uart_config_t lte_uart_config0 ;
91
91
uart_config_t lte_uart_config1 ;
92
92
93
+ static bool lte_legacyattach_flag = false;
94
+
93
95
extern TaskHandle_t xLTEUpgradeTaskHndl ;
94
96
extern TaskHandle_t mpTaskHandle ;
95
97
extern TaskHandle_t svTaskHandle ;
@@ -109,7 +111,7 @@ extern TaskHandle_t xLTETaskHndl;
109
111
static bool lte_push_at_command_ext (char * cmd_str , uint32_t timeout , const char * expected_rsp );
110
112
static bool lte_push_at_command (char * cmd_str , uint32_t timeout );
111
113
static void lte_pause_ppp (void );
112
- static bool lte_check_attached (void );
114
+ static bool lte_check_attached (bool legacy );
113
115
static void lte_check_init (void );
114
116
static bool lte_check_sim_present (void );
115
117
STATIC mp_obj_t lte_suspend (mp_obj_t self_in );
@@ -189,7 +191,7 @@ static void lte_pause_ppp(void) {
189
191
}
190
192
}
191
193
192
- static bool lte_check_attached (void ) {
194
+ static bool lte_check_attached (bool legacy ) {
193
195
char * pos ;
194
196
bool attached = false;
195
197
bool cgatt = false;
@@ -210,19 +212,25 @@ static bool lte_check_attached(void) {
210
212
if (((pos = strstr (modlte_rsp .data , "+CGATT" )) && (strlen (pos ) >= 7 ) && (pos [7 ] == '1' || pos [8 ] == '1' ))) {
211
213
cgatt = true;
212
214
}
213
- lte_push_at_command ("AT+CEREG?" , LTE_RX_TIMEOUT_MIN_MS );
214
- if (!cgatt ) {
215
- if (((pos = strstr (modlte_rsp .data , "+CEREG: 2,1," )) || (pos = strstr (modlte_rsp .data , "+CEREG: 2,5," )))
216
- && (strlen (pos ) >= 31 ) && (pos [30 ] == '7' || pos [30 ] == '9' )) {
217
- attached = true;
218
- }
219
- } else {
220
- if ((pos = strstr (modlte_rsp .data , "+CEREG: 2,1," )) || (pos = strstr (modlte_rsp .data , "+CEREG: 2,5," ))) {
221
- attached = true;
215
+ if (legacy ) {
216
+ lte_push_at_command ("AT+CEREG?" , LTE_RX_TIMEOUT_MIN_MS );
217
+ if (!cgatt ) {
218
+ if (((pos = strstr (modlte_rsp .data , "+CEREG: 2,1," )) || (pos = strstr (modlte_rsp .data , "+CEREG: 2,5," )))
219
+ && (strlen (pos ) >= 31 ) && (pos [30 ] == '7' || pos [30 ] == '9' )) {
220
+ attached = true;
221
+ }
222
222
} else {
223
- attached = false;
223
+ if ((pos = strstr (modlte_rsp .data , "+CEREG: 2,1," )) || (pos = strstr (modlte_rsp .data , "+CEREG: 2,5," ))) {
224
+ attached = true;
225
+ } else {
226
+ attached = false;
227
+ }
224
228
}
225
229
}
230
+ else
231
+ {
232
+ attached = cgatt ;
233
+ }
226
234
lte_push_at_command ("AT+CFUN?" , LTE_RX_TIMEOUT_MIN_MS );
227
235
if (lteppp_get_state () == E_LTE_ATTACHING ) {
228
236
// for some reason the modem has crashed, enabled the radios again...
@@ -357,6 +365,9 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
357
365
}
358
366
}
359
367
368
+ // set legacy flag
369
+ lte_legacyattach_flag = args [2 ].u_bool ;
370
+
360
371
// configure the carrier
361
372
lte_push_at_command ("AT+SQNCTM?" , LTE_RX_TIMEOUT_MAX_MS );
362
373
if (!strstr (modlte_rsp .data , carrier )) {
@@ -380,7 +391,8 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
380
391
static const mp_arg_t lte_init_args [] = {
381
392
{ MP_QSTR_id , MP_ARG_INT , {.u_int = 0 } },
382
393
{ MP_QSTR_carrier , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
383
- { MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } }
394
+ { MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
395
+ { MP_QSTR_legacyattach , MP_ARG_KW_ONLY | MP_ARG_BOOL , {.u_bool = false}}
384
396
};
385
397
386
398
static mp_obj_t lte_make_new (const mp_obj_type_t * type , mp_uint_t n_args , mp_uint_t n_kw , const mp_obj_t * all_args ) {
@@ -517,14 +529,19 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
517
529
{ MP_QSTR_log , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_false } },
518
530
{ MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_obj = mp_const_none } },
519
531
{ MP_QSTR_type , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
532
+ { MP_QSTR_legacyattach , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
520
533
521
534
};
522
535
523
536
// parse args
524
537
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
525
538
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
526
539
527
- lte_check_attached ();
540
+ if (args [5 ].u_obj != mp_const_none ) {
541
+ lte_legacyattach_flag = mp_obj_is_true (args [5 ].u_obj );
542
+ }
543
+
544
+ lte_check_attached (lte_legacyattach_flag );
528
545
529
546
if (lteppp_get_state () < E_LTE_ATTACHING ) {
530
547
// configuring scanning in all 6 bands
@@ -690,7 +707,7 @@ STATIC mp_obj_t lte_suspend(mp_obj_t self_in) {
690
707
break ;
691
708
}
692
709
}
693
- lte_check_attached ();
710
+ lte_check_attached (lte_legacyattach_flag );
694
711
}
695
712
return mp_const_none ;
696
713
}
@@ -700,7 +717,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(lte_suspend_obj, lte_suspend);
700
717
701
718
STATIC mp_obj_t lte_isattached (mp_obj_t self_in ) {
702
719
lte_check_init ();
703
- if (lte_check_attached ()) {
720
+ if (lte_check_attached (lte_legacyattach_flag )) {
704
721
return mp_const_true ;
705
722
}
706
723
return mp_const_false ;
@@ -726,7 +743,7 @@ STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
726
743
args [1 ].u_bool = lte_check_legacy_version ();
727
744
}
728
745
729
- lte_check_attached ();
746
+ lte_check_attached (lte_legacyattach_flag );
730
747
lteppp_set_legacy (args [1 ].u_bool );
731
748
732
749
if (args [1 ].u_bool ) {
@@ -778,7 +795,7 @@ STATIC mp_obj_t lte_resume(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
778
795
if (lteppp_get_state () == E_LTE_PPP ) {
779
796
nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_request_not_possible ));
780
797
}
781
- lte_check_attached ();
798
+ lte_check_attached (lte_legacyattach_flag );
782
799
783
800
if (lteppp_get_state () == E_LTE_SUSPENDED || lteppp_get_state () == E_LTE_ATTACHED ) {
784
801
if (lteppp_get_state () == E_LTE_ATTACHED && lteppp_get_legacy () == E_LTE_LEGACY ) {
@@ -820,7 +837,7 @@ STATIC mp_obj_t lte_disconnect(mp_obj_t self_in) {
820
837
break ;
821
838
}
822
839
}
823
- lte_check_attached ();
840
+ lte_check_attached (lte_legacyattach_flag );
824
841
}
825
842
return mp_const_none ;
826
843
}
0 commit comments