信号机2xh1测试

This commit is contained in:
xzb 2023-10-10 16:51:07 +08:00
parent f703158b1c
commit 528f5b9252
5 changed files with 100 additions and 8 deletions

View File

@ -1,18 +1,55 @@
package main
import (
"fmt"
"joylink.club/ecs"
rtss_simulation "joylink.club/rtsssimulation"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/examples/signal1/sigSys"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/sys/circuit_sys"
"time"
)
// 信号机测试
func main() {
r := &repository.Repository{}
addSignal2XH1(r)
sim := rtss_simulation.NewSimulation(r)
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(circuit_sys.NewSignal2XH1System())
sim.AddSystem(sigSys.NewSignalDebugSystem())
sim.StartUp()
//
time.Sleep(10 * time.Second)
sim.Close()
}
func addSignal2XH1(r *repository.Repository) {
//signal := repository.NewSignal("signal1-2xh1", &proto.Kilometer{})
func addProtoSignal2XH1(r *proto.Repository) {
//相关继电器
r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-ddj", Code: consts.SIGNAL_DDJ})
r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-dj", Code: consts.SIGNAL_DJ})
r.Relays = append(r.Relays, &proto.Relay{Id: "2xh1-lxj", Code: consts.SIGNAL_LXJ})
//
signal := &proto.Signal{}
signal.Id = "signal1-2xh1"
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())
}
}

View File

@ -0,0 +1,26 @@
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.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))}
}
// Update world 执行
func (s *SignalDebugSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
uid := component.UidType.Get(entry)
//state := component.Signal2XH1ElectronicType.Get(entry)
filament := component.Signal2XH1FilamentType.Get(entry)
log.Println("===>> uid = ", uid.Id, " 绿灯 = ", filament.L, " 红灯 = ", filament.H)
})
}

@ -1 +1 @@
Subproject commit 47f78cb54ddc2673b87d3f85eea23e3769e417ad
Subproject commit 6b6259e2eb95db625111b539ef9b526c8d3862f4

View File

@ -0,0 +1,17 @@
package repository
import (
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
)
//测试
func BuildRepositoryForSignalTest(source *proto.Repository) *Repository {
repository := newRepository(source.Id, source.Version)
buildModels(source, repository)
if err := buildSignalRelationShip(source, repository); err != nil {
fmt.Println("===>>buildSignalRelationShip error : ", err.Error())
}
return repository
}

View File

@ -38,7 +38,6 @@ func BuildRepository(source *proto.Repository) (*Repository, error) {
repositoryMap[buildRepositoryKey(source.Id, source.Version)] = repository
return repository, err
}
func FindRepository(id string, version string) *Repository {
return repositoryMap[buildRepositoryKey(id, version)]
}
@ -241,6 +240,19 @@ func buildSignalRelationShip(source *proto.Repository, repository *Repository) e
}
interrelateSignalAndTurnout(signal, repository.turnoutMap[tp.DeviceId], tp.Port)
}
//关联继电器组
for _, group := range protoData.ElectronicComponentGroups {
var components []IGroupedElectronicComponent
for _, id := range group.GetComponentIds() {
if relay := repository.relayMap[id]; relay != nil {
components = append(components, relay)
}
}
signal.componentGroups = append(signal.componentGroups, &ElectronicComponentGroup{
code: group.Code,
components: components,
})
}
}
return nil
}