rts-sim-module/deprecated/test1/tmodel/switch_model.go
walker 0bba8f0934 删除donburi包引用
修改filter导入为从ecs项目导入
整理包结构,将弃用的包放入deprecated文件中
2023-10-09 11:17:25 +08:00

58 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tmodel
import (
"joylink.club/rtsssimulation/deprecated/system"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 道岔电路系统中的继电器
type SwitchRelay struct {
//继电器模型
Relay system.IDeviceModel
//该继电器在该道岔电路系统中的组合类型
RelayGroup string
//该继电器在该道岔电路系统中的功能名称
RelayName string
}
// 道岔
type SwitchModel struct {
DeviceModel
//道岔电路系统中的继电器
Relays []SwitchRelay
}
func NewSwitchModel(id string) *SwitchModel {
return &SwitchModel{DeviceModel: DeviceModel{DevId: id, DevType: proto.DeviceType_DeviceType_Turnout}}
}
func (me *SwitchModel) AddRelay(relay *SwitchRelay) {
me.Relays = append(me.Relays, *relay)
}
// FindCircuitRoleById 根据继电器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.Id()
if id == relayId {
return sr.RelayGroup, sr.RelayName, true
}
}
return "", "", false
}
// FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型
// relayGroup-继电器组合类型
// relayName-继电器在电路中的名称
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
}
}
return nil
}