#include #include #include #include "py/builtin.h" #include "py/mperrno.h" #include "py/obj.h" #include "py/runtime.h" #include "ulog/ulog.h" #define LOG_TAG "DRIVER_LOCATION" extern const mp_obj_type_t driver_location_type; #define LOCATION_JSON_CONFIG_PATH "/data/python/config/location.json" // this is the actual C-structure for our new object typedef struct { // base represents some basic information, like type mp_obj_base_t Base; // a member created by us char *ModuleName; } mp_location_obj_t; void location_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { LOGD(LOG_TAG, "entern %s;\n", __func__); mp_location_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "ModuleName(%s)", self->ModuleName); } 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) { LOGD(LOG_TAG, "entern %s;\n", __func__); mp_location_obj_t *driver_obj = m_new_obj(mp_location_obj_t); if (!driver_obj) { mp_raise_OSError(MP_EINVAL); } driver_obj->Base.type = &driver_location_type; driver_obj->ModuleName = "location"; return MP_OBJ_FROM_PTR(driver_obj); } STATIC mp_obj_t obj_open(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_open, 5, obj_open); STATIC mp_obj_t obj_close(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_close, 5, obj_close); STATIC mp_obj_t obj_accessedWifi(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_accessedWifi, 5, obj_accessedWifi); STATIC mp_obj_t obj_scannedWifi(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_scannedWifi, 5, obj_scannedWifi); STATIC mp_obj_t obj_accessedLbs(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_accessedLbs, 5, obj_accessedLbs); STATIC mp_obj_t obj_nearbts(size_t n_args, const mp_obj_t *args) { LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args); int ret = -1; void *instance = NULL; if (n_args < 5) { LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args); return mp_const_none; } mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_location_obj_t *driver_obj = (mp_location_obj_t *)self; if (driver_obj == NULL) { LOGE(LOG_TAG, "driver_obj is NULL\n"); return mp_const_none; } LOGD(LOG_TAG, "%s:out\n", __func__); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(location_obj_nearbts, 5, obj_nearbts); STATIC const mp_rom_map_elem_t location_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_Location) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&location_obj_open) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&location_obj_close) }, { MP_ROM_QSTR(MP_QSTR_accessedWifi), MP_ROM_PTR(&location_obj_accessedWifi) }, { MP_ROM_QSTR(MP_QSTR_scannedWifi), MP_ROM_PTR(&location_obj_scannedWifi) }, { MP_ROM_QSTR(MP_QSTR_accessedLbs), MP_ROM_PTR(&location_obj_accessedLbs) }, { MP_ROM_QSTR(MP_QSTR_nearbts), MP_ROM_PTR(&location_obj_nearbts) }, }; STATIC MP_DEFINE_CONST_DICT(location_locals_dict, location_locals_dict_table); const mp_obj_type_t driver_location_type = { .base = { &mp_type_type }, .name = MP_QSTR_Location, .print = location_obj_print, .make_new = location_obj_make_new, .locals_dict = (mp_obj_dict_t *)&location_locals_dict, };