|
46 | 46 | #include "ethernet/socket.h" |
47 | 47 | #include "internet/dns/dns.h" |
48 | 48 |
|
| 49 | +/// \module wiznet5k - control WIZnet5x00 Ethernet adaptors |
| 50 | +/// |
| 51 | +/// This module allows you to control WIZnet5x00 Ethernet adaptors based on |
| 52 | +/// the W5200 and W5500 chipsets (only W5200 tested). |
| 53 | +/// |
| 54 | +/// Example usage: |
| 55 | +/// |
| 56 | +/// import wiznet5k |
| 57 | +/// w = wiznet5k.WIZnet5k() |
| 58 | +/// print(w.ipaddr()) |
| 59 | +/// w.gethostbyname('micropython.org') |
| 60 | +/// s = w.socket() |
| 61 | +/// s.connect(('192.168.0.2', 8080)) |
| 62 | +/// s.send('hello') |
| 63 | +/// print(s.recv(10)) |
| 64 | + |
49 | 65 | #define IPADDR_BUF_SIZE (4) |
50 | 66 |
|
51 | 67 | STATIC const mp_obj_type_t wiznet5k_type; |
@@ -157,7 +173,7 @@ STATIC void wiznet5k_print(void (*print)(void *env, const char *fmt, ...), void |
157 | 173 | } |
158 | 174 |
|
159 | 175 | /// \classmethod \constructor() |
160 | | -/// Create and return a wiznet5k object. |
| 176 | +/// Create and return a WIZnet5k object. |
161 | 177 | STATIC mp_obj_t wiznet5k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { |
162 | 178 | // check arguments |
163 | 179 | mp_arg_check_num(n_args, n_kw, 0, 0, false); |
@@ -277,6 +293,8 @@ STATIC mp_obj_t wiznet5k_ipaddr(mp_uint_t n_args, const mp_obj_t *args) { |
277 | 293 | } |
278 | 294 | STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ipaddr_obj, 1, 2, wiznet5k_ipaddr); |
279 | 295 |
|
| 296 | +/// \method socket(family=AF_INET, type=SOCK_STREAM, fileno=-1) |
| 297 | +/// Create a socket. |
280 | 298 | STATIC const mp_arg_t wiznet5k_socket_args[] = { |
281 | 299 | { MP_QSTR_family, MP_ARG_INT, {.u_int = 0} }, // ignored, only AF_INET supported |
282 | 300 | { MP_QSTR_type, MP_ARG_INT, {.u_int = Sn_MR_TCP} }, // SOCK_STREAM or SOCK_DGRAM |
@@ -307,6 +325,8 @@ STATIC mp_obj_t wiznet5k_socket(mp_uint_t n_args, const mp_obj_t *args, mp_map_t |
307 | 325 | } |
308 | 326 | STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wiznet5k_socket_obj, 1, wiznet5k_socket); |
309 | 327 |
|
| 328 | +/// \method gethostbyname(name) |
| 329 | +/// Use DNS to lookup a host name. Returns an IP address. |
310 | 330 | STATIC mp_obj_t wiznet5k_gethostbyname(mp_obj_t self_in, mp_obj_t name_in) { |
311 | 331 | uint8_t dns_ip[IPADDR_BUF_SIZE] = {8, 8, 8, 8}; |
312 | 332 | const char *name = mp_obj_str_get_str(name_in); |
|
0 commit comments