feat: AGV状态实时推送与受控异常处置 + rcs-dps状态接口独立配置与日志落盘修复
This commit is contained in:
@@ -8,21 +8,25 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"bj_power_mes/internal/netutil"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// commTag 本机 IP 前缀(进程启动解析一次),断网排查时可一眼看出日志来自哪台机器。
|
||||
var commTag = netutil.Tag()
|
||||
|
||||
// logClient 日志装饰器:inner 为真实实现(s7Real / tcpClient / mock)。
|
||||
type logClient struct{ inner Client }
|
||||
|
||||
func newLogClient(inner Client) *logClient { return &logClient{inner: inner} }
|
||||
|
||||
func (l *logClient) SendProcessCode(ctx context.Context, combination string) ([]int, error) {
|
||||
logx.WithContext(ctx).Infof("[PLC] --> SendProcessCode combination=%s", combination)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" --> SendProcessCode combination=%s", combination)
|
||||
codes, err := l.inner.SendProcessCode(ctx, combination)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC] <-- SendProcessCode err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- SendProcessCode err=%v", err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- SendProcessCode codes=%v", codes)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- SendProcessCode codes=%v", codes)
|
||||
}
|
||||
return codes, err
|
||||
}
|
||||
@@ -30,24 +34,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] <-- QueryDone err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryDone err=%v", err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- QueryDone done=%v", done)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryDone done=%v", done)
|
||||
}
|
||||
return done, err
|
||||
}
|
||||
|
||||
func (l *logClient) AckDone(ctx context.Context, ok bool) {
|
||||
logx.WithContext(ctx).Infof("[PLC] AckDone ok=%v", ok)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" 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] <-- QueryDockPallet dock=%s err=%v", dockCode, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryDockPallet dock=%s err=%v", dockCode, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has)
|
||||
}
|
||||
return has, err
|
||||
}
|
||||
@@ -55,9 +59,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] <-- QueryStationPallet station=%d err=%v", stationNo, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- QueryStationPallet station=%d err=%v", stationNo, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has)
|
||||
}
|
||||
return has, err
|
||||
}
|
||||
@@ -65,7 +69,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] <-- ReadBits err=%v", err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadBits err=%v", err)
|
||||
} else {
|
||||
// 48 位压成 0/1 字符串,一行可读
|
||||
s := make([]byte, len(bits))
|
||||
@@ -76,7 +80,7 @@ func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) {
|
||||
s[i] = '0'
|
||||
}
|
||||
}
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- ReadBits bits=%s", string(s))
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- ReadBits bits=%s", string(s))
|
||||
}
|
||||
return bits, err
|
||||
}
|
||||
@@ -84,9 +88,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] <-- ReadMW MW%d err=%v", addr, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadMW MW%d err=%v", addr, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- ReadMW MW%d=%d", addr, v)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- ReadMW MW%d=%d", addr, v)
|
||||
}
|
||||
return v, err
|
||||
}
|
||||
@@ -94,18 +98,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] <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err)
|
||||
} else {
|
||||
logx.WithContext(ctx).Infof("[PLC] <-- ReadMWBlock MW%d..MW%d vals=%v", start, start+count-1, vals)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" <-- 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] --> WriteMW MW%d=%d", addr, value)
|
||||
logx.WithContext(ctx).Infof("[PLC]"+commTag+" --> WriteMW MW%d=%d", addr, value)
|
||||
err := l.inner.WriteMW(ctx, addr, value)
|
||||
if err != nil {
|
||||
logx.WithContext(ctx).Errorf("[PLC] <-- WriteMW MW%d=%d err=%v", addr, value, err)
|
||||
logx.WithContext(ctx).Errorf("[PLC]"+commTag+" <-- WriteMW MW%d=%d err=%v", addr, value, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user