Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
# Conflicts: # examples/basic/main.go
This commit is contained in:
commit
ad87ad0bef
@ -4,17 +4,25 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/yohamta/donburi/features/events"
|
||||
"joylink.club/ecs"
|
||||
system "joylink.club/ecs/examples/rtss/sys"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/repository/model"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
)
|
||||
|
||||
var Repo *repository.Repository
|
||||
|
||||
func main() {
|
||||
fmt.Println("基础测试")
|
||||
w := ecs.NewWorld(1000)
|
||||
w.AddSystem(system.NewTurnoutSys())
|
||||
w.StartUp()
|
||||
link := model.NewLink("1")
|
||||
fmt.Println(link)
|
||||
|
||||
lp := model.NewLinkPort(&link, proto.Port_A)
|
||||
fmt.Println(lp)
|
||||
|
||||
Repo = repository.NewRepository("1" /* id */, "0.1" /* version */)
|
||||
section := model.NewPhysicalSection("s1")
|
||||
fmt.Println(section)
|
||||
Repo.AddPhysicalSection(section)
|
||||
fmt.Println(Repo)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
events.ProcessAllEvents(nil)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func main() {
|
||||
{
|
||||
protocPath = filepath.Join(basePath, "protoc-23.1", "bin", "win64", "protoc")
|
||||
protoFolder = filepath.Join(basePath, "src", args[1])
|
||||
goOutDir = "../components"
|
||||
goOutDir = "../"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package cstate;
|
||||
option go_package = "./cstate";
|
||||
option go_package = "./components/cstate";
|
||||
|
||||
//仿真底层ecs组件相关定义
|
||||
|
||||
|
@ -4,7 +4,7 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
// 检测点
|
||||
type CheckPoint struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
km proto.Kilometer
|
||||
t proto.CheckPointType //检测点类型
|
||||
|
@ -3,7 +3,7 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type PortedDevice interface {
|
||||
Model
|
||||
Identity
|
||||
|
||||
// 端口数量
|
||||
PortNum() int
|
||||
|
@ -3,14 +3,16 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Link struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
aRelation LinkNodePort
|
||||
bRelation LinkNodePort
|
||||
}
|
||||
|
||||
func NewLink(model Model) Link {
|
||||
return Link{Model: model}
|
||||
var _ Identity = &Link{}
|
||||
|
||||
func NewLink(id string) Link {
|
||||
return Link{Identity: identity{id: id}}
|
||||
}
|
||||
|
||||
// link位置
|
||||
@ -27,6 +29,11 @@ type LinkNode struct {
|
||||
cRelation LinkPort
|
||||
}
|
||||
|
||||
func (ln LinkNode) Id() string {
|
||||
return ln.turnout.Id()
|
||||
}
|
||||
|
||||
// link端口
|
||||
type LinkPort struct {
|
||||
DevicePort
|
||||
|
||||
@ -34,9 +41,31 @@ type LinkPort struct {
|
||||
port proto.Port
|
||||
}
|
||||
|
||||
func NewLinkPort(link *Link, port proto.Port) LinkPort {
|
||||
return LinkPort{
|
||||
link: link,
|
||||
port: port,
|
||||
}
|
||||
}
|
||||
|
||||
func (lp LinkPort) Device() Identity {
|
||||
return lp.link
|
||||
}
|
||||
|
||||
type LinkNodePort struct {
|
||||
DevicePort
|
||||
|
||||
node *LinkNode
|
||||
port proto.Port
|
||||
}
|
||||
|
||||
func NewLinkNodePort(node *LinkNode, port proto.Port) LinkNodePort {
|
||||
return LinkNodePort{
|
||||
node: node,
|
||||
port: port,
|
||||
}
|
||||
}
|
||||
|
||||
func (lp LinkNodePort) Device() Identity {
|
||||
return lp.node
|
||||
}
|
||||
|
@ -2,46 +2,32 @@ package model
|
||||
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type ModelType int
|
||||
|
||||
type Model interface {
|
||||
// 身份信息
|
||||
type Identity interface {
|
||||
Id() string
|
||||
Type() ModelType
|
||||
}
|
||||
|
||||
// Model 所有模型的共同父类
|
||||
type model struct {
|
||||
// 身份信息
|
||||
type identity struct {
|
||||
id string
|
||||
modelType ModelType
|
||||
}
|
||||
|
||||
func NewModel(id string, modelType ModelType) Model {
|
||||
return model{
|
||||
id: id,
|
||||
modelType: modelType,
|
||||
}
|
||||
}
|
||||
|
||||
func (m model) Id() string {
|
||||
func (m identity) Id() string {
|
||||
return m.id
|
||||
}
|
||||
|
||||
func (m model) Type() ModelType {
|
||||
return m.modelType
|
||||
}
|
||||
|
||||
type Signal struct {
|
||||
Model
|
||||
Identity
|
||||
km proto.Kilometer
|
||||
}
|
||||
type Responder struct {
|
||||
Model
|
||||
Identity
|
||||
}
|
||||
type Slope struct {
|
||||
Model
|
||||
Identity
|
||||
devicePositions []*LinkPosition
|
||||
}
|
||||
|
||||
type Curve struct {
|
||||
Model
|
||||
Identity
|
||||
}
|
||||
|
@ -4,12 +4,34 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
// 物理区段
|
||||
type PhysicalSection struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
len int32 //长度 mm
|
||||
checkPoints []*CheckPoint //将此区段分隔出来的所有检测点
|
||||
// A/B端关联的设备端
|
||||
aRelation DevicePort
|
||||
bRelation DevicePort
|
||||
|
||||
// A/B/C端口关联的检测点
|
||||
aCheckPoint CheckPoint
|
||||
bCheckPoint CheckPoint
|
||||
|
||||
// 关联的设备
|
||||
devices []Identity
|
||||
}
|
||||
|
||||
func NewPhysicalSection(id string) *PhysicalSection {
|
||||
return &PhysicalSection{
|
||||
Identity: identity{id},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PhysicalSection) ARelation() DevicePort {
|
||||
return s.aRelation
|
||||
}
|
||||
|
||||
func (s *PhysicalSection) BRelation() DevicePort {
|
||||
return s.bRelation
|
||||
}
|
||||
|
||||
type PhysicalSectionPort struct {
|
||||
|
@ -3,12 +3,24 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Turnout struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
km proto.Kilometer
|
||||
aRelation DevicePort
|
||||
bRelation DevicePort
|
||||
cRelation DevicePort
|
||||
|
||||
// A/B/C端口关联的设备端口
|
||||
aDevicePort DevicePort
|
||||
bDevicePort DevicePort
|
||||
cDevicePort DevicePort
|
||||
|
||||
// A/B/C端口关联的检测点
|
||||
aCheckPoint CheckPoint
|
||||
bCheckPoint CheckPoint
|
||||
cCheckPoint CheckPoint
|
||||
|
||||
// A/B/C方向关联的设备
|
||||
aDevices []Identity
|
||||
bDevices []Identity
|
||||
cDevices []Identity
|
||||
}
|
||||
|
||||
type TurnoutPort struct {
|
||||
|
@ -5,6 +5,7 @@ import "joylink.club/rtsssimulation/repository/model"
|
||||
type Repository struct {
|
||||
id string
|
||||
version string
|
||||
modelMap map[string]model.Identity
|
||||
physicalSections []*model.PhysicalSection
|
||||
checkPoints []*model.CheckPoint
|
||||
turnouts []*model.Turnout
|
||||
@ -14,6 +15,29 @@ type Repository struct {
|
||||
curves []*model.Curve
|
||||
}
|
||||
|
||||
func NewRepository(id string, version string) *Repository {
|
||||
return &Repository{
|
||||
id: id,
|
||||
version: version,
|
||||
modelMap: make(map[string]model.Identity),
|
||||
physicalSections: make([]*model.PhysicalSection, 0),
|
||||
turnouts: make([]*model.Turnout, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repository) PhysicalSectionList() []*model.PhysicalSection {
|
||||
return repo.physicalSections
|
||||
}
|
||||
|
||||
func (repo *Repository) TurnoutList() []*model.Turnout {
|
||||
return repo.turnouts
|
||||
}
|
||||
|
||||
func (repo *Repository) AddPhysicalSection(section *model.PhysicalSection) {
|
||||
repo.physicalSections = append(repo.physicalSections, section)
|
||||
repo.modelMap[section.Id()] = section
|
||||
}
|
||||
|
||||
// func (r Repository) GetById(id string) (*model.Turnout, error) {
|
||||
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user