一、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 构建指纹更新
131 lines
4.6 KiB
Go
131 lines
4.6 KiB
Go
// logging.go PLC 全量交互日志装饰器(2026-11-16 联调)。
|
||
// 包装 Client 接口全部方法:调用参数、返回值、错误统一落 logx(前缀 [PLC])。
|
||
// 在 NewManager 处包一层,mock / 真实 S7(tcp.go) / tcp 自定义协议全部覆盖;
|
||
// tcp.go 为保护文件不做改动,日志在此层完成。
|
||
package plc
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
|
||
"bj_power_mes/internal/netutil"
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
)
|
||
|
||
// logClient 日志装饰器:inner 为真实实现(s7Real / tcpClient / mock)。
|
||
// tag 为"[host=本机出口IP]",按实际连接 PLC 的目标地址做路由探测得出——多网卡机器上
|
||
// 它精确指出"连 PLC 走的是哪块网卡的 IP",断网排查时不再被 APIPA 虚拟地址误导。
|
||
type logClient struct {
|
||
inner Client
|
||
tag string
|
||
}
|
||
|
||
// 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]"+l.tag+" --> SendProcessCode combination=%s", combination)
|
||
codes, err := l.inner.SendProcessCode(ctx, combination)
|
||
if err != nil {
|
||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- SendProcessCode err=%v", err)
|
||
} else {
|
||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- SendProcessCode codes=%v", codes)
|
||
}
|
||
return codes, err
|
||
}
|
||
|
||
func (l *logClient) QueryDone(ctx context.Context) (bool, error) {
|
||
done, err := l.inner.QueryDone(ctx)
|
||
if err != nil {
|
||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- QueryDone err=%v", err)
|
||
} else {
|
||
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]"+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]"+l.tag+" <-- QueryDockPallet dock=%s err=%v", dockCode, err)
|
||
} else {
|
||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has)
|
||
}
|
||
return has, err
|
||
}
|
||
|
||
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]"+l.tag+" <-- QueryStationPallet station=%d err=%v", stationNo, err)
|
||
} else {
|
||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has)
|
||
}
|
||
return has, err
|
||
}
|
||
|
||
func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) {
|
||
bits, err := l.inner.ReadBits(ctx)
|
||
if err != nil {
|
||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- ReadBits err=%v", err)
|
||
} else {
|
||
// 48 位压成 0/1 字符串,一行可读
|
||
s := make([]byte, len(bits))
|
||
for i, b := range bits {
|
||
if b {
|
||
s[i] = '1'
|
||
} else {
|
||
s[i] = '0'
|
||
}
|
||
}
|
||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- ReadBits bits=%s", string(s))
|
||
}
|
||
return bits, err
|
||
}
|
||
|
||
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]"+l.tag+" <-- ReadMW MW%d err=%v", addr, err)
|
||
} else {
|
||
logx.WithContext(ctx).Infof("[PLC]"+l.tag+" <-- ReadMW MW%d=%d", addr, v)
|
||
}
|
||
return v, err
|
||
}
|
||
|
||
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]"+l.tag+" <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err)
|
||
} else {
|
||
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]"+l.tag+" --> WriteMW MW%d=%d", addr, value)
|
||
err := l.inner.WriteMW(ctx, addr, value)
|
||
if err != nil {
|
||
logx.WithContext(ctx).Errorf("[PLC]"+l.tag+" <-- WriteMW MW%d=%d err=%v", addr, value, err)
|
||
}
|
||
return err
|
||
}
|
||
|
||
// String 满足调试打印。
|
||
func (l *logClient) String() string { return fmt.Sprintf("logClient(%T)", l.inner) }
|