signal 3xh3 驱采

This commit is contained in:
xzb 2023-10-12 15:13:13 +08:00
parent ae3495ce62
commit 6a9b48b4d3
7 changed files with 111 additions and 46 deletions

View File

@ -17,6 +17,7 @@ var (
UdTag = ecs.NewTag() //黄 UdTag = ecs.NewTag() //黄
BdTag = ecs.NewTag() //白 BdTag = ecs.NewTag() //白
AdTag = ecs.NewTag() //蓝 AdTag = ecs.NewTag() //蓝
FdTag = ecs.NewTag() //封,封灯显示
) )
// 组件 // 组件

View File

@ -170,12 +170,34 @@ type Signal3XH3Electronic struct {
Z3XH3_LXJ *ecs.Entry Z3XH3_LXJ *ecs.Entry
//引导信号继电器true-吸合 //引导信号继电器true-吸合
Z3XH3_YXJ *ecs.Entry Z3XH3_YXJ *ecs.Entry
// 物理黄灯true-亮 }
Z3XH3_U *ecs.Entry
// 物理红灯true-亮 // Signal3XH3Lsq 联锁驱
Z3XH3_H *ecs.Entry type Signal3XH3Lsq struct {
//true-联锁施加励磁电流驱动继电器DDJ
Z3XH3_DDJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH3_LXJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH3_YXJ_Q bool
}
// Signal3XH3Lsc 联锁采
type Signal3XH3Lsc struct {
//true-继电器DJ吸起
Z3XH3_DJ_Xq bool
//true-继电器2DJ吸起
Z3XH3_2DJ_Xq bool
//true-继电器DDJ落下
Z3XH3_DDJ_Lx bool
//true-继电器LXJ吸起
Z3XH3_LXJ_Xq bool
//true-继电器YXJ吸起
Z3XH3_YXJ_Xq bool
} }
var ( var (
Signal3XH3ElectronicType = ecs.NewComponentType[Signal3XH3Electronic]() Signal3XH3ElectronicType = ecs.NewComponentType[Signal3XH3Electronic]()
Signal3XH3LsqType = ecs.NewComponentType[Signal3XH3Lsq]()
Signal3XH3LscType = ecs.NewComponentType[Signal3XH3Lsc]()
) )

View File

@ -55,3 +55,12 @@ func NewLights(w ecs.World, lightTags ...component.DsTag) []*ecs.Entry {
} }
return ls return ls
} }
// IsLightFd 灯是否被封(如Signal 3xh3 红绿黄三显示封绿灯)
func IsLightFd(lightEntry *ecs.Entry) bool {
if lightEntry.HasComponent(component.LightDriveType) && lightEntry.HasComponent(component.BitStateType) {
return lightEntry.HasComponent(component.FdTag)
} else {
panic("IsLightFd 参数lightEntry的值非灯实体")
}
}

View File

@ -12,6 +12,9 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 5 { //3xh3组合类型包含5个继电器 if len(elecs) == 5 { //3xh3组合类型包含5个继电器
signalEntry.AddComponent(component.Signal3XH3ElectronicType) signalEntry.AddComponent(component.Signal3XH3ElectronicType)
signalEntry.AddComponent(component.Signal3XH3LsqType)
signalEntry.AddComponent(component.Signal3XH3LscType)
signalEntry.AddComponent(component.SignalLightsType)
// //
elecState := &component.Signal3XH3Electronic{} elecState := &component.Signal3XH3Electronic{}
for _, elec := range elecs { for _, elec := range elecs {
@ -32,6 +35,11 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
} }
// //
component.Signal3XH3ElectronicType.Set(signalEntry, elecState) component.Signal3XH3ElectronicType.Set(signalEntry, elecState)
component.Signal3XH3LsqType.Set(signalEntry, &component.Signal3XH3Lsq{})
component.Signal3XH3LscType.Set(signalEntry, &component.Signal3XH3Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
//封绿灯,即有绿灯但绿被封
component.SignalLightsType.Get(signalEntry).GetLightByTag(component.LdTag).AddComponent(component.FdTag)
} else { } else {
return fmt.Errorf("id=[%s]的信号机3xh3电子元器件数量须为5", signal.Id()) return fmt.Errorf("id=[%s]的信号机3xh3电子元器件数量须为5", signal.Id())
} }

View File

@ -15,11 +15,8 @@ func DriveSignal3XH3Dd(w ecs.World, signalId string, dd bool) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH3ElectronicType.Get(signalEntry) lsq := component.Signal3XH3LsqType.Get(signalEntry)
driveDd := component.RelayDriveType.Get(state.Z3XH3_DDJ) lsq.Z3XH3_DDJ_Q = !dd
//点灯继电器落下时才点灯
driveDd.Td = !dd
driveDd.Xq = !dd
} }
}) })
} }
@ -30,13 +27,9 @@ func DriveSignal3XH3Lx(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH3ElectronicType.Get(signalEntry) lsq := component.Signal3XH3LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) lsq.Z3XH3_LXJ_Q = true
driveLx.Td = true lsq.Z3XH3_YXJ_Q = false
driveLx.Xq = true
driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }
@ -47,13 +40,9 @@ func DriveSignal3XH3Yx(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH3ElectronicType.Get(signalEntry) lsq := component.Signal3XH3LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) lsq.Z3XH3_LXJ_Q = false
driveLx.Td = false lsq.Z3XH3_YXJ_Q = true
driveLx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ)
driveYx.Td = true
driveYx.Xq = true
} }
}) })
} }
@ -64,13 +53,9 @@ func DriveSignal3XH3Non(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH3ElectronicType.Get(signalEntry) lsq := component.Signal3XH3LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) lsq.Z3XH3_LXJ_Q = false
driveLx.Td = false lsq.Z3XH3_YXJ_Q = false
driveLx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }

@ -1 +1 @@
Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c Subproject commit 1c6eed67ea95b41e7b3cae7375f0f740202fd22b

View File

@ -16,49 +16,89 @@ func NewSignal3XH3System() *Signal3XH3System {
// Update world 执行 // Update world 执行
func (s *Signal3XH3System) Update(w ecs.World) { func (s *Signal3XH3System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal3XH3ElectronicType.Get(e) state := component.Signal3XH3ElectronicType.Get(entry)
lsq := component.Signal3XH3LsqType.Get(entry)
lsc := component.Signal3XH3LscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
Z3XH3_H := lights.GetLightByTag(component.HdTag)
Z3XH3_U := lights.GetLightByTag(component.UdTag)
// //
s.calculateU(state) s.calculateLsq(state, lsq)
s.calculateH(state) s.calculateU(state, Z3XH3_U)
s.calculateDJ(state) s.calculateH(state, Z3XH3_H)
s.calculate2DJ(state) s.calculateDJ(state, Z3XH3_U, Z3XH3_H)
s.calculate2DJ(state, Z3XH3_U)
s.calculateLsc(state, lsc)
}) })
} }
func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic) { // 联锁驱
func (s *Signal3XH3System) calculateLsq(state *component.Signal3XH3Electronic, lsq *component.Signal3XH3Lsq) {
ddj := component.RelayDriveType.Get(state.Z3XH3_DDJ)
lxj := component.RelayDriveType.Get(state.Z3XH3_LXJ)
yxj := component.RelayDriveType.Get(state.Z3XH3_YXJ)
//
ddjQ := lsq.Z3XH3_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z3XH3_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
yxjQ := lsq.Z3XH3_YXJ_Q
yxj.Td = yxjQ
yxj.Xq = yxjQ
}
// 联锁采
func (s *Signal3XH3System) calculateLsc(state *component.Signal3XH3Electronic, lsc *component.Signal3XH3Lsc) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
edj := component.BitStateType.Get(state.Z3XH3_2DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
//
lsc.Z3XH3_2DJ_Xq = edj.Val
lsc.Z3XH3_DJ_Xq = dj.Val
lsc.Z3XH3_DDJ_Lx = !ddj.Val
lsc.Z3XH3_LXJ_Xq = lxj.Val
lsc.Z3XH3_YXJ_Xq = yxj.Val
}
func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ) ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ) dj := component.BitStateType.Get(state.Z3XH3_DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ) yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val
driveU := component.LightDriveType.Get(state.Z3XH3_U) driveU := component.LightDriveType.Get(Z3XH3_U)
driveU.Td = isU driveU.Td = isU
} }
func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic) { func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic, Z3XH3_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ) ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
isH := !ddj.Val && !lxj.Val isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(state.Z3XH3_H) driveH := component.LightDriveType.Get(Z3XH3_H)
driveH.Td = isH driveH.Td = isH
} }
func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic) { func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry, Z3XH3_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ) ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
ud := component.BitStateType.Get(state.Z3XH3_U) ud := component.BitStateType.Get(Z3XH3_U)
hd := component.BitStateType.Get(state.Z3XH3_H) hd := component.BitStateType.Get(Z3XH3_H)
isDJ := ud.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val isDJ := ud.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_DJ) drive := component.RelayDriveType.Get(state.Z3XH3_DJ)
drive.Td = isDJ drive.Td = isDJ
drive.Xq = isDJ drive.Xq = isDJ
} }
func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic) { func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ) ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ) dj := component.BitStateType.Get(state.Z3XH3_DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ) yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
ud := component.BitStateType.Get(state.Z3XH3_U) ud := component.BitStateType.Get(Z3XH3_U)
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_2DJ) drive := component.RelayDriveType.Get(state.Z3XH3_2DJ)
drive.Td = is2DJ drive.Td = is2DJ