optimize CAN send over SPI (#2266)

* profiling

* lil faster

* chunking happens later

* little better

* prealloc is no bueno?

* cleanup

* fix usb tests

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2025-09-02 19:26:52 -07:00
committed by GitHub
parent 819fa5854e
commit 5c1ff7bfa3
6 changed files with 35 additions and 22 deletions

View File

@@ -78,17 +78,17 @@ class TestPandaComms(unittest.TestCase):
def test_comms_reset_tx(self):
# store some test messages in the queue
test_msg = (0x100, b"test", 0)
packed = pack_can_buffer([test_msg for _ in range(100)])
packed = pack_can_buffer([test_msg for _ in range(100)], chunk=True)
# write a small chunk such that we have some overflow
TINY_CHUNK_SIZE = 6
lpp.comms_can_write(packed[0][:TINY_CHUNK_SIZE], TINY_CHUNK_SIZE)
lpp.comms_can_write(bytes(packed[0][:TINY_CHUNK_SIZE]), TINY_CHUNK_SIZE)
# reset the comms to clear the overflow buffer on the panda side
lpp.comms_can_reset()
# write a full valid chunk, which should now contain valid messages
lpp.comms_can_write(packed[1], len(packed[1]))
lpp.comms_can_write(bytes(packed[1]), len(packed[1]))
# read the messages from the queue and make sure they're valid
queue_msgs = []
@@ -114,7 +114,7 @@ class TestPandaComms(unittest.TestCase):
for buf in packed:
for i in range(0, len(buf), CHUNK_SIZE):
chunk_len = min(CHUNK_SIZE, len(buf) - i)
lpp.comms_can_write(buf[i:i+chunk_len], chunk_len)
lpp.comms_can_write(bytes(buf[i:i+chunk_len]), chunk_len)
# Check that they ended up in the right buffers
queue_msgs = []