Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate busTime #1989

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RUN /tmp/install.sh && rm -rf $CPPCHECK_DIR/.git/
ENV SKIP_CPPCHECK_INSTALL=1

ENV CEREAL_REF="861144c136c91f70dcbc652c2ffe99f57440ad47"
ENV OPENDBC_REF="e0d4be4a6215d44809718dc84efe1b9f0299ad63"
ENV OPENDBC_REF="8e9d3688412405154a8189c421cfdc9d5feea715"

RUN git config --global --add safe.directory /tmp/openpilot/panda
RUN mkdir -p /tmp/openpilot/ && \
Expand Down
2 changes: 1 addition & 1 deletion board/jungle/scripts/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0"))
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)

Expand Down
2 changes: 1 addition & 1 deletion board/jungle/scripts/echo_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_loopback():
incoming = jungle.can_recv()
found = False
for message in incoming:
incomingAddress, _, incomingData, incomingBus = message
incomingAddress, incomingData, incomingBus = message
if incomingAddress == address and incomingData == data[::-1] and incomingBus == bus:
found = True
break
Expand Down
4 changes: 2 additions & 2 deletions board/jungle/scripts/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def can_loopback(sender):
raise Exception("Amount of received CAN messages (" + str(len(content)) + ") does not equal 1. Bus: " + str(bus) +" OBD: " + str(obd))

# Check content
if content[0][0] != addr or content[0][2] != string:
if content[0][0] != addr or content[0][1] != string:
raise Exception("Received CAN message content or address does not match")

# Check bus
if content[0][3] != bus:
if content[0][2] != bus:
raise Exception("Received CAN message bus does not match")

#################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/can_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def can_logger():
while True:
can_recv = p.can_recv()

for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
csvwriter.writerow(
[str(src), str(hex(address)), f"0x{dat.hex()}", len(dat), str(time.time() - start_time)])

Expand Down
2 changes: 1 addition & 1 deletion examples/tesla_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def tesla_tester():
while True:
#Read the VIN
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == body_bus_num:
if address == 1384: # 0x568 is VIN
vin_index = int(binascii.hexlify(dat)[:2]) # first byte is the index, 00, 01, 02
Expand Down
6 changes: 3 additions & 3 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_checksum(data):

def pack_can_buffer(arr):
snds = [b'']
for address, _, dat, bus in arr:
for address, dat, bus in arr:
assert len(dat) in LEN_TO_DLC
#logging.debug(" W 0x%x: 0x%s", address, dat.hex())

Expand Down Expand Up @@ -85,7 +85,7 @@ def unpack_can_buffer(dat):
data = dat[CANPACKET_HEAD_SIZE:(CANPACKET_HEAD_SIZE+data_len)]
dat = dat[(CANPACKET_HEAD_SIZE+data_len):]

ret.append((address, 0, data, bus))
ret.append((address, data, bus))

return (ret, dat)

Expand Down Expand Up @@ -812,7 +812,7 @@ def can_send_many(self, arr, timeout=CAN_SEND_TIMEOUT_MS):
logging.error("CAN: BAD SEND MANY, RETRYING")

def can_send(self, addr, dat, bus, timeout=CAN_SEND_TIMEOUT_MS):
self.can_send_many([[addr, None, dat, bus]], timeout=timeout)
self.can_send_many([[addr, dat, bus]], timeout=timeout)

@ensure_can_packet_version
def can_recv(self):
Expand Down
2 changes: 1 addition & 1 deletion python/ccp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _recv_dto(self, timeout: float) -> bytes:
msgs = self._panda.can_recv() or []
if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data_bytearray, rx_bus in msgs:
for rx_addr, rx_data_bytearray, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data_bytearray)
if self.debug:
Expand Down
6 changes: 3 additions & 3 deletions python/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def recv(panda, cnt, addr, nbus):
while len(ret) < cnt:
kmsgs += panda.can_recv()
nmsgs = []
for ids, ts, dat, bus in kmsgs:
for ids, dat, bus in kmsgs:
if ids == addr and bus == nbus and len(ret) < cnt:
ret.append(dat)
else:
# leave around
nmsgs.append((ids, ts, dat, bus))
nmsgs.append((ids, dat, bus))
kmsgs = nmsgs[-256:]
return ret

Expand Down Expand Up @@ -96,7 +96,7 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None, rate=None):
panda.can_send(addr, sends[-1], 0)
else:
if rate is None:
panda.can_send_many([(addr, None, s, bus) for s in sends])
panda.can_send_many([(addr, s, bus) for s in sends])
else:
for dat in sends:
panda.can_send(addr, dat, bus)
Expand Down
2 changes: 1 addition & 1 deletion python/xcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _recv_dto(self, timeout: float) -> bytes:
msgs = self._panda.can_recv() or []
if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data, rx_bus in msgs:
for rx_addr, rx_data, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data) # convert bytearray to bytes
if self.debug:
Expand Down
6 changes: 3 additions & 3 deletions tests/black_white_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1

print(" Loop on bus", str(loop[3]))
loop_buses.append(loop[3])
print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[2])
if len(cans_loop) == 0:
print(" No loop")
assert not os.getenv("NOASSERT")
Expand Down
6 changes: 3 additions & 3 deletions tests/black_white_relay_endurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1

print(" Loop on bus", str(loop[3]))
loop_buses.append(loop[3])
print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[2])
if len(cans_loop) == 0:
print(" No loop")
assert os.getenv("NOASSERT")
Expand Down
4 changes: 2 additions & 2 deletions tests/black_white_relay_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def test_buses(black_panda, other_panda, test_obj):

loop_buses = []
for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st):
if (loop[0] != at) or (loop[1] != st):
content_errors += 1
loop_buses.append(loop[3])
loop_buses.append(loop[2])

# test loop buses
recv_buses.sort()
Expand Down
2 changes: 1 addition & 1 deletion tests/bulk_write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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
packet = [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS
panda.can_send_many(packet, timeout=10000)
print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!")

Expand Down
2 changes: 1 addition & 1 deletion tests/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0"))
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)

Expand Down
4 changes: 2 additions & 2 deletions tests/canfd/test_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def canfd_test(p_send, p_recv):
data = bytearray(random.getrandbits(8) for _ in range(DLC_TO_LEN[dlc]))
if len(data) >= 2:
data[0] = calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8"))
to_send.append([address, 0, data, bus])
to_send.append([address, data, bus])
sent_msgs[bus].add((address, bytes(data)))

p_send.can_send_many(to_send, timeout=0)
Expand All @@ -95,7 +95,7 @@ def canfd_test(p_send, p_recv):
while (time.monotonic() - start_time < 1) and any(len(x) > 0 for x in sent_msgs.values()):
incoming = p_recv.can_recv()
for msg in incoming:
address, _, data, bus = msg
address, data, bus = msg
if len(data) >= 2:
assert calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8")) == data[0]
k = (address, bytes(data))
Expand Down
2 changes: 1 addition & 1 deletion tests/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
while True:
incoming = p.can_recv()
for message in incoming:
address, notused, data, bus = message
address, data, bus = message
if b'test' in data:
p.can_send(address, data[::-1], bus)
6 changes: 3 additions & 3 deletions tests/elm_car_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def __can_monitor(self):
self.panda.can_recv() # Toss whatever was already there

while not self.__stop:
for address, ts, data, src in self.panda.can_recv():
for address, data, src in self.panda.can_recv():
if self.__on and src == 0 and len(data) == 8 and data[0] >= 2:
if not self.__silent:
print("Processing CAN message", src, hex(address), binascii.hexlify(data))
self.__can_process_msg(data[1], data[2], address, ts, data, src)
self.__can_process_msg(data[1], data[2], address, data, src)
elif not self.__silent:
print("Rejecting CAN message", src, hex(address), binascii.hexlify(data))

Expand Down Expand Up @@ -120,7 +120,7 @@ def _can_addr_matches(self, addr):
return True
return False

def __can_process_msg(self, mode, pid, address, ts, data, src):
def __can_process_msg(self, mode, pid, address, data, src):
if not self.__silent:
print("CAN MSG", binascii.hexlify(data[1:1 + data[0]]),
"Addr:", hex(address), "Mode:", hex(mode)[2:].zfill(2),
Expand Down
12 changes: 6 additions & 6 deletions tests/hitl/3_usb_to_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def test_can_loopback(p):
# confirm receive both on loopback and send receipt
time.sleep(0.05)
r = p.can_recv()
sr = [x for x in r if x[3] == 0x80 | bus]
lb = [x for x in r if x[3] == bus]
sr = [x for x in r if x[2] == 0x80 | bus]
lb = [x for x in r if x[2] == bus]
assert len(sr) == 1
assert len(lb) == 1

# confirm data is correct
assert 0x1aa == sr[0][0] == lb[0][0]
assert b"message" == sr[0][2] == lb[0][2]
assert b"message" == sr[0][1] == lb[0][1]

def test_reliability(p):
MSG_COUNT = 100
Expand All @@ -35,7 +35,7 @@ def test_reliability(p):
p.set_can_speed_kbps(0, 1000)

addrs = list(range(100, 100 + MSG_COUNT))
ts = [(j, 0, b"\xaa" * 8, 0) for j in addrs]
ts = [(j, b"\xaa" * 8, 0) for j in addrs]

for _ in range(100):
st = time.monotonic()
Expand All @@ -46,8 +46,8 @@ def test_reliability(p):
while len(r) < 200 and (time.monotonic() - st) < 0.5:
r.extend(p.can_recv())

sent_echo = [x for x in r if x[3] == 0x80]
loopback_resp = [x for x in r if x[3] == 0]
sent_echo = [x for x in r if x[2] == 0x80]
loopback_resp = [x for x in r if x[2] == 0]

assert sorted([x[0] for x in loopback_resp]) == addrs
assert sorted([x[0] for x in sent_echo]) == addrs
Expand Down
18 changes: 9 additions & 9 deletions tests/hitl/4_can_loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def test(p_send, p_recv, address=None):
assert len(content) == 1

# Check content
assert content[0][0] == addr and content[0][2] == string
assert content[0][0] == addr and content[0][1] == string

# Check bus
assert content[0][3] == bus
assert content[0][2] == bus

print("Bus:", bus, "address:", addr, "OBD:", obd, "OK")

Expand All @@ -148,9 +148,9 @@ def flood_tx(panda):
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
packet += [[0xaa, 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
packet += [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS

# Disable timeout
panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
Expand Down Expand Up @@ -182,18 +182,18 @@ def test_message_integrity(p):
for _ in range(random.randrange(10)):
to_send = get_random_can_messages(random.randrange(100))
for m in to_send:
sent_msgs[m[3]].add((m[0], m[2]))
sent_msgs[m[2]].add((m[0], m[1]))
p.can_send_many(to_send, timeout=0)

start_time = time.monotonic()
while time.monotonic() - start_time < 2 and any(len(sent_msgs[bus]) for bus in range(3)):
recvd = p.can_recv()
for msg in recvd:
if msg[3] >= 128:
k = (msg[0], bytes(msg[2]))
bus = msg[3]-128
if msg[2] >= 128:
k = (msg[0], bytes(msg[1]))
bus = msg[2]-128
assert k in sent_msgs[bus], f"message {k} was never sent on bus {bus}"
sent_msgs[msg[3]-128].discard(k)
sent_msgs[msg[2]-128].discard(k)

# if a set isn't empty, messages got dropped
for bus in range(3):
Expand Down
4 changes: 2 additions & 2 deletions tests/hitl/6_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_safety_nooutput(p):
time.sleep(0.05)
r = p.can_recv()
# bus 192 is messages blocked by TX safety hook on bus 0
assert len([x for x in r if x[3] != 192]) == 0
assert len([x for x in r if x[3] == 192]) == 1
assert len([x for x in r if x[2] != 192]) == 0
assert len([x for x in r if x[2] == 192]) == 1


def test_canfd_safety_modes(p):
Expand Down
2 changes: 1 addition & 1 deletion tests/hitl/9_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_harness_status(p, panda_jungle):
time.sleep(0.5)

msgs = p.can_recv()
buses = {int(dat): bus for _, _, dat, bus in msgs if bus <= 3}
buses = {int(dat): bus for _, dat, bus in msgs if bus <= 3}
print(msgs)

# jungle doesn't actually switch buses when switching orientation
Expand Down
12 changes: 6 additions & 6 deletions tests/hitl/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_random_can_messages(n):
bus = random.randrange(3)
addr = random.randrange(1 << 29)
dat = bytes([random.getrandbits(8) for _ in range(random.randrange(1, 9))])
m.append([addr, None, dat, bus])
m.append([addr, dat, bus])
return m


Expand All @@ -19,7 +19,7 @@ def time_many_sends(p, bus, p_recv=None, msg_count=100, two_pandas=False, msg_le
raise ValueError("Cannot have two pandas that are the same panda")

msg_id = random.randint(0x100, 0x200)
to_send = [(msg_id, 0, b"\xaa" * msg_len, bus)] * msg_count
to_send = [(msg_id, b"\xaa" * msg_len, bus)] * msg_count

start_time = time.monotonic()
p.can_send_many(to_send)
Expand All @@ -35,11 +35,11 @@ def time_many_sends(p, bus, p_recv=None, msg_count=100, two_pandas=False, msg_le
while len(r_echo) < r_echo_len_exected and (time.monotonic() - start_time) < 10:
r_echo.extend(p.can_recv())

sent_echo = [x for x in r if x[3] == 0x80 | bus and x[0] == msg_id]
sent_echo.extend([x for x in r_echo if x[3] == 0x80 | bus and x[0] == msg_id])
resp = [x for x in r if x[3] == bus and x[0] == msg_id]
sent_echo = [x for x in r if x[2] == 0x80 | bus and x[0] == msg_id]
sent_echo.extend([x for x in r_echo if x[2] == 0x80 | bus and x[0] == msg_id])
resp = [x for x in r if x[2] == bus and x[0] == msg_id]

leftovers = [x for x in r if (x[3] != 0x80 | bus and x[3] != bus) or x[0] != msg_id]
leftovers = [x for x in r if (x[2] != 0x80 | bus and x[2] != bus) or x[0] != msg_id]
assert len(leftovers) == 0

assert len(resp) == msg_count
Expand Down
12 changes: 6 additions & 6 deletions tests/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def run_test_w_pandas(pandas, sleep_duration):
assert cans_echo[0][0] == at
assert cans_loop[0][0] == at

assert cans_echo[0][2] == st
assert cans_loop[0][2] == st
assert cans_echo[0][1] == st
assert cans_loop[0][1] == st

assert cans_echo[0][3] == 0x80 | bus
if cans_loop[0][3] != bus:
print("EXPECTED %d GOT %d" % (bus, cans_loop[0][3]))
assert cans_loop[0][3] == bus
assert cans_echo[0][2] == 0x80 | bus
if cans_loop[0][2] != bus:
print("EXPECTED %d GOT %d" % (bus, cans_loop[0][2]))
assert cans_loop[0][2] == bus

print("CAN pass", bus, ho)
time.sleep(sleep_duration)
Expand Down
Loading
Loading