Skip to content

Commit 909de74

Browse files
committed
Add type hint for can message
1 parent 50a0e4e commit 909de74

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

selfdrive/car/ecu_addrs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/usr/bin/env python3
2+
import capnp
23
import time
34
import traceback
4-
from typing import Any, Set
5+
from typing import Set
56

67
import cereal.messaging as messaging
78
from panda.python.uds import SERVICE_TYPE
89
from selfdrive.boardd.boardd import can_list_to_can_capnp
910
from selfdrive.swaglog import cloudlog
1011

12+
1113
# TODO: figure out type annotation for CanData
12-
def is_tester_present_response(msg: Any) -> bool:
14+
def is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader) -> bool:
1315
# ISO-TP messages are always padded to 8 bytes
1416
# tester present response is always a single frame
1517
if len(msg.dat) == 8 and msg.dat[0] >= 1 and msg.dat[0] <= 7:
@@ -21,7 +23,8 @@ def is_tester_present_response(msg: Any) -> bool:
2123
return True
2224
return False
2325

24-
def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus: int, timeout: float=1, debug: bool=True) -> Set[int]:
26+
27+
def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus: int, timeout: float = 1, debug: bool = True) -> Set[int]:
2528
ecu_addrs = set()
2629
try:
2730
addr_list = [0x700 + i for i in range(256)] + [0x18da00f1 + (i << 8) for i in range(256)]
@@ -45,6 +48,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus
4548
cloudlog.warning(f"ECU addr scan exception: {traceback.format_exc()}")
4649
return ecu_addrs
4750

51+
4852
if __name__ == "__main__":
4953
import argparse
5054

0 commit comments

Comments
 (0)