import org.lsst.ccs.description.groovy.CCSBuilder;

import org.lsst.ccs.subsystem.common.devices.turbopump.*;
import org.lsst.ccs.subsystem.common.devices.refrigeration.*;
import org.lsst.ccs.subsystem.common.devices.refrigeration.data.RefrigerationConfig
import org.lsst.ccs.subsystem.common.devices.vacuum.*;
import org.lsst.ccs.subsystem.common.devices.power.distribution.*;

import org.lsst.ccs.subsystem.pathfinder.VacPlutoDevice;
import org.lsst.ccs.subsystem.pathfinder.IonPumpDevice;
import org.lsst.ccs.subsystem.pathfinder.IonPumpControl;
import org.lsst.ccs.subsystem.pathfinder.FanPIControl
import org.lsst.ccs.subsystem.pathfinder.Maq20DevicePF;
import org.lsst.ccs.subsystem.pathfinder.Maq20DeviceUT;
import org.lsst.ccs.subsystem.common.devices.dataforth.Maq20PWMControl;
import org.lsst.ccs.subsystem.common.devices.dataforth.Maq20PulseControl;
import org.lsst.ccs.subsystem.pathfinder.SimUTMaq20PWMControl;

import org.lsst.ccs.subsystem.pathfinder.WeightedAverageChannel;
import org.lsst.ccs.subsystem.pathfinder.MaxChannel;

import org.lsst.ccs.subsystem.pathfinder.data.VacSysState;

import org.lsst.ccs.subsystem.pathfinder.Mks9xxDevice;

import org.lsst.ccs.subsystem.common.devices.dataforth.Maq20Device
import org.lsst.ccs.subsystem.common.devices.dataforth.Maq20AnalogControl

import org.lsst.ccs.subsystem.pathfinder.data.*;
import org.lsst.ccs.subsystem.pathfinder.*;
import org.lsst.ccs.subsystem.pathfinder.alerts.PathfinderAlerts;
import org.lsst.ccs.bootstrap.BootstrapResourceUtils;

import org.lsst.ccs.subsystem.pathfinder.SuperHeatChannel



import org.lsst.ccs.monitor.Alarm;
import org.lsst.ccs.monitor.Line;
import org.lsst.ccs.monitor.Channel;

CCSBuilder builder = ["pathfinder"]

Properties props = BootstrapResourceUtils.getBootstrapSystemProperties()

def runMode = props.getProperty("org.lsst.ccs.run.mode","normal");
if (runMode.equals("simulation")) {
    maq20Device = SimMaq20Device
    maq20DevicePF = SimMaq20Device
    maq20DeviceUT = SimMaq20Device
    compMaq20PWMControl = SimUTMaq20PWMControl
    pOffset500 = 0.0
    pScale500 = 1.0
    pOffset750 = 0.0
    pScale750 = 1.0
//    thermalSubsys = "thermal-sim"
}
else {
    maq20Device = Maq20Device
    maq20DevicePF = Maq20DevicePF
    maq20DeviceUT = Maq20DeviceUT
    compMaq20PWMControl = Maq20PWMControl
    maq20AnalogControl = Maq20AnalogControl
    maq20DeviceOth = Maq20Device
    pOffset500 = -125.0;
    pScale500 = 31250.0
    pOffset750 = -187.5
    pScale750 = 46875.0
//    thermalSubsys = "thermal"
}


//Class turboClass = Class.forName("org.lsst.ccs.common.devices.turbopump.TwisTorr84" + "Device");

builder.

    main (PathfinderSubsystem, utFan: ref("UTFan"), utFanSpeed: ref("UT/FanSpeed"), pressChan1:"GaugeGCC00/pfpressure", forelinePressChan:"GaugeGCC02/forelinepressure", turboPressChan:"GaugeGCC01/turbopressure", turboSpeedChan:"turbo/rpm",

        switches:[
        VacSysState.SW_HX_VALVE,
        VacSysState.SW_HX_TURBO,
	VacSysState.SW_HX_ION_PUMP1
/*
        VacSysState.SW_BLOCK_HVSTAT,
        VacSysState.SW_BLOCK_CVSTAT,
        VacSysState.SW_OPEN_VHX00,
        VacSysState.SW_OPEN_VCR00,
        VacSysState.SW_OPEN_VCR01,
        VacSysState.SW_OPEN_VCR02,
        VacSysState.SW_OPEN_VCR03,
        VacSysState.SW_OPEN_VCR04,
        VacSysState.SW_BLOCK_HVPUMP,
        VacSysState.SW_BLOCK_CVPUMP
*/
                    ]) {


    VacuumPLCNotAlive (Alarm, alertToBeRaised:PathfinderAlerts.VACUUM_PLC_NOT_ALIVE.getAlert())
    AlarmHxVacuumBad (Alarm, alertToBeRaised:PathfinderAlerts.HX_VACUUM_BAD.getAlert())
    AlarmHxGateForcedShut (Alarm, alertToBeRaised:PathfinderAlerts.HX_GATE_FORCED_SHUT.getAlert())
    AlarmHxGateCannotOpen (Alarm, alertToBeRaised:PathfinderAlerts.HX_GATE_CANNOT_OPEN.getAlert())
    AlarmHxTurboPumpBad (Alarm, alertToBeRaised:PathfinderAlerts.HX_TURBO_PUMP_BAD.getAlert())
    AlarmPressureLow (Alarm, alertToBeRaised:PathfinderAlerts.HX_TURBO_PUMP_BAD.getAlert())
    AlarmPressureHigh (Alarm, alertToBeRaised:PathfinderAlerts.PRESSURE_TOO_LOW.getAlert())
    AlarmVacuumValveShutOff (Alarm, alertToBeRaised:PathfinderAlerts.PRESSURE_TOO_HIGH.getAlert())
    AlarmUPSOnBattery (Alarm, alertToBeRaised:PathfinderAlerts.UPS_ON_BATTERY.getAlert())
    AlarmUPSDisconnected (Alarm, alertToBeRaised:PathfinderAlerts.UPS_DISCONNECTED.getAlert())
    AlarmTurboPumpFailure (Alarm, alertToBeRaised:PathfinderAlerts.TURBO_PUMP_FAIL.getAlert())
    AlarmTurboPumpOverTemp (Alarm, alertToBeRaised:PathfinderAlerts.TURBO_PUMP_OVERTEMP.getAlert()) 
    AlarmLoadRTDOverTemp (Alarm, alertToBeRaised:PathfinderAlerts.LOAD_RTD_OVERTEMP.getAlert()) 
    AlarmGeneric (Alarm, alertToBeRaised:PathfinderAlerts.GENERIC.getAlert())


    UTFlowAlarm (Alarm, description: "UT Coolant flow alarm")

    UTTempLoAlarm (Alarm, description: "UT Low temperature alarm")

    UTTempHiAlarm (Alarm, description: "UT High temperature alarm")

    UTSpeedHiAlarm (Alarm, description: "UT High fan speed alarm")

    PFTempHiMaxAlarm (Alarm, alertToBeRaised:PathfinderAlerts.TEMP_MAX_TOO_HIGH.getAlert())

    maq20_pth (maq20DeviceUT, modules: ["DOUT", "DINP", "DINP", "DIOL:pwm:pulse"]) {
       UTPwm (compMaq20PWMControl, modIndex: 3, funcIndex: 0, frequency: 200.0)
       UTPulse (Maq20PulseControl, modIndex: 3, funcIndex: 1, pulsesPerRevn: 6)

    }

    "UT/FanSpeed" (Channel, description: "UT fan speed", units: "rpm", format: ".0f",
        devcName: "maq20_pth", hwChan: Maq20DeviceUT.CHAN_PULSE_RPM, type: "3", subtype: "1",
        checkHi: "alarm", alarmHi: "UTSpeedHiAlarm")




//    TrimPower  (HeaterPsDevice, softMaxCurrent: 1.95)


// 1
     GaugeGCC01 (Mks9xxDevice) {
        turbopressure  (Channel, description:"Pressure Reading", units:"Torr", format:".3G",
                      hwChan:0,
                    checkLo:"alarm", alarmLo:"AlarmPressureLow",
                    checkHi:"alarm", alarmHi:"AlarmPressureHigh")
    }

// 2
     GaugeGCC00 (Mks9xxDevice) {
        pfpressure  (Channel, description:"Pressure Reading", units:"Torr", format:".3G",
                      hwChan:0,
                    checkLo:"alarm", alarmLo:"AlarmPressureLow",
                    checkHi:"alarm", alarmHi:"AlarmPressureHigh")
    }
// 3
     GaugeGCC02 (Mks9xxDevice) {
        forelinepressure  (Channel, description:"Pressure Reading", units:"Torr", format:".3G",
                      hwChan:0,
                    checkLo:"alarm", alarmLo:"AlarmPressureLow",
                    checkHi:"alarm", alarmHi:"AlarmPressureHigh")
    }

/*
>> showmodules                                                                                                        
ID  Type  Serial No.
 1  RTD   0124186-09
 2  RTD   0126432-12
 3  RTD   0121348-05
 4  IS    0123738-05
 5  IS    0120610-03
 6  RTD   0124186-05
 */

    
    turbo  (CryoTurboDevice) {




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

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

    "power"        (Channel, description:"TurboPump power", units:"Watt",
                       type:"Numeric", subtype:"POWER",
                       checkLo:"none", checkHi:"alarm", format:"%.0f",
                       alarmHi:"AlarmGeneric")

    "driveFrequency"    (Channel, description:"TurboPump drive frequency", units:"Hz",
                       type:"Numeric", subtype:"DRIVEFREQ",
                       checkLo:"none", checkHi:"none", format:"%.0f")

    "pumpTemperature"     (Channel, description:"TurboPump pump temperature", 
                       units:"\u00b0C", 
                       type:"Numeric", subtype:"PUMP_TEMP", format:"%.0f",
                       checkLo:"flag", 
                       checkHi:"alarm", 
                       alarmHi:"AlarmTurboPumpOverTemp")

    "cntrlrSinkTemperature" (Channel, description:"TurboPump controller sink temp.", 
                       units:"\u00b0C", 
                       type:"Numeric", subtype:"CONT_TEMP_SINK", format:"%.0f",
                       checkLo:"flag", 
                       checkHi:"alarm", 
                       alarmHi:"AlarmTurboPumpOverTemp")

    "cntrlrAirTemperature"  (Channel, description:"TurboPump controller air temp.", 
                       units:"\u00b0C", 
                       type:"Numeric", subtype:"CONT_TEMP_AIR", format:"%.0f",
                       checkLo:"flag", 
                       checkHi:"alarm", 
                       alarmHi:"AlarmTurboPumpOverTemp")

    "rpm"          (Channel, description:"TurboPump speed in RPM", units:"unitless",
                       type:"Numeric", subtype:"RPM",
                       checkLo:"none", checkHi:"none", format:"%.0f")

    "status"       (Channel, description:"TurboPump status: 5=normal, 6=fail", units:"unitless", 
                       type:"Numeric", subtype:"STATUS", 
                       format:"%.0f",
                       checkLo:"flag",
                       checkHi:"alarm", alarmHi:"AlarmTurboPumpFailure")




    }





     /*
         Its name, used to identify it in databases, plots, etc.
    Its longer, more descriptive, name.
    The units the value is expressed in, e.g. "Volt".
    The device used for obtaining its value.
    The hardware channel number on the device.
    The channel type, e.g. temperature, pressure, etc, which is needed by some devices.
    The subtype, which supplies hardware configuration information.
    The offset and scale values needed for converting a raw hardware value to a physical one.
    Parameters used for checking the value against a limit.  There is one set for the low limit and one for the high one:
        The checking option: NONE, FLAG or ALARM
        The limit value.
        The alarm to be activated upon status transitions when ALARM is specified.
        The deadband value which delays a potential alarm action during a transition back to good status.
    Its id, which is its index in the list of all channels.

The limit values are maintained by the configuration system and can be changed while running.  Any such change causes a status message to be broadcast, which can be used to update the trending database or to update any console displays.
*/



/* ===
        latchNames[VacSysState.LATCH_CR_GATE_AO]  = "Cryo Gate Can't Open";
        latchNames[VacSysState.LATCH_CR_GATE_NFC] = "Cryo Gate Forced Shut";
        latchNames[VacSysState.LATCH_CR_VACUUM]   = "Cryo Vacuum Bad";
        latchNames[VacSysState.LATCH_CR_PUMP]     = "Cryo Turbo Pump Bad";
        latchNames[VacSysState.LATCH_HX_GATE_AO]  = "Hx Gate Can't Open";
        latchNames[VacSysState.LATCH_HX_GATE_NFC] = "Hx Gate Forced Shut";
        latchNames[VacSysState.LATCH_HX_VACUUM]   = "Hx Vacuum Bad";
        latchNames[VacSysState.LATCH_HX_PUMP]     = "Hx Turbo Pump Bad";
== */





    VacPluto (VacPlutoDevice,
/*
              latchesUsed:[VacSysState.LATCH_CR_GATE_AO, VacSysState.LATCH_CR_GATE_NFC,
                           VacSysState.LATCH_CR_PUMP, VacSysState.LATCH_CR_VACUUM,
							   VacSysState.LATCH_HX_VACUUM],
*/
              latchesUsed:[VacSysState.LATCH_HX_VACUUM, VacSysState.LATCH_HX_PUMP, VacSysState.LATCH_HX_GATE_AO, VacSysState.LATCH_HX_GATE_NFC],
              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_TURBO_OFF, VacSysState.COND_HX_VACUUM_001,
								 VacSysState.COND_HX_VACUUM_01, VacSysState.COND_HX_FORELINE_VAC])
/*
              latchesUsed:[VacSysState.LATCH_HX_VACUUM],
              condsUsed:[VacSysState.COND_HX_VACUUM_001,
                         VacSysState.COND_HX_VACUUM_01,
                         VacSysState.COND_HX_FORELINE_VAC])
*/

    int cip2 = IonPumpDevice.CHAN_CIP2
    int hip1 = IonPumpDevice.CHAN_HIP1
    int hip2 = IonPumpDevice.CHAN_HIP2
    int oip  = IonPumpDevice.CHAN_OIP

    IonPumps (IonPumpDevice) {

        CIP1C (IonPumpControl, hwChan:cip2)

        "current" (Channel, description:"Cryo ion pump current", units:"mA",
                hwChan:cip2, type:"CURRENT", scale:1000.0)

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

    }




// 1 TTC  0131744-05
// 2 IS  0130197-04
// 3 IO  0136788-02

   maq20_bpu (maq20DevicePF, modules: ["TTC", "IS", "IO", "RTD"]) {

       AnalogOut (maq20AnalogControl, modIndex: 2, ranges: ["MA4_20", "MA4_20", "MA4_20"])
       "Heater1_Ctrl_I" (Channel, description: "COLD Heater Control Current", units: "mA", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 0, type: "2", subtype: "MA4_20")
       "Heater2_Ctrl_I" (Channel, description: "CRYO Heater Control Current", units: "mA", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 2, type: "2", subtype: "MA4_20")
       "Water_Valve_I" (Channel, description: "Water Valve Control Current", units: "mA", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 1, type: "2", subtype: "MA4_20")

       FlowMeter (Channel, description: "flow meter", units: "g/min", format: ".1f",
                         devcName: "maq20_bpu", hwChan: 10, type: "1", subtype: "MA4_20", offset: pOffset500, scale: pScale500)
       "UTC-CMC-THC-00" (Channel, description: "UTC-CMC-THC-00 Temp", units: "\u00b0C", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 0, type: "0", subtype: "T220")
       "UTC-CMC-THC-01" (Channel, description: "UTC-CMC-THC-01 Temp", units: "\u00b0C", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 1, type: "0", subtype: "T220")
       "UTC-CMC-THC-02" (Channel, description: "UTC-CMC-THC-02 Temp", units: "\u00b0C", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 2, type: "0", subtype: "T220")
       "UTC-CMC-THC-03" (Channel, description: "UTC-CMC-THC-03 Temp", units: "\u00b0C", format: ".1f",
                          devcName: "maq20_bpu", hwChan: 3, type: "0", subtype: "T220")
    }

//ID  Type  Serial No.
// 1  IO    0136788-02
// 2  RTD   0143400-15
// 3  IS    0130197-04
// 4  TTC   0131744-05
/*
   maq20_oth (maq20DeviceOth, modules: ["IO"."RTD", "IS", "TTC"]) {

            T1 (Channel, description: "Primary Oil Separator Temp", units: "\u00b0C", format: ".1f",
                          devcName: maq20_oth, hwChan: 2, type: "3", subtype: "T220")

            T2  (Channel, description: "Phase Separator Temperature", units: "\u00b0C", format: ".1f",
                          devcName: maq20_oth, hwChan: 5, type: "3", subtype: "T220")

            T3    (Channel, description: "Oil Separator Temperature", units: "\u00b0C", format: ".1f",
                          devcName: maq20_oth, hwChan: 6, type: "3", subtype: "T220")


            T4 (Channel, description: "Secondary Oil Separator Temp", units: "\u00b0C", format: ".1f",
                          devcName: maq20_oth, hwChan: 7, type: "3", subtype: "T220")

    }
*/


    maq20       (Maq20Device, modules: ["RTD", "RTD", "RTD", "IS", "IS", "RTD", "RTD"]) { // first 3 RTD modules are for HEX
/*
      		"HEXRTDS" (Channel, description: "HEXRTDs", units: "\u00b0C", format: ".1f",
                                devcName: "HexRTDs", hwChan: 0, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
			        checkHi:"alarm", alarmHi:"AlarmGeneric")
*/
      "Cryo1/C3ExitTmp" (Channel, description: "C3 EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 0, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo1/PreC3Tmp" (Channel, description: "PRE C3", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 1, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo1/PreC4Tmp" (Channel, description: "PRE C4", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 2, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo1/C4ExitTmp" (Channel, description: "C4 EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 3, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo1/EvapExitTmp" (Channel, description: "EVAP EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 4, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo1/HexRtrnTmp" (Channel, description: "HEX RTRN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 5, type: "0", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

// -------------------------------------------------------------------------------------



      "Cryo2/C3ExitTmp" (Channel, description: "C3 EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 0, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo2/PreC3Tmp" (Channel, description: "PRE C3", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 1, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo2/PreC4Tmp" (Channel, description: "PRE C4", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 2, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo2/C4ExitTmp" (Channel, description: "C4 EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 3, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo2/EvapExitTmp" (Channel, description: "EVAP EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 4, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cryo2/HexRtrnTmp" (Channel, description: "HEX RTRN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 5, type: "5", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

// -------------------------------------------------------------------------------------


      "REF-LOAD-RTD-06" (Channel, description: "CRYO TOP", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 3, type: "6", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-07" (Channel, description: "CRYO BOTT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 4, type: "6", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-08" (Channel, description: "CRYO -XSIDE", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 5, type: "6", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")


//-- -- -- -- -- -- 

      "Cold1/PreExpnTmp" (Channel, description: "PRE-EXPN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 0, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cold1/EvapExitTmp" (Channel, description: "EVAP EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 1, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cold1/HexRtrnTmp" (Channel, description: "HEX RTRN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 2, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")
//--
      "Cold2/PreExpnTmp" (Channel, description: "PRE-EXPN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 3, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cold2/EvapExitTmp" (Channel, description: "EVAP EXIT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 4, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

      "Cold2/HexRtrnTmp" (Channel, description: "HEX RTRN", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 5, type: "2", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmGeneric")

// -------------------------------------------------------------------------------------



      "REF-LOAD-RTD-00" (Channel, description: "EVAP ENTR UPR", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 0, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-01" (Channel, description: "EVAP ENTR LWR", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 1, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-02" (Channel, description: "COLD TOP", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 2, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-03" (Channel, description: "COLD BOTT", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 3, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-04" (Channel, description: "COLD +XSIDE", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 4, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")

      "REF-LOAD-RTD-05" (Channel, description: "COLD -XSIDE", units: "u00b0C", format: ".1f",
                                devcName: "maq20", hwChan: 5, type: "1", subtype: "R200",
                                checkLo:"alarm", alarmLo:"AlarmGeneric",
                                checkHi:"alarm", alarmHi:"AlarmLoadRTDOverTemp")


//    EvapPress (EvaporatorPressDevice, returnPressChans: ["Cold1/ReturnPrs", "Cold2/ReturnPrs"],
//               thermalSubsysName: thermalSubsys, coldRtdChans: ["Cold_Temp/CLP-RTD-50", "Cold_Temp/CLP-RTD-55"])

/*   -- old ----
    "Cold1/PreExpnTmp"  (Channel, description: "Pre Expn Temperature", units: "\u00b0C", format: ".1f",
                         devcName: "maq20", hwChan: 0, type: "6", subtype: "R200")

    "Cold1/EvapExitTmp" (Channel, description: "Evap Exit Temperature", units: "\u00b0C", format: ".1f",
                         devcName: "maq20", hwChan: 1, type: "6", subtype: "R200")

    "Cold1/HexRtrnTmp"  (Channel, description: "HX Return Temperature", units: "\u00b0C", format: ".1f",
                         devcName: "maq20", hwChan: 2, type: "6", subtype: "R200")
*/

 
// -------------------------- Cold1 -------------------
//moved   "Cold1/SupplyPrs"   (Channel, description: "Supply Pressure", units: "psia", format: ".1f",
//moved                         devcName: "maq20", hwChan: 2, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)
//moved
//moved    "Cold1/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
//moved                         devcName: "maq20", hwChan: 3, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

//    "Cold1/EvapDeltaPrs" (Channel, description: "Evap Delta Pressure", units: "psia", format: ".1f",
//                          devcName: "EvapPress", hwChan: EvaporatorPressDevice.CHAN_COLD1)

// -------------------------- Cold2 -------------------
//moved   "Cold2/SupplyPrs"   (Channel, description: "Supply Pressure", units: "psia", format: ".1f",
//moved                         devcName: "maq20", hwChan: 4, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)
//moved
//moved    "Cold2/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
//moved                         devcName: "maq20", hwChan: 5, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

//    "Cold2/EvapDeltaPrs" (Channel, description: "Evap Delta Pressure", units: "psia", format: ".1f",
//                          devcName: "EvapPress", hwChan: EvaporatorPressDevice.CHAN_COLD1)




/*
    "Cold1/SupplyTmp"   (Channel, description: "Supply Temperature", units: "\u00b0C", format: ".1f",
                         devcName: maq20x, hwChan: 4, type: "0", subtype: "T220")

    "Cold1/SupplySubCooling" (SubCoolingChannel, description: "Cold1 Supply SubCooling", units: "\u00b0C", format: ".2f",
                              dischargePressureChannel: ref("Cold1/SupplyPrs"), liquidTempChannel:ref("Cold1/SupplyTmp"))

    "Cold1/EnthalpyExch" (EnthalpyExchangeChannel, description: "Enthalpy Exchange", units: "kJ/kG", format: ".2f",
                          supplyTempChannel: ref("Cold1/SupplyTmp"), preExpnTempChannel: ref("Cold1/PreExpnTmp"),
                          r507aSpecHeat: 1.43)
*/


    "Cryo1/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 0, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo1/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 1, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo1/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 2, type: "4", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cryo2/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 3, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo2/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 4, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo2/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 5, type: "4", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cryo3/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 6, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo3/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 7, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo3/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 8, type: "4", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cryo4/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 9, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo4/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 10, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo4/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 11, type: "4", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cryo5/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 12, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo5/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 13, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo5/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 14, type: "4", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cryo6/VaporPrs"    (Channel, description: "Vapor Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 15, type: "4", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo6/LiquidPrs"   (Channel, description: "Liquid Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 0, type: "3", subtype: "MA4_20", offset: pOffset750, scale: pScale750)
    "Cryo6/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 1, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cold1/SupplyPrs"   (Channel, description: "Supply Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 2, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)
    "Cold1/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 3, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cold2/SupplyPrs"   (Channel, description: "Supply Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 4, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)
    "Cold2/ReturnPrs"   (Channel, description: "Return Pressure", units: "psia", format: ".1f",
                         devcName: "maq20", hwChan: 5, type: "3", subtype: "MA4_20", offset: pOffset500, scale: pScale500)

    "Cold1/SuperHeat"   (SuperHeatChannel, description: "Cold1 SuperHeat", units: "\u00b0C", format: ".2f",
                        devcName: "maq20", evapExitTempChannel: ref("Cold1/EvapExitTmp"), returnPressureChannel:ref("Cold1/ReturnPrs"))
    "Cold2/SuperHeat"   (SuperHeatChannel, description: "Cold2 SuperHeat", units: "\u00b0C", format: ".2f",
                        devcName: "maq20", evapExitTempChannel: ref("Cold2/EvapExitTmp"), returnPressureChannel:ref("Cold2/ReturnPrs"))


    }


    "PFMaxTemp" (MaxChannel, description: "Max PF temperature", units: "\u00b0C",
                      channels: [
ref("Cold1/PreExpnTmp"),
ref("Cold1/EvapExitTmp"),
ref("Cold1/HexRtrnTmp"),
ref("Cold2/PreExpnTmp"),
ref("Cold2/EvapExitTmp"),
ref("Cold2/HexRtrnTmp"),
ref("Cryo1/C3ExitTmp"),
ref("Cryo1/PreC3Tmp"),
ref("Cryo1/PreC4Tmp"),
ref("Cryo1/C4ExitTmp"),
ref("Cryo1/EvapExitTmp"),
ref("Cryo1/HexRtrnTmp"),
ref("Cryo2/C3ExitTmp"),
ref("Cryo2/PreC3Tmp"),
ref("Cryo2/PreC4Tmp"),
ref("Cryo2/C4ExitTmp"),
ref("Cryo2/EvapExitTmp"),
ref("Cryo2/HexRtrnTmp"),
ref("REF-LOAD-RTD-00"),
ref("REF-LOAD-RTD-01"),
ref("REF-LOAD-RTD-02"),
ref("REF-LOAD-RTD-03"),
ref("REF-LOAD-RTD-04"),
ref("REF-LOAD-RTD-05"),
ref("REF-LOAD-RTD-06"),
ref("REF-LOAD-RTD-07"),
ref("REF-LOAD-RTD-08")
], checkHi:"alarm", alarmHi:"PFTempHiMaxAlarm")


    "UT/AverageTemp" (WeightedAverageChannel, description: "UT weighted average temperature", units: "\u00b0C",
                      channels: [ref("maq20_bpu/UTC-CMC-THC-00"), ref("maq20_bpu/UTC-CMC-THC-01"),
                                 ref("maq20_bpu/UTC-CMC-THC-02"), ref("maq20_bpu/UTC-CMC-THC-03")],
                      weights: [2.0, 2.0, 2.0, 2.0])
     UTFan   (FanPIControl, fan: ref("maq20_pth/UTPwm"), refTempChans: ["turbo/cntrlrAirTemperature"],
             ctrlTempChans: [ref("UT/AverageTemp")], ctrlTempWeights: [1.0])



}