信号机3xh1测试
This commit is contained in:
parent
dc9be681a1
commit
bc1cd65d2f
@ -6,7 +6,7 @@ import (
|
|||||||
rtss_simulation "joylink.club/rtsssimulation"
|
rtss_simulation "joylink.club/rtsssimulation"
|
||||||
"joylink.club/rtsssimulation/consts"
|
"joylink.club/rtsssimulation/consts"
|
||||||
"joylink.club/rtsssimulation/entity"
|
"joylink.club/rtsssimulation/entity"
|
||||||
"joylink.club/rtsssimulation/examples/signal1/sigSys"
|
"joylink.club/rtsssimulation/examples/signal_2xh1/sigSys"
|
||||||
"joylink.club/rtsssimulation/fi"
|
"joylink.club/rtsssimulation/fi"
|
||||||
"joylink.club/rtsssimulation/repository"
|
"joylink.club/rtsssimulation/repository"
|
||||||
"joylink.club/rtsssimulation/repository/model/proto"
|
"joylink.club/rtsssimulation/repository/model/proto"
|
||||||
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IdSignal2XH1 = "signal1-2xh1"
|
IdSignal2XH1 = "signal_2xh1-1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 信号机测试
|
// 信号机测试
|
85
examples/signal_3xh1/main.go
Normal file
85
examples/signal_3xh1/main.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
rtss_simulation "joylink.club/rtsssimulation"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
"joylink.club/rtsssimulation/entity"
|
||||||
|
"joylink.club/rtsssimulation/examples/signal_3xh1/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 (
|
||||||
|
IdSignal3XH1 = "signal_3xh1-1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 信号机测试
|
||||||
|
func main() {
|
||||||
|
proto := &proto.Repository{}
|
||||||
|
proto.Id = "test-for-signal"
|
||||||
|
proto.Version = "v1.0"
|
||||||
|
addProtoSignal3XH1(proto)
|
||||||
|
repo := repository.BuildRepositoryForSignalTest(proto)
|
||||||
|
sim := rtss_simulation.NewSimulation(repo)
|
||||||
|
loadEntities(sim, repo)
|
||||||
|
sim.SetSpeed(0.1)
|
||||||
|
sim.AddSystem(sigSys.NewSignalDebugSystem())
|
||||||
|
sim.AddSystem(device_sys.NewRelaySys())
|
||||||
|
sim.AddSystem(circuit_sys.NewSignal3XH1System())
|
||||||
|
sim.StartUp()
|
||||||
|
//
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
worldLog(sim, "===>>灭灯 .....")
|
||||||
|
fi.DriveSignal3XH1Dd(sim, IdSignal3XH1, false)
|
||||||
|
//
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
worldLog(sim, "===>>亮灯 .....")
|
||||||
|
fi.DriveSignal3XH1Dd(sim, IdSignal3XH1, true)
|
||||||
|
//
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
worldLog(sim, "===>>开通引导信号 .....")
|
||||||
|
fi.DriveSignal3XH1Yx(sim, IdSignal3XH1)
|
||||||
|
//
|
||||||
|
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 addProtoSignal3XH1(r *proto.Repository) {
|
||||||
|
//相关继电器
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-ddj", Code: consts.SIGNAL_DDJ, Model: proto.Relay_JWXC_1700})
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-2dj", Code: consts.SIGNAL_2DJ, Model: proto.Relay_JZXC_H18})
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-dj", Code: consts.SIGNAL_DJ, Model: proto.Relay_JZXC_H18})
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-lxj", Code: consts.SIGNAL_LXJ, Model: proto.Relay_JWXC_1700})
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-yxj", Code: consts.SIGNAL_YXJ, Model: proto.Relay_JWXC_1700})
|
||||||
|
r.Relays = append(r.Relays, &proto.Relay{Id: "3xh1-zxj", Code: consts.SIGNAL_ZXJ, Model: proto.Relay_JWXC_1700})
|
||||||
|
//
|
||||||
|
signal := &proto.Signal{}
|
||||||
|
signal.Id = IdSignal3XH1
|
||||||
|
signal.Km = &proto.Kilometer{}
|
||||||
|
//
|
||||||
|
group := &proto.ElectronicComponentGroup{Code: consts.SIGNAL_3XH1,
|
||||||
|
ComponentIds: []string{"3xh1-ddj", "3xh1-2dj", "3xh1-dj", "3xh1-lxj", "3xh1-yxj", "3xh1-zxj"}}
|
||||||
|
//
|
||||||
|
signal.ElectronicComponentGroups = append(signal.ElectronicComponentGroups, group)
|
||||||
|
r.Signals = append(r.Signals, signal)
|
||||||
|
}
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
35
examples/signal_3xh1/sigSys/debug_sys.go
Normal file
35
examples/signal_3xh1/sigSys/debug_sys.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package sigSys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/ecs/filter"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SignalDebugSystem struct {
|
||||||
|
query *ecs.Query
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSignalDebugSystem() *SignalDebugSystem {
|
||||||
|
return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType, component.Signal3XH1FilamentType))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update world 执行
|
||||||
|
func (s *SignalDebugSystem) Update(w ecs.World) {
|
||||||
|
s.query.Each(w, func(entry *ecs.Entry) {
|
||||||
|
uid := component.UidType.Get(entry)
|
||||||
|
state := component.Signal3XH1ElectronicType.Get(entry)
|
||||||
|
filament := component.Signal3XH1FilamentType.Get(entry)
|
||||||
|
//
|
||||||
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
||||||
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
||||||
|
dj := component.BitStateType.Get(state.Z3XH1_DJ)
|
||||||
|
edj := component.BitStateType.Get(state.Z3XH1_2DJ)
|
||||||
|
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
|
||||||
|
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
|
||||||
|
//
|
||||||
|
log.Printf("===>> uid = %s | ddj = %t | lxj = %t zxj = %t yxj = %t | dj = %t 2dj = %t | 绿灯 = %t 红灯 = %t 黄灯 = %t,\n",
|
||||||
|
uid.Id, ddj.Val, lxj.Val, zxj.Val, yxj.Val, dj.Val, edj.Val, filament.L, filament.H, filament.U)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user