Skip to content

Commit 9396973

Browse files
committed
direct capnp to vector[CanData] conversion
1 parent 685dc5a commit 9396973

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

selfdrive/pandad/pandad_api_impl.pyx

+17-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from cython.operator cimport dereference as deref, preincrement as preinc
44
from libcpp.vector cimport vector
55
from libcpp.string cimport string
66
from libcpp cimport bool
7-
from libc.stdint cimport uint8_t, uint32_t, uint64_t
7+
from libc.stdint cimport uint8_t, uint32_t, uint64_t, uintptr_t
88

99
cdef extern from "panda.h":
1010
cdef struct can_frame:
@@ -41,16 +41,21 @@ def can_list_to_can_capnp(can_msgs, msgtype='can', valid=True):
4141
can_list_to_can_capnp_cpp(can_list, out, msgtype == 'sendcan', valid)
4242
return out
4343

44+
45+
cdef class ParsedCanData:
46+
cdef vector[CanData] *data
47+
48+
def __cinit__(self):
49+
self.data = new vector[CanData]()
50+
51+
def __dealloc__(self):
52+
del self.data
53+
54+
def get_data_pointer(self):
55+
return <uintptr_t> self.data
56+
57+
4458
def can_capnp_to_list(strings, msgtype='can'):
45-
cdef vector[CanData] data
46-
can_capnp_to_can_list_cpp(strings, data, msgtype == 'sendcan')
47-
48-
result = []
49-
cdef CanData *d
50-
cdef vector[CanData].iterator it = data.begin()
51-
while it != data.end():
52-
d = &deref(it)
53-
frames = [(f.address, (<char *>&f.dat[0])[:f.dat.size()], f.src) for f in d.frames]
54-
result.append((d.nanos, frames))
55-
preinc(it)
59+
cdef ParsedCanData result = ParsedCanData()
60+
can_capnp_to_can_list_cpp(strings, result.data[0], msgtype == 'sendcan')
5661
return result

0 commit comments

Comments
 (0)