Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can_capnp_to_list: direct capnp to vector<CanData> conversion #34303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opendbc_repo
29 changes: 17 additions & 12 deletions selfdrive/pandad/pandad_api_impl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from cython.operator cimport dereference as deref, preincrement as preinc
from libcpp.vector cimport vector
from libcpp.string cimport string
from libcpp cimport bool
from libc.stdint cimport uint8_t, uint32_t, uint64_t
from libc.stdint cimport uint8_t, uint32_t, uint64_t, uintptr_t

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


cdef class ParsedCanData:
cdef vector[CanData] *data

def __cinit__(self):
self.data = new vector[CanData]()

def __dealloc__(self):
del self.data

def get_data_pointer(self):
return <uintptr_t> self.data


def can_capnp_to_list(strings, msgtype='can'):
cdef vector[CanData] data
can_capnp_to_can_list_cpp(strings, data, msgtype == 'sendcan')

result = []
cdef CanData *d
cdef vector[CanData].iterator it = data.begin()
while it != data.end():
d = &deref(it)
frames = [(f.address, (<char *>&f.dat[0])[:f.dat.size()], f.src) for f in d.frames]
result.append((d.nanos, frames))
preinc(it)
cdef ParsedCanData result = ParsedCanData()
can_capnp_to_can_list_cpp(strings, result.data[0], msgtype == 'sendcan')
return result
Loading