双机zdj9道岔测试

This commit is contained in:
xzb 2023-09-15 14:06:23 +08:00
parent 529017d54b
commit c5c8e0993c
3 changed files with 224 additions and 208 deletions

View File

@ -1,212 +1,7 @@
package main package main
import ( import "joylink.club/rtsssimulation/examples/test1/sjzdj9"
"fmt"
sysEvent "joylink.club/rtsssimulation/system/event"
"time"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/entities"
"joylink.club/rtsssimulation/examples/test1/tmodel"
"joylink.club/rtsssimulation/examples/test1/tstorages"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
func main() { func main() {
//模型仓库 sjzdj9.Test()
modelStorage := tstorages.NewModelStorage()
addRelays(modelStorage)
addSwitchs(modelStorage)
worldStorage := &tstorages.WorldModelStorage{Share: modelStorage, Links: tstorages.NewModelStorage()}
//
worldConfig := simulation.WorldConfig{
ModelManager: worldStorage,
Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()},
Tick: 100,
InitTime: time.Now(),
}
world := simulation.InitializeWorld(&worldConfig)
addEntities(world, modelStorage)
initComponents(world)
//
//ecs.EventsDebugEnable()
//
system.Switch2jzdj9AddListeners(world)
system.RelayAddListeners(world)
//
world.StartUp()
time.Sleep(1 * time.Second)
//反操
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-ycj", Xh: true})
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-fcj", Xh: true})
//
time.Sleep(10 * time.Second)
world.Close()
}
func addEntities(w ecs.World, modelStorage *tstorages.ModelStorage) {
modelStorage.ForEachModelsByType(umi.Switch, func(md tstorages.ModelData) {
entities.CreateSwitch2jzdj9Entity(w, md.GetId())
})
modelStorage.ForEachModelsByType(umi.Relay, func(md tstorages.ModelData) {
entities.CreateRelayEntity(w, md.GetId())
})
}
// //////////////////////////////////////////////////////////////////
func addRelays(modelStorage *tstorages.ModelStorage) {
//道岔sw1,双机zdj9
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-dcj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-fcj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-ycj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zdbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zfbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqj", umi.JWJXC_H125_80))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-bhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-2dqj", umi.JYJXC_160_260))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqjf", umi.JWJXC_480))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-dbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-fbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-qdj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-zbhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqj", umi.JWJXC_H125_80))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-bhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-2dqj", umi.JYJXC_160_260))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqjf", umi.JWJXC_480))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-dbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-fbj", umi.JPXC_1000))
}
func findRelayModel(modelStorage *tstorages.ModelStorage, id string) umi.IRelayModel {
return modelStorage.FindModelById(id).(umi.IRelayModel)
}
func addSwitchs(modelStorage *tstorages.ModelStorage) {
sw1 := tmodel.NewSwitchModel("sw1")
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_DCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-dcj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_FCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-fcj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_YCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-ycj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZDBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zdbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZFBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zfbj")})
//
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-bhj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-2dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqjf")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-dbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-fbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_QDJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-qdj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_ZBHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-zbhj")})
//
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-bhj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-2dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqjf")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-dbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-fbj")})
//
modelStorage.AddModel(sw1)
}
// 初始化组件状态
func initComponents(w ecs.World) {
//双机zdj9道岔相关继电器的状态初始化
switchQuery := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent))
switchQuery.Each(w, func(e *ecs.Entry) {
swId := system.EntityIdentityComponent.Get(e).Id
swState := system.Switch2jZdj9StateComponent.Get(e)
swMd := system.FindModelStorage(w).FindById(swId).(*tmodel.SwitchModel)
for _, relay := range swMd.Relays {
relayId := relay.Relay.(umi.IDeviceModel).GetId()
relayEntry := system.FindEntityById(w, relayId)
relayState := system.RelayStateComponent.Get(relayEntry)
relayGroup := relay.RelayGroup
relayName := relay.RelayName
switch relayGroup {
case system.SJZDJ9_TDC:
{
switch relayName {
case system.SJZDJ9_DCJ:
relayState.Xh = swState.DCJ
relayState.ResetNeedXh()
case system.SJZDJ9_FCJ:
relayState.Xh = swState.FCJ
relayState.ResetNeedXh()
case system.SJZDJ9_YCJ:
relayState.Xh = swState.YCJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZDBJ:
relayState.Xh = swState.ZDBJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZFBJ:
relayState.Xh = swState.ZFBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ1:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J1_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J1_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J1_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J1_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J1_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J1_FBJ
relayState.ResetNeedXh()
case system.SJZDJ9_QDJ:
relayState.Xh = swState.J1_QDJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZBHJ:
relayState.Xh = swState.J1_ZBHJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ2:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J2_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J2_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J2_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J2_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J2_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J2_FBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", swId, relayGroup))
}
} //for
})
} }

View File

@ -0,0 +1,221 @@
package sjzdj9
import (
"fmt"
sysEvent "joylink.club/rtsssimulation/system/event"
"time"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/entities"
"joylink.club/rtsssimulation/examples/test1/tmodel"
"joylink.club/rtsssimulation/examples/test1/tstorages"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// Test 测试双机ZDJ9道岔
func Test() {
//模型仓库
modelStorage := tstorages.NewModelStorage()
addRelays(modelStorage)
addSwitchs(modelStorage)
worldStorage := &tstorages.WorldModelStorage{Share: modelStorage, Links: tstorages.NewModelStorage()}
//
worldConfig := simulation.WorldConfig{
ModelManager: worldStorage,
Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()},
Tick: 100,
InitTime: time.Now(),
}
world := simulation.InitializeWorld(&worldConfig)
addEntities(world, modelStorage)
initComponents(world)
//
//ecs.EventsDebugEnable()
//
system.Switch2jzdj9AddListeners(world)
system.RelayAddListeners(world)
//
world.StartUp()
time.Sleep(1 * time.Second)
//反操
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-ycj", Xh: true})
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-fcj", Xh: true})
//
time.Sleep(8 * time.Second)
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-ycj", Xh: false})
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-fcj", Xh: false})
time.Sleep(1 * time.Second)
//定操
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-ycj", Xh: true})
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-dcj", Xh: true})
//
time.Sleep(8 * time.Second)
world.Close()
}
func addEntities(w ecs.World, modelStorage *tstorages.ModelStorage) {
modelStorage.ForEachModelsByType(umi.Switch, func(md tstorages.ModelData) {
entities.CreateSwitch2jzdj9Entity(w, md.GetId())
})
modelStorage.ForEachModelsByType(umi.Relay, func(md tstorages.ModelData) {
entities.CreateRelayEntity(w, md.GetId())
})
}
// //////////////////////////////////////////////////////////////////
func addRelays(modelStorage *tstorages.ModelStorage) {
//道岔sw1,双机zdj9
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-dcj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-fcj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-ycj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zdbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zfbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqj", umi.JWJXC_H125_80))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-bhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-2dqj", umi.JYJXC_160_260))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqjf", umi.JWJXC_480))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-dbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-fbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-qdj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-zbhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqj", umi.JWJXC_H125_80))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-bhj", umi.JWXC_1700))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-2dqj", umi.JYJXC_160_260))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqjf", umi.JWJXC_480))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-dbj", umi.JPXC_1000))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-fbj", umi.JPXC_1000))
}
func findRelayModel(modelStorage *tstorages.ModelStorage, id string) umi.IRelayModel {
return modelStorage.FindModelById(id).(umi.IRelayModel)
}
func addSwitchs(modelStorage *tstorages.ModelStorage) {
sw1 := tmodel.NewSwitchModel("sw1")
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_DCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-dcj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_FCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-fcj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_YCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-ycj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZDBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zdbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZFBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zfbj")})
//
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-bhj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-2dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqjf")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-dbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-fbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_QDJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-qdj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_ZBHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-zbhj")})
//
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-bhj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-2dqj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqjf")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-dbj")})
sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-fbj")})
//
modelStorage.AddModel(sw1)
}
// 初始化组件状态
func initComponents(w ecs.World) {
//双机zdj9道岔相关继电器的状态初始化
switchQuery := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent))
switchQuery.Each(w, func(e *ecs.Entry) {
swId := system.EntityIdentityComponent.Get(e).Id
swState := system.Switch2jZdj9StateComponent.Get(e)
swMd := system.FindModelStorage(w).FindById(swId).(*tmodel.SwitchModel)
for _, relay := range swMd.Relays {
relayId := relay.Relay.(umi.IDeviceModel).GetId()
relayEntry := system.FindEntityById(w, relayId)
relayState := system.RelayStateComponent.Get(relayEntry)
relayGroup := relay.RelayGroup
relayName := relay.RelayName
switch relayGroup {
case system.SJZDJ9_TDC:
{
switch relayName {
case system.SJZDJ9_DCJ:
relayState.Xh = swState.DCJ
relayState.ResetNeedXh()
case system.SJZDJ9_FCJ:
relayState.Xh = swState.FCJ
relayState.ResetNeedXh()
case system.SJZDJ9_YCJ:
relayState.Xh = swState.YCJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZDBJ:
relayState.Xh = swState.ZDBJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZFBJ:
relayState.Xh = swState.ZFBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ1:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J1_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J1_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J1_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J1_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J1_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J1_FBJ
relayState.ResetNeedXh()
case system.SJZDJ9_QDJ:
relayState.Xh = swState.J1_QDJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZBHJ:
relayState.Xh = swState.J1_ZBHJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ2:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J2_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J2_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J2_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J2_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J2_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J2_FBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", swId, relayGroup))
}
} //for
})
}

View File

@ -20,6 +20,6 @@ func (debug *DebugSystem) Update(w ecs.World) {
swState := Switch2jZdj9StateComponent.Get(entry) swState := Switch2jZdj9StateComponent.Get(entry)
//log.Println(fmt.Sprintf("==>>2JZDJ9=%s QDJ=%t j1-2DQJ=%t j2-2DQJ=%t", swId, swState.J1_QDJ, swState.J1_2DQJ, swState.J2_2DQJ)) //log.Println(fmt.Sprintf("==>>2JZDJ9=%s QDJ=%t j1-2DQJ=%t j2-2DQJ=%t", swId, swState.J1_QDJ, swState.J1_2DQJ, swState.J2_2DQJ))
//log.Println(fmt.Sprintf("==>>2JZDJ9=%s j1-1DQJ=%t j2-1DQJ=%t", swId, swState.J1_1DQJ, swState.J2_1DQJ)) //log.Println(fmt.Sprintf("==>>2JZDJ9=%s j1-1DQJ=%t j2-1DQJ=%t", swId, swState.J1_1DQJ, swState.J2_1DQJ))
log.Println(fmt.Sprintf("==>>2JZDJ9=%s YCJ=%t DCJ=%t FCJ=%t ZDBJ=%t ZFBJ=%t", swId, swState.YCJ, swState.DCJ, swState.FCJ, swState.ZDBJ, swState.ZFBJ)) log.Println(fmt.Sprintf("==>>2JZDJ9=%s YCJ=%t DCJ=%t FCJ=%t j1-2DQJ=%t j2-2DQJ=%t ZDBJ=%t ZFBJ=%t", swId, swState.YCJ, swState.DCJ, swState.FCJ, swState.J1_2DQJ, swState.J2_2DQJ, swState.ZDBJ, swState.ZFBJ))
}) })
} }