双机zdj9道岔测试
This commit is contained in:
parent
3a989ac1b2
commit
32a46687f4
@ -24,7 +24,7 @@ func main() {
|
|||||||
//
|
//
|
||||||
worldConfig := simulation.WorldConfig{
|
worldConfig := simulation.WorldConfig{
|
||||||
ModelManager: worldStorage,
|
ModelManager: worldStorage,
|
||||||
Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewMovableSystem(), system.NewDebugSystem()},
|
Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()},
|
||||||
Tick: 100,
|
Tick: 100,
|
||||||
InitTime: time.Now(),
|
InitTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package tmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"joylink.club/rtsssimulation/umi"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 计轴检测点模型
|
|
||||||
type AxlePointModel struct {
|
|
||||||
DeviceModel
|
|
||||||
//计轴检测点所在轨道
|
|
||||||
LinkOffset umi.ILinkOffsetRef
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAxlePointModel(id string) *AxlePointModel {
|
|
||||||
return &AxlePointModel{DeviceModel: DeviceModel{Id: id, Type: umi.AxlePoint}}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package tmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"joylink.club/rtsssimulation/umi"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 应答器
|
|
||||||
type BaliseModel struct {
|
|
||||||
DeviceModel
|
|
||||||
//应答器所在轨道
|
|
||||||
LinkOffset umi.ILinkOffsetRef
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBaliseModel(id string) *BaliseModel {
|
|
||||||
return &BaliseModel{DeviceModel: DeviceModel{Id: id, Type: umi.Balise}}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package tmodel
|
|
||||||
|
|
||||||
import "joylink.club/rtsssimulation/umi"
|
|
||||||
|
|
||||||
//两档位按钮
|
|
||||||
type TowPosButtonModel struct {
|
|
||||||
DeviceModel
|
|
||||||
// 按钮名称
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTowPosButtonModel(id string) *TowPosButtonModel {
|
|
||||||
return &TowPosButtonModel{DeviceModel: DeviceModel{Id: id, Type: umi.TowPosButton}}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package tmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"joylink.club/rtsssimulation/umi"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 站台一侧屏蔽门模型
|
|
||||||
type PsdModel struct {
|
|
||||||
DeviceModel
|
|
||||||
//屏蔽门所包含的单元
|
|
||||||
Cells []*PsdCellModel
|
|
||||||
//屏蔽门移动从0-100耗时,单位ms
|
|
||||||
MoveTime int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPsdModel(id string) *PsdModel {
|
|
||||||
return &PsdModel{DeviceModel: DeviceModel{Id: id, Type: umi.Psd}, Cells: make([]*PsdCellModel, 0)}
|
|
||||||
}
|
|
||||||
func (me *PsdModel) addCell(cell *PsdCellModel) {
|
|
||||||
me.Cells = append(me.Cells, cell)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 屏蔽门移动从0-100耗时,单位ms
|
|
||||||
func (me *PsdModel) MovingTime() int64 {
|
|
||||||
return me.MoveTime
|
|
||||||
}
|
|
||||||
|
|
||||||
// 屏蔽门的所有单元门
|
|
||||||
func (me *PsdModel) AllDeviceCells() []umi.IDeviceModel {
|
|
||||||
rt := make([]umi.IDeviceModel, 0, len(me.Cells))
|
|
||||||
for _, cell := range me.Cells {
|
|
||||||
rt = append(rt, cell)
|
|
||||||
}
|
|
||||||
return rt
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
|
||||||
|
|
||||||
// 站台一侧屏蔽门单元模型
|
|
||||||
type PsdCellModel struct {
|
|
||||||
DeviceModel
|
|
||||||
//该屏蔽门单元所属的屏蔽门
|
|
||||||
psd umi.IDeviceModel
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPsdCellModel(id string, psdModel *PsdModel) *PsdCellModel {
|
|
||||||
cell := &PsdCellModel{
|
|
||||||
DeviceModel: DeviceModel{Id: id, Type: umi.PsdCell},
|
|
||||||
psd: psdModel,
|
|
||||||
}
|
|
||||||
psdModel.addCell(cell)
|
|
||||||
return cell
|
|
||||||
}
|
|
||||||
func (me *PsdCellModel) Psd() *PsdModel {
|
|
||||||
return me.psd.(*PsdModel)
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ import (
|
|||||||
"joylink.club/rtsssimulation/umi"
|
"joylink.club/rtsssimulation/umi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 仿真world配置
|
// WorldConfig 仿真world配置
|
||||||
type WorldConfig struct {
|
type WorldConfig struct {
|
||||||
//模型管理器,接收模型仓库管理器实例的指针
|
//模型管理器,接收模型仓库管理器实例的指针
|
||||||
ModelManager umi.IModelManager
|
ModelManager umi.IModelManager
|
||||||
|
@ -3,18 +3,20 @@ package simulation
|
|||||||
import (
|
import (
|
||||||
"joylink.club/ecs"
|
"joylink.club/ecs"
|
||||||
"joylink.club/rtsssimulation/entities"
|
"joylink.club/rtsssimulation/entities"
|
||||||
|
"joylink.club/rtsssimulation/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 初始化仿真world
|
// InitializeWorld 初始化仿真world
|
||||||
func InitializeWorld(config *WorldConfig) ecs.World {
|
func InitializeWorld(config *WorldConfig) ecs.World {
|
||||||
world := ecs.NewWorld(config.Tick)
|
world := ecs.NewWorld(config.Tick)
|
||||||
// 初始化系统
|
// 添加系统
|
||||||
|
world.AddSystem(system.NewTimerSystem())
|
||||||
|
world.AddSystem(system.NewMovableSystem())
|
||||||
for _, sys := range config.Systems {
|
for _, sys := range config.Systems {
|
||||||
world.AddSystem(sys)
|
world.AddSystem(sys)
|
||||||
}
|
}
|
||||||
// 创建world时间实体
|
// 添加内置实体
|
||||||
entities.CreateSystemTimerEntity(world, config.InitTime)
|
entities.CreateSystemTimerEntity(world, config.InitTime)
|
||||||
// 创建world模型仓库实体
|
|
||||||
entities.CreateModelStorageEntity(world, config.ModelManager)
|
entities.CreateModelStorageEntity(world, config.ModelManager)
|
||||||
//
|
//
|
||||||
return world
|
return world
|
||||||
|
@ -2,7 +2,7 @@ package sysEvent
|
|||||||
|
|
||||||
import "joylink.club/ecs"
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
//继电器动作事件
|
// RelayActionEvent 继电器动作事件
|
||||||
// 由继电器实体系统产生,表示继电器吸合落下动作
|
// 由继电器实体系统产生,表示继电器吸合落下动作
|
||||||
type RelayActionEvent struct {
|
type RelayActionEvent struct {
|
||||||
//继电器id
|
//继电器id
|
||||||
@ -11,7 +11,7 @@ type RelayActionEvent struct {
|
|||||||
Xh bool
|
Xh bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//继电器状态须改变事件
|
// RelayNeedChangeEvent 继电器状态须改变事件
|
||||||
// 由电路系统运算发现某个继电器需要改变,则由电路系统产生该事件来通知对应继电器产生对应动作
|
// 由电路系统运算发现某个继电器需要改变,则由电路系统产生该事件来通知对应继电器产生对应动作
|
||||||
type RelayNeedChangeEvent struct {
|
type RelayNeedChangeEvent struct {
|
||||||
//继电器id
|
//继电器id
|
||||||
@ -20,8 +20,8 @@ type RelayNeedChangeEvent struct {
|
|||||||
Xh bool
|
Xh bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//继电器动作事件总线
|
// RelayActionEventBus 继电器动作事件总线
|
||||||
var RelayActionEventBus = ecs.NewEventType[RelayActionEvent]()
|
var RelayActionEventBus = ecs.NewEventType[RelayActionEvent]()
|
||||||
|
|
||||||
//继电器状态须改变事件总线
|
// RelayNeedChangeEventBus 继电器状态须改变事件总线
|
||||||
var RelayNeedChangeEventBus = ecs.NewEventType[RelayNeedChangeEvent]()
|
var RelayNeedChangeEventBus = ecs.NewEventType[RelayNeedChangeEvent]()
|
||||||
|
@ -2,7 +2,7 @@ package sysEvent
|
|||||||
|
|
||||||
import "joylink.club/ecs"
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
//信号机3XH1显示状态变化事件
|
// Signal3XH1AspectChangedEvent 信号机3XH1显示状态变化事件
|
||||||
type Signal3XH1AspectChangedEvent struct {
|
type Signal3XH1AspectChangedEvent struct {
|
||||||
//信号机id
|
//信号机id
|
||||||
Id string
|
Id string
|
||||||
@ -14,5 +14,5 @@ type Signal3XH1AspectChangedEvent struct {
|
|||||||
H bool
|
H bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//信号机3XH1显示状态变化事件总线
|
// Signal3XH1AspectChangedEventBus 信号机3XH1显示状态变化事件总线
|
||||||
var Signal3XH1AspectChangedEventBus = ecs.NewEventType[Signal3XH1AspectChangedEvent]()
|
var Signal3XH1AspectChangedEventBus = ecs.NewEventType[Signal3XH1AspectChangedEvent]()
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"joylink.club/ecs"
|
"joylink.club/ecs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 时间维度上移动的物体
|
// MovableObject 一维移动的物体
|
||||||
type MovableObject struct {
|
type MovableObject struct {
|
||||||
Value int64
|
Value int64
|
||||||
//移动方向:0-不动,1-变大,-1 -变小
|
//移动方向:0-不动,1-变大,-1 -变小
|
||||||
@ -16,7 +16,7 @@ func NewMovableObject() *MovableObject {
|
|||||||
return &MovableObject{Value: 0, direction: 0}
|
return &MovableObject{Value: 0, direction: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 时间维度上移动物体组件
|
// MovableObjectComponent 一维移动的物体组件
|
||||||
var MovableObjectComponent = ecs.NewComponentType[MovableObject]()
|
var MovableObjectComponent = ecs.NewComponentType[MovableObject]()
|
||||||
var MovableObject1Component = ecs.NewComponentType[MovableObject]()
|
var MovableObject1Component = ecs.NewComponentType[MovableObject]()
|
||||||
var MovableObject2Component = ecs.NewComponentType[MovableObject]()
|
var MovableObject2Component = ecs.NewComponentType[MovableObject]()
|
||||||
@ -31,7 +31,7 @@ func NewMovableSystem() *MovableSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *MovableSystem) Update(w ecs.World) {
|
func (me *MovableSystem) Update(w ecs.World) {
|
||||||
me.query.Each(w, func(e *ecs.Entry) {
|
me.query.Each(w, func(e *ecs.Entry) {
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 继电器有两个线圈1-2,3-4
|
// RelayState 继电器有两个线圈1-2,3-4
|
||||||
// 电流方向1->2,3->4或4->3,2->1时产生同向磁场
|
// 电流方向1->2,3->4或4->3,2->1时产生同向磁场
|
||||||
type RelayState struct {
|
type RelayState struct {
|
||||||
//继电器是否吸合
|
//继电器是否吸合
|
||||||
@ -21,15 +21,15 @@ func NewRelayState() *RelayState {
|
|||||||
return &RelayState{Xh: false, needXh: false}
|
return &RelayState{Xh: false, needXh: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使needXh同Xh
|
// ResetNeedXh 使needXh同Xh
|
||||||
func (me *RelayState) ResetNeedXh() {
|
func (me *RelayState) ResetNeedXh() {
|
||||||
me.needXh = me.Xh
|
me.needXh = me.Xh
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继电器状态组件
|
// RelayStateComponent 继电器状态组件
|
||||||
var RelayStateComponent = ecs.NewComponentType[RelayState]()
|
var RelayStateComponent = ecs.NewComponentType[RelayState]()
|
||||||
|
|
||||||
// 继电器系统
|
// RelaySystem 继电器系统
|
||||||
type RelaySystem struct {
|
type RelaySystem struct {
|
||||||
relayQuery *ecs.Query
|
relayQuery *ecs.Query
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func RelayAddListeners(w ecs.World) {
|
|||||||
sysEvent.RelayNeedChangeEventBus.Subscribe(w, RelayNeedChangeEventProcessor)
|
sysEvent.RelayNeedChangeEventBus.Subscribe(w, RelayNeedChangeEventProcessor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继电器须要改变事件处理
|
// RelayNeedChangeEventProcessor 继电器须要改变事件处理
|
||||||
var RelayNeedChangeEventProcessor = func(w ecs.World, event sysEvent.RelayNeedChangeEvent) {
|
var RelayNeedChangeEventProcessor = func(w ecs.World, event sysEvent.RelayNeedChangeEvent) {
|
||||||
log.Println("==>>收到继电器须改变事件:id = ", event.Id, " xh = ", event.Xh)
|
log.Println("==>>收到继电器须改变事件:id = ", event.Id, " xh = ", event.Xh)
|
||||||
relayEntry := FindEntityById(w, event.Id)
|
relayEntry := FindEntityById(w, event.Id)
|
||||||
@ -64,7 +64,7 @@ var RelayNeedChangeEventProcessor = func(w ecs.World, event sysEvent.RelayNeedCh
|
|||||||
relayState.needXh = event.Xh
|
relayState.needXh = event.Xh
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *RelaySystem) Update(w ecs.World) {
|
func (me *RelaySystem) Update(w ecs.World) {
|
||||||
me.relayQuery.Each(w, func(e *ecs.Entry) {
|
me.relayQuery.Each(w, func(e *ecs.Entry) {
|
||||||
relayState := RelayStateComponent.Get(e)
|
relayState := RelayStateComponent.Get(e)
|
||||||
|
@ -27,7 +27,7 @@ const (
|
|||||||
SIGNAL_ZXJ = "ZXJ"
|
SIGNAL_ZXJ = "ZXJ"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 电路状态:信号机3XH-1(红-绿-黄) 道岔防护信号机(三显示不封灯,有单黄显示、带引导)
|
// Signal3XH1State 电路状态:信号机3XH-1(红-绿-黄) 道岔防护信号机(三显示不封灯,有单黄显示、带引导)
|
||||||
type Signal3XH1State struct {
|
type Signal3XH1State struct {
|
||||||
// 物理黄灯,true-亮
|
// 物理黄灯,true-亮
|
||||||
U bool
|
U bool
|
||||||
@ -63,7 +63,7 @@ func NewSignal3XH1State() *Signal3XH1State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 信号机3XH-1电路状态组件
|
// Signal3XH1StateComponent 信号机3XH-1电路状态组件
|
||||||
var Signal3XH1StateComponent = ecs.NewComponentType[Signal3XH1State]()
|
var Signal3XH1StateComponent = ecs.NewComponentType[Signal3XH1State]()
|
||||||
var signal3XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH1StateComponent))
|
var signal3XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH1StateComponent))
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func NewSignal3XH1System() *Signal3XH1System {
|
|||||||
return &Signal3XH1System{}
|
return &Signal3XH1System{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继电器动作事件处理
|
// Signal3XH1RelayActionEventProcessor 继电器动作事件处理
|
||||||
// 将继电器动作的结果同步到系统
|
// 将继电器动作的结果同步到系统
|
||||||
var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
||||||
//根据event来更新Signal3XH1State中对应继电器的状态
|
//根据event来更新Signal3XH1State中对应继电器的状态
|
||||||
@ -111,7 +111,7 @@ var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.Relay
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *Signal3XH1System) Update(w ecs.World) {
|
func (me *Signal3XH1System) Update(w ecs.World) {
|
||||||
signal3XH1Query.Each(w, func(e *ecs.Entry) {
|
signal3XH1Query.Each(w, func(e *ecs.Entry) {
|
||||||
signal3XH1State := Signal3XH1StateComponent.Get(e)
|
signal3XH1State := Signal3XH1StateComponent.Get(e)
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"joylink.club/rtsssimulation/umi"
|
"joylink.club/rtsssimulation/umi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 双机ZDJ9道岔电路系统状态定义
|
// Switch2jZdj9State 双机ZDJ9道岔电路系统状态定义
|
||||||
// 继电器: true-吸合;false-未吸合
|
// 继电器: true-吸合;false-未吸合
|
||||||
type Switch2jZdj9State struct {
|
type Switch2jZdj9State struct {
|
||||||
//定操继电器
|
//定操继电器
|
||||||
@ -100,7 +100,7 @@ type Switch2jZdj9State struct {
|
|||||||
J2_Traction int8
|
J2_Traction int8
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建ZDJ9道岔状态并初始化
|
// NewSwitch2jZdj9State 创建ZDJ9道岔状态并初始化
|
||||||
func NewSwitch2jZdj9State() *Switch2jZdj9State {
|
func NewSwitch2jZdj9State() *Switch2jZdj9State {
|
||||||
return &Switch2jZdj9State{
|
return &Switch2jZdj9State{
|
||||||
DCJ: false,
|
DCJ: false,
|
||||||
@ -148,7 +148,7 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 带限时功能断相保护器
|
// DBQState 带限时功能断相保护器
|
||||||
// 限时13秒
|
// 限时13秒
|
||||||
type DBQState struct {
|
type DBQState struct {
|
||||||
//是否缺相,true-缺相,false-三相电正常未缺相
|
//是否缺相,true-缺相,false-三相电正常未缺相
|
||||||
@ -161,7 +161,7 @@ type DBQState struct {
|
|||||||
Dc24Voltage bool
|
Dc24Voltage bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表示电路变压器,变压比2:1,将220V交流电变压后作为为道岔表示电路的电源
|
// SwitchBB 表示电路变压器,变压比2:1,将220V交流电变压后作为为道岔表示电路的电源
|
||||||
// 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压
|
// 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压
|
||||||
type SwitchBB struct {
|
type SwitchBB struct {
|
||||||
//true-变压器初级输入正常
|
//true-变压器初级输入正常
|
||||||
@ -171,7 +171,7 @@ type SwitchBB struct {
|
|||||||
OutBb int8
|
OutBb int8
|
||||||
}
|
}
|
||||||
|
|
||||||
// 道岔380V动力交流电源
|
// Switch380ACPower 道岔380V动力交流电源
|
||||||
type Switch380ACPower struct {
|
type Switch380ACPower struct {
|
||||||
//true-激活
|
//true-激活
|
||||||
Active bool
|
Active bool
|
||||||
@ -183,44 +183,38 @@ type Switch380ACPower struct {
|
|||||||
PhaseC bool
|
PhaseC bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 道岔380V动力交流电相位定义
|
// Switch380ACPhase 道岔380V动力交流电相位定义
|
||||||
type Switch380ACPhase int8
|
type Switch380ACPhase int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//不存在相位交流电
|
ACPahseN Switch380ACPhase = iota //不存在相位交流电
|
||||||
ACPahseN Switch380ACPhase = iota
|
ACPahseA //存在A相位交流电
|
||||||
//存在A相位交流电
|
ACPahseB //存在B相位交流电
|
||||||
ACPahseA
|
ACPahseC //存在C相位交流电
|
||||||
//存在B相位交流电
|
|
||||||
ACPahseB
|
|
||||||
//存在C相位交流电
|
|
||||||
ACPahseC
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 继电器常量定义
|
// 继电器常量定义
|
||||||
const (
|
const (
|
||||||
//QDJ 电源切断继电器LC震荡电路有效震荡时间ms
|
QDJ_LC_TIME int64 = 3000 //QDJ 电源切断继电器LC震荡电路有效震荡时间ms
|
||||||
QDJ_LC_TIME int64 = 3000
|
DBQ_LIMITED_TIME = 13 * 1000 //断相保护器限时,单位ms
|
||||||
//断相保护器限时,单位ms
|
|
||||||
DBQ_LIMITED_TIME = 13 * 1000
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 道岔ZDJ9电路状态组件
|
// Switch2jZdj9StateComponent 道岔ZDJ9电路状态组件
|
||||||
var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]()
|
var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]()
|
||||||
|
|
||||||
// zdj9查询
|
// zdj9查询
|
||||||
var zdj9Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Switch2jZdj9StateComponent))
|
var zdj9Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Switch2jZdj9StateComponent))
|
||||||
|
|
||||||
// 双机ZDJ9道岔系统
|
// Switch2jZdj9System 双机ZDJ9道岔系统
|
||||||
type Switch2jZdj9System struct {
|
type Switch2jZdj9System struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 双机ZDJ9道岔系统
|
// NewSwitch2jZdj9System 双机ZDJ9道岔系统
|
||||||
func NewSwitch2jZdj9System() *Switch2jZdj9System {
|
func NewSwitch2jZdj9System() *Switch2jZdj9System {
|
||||||
return &Switch2jZdj9System{}
|
return &Switch2jZdj9System{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *Switch2jZdj9System) Update(w ecs.World) {
|
func (me *Switch2jZdj9System) Update(w ecs.World) {
|
||||||
zdj9Query.Each(w, func(e *ecs.Entry) {
|
zdj9Query.Each(w, func(e *ecs.Entry) {
|
||||||
zdj9State := Switch2jZdj9StateComponent.Get(e)
|
zdj9State := Switch2jZdj9StateComponent.Get(e)
|
||||||
@ -257,12 +251,11 @@ func (me *Switch2jZdj9System) Update(w ecs.World) {
|
|||||||
|
|
||||||
// SJZDJ9双机zdj9
|
// SJZDJ9双机zdj9
|
||||||
const (
|
const (
|
||||||
//继电器组合类型
|
SJZDJ9_TDC = "TDC" //继电器组合类型
|
||||||
SJZDJ9_TDC = "TDC"
|
|
||||||
SJZDJ9_TDFJ1 = "TDFJ1"
|
SJZDJ9_TDFJ1 = "TDFJ1"
|
||||||
SJZDJ9_TDFJ2 = "TDFJ2"
|
SJZDJ9_TDFJ2 = "TDFJ2"
|
||||||
//继电器功能名称
|
|
||||||
SJZDJ9_1DQJ = "1DQJ"
|
SJZDJ9_1DQJ = "1DQJ" //继电器功能名称
|
||||||
SJZDJ9_BHJ = "BHJ"
|
SJZDJ9_BHJ = "BHJ"
|
||||||
SJZDJ9_2DQJ = "2DQJ"
|
SJZDJ9_2DQJ = "2DQJ"
|
||||||
SJZDJ9_1DQJF = "1DQJF"
|
SJZDJ9_1DQJF = "1DQJF"
|
||||||
@ -281,7 +274,7 @@ func Switch2jzdj9AddListeners(w ecs.World) {
|
|||||||
sysEvent.RelayActionEventBus.Subscribe(w, Switch2jzdj9RelayActionEventProcessor)
|
sysEvent.RelayActionEventBus.Subscribe(w, Switch2jzdj9RelayActionEventProcessor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 接收继电器动作事件
|
// Switch2jzdj9RelayActionEventProcessor 接收继电器动作事件
|
||||||
var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
||||||
log.Println("==>>收到继电器动作事件:id = ", event.Id, " xh = ", event.Xh)
|
log.Println("==>>收到继电器动作事件:id = ", event.Id, " xh = ", event.Xh)
|
||||||
zdj9Query.Each(w, func(e *ecs.Entry) {
|
zdj9Query.Each(w, func(e *ecs.Entry) {
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
"joylink.club/rtsssimulation/umi"
|
"joylink.club/rtsssimulation/umi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 实体身份定义
|
// EntityIdentity 实体身份定义
|
||||||
type EntityIdentity struct {
|
type EntityIdentity struct {
|
||||||
Id string
|
Id string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实体身份组件
|
// EntityIdentityComponent 实体身份组件
|
||||||
var EntityIdentityComponent = ecs.NewComponentType[EntityIdentity]()
|
var EntityIdentityComponent = ecs.NewComponentType[EntityIdentity]()
|
||||||
|
|
||||||
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
||||||
@ -38,7 +38,7 @@ func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
|
|||||||
|
|
||||||
var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent))
|
var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent))
|
||||||
|
|
||||||
// 获取模型仓库
|
// FindModelStorage 获取模型仓库
|
||||||
func FindModelStorage(world ecs.World) umi.IModelManager {
|
func FindModelStorage(world ecs.World) umi.IModelManager {
|
||||||
e, _ := modelStorageQuery.First(world)
|
e, _ := modelStorageQuery.First(world)
|
||||||
return ModelStorageComponent.Get(e).ModelManager
|
return ModelStorageComponent.Get(e).ModelManager
|
||||||
|
@ -11,7 +11,7 @@ var SystemTimerComponent = ecs.NewComponentType[SystemTimer]()
|
|||||||
|
|
||||||
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(SystemTimerComponent))
|
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(SystemTimerComponent))
|
||||||
|
|
||||||
// 系统时钟操作
|
// TimerSystem 系统时钟操作
|
||||||
type TimerSystem struct {
|
type TimerSystem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ func NewTimerSystem() *TimerSystem {
|
|||||||
return &TimerSystem{}
|
return &TimerSystem{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *TimerSystem) Update(w ecs.World) {
|
func (me *TimerSystem) Update(w ecs.World) {
|
||||||
if e, ok := timerQuery.First(w); ok {
|
if e, ok := timerQuery.First(w); ok {
|
||||||
timer := SystemTimerComponent.Get(e)
|
timer := SystemTimerComponent.Get(e)
|
||||||
@ -27,7 +27,7 @@ func (me *TimerSystem) Update(w ecs.World) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置world时间
|
// ResetWorldTimer 重置world时间
|
||||||
func ResetWorldTimer(w ecs.World, time time.Time) {
|
func ResetWorldTimer(w ecs.World, time time.Time) {
|
||||||
if e, ok := timerQuery.First(w); ok {
|
if e, ok := timerQuery.First(w); ok {
|
||||||
timer := SystemTimerComponent.Get(e)
|
timer := SystemTimerComponent.Get(e)
|
||||||
@ -35,7 +35,7 @@ func ResetWorldTimer(w ecs.World, time time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取world当前时间
|
// GetWorldNow 获取world当前时间
|
||||||
func GetWorldNow(w ecs.World) *time.Time {
|
func GetWorldNow(w ecs.World) *time.Time {
|
||||||
if e, ok := timerQuery.First(w); ok {
|
if e, ok := timerQuery.First(w); ok {
|
||||||
timer := SystemTimerComponent.Get(e)
|
timer := SystemTimerComponent.Get(e)
|
||||||
@ -47,29 +47,29 @@ func GetWorldNow(w ecs.World) *time.Time {
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 系统时钟,单例
|
// SystemTimer 系统时钟,单例
|
||||||
type SystemTimer struct {
|
type SystemTimer struct {
|
||||||
timer *time.Time
|
timer *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// 以指定时间构建
|
// NewSystemTimer 以指定时间构建
|
||||||
func NewSystemTimer(time *time.Time) *SystemTimer {
|
func NewSystemTimer(time *time.Time) *SystemTimer {
|
||||||
return &SystemTimer{
|
return &SystemTimer{
|
||||||
timer: time,
|
timer: time,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置时间
|
// ResetTime 重置时间
|
||||||
func (me *SystemTimer) ResetTime(time time.Time) {
|
func (me *SystemTimer) ResetTime(time time.Time) {
|
||||||
*me.timer = time
|
*me.timer = time
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前时间的副本
|
// Now 获取当前时间的副本
|
||||||
func (me *SystemTimer) Now() time.Time {
|
func (me *SystemTimer) Now() time.Time {
|
||||||
return *me.timer
|
return *me.timer
|
||||||
}
|
}
|
||||||
|
|
||||||
// tick系统时钟,单位ms
|
// Tick tick系统时钟,单位ms
|
||||||
func (me *SystemTimer) Tick(tick int) {
|
func (me *SystemTimer) Tick(tick int) {
|
||||||
*me.timer = me.timer.Add(time.Duration(tick) * time.Millisecond)
|
*me.timer = me.timer.Add(time.Duration(tick) * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ package system
|
|||||||
|
|
||||||
import "joylink.club/ecs"
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
// 实现列车在link上运行的系统
|
// TrainSystem 实现列车在link上运行的系统
|
||||||
type TrainSystem struct {
|
type TrainSystem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// world 执行
|
// Update world 执行
|
||||||
func (me *TrainSystem) Update(world ecs.World) {
|
func (me *TrainSystem) Update(world ecs.World) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,17 @@ package umi
|
|||||||
|
|
||||||
// 用户设备模型与仿真底层设备交互定义
|
// 用户设备模型与仿真底层设备交互定义
|
||||||
|
|
||||||
// 模型管理接口
|
// IModelManager 模型管理接口
|
||||||
type IModelManager interface {
|
type IModelManager interface {
|
||||||
//根据模型的复合id获取模型数据
|
//FindById 根据模型的复合id获取模型数据
|
||||||
FindById(id string) IDeviceModel
|
FindById(id string) IDeviceModel
|
||||||
//获取某类型设备的所有模型数据
|
//FindByType 获取某类型设备的所有模型数据
|
||||||
FindByType(deviceType DeviceType) []IDeviceModel
|
FindByType(deviceType DeviceType) []IDeviceModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 端口定义,如轨道、区段、道岔的端口
|
// PortEnum 端口定义,如轨道、区段、道岔的端口
|
||||||
type PortEnum = int8
|
type PortEnum = int8
|
||||||
|
|
||||||
// 具体端口枚举
|
// 具体端口枚举
|
||||||
@ -24,7 +24,7 @@ const (
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//设备类型枚举
|
// DeviceType 设备类型枚举
|
||||||
type DeviceType = int16
|
type DeviceType = int16
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -32,86 +32,79 @@ const (
|
|||||||
Link
|
Link
|
||||||
Switch
|
Switch
|
||||||
Signal
|
Signal
|
||||||
Psd
|
Relay //继电器设备
|
||||||
PsdCell
|
|
||||||
AxlePoint
|
|
||||||
//应答器
|
|
||||||
Balise
|
|
||||||
//两档位按钮
|
|
||||||
TowPosButton
|
|
||||||
//继电器设备
|
|
||||||
Relay
|
|
||||||
)
|
)
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 仿真底层设备模型定义
|
// IDeviceModel 仿真底层设备模型定义
|
||||||
// 用户所有设备模型定义须实现该接口
|
// 用户所有设备模型定义须实现该接口
|
||||||
type IDeviceModel interface {
|
type IDeviceModel interface {
|
||||||
GetId() string
|
GetId() string
|
||||||
GetType() DeviceType
|
GetType() DeviceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仿真底层道岔模型
|
// ILinkModel 仿真底层道岔模型
|
||||||
// 用户所有轨道模型定义须实现该接口
|
// 用户所有轨道模型定义须实现该接口
|
||||||
type ILinkModel interface {
|
type ILinkModel interface {
|
||||||
//获取轨道长度,单位mm
|
//Len 获取轨道长度,单位mm
|
||||||
Len() int64
|
Len() int64
|
||||||
//轨道A端连接的道岔
|
//PortASwitch 轨道A端连接的道岔
|
||||||
PortASwitch() ISwitchRef
|
PortASwitch() ISwitchRef
|
||||||
//轨道B端连接的道岔
|
//PortBSwitch 轨道B端连接的道岔
|
||||||
PortBSwitch() ISwitchRef
|
PortBSwitch() ISwitchRef
|
||||||
}
|
}
|
||||||
|
|
||||||
// 轨道引用
|
// ILinkRef 轨道引用
|
||||||
type ILinkRef interface {
|
type ILinkRef interface {
|
||||||
//被引用的轨道模型
|
//LinkModel 被引用的轨道模型
|
||||||
LinkModel() ILinkModel
|
LinkModel() ILinkModel
|
||||||
//被引用的轨道的端口
|
//LinkPort 被引用的轨道的端口
|
||||||
LinkPort() PortEnum
|
LinkPort() PortEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
// 轨道偏移引用
|
// ILinkOffsetRef 轨道偏移引用
|
||||||
type ILinkOffsetRef interface {
|
type ILinkOffsetRef interface {
|
||||||
//被引用的轨道模型
|
//LinkModel 被引用的轨道模型
|
||||||
LinkModel() ILinkModel
|
LinkModel() ILinkModel
|
||||||
//偏移量,单位mm
|
//GetOffset 偏移量,单位mm
|
||||||
GetOffset() int64
|
GetOffset() int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仿真底层道岔模型
|
// ISwitchModel 仿真底层道岔模型
|
||||||
// 用户所有道岔模型定义须实现该接口
|
// 用户所有道岔模型定义须实现该接口
|
||||||
type ISwitchModel interface {
|
type ISwitchModel interface {
|
||||||
//道岔A端口连接的轨道
|
//PortALink 道岔A端口连接的轨道
|
||||||
PortALink() ILinkRef
|
PortALink() ILinkRef
|
||||||
//道岔B端口连接的轨道
|
//PortBLink 道岔B端口连接的轨道
|
||||||
PortBLink() ILinkRef
|
PortBLink() ILinkRef
|
||||||
//道岔C端口连接的轨道
|
//PortCLink 道岔C端口连接的轨道
|
||||||
PortCLink() ILinkRef
|
PortCLink() ILinkRef
|
||||||
}
|
}
|
||||||
|
|
||||||
// 道岔引用
|
// ISwitchRef 道岔引用
|
||||||
type ISwitchRef interface {
|
type ISwitchRef interface {
|
||||||
//被引用的道岔模型
|
//SwitchModel 被引用的道岔模型
|
||||||
SwitchModel() ISwitchModel
|
SwitchModel() ISwitchModel
|
||||||
//被引用的道岔的端口
|
//SwitchPort 被引用的道岔的端口
|
||||||
SwitchPort() PortEnum
|
SwitchPort() PortEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仿真底层屏蔽门模型
|
// IPsdModel 仿真底层屏蔽门模型
|
||||||
// 用户所有屏蔽门模型定义须实现该接口
|
// 用户所有屏蔽门模型定义须实现该接口
|
||||||
type IPsdModel interface {
|
type IPsdModel interface {
|
||||||
//屏蔽门移动从0-100耗时,单位ms
|
//MovingTime 屏蔽门移动从0-100耗时,单位ms
|
||||||
MovingTime() int64
|
MovingTime() int64
|
||||||
//屏蔽门的所有单元门
|
//AllDeviceCells 屏蔽门的所有单元门
|
||||||
AllDeviceCells() []IDeviceModel
|
AllDeviceCells() []IDeviceModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////
|
||||||
//继电器类型定义
|
|
||||||
|
// RelayType 继电器类型定义
|
||||||
type RelayType = int8
|
type RelayType = int8
|
||||||
|
|
||||||
//继电器类枚举
|
// 继电器型号枚举
|
||||||
const (
|
const (
|
||||||
//无极缓放继电器
|
//无极缓放继电器
|
||||||
JWXC_1700 RelayType = iota + 1
|
JWXC_1700 RelayType = iota + 1
|
||||||
@ -135,23 +128,23 @@ const (
|
|||||||
JZXC_H18
|
JZXC_H18
|
||||||
)
|
)
|
||||||
|
|
||||||
// 继电器模型
|
// IRelayModel 继电器模型
|
||||||
type IRelayModel interface {
|
type IRelayModel interface {
|
||||||
//该继电器类型
|
//JType 该继电器类型
|
||||||
JType() RelayType
|
JType() RelayType
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取继电器在具体电路中的角色(组合类型、功能名称)
|
// IRelayCRole 获取继电器在具体电路中的角色(组合类型、功能名称)
|
||||||
// 如信号机3XH-1电路中点灯继电器:组合类型-"3XH-1" 功能名称-"DDJ"
|
// 如信号机3XH-1电路中点灯继电器:组合类型-"3XH-1" 功能名称-"DDJ"
|
||||||
// 对应设备电路中有继电器的设备模型须实现该接口
|
// 对应设备电路中有继电器的设备模型须实现该接口
|
||||||
type IRelayCRole interface {
|
type IRelayCRole interface {
|
||||||
//根据继电器id获取在具体电路中的电路角色
|
//FindCircuitRoleById 根据继电器id获取在具体电路中的电路角色
|
||||||
//relayId-继电器id
|
//relayId-继电器id
|
||||||
//relayGroup-继电器组合类型
|
//relayGroup-继电器组合类型
|
||||||
//relayName-继电器在电路中的名称
|
//relayName-继电器在电路中的名称
|
||||||
//find-true找到,false未找到
|
//find-true找到,false未找到
|
||||||
FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool)
|
FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool)
|
||||||
//根据继电器具体电路角色来获取继电器设备模型
|
//FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型
|
||||||
//relayGroup-继电器组合类型
|
//relayGroup-继电器组合类型
|
||||||
//relayName-继电器在电路中的名称
|
//relayName-继电器在电路中的名称
|
||||||
FindRelayModelByCRole(relayGroup string, relayName string) IRelayModel
|
FindRelayModelByCRole(relayGroup string, relayName string) IRelayModel
|
||||||
|
Loading…
Reference in New Issue
Block a user