cc3200: Move server methods from WLAN to the network module.
This commit is contained in:
parent
92496abe0f
commit
f8ee88bbe0
|
@ -33,6 +33,7 @@
|
|||
#include MICROPY_HAL_H
|
||||
#include "modnetwork.h"
|
||||
#include "mpexception.h"
|
||||
#include "serverstask.h"
|
||||
|
||||
/// \module network - network configuration
|
||||
///
|
||||
|
@ -68,10 +69,44 @@ STATIC mp_obj_t network_route(void) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);
|
||||
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
STATIC mp_obj_t network_server_start(void) {
|
||||
servers_start();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_start_obj, network_server_start);
|
||||
|
||||
STATIC mp_obj_t network_server_stop(void) {
|
||||
servers_stop();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_stop_obj, network_server_stop);
|
||||
|
||||
STATIC mp_obj_t network_server_enabled(void) {
|
||||
return MP_BOOL(servers_are_enabled());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_enabled_obj, network_server_enabled);
|
||||
|
||||
STATIC mp_obj_t network_server_login(mp_obj_t user, mp_obj_t pass) {
|
||||
const char *_user = mp_obj_str_get_str(user);
|
||||
const char *_pass = mp_obj_str_get_str(pass);
|
||||
servers_set_login ((char *)_user, (char *)_pass);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(network_server_login_obj, network_server_login);
|
||||
#endif
|
||||
|
||||
STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_route), (mp_obj_t)&network_route_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_route), (mp_obj_t)&network_route_obj },
|
||||
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_start_server), (mp_obj_t)&network_server_start_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop_server), (mp_obj_t)&network_server_stop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_server_enabled), (mp_obj_t)&network_server_enabled_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_server_login), (mp_obj_t)&network_server_login_obj },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
|
||||
|
|
|
@ -416,7 +416,7 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
// Stop all other processes using the wlan engine
|
||||
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
|
||||
wlan_stop_servers();
|
||||
servers_stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -514,7 +514,7 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
// Start the servers again
|
||||
if (wlan_obj.servers_enabled) {
|
||||
servers_enable();
|
||||
servers_start();
|
||||
}
|
||||
#endif
|
||||
return MODWLAN_OK;
|
||||
|
@ -534,7 +534,7 @@ void wlan_stop (uint32_t timeout) {
|
|||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
// Stop all other processes using the wlan engine
|
||||
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
|
||||
wlan_stop_servers();
|
||||
servers_stop();
|
||||
}
|
||||
#endif
|
||||
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
|
||||
|
@ -555,15 +555,6 @@ void wlan_get_ip (uint32_t *ip) {
|
|||
}
|
||||
}
|
||||
|
||||
void wlan_stop_servers (void) {
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
servers_disable();
|
||||
do {
|
||||
HAL_Delay (5);
|
||||
} while (servers_are_enabled());
|
||||
#endif
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// DEFINE STATIC FUNCTIONS
|
||||
//*****************************************************************************
|
||||
|
@ -963,33 +954,6 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_callback_obj, 1, wlan_callback);
|
||||
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
STATIC mp_obj_t wlan_serversstart(mp_obj_t self_in) {
|
||||
servers_enable();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_serversstart_obj, wlan_serversstart);
|
||||
|
||||
STATIC mp_obj_t wlan_serversstop(mp_obj_t self_in) {
|
||||
wlan_stop_servers();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_serversstop_obj, wlan_serversstop);
|
||||
|
||||
STATIC mp_obj_t wlan_serversenabled(mp_obj_t self_in) {
|
||||
return MP_BOOL(servers_are_enabled());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_serversenabled_obj, wlan_serversenabled);
|
||||
|
||||
STATIC mp_obj_t wlan_serversuserpass(mp_obj_t self_in, mp_obj_t user, mp_obj_t pass) {
|
||||
const char *_user = mp_obj_str_get_str(user);
|
||||
const char *_pass = mp_obj_str_get_str(pass);
|
||||
servers_set_user_pass((char *)_user, (char *)_pass);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(wlan_serversuserpass_obj, wlan_serversuserpass);
|
||||
#endif
|
||||
|
||||
STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&wlan_connect_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&wlan_scan_obj },
|
||||
|
@ -998,12 +962,6 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
|
|||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&wlan_ifconfig_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_urn), (mp_obj_t)&wlan_urn_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&wlan_callback_obj },
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_start_servers), (mp_obj_t)&wlan_serversstart_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop_servers), (mp_obj_t)&wlan_serversstop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_servers_enabled), (mp_obj_t)&wlan_serversenabled_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_servers_userpass), (mp_obj_t)&wlan_serversuserpass_obj },
|
||||
#endif
|
||||
|
||||
// class constants
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_OPEN), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_OPEN) },
|
||||
|
|
|
@ -60,6 +60,5 @@ extern void wlan_first_start (void);
|
|||
extern void wlan_stop (uint32_t timeout);
|
||||
extern void wlan_get_mac (uint8_t *macAddress);
|
||||
extern void wlan_get_ip (uint32_t *ip);
|
||||
extern void wlan_stop_servers (void);
|
||||
|
||||
#endif /* MODWLAN_H_ */
|
||||
|
|
|
@ -162,7 +162,7 @@ soft_reset:
|
|||
mptask_init_sflash_filesystem();
|
||||
|
||||
// enable telnet and ftp servers
|
||||
servers_enable();
|
||||
servers_start();
|
||||
|
||||
// append the SFLASH paths to the system path
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH));
|
||||
|
|
|
@ -199,6 +199,10 @@ Q(IPPROTO_RAW)
|
|||
// for network class
|
||||
Q(network)
|
||||
Q(route)
|
||||
Q(start_server)
|
||||
Q(stop_server)
|
||||
Q(server_enabled)
|
||||
Q(server_login)
|
||||
|
||||
// for WLAN class
|
||||
Q(WLAN)
|
||||
|
@ -213,10 +217,6 @@ Q(disconnect)
|
|||
Q(channel)
|
||||
Q(ifconfig)
|
||||
Q(urn)
|
||||
Q(start_servers)
|
||||
Q(stop_servers)
|
||||
Q(servers_enabled)
|
||||
Q(servers_userpass)
|
||||
Q(STA)
|
||||
Q(AP)
|
||||
Q(P2P)
|
||||
|
|
|
@ -125,28 +125,31 @@ void TASK_Servers (void *pvParameters) {
|
|||
}
|
||||
}
|
||||
|
||||
void servers_enable (void) {
|
||||
void servers_start (void) {
|
||||
servers_data.do_disable = false;
|
||||
servers_data.do_enable = true;
|
||||
}
|
||||
|
||||
void servers_disable (void) {
|
||||
void servers_stop (void) {
|
||||
servers_data.do_enable = false;
|
||||
servers_data.do_disable = true;
|
||||
do {
|
||||
HAL_Delay (SERVERS_CYCLE_TIME_MS);
|
||||
} while (servers_are_enabled());
|
||||
}
|
||||
|
||||
bool servers_are_enabled (void) {
|
||||
return servers_data.enabled;
|
||||
}
|
||||
|
||||
void servers_close_socket (_i16 *sd) {
|
||||
void servers_close_socket (int16_t *sd) {
|
||||
if (*sd > 0) {
|
||||
sl_Close(*sd);
|
||||
*sd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void servers_set_user_pass (char *user, char *pass) {
|
||||
void servers_set_login (char *user, char *pass) {
|
||||
memcpy(servers_user, user, SERVERS_USER_LEN_MAX);
|
||||
memcpy(servers_pass, pass, SERVERS_PASS_LEN_MAX);
|
||||
}
|
||||
|
|
|
@ -60,10 +60,10 @@ extern char *servers_pass;
|
|||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
extern void TASK_Servers (void *pvParameters);
|
||||
extern void servers_enable (void);
|
||||
extern void servers_disable (void);
|
||||
extern void servers_start (void);
|
||||
extern void servers_stop (void);
|
||||
extern bool servers_are_enabled (void);
|
||||
extern void servers_close_socket (_i16 *sd);
|
||||
extern void servers_set_user_pass (char *user, char *pass);
|
||||
extern void servers_close_socket (int16_t *sd);
|
||||
extern void servers_set_login (char *user, char *pass);
|
||||
|
||||
#endif /* SERVERSTASK_H_ */
|
||||
|
|
Loading…
Reference in New Issue