import org.lsst.ccs.description.groovy.CCSBuilder
import org.lsst.ccs.subsystem.vacuum.VacuumMain
import org.lsst.ccs.subsystem.vacuum.VacSimPlutoDevice
import org.lsst.ccs.subsystem.vacuum.IonPumpDevice
import org.lsst.ccs.subsystem.vacuum.IonPumpControl
import org.lsst.ccs.subsystem.vacuum.Mks9xxDevice
import org.lsst.ccs.subsystem.vacuum.CryoTurboDevice
import org.lsst.ccs.subsystem.vacuum.data.VacSysState
import org.lsst.ccs.monitor.Channel
import org.lsst.ccs.monitor.Alarm

CCSBuilder builder = ["vacuum-sim"]

builder.main (VacuumMain, cryoPressChan:"CryoVac", turboPressChan:"TurboVac",
              turboSpeedChan:"TurboSpeed", forelinePressChan:"ForelineVac",
              switches:[VacSysState.SW_CRYO_TURBO_PUMP, VacSysState.SW_CRYO_ION_PUMP1,
                        VacSysState.SW_CRYO_ION_PUMP2, VacSysState.SW_CRYO_ION_PUMP3,
                        VacSysState.SW_CRYO_ION_PUMP4, VacSysState.SW_CRYO_ION_PUMP5,
                        VacSysState.SW_CRYO_ION_PUMP6, VacSysState.SW_CRYO_GATE_VALVE]) {

    AlarmGeneric (Alarm, description:"Vacuum System Alarm - Generic", eventParm:23)

    VacPluto (VacSimPlutoDevice,
              latchesUsed:[VacSysState.LATCH_CR_GATE_AO, VacSysState.LATCH_CR_GATE_NFC,
                           VacSysState.LATCH_CR_PUMP, VacSysState.LATCH_CR_VACUUM,
			   VacSysState.LATCH_HX_VACUUM],
              condsUsed:[VacSysState.COND_CR_FORELINE_VAC, VacSysState.COND_CR_TRB_PRESS_10,
                         VacSysState.COND_CR_TRB_PUMP_OFF, VacSysState.COND_CR_VACUUM_001,
                         VacSysState.COND_CR_VACUUM_01, VacSysState.COND_HX_VACUUM_001,
			 VacSysState.COND_HX_VACUUM_01, VacSysState.COND_HX_FORELINE_VAC])

    int cip1 = IonPumpDevice.CHAN_CIP1
    int cip2 = IonPumpDevice.CHAN_CIP2
    int cip3 = IonPumpDevice.CHAN_CIP3
    int cip4 = IonPumpDevice.CHAN_CIP4
    int cip5 = IonPumpDevice.CHAN_CIP5
    int cip6 = IonPumpDevice.CHAN_CIP6
    int hip1 = IonPumpDevice.CHAN_HIP1
    int hip2 = IonPumpDevice.CHAN_HIP2
    int oip  = IonPumpDevice.CHAN_OIP

    IonPumps (IonPumpDevice) {

        CIP1C (IonPumpControl, hwChan:cip1)

        CIP2C (IonPumpControl, hwChan:cip2)

        CIP3C (IonPumpControl, hwChan:cip3)

        CIP4C (IonPumpControl, hwChan:cip4)

        CIP5C (IonPumpControl, hwChan:cip5)

        CIP6C (IonPumpControl, hwChan:cip6)

        CIP1_V     (Channel, description:"Cryo ion pump 1 voltage", units:"Volts", format:".1f",
                    hwChan:cip1, type:"VOLTAGE")

        CIP1_I     (Channel, description:"Cryo ion pump 1 current", units:"mA",
                    hwChan:cip1, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP1_Usage (Channel, description:"Cryo ion pump 1 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip1, type:"USAGE")

        CIP1_Life   (Channel, description:"Cryo ion pump 1 lifetime", units:"Hours", format:".0f",
                    hwChan:cip1, type:"LIFETIME")

        CIP2_V     (Channel, description:"Cryo ion pump 2 voltage", units:"Volts", format:".1f",
                    hwChan:cip2, type:"VOLTAGE")

        CIP2_I     (Channel, description:"Cryo ion pump 2 current", units:"mA",
                    hwChan:cip2, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP2_Usage (Channel, description:"Cryo ion pump 2 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip2, type:"USAGE")

        CIP2_Life   (Channel, description:"Cryo ion pump 2 lifetime", units:"Hours", format:".0f",
                    hwChan:cip2, type:"LIFETIME")

        CIP3_V     (Channel, description:"Cryo ion pump 3 voltage", units:"Volts", format:".1f",
                    hwChan:cip3, type:"VOLTAGE")

        CIP3_I     (Channel, description:"Cryo ion pump 3 current", units:"mA",
                    hwChan:cip3, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP3_Usage (Channel, description:"Cryo ion pump 3 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip3, type:"USAGE")

        CIP3_Life   (Channel, description:"Cryo ion pump 3 lifetime", units:"Hours", format:".0f",
                    hwChan:cip3, type:"LIFETIME")

        CIP4_V     (Channel, description:"Cryo ion pump 4 voltage", units:"Volts", format:".1f",
                    hwChan:cip4, type:"VOLTAGE")

        CIP4_I     (Channel, description:"Cryo ion pump 4 current", units:"mA",
                    hwChan:cip4, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP4_Usage (Channel, description:"Cryo ion pump 4 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip4, type:"USAGE")

        CIP4_Life  (Channel, description:"Cryo ion pump 4 lifetime", units:"Hours", format:".0f",
                    hwChan:cip4, type:"LIFETIME")

        CIP5_V     (Channel, description:"Cryo ion pump 5 voltage", units:"Volts", format:".1f",
                    hwChan:cip5, type:"VOLTAGE")

        CIP5_I     (Channel, description:"Cryo ion pump 5 current", units:"mA",
                    hwChan:cip5, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP5_Usage (Channel, description:"Cryo ion pump 5 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip5, type:"USAGE")

        CIP5_Life  (Channel, description:"Cryo ion pump 5 lifetime", units:"Hours", format:".0f",
                    hwChan:cip5, type:"LIFETIME")

        CIP6_V     (Channel, description:"Cryo ion pump 6 voltage", units:"Volts", format:".1f",
                    hwChan:cip6, type:"VOLTAGE")

        CIP6_I     (Channel, description:"Cryo ion pump 6 current", units:"mA",
                    hwChan:cip6, type:"CURRENT", scale:1000.0, limitHi:3.2, dbandHi:1.6)

        CIP6_Usage (Channel, description:"Cryo ion pump 6 usage", units:"Torr-hrs", format:".3g",
                    hwChan:cip6, type:"USAGE")

        CIP6_Life  (Channel, description:"Cryo ion pump 6 lifetime", units:"Hours", format:".0f",
                    hwChan:cip6, type:"LIFETIME")

    }

    TurboPump (CryoTurboDevice) {

        TurboSpeed    (Channel, description:"Turbo pump speed", units:"rpm", format:".0f",
                       type:"Numeric", subtype:"DRIVEFREQ", scale:60, limitHi:100000)

        TurboCurrent  (Channel, description:"TurboPump current", units:"mA dc",
                       type:"Numeric", subtype:"CURRENT",
                       checkLo:"none", checkHi:"none", format:"%.0f")

        TurboVoltage  (Channel, description:"TurboPump voltage", units:"V dc",
                       type:"Numeric", subtype:"VOLTAGE",
                       checkLo:"none", checkHi:"none", format:"%.0f")

        TurboPower    (Channel, description:"TurboPump power", units:"W",
                       type:"Numeric", subtype:"POWER",
                       checkLo:"none", checkHi:"alarm", alarmHi:"AlarmGeneric", format:"%.0f",
                       limitHi:150.0, dbandHi:100.0)

        TurboPumpTemp (Channel, description:"TurboPump pump temperature",
                       units:"deg C",
                       type:"Numeric", subtype:"PUMP_TEMP", format:"%.0f",
                       limitLo:0.0, checkLo:"flag", dbandLo:5.0,
                       limitHi:40.0, checkHi:"alarm", alarmHi:"AlarmGeneric", dbandHi:10.0)
    }

    CryoVacGauge (Mks9xxDevice) {

        CryoVac (Channel, description:"Cryostat vacuum", units:"Torr", format:".3g", limitHi:1000)
    }

    TurboVacGauge (Mks9xxDevice) {

        TurboVac (Channel, description:"Turbo pump vacuum", units:"Torr", format:".3g", limitHi:1000)
    }

    ForelineVacGauge (Mks9xxDevice) {

        ForelineVac (Channel, description:"Foreline pump vacuum", units:"Torr", format:".3g", limitHi:1000)
    }

    Hex1VacGauge (Mks9xxDevice) {

        Hex1Vac (Channel, description:"Heat exchanger 1 vacuum", units:"Torr", format:".3g", limitHi:1000)
    }

    Hex2VacGauge (Mks9xxDevice) {

        Hex2Vac (Channel, description:"Heat exchanger 2 vacuum", units:"Torr", format:".3g", limitHi:1000)
    }

}
