diff --git a/selfdrive/boardd/panda.cc b/selfdrive/boardd/panda.cc index c72854a8d4..78b123f698 100644 --- a/selfdrive/boardd/panda.cc +++ b/selfdrive/boardd/panda.cc @@ -433,15 +433,15 @@ bool Panda::can_receive(std::vector& out_vec) { static uint8_t tail[CANPACKET_MAX_SIZE]; uint8_t tail_size = 0; uint8_t counter = 0; - for (int i = 0; i < recv; i += 64) { + for (int i = 0; i < recv; i += USBPACKET_MAX_SIZE) { // Check for counter every 64 bytes (length of USB packet) if (counter != data[i]) { LOGE("CAN: MALFORMED USB RECV PACKET"); break; } counter++; - uint8_t chunk_len = ((recv - i) > 64) ? 63 : (recv - i - 1); // as 1 is always reserved for counter - uint8_t chunk[CANPACKET_MAX_SIZE]; + uint8_t chunk_len = ((recv - i) > USBPACKET_MAX_SIZE) ? 63 : (recv - i - 1); // as 1 is always reserved for counter + uint8_t chunk[USBPACKET_MAX_SIZE + CANPACKET_MAX_SIZE]; memcpy(chunk, tail, tail_size); memcpy(&chunk[tail_size], &data[i+1], chunk_len); chunk_len += tail_size; diff --git a/selfdrive/boardd/panda.h b/selfdrive/boardd/panda.h index 415bb30103..4be9454cf5 100644 --- a/selfdrive/boardd/panda.h +++ b/selfdrive/boardd/panda.h @@ -17,6 +17,7 @@ #define PANDA_BUS_CNT 4 #define RECV_SIZE (0x4000U) #define USB_TX_SOFT_LIMIT (0x100U) +#define USBPACKET_MAX_SIZE (0x40U) #define CANPACKET_HEAD_SIZE 5U #define CANPACKET_MAX_SIZE 72U #define CANPACKET_REJECTED (0xC0U)