@@ -90,7 +90,7 @@ 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 ;
93
+ static bool lte_legacyattach_flag = true ;
94
94
95
95
extern TaskHandle_t xLTEUpgradeTaskHndl ;
96
96
extern TaskHandle_t mpTaskHandle ;
@@ -115,6 +115,7 @@ static bool lte_check_attached(bool legacy);
115
115
static void lte_check_init (void );
116
116
static bool lte_check_sim_present (void );
117
117
STATIC mp_obj_t lte_suspend (mp_obj_t self_in );
118
+ STATIC mp_obj_t lte_connect (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args );
118
119
119
120
STATIC mp_obj_t lte_deinit (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args );
120
121
STATIC mp_obj_t lte_disconnect (mp_obj_t self_in );
@@ -131,13 +132,11 @@ void modlte_init0(void) {
131
132
// DEFINE STATIC FUNCTIONS
132
133
//*****************************************************************************
133
134
134
- static bool lte_push_at_command_ext (char * cmd_str , uint32_t timeout , const char * expected_rsp ) {
135
- lte_task_cmd_data_t cmd = {
136
- .timeout = timeout
137
- };
135
+ static bool lte_push_at_command_ext (char * cmd_str , uint32_t timeout , const char * expected_rsp ) {
136
+ lte_task_cmd_data_t cmd = { .timeout = timeout };
138
137
memcpy (cmd .data , cmd_str , strlen (cmd_str ));
139
- //printf("[CMD] %s\n", cmd_str);
140
- lteppp_send_at_command (& cmd , & modlte_rsp );
138
+ //printf("[CMD] %s\n", cmd_str);
139
+ lteppp_send_at_command (& cmd , & modlte_rsp );
141
140
if (strstr (modlte_rsp .data , expected_rsp ) != NULL ) {
142
141
//printf("[OK] %s\n", modlte_rsp.data);
143
142
return true;
@@ -147,14 +146,12 @@ static bool lte_push_at_command_ext (char *cmd_str, uint32_t timeout, const char
147
146
}
148
147
149
148
static bool lte_push_at_command_delay_ext (char * cmd_str , uint32_t timeout , const char * expected_rsp , TickType_t delay ) {
150
- lte_task_cmd_data_t cmd = {
151
- .timeout = timeout
152
- };
149
+ lte_task_cmd_data_t cmd = { .timeout = timeout };
153
150
memcpy (cmd .data , cmd_str , strlen (cmd_str ));
154
- //printf("[CMD] %s\n", cmd_str);
155
- lteppp_send_at_command_delay (& cmd , & modlte_rsp , delay );
151
+ //printf("[CMD] %s\n", cmd_str);
152
+ lteppp_send_at_command_delay (& cmd , & modlte_rsp , delay );
156
153
if (strstr (modlte_rsp .data , expected_rsp ) != NULL ) {
157
- //printf("[OK] %s\n", modlte_rsp.data);
154
+ //printf("[OK] %s\n", modlte_rsp.data);
158
155
return true;
159
156
}
160
157
//printf("[FAIL] %s\n", modlte_rsp.data);
@@ -215,6 +212,10 @@ static bool lte_check_attached(bool legacy) {
215
212
if (legacy ) {
216
213
lte_push_at_command ("AT+CEREG?" , LTE_RX_TIMEOUT_MIN_MS );
217
214
if (!cgatt ) {
215
+ if (strstr (modlte_rsp .data , "ERROR" )) {
216
+ mp_hal_delay_ms (LTE_RX_TIMEOUT_MIN_MS );
217
+ lte_push_at_command ("AT+CEREG?" , LTE_RX_TIMEOUT_MIN_MS );
218
+ }
218
219
if (((pos = strstr (modlte_rsp .data , "+CEREG: 2,1," )) || (pos = strstr (modlte_rsp .data , "+CEREG: 2,5," )))
219
220
&& (strlen (pos ) >= 31 ) && (pos [30 ] == '7' || pos [30 ] == '9' )) {
220
221
attached = true;
@@ -232,9 +233,9 @@ static bool lte_check_attached(bool legacy) {
232
233
attached = cgatt ;
233
234
}
234
235
lte_push_at_command ("AT+CFUN?" , LTE_RX_TIMEOUT_MIN_MS );
235
- if (lteppp_get_state () == E_LTE_ATTACHING ) {
236
- // for some reason the modem has crashed, enabled the radios again...
236
+ if (lteppp_get_state () >= E_LTE_ATTACHING ) {
237
237
if (!strstr (modlte_rsp .data , "+CFUN: 1" )) {
238
+ //for some reason the modem has crashed, enabled the radios again...
238
239
lte_push_at_command ("AT+CFUN=1" , LTE_RX_TIMEOUT_MIN_MS );
239
240
}
240
241
} else {
@@ -248,16 +249,21 @@ static bool lte_check_attached(bool legacy) {
248
249
if (attached && lteppp_get_state () < E_LTE_PPP ) {
249
250
lteppp_set_state (E_LTE_ATTACHED );
250
251
}
251
- //printf("This is our current LTE state: %d\n", lteppp_get_state());
252
- //printf("This is check_attached returning %d\n", attached);
252
+ if (!attached && lteppp_get_state () > E_LTE_IDLE ) {
253
+ lteppp_set_state (E_LTE_ATTACHING );
254
+ }
253
255
return attached ;
254
256
}
255
257
256
258
static bool lte_check_legacy_version (void ) {
257
259
if (lte_push_at_command ("ATI1" , LTE_RX_TIMEOUT_MAX_MS )) {
258
260
return strstr (modlte_rsp .data , "LR5.1.1.0-33080" );
259
261
} else {
260
- nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "LTE modem version not read" ));
262
+ if (lte_push_at_command ("ATI1" , LTE_RX_TIMEOUT_MAX_MS )) {
263
+ return strstr (modlte_rsp .data , "LR5.1.1.0-33080" );
264
+ } else {
265
+ nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "LTE modem version not read" ));
266
+ }
261
267
}
262
268
return true;
263
269
}
@@ -278,7 +284,12 @@ static void lte_check_inppp(void) {
278
284
static bool lte_check_sim_present (void ) {
279
285
lte_push_at_command ("AT+CPIN?" , LTE_RX_TIMEOUT_MAX_MS );
280
286
if (strstr (modlte_rsp .data , "ERROR" )) {
281
- return false;
287
+ lte_push_at_command ("AT+CPIN?" , LTE_RX_TIMEOUT_MAX_MS );
288
+ if (strstr (modlte_rsp .data , "ERROR" )) {
289
+ return false;
290
+ } else {
291
+ return true;
292
+ }
282
293
} else {
283
294
return true;
284
295
}
@@ -390,9 +401,9 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
390
401
391
402
static const mp_arg_t lte_init_args [] = {
392
403
{ MP_QSTR_id , MP_ARG_INT , {.u_int = 0 } },
393
- { MP_QSTR_carrier , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
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} }
404
+ { MP_QSTR_carrier , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
405
+ { MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
406
+ { MP_QSTR_legacyattach , MP_ARG_KW_ONLY | MP_ARG_BOOL , {.u_bool = true} }
396
407
};
397
408
398
409
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 ) {
@@ -524,12 +535,12 @@ STATIC mp_obj_t lte_attach(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
524
535
lte_check_init ();
525
536
526
537
STATIC const mp_arg_t allowed_args [] = {
527
- { MP_QSTR_band , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
528
- { MP_QSTR_apn , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
529
- { MP_QSTR_log , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_false } },
530
- { MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_obj = mp_const_none } },
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 } },
538
+ { MP_QSTR_band , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
539
+ { MP_QSTR_apn , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
540
+ { MP_QSTR_log , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_false } },
541
+ { MP_QSTR_cid , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_obj = mp_const_none } },
542
+ { MP_QSTR_type , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
543
+ { MP_QSTR_legacyattach , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
533
544
534
545
};
535
546
@@ -813,7 +824,11 @@ STATIC mp_obj_t lte_resume(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
813
824
lteppp_set_state (E_LTE_PPP );
814
825
vTaskDelay (1500 );
815
826
} else {
816
- nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_resource_not_avaliable ));
827
+ lteppp_disconnect ();
828
+ lteppp_set_state (E_LTE_ATTACHED );
829
+ lte_check_attached (lte_legacyattach_flag );
830
+ return lte_connect (n_args , pos_args , kw_args );
831
+ //nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
817
832
}
818
833
} else if (lteppp_get_state () == E_LTE_PPP ) {
819
834
nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "modem already connected" ));
@@ -1080,7 +1095,7 @@ STATIC const mp_map_elem_t lte_locals_dict_table[] = {
1080
1095
{ MP_OBJ_NEW_QSTR (MP_QSTR_send_at_cmd ), (mp_obj_t )& lte_send_at_cmd_obj },
1081
1096
{ MP_OBJ_NEW_QSTR (MP_QSTR_reset ), (mp_obj_t )& lte_reset_obj },
1082
1097
{ MP_OBJ_NEW_QSTR (MP_QSTR_modem_upgrade_mode ), (mp_obj_t )& lte_upgrade_mode_obj },
1083
- { MP_OBJ_NEW_QSTR (MP_QSTR_reconnect_uart ), (mp_obj_t )& lte_reconnect_uart_obj },
1098
+ { MP_OBJ_NEW_QSTR (MP_QSTR_reconnect_uart ), (mp_obj_t )& lte_reconnect_uart_obj },
1084
1099
1085
1100
// class constants
1086
1101
{ MP_OBJ_NEW_QSTR (MP_QSTR_IP ), MP_OBJ_NEW_QSTR (MP_QSTR_IP ) },
0 commit comments