Add cross-platform Python host agent with psutil and optional NVML.

Replace Windows-only WMI collector so Win10/11, Linux, and macOS can feed the same SI protocol.
This commit is contained in:
2026-10-27 20:21:08 +08:00
parent 116615818b
commit 8cc030178f
4 changed files with 494 additions and 247 deletions

View File

@@ -11,7 +11,7 @@
## 原理
ESP32 无法直接读 PC 硬件。本机跑 [`host/send_sysinfo.ps1`](host/send_sysinfo.ps1),经 **USB 串口** 按行推送:
ESP32 无法直接读 PC 硬件。主机端跑跨平台脚本,经 **USB 串口** 按行推送:
```
SI|host=DESKTOP|cpu=i7-13700K|cpu%=12.3|gpu=RTX 4070|gpu%=5|ram=18.2/31.8|disk=512/931
@@ -19,7 +19,26 @@ SI|host=DESKTOP|cpu=i7-13700K|cpu%=12.3|gpu=RTX 4070|gpu%=5|ram=18.2/31.8|disk=5
屏上 LVGL 面板解析后画进度条;超过约 5 秒无新包显示 **stale**。
GPU 占用:优先 `nvidia-smi`,否则尝试 Windows GPU Engine 计数器;都失败则显示 `n/a`(名称仍可读)。
### 通用主机方案(Win10/11 · Linux · macOS)
业界常规做法(本仓库已采用):
| 层级 | 库 / 接口 | 覆盖 |
|------|-----------|------|
| **CPU / 内存 / 磁盘** | [`psutil`](https://psutil.readthedocs.io/) | Windows / Linux / macOS / BSD… |
| **串口** | [`pyserial`](https://pyserial.readthedocs.io/) | 同上 |
| **GPU 占用(可选)** | [`nvidia-ml-py`](https://pypi.org/project/nvidia-ml-py/)(NVML)→ `nvidia-smi` → `amd-smi`/`rocm-smi` | NVIDIA 最稳;AMD 有驱动/CLI 时可用;没有则 `gpu%=-1`(名称仍尽量读) |
入口:**[`host/send_sysinfo.py`](host/send_sysinfo.py)**(推荐)。Windows 也可 `.\host\send_sysinfo.ps1`(内部仍调 Python)。
```powershell
cd host
pip install -r requirements.txt
pip install nvidia-ml-py # 有 NVIDIA 时建议装
python send_sysinfo.py # 自动选串口
python send_sysinfo.py -p COM5 # Windows
python send_sysinfo.py -p /dev/ttyUSB0 # Linux
```
## 刷写
@@ -52,13 +71,14 @@ cd firmware\cyd # 或 firmware\cyd_35r
## 推送本机信息
板子刷好并插上 USB 后,在 **PC** 上:
板子刷好并插上 USB 后,在主机上:
```powershell
cd host
.\send_sysinfo.ps1
python send_sysinfo.py
# 或
.\send_sysinfo.ps1 -Port COM5 -IntervalMs 1000
python send_sysinfo.py -p COM5 -i 1000
.\send_sysinfo.ps1 -Port COM5 # Windows 快捷入口
```
注意:串口同时只能被一个程序占用;跑推送脚本时不要开 `pio device monitor`。
@@ -68,6 +88,8 @@ cd host
```
include/pins.h, touch.h, host_info.h, ui.h, lv_conf.h
src/main.cpp, touch.cpp, host_info.cpp, ui.cpp
host/send_sysinfo.ps1
host/send_sysinfo.py # 跨平台主入口
host/requirements.txt
host/send_sysinfo.ps1 # Windows 启动器
firmware/
```