feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图

This commit is contained in:
SunYF
2026-10-28 10:10:17 +08:00
parent 1f10c3091e
commit 4d3c4e2c3a
131 changed files with 18118 additions and 1728 deletions
+35 -6
View File
@@ -89,28 +89,40 @@ func (s *s7Real) readBlock(ctx context.Context) ([]byte, error) {
// readByte 读取单个 Merker 字节(用于 48 位块之外的完成信号位等)。
func (s *s7Real) readByte(ctx context.Context, byteOffset int) (byte, error) {
buf, err := s.readBytes(ctx, byteOffset, 1)
if err != nil {
return 0, err
}
return buf[0], nil
}
// readBytes 读任意 Merker 字节区间(带惰性连接与断线重连),供 ReadMWBlock 等批量读使用。
func (s *s7Real) readBytes(ctx context.Context, byteOffset, length int) ([]byte, error) {
if byteOffset < 0 || length <= 0 {
return nil, fmt.Errorf("非法读区间: offset=%d len=%d", byteOffset, length)
}
s.mu.Lock()
if err := s.ensure(); err != nil {
s.mu.Unlock()
return 0, err
return nil, err
}
cl := s.client
s.mu.Unlock()
buf := make([]byte, 1)
buf := make([]byte, length)
done := make(chan error, 1)
go func() { done <- cl.AGReadMB(byteOffset, 1, buf) }()
go func() { done <- cl.AGReadMB(byteOffset, length, buf) }()
select {
case <-ctx.Done():
return 0, ctx.Err()
return nil, ctx.Err()
case err := <-done:
if err != nil {
s.mu.Lock()
_ = s.handler.Close()
s.client = nil
s.mu.Unlock()
return 0, err
return nil, err
}
return buf[0], nil
return buf, nil
}
}
@@ -240,6 +252,23 @@ func (t *tcpClient) ReadMW(ctx context.Context, addr int) (int, error) {
return int(hi)<<8 | int(lo), nil
}
// ReadMWBlock 批量读连续 MW 寄存器(大端):一次 AGReadMB 读 count*2 字节,
// 避免逐地址读造成的 2*count 次 TCP 往返(看板快照用,MW800..MW887 一次取完)。
func (t *tcpClient) ReadMWBlock(ctx context.Context, start, count int) ([]int, error) {
if start < 0 || count <= 0 || start+count*2 > 65536 {
return nil, fmt.Errorf("非法 MW 批量读区间: start=%d count=%d", start, count)
}
buf, err := t.real.readBytes(ctx, start, count*2)
if err != nil {
return nil, err
}
out := make([]int, count)
for i := 0; i < count; i++ {
out[i] = int(buf[i*2])<<8 | int(buf[i*2+1])
}
return out, nil
}
// WriteMW 写 16 位寄存器(MW,大端):高字节写 addr、低字节写 addr+1。
func (t *tcpClient) WriteMW(ctx context.Context, addr, value int) error {
buf := []byte{byte(value >> 8), byte(value & 0xff)}