@@ -49,39 +49,41 @@ mp_obj_t pyb_wlan_disconnect(void) {
49
49
return mp_obj_new_int (ret );
50
50
}
51
51
52
- mp_obj_t decode_addr (unsigned char * ip , int nBytes ) {
52
+ mp_obj_t decode_addr (unsigned char * ip , int n_bytes ) {
53
53
char data [64 ] = "" ;
54
- if (nBytes == 4 ) {
54
+ if (n_bytes == 4 ) {
55
55
snprintf (data , 64 , "%u.%u.%u.%u" , ip [3 ], ip [2 ], ip [1 ], ip [0 ]);
56
- } else if (nBytes == 6 ) {
56
+ } else if (n_bytes == 6 ) {
57
57
snprintf (data , 64 , "%02x:%02x:%02x:%02x:%02x:%02x" , ip [5 ], ip [4 ], ip [3 ], ip [2 ], ip [1 ], ip [0 ]);
58
- } else if (nBytes == 32 ) {
58
+ } else if (n_bytes == 32 ) {
59
59
snprintf (data , 64 , "%s" , ip );
60
60
}
61
61
return mp_obj_new_str (qstr_from_strn_copy (data , strlen (data )));
62
62
}
63
63
64
- void _wlan_getIP_get_address (mp_obj_t object , qstr q_attr , unsigned char * ip , int nBytes ) {
65
- rt_store_attr (object , q_attr , decode_addr (ip , nBytes ));
64
+ void decode_addr_and_store (mp_obj_t object , qstr q_attr , unsigned char * ip , int n_bytes ) {
65
+ rt_store_attr (object , q_attr , decode_addr (ip , n_bytes ));
66
66
}
67
67
68
68
mp_obj_t pyb_wlan_get_ip (void ) {
69
- tNetappIpconfigRetArgs ipconfig ;
70
- netapp_ipconfig (& ipconfig );
71
-
72
- /* If byte 1 is 0 we don't have a valid address */
73
- if (ipconfig .aucIP [3 ] == 0 ) return mp_const_none ;
74
-
75
- mp_obj_t data = mp_module_new (); // TODO should really be a class
76
- _wlan_getIP_get_address (data , qstr_from_str_static ("ip" ), & ipconfig .aucIP [0 ], 4 );
77
- _wlan_getIP_get_address (data , qstr_from_str_static ("subnet" ), & ipconfig .aucSubnetMask [0 ], 4 );
78
- _wlan_getIP_get_address (data , qstr_from_str_static ("gateway" ), & ipconfig .aucDefaultGateway [0 ], 4 );
79
- _wlan_getIP_get_address (data , qstr_from_str_static ("dhcp" ), & ipconfig .aucDHCPServer [0 ], 4 );
80
- _wlan_getIP_get_address (data , qstr_from_str_static ("dns" ), & ipconfig .aucDNSServer [0 ], 4 );
81
- _wlan_getIP_get_address (data , qstr_from_str_static ("mac" ), & ipconfig .uaMacAddr [0 ], 6 );
82
- _wlan_getIP_get_address (data , qstr_from_str_static ("ssid" ), & ipconfig .uaSSID [0 ], 32 );
83
-
84
- return data ;
69
+ tNetappIpconfigRetArgs ipconfig ;
70
+ netapp_ipconfig (& ipconfig );
71
+
72
+ // If byte 1 is 0 we don't have a valid address
73
+ if (ipconfig .aucIP [3 ] == 0 ) {
74
+ return mp_const_none ;
75
+ }
76
+
77
+ mp_obj_t data = mp_module_new (); // TODO should really be a class
78
+ decode_addr_and_store (data , qstr_from_str_static ("ip" ), & ipconfig .aucIP [0 ], 4 );
79
+ decode_addr_and_store (data , qstr_from_str_static ("subnet" ), & ipconfig .aucSubnetMask [0 ], 4 );
80
+ decode_addr_and_store (data , qstr_from_str_static ("gateway" ), & ipconfig .aucDefaultGateway [0 ], 4 );
81
+ decode_addr_and_store (data , qstr_from_str_static ("dhcp" ), & ipconfig .aucDHCPServer [0 ], 4 );
82
+ decode_addr_and_store (data , qstr_from_str_static ("dns" ), & ipconfig .aucDNSServer [0 ], 4 );
83
+ decode_addr_and_store (data , qstr_from_str_static ("mac" ), & ipconfig .uaMacAddr [0 ], 6 );
84
+ decode_addr_and_store (data , qstr_from_str_static ("ssid" ), & ipconfig .uaSSID [0 ], 32 );
85
+
86
+ return data ;
85
87
}
86
88
87
89
uint32_t last_ip = 0 ; // XXX such a hack!
0 commit comments