64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
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 {
|
|
// 驱动码表
|
|
QdBits []*proto.QdData
|
|
// 采集码表
|
|
CjBits []*proto.CjData
|
|
// 驱动索引
|
|
QdIndex map[string]int
|
|
}
|
|
|
|
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 {
|
|
return &CiQcState{
|
|
component_proto.CiQcState{
|
|
Qbs: make([]byte, qlen),
|
|
Cbs: make([]byte, clen),
|
|
},
|
|
}
|
|
}
|
|
|
|
func GetCiQdBitOfRelay(ci *ecs.Entry, uid string) (bool, error) {
|
|
return false, nil
|
|
}
|