diff --git a/proto/src/cg_repo.proto b/proto/src/cg_repo.proto index 6c76f68..647bdbc 100644 --- a/proto/src/cg_repo.proto +++ b/proto/src/cg_repo.proto @@ -463,9 +463,9 @@ message Lamp { // 设备电子元件组合 message DeviceEcc { - // 设备类型 + // 模型类型 Model.Type deviceType = 1; - // 设备编号 + // 模型编号 string deviceCode = 2; // 电子元件组合 repeated Ecc ecc = 3; diff --git a/repo/idmapping_build.go b/repo/idmapping_build.go index 9980f40..a390ace 100644 --- a/repo/idmapping_build.go +++ b/repo/idmapping_build.go @@ -7,7 +7,6 @@ import ( "strings" "joylink.club/rtsssimulation/repo/dto" - "joylink.club/rtsssimulation/repo/model" ) // 城轨uid @@ -58,10 +57,10 @@ type idMap struct { // 元素id Eid uint32 // 唯一id - Uid model.Uid + Uid *CgUid } -func NewIdMap(did string, eid uint32, uid model.Uid) *idMap { +func NewIdMap(did string, eid uint32, uid *CgUid) *idMap { return &idMap{ Did: did, Eid: eid, diff --git a/repo/model/api.go b/repo/model/api.go deleted file mode 100644 index d564aaa..0000000 --- a/repo/model/api.go +++ /dev/null @@ -1,57 +0,0 @@ -package model - -type ModelType string - -const ( - // 车站 - MT_Station ModelType = "Station" - // 站台 - MT_Stand ModelType = "Stand" - // 屏蔽门 - MT_PSD ModelType = "PSD" - // Link - MT_Link ModelType = "Link" - // 区段 - MT_Section ModelType = "Section" - // 道岔 - MT_Turnout ModelType = "Turnout" - // 信号机 - MT_Signal ModelType = "Signal" - // 应答器 - MT_Balise ModelType = "Balise" -) - -type Uid interface { - Id() string - // 设备原始编号 - Code() string -} - -// 模型接口 -type Model interface { - // Unique id,唯一id - Uid() Uid - // 模型类型 - Type() ModelType -} - -// Link -type Link interface { - Model -} - -// 物理区段(实际检测区段,一般区段两端点,道岔区段为3-4个端点) -type PhysicalSection interface { - Model - Code() string -} - -// 道岔 -type Turnout interface { - Model -} - -// 关联的端口关系 -type AssociatedPort interface { - Port() string -} diff --git a/repo/model/common.go b/repo/model/common.go new file mode 100644 index 0000000..a766c75 --- /dev/null +++ b/repo/model/common.go @@ -0,0 +1,34 @@ +package model + +type ModelType string + +const ( + // 车站 + ModelType_Station ModelType = "Station" + // 站台 + ModelType_Stand ModelType = "Stand" + // 屏蔽门 + ModelType_PSD ModelType = "PSD" + // Link + ModelType_Link ModelType = "Link" + // 区段 + ModelType_Section ModelType = "Section" + // 道岔 + ModelType_Turnout ModelType = "Turnout" + // 信号机 + ModelType_Signal ModelType = "Signal" + // 应答器 + ModelType_Balise ModelType = "Balise" +) + +type Uid interface { + Id() string +} + +// 模型接口 +type Model interface { + // Unique id,唯一id + Uid() Uid + // 模型类型 + Type() ModelType +} diff --git a/repo/model/impl/link.go b/repo/model/impl/link.go index 872d6fa..6ad6a9c 100644 --- a/repo/model/impl/link.go +++ b/repo/model/impl/link.go @@ -35,7 +35,7 @@ func (l *Link) Uid() string { } func (l *Link) Type() model.ModelType { - return model.MT_Link + return model.ModelType_Link } // link偏移 diff --git a/repo/model/impl/physical_section.go b/repo/model/impl/physical_section.go index cbc2d97..32d8072 100644 --- a/repo/model/impl/physical_section.go +++ b/repo/model/impl/physical_section.go @@ -25,7 +25,7 @@ func (s *PhysicalSection) Uid() string { } func (s *PhysicalSection) Type() model.ModelType { - return model.MT_Section + return model.ModelType_Section } func (s *PhysicalSection) Code() string { diff --git a/repo/model/link.go b/repo/model/link.go new file mode 100644 index 0000000..9e84047 --- /dev/null +++ b/repo/model/link.go @@ -0,0 +1,141 @@ +package model + +import "log/slog" + +// link端口 +type Link_Port int + +const ( + LinkPort_A Link_Port = -1 + LinkPort_B Link_Port = 1 +) + +// Link +type Link interface { + Model + // Link总长度 + Length() int64 + // 获取端口A关联的道岔 + GetPaTurnout() Turnout + // 获取端口B关联的道岔 + GetPbTurnout() Turnout + // 下一个link及端口 + // port - 当前link端口 + // tpos - 当前道岔位置 + Next(port Link_Port, tpos TurnoutPosition) *LinkPort +} + +type LinkPort struct { + link Link + port Link_Port +} + +func NewLinkPort(link Link, port Link_Port) *LinkPort { + return &LinkPort{ + link: link, + port: port, + } +} + +// link偏移位置 +// 默认linkA端口偏移为0,从A到B为增大,从B到A为减小 +type LinkOffset struct { + link Link + offset int64 // 偏移坐标,link相当于一个一维坐标系,以端口A为原点 +} + +// 创建link偏移位置,若offset超出link长度则返回nil +func NewLinkOffset(link Link, offset int64) *LinkOffset { + if offset < 0 || offset > link.Length() { + return nil + } + return &LinkOffset{ + link: link, + offset: offset, + } +} + +func (l *LinkOffset) Link() Link { + return l.link +} +func (l *LinkOffset) Offset() int64 { + return l.offset +} + +// link偏移范围 +type LinkRange struct { + link Link + start int64 + end int64 +} + +func NewLinkRange(link Link, a int64, b int64) *LinkRange { + if a < 0 || a > link.Length() { + slog.Error("创建link偏移范围失败: 超出link长度范围", slog.Int64("a", a)) + return nil + } else if b < 0 || b > link.Length() { + slog.Error("创建link偏移范围失败: 超出link长度范围", slog.Int64("b", b)) + return nil + } + var start int64 + var end int64 + if a > b { + start = b + end = a + } else { + start = a + end = b + } + return &LinkRange{ + link: link, + start: start, + end: end, + } +} + +// 是否相交 +func (l *LinkRange) IsIntersect(other *LinkRange) bool { + if l.link != other.link { + return false + } + if l.start > other.end || other.start > l.end { + return false + } + return true +} + +// 是否相交 +func (l *LinkRange) IsIntersect2(a, b int64) bool { + var start int64 + var end int64 + if a > b { + start = b + end = a + } else { + start = a + end = b + } + if start > l.end || end < l.start { + return false + } + return true +} + +// 是否在范围内 +func (l *LinkRange) IsInRange(lo *LinkOffset) bool { + if lo.link != l.link { + return false + } + if lo.offset < l.start || lo.offset > l.end { + return false + } + return true +} + +// 偏移坐标是否在范围内 +func (l *LinkRange) IsInRange2(offset int64) bool { + if offset < l.start || offset > l.end { + return false + } + return true +} diff --git a/repo/model/section.go b/repo/model/section.go new file mode 100644 index 0000000..93ca2fc --- /dev/null +++ b/repo/model/section.go @@ -0,0 +1,9 @@ +package model + +// 物理区段(实际检测区段) +type PhysicalSection interface { + Model + Code() string + // 所在Link范围 + LinkRanges() []*LinkRange +} diff --git a/repo/model/station.go b/repo/model/station.go new file mode 100644 index 0000000..21b6b52 --- /dev/null +++ b/repo/model/station.go @@ -0,0 +1,10 @@ +package model + +// 车站 +type Station interface { + Model + // 车站名 + Name() string + // 是否设备集中站 + IsEcs() bool +} diff --git a/repo/model/turnout.go b/repo/model/turnout.go new file mode 100644 index 0000000..10a4dd8 --- /dev/null +++ b/repo/model/turnout.go @@ -0,0 +1,32 @@ +package model + +// 道岔位置 +type TurnoutPosition int + +const ( + // 失表 + TPos_Lost TurnoutPosition = 0 + // 定位 + TPos_DW TurnoutPosition = 1 + // 反位 + TPos_FW TurnoutPosition = 2 +) + +type Turnout_Port int + +const ( + TurnoutPort_A Turnout_Port = 0 + TurnoutPort_B Turnout_Port = 1 + TurnoutPort_C Turnout_Port = 2 +) + +// 道岔 +type Turnout interface { + Model + // 获取A方向连接的link端口 + GetALinkPort() *LinkPort + // 获取B方向连接的link端口 + GetBLinkPort() *LinkPort + // 获取C方向连接的link端口 + GetCLinkPort() *LinkPort +}