67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from datetime import datetime
|
|
from smartcard.System import readers
|
|
from smartcard.Exceptions import CardConnectionException, NoCardException
|
|
from smartcard.System import readers
|
|
from smartcard.util import toHexString
|
|
from main import detect_card
|
|
from profiles import TeslaVCSEC
|
|
|
|
|
|
|
|
|
|
reader = readers()[0]
|
|
start_time = datetime.now()
|
|
card_count = 0
|
|
|
|
last_uid = None
|
|
|
|
try:
|
|
while True:
|
|
result = detect_card(reader, previous_uid=last_uid)
|
|
if result is None:
|
|
# User pressed Enter
|
|
break
|
|
if result == "retry":
|
|
# Card vanished mid-detect, loop back
|
|
continue
|
|
|
|
connection, uid = result
|
|
card_count += 1
|
|
print(f"--- Card #{card_count} ---")
|
|
|
|
try:
|
|
tesla = TeslaVCSEC()
|
|
result = tesla.validate(connection)
|
|
print(f"{uid}: {result}")
|
|
# uid, public_key = process_card(
|
|
# args, reader, current_keys, new_keys, connection, uid,
|
|
# )
|
|
# write_log_entry(args.log_file, card_count, uid, public_key, "OK")
|
|
last_uid = uid
|
|
print()
|
|
print(f"Card #{card_count} complete. ({card_count} total)")
|
|
except (RuntimeError, CardConnectionException, NoCardException) as exc:
|
|
_warn(f"Card #{card_count} failed: {exc}")
|
|
print()
|
|
retry = input(" Retry this card? [Y/n]: ").strip().lower()
|
|
if retry in ("", "y", "yes"):
|
|
card_count -= 1
|
|
# Card must leave the RF field to reset after a failed
|
|
# operation — wait for removal before re-detecting.
|
|
_info("Remove card from reader to reset it...")
|
|
while _read_uid_quick(reader) is not None:
|
|
time.sleep(0.15)
|
|
_info("Card removed. Re-present when ready.")
|
|
last_uid = None # allow same UID to be picked up again
|
|
else:
|
|
# write_log_entry(
|
|
# args.log_file, card_count,
|
|
# uid or "UNKNOWN", None, f"FAILED: {exc}",
|
|
# )
|
|
last_uid = uid
|
|
|
|
print()
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n")
|
|
_warn("Interrupted by user.") |