feat(mes): AGV挂起动作引擎 + 智能跟车流转 + PLC快照缓存(2026-11-19 主控拍板)
一、AGV 挂起动作引擎(弃显式任务队列、弃并发硬拒) - 新增 internal/logic/agv_pending.go:待发动作直接挂任务(pending_action + pending_since), CONTINUE_LIFT(举升完成→continueTask#1)/ WAIT_DROP_CONFIRM(人工确认放下→continueTask#2) / FREE_ROBOT(末组完成→freeRobot);系统动作超 60s 未触发转预警人工重试,绝不自动重发 - Client 新增 ContinueTask(RCS 2.1.2) / FreeRobot(3.1.2),仅点名释放指定车,禁止释放全部 - agv_task 增 pending_action/pending_since 字段,ent 重生成 + db.go 幂等迁移补丁 + migrateonce - 回调按 B01/B02/C01 模板编排:业务流转到位即自动放行放下、回调自动放车; 仅人工派车(MANUAL)挂 WAIT_DROP_CONFIRM;新增 /agv/confirm-drop、/agv/pending/retry - 前端 AgvManual/Agv 确认放下、挂起重试按钮与等待提示联动 二、智能跟车 + 动态目标截断流转引擎 - 新增 internal/logic/flow_engine.go:事件驱动(报工/扫码),读 48 位物理快照,从下游往上游算, 前方占用则动态截断到最近空闲缓存位;IN_TRANSIT 在途闭锁防重复下发,MW=0 才确认到位落台账; 主线占用=台账 OR 传感器,工位 G 位只认台账;在途超 5s 落预警 - workpiece 增 flow_transit_mw/target/at 字段,ent 重生成 + 迁移补丁 三、PLC 读取优化与诊断 - 新增 internal/plc/snapshot_cache.go:2s TTL + singleflight + 写失效,合并 SSE/PLC监控/流转引擎 的重复点位读取;tcp.go 读块重构、localip.go 多网卡、plcdiag 诊断工具、plc_monitor/logging 配套 四、文档与前端 - help.js 重写「工位下发」帮助:明确报工自动驱动流转 vs 下发路线码的定位、缺料/握手/撤回边界 - 案例.md 补充定稿说明;public/index.html 构建指纹更新
This commit is contained in:
@@ -12,21 +12,33 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// commTag 本机 IP 前缀(进程启动解析一次),断网排查时可一眼看出日志来自哪台机器。
|
||||
var commTag = netutil.Tag()
|
||||
|
||||
// logClient 日志装饰器:inner 为真实实现(s7Real / tcpClient / mock)。
|
||||
type logClient struct{ inner Client }
|
||||
// tag 为"[host=本机出口IP]",按实际连接 PLC 的目标地址做路由探测得出——多网卡机器上
|
||||
// 它精确指出"连 PLC 走的是哪块网卡的 IP",断网排查时不再被 APIPA 虚拟地址误导。
|
||||
type logClient struct {
|
||||
inner Client
|
||||
tag string
|
||||
}
|
||||
|
||||
func newLogClient(inner Client) *logClient { return &logClient{inner: inner} }
|
||||
// newLogClient 按 PLC 目标地址解析本机出口 IP。target 形如 "192.168.22.20:102";
|
||||
// 探测不到(如纯 mock 无目标)时回退到通用 netutil.Tag()。进程构造期算一次,不逐请求枚举。
|
||||
func newLogClient(inner Client, target string) *logClient {
|
||||
tag := netutil.Tag()
|
||||
if target != "" {
|
||||
if ip := netutil.LocalIPFor(target); ip != "" {
|
||||
tag = "[host=" + ip + "]"
|
||||
}
|
||||
}
|
||||
return &logClient{inner: inner, tag: tag}
|
||||
}
|
||||
|
||||
func (l *logClient) SendProcessCode(ctx context.Context, combination string) ([]int, error) {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" --> SendProcessCode combination=%s", combination)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" --> SendProcessCode combination=%s", combination)
|
||||
codes, err := l.inner.SendProcessCode(ctx, combination)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- SendProcessCode err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- SendProcessCode err=%v", err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- SendProcessCode codes=%v", codes)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- SendProcessCode codes=%v", codes)
|
||||
}
|
||||
return codes, err
|
||||
}
|
||||
@@ -34,24 +46,24 @@ func (l *logClient) SendProcessCode(ctx context.Context, combination string) ([]
|
||||
func (l *logClient) QueryDone(ctx context.Context) (bool, error) {
|
||||
done, err := l.inner.QueryDone(ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryDone err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- QueryDone err=%v", err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryDone done=%v", done)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- QueryDone done=%v", done)
|
||||
}
|
||||
return done, err
|
||||
}
|
||||
|
||||
func (l *logClient) AckDone(ctx context.Context, ok bool) {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" AckDone ok=%v", ok)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" AckDone ok=%v", ok)
|
||||
l.inner.AckDone(ctx, ok)
|
||||
}
|
||||
|
||||
func (l *logClient) QueryDockPallet(ctx context.Context, dockCode string) (bool, error) {
|
||||
has, err := l.inner.QueryDockPallet(ctx, dockCode)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryDockPallet dock=%s err=%v", dockCode, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- QueryDockPallet dock=%s err=%v", dockCode, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has)
|
||||
}
|
||||
return has, err
|
||||
}
|
||||
@@ -59,9 +71,9 @@ func (l *logClient) QueryDockPallet(ctx context.Context, dockCode string) (bool,
|
||||
func (l *logClient) QueryStationPallet(ctx context.Context, stationNo int) (bool, error) {
|
||||
has, err := l.inner.QueryStationPallet(ctx, stationNo)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryStationPallet station=%d err=%v", stationNo, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- QueryStationPallet station=%d err=%v", stationNo, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has)
|
||||
}
|
||||
return has, err
|
||||
}
|
||||
@@ -69,7 +81,7 @@ func (l *logClient) QueryStationPallet(ctx context.Context, stationNo int) (bool
|
||||
func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) {
|
||||
bits, err := l.inner.ReadBits(ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadBits err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- ReadBits err=%v", err)
|
||||
} else {
|
||||
// 48 位压成 0/1 字符串,一行可读
|
||||
s := make([]byte, len(bits))
|
||||
@@ -80,7 +92,7 @@ func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) {
|
||||
s[i] = '0'
|
||||
}
|
||||
}
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- ReadBits bits=%s", string(s))
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- ReadBits bits=%s", string(s))
|
||||
}
|
||||
return bits, err
|
||||
}
|
||||
@@ -88,9 +100,9 @@ func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) {
|
||||
func (l *logClient) ReadMW(ctx context.Context, addr int) (int, error) {
|
||||
v, err := l.inner.ReadMW(ctx, addr)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadMW MW%d err=%v", addr, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- ReadMW MW%d err=%v", addr, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- ReadMW MW%d=%d", addr, v)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- ReadMW MW%d=%d", addr, v)
|
||||
}
|
||||
return v, err
|
||||
}
|
||||
@@ -98,18 +110,18 @@ func (l *logClient) ReadMW(ctx context.Context, addr int) (int, error) {
|
||||
func (l *logClient) ReadMWBlock(ctx context.Context, start, count int) ([]int, error) {
|
||||
vals, err := l.inner.ReadMWBlock(ctx, start, count)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- ReadMWBlock MW%d..MW%d vals=%v", start, start+count-1, vals)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- ReadMWBlock MW%d..MW%d vals=%v", start, start+count-1, vals)
|
||||
}
|
||||
return vals, err
|
||||
}
|
||||
|
||||
func (l *logClient) WriteMW(ctx context.Context, addr, value int) error {
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" --> WriteMW MW%d=%d", addr, value)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" --> WriteMW MW%d=%d", addr, value)
|
||||
err := l.inner.WriteMW(ctx, addr, value)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- WriteMW MW%d=%d err=%v", addr, value, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- WriteMW MW%d=%d err=%v", addr, value, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user