  
  #include "cereal/messaging/messaging.h"
  #include "selfdrive/common/gpio.h"
  #include "selfdrive/common/swaglog.h"
  #include "selfdrive/common/util.h"
  
 
</s> remove #define RECV_SIZE (0x1000)
 </s> add #define RECV_SIZE (0x4000) </s> remove   std::vector<uint32_t> send;
 </s> add   std::vector<uint8_t> send; </s> remove     // add to vector
    out_vec.push_back(canData);
 </s> add   static uint8_t tail[72];
  uint8_t tail_size = 0;
  uint8_t counter = 0;
  for (int i = 0; i < recv; i += 64) {
    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[72];
    memcpy(chunk, tail, tail_size);
    memcpy(&chunk[tail_size], &data[i+1], chunk_len);
    chunk_len += tail_size;
    tail_size = 0;
    uint8_t pos = 0;
    while (pos < chunk_len) {
      uint8_t data_len = dlc_to_len[(chunk[pos] >> 4)];
      uint8_t pckt_len = CANPACKET_HEAD_SIZE + data_len;
      if (pckt_len <= (chunk_len - pos)) {
        can_frame canData;
        canData.busTime = 0;
        canData.address = (*(uint32_t*)&chunk[pos+1]) >> 3;
        canData.src = (chunk[pos] >> 1) & 0x7;

        bool rejected = chunk[pos+1] & 0x1;
        bool returned = (chunk[pos+1] >> 1) & 0x1;
        if (rejected) { canData.src += CANPACKET_REJECTED; }
        if (returned) { canData.src += CANPACKET_RETURNED; }
        canData.dat.assign((char*)&chunk[pos+5], data_len);

        pos += pckt_len;

        // add to vector
        out_vec.push_back(canData);
      } else {
        tail_size = (chunk_len - pos);
        memcpy(tail, &chunk[pos], tail_size);
        break;
      }
    }
#include "panda/board/dlc_to_len.h"
  
  #include "cereal/messaging/messaging.h"
#include "panda/board/dlc_to_len.h"
  #include "selfdrive/common/gpio.h"
  #include "selfdrive/common/swaglog.h"
  #include "selfdrive/common/util.h"
  
keep add keep keep keep keep
 New usb protocol for panda (#22752)

* first try

* move dlc_to_len

* panda switch to mailbox branch

* add bitstruct to pipfile

* bump panda and remove bitstruct

* few cleanups and fixes

* sanity check data.size == dlc_to_len

* check problem with test

* Revert "check problem with test"

This reverts commit b4855b7c12188d36d5d510e729344dab2cf21be9.

* clean

* revert Pipfile.lock

* that was an issue???

* fix crash

* ...

* include dlc_to_len from panda

* alph

* define macros for returned and rejected

* cleanup

* bump panda to current master 
selfdrive/boardd/panda.cc