81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
package device
|
||
|
||
// ============================================================
|
||
// [设备层] 领域类型:连接态、设备信息、帧数据、配对/连接请求
|
||
// ============================================================
|
||
|
||
// ConnMode 连接方式
|
||
type ConnMode string
|
||
|
||
const (
|
||
ConnUSB ConnMode = "usb"
|
||
ConnLAN ConnMode = "lan" // adb connect host:port
|
||
)
|
||
|
||
// DeviceInfo 列表/状态栏展示用
|
||
type DeviceInfo struct {
|
||
ID string `json:"id"` // adb serial,无线多为 ip:port
|
||
Model string `json:"model"`
|
||
Mode ConnMode `json:"mode"`
|
||
Online bool `json:"online"`
|
||
Width int `json:"width"`
|
||
Height int `json:"height"`
|
||
State string `json:"state,omitempty"` // device | offline | unauthorized
|
||
LastSeen string `json:"lastSeen,omitempty"`
|
||
}
|
||
|
||
// FrameSnapshot 一帧画面(ADB screencap PNG → base64)
|
||
type FrameSnapshot struct {
|
||
DeviceID string `json:"deviceId"`
|
||
MimeType string `json:"mimeType"`
|
||
Base64 string `json:"base64"`
|
||
Width int `json:"width"`
|
||
Height int `json:"height"`
|
||
Timestamp int64 `json:"timestamp"`
|
||
}
|
||
|
||
// TapRequest 点击(像素坐标)
|
||
type TapRequest struct {
|
||
DeviceID string `json:"deviceId"`
|
||
X float64 `json:"x"`
|
||
Y float64 `json:"y"`
|
||
}
|
||
|
||
// SwipeRequest uses display pixels, in the current screen orientation.
|
||
type SwipeRequest struct {
|
||
DeviceID string `json:"deviceId"`
|
||
X1 float64 `json:"x1"`
|
||
Y1 float64 `json:"y1"`
|
||
X2 float64 `json:"x2"`
|
||
Y2 float64 `json:"y2"`
|
||
DurationMs int `json:"durationMs"`
|
||
}
|
||
|
||
// PairRequest 无线调试配对(开发者选项里的「无线调试 → 使用配对码配对」)
|
||
// PairHostPort 与 ConnectHostPort 通常是不同端口
|
||
type PairRequest struct {
|
||
HostPort string `json:"hostPort"` // 例 192.168.1.8:37123
|
||
Code string `json:"code"` // 六位配对码
|
||
}
|
||
|
||
// ConnectRequest 无线连接(配对成功后,用「IP 地址与端口」里的连接端口)
|
||
type ConnectRequest struct {
|
||
HostPort string `json:"hostPort"` // 例 192.168.1.8:5555
|
||
}
|
||
|
||
// ActionResult 通用操作回执(给 UI 提示)
|
||
type ActionResult struct {
|
||
OK bool `json:"ok"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// TouchRequest uses the decoded video coordinates expected by scrcpy.
|
||
type TouchRequest struct {
|
||
DeviceID string `json:"deviceId"`
|
||
Action int `json:"action"` // Android: down=0, up=1, move=2, cancel=3
|
||
X int `json:"x"`
|
||
Y int `json:"y"`
|
||
Width int `json:"width"`
|
||
Height int `json:"height"`
|
||
}
|