signal 3xh2

This commit is contained in:
xzb 2023-10-11 17:25:25 +08:00
parent 412de346bc
commit ff32f14e12
4 changed files with 59 additions and 74 deletions

View File

@ -48,3 +48,30 @@ type Signal3XH1Electronic struct {
var (
Signal3XH1ElectronicType = ecs.NewComponentType[Signal3XH1Electronic]()
)
/////////////////////////////////////////////////////////////////////////
// Signal3XH2Electronic 电路状态信号机3XH-2(红-绿-黄) 道岔防护信号机(三显示不封灯、无单黄显示、带引导)
// 引导信号:红黄
type Signal3XH2Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH2_DDJ *ecs.Entry
//2DJ灯丝继电器true-吸合
Z3XH2_2DJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH2_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH2_LXJ *ecs.Entry
//引导信号继电器true-吸合
Z3XH2_YXJ *ecs.Entry
// 物理黄灯true-亮
Z3XH2_U *ecs.Entry
// 物理绿灯true-亮
Z3XH2_L *ecs.Entry
// 物理红灯true-亮
Z3XH2_H *ecs.Entry
}
var (
Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]()
)

View File

@ -1,39 +0,0 @@
package component
import "joylink.club/ecs"
// Signal3XH2Electronic 电路状态信号机3XH-2(红-绿-黄) 道岔防护信号机(三显示不封灯、无单黄显示、带引导)
// 引导信号:红黄
type Signal3XH2Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH2_DDJ *ecs.Entry
//2DJ灯丝继电器true-吸合
Z3XH2_2DJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH2_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH2_LXJ *ecs.Entry
//引导信号继电器true-吸合
Z3XH2_YXJ *ecs.Entry
}
// Signal3XH2Filament 信号机3XH-2 灯丝状态
type Signal3XH2Filament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理绿灯true-灯丝正常
Lf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
// 物理绿灯true-亮
L bool
// 物理红灯true-亮
H bool
}
var (
Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]()
Signal3XH2FilamentType = ecs.NewComponentType[Signal3XH2Filament]()
)

View File

@ -12,9 +12,8 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 5 { //3xh2组合类型包含5个继电器
signalEntry.AddComponent(component.Signal3XH2ElectronicType)
signalEntry.AddComponent(component.Signal3XH2FilamentType)
//
elecState := &component.Signal3XH2Electronic{}
elecState := &component.Signal3XH2Electronic{Z3XH2_L: NewLightLEntity(w), Z3XH2_H: NewLightHEntity(w), Z3XH2_U: NewLightUEntity(w)}
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DDJ:
@ -33,7 +32,6 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
}
//
component.Signal3XH2ElectronicType.Set(signalEntry, elecState)
component.Signal3XH2FilamentType.Set(signalEntry, &component.Signal3XH2Filament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false})
} else {
return fmt.Errorf("id=[%s]的信号机3xh2电子元器件数量须为5", signal.Id())
}

View File

@ -11,69 +11,68 @@ type Signal3XH2System struct {
}
func NewSignal3XH2System() *Signal3XH2System {
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(component.Signal3XH2ElectronicType, component.Signal3XH2FilamentType))}
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(component.Signal3XH2ElectronicType))}
}
// Update world 执行
func (s *Signal3XH2System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH2ElectronicType.Get(e)
filament := component.Signal3XH2FilamentType.Get(e)
s.calculateU(state, filament)
s.calculateL(state, filament)
s.calculateH(state, filament)
s.calculateDJ(state, filament)
s.calculate2DJ(state, filament)
s.calculateU(state)
s.calculateL(state)
s.calculateH(state)
s.calculateDJ(state)
s.calculate2DJ(state)
})
}
func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic, filament *component.Signal3XH2Filament) {
func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ)
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
isU := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
filament.U = isU
driveU := component.LightDriveType.Get(state.Z3XH2_U)
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
driveU.Td = isU
}
func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic, filament *component.Signal3XH2Filament) {
func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
isL := filament.Lf && !ddj.Val && lxj.Val
filament.L = isL
driveL := component.LightDriveType.Get(state.Z3XH2_L)
isL := !ddj.Val && lxj.Val
driveL.Td = isL
}
func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic, filament *component.Signal3XH2Filament) {
func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
isH := filament.Hf && !ddj.Val && !lxj.Val
filament.H = isH
driveH := component.LightDriveType.Get(state.Z3XH2_H)
isH := !ddj.Val && !lxj.Val
driveH.Td = isH
}
func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic, filament *component.Signal3XH2Filament) {
func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ)
isDJ := filament.Lf && !ddj.Val && lxj.Val || filament.Hf && !ddj.Val && !lxj.Val
ld := component.BitStateType.Get(state.Z3XH2_L)
hd := component.BitStateType.Get(state.Z3XH2_H)
isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
//通知继电器进行动作
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.Z3XH2_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
drive := component.RelayDriveType.Get(state.Z3XH2_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic, filament *component.Signal3XH2Filament) {
func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ)
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
edj := component.BitStateType.Get(state.Z3XH2_2DJ)
is2DJ := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
ud := component.BitStateType.Get(state.Z3XH2_U)
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//通知继电器进行动作
if is2DJ != edj.Val {
drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}
drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}