From 4c8657fc8cec735cd071b83170be56139bec1fe6 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 6 Apr 2020 16:49:37 -0700 Subject: [PATCH] openpilot support for panda nak (#1324) old-commit-hash: 7ea2524b6fbb89f23d3591ee2c115181af480d5a --- panda | 2 +- selfdrive/boardd/boardd.cc | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/panda b/panda index 51e0a55d6d..5440de0fde 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit 51e0a55d6d5fce5a9edf4178baccd4b2a4e23290 +Subproject commit 5440de0fdee3f04a1b1a15291854d2a183af5f67 diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 78645a46a9..7883fde687 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -568,10 +568,19 @@ void can_send(SubSocket *subscriber) { int sent; pthread_mutex_lock(&usb_lock); + if (!fake_send) { do { - err = libusb_bulk_transfer(dev_handle, 3, (uint8_t*)send, msg_count*0x10, &sent, TIMEOUT); - if (err != 0 || msg_count*0x10 != sent) { handle_usb_issue(err, __func__); } + // Try sending can messages. If the receive buffer on the panda is full it will NAK + // and libusb will try again. After 5ms, it will time out. We will drop the messages. + err = libusb_bulk_transfer(dev_handle, 3, (uint8_t*)send, msg_count*0x10, &sent, 5); + if (err == LIBUSB_ERROR_TIMEOUT) { + LOGW("Transmit buffer full"); + break; + } else if (err != 0 || msg_count*0x10 != sent) { + LOGW("Error"); + handle_usb_issue(err, __func__); + } } while(err != 0); }