mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
vin and ecu_addrs: add more argparse options (#25913)
* add bus options * use debug * add timeout and try * fix * don't need keywords * log this too * fix old-commit-hash: 0ec8546042091f97072edcf8f5218627ea8a75a9
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import capnp
|
||||
import time
|
||||
import traceback
|
||||
from typing import Optional, Set, Tuple
|
||||
|
||||
import cereal.messaging as messaging
|
||||
@@ -62,7 +61,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, que
|
||||
print(f"Duplicate ECU address: {hex(msg.address)}")
|
||||
ecu_responses.add((msg.address, subaddr, msg.src))
|
||||
except Exception:
|
||||
cloudlog.warning(f"ECU addr scan exception: {traceback.format_exc()}")
|
||||
cloudlog.exception("ECU addr scan exception")
|
||||
return ecu_responses
|
||||
|
||||
|
||||
@@ -71,6 +70,8 @@ if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description='Get addresses of all ECUs')
|
||||
parser.add_argument('--debug', action='store_true')
|
||||
parser.add_argument('--bus', type=int, default=1)
|
||||
parser.add_argument('--timeout', type=float, default=1.0)
|
||||
args = parser.parse_args()
|
||||
|
||||
logcan = messaging.sub_sock('can')
|
||||
@@ -79,7 +80,7 @@ if __name__ == "__main__":
|
||||
time.sleep(1.0)
|
||||
|
||||
print("Getting ECU addresses ...")
|
||||
ecu_addrs = get_all_ecu_addrs(logcan, sendcan, 1, debug=args.debug)
|
||||
ecu_addrs = get_all_ecu_addrs(logcan, sendcan, args.bus, args.timeout, debug=args.debug)
|
||||
|
||||
print()
|
||||
print("Found ECUs on addresses:")
|
||||
|
||||
+11
-1
@@ -35,9 +35,19 @@ def get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import time
|
||||
|
||||
parser = argparse.ArgumentParser(description='Get VIN of the car')
|
||||
parser.add_argument('--debug', action='store_true')
|
||||
parser.add_argument('--bus', type=int, default=1)
|
||||
parser.add_argument('--timeout', type=float, default=0.1)
|
||||
parser.add_argument('--retry', type=int, default=5)
|
||||
args = parser.parse_args()
|
||||
|
||||
sendcan = messaging.pub_sock('sendcan')
|
||||
logcan = messaging.sub_sock('can')
|
||||
time.sleep(1)
|
||||
addr, vin_rx_addr, vin = get_vin(logcan, sendcan, 1, debug=False)
|
||||
|
||||
addr, vin_rx_addr, vin = get_vin(logcan, sendcan, args.bus, args.timeout, args.retry, debug=args.debug)
|
||||
print(f'TX: {hex(addr)}, RX: {hex(vin_rx_addr)}, VIN: {vin}')
|
||||
|
||||
Reference in New Issue
Block a user