From 4a58792c65485e9637496f5fd194e37fdcc3cdae Mon Sep 17 00:00:00 2001 From: walker Date: Wed, 13 Dec 2023 11:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E9=94=81=E9=A9=B1=E9=87=87=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=89=80=E5=B1=9E=E9=9B=86=E4=B8=AD=E7=AB=99id?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=92=8C=E6=9F=A5=E8=AF=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ci_qc.go | 21 +++++++++++++++++++-- component/singleton.go | 11 +++++++++++ entity/ci_qc.go | 5 +---- repository/repository.go | 9 +++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/component/ci_qc.go b/component/ci_qc.go index 35594b4..bf986c8 100644 --- a/component/ci_qc.go +++ b/component/ci_qc.go @@ -17,6 +17,7 @@ var ( // 联锁驱采数据表 type CiQcTable struct { + EcsUid string // 驱动码表 QdBits []*proto.QdData // 采集码表 @@ -25,6 +26,14 @@ type CiQcTable struct { QdIndex map[string]int } +func NewCiQcTable(ecsUid string, qdbits []*proto.QdData, cjbits []*proto.CjData) *CiQcTable { + return &CiQcTable{ + EcsUid: ecsUid, + QdBits: qdbits, + CjBits: cjbits, + } +} + func (qc *CiQcTable) BuildQcIndex() error { qc.QdIndex = make(map[string]int) for i, qd := range qc.QdBits { @@ -50,10 +59,18 @@ type CiQcState struct { } func NewCiQcState(qlen int, clen int) *CiQcState { + qbl := qlen / 8 + if qlen%8 != 0 { + qbl++ + } + cbl := clen / 8 + if clen%8 != 0 { + cbl++ + } return &CiQcState{ component_proto.CiQcState{ - Qbs: make([]byte, qlen), - Cbs: make([]byte, clen), + Qbs: make([]byte, qbl), + Cbs: make([]byte, cbl), }, } } diff --git a/component/singleton.go b/component/singleton.go index efad786..d01123e 100644 --- a/component/singleton.go +++ b/component/singleton.go @@ -83,6 +83,17 @@ func (wd *WorldData) SetQdBit(uid string, v bool) error { return fmt.Errorf("没有定义id=%s的继电器的驱动码表", uid) } +// 获取集中站id对应的联锁驱采实体 +func (wd *WorldData) FindQcEntityByEcsId(ecsId string) *ecs.Entry { + for _, entry := range wd.CiQcEntities { + qc := CiQcTableType.Get(entry) + if qc.EcsUid == ecsId { + return entry + } + } + return nil +} + type QdBitParam struct { Uid string Val bool diff --git a/entity/ci_qc.go b/entity/ci_qc.go index 608cee6..294e758 100644 --- a/entity/ci_qc.go +++ b/entity/ci_qc.go @@ -29,10 +29,7 @@ func LoadCiQC(w ecs.World) error { continue } entry := newCiQC(w, data) - qctable := &component.CiQcTable{ - QdBits: csr.QdList, - CjBits: csr.CjList, - } + qctable := component.NewCiQcTable(csr.StationId, csr.QdList, csr.CjList) err := qctable.BuildQcIndex() if err != nil { return err diff --git a/repository/repository.go b/repository/repository.go index d9f1c4e..4010269 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -256,6 +256,15 @@ func (repo *Repository) FindPhysicalSection(id string) *PhysicalSection { return repo.physicalSectionMap[id] } +func (repo *Repository) FindStationByStationName(name string) *Station { + for _, s := range repo.StationList() { + if s.code == name { + return s + } + } + return nil +} + func (repo *Repository) FindPsd(id string) *Psd { return repo.psdMap[id] }