信号机3XH1电路
This commit is contained in:
parent
8bc6bffef4
commit
0c18d84e7b
@ -13,19 +13,12 @@ type SwitchModel struct {
|
||||
PortB umi.ILinkRef
|
||||
//道岔C端口连接的轨道
|
||||
PortC umi.ILinkRef
|
||||
//道岔转动需要的时间(从开度0-100的时间),单位ms
|
||||
TurnTime int64
|
||||
}
|
||||
|
||||
func NewSwitchModel(id string) *SwitchModel {
|
||||
return &SwitchModel{DeviceModel: DeviceModel{Id: id, Type: umi.Switch}}
|
||||
}
|
||||
|
||||
// 道岔转动从0-100耗时,单位ms
|
||||
func (me *SwitchModel) TurningTime() int64 {
|
||||
return me.TurnTime
|
||||
}
|
||||
|
||||
// 道岔A端口连接的轨道
|
||||
func (me *SwitchModel) PortALink() umi.ILinkRef {
|
||||
return me.PortA
|
||||
|
@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
sysEvent "joylink.club/rtsssimulation/system/event"
|
||||
"joylink.club/rtsssimulation/umi"
|
||||
)
|
||||
|
||||
// 电路状态:信号机3XH-1(红-绿-黄) 道岔防护信号机(三显示不封灯,有单黄显示、带引导)
|
||||
@ -44,27 +47,51 @@ func NewSignal3XH1State() *Signal3XH1State {
|
||||
|
||||
// 信号机3XH-1电路状态组件
|
||||
var Signal3XH1StateComponent = ecs.NewComponentType[Signal3XH1State]()
|
||||
var signal3XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH1StateComponent))
|
||||
|
||||
type Signal3XH1System struct {
|
||||
stateQuery *ecs.Query
|
||||
}
|
||||
|
||||
func NewSignal3XH1System() *Signal3XH1System {
|
||||
return &Signal3XH1System{
|
||||
stateQuery: ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH1StateComponent)),
|
||||
}
|
||||
return &Signal3XH1System{}
|
||||
}
|
||||
|
||||
// 继电器动作事件处理
|
||||
// 将继电器动作的结果同步到系统
|
||||
var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
||||
//根据event来更新Signal3XH1State中对应继电器的状态
|
||||
|
||||
signal3XH1Query.Each(w, func(e *ecs.Entry) {
|
||||
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
|
||||
roler, ok := signalModel.(umi.IRelayCRoler)
|
||||
if ok {
|
||||
if _, relayName, find := roler.FindCircuitRole(event.Id); find {
|
||||
state := Signal3XH1StateComponent.Get(e)
|
||||
switch relayName {
|
||||
case "DDJ":
|
||||
state.DDJ = event.Xh
|
||||
case "DJ":
|
||||
state.DJ = event.Xh
|
||||
case "2DJ":
|
||||
state.EDJ = event.Xh
|
||||
case "LXJ":
|
||||
state.LXJ = event.Xh
|
||||
case "YXJ":
|
||||
state.YXJ = event.Xh
|
||||
case "ZXJ":
|
||||
state.ZXJ = event.Xh
|
||||
default:
|
||||
panic(fmt.Sprintf("Signal3XH1的模型[%s]中继电器功能名称[%s]无法识别", signalModel.GetId(), relayName))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
panic("Signal3XH1的模型未实现接口umi.IRelayCRoler")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// world 执行
|
||||
func (me *Signal3XH1System) Update(w ecs.World) {
|
||||
me.stateQuery.Each(w, func(e *ecs.Entry) {
|
||||
signal3XH1Query.Each(w, func(e *ecs.Entry) {
|
||||
signal3XH1State := Signal3XH1StateComponent.Get(e)
|
||||
//
|
||||
_U := signal3XH1State.U
|
||||
|
@ -82,8 +82,6 @@ type ILinkOffsetRef interface {
|
||||
// 仿真底层道岔模型
|
||||
// 用户所有道岔模型定义须实现该接口
|
||||
type ISwitchModel interface {
|
||||
//道岔转动从0-100耗时,单位ms
|
||||
TurningTime() int64
|
||||
//道岔A端口连接的轨道
|
||||
PortALink() ILinkRef
|
||||
//道岔B端口连接的轨道
|
||||
@ -138,12 +136,18 @@ const (
|
||||
)
|
||||
|
||||
// 继电器模型
|
||||
// 继电器按作用分类:驱动继电器、采集继电器
|
||||
type IRelayModel interface {
|
||||
//该继电器管理的设备
|
||||
ManagedDevice() IDeviceModel
|
||||
//该继电器类型
|
||||
JType() RelayType
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// 获取继电器在具体电路中的角色(组合类型、功能名称)
|
||||
// 如信号机3XH-1电路中点灯继电器:组合类型-"3XH-1" 功能名称-"DDJ"
|
||||
// 对应设备电路中有继电器的设备模型须实现该接口
|
||||
type IRelayCRoler interface {
|
||||
//relayId-继电器id
|
||||
//relayGroup-继电器组合类型
|
||||
//relayName-继电器在电路中的名称
|
||||
//find-true找到,false未找到
|
||||
FindCircuitRole(relayId string) (relayGroup string, relayName string, find bool)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user