2023-10-10 09:35:02 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-10 16:51:07 +08:00
|
|
|
"fmt"
|
|
|
|
"joylink.club/ecs"
|
2023-10-10 09:35:02 +08:00
|
|
|
rtss_simulation "joylink.club/rtsssimulation"
|
2023-10-10 16:51:07 +08:00
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-10 18:06:30 +08:00
|
|
|
"joylink.club/rtsssimulation/examples/signal_2xh1/sigSys"
|
2023-10-10 17:26:09 +08:00
|
|
|
"joylink.club/rtsssimulation/fi"
|
2023-10-10 09:35:02 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
2023-10-10 16:51:07 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-10-10 17:26:09 +08:00
|
|
|
"log"
|
2023-10-10 16:51:07 +08:00
|
|
|
"time"
|
2023-10-10 09:35:02 +08:00
|
|
|
)
|
|
|
|
|
2023-10-10 17:26:09 +08:00
|
|
|
const (
|
2023-10-10 18:06:30 +08:00
|
|
|
IdSignal2XH1 = "signal_2xh1-1"
|
2023-10-10 17:26:09 +08:00
|
|
|
)
|
|
|
|
|
2023-10-10 09:35:02 +08:00
|
|
|
// 信号机测试
|
|
|
|
func main() {
|
2023-10-10 16:51:07 +08:00
|
|
|
proto := &proto.Repository{}
|
|
|
|
proto.Id = "test-for-signal"
|
|
|
|
proto.Version = "v1.0"
|
|
|
|
addProtoSignal2XH1(proto)
|
|
|
|
repo := repository.BuildRepositoryForSignalTest(proto)
|
|
|
|
sim := rtss_simulation.NewSimulation(repo)
|
|
|
|
loadEntities(sim, repo)
|
|
|
|
sim.SetSpeed(0.1)
|
|
|
|
sim.AddSystem(sigSys.NewSignalDebugSystem())
|
2023-10-10 09:35:02 +08:00
|
|
|
sim.StartUp()
|
2023-10-10 16:51:07 +08:00
|
|
|
//
|
2023-10-10 17:26:09 +08:00
|
|
|
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)
|
2023-10-10 16:51:07 +08:00
|
|
|
sim.Close()
|
2023-10-10 09:35:02 +08:00
|
|
|
}
|
2023-10-10 17:26:09 +08:00
|
|
|
func worldLog(w ecs.World, logInfo string) {
|
|
|
|
ecs.Request(w, func() any {
|
|
|
|
log.Println(logInfo)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2023-10-10 16:51:07 +08:00
|
|
|
func addProtoSignal2XH1(r *proto.Repository) {
|
|
|
|
//相关继电器
|
2023-10-10 17:26:09 +08:00
|
|
|
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})
|
2023-10-10 16:51:07 +08:00
|
|
|
//
|
|
|
|
signal := &proto.Signal{}
|
2023-10-10 17:26:09 +08:00
|
|
|
signal.Id = IdSignal2XH1
|
2023-10-10 16:51:07 +08:00
|
|
|
signal.Km = &proto.Kilometer{}
|
|
|
|
//
|
|
|
|
group := &proto.ElectronicComponentGroup{Code: consts.SIGNAL_2XH1, ComponentIds: []string{"2xh1-ddj", "2xh1-dj", "2xh1-lxj"}}
|
|
|
|
//
|
|
|
|
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())
|
|
|
|
}
|
2023-10-10 09:35:02 +08:00
|
|
|
}
|