2023-09-15 14:06:23 +08:00
|
|
|
package sjzdj9
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-09-26 10:49:22 +08:00
|
|
|
"joylink.club/rtsssimulation/examples/test1/tinit"
|
2023-09-21 16:23:03 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-09-15 14:06:23 +08:00
|
|
|
"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/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test 测试双机ZDJ9道岔
|
|
|
|
func Test() {
|
|
|
|
//模型仓库
|
|
|
|
modelStorage := tstorages.NewModelStorage()
|
|
|
|
addRelays(modelStorage)
|
|
|
|
addSwitchs(modelStorage)
|
|
|
|
worldStorage := &tstorages.WorldModelStorage{Share: modelStorage, Links: tstorages.NewModelStorage()}
|
|
|
|
//
|
2023-09-26 10:49:22 +08:00
|
|
|
worldConfig := tinit.WorldConfig{
|
2023-09-15 14:06:23 +08:00
|
|
|
ModelManager: worldStorage,
|
|
|
|
Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()},
|
2023-09-15 16:39:11 +08:00
|
|
|
Tick: 200,
|
2023-09-15 14:06:23 +08:00
|
|
|
InitTime: time.Now(),
|
|
|
|
}
|
2023-09-26 10:49:22 +08:00
|
|
|
world := tinit.InitializeWorld(&worldConfig)
|
2023-09-15 14:06:23 +08:00
|
|
|
addEntities(world, modelStorage)
|
|
|
|
initComponents(world)
|
|
|
|
//
|
|
|
|
//ecs.EventsDebugEnable()
|
|
|
|
//
|
|
|
|
system.Switch2jzdj9AddListeners(world)
|
|
|
|
system.RelayAddListeners(world)
|
|
|
|
//
|
|
|
|
world.StartUp()
|
|
|
|
time.Sleep(1 * time.Second)
|
2023-09-15 16:39:11 +08:00
|
|
|
//联锁驱动反操
|
|
|
|
system.Switch2jZdj9DriveYc(world, "sw1", true)
|
|
|
|
system.Switch2jZdj9DriveFc(world, "sw1", true)
|
2023-09-15 14:06:23 +08:00
|
|
|
//
|
2023-09-15 16:39:11 +08:00
|
|
|
time.Sleep(12 * time.Second)
|
2023-09-26 15:28:29 +08:00
|
|
|
|
2023-09-15 14:06:23 +08:00
|
|
|
world.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func addEntities(w ecs.World, modelStorage *tstorages.ModelStorage) {
|
2023-09-21 16:23:03 +08:00
|
|
|
modelStorage.ForEachModelsByType(proto.DeviceType_DeviceType_Turnout, func(md tstorages.ModelData) {
|
|
|
|
entities.CreateSwitch2jzdj9Entity(w, md.Id())
|
2023-09-15 14:06:23 +08:00
|
|
|
})
|
2023-09-21 16:23:03 +08:00
|
|
|
modelStorage.ForEachModelsByType(proto.DeviceType_DeviceType_Relay, func(md tstorages.ModelData) {
|
|
|
|
entities.CreateRelayEntity(w, md.Id())
|
2023-09-15 14:06:23 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// //////////////////////////////////////////////////////////////////
|
|
|
|
func addRelays(modelStorage *tstorages.ModelStorage) {
|
|
|
|
//道岔sw1,双机zdj9
|
2023-09-21 16:23:03 +08:00
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-dcj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-fcj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-ycj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zdbj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zfbj"))
|
2023-09-15 14:06:23 +08:00
|
|
|
|
2023-09-21 16:23:03 +08:00
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-bhj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-2dqj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqjf"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-dbj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-fbj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-qdj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-zbhj"))
|
2023-09-15 14:06:23 +08:00
|
|
|
|
2023-09-21 16:23:03 +08:00
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-bhj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-2dqj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqjf"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-dbj"))
|
|
|
|
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-fbj"))
|
2023-09-15 14:06:23 +08:00
|
|
|
}
|
2023-09-22 10:53:51 +08:00
|
|
|
func findRelayModel(modelStorage *tstorages.ModelStorage, id string) system.IDeviceModel {
|
2023-09-21 15:49:46 +08:00
|
|
|
return modelStorage.FindModelById(id)
|
2023-09-15 14:06:23 +08:00
|
|
|
}
|
|
|
|
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 {
|
2023-09-22 10:53:51 +08:00
|
|
|
relayId := relay.Relay.(system.IDeviceModel).Id()
|
2023-09-15 14:06:23 +08:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|