umi调整

This commit is contained in:
xzb 2023-09-22 10:53:51 +08:00
parent bd24347708
commit 1fb8a5b7eb
21 changed files with 69 additions and 79 deletions

View File

@ -5,11 +5,10 @@ import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// CreateModelStorageEntity 创建模型仓库实体
func CreateModelStorageEntity(w ecs.World, modelManager umi.IModelManager) *ecs.Entry {
func CreateModelStorageEntity(w ecs.World, modelManager system.IModelManager) *ecs.Entry {
e := w.Create(system.ModelStorageComponent)
system.ModelStorageComponent.Set(e, &system.ModelStorageRef{ModelManager: modelManager})
return e

View File

@ -4,11 +4,10 @@ import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// CreateStationPsdsCircuitEntity 创建车站屏蔽门电路实体
func CreateStationPsdsCircuitEntity(w ecs.World, stationId string, psds []umi.IPsdModel) *ecs.Entry {
func CreateStationPsdsCircuitEntity(w ecs.World, stationId string, psds []system.IPsdModel) *ecs.Entry {
circuit := w.Create(system.EntityIdentityComponent, system.StationPsdsCircuitStateComponent, system.PsdTagHandlerComponent)
system.EntityIdentityComponent.Set(circuit, &system.EntityIdentity{Id: stationId})
system.StationPsdsCircuitStateComponent.Set(circuit, system.NewStationPsdsCircuitState())
@ -40,7 +39,7 @@ func CreateStationPsdsCircuitEntity(w ecs.World, stationId string, psds []umi.IP
}
psdEntry := w.Create(cc...)
//
psdId := psd.(umi.IDeviceModel).Id()
psdId := psd.(system.IDeviceModel).Id()
system.EntityIdentityComponent.Set(psdEntry, &system.EntityIdentity{Id: psdId})
system.PsdStateComponent.Set(psdEntry, system.NewPsdState())
system.PercentageDeviceStateComponent.Set(psdEntry, system.NewPercentageDeviceStateL())

View File

@ -12,7 +12,6 @@ import (
"joylink.club/rtsssimulation/examples/test1/tstorages"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// Test 测试双机ZDJ9道岔
@ -90,7 +89,7 @@ func addRelays(modelStorage *tstorages.ModelStorage) {
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-dbj"))
modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-fbj"))
}
func findRelayModel(modelStorage *tstorages.ModelStorage, id string) umi.IDeviceModel {
func findRelayModel(modelStorage *tstorages.ModelStorage, id string) system.IDeviceModel {
return modelStorage.FindModelById(id)
}
func addSwitchs(modelStorage *tstorages.ModelStorage) {
@ -129,7 +128,7 @@ func initComponents(w ecs.World) {
swState := system.Switch2jZdj9StateComponent.Get(e)
swMd := system.FindModelStorage(w).FindById(swId).(*tmodel.SwitchModel)
for _, relay := range swMd.Relays {
relayId := relay.Relay.(umi.IDeviceModel).Id()
relayId := relay.Relay.(system.IDeviceModel).Id()
relayEntry := system.FindEntityById(w, relayId)
relayState := system.RelayStateComponent.Get(relayEntry)
relayGroup := relay.RelayGroup

View File

@ -1,7 +1,7 @@
package tmodel
import (
"joylink.club/rtsssimulation/umi"
"joylink.club/rtsssimulation/system"
)
// 设备模型基础信息
@ -9,12 +9,12 @@ type DeviceModel struct {
// 设备id
DevId string
// 设备类型
DevType umi.DeviceType
DevType system.DeviceType
}
func (me *DeviceModel) Id() string {
return me.DevId
}
func (me *DeviceModel) Type() umi.DeviceType {
func (me *DeviceModel) Type() system.DeviceType {
return me.DevType
}

View File

@ -2,13 +2,13 @@ package tmodel
import (
"joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/umi"
"joylink.club/rtsssimulation/system"
)
// 道岔电路系统中的继电器
type SwitchRelay struct {
//继电器模型
Relay umi.IDeviceModel
Relay system.IDeviceModel
//该继电器在该道岔电路系统中的组合类型
RelayGroup string
//该继电器在该道岔电路系统中的功能名称
@ -47,7 +47,7 @@ func (me *SwitchModel) FindCircuitRoleById(relayId string) (relayGroup string, r
// FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型
// relayGroup-继电器组合类型
// relayName-继电器在电路中的名称
func (me *SwitchModel) FindRelayModelByCRole(relayGroup string, relayName string) umi.IDeviceModel {
func (me *SwitchModel) FindRelayModelByCRole(relayGroup string, relayName string) system.IDeviceModel {
for _, sr := range me.Relays {
if sr.RelayGroup == relayGroup && sr.RelayName == relayName {
return sr.Relay

View File

@ -2,23 +2,22 @@ package tstorages
import (
"fmt"
"joylink.club/rtsssimulation/umi"
"joylink.club/rtsssimulation/system"
)
// 仿真模型数据定义
type ModelData = umi.IDeviceModel
type ModelData = system.IDeviceModel
// 模型存储、管理仓库
type ModelStorage struct {
//key-模型id,value-模型指针
idModelMap map[string]ModelData
//key-设备类型value-对应设备类型的所有模型数据的指针列表
typeModelMap map[umi.DeviceType][]ModelData
typeModelMap map[system.DeviceType][]ModelData
}
func NewModelStorage() *ModelStorage {
return &ModelStorage{idModelMap: make(map[string]ModelData, 2048), typeModelMap: make(map[umi.DeviceType][]ModelData, 128)}
return &ModelStorage{idModelMap: make(map[string]ModelData, 2048), typeModelMap: make(map[system.DeviceType][]ModelData, 128)}
}
// 添加模型数据
@ -41,7 +40,7 @@ func (me *ModelStorage) AddModel(m ModelData) error {
}
// 根据设备类型获取该类型的所有设备数据
func (me *ModelStorage) FindModelsByType(deviceType umi.DeviceType) []ModelData {
func (me *ModelStorage) FindModelsByType(deviceType system.DeviceType) []ModelData {
models, ok := me.typeModelMap[deviceType]
if ok {
return models
@ -62,7 +61,7 @@ func (me *ModelStorage) FindModelById(id string) ModelData {
}
// 遍历某个类型的所有设备
func (me *ModelStorage) ForEachModelsByType(deviceType umi.DeviceType, callback func(md ModelData)) {
func (me *ModelStorage) ForEachModelsByType(deviceType system.DeviceType, callback func(md ModelData)) {
mds := me.FindModelsByType(deviceType)
for _, modelData := range mds {
callback(modelData)

View File

@ -3,8 +3,7 @@ package tstorages
import (
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/umi"
"joylink.club/rtsssimulation/system"
)
// 共享仓库映射
@ -52,7 +51,7 @@ type WorldModelStorage struct {
}
// 根据模型的复合id获取模型数据
func (me *WorldModelStorage) FindById(id string) umi.IDeviceModel {
func (me *WorldModelStorage) FindById(id string) system.IDeviceModel {
md := me.Links.FindModelById(id)
if md != nil {
return md
@ -65,7 +64,7 @@ func (me *WorldModelStorage) FindById(id string) umi.IDeviceModel {
}
// 获取某类型设备的所有模型数据
func (me *WorldModelStorage) FindByType(deviceType umi.DeviceType) []umi.IDeviceModel {
func (me *WorldModelStorage) FindByType(deviceType system.DeviceType) []system.IDeviceModel {
if proto.DeviceType_DeviceType_Link == deviceType {
return me.Links.FindModelsByType(deviceType)
} else {

@ -1 +1 @@
Subproject commit 2949aa52e18d5d7eb8281cbba968b4bb22b6e741
Subproject commit 4997760ffb1284a7898ab84164671d5e21ec9248

View File

@ -21,3 +21,21 @@ func (m identity) Id() string {
func (m identity) Type() proto.DeviceType {
return m.deviceType
}
/////////////////////////////////////////////////////////////
// IRelayCRole 获取继电器在具体电路中的角色(组合类型、功能名称)
// 如信号机3XH-1电路中点灯继电器组合类型-"3XH-1" 功能名称-"DDJ"
// 对应设备电路中有继电器的设备模型须实现该接口
type IRelayCRole interface {
//FindCircuitRoleById 根据继电器id获取在具体电路中的电路角色
//relayId-继电器id
//relayGroup-继电器组合类型
//relayName-继电器在电路中的名称
//find-true找到false未找到
FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool)
//FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型
//relayGroup-继电器组合类型
//relayName-继电器在电路中的名称
FindRelayModelByCRole(relayGroup string, relayName string) Identity
}

View File

@ -1,16 +1,16 @@
package simulation
import (
"joylink.club/rtsssimulation/system"
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/umi"
)
// WorldConfig 仿真world配置
type WorldConfig struct {
//模型管理器,接收模型仓库管理器实例的指针
ModelManager umi.IModelManager
ModelManager system.IModelManager
//world 系统
Systems []ecs.ISystem
//world tick

View File

@ -1,14 +1,23 @@
package umi
package system
import (
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 用户设备模型与仿真底层设备交互定义
// system 视角的模型定义
type DeviceType = proto.DeviceType
// IDeviceModel 仿真底层设备模型定义
// 用户所有设备模型定义须实现该接口
type IDeviceModel = repository.Identity
// IRelayCRole 获取继电器在具体电路中的角色(组合类型、功能名称)
// 如信号机3XH-1电路中点灯继电器组合类型-"3XH-1" 功能名称-"DDJ"
// 对应设备电路中有继电器的设备模型须实现该接口
type IRelayCRole = repository.IRelayCRole
// IModelManager 模型管理接口
type IModelManager interface {
//FindById 根据模型的复合id获取模型数据
@ -21,10 +30,6 @@ type IModelManager interface {
///////////////////////////////////////////////////////////
// IDeviceModel 仿真底层设备模型定义
// 用户所有设备模型定义须实现该接口
type IDeviceModel = repository.Identity
// IPsdModel 仿真底层屏蔽门模型
// 用户所有屏蔽门模型定义须实现该接口
type IPsdModel interface {
@ -41,21 +46,3 @@ type IPsdModel interface {
//IsX8 true-下行8编组
IsX8() bool
}
// //////////////////////////////////////////////////////////
// IRelayCRole 获取继电器在具体电路中的角色(组合类型、功能名称)
// 如信号机3XH-1电路中点灯继电器组合类型-"3XH-1" 功能名称-"DDJ"
// 对应设备电路中有继电器的设备模型须实现该接口
type IRelayCRole interface {
//FindCircuitRoleById 根据继电器id获取在具体电路中的电路角色
//relayId-继电器id
//relayGroup-继电器组合类型
//relayName-继电器在电路中的名称
//find-true找到false未找到
FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool)
//FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型
//relayGroup-继电器组合类型
//relayName-继电器在电路中的名称
FindRelayModelByCRole(relayGroup string, relayName string) IDeviceModel
}

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// Signal2XH1State 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机
@ -72,7 +71,7 @@ var Signal2XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新Signal2XH1State中对应继电器的状态
signal2XH1Query.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_2XH1 {

View File

@ -6,7 +6,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// 信号机电路继电器组合类型和功能名称常量
@ -98,7 +97,7 @@ var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新Signal3XH1State中对应继电器的状态
signal3XH1Query.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_3XH1 {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// Signal3XH2State 电路状态信号机3XH-2(红-绿-黄) 道岔防护信号机(三显示不封灯、无单黄显示、带引导)
@ -76,7 +75,7 @@ var Signal3XH2RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新Signal3XH1State中对应继电器的状态
signal3XH2Query.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_3XH2 {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// Signal3XH3State 电路状态信号机3XH-3(红-绿-黄) 道岔防护信号机(三显示封绿灯、有单黄显示、带引导)
@ -72,7 +71,7 @@ var Signal3XH3RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新Signal3XH3State中对应继电器的状态
signal3XH3Query.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_3XH3 {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// Signal3XH4State 电路状态信号机3XH-4(红-绿-黄) 出站兼道岔防护信号机(三显示不封灯、有单黄显示、无引导)
@ -72,7 +71,7 @@ var Signal3XH4RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新Signal3XH4State中对应继电器的状态
signal3XH4Query.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_3XH4 {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// SignalDCXHState 电路状态信号机DCXH(蓝-白) 调车信号机
@ -62,7 +61,7 @@ var SignalDCXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新SignalDCXHState中对应继电器的状态
signalDCXHQuery.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_DCXH {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// SignalJCKXHState 电路状态信号机JCKXH(红-白-黄) 进/出库列车兼调车信号机(三显示不封灯、有单黄显示、无引导)
@ -69,7 +68,7 @@ var SignalJCKXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.Rela
//根据event来更新SignalJCKXHState中对应继电器的状态
signalJCKXHQuery.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_JCKXH {

View File

@ -5,7 +5,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// SignalJDXHState 电路状态信号机JDXH(红-绿-黄) 进段信号机(三显示不封灯、无单黄显示、带引导)
@ -71,7 +70,7 @@ var SignalJDXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
//根据event来更新SignalJDXHState中对应继电器的状态
signalJDXHQuery.Each(w, func(e *ecs.Entry) {
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := signalModel.(umi.IRelayCRole)
roler, ok := signalModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
if relayGroup == SIGNAL_JDXH {

View File

@ -7,7 +7,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// --------联锁驱动-----------------
@ -298,7 +297,7 @@ var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.Rel
log.Println("==>>收到继电器动作事件id = ", event.Id, " xh = ", event.Xh)
zdj9Query.Each(w, func(e *ecs.Entry) {
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := switchModel.(umi.IRelayCRole)
roler, ok := switchModel.(IRelayCRole)
if ok {
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
state := Switch2jZdj9StateComponent.Get(e)
@ -384,9 +383,9 @@ var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.Rel
// 发送继电器需要改变事件
func (me *Switch2jZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry *ecs.Entry, relayGroup string, relayName string, needXh bool) {
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(switchEntry).Id)
relayRole, _ := switchModel.(umi.IRelayCRole)
relayRole, _ := switchModel.(IRelayCRole)
relayModel := relayRole.FindRelayModelByCRole(relayGroup, relayName)
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(umi.IDeviceModel).Id(), Xh: needXh})
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(IDeviceModel).Id(), Xh: needXh})
}
// 断相保护电路运算

View File

@ -7,7 +7,6 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"joylink.club/rtsssimulation/umi"
)
// EntityIdentity 实体身份定义
@ -40,7 +39,7 @@ func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent))
// FindModelStorage 获取模型仓库
func FindModelStorage(world ecs.World) umi.IModelManager {
func FindModelStorage(world ecs.World) IModelManager {
e, _ := modelStorageQuery.First(world)
return ModelStorageComponent.Get(e).ModelManager
}
@ -74,7 +73,7 @@ var EntityTagHandlerComponent = ecs.NewComponentType[EntityTagHandler]()
// ModelStorageRef 模型仓库引用
// 用于world内使用查询模型
type ModelStorageRef struct {
ModelManager umi.IModelManager
ModelManager IModelManager
}
// ModelStorageComponent 模型仓库组件
@ -89,9 +88,9 @@ var ModelStorageComponent = ecs.NewComponentType[ModelStorageRef]()
// xh-true:吸合false:落下
func DriveRelay(w ecs.World, circuitModelId string, relayGroup string, relayName string, xh bool) bool {
if swModel := FindModelStorage(w).FindById(circuitModelId); swModel != nil {
if roler, isCr := swModel.(umi.IRelayCRole); isCr {
if roler, isCr := swModel.(IRelayCRole); isCr {
if relayModel := roler.FindRelayModelByCRole(relayGroup, relayName); relayModel != nil {
if deviceModel, isDm := relayModel.(umi.IDeviceModel); isDm {
if deviceModel, isDm := relayModel.(IDeviceModel); isDm {
relayId := deviceModel.Id()
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayId, Xh: xh})
return true
@ -105,9 +104,9 @@ func DriveRelay(w ecs.World, circuitModelId string, relayGroup string, relayName
func createRelayNeedChangeEvent(w ecs.World, circuitModelId string, relayGroup string, relayName string, xh bool) (*sysEvent.RelayNeedChangeEvent, bool) {
if swModel := FindModelStorage(w).FindById(circuitModelId); swModel != nil {
if roler, isCr := swModel.(umi.IRelayCRole); isCr {
if roler, isCr := swModel.(IRelayCRole); isCr {
if relayModel := roler.FindRelayModelByCRole(relayGroup, relayName); relayModel != nil {
if deviceModel, isDm := relayModel.(umi.IDeviceModel); isDm {
if deviceModel, isDm := relayModel.(IDeviceModel); isDm {
relayId := deviceModel.Id()
return &sysEvent.RelayNeedChangeEvent{Id: relayId, Xh: xh}, true
}