Added VisionIpcBufExtra properties to python VisionIpcClient (#479)

* Added VisionIpcBufExtra properties to python VisionIpcClient

* Check frame_id in test_send_single_buffer
This commit is contained in:
Mitchell Goff 2023-06-20 16:55:51 -07:00 committed by GitHub
parent 662206899d
commit 96626cae1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View File

@ -60,3 +60,39 @@ class TestVisionIpc(unittest.TestCase):
recv_buf = client.recv()
self.assertIsNot(recv_buf, None)
self.assertEqual(recv_buf.view('<i4')[0], 1234)
self.assertEqual(client.frame_id, 1337)
def test_no_conflate(self):
self.create_vipc_server("camerad", VisionStreamType.VISION_STREAM_ROAD)
client = VisionIpcClient("camerad", VisionStreamType.VISION_STREAM_ROAD, False)
self.assertTrue(client.connect(True))
zmq_sleep()
buf = np.zeros(100 * 150, dtype=np.uint8)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=1)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=2)
recv_buf = client.recv()
self.assertIsNot(recv_buf, None)
self.assertEqual(client.frame_id, 1)
recv_buf = client.recv()
self.assertIsNot(recv_buf, None)
self.assertEqual(client.frame_id, 2)
def test_conflate(self):
self.create_vipc_server("camerad", VisionStreamType.VISION_STREAM_ROAD)
client = VisionIpcClient("camerad", VisionStreamType.VISION_STREAM_ROAD, True)
self.assertTrue(client.connect(True))
zmq_sleep()
buf = np.zeros(100 * 150, dtype=np.uint8)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=1)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=2)
recv_buf = client.recv()
self.assertIsNot(recv_buf, None)
self.assertEqual(client.frame_id, 2)
recv_buf = client.recv()
self.assertIs(recv_buf, None)

View File

@ -65,6 +65,7 @@ cdef class VisionIpcServer:
cdef class VisionIpcClient:
cdef cppVisionBuf * buf
cdef cppVisionIpcClient * client
cdef VisionIpcBufExtra extra
def __cinit__(self, string name, VisionStreamType stream, bool conflate):
self.client = new cppVisionIpcClient(name, stream, conflate, NULL, NULL)
@ -89,8 +90,20 @@ cdef class VisionIpcClient:
def uv_offset(self):
return None if not self.buf else self.buf.uv_offset
@property
def frame_id(self):
return self.extra.frame_id
@property
def timestamp_sof(self):
return self.extra.timestamp_sof
@property
def timestamp_eof(self):
return self.extra.timestamp_eof
def recv(self, int timeout_ms=100):
self.buf = self.client.recv(NULL, timeout_ms)
self.buf = self.client.recv(&self.extra, timeout_ms)
if not self.buf:
return None
cdef cnp.ndarray dat = np.empty(self.buf.len, dtype=np.uint8)