@@ -850,17 +850,16 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
850
850
851
851
852
852
if (args [ARG_id ].u_obj == mp_const_none && args [ARG_pac ].u_obj == mp_const_none && args [ARG_public_key ].u_obj == mp_const_none && args [ARG_private_key ].u_obj == mp_const_none ) {
853
+ // query sigfox info
853
854
854
- mp_obj_tuple_t * t = MP_OBJ_TO_PTR (mp_obj_new_tuple (4 , NULL ));
855
-
856
- t -> items [ARG_id ] = is_empty (id , sizeof (id )) ? mp_const_none :mp_obj_new_str ((const char * )id , sizeof (id ));
857
- t -> items [ARG_pac ] = is_empty (pac , sizeof (pac )) ? mp_const_none :mp_obj_new_str ((const char * )pac , sizeof (pac ));
858
- t -> items [ARG_public_key ] = is_empty (public_key , sizeof (public_key )) ? mp_const_none :mp_obj_new_str ((const char * )public_key , sizeof (public_key ));
859
- t -> items [ARG_private_key ] = is_empty (private_key , sizeof (private_key )) ? mp_const_none :mp_obj_new_str ((const char * )private_key , sizeof (private_key ));
860
-
861
- return MP_OBJ_FROM_PTR (t );
862
-
855
+ if ( !is_empty (id , sizeof (id )) && !is_empty (pac , sizeof (pac )) && !is_empty (public_key , sizeof (public_key )) && !is_empty (private_key , sizeof (private_key )) ){
856
+ // all configs valid
857
+ return mp_const_true ;
858
+ } else {
859
+ return mp_const_false ;
860
+ }
863
861
} else {
862
+ // write sigfox info
864
863
865
864
// temporary array to store even the longest value from id, pac, public_key and private_key
866
865
uint8_t tmp_array [16 ];
@@ -892,7 +891,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
892
891
893
892
ret_val = config_set_sigfox_id (tmp_array );
894
893
if (ret_val == false) {
895
- return mp_const_false ;
894
+ nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "Failed to write id" )) ;
896
895
}
897
896
} else {
898
897
nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Use force option to overwrite existing id!" ));
@@ -923,7 +922,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
923
922
924
923
ret_val = config_set_sigfox_pac (tmp_array );
925
924
if (ret_val == false) {
926
- return mp_const_false ;
925
+ nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "Failed to write pac" )) ;
927
926
}
928
927
} else {
929
928
nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Use force option to overwrite existing pac!" ));
@@ -954,7 +953,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
954
953
955
954
ret_val = config_set_sigfox_public_key (tmp_array );
956
955
if (ret_val == false) {
957
- return mp_const_false ;
956
+ nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "Failed to write public key" )) ;
958
957
}
959
958
} else {
960
959
nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Use force option to overwrite existing public key!" ));
@@ -986,15 +985,14 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
986
985
987
986
ret_val = config_set_sigfox_private_key (tmp_array );
988
987
if (ret_val == false) {
989
- return mp_const_false ;
988
+ nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "Failed to write private key" )) ;
990
989
}
991
990
} else {
992
991
nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Use force option to overwrite existing private key!" ));
993
992
}
994
993
}
995
994
return mp_const_true ;
996
995
}
997
- return mp_const_none ;
998
996
}
999
997
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (mod_pycom_sigfox_info_obj , 0 , mod_pycom_sigfox_info );
1000
998
0 commit comments