fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"bj_power_mes/internal/robot"
|
||||
)
|
||||
|
||||
// ScannerTool 扫码器,实现 HandheldTool 接口
|
||||
// 通过 RobotManager 控制机器人执行扫码动作并读取扫码结果
|
||||
type ScannerTool struct {
|
||||
robotMgr *robot.Manager // 机器人管理器,用于控制扫码动作
|
||||
}
|
||||
|
||||
// NewScannerTool 创建扫码器工具
|
||||
func NewScannerTool(robotMgr *robot.Manager) *ScannerTool {
|
||||
return &ScannerTool{robotMgr: robotMgr}
|
||||
}
|
||||
|
||||
// ID 返回扫码器唯一标识
|
||||
func (t *ScannerTool) ID() string { return "scanner-1" }
|
||||
|
||||
// Type 返回工具类型编码
|
||||
func (t *ScannerTool) Type() string { return "SCANNER" }
|
||||
|
||||
// Name 返回工具显示名称
|
||||
func (t *ScannerTool) Name() string { return "扫码器" }
|
||||
|
||||
// Execute 执行扫码操作:启动扫码→读取结果→清除数据
|
||||
func (t *ScannerTool) Execute(ctx context.Context, cmd ToolCommand) error {
|
||||
wt := extractWorkpieceType(cmd.Params)
|
||||
round := 1
|
||||
if v, ok := cmd.Params["round"]; ok {
|
||||
if n, ok := v.(int); ok {
|
||||
round = n
|
||||
}
|
||||
}
|
||||
|
||||
rc, exist := t.robotMgr.GetRobot()
|
||||
if !exist || rc == nil {
|
||||
return fmt.Errorf("robot controller not available")
|
||||
}
|
||||
|
||||
slog.Info("scanner: start scan", "workpieceType", wt, "round", round)
|
||||
if err := rc.StartScanCode(ctx, wt, round); err != nil {
|
||||
return fmt.Errorf("start scan code: %w", err)
|
||||
}
|
||||
|
||||
code, err := t.robotMgr.ReadScanCodeData(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read scan code: %w", err)
|
||||
}
|
||||
|
||||
if clearErr := t.robotMgr.ClearScanCodeData(ctx); clearErr != nil {
|
||||
slog.Warn("scanner: failed to clear scan data", "error", clearErr)
|
||||
}
|
||||
|
||||
slog.Info("scanner: scan complete", "code", code)
|
||||
cmd.Params["scanCode"] = code
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user