import time,json from pathlib import Path import pyautogui as pg,win32clipboard import numpy as np from pywinauto import Desktop R=Path('D:/YMR/AMI');O=R/'docs/evidence/2026-10-07/small-as-status' w=Desktop(backend='win32').window(handle=1116782);w.set_focus() out=Desktop(backend='win32').window(handle=592104) pg.PAUSE=.12 checks=[] def execute(code): pg.click(700,1160);pg.hotkey('ctrl','a') win32clipboard.OpenClipboard();win32clipboard.EmptyClipboard();win32clipboard.SetClipboardText(code.replace('\n','\r\n'),win32clipboard.CF_UNICODETEXT);win32clipboard.CloseClipboard() pg.hotkey('ctrl','v');time.sleep(.2);pg.click(1070,1260);time.sleep(.4) def output():return ' '.join(out.window_text().split()).upper() def clear():pg.click(1600,1090);time.sleep(.1) def shot(name): a=pg.screenshot(region=(920,492,720,408));a.save(str(O/(name+'.png')));return np.asarray(a) for state,label,color in [(6,'unknown','gray'),(0,'off','white'),(1,'ready','yellow'),(2,'driving','yellow'),(3,'finished','blue'),(4,'emergency','red'),(5,'manual','green')]: execute(f'current_task=2\nlock_state=1\nebs_state=1\nas_state={state}') clear();execute('get as_state\nget shown_as') expected=f'71 {state:02X} 00 00 00 FF FF FF' assert output().count(expected)==2,(state,output()) a=shot('dash-as-'+label)[int(215*1.5):int(245*1.5),int(194*1.5):int(302*1.5),:3].astype(np.int16) r,g,b=a[:,:,0],a[:,:,1],a[:,:,2] masks={'gray':(r>75)&(r<180)&(abs(r-g)<8)&(abs(r-b)<8), 'white':(r>210)&(g>210)&(b>210),'yellow':(r>180)&(g>180)&(b<80), 'blue':(b>180)&(g<80)&(r<80),'red':(r>180)&(g<80)&(b<80), 'green':(g>180)&(r<80)&(b<80)} count=int(masks[color].sum());assert count>30,(state,color,count) checks.append(dict(state=state,label=label,color=color,pixels=count,rendered_state_query=output(),passed=True)) print(label,'passed',flush=True) execute('as_state=4\npage debug\nas_state=1\npage dash');clear();execute('get as_state\nget shown_as');assert output().count('71 01 00 00 00 FF FF FF')==2 shot('dash-as-cross-page');checks.append(dict(name='cross-page latest state and postinit redraw',passed=True)) execute('click bt4,1\nclick bt4,0\nclick b0,1\nclick b0,0');clear();execute('get as_state\nget shown_as');assert output().count('71 01 00 00 00 FF FF FF')==2 checks.append(dict(name='task confirmation preserves actual AS feedback',passed=True)) execute('current_task=2\nlock_state=1\nebs_state=1\nas_state=1\ndash.speed.val=38\ndash.lvbat.val=1260') shot('dash-as-ready-sample') (O/'simulator-results.json').write_text(json.dumps(dict(scope='official HMI simulator, no physical UART/CAN',checks=checks),ensure_ascii=False,indent=2),encoding='utf-8')