28#define PYOBJECT_NULL_STRING PyString_FromStringAndSize("", 0)
32 T obj_ptr = (T)PyCapsule_GetPointer(pyobj, type_ptr.c_str());
33 if (obj_ptr ==
nullptr) {
34 AERROR <<
"PyObjectToPtr failed,type->" << type_ptr <<
"pyobj: " << pyobj;
40 uint64_t nanoseconds = 0;
41 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"K:cyber_new_PyTime"),
43 AERROR <<
"cyber_new_PyTime parsetuple failed!";
49 return PyCapsule_New(pytime,
"apollo_cybertron_pytime",
nullptr);
53 PyObject* pyobj_time =
nullptr;
54 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_delete_PyTime"),
60 auto* pytime =
reinterpret_cast<PyTime*
>(
61 PyCapsule_GetPointer(pyobj_time,
"apollo_cybertron_pytime"));
62 if (
nullptr == pytime) {
63 AERROR <<
"cyber_delete_PyTime:time ptr is null!";
73 PyObject* pyobj_time =
nullptr;
74 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_PyTime_to_sec"),
76 AERROR <<
"cyber_PyTime_to_sec:PyArg_ParseTuple failed!";
77 return PyFloat_FromDouble(0);
80 auto* pytime =
reinterpret_cast<PyTime*
>(
81 PyCapsule_GetPointer(pyobj_time,
"apollo_cybertron_pytime"));
82 if (
nullptr == pytime) {
83 AERROR <<
"cyber_PyTime_to_sec ptr is null!";
84 return PyFloat_FromDouble(0);
87 double num = pytime->to_sec();
88 return PyFloat_FromDouble(num);
92 PyObject* pyobj_time =
nullptr;
93 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_PyTime_to_nsec"),
95 AERROR <<
"cyber_PyTime_to_nsec:PyArg_ParseTuple failed!";
96 return PyLong_FromUnsignedLongLong(0);
99 auto* pytime =
reinterpret_cast<PyTime*
>(
100 PyCapsule_GetPointer(pyobj_time,
"apollo_cybertron_pytime"));
101 if (
nullptr == pytime) {
102 AERROR <<
"cyber_PyTime_to_nsec ptr is null!";
103 return PyLong_FromUnsignedLongLong(0);
106 uint64_t num = pytime->to_nsec();
107 return PyLong_FromUnsignedLongLong(num);
111 PyObject* pyobj_time =
nullptr;
112 uint64_t nanoseconds = 0;
113 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"OK:cyber_PyTime_sleep_until"),
114 &pyobj_time, &nanoseconds)) {
115 AERROR <<
"cyber_PyTime_sleep_until:PyArg_ParseTuple failed!";
120 auto* pytime =
reinterpret_cast<PyTime*
>(
121 PyCapsule_GetPointer(pyobj_time,
"apollo_cybertron_pytime"));
122 if (
nullptr == pytime) {
123 AERROR <<
"cyber_PyTime_sleep_until ptr is null!";
128 pytime->sleep_until(nanoseconds);
135 return PyLong_FromUnsignedLongLong(now.
to_nsec());
140 return PyLong_FromUnsignedLongLong(mono_time.
to_nsec());
145 uint64_t nanoseconds = 0;
146 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"L:cyber_new_PyDuration"),
148 AERROR <<
"cyber_new_PyDuration parsetuple failed!";
154 return PyCapsule_New(pyduration,
"apollo_cybertron_pyduration",
nullptr);
158 PyObject* pyobj_duration =
nullptr;
159 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_delete_PyDuration"),
165 auto* pyduration =
reinterpret_cast<PyDuration*
>(
166 PyCapsule_GetPointer(pyobj_duration,
"apollo_cybertron_pyduration"));
167 if (
nullptr == pyduration) {
168 AERROR <<
"cyber_delete_PyDuration:pyduration ptr is null!";
178 PyObject* pyobj_duration =
nullptr;
179 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_PyDuration_sleep"),
185 auto* pyduration =
reinterpret_cast<PyDuration*
>(
186 PyCapsule_GetPointer(pyobj_duration,
"apollo_cybertron_pyduration"));
187 if (
nullptr == pyduration) {
188 AERROR <<
"cyber_PyDuration_sleep:pyduration ptr is null!";
199 uint64_t nanoseconds = 0;
200 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"L:cyber_new_PyRate"),
202 AERROR <<
"cyber_new_PyRate parsetuple failed!";
208 return PyCapsule_New(pyrate,
"apollo_cybertron_pyrate",
nullptr);
212 PyObject* pyobj_rate =
nullptr;
213 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_delete_PyRate"),
219 auto* pyrate =
reinterpret_cast<PyRate*
>(
220 PyCapsule_GetPointer(pyobj_rate,
"apollo_cybertron_pyrate"));
221 if (
nullptr == pyrate) {
222 AERROR <<
"cyber_delete_PyRate:rate ptr is null!";
232 PyObject* pyobj_rate =
nullptr;
233 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_PyRate_sleep"),
239 auto* pyrate =
reinterpret_cast<PyRate*
>(
240 PyCapsule_GetPointer(pyobj_rate,
"apollo_cybertron_pyrate"));
241 if (
nullptr == pyrate) {
242 AERROR <<
"cyber_PyRate_sleep:rate ptr is null!";
252 PyObject* pyobj_rate =
nullptr;
253 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"O:cyber_PyRate_reset"),
259 auto* pyrate =
reinterpret_cast<PyRate*
>(
260 PyCapsule_GetPointer(pyobj_rate,
"apollo_cybertron_pyrate"));
261 if (
nullptr == pyrate) {
262 AERROR <<
"cyber_PyRate_reset:rate ptr is null!";
272 PyObject* pyobj_rate =
nullptr;
273 if (!PyArg_ParseTuple(args,
274 const_cast<char*
>(
"O:cyber_PyRate_get_cycle_time"),
276 return PyLong_FromUnsignedLongLong(0);
279 auto* pyrate =
reinterpret_cast<PyRate*
>(
280 PyCapsule_GetPointer(pyobj_rate,
"apollo_cybertron_pyrate"));
281 if (
nullptr == pyrate) {
282 AERROR <<
"cyber_PyRate_get_cycle_time:rate ptr is null!";
283 return PyLong_FromUnsignedLongLong(0);
285 uint64_t ctime = pyrate->get_cycle_time();
286 return PyLong_FromUnsignedLongLong(ctime);
290 PyObject* pyobj_rate =
nullptr;
291 if (!PyArg_ParseTuple(
292 args,
const_cast<char*
>(
"O:cyber_PyRate_get_expected_cycle_time"),
294 return PyLong_FromUnsignedLongLong(0);
297 auto* pyrate =
reinterpret_cast<PyRate*
>(
298 PyCapsule_GetPointer(pyobj_rate,
"apollo_cybertron_pyrate"));
299 if (
nullptr == pyrate) {
300 AERROR <<
"cyber_PyRate_get_expected_cycle_time:rate ptr is null!";
301 return PyLong_FromUnsignedLongLong(0);
303 uint64_t exp_cycle_time = pyrate->get_expected_cycle_time();
304 return PyLong_FromUnsignedLongLong(exp_cycle_time);
307static PyMethodDef _cyber_time_methods[] = {
331 {
nullptr,
nullptr, 0,
nullptr}
336 static struct PyModuleDef module_def = {
337 PyModuleDef_HEAD_INIT,
338 "_cyber_time_wrapper",
348 return PyModule_Create(&module_def);
static PyTime mono_time()
PyObject * cyber_delete_PyTime(PyObject *self, PyObject *args)
PyMODINIT_FUNC PyInit__cyber_time_wrapper(void)
Init function of this module
PyObject * cyber_PyTime_to_nsec(PyObject *self, PyObject *args)
PyObject * cyber_PyRate_get_expected_cycle_time(PyObject *self, PyObject *args)
PyObject * cyber_PyTime_mono_time(PyObject *self, PyObject *args)
PyObject * cyber_new_PyRate(PyObject *self, PyObject *args)
PyObject * cyber_new_PyTime(PyObject *self, PyObject *args)
PyObject * cyber_delete_PyRate(PyObject *self, PyObject *args)
PyObject * cyber_PyTime_now(PyObject *self, PyObject *args)
PyObject * cyber_PyDuration_sleep(PyObject *self, PyObject *args)
T PyObjectToPtr(PyObject *pyobj, const std::string &type_ptr)
PyObject * cyber_PyTime_to_sec(PyObject *self, PyObject *args)
PyObject * cyber_delete_PyDuration(PyObject *self, PyObject *args)
PyObject * cyber_PyRate_sleep(PyObject *self, PyObject *args)
PyObject * cyber_new_PyDuration(PyObject *self, PyObject *args)
PyObject * cyber_PyRate_reset(PyObject *self, PyObject *args)
PyObject * cyber_PyTime_sleep_until(PyObject *self, PyObject *args)
PyObject * cyber_PyRate_get_cycle_time(PyObject *self, PyObject *args)