电路测试

This commit is contained in:
xzb 2023-09-14 15:03:16 +08:00
parent 84f79d9c45
commit 075d7a8739
6 changed files with 54 additions and 4 deletions

5
examples/test1/main.go Normal file
View File

@ -0,0 +1,5 @@
package main
func main() {
}

View File

@ -0,0 +1,6 @@
package tmodel
// 继电器模型
type RelayModel struct {
DeviceModel
}

View File

@ -4,6 +4,16 @@ import (
"joylink.club/rtsssimulation/umi"
)
// 道岔电路系统中的继电器
type SwitchRelay struct {
//继电器模型
Relay umi.IRelayModel
//该继电器在该道岔电路系统中的组合类型
RelayGroup string
//该继电器在该道岔电路系统中的功能名称
RelayName string
}
// 道岔
type SwitchModel struct {
DeviceModel
@ -13,6 +23,8 @@ type SwitchModel struct {
PortB umi.ILinkRef
//道岔C端口连接的轨道
PortC umi.ILinkRef
//道岔电路系统中的继电器
Relays []SwitchRelay
}
func NewSwitchModel(id string) *SwitchModel {
@ -34,6 +46,33 @@ func (me *SwitchModel) PortCLink() umi.ILinkRef {
return me.PortC
}
// 根据继电器id获取在具体电路中的电路角色
// relayId-继电器id
// relayGroup-继电器组合类型
// relayName-继电器在电路中的名称
// find-true找到false未找到
func (me *SwitchModel) FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool) {
for _, sr := range me.Relays {
id := sr.Relay.(umi.IDeviceModel).GetId()
if id == relayId {
return sr.RelayGroup, sr.RelayName, true
}
}
return "", "", false
}
// 根据继电器具体电路角色来获取继电器设备模型
// relayGroup-继电器组合类型
// relayName-继电器在电路中的名称
func (me *SwitchModel) FindRelayModelByCRole(relayGroup string, relayName string) umi.IRelayModel {
for _, sr := range me.Relays {
if sr.RelayGroup == relayGroup && sr.RelayName == relayName {
return sr.Relay
}
}
return nil
}
//////////////////////////////////////////////////////////
// 道岔端口引用

View File

@ -173,7 +173,7 @@ func (me *Signal3XH1System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
relayRole, _ := signalModel.(umi.IRelayCRole)
relayModel := relayRole.FindRelayModelByCRole(SIGNAL_3XH1, SIGNAL_DJ)
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.GetId(), Xh: isDj})
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(umi.IDeviceModel).GetId(), Xh: isDj})
}
}
@ -187,6 +187,6 @@ func (me *Signal3XH1System) calculate2DJ(w ecs.World, e *ecs.Entry, state *Signa
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
relayRole, _ := signalModel.(umi.IRelayCRole)
relayModel := relayRole.FindRelayModelByCRole(SIGNAL_3XH1, SIGNAL_2DJ)
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.GetId(), Xh: is2DJ})
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(umi.IDeviceModel).GetId(), Xh: is2DJ})
}
}

View File

@ -368,7 +368,7 @@ func (me *Switch2jZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEnt
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(switchEntry).Id)
relayRole, _ := switchModel.(umi.IRelayCRole)
relayModel := relayRole.FindRelayModelByCRole(relayGroup, relayName)
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.GetId(), Xh: needXh})
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(umi.IDeviceModel).GetId(), Xh: needXh})
}
// 断相保护电路运算

View File

@ -154,5 +154,5 @@ type IRelayCRole interface {
//根据继电器具体电路角色来获取继电器设备模型
//relayGroup-继电器组合类型
//relayName-继电器在电路中的名称
FindRelayModelByCRole(relayGroup string, relayName string) IDeviceModel
FindRelayModelByCRole(relayGroup string, relayName string) IRelayModel
}