From 36ae417c9f1417d65ca773d48a36589e300b4f71 Mon Sep 17 00:00:00 2001 From: danicampora Date: Mon, 19 Oct 2015 15:19:34 +0200 Subject: [PATCH] docs: Add wipy and network.server documentation. --- cc3200/mods/modnetwork.c | 14 ++++++------ cc3200/qstrdefsport.h | 2 +- docs/library/index.rst | 1 + docs/library/network.rst | 45 +++++++++++++++++++++++++++++++++++---- docs/library/wipy.rst | 15 +++++++++++++ docs/wipy/general.rst | 5 +++-- docs/wipy/quickref.rst | 30 ++++++++++++++++++-------- tests/wipy/wlan/server.py | 10 ++++----- 8 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 docs/library/wipy.rst diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index f4fe1b7a15..f8dbd9c53a 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -91,10 +91,12 @@ STATIC const mp_arg_t network_server_args[] = { { MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t network_server_new (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +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) { // parse args + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(args), network_server_args, args); + mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), network_server_args, args); // check the server id 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, self->base.type = &network_server_type; network_server_init_helper(self, &args[1]); - return self; + return (mp_obj_t)self; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_new_obj, 0, network_server_new); STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args @@ -152,7 +153,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan }, #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) - { MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_new_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_type }, #endif }; @@ -169,7 +170,7 @@ STATIC const mp_map_elem_t network_server_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&network_server_init_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&network_server_deinit_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&network_server_timeout_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_running), (mp_obj_t)&network_server_running_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_isrunning), (mp_obj_t)&network_server_running_obj }, }; STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table); @@ -177,6 +178,7 @@ STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_di STATIC const mp_obj_type_t network_server_type = { { &mp_type_type }, .name = MP_QSTR_server, + .make_new = network_server_make_new, .locals_dict = (mp_obj_t)&network_server_locals_dict, }; #endif diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h index b42c69f811..d28c03e29e 100644 --- a/cc3200/qstrdefsport.h +++ b/cc3200/qstrdefsport.h @@ -283,7 +283,7 @@ Q(init) Q(deinit) Q(login) Q(timeout) -Q(running) +Q(isrunning) // for WLAN class Q(WLAN) diff --git a/docs/library/index.rst b/docs/library/index.rst index b53a67ed1c..81a9824efd 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -105,6 +105,7 @@ it will fallback to loading the built-in ``ujson`` module. machine.rst network.rst + wipy.rst .. only:: port_esp8266 diff --git a/docs/library/network.rst b/docs/library/network.rst index cee65491c6..4485ff7e1b 100644 --- a/docs/library/network.rst +++ b/docs/library/network.rst @@ -27,6 +27,40 @@ For example:: data = s.recv(1000) s.close() +.. only:: port_wipy + + .. _network.server: + + class server + ============ + + Constructors + ------------ + + .. class:: server(id, ...) + + Create a server instance, see ``init`` for parameters of initialization. + + Methods + ------- + + .. method:: server.init(\*, login=('micro', 'python'), timeout=300) + + Init (and effectively start the server). Optionally a new ``user``, ``password`` + and ``timeout`` (in seconds) can be passed. + + .. method:: server.deinit() + + Stop the server + + .. method:: server.timeout([timeout_in_seconds]) + + Get or set the server timeout. + + .. method:: server.isrunning() + + Returns ``True`` is the server is running, ``False`` otherwise. + .. only:: port_pyboard class CC3K @@ -178,13 +212,13 @@ For example:: Dump the WIZnet5x00 registers. Useful for debugging. -class WLAN -========== - .. _network.WLAN: .. only:: port_esp8266 + class WLAN + ========== + This class provides a driver for WiFi network processor in the ESP8266. Example usage:: import network @@ -258,6 +292,9 @@ class WLAN .. only:: port_wipy + class WLAN + ========== + This class provides a driver for WiFi network processor in the WiPy. Example usage:: import network @@ -282,7 +319,7 @@ class WLAN Methods ------- - .. method:: init(mode, \*, ssid, security, key, channel, antenna) + .. method:: wlan.init(mode, \*, ssid, security, key, channel, antenna) Set or get the WiFi network processor configuration. diff --git a/docs/library/wipy.rst b/docs/library/wipy.rst new file mode 100644 index 0000000000..66aecd0530 --- /dev/null +++ b/docs/library/wipy.rst @@ -0,0 +1,15 @@ +:mod:`wipy` -- WiPy specific features +===================================== + +.. module:: wipy + :synopsis: WiPy specific features + +The ``wipy`` module contains functions to control specific features of the +WiPy, such as the heartbeat LED. + +Functions +--------- + +.. function:: heartbeat([enable]) + + Get or set the state (enabled or disabled) of the heartbeat LED. diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst index b1f78da529..528dd4c196 100644 --- a/docs/wipy/general.rst +++ b/docs/wipy/general.rst @@ -119,9 +119,10 @@ The heart beat LED ------------------ By default the heart beat LED flashes once every 4s to signal that the system is -alive. This can be overridden through the HeartBeat class: +alive. This can be overridden through the :mod:`wipy` module:: -``machine.HeartBeat().disable()`` + import wipy + wipy.heartbeat(False) There are currently 2 kinds of errors that you might see: diff --git a/docs/wipy/quickref.rst b/docs/wipy/quickref.rst index c99671752d..4ecffffe38 100644 --- a/docs/wipy/quickref.rst +++ b/docs/wipy/quickref.rst @@ -10,7 +10,7 @@ Quick reference for the WiPy General board control (including sleep modes) --------------------------------------------- -See :mod:`machine`. :: +See the :mod:`machine` module:: import machine @@ -198,14 +198,26 @@ See :ref:`network.WLAN ` and :mod:`machine`. :: machine.sleep() # now, connect to the FTP or the Telnet server and the WiPy will wake-up -Heart beat LED --------------- +Telnet and FTP server +--------------------- -See :ref:`machine.HeartBeat `. :: +See :ref:`network.server ` :: - from machine import HeartBeat + from network import network - # disable the heart beat indication (you are free to use this LED connected to GP25) - HeartBeat().disable() - # enable the heart beat again - HeartBeat().enable() + # init with new user, pass word and seconds timeout + server = server.init(login=('user', 'password'), timeout=60) + server.timeout(300) # change the timeout + server.timeout() # get the timeout + server.isrunning() # check wether the server is running or not + +HeartBeat LED +------------- + +See :mod:`wipy`. :: + + import wipy + + wipy.heartbeat(False) # disable the heartbeat LED + wipy.heartbeat(True) # enable the heartbeat LED + wipy.heartbeat() # get the heartbeat state diff --git a/tests/wipy/wlan/server.py b/tests/wipy/wlan/server.py index 07dc26f504..c474de6270 100644 --- a/tests/wipy/wlan/server.py +++ b/tests/wipy/wlan/server.py @@ -12,18 +12,18 @@ if not 'LaunchPad' in mch and not'WiPy' in mch: server = network.server() print(server.timeout() == 300) -print(server.running() == True) +print(server.isrunning() == True) server.deinit() -print(server.running() == False) +print(server.isrunning() == False) server.init(login=('test-user', 'test-password'), timeout=60) -print(server.running() == True) +print(server.isrunning() == True) print(server.timeout() == 60) server.deinit() -print(server.running() == False) +print(server.isrunning() == False) server.init() -print(server.running() == True) +print(server.isrunning() == True) try: server.init(1)