package component import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component/component_proto" "joylink.club/rtsssimulation/repository/model/proto" ) var ( // 驱采表引用 CiQcTableType = ecs.NewComponentType[CiQcTable]() // 联锁驱动、采集状态表 CiQcStateType = ecs.NewComponentType[CiQcState]() ) // 联锁驱采数据表 type CiQcTable struct { EcsUid string // 驱动码表 QdBits []*proto.QdData // 采集码表 CjBits []*proto.CjData // 驱动索引 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 { if len(qd.RefRelays) > 0 { key := qd.RefRelays[0] if _, ok := qc.QdIndex[key]; ok { return fmt.Errorf("联锁驱动数据重复,驱动码表存在多个相同继电器: '%s'", key) } else { qc.QdIndex[key] = i } } } return nil } func (qc *CiQcTable) QueryQdIndex(uid string) (int, bool) { idx, ok := qc.QdIndex[uid] return idx, ok } type CiQcState struct { component_proto.CiQcState } 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, qbl), Cbs: make([]byte, cbl), }, } }