From d3c51f1d000537b4981bd912e594ec81c48c6da0 Mon Sep 17 00:00:00 2001 From: walker Date: Tue, 29 Aug 2023 16:08:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B0=83=E6=95=B4model=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/basic/main.go | 14 ++++++-------- repository/model/link.go | 31 +++++++++++++++++++++++++++++-- repository/model/model.go | 23 ++++------------------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/examples/basic/main.go b/examples/basic/main.go index f06fee3..7fe9c92 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -2,17 +2,15 @@ package main import ( "fmt" - "time" - "joylink.club/ecs" - system "joylink.club/ecs/examples/rtss/sys" + "joylink.club/rtsssimulation/repository/model" + "joylink.club/rtsssimulation/repository/model/proto" ) func main() { - fmt.Println("基础测试") - w := ecs.NewWorld(1000) - w.AddSystem(system.NewTurnoutSys()) - w.StartUp() + link := model.NewLink("1") + fmt.Println(link) - time.Sleep(5 * time.Second) + lp := model.NewLinkPort(&link, proto.Port_A) + fmt.Println(lp) } diff --git a/repository/model/link.go b/repository/model/link.go index 3155534..8c704e4 100644 --- a/repository/model/link.go +++ b/repository/model/link.go @@ -9,8 +9,8 @@ type Link struct { bRelation LinkNodePort } -func NewLink(model Model) Link { - return Link{Model: model} +func NewLink(id string) Link { + return Link{Model: modelInfo{id: id}} } // link位置 @@ -27,6 +27,11 @@ type LinkNode struct { cRelation LinkPort } +func (ln LinkNode) Id() string { + return ln.turnout.Id() +} + +// link端口 type LinkPort struct { DevicePort @@ -34,9 +39,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() Model { + 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() Model { + return lp.node +} diff --git a/repository/model/model.go b/repository/model/model.go index a9a1d14..e112ccc 100644 --- a/repository/model/model.go +++ b/repository/model/model.go @@ -2,34 +2,19 @@ package model import "joylink.club/rtsssimulation/repository/model/proto" -type ModelType int - type Model interface { Id() string - Type() ModelType } -// Model 所有模型的共同父类 -type model struct { - id string - modelType ModelType +// Model 模型公共属性 +type modelInfo struct { + id string } -func NewModel(id string, modelType ModelType) Model { - return model{ - id: id, - modelType: modelType, - } -} - -func (m model) Id() string { +func (m modelInfo) Id() string { return m.id } -func (m model) Type() ModelType { - return m.modelType -} - type Signal struct { Model km proto.Kilometer From 9505fece917027d9e31f04f169cfac80e56efd50 Mon Sep 17 00:00:00 2001 From: walker Date: Tue, 29 Aug 2023 18:01:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4model=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/basic/main.go | 10 ++++++++++ repository/model/check_point.go | 2 +- repository/model/device_port.go | 2 +- repository/model/link.go | 10 ++++++---- repository/model/model.go | 17 +++++++++-------- repository/model/physical_section.go | 28 +++++++++++++++++++++++++--- repository/model/turnout.go | 22 +++++++++++++++++----- repository/repository.go | 24 ++++++++++++++++++++++++ 8 files changed, 93 insertions(+), 22 deletions(-) diff --git a/examples/basic/main.go b/examples/basic/main.go index 7fe9c92..047170e 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -3,14 +3,24 @@ package main import ( "fmt" + "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model" "joylink.club/rtsssimulation/repository/model/proto" ) +var Repo *repository.Repository + func main() { 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) + } 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 8c704e4..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 } +var _ Identity = &Link{} + func NewLink(id string) Link { - return Link{Model: modelInfo{id: id}} + return Link{Identity: identity{id: id}} } // link位置 @@ -46,7 +48,7 @@ func NewLinkPort(link *Link, port proto.Port) LinkPort { } } -func (lp LinkPort) Device() Model { +func (lp LinkPort) Device() Identity { return lp.link } @@ -64,6 +66,6 @@ func NewLinkNodePort(node *LinkNode, port proto.Port) LinkNodePort { } } -func (lp LinkNodePort) Device() Model { +func (lp LinkNodePort) Device() Identity { return lp.node } diff --git a/repository/model/model.go b/repository/model/model.go index e112ccc..85da20b 100644 --- a/repository/model/model.go +++ b/repository/model/model.go @@ -2,31 +2,32 @@ package model import "joylink.club/rtsssimulation/repository/model/proto" -type Model interface { +// 身份信息 +type Identity interface { Id() string } -// Model 模型公共属性 -type modelInfo struct { +// 身份信息 +type identity struct { id string } -func (m modelInfo) Id() string { +func (m identity) Id() string { return m.id } 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) { // } From 6d3e7661e327f4139eb385f4d9b0f51d41c3912c Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 30 Aug 2023 13:13:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9proto=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=80=BB=E8=BE=91=EF=BC=9B=E4=BF=AE=E6=94=B9?= =?UTF-8?q?status.proto=E5=AF=BC=E5=87=BA=E5=8C=85=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/main.go | 2 +- proto/src/component/status.proto | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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组件相关定义