| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import serial, time, json, subprocess, re
- ADB = 'D:\\BaiduNetdiskDownload\\HBuilderX.4.24.2024072208\\HBuilderX\\plugins\\launcher-tools\\tools\\adbs\\adb.exe'
- print(f"[{time.strftime('%H:%M:%S')}] === 步骤 1: COM9 发命令 ===")
- s = serial.Serial('COM9', 115200, timeout=0.1)
- print(f" ✅ COM9 打开")
- # 先发 sm2,01(确保睡眠带稳定)
- s.write(b'{"zt":"sm2","neirong":"01"}\n')
- s.flush()
- print(f" >>> sm2,01")
- # 发 xy1,01
- s.write(b'{"zt":"xy1","neirong":"01"}\n')
- s.flush()
- print(f" >>> xy1,01")
- # 等 12 秒,观察血氧能不能上来
- print(f"\n[{time.strftime('%H:%M:%S')}] === 步骤 2: COM9 等 12 秒看血氧 ===")
- line = b''
- end = time.time() + 12
- xy1_up = False
- while time.time() < end:
- data = s.read(512)
- for b in data:
- if b in (13, 10):
- if not line: continue
- t = line.decode('ascii', errors='replace')
- line = b''
- if t.startswith('{'):
- d = json.loads(t)
- xl1 = d.get('xl1', '') or '(空)'
- xy1 = d.get('xy1', '') or '(空)'
- xl2 = d.get('xl2', '') or '(空)'
- hx2 = d.get('hx2', '') or '(空)'
- flag = ''
- if xl1 != '(空)' and xy1 != '(空)':
- flag = ' ✅血氧上来了!'
- xy1_up = True
- elif xl1 == '(空)' and xy1 == '(空)':
- flag = ' ⚠️血氧空'
- print(f" PC COM9: xl1={xl1:<6} xy1={xy1:<6} xl2={xl2:<6} hx2={hx2:<6}{flag}")
- else:
- line += bytes([b])
- s.close()
- print(f"\n 血氧有没有上来: {'✅ YES' if xy1_up else '❌ NO'}")
- # 现在连平板看它能不能收到
- print(f"\n[{time.strftime('%H:%M:%S')}] === 步骤 3: 连平板抓 logcat(10 秒)===")
- # 先 kill 所有 adb 进程干净
- subprocess.run(['taskkill', '/F', '/IM', 'adb.exe'], capture_output=True, shell=True)
- time.sleep(2)
- # 启动 adb server + connect
- r = subprocess.run([ADB, 'start-server'], capture_output=True, text=True, timeout=10)
- time.sleep(3)
- # 清 logcat
- subprocess.run([ADB, 'logcat', '-c'], capture_output=True, timeout=5)
- # 抓 logcat
- proc = subprocess.Popen([ADB, 'logcat', '-v', 'time'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
- json_re = re.compile(r'ASCII=(\{.+\})')
- results = []
- start = time.time()
- while time.time() - start < 10:
- line_out = proc.stdout.readline()
- if not line_out: continue
- if 'UsbSerial' in line_out or 'BoardJson' in line_out:
- m = json_re.search(line_out)
- if m:
- try:
- d = json.loads(m.group(1))
- xl1 = d.get('xl1', '') or '(空)'
- xy1 = d.get('xy1', '') or '(空)'
- sm2 = d.get('sm2', '') or '(空)'
- xl2 = d.get('xl2', '') or '(空)'
- hx2 = d.get('hx2', '') or '(空)'
- flag = ''
- if xl1 != '(空)' and xy1 != '(空)': flag += ' ✅血氧'
- elif xl1 == '(空)' and xy1 == '(空)': flag += ' ⚠️血氧空'
- if xl2 != '(空)' and hx2 != '(空)': flag += ' ✅睡眠'
- elif xl2 == '(空)' and hx2 == '(空)': flag += ' ⚠️睡眠空'
- results.append((xl1, xy1, sm2, xl2, hx2))
- print(f" 平板收到: xl1={xl1:<6} xy1={xy1:<6} sm2={sm2:<5} xl2={xl2:<6} hx2={hx2:<6}{flag}")
- except:
- pass
- proc.terminate()
- proc.wait(timeout=3)
- print(f"\n=== 🎯 最终验证 ===")
- print(f" PC COM9 血氧: {'✅ 正常' if xy1_up else '❌ 空'}")
- print(f" 平板收到 JSON: {len(results)} 帧")
- if results:
- last = results[-1]
- xl1_ok = last[0] != '(空)' and last[1] != '(空)'
- xl2_ok = last[3] != '(空)' and last[4] != '(空)'
- print(f" 平板血氧: {'✅ 正常' if xl1_ok else '❌ 空'} ({last[0]}, {last[1]})")
- print(f" 平板睡眠: {'✅ 正常' if xl2_ok else '❌ 空'} ({last[3]}, {last[4]})")
- else:
- print(" ⚠️ 平板没收到任何 JSON")
|