sgianl jdxh 驱采

This commit is contained in:
xzb 2023-10-13 09:31:49 +08:00
parent 4f05a50503
commit 4dbe6e6042
3 changed files with 94 additions and 65 deletions

View File

@ -322,22 +322,8 @@ type SignalJDXHElectronic struct {
JDXH_LXJ *ecs.Entry JDXH_LXJ *ecs.Entry
//引导信号继电器true-吸合 //引导信号继电器true-吸合
JDXH_YXJ *ecs.Entry JDXH_YXJ *ecs.Entry
} //引导转换继电器,true-吸合
JDXH_YZHJ *ecs.Entry
// SignalJDXHFilament 信号机JDXH 灯丝状态
type SignalJDXHFilament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理绿灯true-灯丝正常
Lf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
// 物理绿灯true-亮
L bool
// 物理红灯true-亮
H bool
} }
// SignalJDXHLsq 联锁驱 // SignalJDXHLsq 联锁驱
@ -362,5 +348,6 @@ type SignalJDXHLsc struct {
var ( var (
SignalJDXHElectronicType = ecs.NewComponentType[SignalJDXHElectronic]() SignalJDXHElectronicType = ecs.NewComponentType[SignalJDXHElectronic]()
SignalJDXHFilamentType = ecs.NewComponentType[SignalJDXHFilament]() SignalJDXHLsqType = ecs.NewComponentType[SignalJDXHLsq]()
SignalJDXHLscType = ecs.NewComponentType[SignalJDXHLsc]()
) )

View File

@ -12,7 +12,9 @@ func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 4 { //jdxh组合类型包含3个继电器 if len(elecs) == 4 { //jdxh组合类型包含3个继电器
signalEntry.AddComponent(component.SignalJDXHElectronicType) signalEntry.AddComponent(component.SignalJDXHElectronicType)
signalEntry.AddComponent(component.SignalJDXHFilamentType) signalEntry.AddComponent(component.SignalJDXHLsqType)
signalEntry.AddComponent(component.SignalJDXHLscType)
signalEntry.AddComponent(component.SignalLightsType)
// //
elecState := &component.SignalJDXHElectronic{} elecState := &component.SignalJDXHElectronic{}
for _, elec := range elecs { for _, elec := range elecs {
@ -31,7 +33,9 @@ func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
} }
// //
component.SignalJDXHElectronicType.Set(signalEntry, elecState) component.SignalJDXHElectronicType.Set(signalEntry, elecState)
component.SignalJDXHFilamentType.Set(signalEntry, &component.SignalJDXHFilament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false}) component.SignalJDXHLsqType.Set(signalEntry, &component.SignalJDXHLsq{})
component.SignalJDXHLscType.Set(signalEntry, &component.SignalJDXHLsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else { } else {
return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id()) return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id())
} }

View File

@ -11,62 +11,100 @@ type SignalJDXHSystem struct {
} }
func NewSignalJDXHSystem() *SignalJDXHSystem { func NewSignalJDXHSystem() *SignalJDXHSystem {
return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalJDXHElectronicType, component.SignalJDXHFilamentType))} return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(
component.SignalJDXHElectronicType,
component.SignalJDXHLsqType,
component.SignalJDXHLscType,
component.SignalLightsType))}
} }
// Update world 执行 // Update world 执行
func (s *SignalJDXHSystem) Update(w ecs.World) { func (s *SignalJDXHSystem) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
state := component.SignalJDXHElectronicType.Get(e) state := component.SignalJDXHElectronicType.Get(entry)
filament := component.SignalJDXHFilamentType.Get(e) lsq := component.SignalJDXHLsqType.Get(entry)
lsc := component.SignalJDXHLscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
JDXH_H := lights.GetLightByTag(component.HdTag)
JDXH_L := lights.GetLightByTag(component.LdTag)
JDXH_U := lights.GetLightByTag(component.UdTag)
// //
s.calculateL(state, filament) s.calculateLsq(state, lsq)
s.calculateU(state, filament) s.calculateL(state, JDXH_L)
s.calculateH(state, filament) s.calculateU(state, JDXH_U)
s.calculateDJ(state, filament) s.calculateH(state, JDXH_H)
s.calculate2DJ(state, filament) s.calculateDJ(state, JDXH_L, JDXH_H)
s.calculate2DJ(state, JDXH_U)
s.calculateLsc(state, lsc)
}) })
} }
func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { // 联锁驱
lxj := component.BitStateType.Get(state.JDXH_LXJ) func (s *SignalJDXHSystem) calculateLsq(state *component.SignalJDXHElectronic, lsq *component.SignalJDXHLsq) {
dj := component.BitStateType.Get(state.JDXH_DJ) lxj := component.RelayDriveType.Get(state.JDXH_LXJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ) yzhj := component.RelayDriveType.Get(state.JDXH_YZHJ)
isU := filament.Uf && !lxj.Val && dj.Val && yxj.Val //
filament.U = isU lxjQ := lsq.JDXH_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
yzhjQ := lsq.JDXH_YZHJ_Q
yzhj.Td = yzhjQ
yzhj.Xq = yzhjQ
} }
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { // 联锁采
lxj := component.BitStateType.Get(state.JDXH_LXJ) func (s *SignalJDXHSystem) calculateLsc(state *component.SignalJDXHElectronic, lsc *component.SignalJDXHLsc) {
isL := filament.Lf && lxj.Val
filament.L = isL
}
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isH := filament.Hf && !lxj.Val
filament.H = isH
}
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
isDJ := filament.Lf && lxj.Val || filament.Hf && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.JDXH_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}
func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
edj := component.BitStateType.Get(state.JDXH_2DJ) edj := component.BitStateType.Get(state.JDXH_2DJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
lxj := component.BitStateType.Get(state.JDXH_LXJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ) yxj := component.BitStateType.Get(state.JDXH_YXJ)
is2DJ := filament.Uf && !lxj.Val && dj.Val && yxj.Val yzhj := component.BitStateType.Get(state.JDXH_YZHJ)
if is2DJ != edj.Val { //
drive := component.RelayDriveType.Get(state.JDXH_2DJ) lsc.JDXH_2DJ_Xq = edj.Val
drive.Td = is2DJ lsc.JDXH_DJ_Xq = dj.Val
drive.Xq = is2DJ lsc.JDXH_LXJ_Xq = lxj.Val
} lsc.JDXH_YZHJ_YXJ_Xq = yxj.Val && yzhj.Val
}
func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ)
isU := !lxj.Val && dj.Val && yxj.Val
driveU := component.LightDriveType.Get(JDXH_U)
driveU.Td = isU
}
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isL := lxj.Val
driveL := component.LightDriveType.Get(JDXH_L)
driveL.Td = isL
}
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, JDXH_H *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isH := !lxj.Val
driveH := component.LightDriveType.Get(JDXH_H)
driveH.Td = isH
}
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry, JDXH_H *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
hd := component.BitStateType.Get(JDXH_H)
ld := component.BitStateType.Get(JDXH_L)
isDJ := ld.Val && lxj.Val || hd.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.JDXH_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ)
ud := component.BitStateType.Get(JDXH_U)
is2DJ := ud.Val && !lxj.Val && dj.Val && yxj.Val
drive := component.RelayDriveType.Get(state.JDXH_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
} }