mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
Fix bulk transfer dropping messages sometimes (#729)
* fix max messages per bulk transfer * retry on partial send * need 2x the packet size for some reason * improve bulk write test
This commit is contained in:
@@ -236,7 +236,8 @@ void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) {
|
||||
}
|
||||
|
||||
void usb_cb_ep3_out_complete(void) {
|
||||
if (can_tx_check_min_slots_free(MAX_CAN_MSGS_PER_BULK_TRANSFER)) {
|
||||
// TODO: how does a second USB packet sneek in? (why multiply by 2)
|
||||
if (can_tx_check_min_slots_free(MAX_CAN_MSGS_PER_BULK_TRANSFER * 2U)) {
|
||||
usb_outep3_resume_if_paused();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,7 +533,13 @@ class Panda(object):
|
||||
for s in snds:
|
||||
self._handle.bulkWrite(3, s)
|
||||
else:
|
||||
self._handle.bulkWrite(3, b''.join(snds), timeout=timeout)
|
||||
dat = b''.join(snds)
|
||||
while True:
|
||||
bs = self._handle.bulkWrite(3, dat, timeout=timeout)
|
||||
dat = dat[bs:]
|
||||
if len(dat) == 0:
|
||||
break
|
||||
print("CAN: PARTIAL SEND MANY, RETRYING")
|
||||
break
|
||||
except (usb1.USBErrorIO, usb1.USBErrorOverflow):
|
||||
print("CAN: BAD SEND MANY, RETRYING")
|
||||
|
||||
@@ -214,8 +214,12 @@ def test_bulk_write(p):
|
||||
|
||||
def flood_tx(panda):
|
||||
print('Sending!')
|
||||
msg = b"\xaa" * 4
|
||||
packet = [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS
|
||||
msg = b"\xaa" * 8
|
||||
packet = []
|
||||
# start with many messages on a single bus (higher contention for single TX ring buffer)
|
||||
packet += [[0xaa, None, msg, 0]] * NUM_MESSAGES_PER_BUS
|
||||
# end with many messages on multiple buses
|
||||
packet += [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS
|
||||
|
||||
# Disable timeout
|
||||
panda.can_send_many(packet, timeout=0)
|
||||
@@ -241,7 +245,7 @@ def test_bulk_write(p):
|
||||
print(f"Received {len(rx)} messages")
|
||||
|
||||
# All messages should have been received
|
||||
if len(rx) != 3 * NUM_MESSAGES_PER_BUS:
|
||||
if len(rx) != 4 * NUM_MESSAGES_PER_BUS:
|
||||
Exception("Did not receive all messages!")
|
||||
|
||||
# Set back to silent mode
|
||||
|
||||
Reference in New Issue
Block a user