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
//引导信号继电器true-吸合
JDXH_YXJ *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
//引导转换继电器,true-吸合
JDXH_YZHJ *ecs.Entry
}
// SignalJDXHLsq 联锁驱
@ -362,5 +348,6 @@ type SignalJDXHLsc struct {
var (
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个继电器
signalEntry.AddComponent(component.SignalJDXHElectronicType)
signalEntry.AddComponent(component.SignalJDXHFilamentType)
signalEntry.AddComponent(component.SignalJDXHLsqType)
signalEntry.AddComponent(component.SignalJDXHLscType)
signalEntry.AddComponent(component.SignalLightsType)
//
elecState := &component.SignalJDXHElectronic{}
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.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 {
return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id())
}

View File

@ -11,62 +11,100 @@ type SignalJDXHSystem struct {
}
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 执行
func (s *SignalJDXHSystem) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.SignalJDXHElectronicType.Get(e)
filament := component.SignalJDXHFilamentType.Get(e)
s.query.Each(w, func(entry *ecs.Entry) {
state := component.SignalJDXHElectronicType.Get(entry)
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.calculateU(state, filament)
s.calculateH(state, filament)
s.calculateDJ(state, filament)
s.calculate2DJ(state, filament)
s.calculateLsq(state, lsq)
s.calculateL(state, JDXH_L)
s.calculateU(state, JDXH_U)
s.calculateH(state, JDXH_H)
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) {
// 联锁驱
func (s *SignalJDXHSystem) calculateLsq(state *component.SignalJDXHElectronic, lsq *component.SignalJDXHLsq) {
lxj := component.RelayDriveType.Get(state.JDXH_LXJ)
yzhj := component.RelayDriveType.Get(state.JDXH_YZHJ)
//
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) calculateLsc(state *component.SignalJDXHElectronic, lsc *component.SignalJDXHLsc) {
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)
yzhj := component.BitStateType.Get(state.JDXH_YZHJ)
//
lsc.JDXH_2DJ_Xq = edj.Val
lsc.JDXH_DJ_Xq = dj.Val
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 := filament.Uf && !lxj.Val && dj.Val && yxj.Val
filament.U = isU
isU := !lxj.Val && dj.Val && yxj.Val
driveU := component.LightDriveType.Get(JDXH_U)
driveU.Td = isU
}
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isL := filament.Lf && lxj.Val
filament.L = isL
isL := lxj.Val
driveL := component.LightDriveType.Get(JDXH_L)
driveL.Td = isL
}
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, JDXH_H *ecs.Entry) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isH := filament.Hf && !lxj.Val
filament.H = isH
isH := !lxj.Val
driveH := component.LightDriveType.Get(JDXH_H)
driveH.Td = isH
}
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry, JDXH_H *ecs.Entry) {
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 {
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, filament *component.SignalJDXHFilament) {
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)
edj := component.BitStateType.Get(state.JDXH_2DJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ)
is2DJ := filament.Uf && !lxj.Val && dj.Val && yxj.Val
if is2DJ != edj.Val {
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
}
}