Skip to content

Commit a6b3bdb

Browse files
add get_imei()
1 parent 5ef2dc7 commit a6b3bdb

3 files changed

Lines changed: 68 additions & 9 deletions

File tree

include/methods.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extern "C"
102102
PyObject* meth_get_accessory_firmware_version(PyObject* self, PyObject* args);
103103
PyObject* meth_set_safe_boot_mode(PyObject* self, PyObject* args);
104104
PyObject* meth_get_device_name(PyObject* self, PyObject* args); // icsneoGetDeviceName
105+
PyObject* meth_get_imei(PyObject* self, PyObject* args); // icsneoGetIMEI
105106

106107
#ifdef _cplusplus
107108
}
@@ -114,11 +115,11 @@ extern "C"
114115
flags, \
115116
"\n.. note:: Compatibility Function: Identical to PEP8 compliant :func:`" MODULE_NAME "." name \
116117
"` method.\n\n" }, \
117-
{ icsname_no_icsneo, \
118-
(PyCFunction)meth, \
119-
flags, \
120-
"\n.. note:: Compatibility Function: Identical to PEP8 compliant :func:`" MODULE_NAME "." name \
121-
"` method.\n\n" }
118+
{ \
119+
icsname_no_icsneo, (PyCFunction)meth, flags, \
120+
"\n.. note:: Compatibility Function: Identical to PEP8 compliant :func:`" MODULE_NAME "." name \
121+
"` method.\n\n" \
122+
}
122123

123124
#define _DOC_FIND_DEVICES \
124125
MODULE_NAME ".find_devices(device_type=" MODULE_NAME ".NEODEVICE_ALL)\n" \
@@ -1943,6 +1944,21 @@ extern "C"
19431944
"\tstr\n" \
19441945
"\n"
19451946

1947+
#define _DOC_GET_IMEI \
1948+
MODULE_NAME ".get_imei(device) -> int\n" \
1949+
"\n" \
1950+
"Gets the unique 15 digit IMEI from the device. raises RuntimeError if not supported.\n" \
1951+
"\n" \
1952+
"Args:\n" \
1953+
"\tdevice (:class:`" MODULE_NAME ".PyNeoDeviceEx`): :class:`" MODULE_NAME ".PyNeoDeviceEx`\n\n" \
1954+
"\n" \
1955+
"Raises:\n" \
1956+
"\t:class:`" MODULE_NAME ".RuntimeError`\n" \
1957+
"\n" \
1958+
"Returns:\n" \
1959+
"\tint\n" \
1960+
"\n"
1961+
19461962
extern PyMethodDef IcsMethods[];
19471963

19481964
#endif // _METHODS_H_

src/ics/py_neo_device_ex.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,8 @@ def flash_devices(self, *args, **kwargs):
493493

494494
def get_device_name(self, *args, **kwargs):
495495
"see ics.get_device_name for details on arguments."
496-
return ics.get_device_name(self, *args, **kwargs)
496+
return ics.get_device_name(self, *args, **kwargs)
497+
498+
def get_imei(self, *args, **kwargs):
499+
"see ics.get_imei for details on arguments."
500+
return ics.get_imei(self, *args, **kwargs)

src/methods.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ PyMethodDef IcsMethods[] = {
608608
meth_get_device_name,
609609
METH_VARARGS,
610610
_DOC_GET_DEVICE_NAME),
611+
_EZ_ICS_STRUCT_METHOD("get_imei",
612+
"icsneoGetIMEI",
613+
"GetIMEI",
614+
meth_get_imei,
615+
METH_VARARGS,
616+
_DOC_GET_IMEI),
611617

612618
{ "override_library_name", (PyCFunction)meth_override_library_name, METH_VARARGS, _DOC_OVERRIDE_LIBRARY_NAME },
613619
{ "get_library_path", (PyCFunction)meth_get_library_path, METH_NOARGS, "" },
@@ -1952,19 +1958,19 @@ PyObject* meth_get_error_messages(PyObject* self, PyObject* args)
19521958
int description_short_length = 255;
19531959
int description_long_length = 255;
19541960
int severity = 0, restart_needed = 0;
1955-
auto gil = PyAllowThreads();
1961+
auto gil2 = PyAllowThreads();
19561962
if (!icsneoGetErrorInfo(errors[i],
19571963
description_short,
19581964
description_long,
19591965
&description_short_length,
19601966
&description_long_length,
19611967
&severity,
19621968
&restart_needed)) {
1963-
gil.restore();
1969+
gil2.restore();
19641970
Py_XDECREF(list);
19651971
return set_ics_exception(exception_runtime_error(), "icsneoGetErrorInfo() Failed");
19661972
}
1967-
gil.restore();
1973+
gil2.restore();
19681974
PyObject* tuple = Py_BuildValue(
19691975
"i, s, s, i, i", errors[i], description_short, description_long, severity, restart_needed);
19701976

@@ -5445,3 +5451,36 @@ PyObject* meth_get_device_name(PyObject* self, PyObject* args) // icsneoGetDevic
54455451
return set_ics_exception(exception_runtime_error(), (char*)ex.what());
54465452
}
54475453
}
5454+
5455+
PyObject* meth_get_imei(PyObject* self, PyObject* args) { // icsneoGetIMEI
5456+
(void)self;
5457+
PyObject* obj = NULL;
5458+
if (!PyArg_ParseTuple(args, arg_parse("O:", __FUNCTION__), &obj)) {
5459+
return NULL;
5460+
}
5461+
if (!PyNeoDeviceEx_CheckExact(obj)) {
5462+
return set_ics_exception(exception_runtime_error(), "Argument must be of type " MODULE_NAME ".PyNeoDeviceEx");
5463+
}
5464+
void* handle = NULL;
5465+
if (!PyNeoDeviceEx_GetHandle(obj, &handle)) {
5466+
return NULL;
5467+
}
5468+
try {
5469+
ice::Library* lib = dll_get_library();
5470+
if (!lib) {
5471+
char buffer[512];
5472+
return set_ics_exception(exception_runtime_error(), dll_get_error(buffer));
5473+
}
5474+
uint64_t imei = 0;
5475+
ice::Function<int __stdcall(void*, uint64_t*)> icsneoGetIMEI(lib, "icsneoGetIMEI");
5476+
auto gil = PyAllowThreads();
5477+
if (!icsneoGetIMEI(handle, &imei)) {
5478+
gil.restore();
5479+
return set_ics_exception(exception_runtime_error(), "icsneoGetIMEI() Failed");
5480+
}
5481+
gil.restore();
5482+
return Py_BuildValue("K", imei);
5483+
} catch (ice::Exception& ex) {
5484+
return set_ics_exception(exception_runtime_error(), (char*)ex.what());
5485+
}
5486+
}

0 commit comments

Comments
 (0)