rts-sim-module/examples/signal_3xh1/main.go

84 lines
2.7 KiB
Go

package main
import (
"fmt"
"log/slog"
"os"
"time"
"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"
)
const (
IdSignal3XH1 = "signal_3xh1-1"
)
// 信号机测试
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"
addProtoSignal3XH1(proto)
repo := repository.BuildRepositoryForSignalTest(proto)
sim, _ := rtss_simulation.NewSimulation(repo)
loadEntities(sim, repo)
sim.SetSpeed(1)
sim.AddSystem(sigSys.NewSignalDebugSystem())
sim.StartUp()
//
time.Sleep(1 * time.Second)
slog.Debug("灭灯 .....")
fi.DriveSignal3XH1Dd(sim, IdSignal3XH1, false)
//
time.Sleep(1 * time.Second)
slog.Debug("亮灯 .....")
fi.DriveSignal3XH1Dd(sim, IdSignal3XH1, true)
//
time.Sleep(2 * time.Second)
slog.Debug("开通引导信号 .....")
fi.DriveSignal3XH1Yx(sim, IdSignal3XH1)
time.Sleep(2 * time.Second)
slog.Debug("开通列车信号 .....")
fi.DriveSignal3XH1Lx(sim, IdSignal3XH1, false)
//
time.Sleep(5 * time.Second)
sim.Close()
}
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())
}
}