feat: 重构 AGV 对接与在制品查询,新增 PLC 手动监控功能

This commit is contained in:
SunYF
2026-10-17 17:49:47 +08:00
parent f65a52d9e1
commit f743cf21fb
96 changed files with 6130 additions and 1781 deletions
+65 -1
View File
@@ -3,6 +3,7 @@ package plc
import (
"context"
"errors"
"fmt"
"sync"
)
@@ -16,10 +17,30 @@ type mockClient struct {
// stationPallet 模拟工位托盘位是否有件(PLC↔MES 对账用):key=工位号,默认全部无件;
// 联调/自测时可用 SetStationPallet 置位,模拟“PLC 说有位、MES 说无工件”的 mismatch 场景。
stationPallet map[int]bool
// bits 模拟 48 位点位信号(§4.1):[0..11]G1..G12 [12..26]C1..C15 [27..46]DOCK01..DOCK20 [47]JBT21
bits []bool
// mw 模拟 MW 寄存器当前值(§4.4 覆盖的 MW800..MW886)
mw map[int]int
// mBytes 模拟任意 Merker 字节(强制写 M 位用):key=字节偏移,默认全 0
mBytes map[int]byte
}
func newMockClient() *mockClient {
return &mockClient{dockPallet: map[string]bool{}, stationPallet: map[int]bool{}}
m := &mockClient{
dockPallet: map[string]bool{},
stationPallet: map[int]bool{},
bits: make([]bool, 48),
mw: map[int]int{},
mBytes: map[int]byte{},
}
// 预置若干点位为“有托盘”,便于手动监控页 mock 演示 48 位状态展示(●/○ 混合)
for _, i := range []int{0, 1, 12, 13, 14, 27, 28, 29, 47} {
m.bits[i] = true
}
// 预置两条在途指令(MW 非0),便于演示 2.2 动作类信号解析(非0即解析 源→目标)
m.mw[800] = 105 // MW800 = 105 → G1 → C5(A 类)
m.mw[872] = 305 // MW872 = 305 → C3 → C5(D 类)
return m
}
// SetDockPallet 手动设置某接驳台是否有托盘(供联调/测试用)
@@ -66,4 +87,47 @@ func (m *mockClient) QueryStationPallet(_ context.Context, stationNo int) (bool,
m.mu.RLock()
defer m.mu.RUnlock()
return m.stationPallet[stationNo], nil
}
// ReadBits 读 48 位点位信号(mock):返回内存态位数组。
func (m *mockClient) ReadBits(_ context.Context) ([]bool, error) {
m.mu.RLock()
defer m.mu.RUnlock()
out := make([]bool, len(m.bits))
copy(out, m.bits)
return out, nil
}
// ReadMW 读 16 位寄存器(mock):返回内存态 MW 值,缺省 0。
func (m *mockClient) ReadMW(_ context.Context, addr int) (int, error) {
m.mu.RLock()
defer m.mu.RUnlock()
return m.mw[addr], nil
}
// WriteMW 写 16 位寄存器(mock):写入内存态 MW,供手动下发演示。
func (m *mockClient) WriteMW(_ context.Context, addr, value int) error {
m.mu.Lock()
defer m.mu.Unlock()
m.mw[addr] = value
return nil
}
// WriteBit 强制写单个 M 位(mock):读写内存态 mBytes,返回写前/写后值。
func (m *mockClient) WriteBit(_ context.Context, merkerByte, merkerBit int, on bool) (before, after bool, err error) {
if merkerByte < 0 || merkerBit < 0 || merkerBit > 7 {
return false, false, fmt.Errorf("非法的 M 位:MB%d.%d", merkerByte, merkerBit)
}
m.mu.Lock()
defer m.mu.Unlock()
cur := m.mBytes[merkerByte]
before = cur&(1<<merkerBit) != 0
if on {
cur |= 1 << merkerBit
} else {
cur &^= 1 << merkerBit
}
m.mBytes[merkerByte] = cur
after = cur&(1<<merkerBit) != 0
return before, after, nil
}