Skip to content

Commit 36ae417

Browse files
author
danicampora
committed
docs: Add wipy and network.server documentation.
1 parent 2e0cd20 commit 36ae417

File tree

8 files changed

+95
-27
lines changed

8 files changed

+95
-27
lines changed

cc3200/mods/modnetwork.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ STATIC const mp_arg_t network_server_args[] = {
9191
{ MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
9292
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
9393
};
94-
STATIC mp_obj_t network_server_new (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
94+
STATIC mp_obj_t network_server_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
9595
// parse args
96+
mp_map_t kw_args;
97+
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
9698
mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args)];
97-
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(args), network_server_args, args);
99+
mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), network_server_args, args);
98100

99101
// check the server id
100102
if (args[0].u_obj != MP_OBJ_NULL) {
@@ -108,9 +110,8 @@ STATIC mp_obj_t network_server_new (mp_uint_t n_args, const mp_obj_t *pos_args,
108110
self->base.type = &network_server_type;
109111
network_server_init_helper(self, &args[1]);
110112

111-
return self;
113+
return (mp_obj_t)self;
112114
}
113-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_new_obj, 0, network_server_new);
114115

115116
STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
116117
// parse args
@@ -152,7 +153,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
152153
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan },
153154

154155
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
155-
{ MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_new_obj },
156+
{ MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_type },
156157
#endif
157158
};
158159

@@ -169,14 +170,15 @@ STATIC const mp_map_elem_t network_server_locals_dict_table[] = {
169170
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&network_server_init_obj },
170171
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&network_server_deinit_obj },
171172
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&network_server_timeout_obj },
172-
{ MP_OBJ_NEW_QSTR(MP_QSTR_running), (mp_obj_t)&network_server_running_obj },
173+
{ MP_OBJ_NEW_QSTR(MP_QSTR_isrunning), (mp_obj_t)&network_server_running_obj },
173174
};
174175

175176
STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table);
176177

177178
STATIC const mp_obj_type_t network_server_type = {
178179
{ &mp_type_type },
179180
.name = MP_QSTR_server,
181+
.make_new = network_server_make_new,
180182
.locals_dict = (mp_obj_t)&network_server_locals_dict,
181183
};
182184
#endif

cc3200/qstrdefsport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Q(init)
283283
Q(deinit)
284284
Q(login)
285285
Q(timeout)
286-
Q(running)
286+
Q(isrunning)
287287

288288
// for WLAN class
289289
Q(WLAN)

docs/library/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ it will fallback to loading the built-in ``ujson`` module.
105105

106106
machine.rst
107107
network.rst
108+
wipy.rst
108109

109110

110111
.. only:: port_esp8266

docs/library/network.rst

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@ For example::
2727
data = s.recv(1000)
2828
s.close()
2929

30+
.. only:: port_wipy
31+
32+
.. _network.server:
33+
34+
class server
35+
============
36+
37+
Constructors
38+
------------
39+
40+
.. class:: server(id, ...)
41+
42+
Create a server instance, see ``init`` for parameters of initialization.
43+
44+
Methods
45+
-------
46+
47+
.. method:: server.init(\*, login=('micro', 'python'), timeout=300)
48+
49+
Init (and effectively start the server). Optionally a new ``user``, ``password``
50+
and ``timeout`` (in seconds) can be passed.
51+
52+
.. method:: server.deinit()
53+
54+
Stop the server
55+
56+
.. method:: server.timeout([timeout_in_seconds])
57+
58+
Get or set the server timeout.
59+
60+
.. method:: server.isrunning()
61+
62+
Returns ``True`` is the server is running, ``False`` otherwise.
63+
3064
.. only:: port_pyboard
3165

3266
class CC3K
@@ -178,13 +212,13 @@ For example::
178212

179213
Dump the WIZnet5x00 registers. Useful for debugging.
180214

181-
class WLAN
182-
==========
183-
184215
.. _network.WLAN:
185216

186217
.. only:: port_esp8266
187218

219+
class WLAN
220+
==========
221+
188222
This class provides a driver for WiFi network processor in the ESP8266. Example usage::
189223

190224
import network
@@ -258,6 +292,9 @@ class WLAN
258292

259293
.. only:: port_wipy
260294

295+
class WLAN
296+
==========
297+
261298
This class provides a driver for WiFi network processor in the WiPy. Example usage::
262299

263300
import network
@@ -282,7 +319,7 @@ class WLAN
282319
Methods
283320
-------
284321

285-
.. method:: init(mode, \*, ssid, security, key, channel, antenna)
322+
.. method:: wlan.init(mode, \*, ssid, security, key, channel, antenna)
286323

287324
Set or get the WiFi network processor configuration.
288325

docs/library/wipy.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
:mod:`wipy` -- WiPy specific features
2+
=====================================
3+
4+
.. module:: wipy
5+
:synopsis: WiPy specific features
6+
7+
The ``wipy`` module contains functions to control specific features of the
8+
WiPy, such as the heartbeat LED.
9+
10+
Functions
11+
---------
12+
13+
.. function:: heartbeat([enable])
14+
15+
Get or set the state (enabled or disabled) of the heartbeat LED.

docs/wipy/general.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ The heart beat LED
119119
------------------
120120

121121
By default the heart beat LED flashes once every 4s to signal that the system is
122-
alive. This can be overridden through the HeartBeat class:
122+
alive. This can be overridden through the :mod:`wipy` module::
123123

124-
``machine.HeartBeat().disable()``
124+
import wipy
125+
wipy.heartbeat(False)
125126

126127
There are currently 2 kinds of errors that you might see:
127128

docs/wipy/quickref.rst

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Quick reference for the WiPy
1010
General board control (including sleep modes)
1111
---------------------------------------------
1212

13-
See :mod:`machine`. ::
13+
See the :mod:`machine` module::
1414

1515
import machine
1616

@@ -198,14 +198,26 @@ See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
198198
machine.sleep()
199199
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
200200

201-
Heart beat LED
202-
--------------
201+
Telnet and FTP server
202+
---------------------
203+
204+
See :ref:`network.server <network.server>` ::
205+
206+
from network import network
207+
208+
# init with new user, pass word and seconds timeout
209+
server = server.init(login=('user', 'password'), timeout=60)
210+
server.timeout(300) # change the timeout
211+
server.timeout() # get the timeout
212+
server.isrunning() # check wether the server is running or not
213+
214+
HeartBeat LED
215+
-------------
203216

204-
See :ref:`machine.HeartBeat <machine.HeartBeat>`. ::
217+
See :mod:`wipy`. ::
205218

206-
from machine import HeartBeat
219+
import wipy
207220

208-
# disable the heart beat indication (you are free to use this LED connected to GP25)
209-
HeartBeat().disable()
210-
# enable the heart beat again
211-
HeartBeat().enable()
221+
wipy.heartbeat(False) # disable the heartbeat LED
222+
wipy.heartbeat(True) # enable the heartbeat LED
223+
wipy.heartbeat() # get the heartbeat state

tests/wipy/wlan/server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
server = network.server()
1313

1414
print(server.timeout() == 300)
15-
print(server.running() == True)
15+
print(server.isrunning() == True)
1616
server.deinit()
17-
print(server.running() == False)
17+
print(server.isrunning() == False)
1818

1919
server.init(login=('test-user', 'test-password'), timeout=60)
20-
print(server.running() == True)
20+
print(server.isrunning() == True)
2121
print(server.timeout() == 60)
2222

2323
server.deinit()
24-
print(server.running() == False)
24+
print(server.isrunning() == False)
2525
server.init()
26-
print(server.running() == True)
26+
print(server.isrunning() == True)
2727

2828
try:
2929
server.init(1)

0 commit comments

Comments
 (0)