mirror of https://github.com/commaai/panda.git
bugfix
This commit is contained in:
parent
c287a38b56
commit
6efca483c3
|
@ -340,12 +340,12 @@ class CanClient():
|
|||
print("CAN-RX: drain - {}".format(len(msgs)))
|
||||
self.rx_buff.clear()
|
||||
else:
|
||||
print('canclient, got msgs', msgs)
|
||||
# print('canclient, got msgs', msgs)
|
||||
for rx_addr, _, rx_data, rx_bus in msgs or []:
|
||||
print('rx_addr', rx_addr, self._recv_filter(rx_bus, rx_addr), len(rx_data))
|
||||
# print('rx_addr', rx_addr, self._recv_filter(rx_bus, rx_addr), len(rx_data))
|
||||
if self._recv_filter(rx_bus, rx_addr) and len(rx_data) > 0:
|
||||
rx_data = bytes(rx_data) # convert bytearray to bytes
|
||||
print('worked!', rx_data)
|
||||
# print('worked!', rx_data)
|
||||
|
||||
if self.debug:
|
||||
print(f"CAN-RX: {hex(rx_addr)} - 0x{bytes.hex(rx_data)}")
|
||||
|
@ -359,13 +359,13 @@ class CanClient():
|
|||
self.rx_buff.append(rx_data)
|
||||
# break when non-full buffer is processed
|
||||
if len(msgs) < 254:
|
||||
print('break')
|
||||
# print('break')
|
||||
return
|
||||
|
||||
def recv(self, drain: bool = False) -> Generator[bytes, None, None]:
|
||||
# buffer rx messages in case two response messages are received at once
|
||||
# (e.g. response pending and success/failure response)
|
||||
print('here')
|
||||
# print('here')
|
||||
self._recv_buffer(drain)
|
||||
try:
|
||||
while True:
|
||||
|
|
|
@ -69,7 +69,7 @@ class UdsServer(UdsClient):
|
|||
while not self.kill_event.is_set():
|
||||
resp, _ = isotp_msg.recv(0) # resp is request from client
|
||||
print('UDS Server - got resp', resp)
|
||||
# time.sleep(0.01)
|
||||
time.sleep(0.01)
|
||||
|
||||
# message from client not fully built
|
||||
if resp is None:
|
||||
|
@ -111,11 +111,12 @@ class UdsServer(UdsClient):
|
|||
data = resp[(1 if resp_sfn is None else 2):]
|
||||
if data in self.services[resp_sid][resp_sfn]:
|
||||
# valid data
|
||||
send_dat = [resp_sid + 0x40, int.from_bytes(resp_sfn)]
|
||||
send_dat = bytes([resp_sid + 0x40, int.from_bytes(resp_sfn)])
|
||||
if len(self.services[resp_sid][resp_sfn][data]):
|
||||
send_dat.append(self.services[resp_sid][resp_sfn][data]) # add data if exists
|
||||
# send_dat.append(self.services[resp_sid][resp_sfn][data]) # add data if exists
|
||||
send_dat += (self.services[resp_sid][resp_sfn][data]) # add data if exists
|
||||
print('send_dat', send_dat, resp_sid)
|
||||
send_dat = bytes(send_dat)
|
||||
# send_dat = bytes(send_dat)
|
||||
isotp_msg.send(send_dat)
|
||||
|
||||
else:
|
||||
|
@ -139,6 +140,10 @@ class UdsServer(UdsClient):
|
|||
self.kill_event.set()
|
||||
self.uds_thread.join()
|
||||
|
||||
def pop_all(l):
|
||||
r, l[:] = l[:], []
|
||||
return r
|
||||
|
||||
|
||||
class MockCanBuffer:
|
||||
def __init__(self):
|
||||
|
@ -151,14 +156,18 @@ class MockCanBuffer:
|
|||
with self.lock:
|
||||
print(f'added to can_send {server=}', (addr, 0, dat, bus))
|
||||
buf = self.rx_msgs_server if server else self.rx_msgs_client
|
||||
buf.append([(addr, 0, dat, bus)])
|
||||
buf.append((addr, 0, dat, bus))
|
||||
|
||||
def can_recv(self, server=False):
|
||||
with self.lock:
|
||||
buf = self.rx_msgs_client if server else self.rx_msgs_server
|
||||
if len(buf):
|
||||
print(f'returned {server=}', buf[0])
|
||||
return buf.pop(0)
|
||||
|
||||
ret = pop_all(buf)
|
||||
|
||||
return ret
|
||||
# return buf.pop(0)
|
||||
else:
|
||||
return []
|
||||
|
||||
|
|
Loading…
Reference in New Issue