feat: add VCU status feedback and map DEBUG safety inputs
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""Send custom AMI 0x183 VCU display feedback; no vehicle actuation."""
|
||||
import argparse
|
||||
import math
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
def build_payload(task, locked, ebs_normal, valid=7, sequence=0):
|
||||
if task not in range(7) or locked not in (0, 1) or ebs_normal not in (0, 1):
|
||||
raise ValueError('task must be 0..6; locked and ebs-normal must be 0 or 1')
|
||||
if valid not in range(8) or sequence not in range(256):
|
||||
raise ValueError('valid must be 0..7 and sequence must be 0..255')
|
||||
return bytes([task, locked, ebs_normal, valid, sequence, 0, 0, 1])
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--task', type=int, required=True, choices=range(7))
|
||||
parser.add_argument('--locked', type=int, required=True, choices=(0, 1))
|
||||
parser.add_argument('--ebs-normal', type=int, required=True, choices=(0, 1))
|
||||
parser.add_argument('--valid', type=int, default=7)
|
||||
parser.add_argument('--sequence', type=int, default=0)
|
||||
parser.add_argument('--interface', default='pcan')
|
||||
parser.add_argument('--channel', default='PCAN_USBBUS1')
|
||||
parser.add_argument('--bitrate', type=int, choices=(250000, 500000), default=500000)
|
||||
parser.add_argument('--period', type=float, default=.1)
|
||||
parser.add_argument('--duration', type=float, default=10)
|
||||
parser.add_argument('--dll-dir')
|
||||
parser.add_argument('--dry-run', action='store_true')
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
payload = build_payload(args.task, args.locked, args.ebs_normal, args.valid, args.sequence)
|
||||
except ValueError as exc:
|
||||
parser.error(str(exc))
|
||||
if not (0 < args.period <= .5 and 0 < args.duration and math.isfinite(args.duration)):
|
||||
parser.error('period must be >0 and <=0.5 seconds; duration must be finite and positive')
|
||||
print(f'Standard ID 0x183, DLC 8, data {payload.hex(" ").upper()}, bitrate {args.bitrate}', flush=True)
|
||||
if args.dry_run:
|
||||
return
|
||||
dll_handle = None
|
||||
if args.dll_dir:
|
||||
directory = os.path.abspath(args.dll_dir)
|
||||
os.environ['PATH'] = directory + os.pathsep + os.environ['PATH']
|
||||
dll_handle = os.add_dll_directory(directory)
|
||||
import can
|
||||
count = 0
|
||||
try:
|
||||
with can.Bus(interface=args.interface, channel=args.channel, bitrate=args.bitrate) as bus:
|
||||
started = time.monotonic()
|
||||
deadline = started
|
||||
while time.monotonic() < started + args.duration:
|
||||
payload = build_payload(args.task, args.locked, args.ebs_normal,
|
||||
args.valid, (args.sequence + count) & 255)
|
||||
bus.send(can.Message(arbitration_id=0x183, is_extended_id=False, data=payload), timeout=.2)
|
||||
count += 1
|
||||
deadline += args.period
|
||||
time.sleep(max(0, min(deadline, started + args.duration) - time.monotonic()))
|
||||
finally:
|
||||
if dll_handle is not None:
|
||||
dll_handle.close()
|
||||
print(f'Sent {count} frames. Display becomes unknown over 500 ms after feedback stops.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user