Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5bbc3cdc
Commit
5bbc3cdc
authored
Dec 21, 2013
by
Damien
Browse files
stm: Tidy up some wlan code.
parent
6f954324
Changes
1
Hide whitespace changes
Inline
Side-by-side
stm/pybwlan.c
View file @
5bbc3cdc
...
...
@@ -49,39 +49,41 @@ mp_obj_t pyb_wlan_disconnect(void) {
return
mp_obj_new_int
(
ret
);
}
mp_obj_t
decode_addr
(
unsigned
char
*
ip
,
int
n
B
ytes
)
{
mp_obj_t
decode_addr
(
unsigned
char
*
ip
,
int
n
_b
ytes
)
{
char
data
[
64
]
=
""
;
if
(
n
B
ytes
==
4
)
{
if
(
n
_b
ytes
==
4
)
{
snprintf
(
data
,
64
,
"%u.%u.%u.%u"
,
ip
[
3
],
ip
[
2
],
ip
[
1
],
ip
[
0
]);
}
else
if
(
n
B
ytes
==
6
)
{
}
else
if
(
n
_b
ytes
==
6
)
{
snprintf
(
data
,
64
,
"%02x:%02x:%02x:%02x:%02x:%02x"
,
ip
[
5
],
ip
[
4
],
ip
[
3
],
ip
[
2
],
ip
[
1
],
ip
[
0
]);
}
else
if
(
n
B
ytes
==
32
)
{
}
else
if
(
n
_b
ytes
==
32
)
{
snprintf
(
data
,
64
,
"%s"
,
ip
);
}
return
mp_obj_new_str
(
qstr_from_strn_copy
(
data
,
strlen
(
data
)));
}
void
_wlan_getIP_get_address
(
mp_obj_t
object
,
qstr
q_attr
,
unsigned
char
*
ip
,
int
n
B
ytes
)
{
rt_store_attr
(
object
,
q_attr
,
decode_addr
(
ip
,
n
B
ytes
));
void
decode_addr_and_store
(
mp_obj_t
object
,
qstr
q_attr
,
unsigned
char
*
ip
,
int
n
_b
ytes
)
{
rt_store_attr
(
object
,
q_attr
,
decode_addr
(
ip
,
n
_b
ytes
));
}
mp_obj_t
pyb_wlan_get_ip
(
void
)
{
tNetappIpconfigRetArgs
ipconfig
;
netapp_ipconfig
(
&
ipconfig
);
/* If byte 1 is 0 we don't have a valid address */
if
(
ipconfig
.
aucIP
[
3
]
==
0
)
return
mp_const_none
;
mp_obj_t
data
=
mp_module_new
();
// TODO should really be a class
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"ip"
),
&
ipconfig
.
aucIP
[
0
],
4
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"subnet"
),
&
ipconfig
.
aucSubnetMask
[
0
],
4
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"gateway"
),
&
ipconfig
.
aucDefaultGateway
[
0
],
4
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"dhcp"
),
&
ipconfig
.
aucDHCPServer
[
0
],
4
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"dns"
),
&
ipconfig
.
aucDNSServer
[
0
],
4
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"mac"
),
&
ipconfig
.
uaMacAddr
[
0
],
6
);
_wlan_getIP_get_address
(
data
,
qstr_from_str_static
(
"ssid"
),
&
ipconfig
.
uaSSID
[
0
],
32
);
return
data
;
tNetappIpconfigRetArgs
ipconfig
;
netapp_ipconfig
(
&
ipconfig
);
// If byte 1 is 0 we don't have a valid address
if
(
ipconfig
.
aucIP
[
3
]
==
0
)
{
return
mp_const_none
;
}
mp_obj_t
data
=
mp_module_new
();
// TODO should really be a class
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"ip"
),
&
ipconfig
.
aucIP
[
0
],
4
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"subnet"
),
&
ipconfig
.
aucSubnetMask
[
0
],
4
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"gateway"
),
&
ipconfig
.
aucDefaultGateway
[
0
],
4
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"dhcp"
),
&
ipconfig
.
aucDHCPServer
[
0
],
4
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"dns"
),
&
ipconfig
.
aucDNSServer
[
0
],
4
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"mac"
),
&
ipconfig
.
uaMacAddr
[
0
],
6
);
decode_addr_and_store
(
data
,
qstr_from_str_static
(
"ssid"
),
&
ipconfig
.
uaSSID
[
0
],
32
);
return
data
;
}
uint32_t
last_ip
=
0
;
// XXX such a hack!
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment