From b6bdcc8748cbc6f347839d7ee8f8df9f50f52edd Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 12 Oct 2023 10:07:40 +0800 Subject: [PATCH] =?UTF-8?q?signal=202xh1=20=E9=A9=B1=E9=87=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/signal.go | 20 +++++++++++++++++ entity/signal_2xh1.go | 4 ++++ examples/signal_2xh1/main.go | 17 +++++++++----- examples/signal_2xh1/sigSys/debug_sys.go | 10 +++++++-- fi/signal_2xh1.go | 18 +++++---------- sys/circuit_sys/signal_2xh1.go | 28 ++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 20 deletions(-) diff --git a/component/signal.go b/component/signal.go index f6a88f6..4f07f8e 100644 --- a/component/signal.go +++ b/component/signal.go @@ -16,9 +16,29 @@ type Signal2XH1Electronic struct { Z2XH1_H *ecs.Entry } +// Signal2XH1Lsq 联锁驱 +type Signal2XH1Lsq struct { + //true-联锁施加励磁电流驱动继电器DDJ + Z2XH1_DDJ_Q bool + ////true-联锁施加励磁电流驱动继电器LXJ + Z2XH1_LXJ_Q bool +} + +// Signal2XH1Lsc 联锁采 +type Signal2XH1Lsc struct { + //true-继电器DJ吸起 + Z2XH1_DJ_Xq bool + //true-继电器DDJ落下 + Z2XH1_DDJ_Lx bool + //true-继电器LXJ吸起 + Z2XH1_LXJ_Xq bool +} + var ( //Signal2XH1ElectronicType 2XH1信号机电路组件 Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]() + Signal2XH1LsqType = ecs.NewComponentType[Signal2XH1Lsq]() + Signal2XH1LscType = ecs.NewComponentType[Signal2XH1Lsc]() ) ///////////////////////////////////////////////////////////////////////// diff --git a/entity/signal_2xh1.go b/entity/signal_2xh1.go index dd18cd7..f79d961 100644 --- a/entity/signal_2xh1.go +++ b/entity/signal_2xh1.go @@ -12,6 +12,8 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent if len(elecs) == 3 { //2xh1组合类型包含3个继电器 signalEntry.AddComponent(component.Signal2XH1ElectronicType) + signalEntry.AddComponent(component.Signal2XH1LsqType) + signalEntry.AddComponent(component.Signal2XH1LscType) // elecState := &component.Signal2XH1Electronic{Z2XH1_L: NewLightLEntity(w), Z2XH1_H: NewLightHEntity(w)} for _, elec := range elecs { @@ -28,6 +30,8 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent } // component.Signal2XH1ElectronicType.Set(signalEntry, elecState) + component.Signal2XH1LsqType.Set(signalEntry, &component.Signal2XH1Lsq{}) + component.Signal2XH1LscType.Set(signalEntry, &component.Signal2XH1Lsc{}) } else { return fmt.Errorf("id=[%s]的信号机2xh1,电子元器件数量须为3", signal.Id()) } diff --git a/examples/signal_2xh1/main.go b/examples/signal_2xh1/main.go index f1b7a7c..a2cfa8f 100644 --- a/examples/signal_2xh1/main.go +++ b/examples/signal_2xh1/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "joylink.club/ecs" rtss_simulation "joylink.club/rtsssimulation" "joylink.club/rtsssimulation/consts" @@ -11,6 +10,8 @@ import ( "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" "log" + "log/slog" + "os" "time" ) @@ -20,6 +21,10 @@ const ( // 信号机测试 func main() { + // + logConfig := &slog.HandlerOptions{AddSource: false, Level: slog.LevelDebug} + slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, logConfig))) + // proto := &proto.Repository{} proto.Id = "test-for-signal" proto.Version = "v1.0" @@ -32,16 +37,16 @@ func main() { sim.StartUp() // time.Sleep(1 * time.Second) - worldLog(sim, "===>>灭灯 .....") + slog.Debug("灭灯 .....") fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, false) //灭灯 time.Sleep(2 * time.Second) - worldLog(sim, "===>>亮灯 .....") + slog.Debug("亮灯 .....") fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, true) //亮灯 time.Sleep(2 * time.Second) - worldLog(sim, "===>>开通列车信号 .....") + slog.Debug("开通列车信号 .....") fi.DriveSignal2XH1Lx(sim, IdSignal2XH1) //开通列车信号 time.Sleep(3 * time.Second) - worldLog(sim, "===>>开通禁止信号 .....") + slog.Debug("开通禁止信号 .....") fi.DriveSignal2XH1Non(sim, IdSignal2XH1) //开通禁止信号 // time.Sleep(3 * time.Second) @@ -73,6 +78,6 @@ func loadEntities(w ecs.World, repo *repository.Repository) { entity.LoadWorldData(w, repo) // if le := entity.LoadSignals(w); le != nil { - fmt.Println("===>>LoadSignals error : ", le.Error()) + slog.Error(le.Error()) } } diff --git a/examples/signal_2xh1/sigSys/debug_sys.go b/examples/signal_2xh1/sigSys/debug_sys.go index 26f62fd..d5128a1 100644 --- a/examples/signal_2xh1/sigSys/debug_sys.go +++ b/examples/signal_2xh1/sigSys/debug_sys.go @@ -4,7 +4,7 @@ import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" - "log" + "log/slog" ) type SignalDebugSystem struct { @@ -25,7 +25,13 @@ func (s *SignalDebugSystem) Update(w ecs.World) { // ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) + lsq := component.Signal2XH1LsqType.Get(entry) + lsc := component.Signal2XH1LscType.Get(entry) // - log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, ld.Val, hd.Val) + slog.Debug(uid.Id, + "ddjQ", lsq.Z2XH1_DDJ_Q, "lxjQ", lsq.Z2XH1_LXJ_Q, + "ddjLx", lsc.Z2XH1_DDJ_Lx, "djXq", lsc.Z2XH1_DJ_Xq, "lxjXq", lsc.Z2XH1_LXJ_Xq, + "ddj", ddj.Val, "lxj", lxj.Val, + "绿灯", ld.Val, "红灯", hd.Val) }) } diff --git a/fi/signal_2xh1.go b/fi/signal_2xh1.go index bb26943..f8887f2 100644 --- a/fi/signal_2xh1.go +++ b/fi/signal_2xh1.go @@ -15,10 +15,8 @@ func DriveSignal2XH1Dd(w ecs.World, signalId string, dd bool) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal2XH1ElectronicType.Get(signalEntry) - drive := component.RelayDriveType.Get(state.Z2XH1_DDJ) - drive.Td = !dd - drive.Xq = !dd + lsq := component.Signal2XH1LsqType.Get(signalEntry) + lsq.Z2XH1_DDJ_Q = !dd } }) } @@ -29,10 +27,8 @@ func DriveSignal2XH1Lx(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal2XH1ElectronicType.Get(signalEntry) - drive := component.RelayDriveType.Get(state.Z2XH1_LXJ) - drive.Td = true - drive.Xq = true + lsq := component.Signal2XH1LsqType.Get(signalEntry) + lsq.Z2XH1_LXJ_Q = true } }) } @@ -43,10 +39,8 @@ func DriveSignal2XH1Non(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal2XH1ElectronicType.Get(signalEntry) - drive := component.RelayDriveType.Get(state.Z2XH1_LXJ) - drive.Td = false - drive.Xq = false + lsq := component.Signal2XH1LsqType.Get(signalEntry) + lsq.Z2XH1_LXJ_Q = false } }) } diff --git a/sys/circuit_sys/signal_2xh1.go b/sys/circuit_sys/signal_2xh1.go index f753d74..a0d0586 100644 --- a/sys/circuit_sys/signal_2xh1.go +++ b/sys/circuit_sys/signal_2xh1.go @@ -18,12 +18,40 @@ func NewSignal2XH1System() *Signal2XH1System { func (s *Signal2XH1System) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { state := component.Signal2XH1ElectronicType.Get(entry) + lsq := component.Signal2XH1LsqType.Get(entry) + lsc := component.Signal2XH1LscType.Get(entry) + s.calculateLsq(state, lsq) s.calculateL(state) s.calculateH(state) s.calculateDJ(state) + s.calculateLsc(state, lsc) }) } +// 联锁驱 +func (s *Signal2XH1System) calculateLsq(state *component.Signal2XH1Electronic, lsq *component.Signal2XH1Lsq) { + ddj := component.RelayDriveType.Get(state.Z2XH1_DDJ) + lxj := component.RelayDriveType.Get(state.Z2XH1_LXJ) + // + ddjQ := lsq.Z2XH1_DDJ_Q + ddj.Td = ddjQ + ddj.Xq = ddjQ + // + lxjQ := lsq.Z2XH1_LXJ_Q + lxj.Td = lxjQ + lxj.Xq = lxjQ +} + +// 联锁采 +func (s *Signal2XH1System) calculateLsc(state *component.Signal2XH1Electronic, lsc *component.Signal2XH1Lsc) { + ddj := component.BitStateType.Get(state.Z2XH1_DDJ) + dj := component.BitStateType.Get(state.Z2XH1_DJ) + lxj := component.BitStateType.Get(state.Z2XH1_LXJ) + // + lsc.Z2XH1_DDJ_Lx = !ddj.Val + lsc.Z2XH1_DJ_Xq = dj.Val + lsc.Z2XH1_LXJ_Xq = lxj.Val +} func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) { driveL := component.LightDriveType.Get(state.Z2XH1_L) ddj := component.BitStateType.Get(state.Z2XH1_DDJ)