diff --git a/examples/basic/main.go b/examples/basic/main.go index bccb893..f9e501f 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -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) } diff --git a/proto/main.go b/proto/main.go index 56c604d..2c9f5dc 100644 --- a/proto/main.go +++ b/proto/main.go @@ -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 = "../" } } diff --git a/proto/src/component/status.proto b/proto/src/component/status.proto index afd36f9..69733e9 100644 --- a/proto/src/component/status.proto +++ b/proto/src/component/status.proto @@ -1,6 +1,6 @@ syntax = "proto3"; package cstate; -option go_package = "./cstate"; +option go_package = "./components/cstate"; //仿真底层ecs组件相关定义 diff --git a/repository/model/check_point.go b/repository/model/check_point.go index f939114..f56bbb3 100644 --- a/repository/model/check_point.go +++ b/repository/model/check_point.go @@ -4,7 +4,7 @@ import "joylink.club/rtsssimulation/repository/model/proto" // 检测点 type CheckPoint struct { - Model + Identity km proto.Kilometer t proto.CheckPointType //检测点类型 diff --git a/repository/model/device_port.go b/repository/model/device_port.go index ba6dea9..2f7feac 100644 --- a/repository/model/device_port.go +++ b/repository/model/device_port.go @@ -3,7 +3,7 @@ package model import "joylink.club/rtsssimulation/repository/model/proto" type PortedDevice interface { - Model + Identity // 端口数量 PortNum() int diff --git a/repository/model/link.go b/repository/model/link.go index 3155534..e85aa6d 100644 --- a/repository/model/link.go +++ b/repository/model/link.go @@ -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 +} diff --git a/repository/model/model.go b/repository/model/model.go index a9a1d14..85da20b 100644 --- a/repository/model/model.go +++ b/repository/model/model.go @@ -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 { - id string - modelType ModelType +// 身份信息 +type identity struct { + id string } -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 } diff --git a/repository/model/physical_section.go b/repository/model/physical_section.go index f96693a..0619fc4 100644 --- a/repository/model/physical_section.go +++ b/repository/model/physical_section.go @@ -4,12 +4,34 @@ import "joylink.club/rtsssimulation/repository/model/proto" // 物理区段 type PhysicalSection struct { - Model + Identity len int32 //长度 mm checkPoints []*CheckPoint //将此区段分隔出来的所有检测点 - aRelation DevicePort - bRelation DevicePort + // 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 { diff --git a/repository/model/turnout.go b/repository/model/turnout.go index 3cba85e..847fb28 100644 --- a/repository/model/turnout.go +++ b/repository/model/turnout.go @@ -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 + km proto.Kilometer + + // 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 { diff --git a/repository/repository.go b/repository/repository.go index 1cfb47b..13a99d9 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -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) { // }