signal 2xh1 驱采

This commit is contained in:
xzb 2023-10-12 10:07:40 +08:00
parent b5cfb5b8b7
commit b6bdcc8748
6 changed files with 77 additions and 20 deletions

View File

@ -16,9 +16,29 @@ type Signal2XH1Electronic struct {
Z2XH1_H *ecs.Entry 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 ( var (
//Signal2XH1ElectronicType 2XH1信号机电路组件 //Signal2XH1ElectronicType 2XH1信号机电路组件
Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]() Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]()
Signal2XH1LsqType = ecs.NewComponentType[Signal2XH1Lsq]()
Signal2XH1LscType = ecs.NewComponentType[Signal2XH1Lsc]()
) )
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

View File

@ -12,6 +12,8 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 3 { //2xh1组合类型包含3个继电器 if len(elecs) == 3 { //2xh1组合类型包含3个继电器
signalEntry.AddComponent(component.Signal2XH1ElectronicType) signalEntry.AddComponent(component.Signal2XH1ElectronicType)
signalEntry.AddComponent(component.Signal2XH1LsqType)
signalEntry.AddComponent(component.Signal2XH1LscType)
// //
elecState := &component.Signal2XH1Electronic{Z2XH1_L: NewLightLEntity(w), Z2XH1_H: NewLightHEntity(w)} elecState := &component.Signal2XH1Electronic{Z2XH1_L: NewLightLEntity(w), Z2XH1_H: NewLightHEntity(w)}
for _, elec := range elecs { 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.Signal2XH1ElectronicType.Set(signalEntry, elecState)
component.Signal2XH1LsqType.Set(signalEntry, &component.Signal2XH1Lsq{})
component.Signal2XH1LscType.Set(signalEntry, &component.Signal2XH1Lsc{})
} else { } else {
return fmt.Errorf("id=[%s]的信号机2xh1电子元器件数量须为3", signal.Id()) return fmt.Errorf("id=[%s]的信号机2xh1电子元器件数量须为3", signal.Id())
} }

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"joylink.club/ecs" "joylink.club/ecs"
rtss_simulation "joylink.club/rtsssimulation" rtss_simulation "joylink.club/rtsssimulation"
"joylink.club/rtsssimulation/consts" "joylink.club/rtsssimulation/consts"
@ -11,6 +10,8 @@ import (
"joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"log" "log"
"log/slog"
"os"
"time" "time"
) )
@ -20,6 +21,10 @@ const (
// 信号机测试 // 信号机测试
func main() { func main() {
//
logConfig := &slog.HandlerOptions{AddSource: false, Level: slog.LevelDebug}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, logConfig)))
//
proto := &proto.Repository{} proto := &proto.Repository{}
proto.Id = "test-for-signal" proto.Id = "test-for-signal"
proto.Version = "v1.0" proto.Version = "v1.0"
@ -32,16 +37,16 @@ func main() {
sim.StartUp() sim.StartUp()
// //
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
worldLog(sim, "===>>灭灯 .....") slog.Debug("灭灯 .....")
fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, false) //灭灯 fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, false) //灭灯
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
worldLog(sim, "===>>亮灯 .....") slog.Debug("亮灯 .....")
fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, true) //亮灯 fi.DriveSignal2XH1Dd(sim, IdSignal2XH1, true) //亮灯
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
worldLog(sim, "===>>开通列车信号 .....") slog.Debug("开通列车信号 .....")
fi.DriveSignal2XH1Lx(sim, IdSignal2XH1) //开通列车信号 fi.DriveSignal2XH1Lx(sim, IdSignal2XH1) //开通列车信号
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
worldLog(sim, "===>>开通禁止信号 .....") slog.Debug("开通禁止信号 .....")
fi.DriveSignal2XH1Non(sim, IdSignal2XH1) //开通禁止信号 fi.DriveSignal2XH1Non(sim, IdSignal2XH1) //开通禁止信号
// //
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
@ -73,6 +78,6 @@ func loadEntities(w ecs.World, repo *repository.Repository) {
entity.LoadWorldData(w, repo) entity.LoadWorldData(w, repo)
// //
if le := entity.LoadSignals(w); le != nil { if le := entity.LoadSignals(w); le != nil {
fmt.Println("===>>LoadSignals error : ", le.Error()) slog.Error(le.Error())
} }
} }

View File

@ -4,7 +4,7 @@ import (
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/ecs/filter" "joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
"log" "log/slog"
) )
type SignalDebugSystem struct { type SignalDebugSystem struct {
@ -25,7 +25,13 @@ func (s *SignalDebugSystem) Update(w ecs.World) {
// //
ddj := component.BitStateType.Get(state.Z2XH1_DDJ) ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ) 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)
}) })
} }

View File

@ -15,10 +15,8 @@ func DriveSignal2XH1Dd(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.Signal2XH1ElectronicType.Get(signalEntry) lsq := component.Signal2XH1LsqType.Get(signalEntry)
drive := component.RelayDriveType.Get(state.Z2XH1_DDJ) lsq.Z2XH1_DDJ_Q = !dd
drive.Td = !dd
drive.Xq = !dd
} }
}) })
} }
@ -29,10 +27,8 @@ func DriveSignal2XH1Lx(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.Signal2XH1ElectronicType.Get(signalEntry) lsq := component.Signal2XH1LsqType.Get(signalEntry)
drive := component.RelayDriveType.Get(state.Z2XH1_LXJ) lsq.Z2XH1_LXJ_Q = true
drive.Td = true
drive.Xq = true
} }
}) })
} }
@ -43,10 +39,8 @@ func DriveSignal2XH1Non(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.Signal2XH1ElectronicType.Get(signalEntry) lsq := component.Signal2XH1LsqType.Get(signalEntry)
drive := component.RelayDriveType.Get(state.Z2XH1_LXJ) lsq.Z2XH1_LXJ_Q = false
drive.Td = false
drive.Xq = false
} }
}) })
} }

View File

@ -18,12 +18,40 @@ func NewSignal2XH1System() *Signal2XH1System {
func (s *Signal2XH1System) Update(w ecs.World) { func (s *Signal2XH1System) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal2XH1ElectronicType.Get(entry) state := component.Signal2XH1ElectronicType.Get(entry)
lsq := component.Signal2XH1LsqType.Get(entry)
lsc := component.Signal2XH1LscType.Get(entry)
s.calculateLsq(state, lsq)
s.calculateL(state) s.calculateL(state)
s.calculateH(state) s.calculateH(state)
s.calculateDJ(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) { func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) {
driveL := component.LightDriveType.Get(state.Z2XH1_L) driveL := component.LightDriveType.Get(state.Z2XH1_L)
ddj := component.BitStateType.Get(state.Z2XH1_DDJ) ddj := component.BitStateType.Get(state.Z2XH1_DDJ)