- local-agent/server:detector 保留 kn_number(parseScanDevices 可測化、 合成 ID 語意不動)+ DeviceInfo.SerialNumber + Manager serialToLocalID 反查表 + GetDevice 雙查(sessions 先、serial 後,純加法) - visiona-agent:pairing exchange 帶本地裝置清單(DeviceLister 失敗不中斷 配對、timeout 2s、omitempty 舊版相容) - visionA-backend:exchange 收 devices —— R1 取第一顆可用序號、R2 假序號 0x00000000 寫 NULL、R4 同 owner 同序號復用既有 device_id(防 23505)、 pg+mem 兩實作對齊 - 五個 proxy 操作(flash/inference/camera/connect/disconnect)收斂於 GetDevice 單一入口,serial 路由一處涵蓋 - docs:api-spec.md §2 增補 POST /api/pairing/exchange(schema + R1/R2/R4) - 測試:行為級四環節鏈 + dbtest 130 實跑 6/6 + DBOn 回歸 4/4; 三 module build/vet/test 全綠 - review:通過 0C/0M/6Mi/5Sug(.autoflow/05-implementation/review/ wp0-serial-routing-review.md);Minor #1 Rescan stale session 掛 WP-C 前置 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
97 lines
3.0 KiB
Go
97 lines
3.0 KiB
Go
package driver
|
|
|
|
import "time"
|
|
|
|
type DeviceDriver interface {
|
|
Info() DeviceInfo
|
|
Connect() error
|
|
Disconnect() error
|
|
IsConnected() bool
|
|
Flash(modelPath string, progressCh chan<- FlashProgress) error
|
|
StartInference() error
|
|
StopInference() error
|
|
ReadInference() (*InferenceResult, error)
|
|
RunInference(imageData []byte) (*InferenceResult, error)
|
|
GetModelInfo() (*ModelInfo, error)
|
|
}
|
|
|
|
type DeviceInfo struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Port string `json:"port"`
|
|
// SerialNumber is the Kneron kn_number reported by the Python bridge
|
|
// (formatted "0x%08X"). Empty when the bridge cannot read it (e.g. the
|
|
// pyusb fallback reports the fake value 0x00000000, which callers should
|
|
// treat as "no serial"). Used as the stable cross-layer routing key
|
|
// (cloud devices.serial_number <-> local sessions key), see ADR-018.
|
|
SerialNumber string `json:"serialNumber,omitempty"`
|
|
VendorID uint16 `json:"vendorId,omitempty"`
|
|
ProductID uint16 `json:"productId,omitempty"`
|
|
Status DeviceStatus `json:"status"`
|
|
FirmwareVer string `json:"firmwareVersion,omitempty"`
|
|
FlashedModel string `json:"flashedModel,omitempty"`
|
|
}
|
|
|
|
type DeviceStatus string
|
|
|
|
const (
|
|
StatusDetected DeviceStatus = "detected"
|
|
StatusConnecting DeviceStatus = "connecting"
|
|
StatusConnected DeviceStatus = "connected"
|
|
StatusFlashing DeviceStatus = "flashing"
|
|
StatusInferencing DeviceStatus = "inferencing"
|
|
StatusError DeviceStatus = "error"
|
|
StatusDisconnected DeviceStatus = "disconnected"
|
|
)
|
|
|
|
type FlashProgress struct {
|
|
Percent int `json:"percent"`
|
|
Stage string `json:"stage"`
|
|
Message string `json:"message,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
type InferenceResult struct {
|
|
DeviceID string `json:"deviceId,omitempty"`
|
|
ModelID string `json:"modelId,omitempty"`
|
|
TaskType string `json:"taskType"`
|
|
Timestamp int64 `json:"timestamp"`
|
|
LatencyMs float64 `json:"latencyMs"`
|
|
Classifications []ClassResult `json:"classifications,omitempty"`
|
|
Detections []DetectionResult `json:"detections,omitempty"`
|
|
|
|
// Batch image fields (omitted for single-image/camera/video modes)
|
|
ImageIndex int `json:"imageIndex,omitempty"`
|
|
TotalImages int `json:"totalImages,omitempty"`
|
|
Filename string `json:"filename,omitempty"`
|
|
|
|
// Video progress fields (omitted for non-video modes)
|
|
FrameIndex int `json:"frameIndex,omitempty"`
|
|
TotalFrames int `json:"totalFrames,omitempty"`
|
|
}
|
|
|
|
type ClassResult struct {
|
|
Label string `json:"label"`
|
|
Confidence float64 `json:"confidence"`
|
|
}
|
|
|
|
type DetectionResult struct {
|
|
Label string `json:"label"`
|
|
Confidence float64 `json:"confidence"`
|
|
BBox BBox `json:"bbox"`
|
|
}
|
|
|
|
type BBox struct {
|
|
X float64 `json:"x"`
|
|
Y float64 `json:"y"`
|
|
Width float64 `json:"width"`
|
|
Height float64 `json:"height"`
|
|
}
|
|
|
|
type ModelInfo struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
LoadedAt time.Time `json:"loadedAt"`
|
|
}
|