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 "DRIVER_LOCATION"
12
13 extern const mp_obj_type_t driver_location_type;
14
15 #define LOCATION_JSON_CONFIG_PATH "/data/python/config/location.json"
16
17 // this is the actual C-structure for our new object
18 typedef struct {
19 // base represents some basic information, like type
20 mp_obj_base_t Base;
21 // a member created by us
22 char *ModuleName;
23 } mp_location_obj_t;
24
location_obj_print(const mp_print_t * print,mp_obj_t self_in,mp_print_kind_t kind)25 void location_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
26 {
27 LOGD(LOG_TAG, "entern %s;\n", __func__);
28 mp_location_obj_t *self = MP_OBJ_TO_PTR(self_in);
29 mp_printf(print, "ModuleName(%s)", self->ModuleName);
30 }
31
location_obj_make_new(const mp_obj_type_t * type,size_t n_args,size_t n_kw,const mp_obj_t * args)32 STATIC mp_obj_t location_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
33 {
34 LOGD(LOG_TAG, "entern %s;\n", __func__);
35 mp_location_obj_t *driver_obj = m_new_obj(mp_location_obj_t);
36 if (!driver_obj) {
37 mp_raise_OSError(MP_EINVAL);
38 }
39
40 driver_obj->Base.type = &driver_location_type;
41 driver_obj->ModuleName = "location";
42
43 return MP_OBJ_FROM_PTR(driver_obj);
44 }
45
obj_open(size_t n_args,const mp_obj_t * args)46 STATIC mp_obj_t obj_open(size_t n_args, const mp_obj_t *args)
47 {
48 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
49 int ret = -1;
50 void *instance = NULL;
51 if (n_args < 5) {
52 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
53 return mp_const_none;
54 }
55 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
56 mp_location_obj_t *driver_obj = (mp_location_obj_t *)self;
57 if (driver_obj == NULL) {
58 LOGE(LOG_TAG, "driver_obj is NULL\n");
59 return mp_const_none;
60 }
61 LOGD(LOG_TAG, "%s:out\n", __func__);
62
63 return mp_const_none;
64 }
65 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_open, 5, obj_open);
66
obj_close(size_t n_args,const mp_obj_t * args)67 STATIC mp_obj_t obj_close(size_t n_args, const mp_obj_t *args)
68 {
69 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
70 int ret = -1;
71 void *instance = NULL;
72 if (n_args < 5) {
73 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, 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_location_obj_t *driver_obj = (mp_location_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(location_obj_close, 5, obj_close);
87
obj_accessedWifi(size_t n_args,const mp_obj_t * args)88 STATIC mp_obj_t obj_accessedWifi(size_t n_args, const mp_obj_t *args)
89 {
90 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
91 int ret = -1;
92 void *instance = NULL;
93 if (n_args < 5) {
94 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
95 return mp_const_none;
96 }
97 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
98 mp_location_obj_t *driver_obj = (mp_location_obj_t *)self;
99 if (driver_obj == NULL) {
100 LOGE(LOG_TAG, "driver_obj is NULL\n");
101 return mp_const_none;
102 }
103 LOGD(LOG_TAG, "%s:out\n", __func__);
104
105 return mp_const_none;
106 }
107 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_accessedWifi, 5, obj_accessedWifi);
108
obj_scannedWifi(size_t n_args,const mp_obj_t * args)109 STATIC mp_obj_t obj_scannedWifi(size_t n_args, const mp_obj_t *args)
110 {
111 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
112 int ret = -1;
113 void *instance = NULL;
114 if (n_args < 5) {
115 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
116 return mp_const_none;
117 }
118 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
119 mp_location_obj_t *driver_obj = (mp_location_obj_t *)self;
120 if (driver_obj == NULL) {
121 LOGE(LOG_TAG, "driver_obj is NULL\n");
122 return mp_const_none;
123 }
124 LOGD(LOG_TAG, "%s:out\n", __func__);
125
126 return mp_const_none;
127 }
128 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_scannedWifi, 5, obj_scannedWifi);
129
obj_accessedLbs(size_t n_args,const mp_obj_t * args)130 STATIC mp_obj_t obj_accessedLbs(size_t n_args, const mp_obj_t *args)
131 {
132 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
133 int ret = -1;
134 void *instance = NULL;
135 if (n_args < 5) {
136 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
137 return mp_const_none;
138 }
139 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
140 mp_location_obj_t *driver_obj = (mp_location_obj_t *)self;
141 if (driver_obj == NULL) {
142 LOGE(LOG_TAG, "driver_obj is NULL\n");
143 return mp_const_none;
144 }
145 LOGD(LOG_TAG, "%s:out\n", __func__);
146
147 return mp_const_none;
148 }
149 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_accessedLbs, 5, obj_accessedLbs);
150
obj_nearbts(size_t n_args,const mp_obj_t * args)151 STATIC mp_obj_t obj_nearbts(size_t n_args, const mp_obj_t *args)
152 {
153 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
154 int ret = -1;
155 void *instance = NULL;
156 if (n_args < 5) {
157 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
158 return mp_const_none;
159 }
160 mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
161 mp_location_obj_t *driver_obj = (mp_location_obj_t *)self;
162 if (driver_obj == NULL) {
163 LOGE(LOG_TAG, "driver_obj is NULL\n");
164 return mp_const_none;
165 }
166 LOGD(LOG_TAG, "%s:out\n", __func__);
167
168 return mp_const_none;
169 }
170 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_nearbts, 5, obj_nearbts);
171
172 STATIC const mp_rom_map_elem_t location_locals_dict_table[] = {
173 { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_Location) },
174 { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&location_obj_open) },
175 { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&location_obj_close) },
176 { MP_ROM_QSTR(MP_QSTR_accessedWifi), MP_ROM_PTR(&location_obj_accessedWifi) },
177 { MP_ROM_QSTR(MP_QSTR_scannedWifi), MP_ROM_PTR(&location_obj_scannedWifi) },
178 { MP_ROM_QSTR(MP_QSTR_accessedLbs), MP_ROM_PTR(&location_obj_accessedLbs) },
179 { MP_ROM_QSTR(MP_QSTR_nearbts), MP_ROM_PTR(&location_obj_nearbts) },
180 };
181
182 STATIC MP_DEFINE_CONST_DICT(location_locals_dict, location_locals_dict_table);
183
184 const mp_obj_type_t driver_location_type = {
185 .base = { &mp_type_type },
186 .name = MP_QSTR_Location,
187 .print = location_obj_print,
188 .make_new = location_obj_make_new,
189 .locals_dict = (mp_obj_dict_t *)&location_locals_dict,
190 };
191