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] }