package circuit_sys import ( "fmt" "log/slog" "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/consts" "joylink.club/rtsssimulation/entity" ) // ZDJ9双机牵引道岔电路系统 type ZDJ9TwoDragSys struct { query *ecs.Query } func NewZdj9TwoDragSys() *ZDJ9TwoDragSys { return &ZDJ9TwoDragSys{ query: ecs.NewQuery(filter.Contains( component.Zdj9TwoElectronicType, component.TurnoutZzjType)), } } // 电路更新 func (zdj9 *ZDJ9TwoDragSys) Update(w ecs.World) { wd := entity.GetWorldData(w) zdj9.query.Each(w, func(entry *ecs.Entry) { elec := component.Zdj9TwoElectronicType.Get(entry) zdj9.exciteDriveElectronic(entry, elec, wd) // 转辙机一机电路相关动作 // 1DQJ励磁状态控制 zdj9.exciteM1_TDFJ_1DQJ(elec) // 1DQJF励磁状态控制 zdj9.exciteM1_TDFJ_1DQJF(elec) // TDFJ1_2DQJ励磁状态控制 zdj9.exciteM1_TDFJ_2DQJ(elec) // 限时断相保护器 zdj9.exciteM1_TDFJ_DBQ(w, entry, elec) // TDFJ1_BHJ励磁状态控制 zdj9.exciteM1_TDFJ_BHJ(elec) // 总保护继电器 zdj9.exciteM1_TDFJ_ZBHJ(elec) // 切断继电器 zdj9.exciteM1_TDFJ_QDJ(w, entry, elec) // 定表/反表继电器 zdj9.exciteM1_TDFJ1_DFBJ(entry, elec) // 转辙机二机电路相关动作 // 1DQJ励磁状态控制 zdj9.exciteM2_TDFJ_1DQJ(elec) // 1DQJF励磁状态控制 zdj9.exciteM2_TDFJ_1DQJF(elec) // TDFJ1_2DQJ励磁状态控制 zdj9.exciteM2_TDFJ_2DQJ(elec) // 限时断相保护器 zdj9.exciteM2_TDFJ_DBQ(w, entry, elec) // TDFJ1_BHJ励磁状态控制 zdj9.exciteM2_TDFJ_BHJ(elec) // 定表/反表继电器 zdj9.exciteM2_TDFJ1_DFBJ(entry, elec) // 总定表/反表继电器 zdj9.exciteZDFBJ(entry, elec) }) } func (zdj9 *ZDJ9TwoDragSys) handleCiQdRelay(entry *ecs.Entry, wd *component.WorldData) { if entry.HasComponent(component.UidType) { bit, err := wd.QueryQdBit(component.UidType.Get(entry).Id) if err != nil { // slog.Debug(err.Error()) return } dcj_drive := component.RelayDriveType.Get(entry) if dcj_drive.Td != bit { dcj_drive.Td = bit } } } // 处理驱动电路励磁相关继电器 func (zdj9 *ZDJ9TwoDragSys) exciteDriveElectronic(entry *ecs.Entry, elec *component.Zdj9TwoElectronic, wd *component.WorldData) { if entry.HasComponent(component.TurnoutFaultCiqdType) { // 联锁驱动失效 return } zdj9.handleCiQdRelay(elec.TDC_DCJ, wd) zdj9.handleCiQdRelay(elec.TDC_FCJ, wd) zdj9.handleCiQdRelay(elec.TDC_YCJ, wd) } // 总定表、反表继电器控制 func (zdj9 *ZDJ9TwoDragSys) exciteZDFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { tdfj1_dbj := component.BitStateType.Get(elec.TDFJ1_DBJ) tdfj2_dbj := component.BitStateType.Get(elec.TDFJ2_DBJ) tdfj1_fbj := component.BitStateType.Get(elec.TDFJ1_FBJ) tdfj2_fbj := component.BitStateType.Get(elec.TDFJ2_FBJ) zdbj_drive := component.RelayDriveType.Get(elec.TDC_ZDBJ) zfbj_drive := component.RelayDriveType.Get(elec.TDC_ZFBJ) // 总定表 if zdbj_drive.Td { // 总定表继电器通电,监测电路是否断开 if !(isZdbjDrive(entry, tdfj1_dbj, tdfj2_dbj)) { zdbj_drive.Td = false } } else { if isZdbjDrive(entry, tdfj1_dbj, tdfj2_dbj) { zdbj_drive.Td = true } } // 总反表 if zfbj_drive.Td { if !(isZfbjDrive(entry, tdfj1_fbj, tdfj2_fbj)) { zfbj_drive.Td = false } } else { if isZfbjDrive(entry, tdfj1_fbj, tdfj2_fbj) { zfbj_drive.Td = true } } } // 总定表继电器驱动电路是否导通 func isZdbjDrive(entry *ecs.Entry, tdfj1_dbj *component.BitState, tdfj2_dbj *component.BitState) bool { return tdfj1_dbj.Val && tdfj2_dbj.Val && !entry.HasComponent(component.TurnoutFaultSbType) && !entry.HasComponent(component.TurnoutFaultDwsbType) } func isZfbjDrive(entry *ecs.Entry, tdfj1_fbj *component.BitState, tdfj2_fbj *component.BitState) bool { return tdfj1_fbj.Val && tdfj2_fbj.Val && !entry.HasComponent(component.TurnoutFaultSbType) && !entry.HasComponent(component.TurnoutFaultFwsbType) } // 二极管整流电路为继电器励磁电路提供半波整流电源 // 转辙机一定表/反表继电器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { _1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ) _2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ) zzj := component.GetTurnoutZzj1State(entry) dbj_drive := component.RelayDriveType.Get(elec.TDFJ1_DBJ) fbj_drive := component.RelayDriveType.Get(elec.TDFJ1_FBJ) zdj9.exciteDFBJ(_1dqj, _2dqj, zzj, dbj_drive, fbj_drive) } // 转辙机二定表/反表继电器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { _1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ) _2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ) zzj := component.GetTurnoutZzj2State(entry) dbj_drive := component.RelayDriveType.Get(elec.TDFJ2_DBJ) fbj_drive := component.RelayDriveType.Get(elec.TDFJ2_FBJ) zdj9.exciteDFBJ(_1dqj, _2dqj, zzj, dbj_drive, fbj_drive) } // 定反表励磁控制 func (zdj9 *ZDJ9TwoDragSys) exciteDFBJ(_1dqj *component.BitState, _2dqj *component.BitState, zzj *component.ZzjState, dbj_drive *component.RelayDrive, fbj_drive *component.RelayDrive) { // 默认BB(道岔表示变压器)正常 if !dbj_drive.Td { // 定表继电器未通电 if !_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34 { // 1DQJ落下,2DQJ定位,开闭器接点在1/3排 dbj_drive.Td = true } } else { // 定表继电器通电 if !(!_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34) { // 励磁电路断开 dbj_drive.Td = false } } if !fbj_drive.Td { // 反表继电器未通电 if !_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34 { // 2DQJ反位,开闭器在2/4排 fbj_drive.Td = true } } else { // 反表继电器通电 if !(!_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34) { // 电路断开 fbj_drive.Td = false } } } // 切断继电器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ) tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ) tdfj1_zbhj := component.BitStateType.Get(elec.TDFJ1_ZBHJ) tdfj1_qdj := component.BitStateType.Get(elec.TDFJ1_QDJ) drive := component.RelayDriveType.Get(elec.TDFJ1_QDJ) if !tdfj1_qdj.Val { // 落下状态 if !drive.Td && (!tdfj1_bhj.Val && !tdfj2_bhj.Val) || tdfj1_zbhj.Val { // 电路导通 drive.Td = true elec.TDFJ1_QDJ_Remain = consts.QDJ_DELAY slog.Debug("切断继电器通电") } } else { // 吸起状态 if drive.Td && !tdfj1_zbhj.Val && !(!tdfj1_bhj.Val && !tdfj2_bhj.Val) { // 电路断开 // 延时电路 if elec.TDFJ1_QDJ_Remain > 0 { remain := elec.TDFJ1_QDJ_Remain - w.Tick() if remain <= 0 { elec.TDFJ1_QDJ_Remain = 0 drive.Td = false slog.Debug("切断继电器断电") } else { elec.TDFJ1_QDJ_Remain = remain } } } } } // 总保护继电器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9TwoElectronic) { tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ) tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ) tdfj1_zbhj := component.RelayDriveType.Get(elec.TDFJ1_ZBHJ) if !tdfj1_zbhj.Td { // 未通电 if tdfj1_bhj.Val && tdfj2_bhj.Val { // 励磁电路导通 tdfj1_zbhj.Td = true } } else { // 通电 if !tdfj1_bhj.Val && !tdfj2_bhj.Val { // 励磁电路断开 tdfj1_zbhj.Td = false } } } // 转辙机一断相保护器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { _1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ) _1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF) _2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ) zzj := component.GetTurnoutZzj1State(entry) dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ) zdj9.exciteDBQ(1, _1dqj, _1dqjf, _2dqj, dbq, zzj) } // 转辙机二断相保护器控制 func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) { _1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ) _1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF) _2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ) zzj := component.GetTurnoutZzj2State(entry) dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ) zdj9.exciteDBQ(2, _1dqj, _1dqjf, _2dqj, dbq, zzj) } // 断相保护器控制 // i - 几号转辙机(1/2) func (zdj9 *ZDJ9TwoDragSys) exciteDBQ(i int, _1dqj *component.BitState, _1dqjf *component.BitState, _2dqj *component.BitState, dbq *component.DBQState, zzj *component.ZzjState) { if dbq.Td { // 通电 if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) && !(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开 dbq.Td = false zzj.Td = false slog.Debug(fmt.Sprintf("转辙机%v断电", i)) } else { // 处理正反转 if zzj.Dw && !_2dqj.Val { zzj.Dw = false slog.Debug(fmt.Sprintf("转辙机%v转到反位", i)) } else if !zzj.Dw && _2dqj.Val { zzj.Dw = true slog.Debug(fmt.Sprintf("转辙机%v转到定位", i)) } } } else { // 未通电 if _1dqj.Val && _1dqjf.Val && ((!zzj.JD12 && !_2dqj.Val) || (zzj.JD34 && _2dqj.Val)) { // 通电 dbq.Td = true zzj.Td = true slog.Debug(fmt.Sprintf("转辙机%v通电", i)) } } } // 转辙机一TDFJ_BHJ保护继电器励磁状态控制 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) { dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ) bhj := component.RelayDriveType.Get(elec.TDFJ1_BHJ) zdj9.exciteBHJ(dbq, bhj) } // 转辙机二TDFJ_BHJ保护继电器励磁状态控制 func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) { dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ) bhj := component.RelayDriveType.Get(elec.TDFJ2_BHJ) zdj9.exciteBHJ(dbq, bhj) } // 保护继电器励磁控制 func (zdj9 *ZDJ9TwoDragSys) exciteBHJ(dbq *component.DBQState, bhj *component.RelayDrive) { if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通 bhj.Td = true } else if bhj.Td && !dbq.Dzkg { // BHJ励磁电路断开 bhj.Td = false } } // 转辙机一TDFJ_1DQJF励磁电路逻辑 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) { tdfj_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ) tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ1_1DQJF) zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive) } // 转辙机二TDFJ_1DQJF励磁电路逻辑 func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) { tdfj_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ) tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ2_1DQJF) zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive) } // 1DQJF励磁控制 func (zdj9 *ZDJ9TwoDragSys) excite1DQJF(_1dqj *component.BitState, _1dqjf_drive *component.RelayDrive) { if _1dqjf_drive.Td { // 通电 if !_1dqj.Val { _1dqjf_drive.Td = false } } else { // 未通电 if _1dqj.Val { _1dqjf_drive.Td = true } } } // 转辙机一TDFJ_1DQJ励磁电路逻辑 func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) { // 暂时先实现非应急按钮操作 ycj := component.BitStateType.Get(elec.TDC_YCJ) dcj := component.BitStateType.Get(elec.TDC_DCJ) fcj := component.BitStateType.Get(elec.TDC_FCJ) tdfj1_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ) tdfj1_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ) bhj := component.BitStateType.Get(elec.TDFJ1_BHJ) qdj := component.BitStateType.Get(elec.TDFJ1_QDJ) drive := component.RelayDriveType.Get(elec.TDFJ1_1DQJ) if drive.Td { // 通电 // 判定是否所有励磁电路断开(todo 暂不考虑应急按钮) if !(qdj.Val && bhj.Val) && !(ycj.Val && ((tdfj1_2dqj.Val && fcj.Val) || (!tdfj1_2dqj.Val && dcj.Val))) { // 电路断开 drive.Td = false slog.Debug("TDFJ1_1DQJ断电") } } else { // 未通电 if (ycj.Val && ((tdfj1_2dqj.Val && fcj.Val) || (!tdfj1_2dqj.Val && dcj.Val))) || (tdfj1_1dqj.Val && qdj.Val && bhj.Val) { // 电路导通 drive.Td = true slog.Debug("TDFJ1_1DQJ通电") } } } // 转辙机二TDFJ_1DQJ励磁电路逻辑 func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) { // 暂时先实现非应急按钮操作 ycj := component.BitStateType.Get(elec.TDC_YCJ) dcj := component.BitStateType.Get(elec.TDC_DCJ) fcj := component.BitStateType.Get(elec.TDC_FCJ) tdfj1_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ) tdfj2_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ) tdfj2_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ) bhj := component.BitStateType.Get(elec.TDFJ2_BHJ) qdj := component.BitStateType.Get(elec.TDFJ1_QDJ) drive := component.RelayDriveType.Get(elec.TDFJ2_1DQJ) if drive.Td { // 通电 if !(qdj.Val && bhj.Val) && !(tdfj1_1dqj.Val && ycj.Val && ((tdfj2_2dqj.Val && fcj.Val) || (!tdfj2_2dqj.Val && dcj.Val))) { // 电路断开 drive.Td = false slog.Debug("TDFJ2_1DQJ断电") } } else { // 未通电 if (tdfj1_1dqj.Val && ycj.Val && ((tdfj2_2dqj.Val && fcj.Val) || (!tdfj2_2dqj.Val && dcj.Val))) || (tdfj2_1dqj.Val && qdj.Val && bhj.Val) { // 电路导通 drive.Td = true slog.Debug("TDFJ2_1DQJ通电") } } } // 转辙机一TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路) func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) { _1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF) dcj := component.BitStateType.Get(elec.TDC_DCJ) fcj := component.BitStateType.Get(elec.TDC_FCJ) drive := component.RelayDriveType.Get(elec.TDFJ1_2DQJ) zdj9.excite2DQJ(1, _1dqjf, dcj, fcj, drive) } // 转辙机二TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路) func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) { _1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF) dcj := component.BitStateType.Get(elec.TDC_DCJ) fcj := component.BitStateType.Get(elec.TDC_FCJ) drive := component.RelayDriveType.Get(elec.TDFJ2_2DQJ) zdj9.excite2DQJ(2, _1dqjf, dcj, fcj, drive) } // 2DQJ励磁控制 // i - 几号转辙机(1/2) func (zdj9 *ZDJ9TwoDragSys) excite2DQJ(i int, _1dqjf *component.BitState, dcj *component.BitState, fcj *component.BitState, drive *component.RelayDrive) { if drive.Td { // 通电 if !drive.Xq && _1dqjf.Val && dcj.Val { drive.Xq = true slog.Debug(fmt.Sprintf("TDFJ%v_2DQJ到定位", i)) } else if drive.Xq && _1dqjf.Val && fcj.Val { drive.Xq = false slog.Debug(fmt.Sprintf("TDFJ%v_2DQJ到反位", i)) } else if !(_1dqjf.Val && (dcj.Val || fcj.Val)) { // 断电 drive.Td = false slog.Debug(fmt.Sprintf("TDFJ%v_2DQJ断电", i)) } } else { // 未通电 if _1dqjf.Val { if dcj.Val { // 通电,到吸起位 drive.Td = true drive.Xq = true slog.Debug(fmt.Sprintf("TDFJ%v_2DQJ通电,到吸起位", i)) } else if fcj.Val { // 通电,到落下位 drive.Td = true drive.Xq = false slog.Debug(fmt.Sprintf("TDFJ%v_2DQJ通电,到落下位", i)) } } } }