signal 2xh1
This commit is contained in:
parent
059ae03678
commit
1a809f1af4
@ -1,6 +1,8 @@
|
||||
package component
|
||||
|
||||
import "joylink.club/ecs"
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
)
|
||||
|
||||
// Signal2XH1Electronic 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机
|
||||
type Signal2XH1Electronic struct {
|
||||
@ -16,21 +18,7 @@ type Signal2XH1Electronic struct {
|
||||
Z2XH1_H *ecs.Entry
|
||||
}
|
||||
|
||||
// Signal2XH1Filament 信号机2XH-1 灯丝状态
|
||||
type Signal2XH1Filament struct {
|
||||
// 物理绿灯,true-灯丝正常
|
||||
Lf bool
|
||||
// 物理红灯,true-灯丝正常
|
||||
Hf bool
|
||||
// 物理绿灯,true-亮
|
||||
L bool
|
||||
// 物理红灯,true-亮
|
||||
H bool
|
||||
}
|
||||
|
||||
var (
|
||||
//Signal2XH1ElectronicType 2XH1信号机电路组件
|
||||
Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]()
|
||||
//Signal2XH1FilamentType 2XH1信号机灯丝组件
|
||||
Signal2XH1FilamentType = ecs.NewComponentType[Signal2XH1Filament]()
|
||||
)
|
||||
|
@ -12,9 +12,8 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
|
||||
|
||||
if len(elecs) == 3 { //2xh1组合类型包含3个继电器
|
||||
signalEntry.AddComponent(component.Signal2XH1ElectronicType)
|
||||
signalEntry.AddComponent(component.Signal2XH1FilamentType)
|
||||
//
|
||||
elecState := &component.Signal2XH1Electronic{}
|
||||
elecState := &component.Signal2XH1Electronic{Z2XH1_L: NewLightLEntity(w), Z2XH1_H: NewLightHEntity(w)}
|
||||
for _, elec := range elecs {
|
||||
switch elec.Code() {
|
||||
case consts.SIGNAL_DDJ:
|
||||
@ -29,7 +28,6 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
|
||||
}
|
||||
//
|
||||
component.Signal2XH1ElectronicType.Set(signalEntry, elecState)
|
||||
component.Signal2XH1FilamentType.Set(signalEntry, &component.Signal2XH1Filament{Lf: true, Hf: true, L: false, H: false})
|
||||
} else {
|
||||
return fmt.Errorf("id=[%s]的信号机2xh1,电子元器件数量须为3", signal.Id())
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import (
|
||||
"joylink.club/rtsssimulation/fi"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
"joylink.club/rtsssimulation/sys/circuit_sys"
|
||||
"joylink.club/rtsssimulation/sys/device_sys"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
@ -31,8 +29,6 @@ func main() {
|
||||
loadEntities(sim, repo)
|
||||
sim.SetSpeed(0.1)
|
||||
sim.AddSystem(sigSys.NewSignalDebugSystem())
|
||||
sim.AddSystem(device_sys.NewRelaySys())
|
||||
sim.AddSystem(circuit_sys.NewSignal2XH1System())
|
||||
sim.StartUp()
|
||||
//
|
||||
time.Sleep(1 * time.Second)
|
||||
|
@ -12,7 +12,7 @@ type SignalDebugSystem struct {
|
||||
}
|
||||
|
||||
func NewSignalDebugSystem() *SignalDebugSystem {
|
||||
return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))}
|
||||
return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))}
|
||||
}
|
||||
|
||||
// Update world 执行
|
||||
@ -20,11 +20,12 @@ func (s *SignalDebugSystem) Update(w ecs.World) {
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
uid := component.UidType.Get(entry)
|
||||
state := component.Signal2XH1ElectronicType.Get(entry)
|
||||
filament := component.Signal2XH1FilamentType.Get(entry)
|
||||
ld := component.BitStateType.Get(state.Z2XH1_L)
|
||||
hd := component.BitStateType.Get(state.Z2XH1_H)
|
||||
//
|
||||
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
||||
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
||||
//
|
||||
log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, filament.L, filament.H)
|
||||
log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, ld.Val, hd.Val)
|
||||
})
|
||||
}
|
||||
|
@ -11,37 +11,44 @@ type Signal2XH1System struct {
|
||||
}
|
||||
|
||||
func NewSignal2XH1System() *Signal2XH1System {
|
||||
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))}
|
||||
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))}
|
||||
}
|
||||
|
||||
// Update world 执行
|
||||
func (s *Signal2XH1System) Update(w ecs.World) {
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
state := component.Signal2XH1ElectronicType.Get(entry)
|
||||
filament := component.Signal2XH1FilamentType.Get(entry)
|
||||
s.calculateL(state, filament)
|
||||
s.calculateH(state, filament)
|
||||
s.calculateDJ(state, filament)
|
||||
s.calculateL(state)
|
||||
s.calculateH(state)
|
||||
s.calculateDJ(state)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
|
||||
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) {
|
||||
driveL := component.LightDriveType.Get(state.Z2XH1_L)
|
||||
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
||||
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
||||
isL := !ddj.Val && lxj.Val && filament.Lf
|
||||
filament.L = isL
|
||||
isL := !ddj.Val && lxj.Val
|
||||
if driveL.Td != isL {
|
||||
driveL.Td = isL
|
||||
}
|
||||
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
|
||||
}
|
||||
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic) {
|
||||
driveH := component.LightDriveType.Get(state.Z2XH1_H)
|
||||
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
||||
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
||||
isH := !ddj.Val && !lxj.Val && filament.Hf
|
||||
filament.H = isH
|
||||
isH := !ddj.Val && !lxj.Val
|
||||
if driveH.Td != isH {
|
||||
driveH.Td = isH
|
||||
}
|
||||
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
|
||||
}
|
||||
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic) {
|
||||
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
||||
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
||||
dj := component.BitStateType.Get(state.Z2XH1_DJ)
|
||||
isDJ := !ddj.Val && lxj.Val && filament.Lf || !ddj.Val && !lxj.Val && filament.Hf
|
||||
lf := true
|
||||
hf := true
|
||||
isDJ := !ddj.Val && lxj.Val && lf || !ddj.Val && !lxj.Val && hf
|
||||
//通知继电器进行动作
|
||||
if dj.Val != isDJ {
|
||||
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)
|
||||
|
Loading…
Reference in New Issue
Block a user