From dc9be681a1fbca1eb9af0b9f9503fc9c6ce80c6d Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Tue, 10 Oct 2023 17:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA2xh1=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/signal1/main.go | 39 +++++++++++++++++++++++----- examples/signal1/sigSys/debug_sys.go | 8 ++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/examples/signal1/main.go b/examples/signal1/main.go index ff0b7ac..86006cb 100644 --- a/examples/signal1/main.go +++ b/examples/signal1/main.go @@ -7,12 +7,19 @@ import ( "joylink.club/rtsssimulation/consts" "joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/examples/signal1/sigSys" + "joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/sys/circuit_sys" + "joylink.club/rtsssimulation/sys/device_sys" + "log" "time" ) +const ( + IdSignal2XH1 = "signal1-2xh1" +) + // 信号机测试 func main() { proto := &proto.Repository{} @@ -23,21 +30,41 @@ func main() { sim := rtss_simulation.NewSimulation(repo) loadEntities(sim, repo) sim.SetSpeed(0.1) - sim.AddSystem(circuit_sys.NewSignal2XH1System()) sim.AddSystem(sigSys.NewSignalDebugSystem()) + sim.AddSystem(device_sys.NewRelaySys()) + sim.AddSystem(circuit_sys.NewSignal2XH1System()) sim.StartUp() // - time.Sleep(10 * time.Second) + time.Sleep(1 * time.Second) + worldLog(sim, "===>>灭灯 .....") + fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, false) //灭灯 + time.Sleep(2 * time.Second) + worldLog(sim, "===>>亮灯 .....") + fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, true) //亮灯 + time.Sleep(2 * time.Second) + worldLog(sim, "===>>开通列车信号 .....") + fi.DriveSignal2XH1Lx(sim, IdSignal2XH1) //开通列车信号 + time.Sleep(3 * time.Second) + worldLog(sim, "===>>开通禁止信号 .....") + fi.DriveSignal2XH1Non(sim, IdSignal2XH1) //开通禁止信号 + // + time.Sleep(3 * time.Second) sim.Close() } +func worldLog(w ecs.World, logInfo string) { + ecs.Request(w, func() any { + log.Println(logInfo) + return nil + }) +} func addProtoSignal2XH1(r *proto.Repository) { //相关继电器 - r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-ddj", Code: consts.SIGNAL_DDJ}) - r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-dj", Code: consts.SIGNAL_DJ}) - r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-lxj", Code: consts.SIGNAL_LXJ}) + r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-ddj", Code: consts.SIGNAL_DDJ, Model: proto.Relay_JWXC_1700}) + r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-dj", Code: consts.SIGNAL_DJ, Model: proto.Relay_JZXC_H18}) + r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-lxj", Code: consts.SIGNAL_LXJ, Model: proto.Relay_JWXC_1700}) // signal := &proto.Signal{} - signal.Id = "signal1-2xh1" + signal.Id = IdSignal2XH1 signal.Km = &proto.Kilometer{} // group := &proto.ElectronicComponentGroup{Code: consts.SIGNAL_2XH1, ComponentIds: []string{"2xh1-ddj", "2xh1-dj", "2xh1-lxj"}} diff --git a/examples/signal1/sigSys/debug_sys.go b/examples/signal1/sigSys/debug_sys.go index 21d49b3..a7cead5 100644 --- a/examples/signal1/sigSys/debug_sys.go +++ b/examples/signal1/sigSys/debug_sys.go @@ -19,8 +19,12 @@ func NewSignalDebugSystem() *SignalDebugSystem { func (s *SignalDebugSystem) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { uid := component.UidType.Get(entry) - //state := component.Signal2XH1ElectronicType.Get(entry) + state := component.Signal2XH1ElectronicType.Get(entry) filament := component.Signal2XH1FilamentType.Get(entry) - log.Println("===>> uid = ", uid.Id, " 绿灯 = ", filament.L, " 红灯 = ", filament.H) + // + ddj := component.BitStateType.Get(state.Z2XH1_DDJ) + lxj := component.BitStateType.Get(state.Z2XH1_LXJ) + // + log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, filament.L, filament.H) }) }