From 06b8f1042ba2408981a6095b35394d6300bfa0e0 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 27 Jan 2021 00:10:53 +0800 Subject: [PATCH] Panda: add can_send buffer caching (#19910) old-commit-hash: 5c58a2618eed043bca9e1b5a2b8303756663cca1 --- selfdrive/boardd/panda.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/selfdrive/boardd/panda.cc b/selfdrive/boardd/panda.cc index 50065cda8e..f2ff6d97e9 100644 --- a/selfdrive/boardd/panda.cc +++ b/selfdrive/boardd/panda.cc @@ -1,7 +1,7 @@ #include #include #include - +#include #include #include "common/swaglog.h" @@ -303,9 +303,10 @@ void Panda::send_heartbeat(){ } void Panda::can_send(capnp::List::Reader can_data_list){ - int msg_count = can_data_list.size(); + static std::vector send; + const int msg_count = can_data_list.size(); - uint32_t *send = new uint32_t[msg_count*0x10](); + send.resize(msg_count*0x10); for (int i = 0; i < msg_count; i++) { auto cmsg = can_data_list[i]; @@ -320,9 +321,7 @@ void Panda::can_send(capnp::List::Reader can_data_list){ memcpy(&send[i*4+2], can_data.begin(), can_data.size()); } - usb_bulk_write(3, (unsigned char*)send, msg_count*0x10, 5); - - delete[] send; + usb_bulk_write(3, (unsigned char*)send.data(), send.size(), 5); } int Panda::can_receive(kj::Array& out_buf) {