2023-11-03 17:26:32 +08:00
|
|
|
package component
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"joylink.club/ecs"
|
2024-01-10 10:57:47 +08:00
|
|
|
"joylink.club/rtsssimulation/component/component_data"
|
2023-11-03 17:26:32 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// 驱采表引用
|
|
|
|
CiQcTableType = ecs.NewComponentType[CiQcTable]()
|
|
|
|
// 联锁驱动、采集状态表
|
|
|
|
CiQcStateType = ecs.NewComponentType[CiQcState]()
|
|
|
|
)
|
|
|
|
|
|
|
|
// 联锁驱采数据表
|
|
|
|
type CiQcTable struct {
|
2023-12-13 11:21:13 +08:00
|
|
|
EcsUid string
|
2023-11-03 17:26:32 +08:00
|
|
|
// 驱动码表
|
|
|
|
QdBits []*proto.QdData
|
|
|
|
// 采集码表
|
|
|
|
CjBits []*proto.CjData
|
|
|
|
// 驱动索引
|
|
|
|
QdIndex map[string]int
|
|
|
|
}
|
|
|
|
|
2023-12-13 11:21:13 +08:00
|
|
|
func NewCiQcTable(ecsUid string, qdbits []*proto.QdData, cjbits []*proto.CjData) *CiQcTable {
|
|
|
|
return &CiQcTable{
|
|
|
|
EcsUid: ecsUid,
|
|
|
|
QdBits: qdbits,
|
|
|
|
CjBits: cjbits,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:26:32 +08:00
|
|
|
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 {
|
2024-01-10 10:57:47 +08:00
|
|
|
component_data.CiQcState
|
2023-11-03 17:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCiQcState(qlen int, clen int) *CiQcState {
|
2023-12-13 11:21:13 +08:00
|
|
|
qbl := qlen / 8
|
|
|
|
if qlen%8 != 0 {
|
|
|
|
qbl++
|
|
|
|
}
|
|
|
|
cbl := clen / 8
|
|
|
|
if clen%8 != 0 {
|
|
|
|
cbl++
|
|
|
|
}
|
2023-11-03 17:26:32 +08:00
|
|
|
return &CiQcState{
|
2024-01-10 10:57:47 +08:00
|
|
|
component_data.CiQcState{
|
2023-12-13 11:21:13 +08:00
|
|
|
Qbs: make([]byte, qbl),
|
|
|
|
Cbs: make([]byte, cbl),
|
2023-11-03 17:26:32 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|