1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "py/builtin.h"
6 #include "py/mperrno.h"
7 #include "py/obj.h"
8 #include "py/runtime.h"
9 #include "ulog/ulog.h"
10
11 #define LOG_TAG "MOD_TCP"
12
13 // this is the actual C-structure for our new object
14 typedef struct {
15 // base represents some basic information, like type
16 mp_obj_base_t Base;
17 // a member created by us
18 char *ModuleName;
19 } mp_tcp_obj_t;
20
obj_createSocket(size_t n_args,const mp_obj_t * args)21 STATIC mp_obj_t obj_createSocket(size_t n_args, const mp_obj_t *args)
22 {
23 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
24 int ret = -1;
25 void *instance = NULL;
26 if (n_args < 5) {
27 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__,
28 n_args);
29 return mp_const_none;
30 }
31 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
32 mp_tcp_obj_t *driver_obj = (mp_tcp_obj_t *)self;
33 if (driver_obj == NULL) {
34 LOGE(LOG_TAG, "driver_obj is NULL\n");
35 return mp_const_none;
36 }
37 LOGD(LOG_TAG, "%s:out\n", __func__);
38
39 return mp_const_none;
40 }
41 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(mp_obj_tcp_createSocket, 5,
42 obj_createSocket);
43
obj_send(size_t n_args,const mp_obj_t * args)44 STATIC mp_obj_t obj_send(size_t n_args, const mp_obj_t *args)
45 {
46 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
47 int ret = -1;
48 void *instance = NULL;
49 if (n_args < 5) {
50 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__,
51 n_args);
52 return mp_const_none;
53 }
54 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
55 mp_tcp_obj_t *driver_obj = (mp_tcp_obj_t *)self;
56 if (driver_obj == NULL) {
57 LOGE(LOG_TAG, "driver_obj is NULL\n");
58 return mp_const_none;
59 }
60 LOGD(LOG_TAG, "%s:out\n", __func__);
61
62 return mp_const_none;
63 }
64 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(mp_obj_tcp_send, 5, obj_send);
65
obj_recv(size_t n_args,const mp_obj_t * args)66 STATIC mp_obj_t obj_recv(size_t n_args, const mp_obj_t *args)
67 {
68 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
69 int ret = -1;
70 void *instance = NULL;
71 if (n_args < 5) {
72 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__,
73 n_args);
74 return mp_const_none;
75 }
76 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
77 mp_tcp_obj_t *driver_obj = (mp_tcp_obj_t *)self;
78 if (driver_obj == NULL) {
79 LOGE(LOG_TAG, "driver_obj is NULL\n");
80 return mp_const_none;
81 }
82 LOGD(LOG_TAG, "%s:out\n", __func__);
83
84 return mp_const_none;
85 }
86 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(mp_obj_tcp_recv, 5, obj_recv);
87
88 STATIC const mp_rom_map_elem_t tcp_module_globals_table[] = {
89 { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tcp) },
90 { MP_OBJ_NEW_QSTR(MP_QSTR_createSocket),
91 MP_ROM_PTR(&mp_obj_tcp_createSocket) },
92 { MP_OBJ_NEW_QSTR(MP_QSTR_send), MP_ROM_PTR(&mp_obj_tcp_send) },
93 { MP_OBJ_NEW_QSTR(MP_QSTR_recv), MP_ROM_PTR(&mp_obj_tcp_recv) },
94 };
95
96 STATIC MP_DEFINE_CONST_DICT(tcp_module_globals, tcp_module_globals_table);
97
98 const mp_obj_module_t tcp_module = {
99 .base = { &mp_type_module },
100 .globals = (mp_obj_dict_t *)&tcp_module_globals,
101 };
102