signal 3xh3

This commit is contained in:
xzb 2023-10-11 17:44:44 +08:00
parent ff32f14e12
commit b5cfb5b8b7
4 changed files with 54 additions and 68 deletions

View File

@ -75,3 +75,28 @@ type Signal3XH2Electronic struct {
var (
Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]()
)
//////////////////////////////////////////////////////////////////////////////
// Signal3XH3Electronic 电路状态信号机3XH-3(红-绿-黄) 道岔防护信号机(三显示封绿灯、有单黄显示、带引导)
// 引导信号:红黄
type Signal3XH3Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH3_DDJ *ecs.Entry
//2DJ灯丝继电器true-吸合
Z3XH3_2DJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH3_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH3_LXJ *ecs.Entry
//引导信号继电器true-吸合
Z3XH3_YXJ *ecs.Entry
// 物理黄灯true-亮
Z3XH3_U *ecs.Entry
// 物理红灯true-亮
Z3XH3_H *ecs.Entry
}
var (
Signal3XH3ElectronicType = ecs.NewComponentType[Signal3XH3Electronic]()
)

View File

@ -1,35 +0,0 @@
package component
import "joylink.club/ecs"
// Signal3XH3Electronic 电路状态信号机3XH-3(红-绿-黄) 道岔防护信号机(三显示封绿灯、有单黄显示、带引导)
// 引导信号:红黄
type Signal3XH3Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH3_DDJ *ecs.Entry
//2DJ灯丝继电器true-吸合
Z3XH3_2DJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH3_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH3_LXJ *ecs.Entry
//引导信号继电器true-吸合
Z3XH3_YXJ *ecs.Entry
}
// Signal3XH3Filament 信号机3XH-3 灯丝状态
type Signal3XH3Filament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
// 物理红灯true-亮
H bool
}
var (
Signal3XH3ElectronicType = ecs.NewComponentType[Signal3XH3Electronic]()
Signal3XH3FilamentType = ecs.NewComponentType[Signal3XH3Filament]()
)

View File

@ -12,7 +12,6 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 5 { //3xh3组合类型包含5个继电器
signalEntry.AddComponent(component.Signal3XH3ElectronicType)
signalEntry.AddComponent(component.Signal3XH3FilamentType)
//
elecState := &component.Signal3XH3Electronic{}
for _, elec := range elecs {
@ -33,7 +32,6 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
}
//
component.Signal3XH3ElectronicType.Set(signalEntry, elecState)
component.Signal3XH3FilamentType.Set(signalEntry, &component.Signal3XH3Filament{Uf: true, Hf: true, U: false, H: false})
} else {
return fmt.Errorf("id=[%s]的信号机3xh3电子元器件数量须为5", signal.Id())
}

View File

@ -11,58 +11,56 @@ type Signal3XH3System struct {
}
func NewSignal3XH3System() *Signal3XH3System {
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(component.Signal3XH3ElectronicType, component.Signal3XH3FilamentType))}
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(component.Signal3XH3ElectronicType))}
}
// Update world 执行
func (s *Signal3XH3System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH3ElectronicType.Get(e)
filament := component.Signal3XH3FilamentType.Get(e)
//
s.calculateU(w, state, filament)
s.calculateH(w, state, filament)
s.calculateDJ(w, e, state, filament)
s.calculate2DJ(w, e, state, filament)
s.calculateU(state)
s.calculateH(state)
s.calculateDJ(state)
s.calculate2DJ(state)
})
}
func (s *Signal3XH3System) calculateU(w ecs.World, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
isU := filament.Uf && (!ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val)
filament.U = isU
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val
driveU := component.LightDriveType.Get(state.Z3XH3_U)
driveU.Td = isU
}
func (s *Signal3XH3System) calculateH(w ecs.World, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
isH := filament.Hf && !ddj.Val && !lxj.Val
filament.H = isH
isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(state.Z3XH3_H)
driveH.Td = isH
}
func (s *Signal3XH3System) calculateDJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
ud := component.BitStateType.Get(state.Z3XH3_U)
hd := component.BitStateType.Get(state.Z3XH3_H)
isDJ := ud.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
isDJ := filament.Uf && !ddj.Val && lxj.Val || filament.Hf && !ddj.Val && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.Z3XH3_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}
func (s *Signal3XH3System) calculate2DJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
edj := component.BitStateType.Get(state.Z3XH3_2DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
is2DJ := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
if is2DJ != edj.Val {
drive := component.RelayDriveType.Get(state.Z3XH3_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}
ud := component.BitStateType.Get(state.Z3XH3_U)
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}