signal 2xh1
This commit is contained in:
parent
a60a390708
commit
b12b050f5a
32
component/signal_2xh1.go
Normal file
32
component/signal_2xh1.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package component
|
||||||
|
|
||||||
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
|
// Signal2XH1Electronic 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机
|
||||||
|
type Signal2XH1Electronic struct {
|
||||||
|
// 物理绿灯,true-亮
|
||||||
|
L bool
|
||||||
|
// 物理红灯,true-亮
|
||||||
|
H bool
|
||||||
|
// 点灯继电器,true-吸合,常态落下表示逻辑点灯
|
||||||
|
Z2XH1_DDJ *ecs.Entry
|
||||||
|
//灯丝继电器,true-吸合
|
||||||
|
Z2XH1_DJ *ecs.Entry
|
||||||
|
//列车信号继电器,true-吸合
|
||||||
|
Z2XH1_LXJ *ecs.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal2XH1Filament 信号机2XH-1 灯丝状态
|
||||||
|
type Signal2XH1Filament struct {
|
||||||
|
// 物理绿灯,true-灯丝正常
|
||||||
|
Lf bool
|
||||||
|
// 物理红灯,true-灯丝正常
|
||||||
|
Hf bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
//Signal2XH1ElectronicType 2XH1信号机电路组件
|
||||||
|
Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]()
|
||||||
|
//Signal2XH1FilamentType 2XH1信号机灯丝组件
|
||||||
|
Signal2XH1FilamentType = ecs.NewComponentType[Signal2XH1Filament]()
|
||||||
|
)
|
@ -11,3 +11,25 @@ const (
|
|||||||
// 继电器缓放时间,单位ms
|
// 继电器缓放时间,单位ms
|
||||||
RelayHfTime = int(0.5 * 1000)
|
RelayHfTime = int(0.5 * 1000)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 信号机电路继电器组合类型和功能名称常量
|
||||||
|
// 其他信号机的一并定义于此
|
||||||
|
const (
|
||||||
|
//继电器组合类型
|
||||||
|
SIGNAL_3XH1 = "3XH-1"
|
||||||
|
SIGNAL_3XH2 = "3XH-2"
|
||||||
|
SIGNAL_3XH3 = "3XH-3"
|
||||||
|
SIGNAL_3XH4 = "3XH-4"
|
||||||
|
SIGNAL_2XH1 = "2XH-1"
|
||||||
|
SIGNAL_JDXH = "JDXH"
|
||||||
|
SIGNAL_DCXH = "DCXH"
|
||||||
|
SIGNAL_JCKXH = "JCKXH"
|
||||||
|
//继电器功能名称
|
||||||
|
SIGNAL_DDJ = "DDJ"
|
||||||
|
SIGNAL_DJ = "DJ"
|
||||||
|
SIGNAL_2DJ = "2DJ"
|
||||||
|
SIGNAL_LXJ = "LXJ"
|
||||||
|
SIGNAL_YXJ = "YXJ"
|
||||||
|
SIGNAL_ZXJ = "ZXJ"
|
||||||
|
SIGNAL_DXJ = "DXJ"
|
||||||
|
)
|
||||||
|
50
entity/signal.go
Normal file
50
entity/signal.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LoadSignals 加载信号机实体
|
||||||
|
func LoadSignals(w ecs.World) error {
|
||||||
|
data := GetWorldData(w)
|
||||||
|
signals := data.Repo.SignalList()
|
||||||
|
for _, signal := range signals {
|
||||||
|
groups := signal.RelayGroups()
|
||||||
|
if len(groups) == 1 {
|
||||||
|
group := groups[0]
|
||||||
|
signalEntry := newSignalEntity(w, signal.Id(), data)
|
||||||
|
elecs := group.Components()
|
||||||
|
//
|
||||||
|
switch group.Code() {
|
||||||
|
case consts.SIGNAL_2XH1:
|
||||||
|
loadSignal2xh1(w, signal, signalEntry, elecs, data.EntityMap)
|
||||||
|
case consts.SIGNAL_3XH1:
|
||||||
|
case consts.SIGNAL_3XH2:
|
||||||
|
case consts.SIGNAL_3XH3:
|
||||||
|
case consts.SIGNAL_3XH4:
|
||||||
|
case consts.SIGNAL_JDXH:
|
||||||
|
case consts.SIGNAL_DCXH:
|
||||||
|
case consts.SIGNAL_JCKXH:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())
|
||||||
|
}
|
||||||
|
} else { //信号机有且只有一个组合类型
|
||||||
|
return fmt.Errorf("id=[%s]的信号机须有且只有一个组合类型", signal.Id())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新建信号机实体
|
||||||
|
func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
|
||||||
|
entry, ok := worldData.EntityMap[uid]
|
||||||
|
if !ok {
|
||||||
|
entry = w.Create(component.UidType)
|
||||||
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||||
|
worldData.EntityMap[uid] = entry
|
||||||
|
}
|
||||||
|
return entry
|
||||||
|
}
|
37
entity/signal_2xh1.go
Normal file
37
entity/signal_2xh1.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
"joylink.club/rtsssimulation/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
||||||
|
|
||||||
|
if len(elecs) == 3 { //2xh1组合类型包含3个继电器
|
||||||
|
signalEntry.AddComponent(component.Signal2XH1ElectronicType)
|
||||||
|
signalEntry.AddComponent(component.Signal2XH1FilamentType)
|
||||||
|
//
|
||||||
|
elecState := &component.Signal2XH1Electronic{L: false, H: false}
|
||||||
|
for _, elec := range elecs {
|
||||||
|
switch elec.Code() {
|
||||||
|
case consts.SIGNAL_DDJ:
|
||||||
|
elecState.Z2XH1_DDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
case consts.SIGNAL_DJ:
|
||||||
|
elecState.Z2XH1_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
case consts.SIGNAL_LXJ:
|
||||||
|
elecState.Z2XH1_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("id=[%s]的信号机2xh1,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
component.Signal2XH1ElectronicType.Set(signalEntry, elecState)
|
||||||
|
component.Signal2XH1FilamentType.Set(signalEntry, &component.Signal2XH1Filament{Lf: true, Hf: true})
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("id=[%s]的信号机2xh1,电子元器件数量须为3", signal.Id())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 7ce0d9aa7bf6cbbf045ef3aa57ec14d43a742906
|
Subproject commit 200352eb58f1704a741d367e3c8afd02ae492b58
|
@ -9,6 +9,8 @@ type Signal struct {
|
|||||||
//section *PhysicalSection
|
//section *PhysicalSection
|
||||||
//turnoutPort TurnoutPort
|
//turnoutPort TurnoutPort
|
||||||
linkPosition *LinkPosition
|
linkPosition *LinkPosition
|
||||||
|
//信号机电路系统电子元器件
|
||||||
|
componentGroups []*ElectronicComponentGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignal(id string, km *proto.Kilometer) *Signal {
|
func NewSignal(id string, km *proto.Kilometer) *Signal {
|
||||||
@ -29,3 +31,6 @@ func (s *Signal) bindLinkPosition(position *LinkPosition) {
|
|||||||
// func (s *Signal) bindTurnoutPort(tp TurnoutPort) {
|
// func (s *Signal) bindTurnoutPort(tp TurnoutPort) {
|
||||||
// s.turnoutPort = tp
|
// s.turnoutPort = tp
|
||||||
// }
|
// }
|
||||||
|
func (s *Signal) RelayGroups() []*ElectronicComponentGroup {
|
||||||
|
return s.componentGroups
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user