package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) type PsdSys struct { query *ecs.Query } func NewPsdSys() *PsdSys { return &PsdSys{ query: ecs.NewQuery(filter.Contains(component.PsdCircuitType, component.PsdDriveCircuitType)), } } func (p *PsdSys) Update(world ecs.World) { p.query.Each(world, func(entry *ecs.Entry) { psdMotor := component.PsdMotorType.Get(entry) psdMotorState := component.PsdMotorStateType.Get(psdMotor) psd := component.PsdCircuitType.Get(entry) psdDrive := component.PsdDriveCircuitType.Get(entry) p.exciteByDrive(psd, psdDrive) p.exciteGMJ(psdMotorState, psd, psdDrive) p.exciteKMJ4(psdMotorState, psd, psdDrive) p.exciteKMJ8(psdMotorState, psd, psdDrive) p.exciteMGJ(entry, psdMotorState) p.updatePsdState(entry, psdMotorState) }) } func (p *PsdSys) exciteByDrive(psd *component.PsdCircuit, drive *component.PsdDriveCircuit) { if drive.GMJ { component.RelayDriveType.Get(psd.GMJ).Td = true component.BitStateType.Get(psd.GMJ).Val = true } if drive.KMJ4 { component.RelayDriveType.Get(psd.KMJ4).Td = true component.BitStateType.Get(psd.KMJ4).Val = true } if drive.KMJ8 { component.RelayDriveType.Get(psd.KMJ8).Td = true component.BitStateType.Get(psd.KMJ8).Val = true } } func (p *PsdSys) exciteGMJ(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) { gmj := component.BitStateType.Get(psd.GMJ) kmj4 := component.BitStateType.Get(psd.KMJ4) kmj8 := component.BitStateType.Get(psd.KMJ8) if psdDrive.GMJ { //驱动电路接通 component.RelayDriveType.Get(psd.GMJ).Td = true gmj.Val = true } else if gmj.Val { if !kmj4.Val && !kmj8.Val { component.RelayDriveType.Get(psd.GMJ).Td = true } else { component.RelayDriveType.Get(psd.GMJ).Td = false gmj.Val = false } } if gmj.Val && !kmj4.Val && !kmj8.Val { state.Gm_Td = true } } func (p *PsdSys) exciteKMJ4(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) { kmj4 := component.BitStateType.Get(psd.KMJ4) gmj := component.BitStateType.Get(psd.GMJ) kmj8 := component.BitStateType.Get(psd.KMJ8) if psdDrive.KMJ4 { component.RelayDriveType.Get(psd.KMJ4).Td = true kmj4.Val = true } else if kmj4.Val { if !gmj.Val && !kmj8.Val { component.RelayDriveType.Get(psd.KMJ4).Td = true } else { component.RelayDriveType.Get(psd.KMJ4).Td = false kmj4.Val = false } } if kmj4.Val && !gmj.Val && !kmj8.Val { state.Km4_Td = true } } func (p *PsdSys) exciteKMJ8(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) { kmj8 := component.BitStateType.Get(psd.KMJ8) gmj := component.BitStateType.Get(psd.GMJ) kmj4 := component.BitStateType.Get(psd.KMJ4) if psdDrive.KMJ4 { component.RelayDriveType.Get(psd.KMJ8).Td = true kmj8.Val = true } else if kmj8.Val { if !gmj.Val && !kmj4.Val { component.RelayDriveType.Get(psd.KMJ8).Td = true } else { component.RelayDriveType.Get(psd.KMJ8).Td = false kmj8.Val = false } } if kmj8.Val && !gmj.Val && !kmj4.Val { state.Km8_Td = true } } func (p *PsdSys) exciteMGJ(entry *ecs.Entry, state *component.PsdMotorState) { psdCircuit := component.PsdCircuitType.Get(entry) if state.Is4Km() || state.Is8Km() { component.RelayDriveType.Get(psdCircuit.MGJ).Td = false component.BitStateType.Get(psdCircuit.MGJ).Val = false } else { component.RelayDriveType.Get(psdCircuit.MGJ).Td = true component.BitStateType.Get(psdCircuit.MGJ).Val = true } } func (p *PsdSys) updatePsdState(entry *ecs.Entry, psdMotorState *component.PsdMotorState) { psdState := component.PsdStateType.Get(entry) if psdMotorState.Is8Km() { psdState.Km8 = true psdState.Km4 = false } else if psdMotorState.Is4Km() { psdState.Km4 = true psdState.Km8 = false } else { psdState.Km4 = false psdState.Km8 = false } }