import org.lsst.ccs.description.groovy.CCSBuilder
import org.lsst.ccs.drivers.auxelex.Bfr
import org.lsst.ccs.drivers.auxelex.Pdu24VC
import org.lsst.ccs.drivers.auxelex.Pdu24VD
import org.lsst.ccs.drivers.auxelex.Pdu5V
import org.lsst.ccs.drivers.auxelex.Pdu48V
import org.lsst.ccs.subsystem.common.devices.dataforth.Maq20DiscControl
import org.lsst.ccs.subsystem.power.QuadBox
import org.lsst.ccs.subsystem.power.BfrDevice
import org.lsst.ccs.subsystem.power.Pdu5vDevice
import org.lsst.ccs.subsystem.power.Pdu24vcDevice
import org.lsst.ccs.subsystem.power.Pdu24vdDevice
import org.lsst.ccs.subsystem.power.Pdu48vDevice
import org.lsst.ccs.subsystem.power.RebBulkPsDevice
import org.lsst.ccs.subsystem.power.QbMaq20Device
import org.lsst.ccs.monitor.Channel
import org.lsst.ccs.subsystem.power.BulkPSEmergencyResponseManager;

CCSBuilder builder = ["quadbox"]

builder.main (QuadBox) {

    emergencyResponseManager (BulkPSEmergencyResponseManager)    
    
    BFR (BfrDevice) {

        Protection_I (Channel, description: "Protection system current", units: "mA", format: ".1f",
                      hwChan:Bfr.SENSOR_PROT, scale: 1000.0)

        Clean_5_24V_I (Channel, description: "Clean 5 and 24V current", units: "mA", format: ".1f",
                       hwChan:Bfr.SENSOR_PWS_20_21, scale: 1000.0)

        Dirty_24V_I (Channel, description: "Dirty 24V current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_3, scale: 1000.0)

        Dirty_48V_I (Channel, description: "Dirty 48V current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_1, scale: 1000.0)

        RebPs_0_2_I (Channel, description: "REB PS 0-2 current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_16, scale: 1000.0)

        RebPs_3_5_I (Channel, description: "REB PS 3-5 current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_17, scale: 1000.0)

        RebPs_6_8_I (Channel, description: "REB PS 6-8 current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_18, scale: 1000.0)

        RebPs_9_12_I (Channel, description: "REB PS 9-12 current", units: "mA", format: ".1f",
                      hwChan:Bfr.SENSOR_PWS_19, scale: 1000.0)

        Dirty_28V_I (Channel, description: "Dirty 28V current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_4, scale: 1000.0)

        //Heater_I (Channel, description: "Heater current", units: "mA", format: ".1f",
        //          hwChan:Bfr.SENSOR_HTRS, scale: 1000.0)

        RebPs_Spr_I (Channel, description: "REB PS spare current", units: "mA", format: ".1f",
                     hwChan:Bfr.SENSOR_PWS_25, scale: 1000.0)

    }

    PDU_5V (Pdu5vDevice) {

        OTM_0_A_V (Channel, description: "OTM 0-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_0_A, type:"VOLTAGE")

        OTM_0_A_I (Channel, description: "OTM 0-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_0_A, type:"CURRENT", scale: 1000.0)

        OTM_0_B_V (Channel, description: "OTM 0-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_0_B, type:"VOLTAGE")

        OTM_0_B_I (Channel, description: "OTM 0-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_0_B, type:"CURRENT", scale: 1000.0)

        OTM_1_A_V (Channel, description: "OTM 1-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_1_A, type:"VOLTAGE")

        OTM_1_A_I (Channel, description: "OTM 1-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_1_A, type:"CURRENT", scale: 1000.0)

        OTM_1_B_V (Channel, description: "OTM 1-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_1_B, type:"VOLTAGE")

        OTM_1_B_I (Channel, description: "OTM 1-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_1_B, type:"CURRENT", scale: 1000.0)

        OTM_2_A_V (Channel, description: "OTM 2-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_2_A, type:"VOLTAGE")

        OTM_2_A_I (Channel, description: "OTM 2-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_2_A, type:"CURRENT", scale: 1000.0)

        OTM_2_B_V (Channel, description: "OTM 2-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_2_B, type:"VOLTAGE")

        OTM_2_B_I (Channel, description: "OTM 2-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_2_B, type:"CURRENT", scale: 1000.0)

        OTM_3_A_V (Channel, description: "OTM 3-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_3_A, type:"VOLTAGE")

        OTM_3_A_I (Channel, description: "OTM 3-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_3_A, type:"CURRENT", scale: 1000.0)

        OTM_3_B_V (Channel, description: "OTM 3-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_3_B, type:"VOLTAGE")

        OTM_3_B_I (Channel, description: "OTM 3-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_3_B, type:"CURRENT", scale: 1000.0)

        OTM_4_A_V (Channel, description: "OTM 4-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_4_A, type:"VOLTAGE")

        OTM_4_A_I (Channel, description: "OTM 4-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_4_A, type:"CURRENT", scale: 1000.0)

        OTM_4_B_V (Channel, description: "OTM 4-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_4_B, type:"VOLTAGE")

        OTM_4_B_I (Channel, description: "OTM 4-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_4_B, type:"CURRENT", scale: 1000.0)

        OTM_5_A_V (Channel, description: "OTM 5-A voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_5_A, type:"VOLTAGE")

        OTM_5_A_I (Channel, description: "OTM 5-A current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_5_A, type:"CURRENT", scale: 1000.0)

        OTM_5_B_V (Channel, description: "OTM 5-B voltage", units: "Volts", format: ".2f",
                   hwChan:Pdu5V.CHAN_OTM_5_B, type:"VOLTAGE")

        OTM_5_B_I (Channel, description: "OTM 5-B current", units: "mA", format: ".1f",
                   hwChan:Pdu5V.CHAN_OTM_5_B, type:"CURRENT", scale: 1000.0)

    }

    PDU_24VC (Pdu24vcDevice) {
        
        Main_V (Channel, description: "24V Clean PDU main voltage", units: "Volts", format: ".2f",
                type:"MAINVOLT")

        Main_I (Channel, description: "24V Clean PDU main current", units: "mA", format: ".1f",
                type:"MAINCURR", scale: 1000.0)

        Main_T (Channel, description: "24V Clean PDU main temperature", units: "\u00b0C", format: ".1f",
                type:"MAINTEMP")

        Board_T (Channel, description: "24V Clean PDU board temperature", units: "\u00b0C", format: ".1f",
                 type:"BOARDTEMP")

        FPGA_T (Channel, description: "24V Clean PDU FPGA temperature", units: "\u00b0C", format: ".1f",
                type:"FPGATEMP")

        Cryo_Maq20_V (Channel, description: "Cryostat MAQ20 voltage", units: "Volts", format: ".2f",
                      hwChan:Pdu24VC.CHAN_CRYO_MAQ20, type:"VOLTAGE")

        Cryo_Maq20_I (Channel, description: "Cryostat MAQ20 current", units: "mA", format: ".1f",
                      hwChan:Pdu24VC.CHAN_CRYO_MAQ20, type:"CURRENT", scale: 1000.0)

        Body_Maq20_V (Channel, description: "Body MAQ20 voltage", units: "Volts", format: ".2f",
                      hwChan:Pdu24VC.CHAN_BODY_MAQ20, type:"VOLTAGE")

        Body_Maq20_I (Channel, description: "Body MAQ20 current", units: "mA", format: ".1f",
                      hwChan:Pdu24VC.CHAN_BODY_MAQ20, type:"CURRENT", scale: 1000.0)

        Gauges_V (Channel, description: "Gauges voltage", units: "Volts", format: ".2f",
                  hwChan:Pdu24VC.CHAN_GAUGES, type:"VOLTAGE")

        Gauges_I (Channel, description: "Gauges current", units: "mA", format: ".1f",
                  hwChan:Pdu24VC.CHAN_GAUGES, type:"CURRENT", scale: 1000.0)

        Ion_Pumps_V (Channel, description: "Ion pumps voltage", units: "Volts", format: ".2f",
                     hwChan:Pdu24VC.CHAN_ION_PUMPS, type:"VOLTAGE")

        Ion_Pumps_I (Channel, description: "Ion pumps current", units: "mA", format: ".1f",
                     hwChan:Pdu24VC.CHAN_ION_PUMPS, type:"CURRENT", scale: 1000.0)

        FES_CarouselC_V (Channel, description: "FES carouselC voltage", units: "Volts", format: ".2f",
                         hwChan:Pdu24VC.CHAN_FES_CAROUSEL, type:"VOLTAGE")

        FES_CarouselC_I (Channel, description: "FES carouselC current", units: "mA", format: ".1f",
                         hwChan:Pdu24VC.CHAN_FES_CAROUSEL, type:"CURRENT", scale: 1000.0)

        FES_ChangerC_V (Channel, description: "FES changerC voltage", units: "Volts", format: ".2f",
                        hwChan:Pdu24VC.CHAN_FES_CHANGER, type:"VOLTAGE")

        FES_ChangerC_I (Channel, description: "FES changerC current", units: "mA", format: ".1f",
                        hwChan:Pdu24VC.CHAN_FES_CHANGER, type:"CURRENT", scale: 1000.0)

        FES_LoaderC_V (Channel, description: "FES loaderC voltage", units: "Volts", format: ".2f",
                       hwChan:Pdu24VC.CHAN_FES_LOADER, type:"VOLTAGE")

        FES_LoaderC_I (Channel, description: "FES loaderC current", units: "mA", format: ".1f",
                       hwChan:Pdu24VC.CHAN_FES_LOADER, type:"CURRENT", scale: 1000.0)

        Shtr_PLC1_V (Channel, description: "Shutter PLC 1 voltage", units: "Volts", format: ".2f",
                     hwChan:Pdu24VC.CHAN_SHTR_PLC_1, type:"VOLTAGE")

        Shtr_PLC1_I (Channel, description: "Shutter PLC 1 current", units: "mA", format: ".1f",
                     hwChan:Pdu24VC.CHAN_SHTR_PLC_1, type:"CURRENT", scale: 1000.0)

        Shtr_PLC2_V (Channel, description: "Shutter PLC 2 voltage", units: "Volts", format: ".2f",
                     hwChan:Pdu24VC.CHAN_SHTR_PLC_2, type:"VOLTAGE")

        Shtr_PLC2_I (Channel, description: "Shutter PLC 2 current", units: "mA", format: ".1f",
                     hwChan:Pdu24VC.CHAN_SHTR_PLC_2, type:"CURRENT", scale: 1000.0)

    }

    PDU_24VD (Pdu24vdDevice) {
        
        Main_V (Channel, description: "24V Dirty PDU main voltage", units: "Volts", format: ".2f",
                type:"MAINVOLT")

        Main_I (Channel, description: "24V Dirty PDU main current", units: "mA", format: ".1f",
                type:"MAINCURR", scale: 1000.0)

        Main_T (Channel, description: "24V Dirty PDU main temperature", units: "\u00b0C", format: ".1f",
                type:"MAINTEMP")

        Board_T (Channel, description: "24V Dirty PDU board temperature", units: "\u00b0C", format: ".1f",
                 type:"BOARDTEMP")

        FPGA_T (Channel, description: "24V Dirty PDU FPGA temperature", units: "\u00b0C", format: ".1f",
                type:"FPGATEMP")

        Cryo_Turbo_V (Channel, description: "Cryo turbo pump voltage", units: "Volts", format: ".2f",
                      hwChan:Pdu24VD.CHAN_CRYO_TURBO, type:"VOLTAGE")

        Cryo_Turbo_I (Channel, description: "Cryo turbo pump current", units: "mA", format: ".1f",
                      hwChan:Pdu24VD.CHAN_CRYO_TURBO, type:"CURRENT", scale: 1000.0)

        Hex_Turbo_V (Channel, description: "Hex turbo pump voltage", units: "Volts", format: ".2f",
                    hwChan:Pdu24VD.CHAN_HEX_TURBO, type:"VOLTAGE")

        Hex_Turbo_I (Channel, description: "Hex turbo pump current", units: "mA", format: ".1f",
                    hwChan:Pdu24VD.CHAN_HEX_TURBO, type:"CURRENT", scale: 1000.0)

        FES_Clamps_V (Channel, description: "FES clamps voltage", units: "Volts", format: ".2f",
                      hwChan:Pdu24VD.CHAN_FES_CLAMPS, type:"VOLTAGE")

        FES_Clamps_I (Channel, description: "FES clamps current", units: "mA", format: ".1f",
                      hwChan:Pdu24VD.CHAN_FES_CLAMPS, type:"CURRENT", scale: 1000.0)

        FES_Brakes_V (Channel, description: "FES brakes voltage", units: "Volts", format: ".2f",
                      hwChan:Pdu24VD.CHAN_FES_BRAKES, type:"VOLTAGE")

        FES_Brakes_I (Channel, description: "FES brakes current", units: "mA", format: ".1f",
                      hwChan:Pdu24VD.CHAN_FES_BRAKES, type:"CURRENT", scale: 1000.0)

        FES_ChangerD_V (Channel, description: "FES changerD voltage", units: "Volts", format: ".2f",
                        hwChan:Pdu24VD.CHAN_FES_CHANGER, type:"VOLTAGE")

        FES_ChangerD_I (Channel, description: "FES changerD current", units: "mA", format: ".1f",
                        hwChan:Pdu24VD.CHAN_FES_CHANGER, type:"CURRENT", scale: 1000.0)

        FES_LoaderD_V (Channel, description: "FES loaderD voltage", units: "Volts", format: ".2f",
                       hwChan:Pdu24VD.CHAN_FES_LOADER, type:"VOLTAGE")

        FES_LoaderD_I (Channel, description: "FES loaderD current", units: "mA", format: ".1f",
                       hwChan:Pdu24VD.CHAN_FES_LOADER, type:"CURRENT", scale: 1000.0)

        Shtr_Brakes_V (Channel, description: "Shutter brakes voltage", units: "Volts", format: ".2f",
                       hwChan:Pdu24VD.CHAN_SHTR_BRAKES, type:"VOLTAGE")

        Shtr_Brakes_I (Channel, description: "Shutter brakes current", units: "mA", format: ".1f",
                       hwChan:Pdu24VD.CHAN_SHTR_BRAKES, type:"CURRENT", scale: 1000.0)

    }

    PDU_48V (Pdu48vDevice) {
        
        Main_V (Channel, description: "48V PDU main voltage", units: "Volts", format: ".2f",
                type:"MAINVOLT")

        Main_I (Channel, description: "48V PDU main current", units: "mA", format: ".1f",
                type:"MAINCURR", scale: 1000.0)

        Main_T (Channel, description: "48V PDU main temperature", units: "\u00b0C", format: ".1f",
                type:"MAINTEMP")

        Board_T (Channel, description: "48V PDU board temperature", units: "\u00b0C", format: ".1f",
                 type:"BOARDTEMP")

        FPGA_T (Channel, description: "48V PDU FPGA temperature", units: "\u00b0C", format: ".1f",
                type:"FPGATEMP")

        Purge_Fan_V (Channel, description: "Purge fan voltage", units: "Volts", format: ".2f",
                     hwChan:Pdu48V.CHAN_PURGE_FAN, type:"VOLTAGE")

        Purge_Fan_I (Channel, description: "Purge fan current", units: "mA", format: ".1f",
                     hwChan:Pdu48V.CHAN_PURGE_FAN, type:"CURRENT", scale: 1000.0)

        FES_CarouselD_V (Channel, description: "FES carouselD voltage", units: "Volts", format: ".2f",
                         hwChan:Pdu48V.CHAN_FES_CAROUSEL, type:"VOLTAGE")

        FES_CarouselD_I (Channel, description: "FES carouselD current", units: "mA", format: ".1f",
                         hwChan:Pdu48V.CHAN_FES_CAROUSEL, type:"CURRENT", scale: 1000.0)

        FES_Heater_V (Channel, description: "FES heater voltage", units: "Volts", format: ".2f",
                        hwChan:Pdu48V.CHAN_FES_HEATER, type:"VOLTAGE")

        FES_Heater_I (Channel, description: "FES heater current", units: "mA", format: ".1f",
                        hwChan:Pdu48V.CHAN_FES_HEATER, type:"CURRENT", scale: 1000.0)

        Shtr_Motor1_V (Channel, description: "Shutter motor 1 voltage", units: "Volts", format: ".2f",
                       hwChan:Pdu48V.CHAN_SHTR_MOTOR_1, type:"VOLTAGE")

        Shtr_Motor1_I (Channel, description: "Shutter motor 1 current", units: "mA", format: ".1f",
                       hwChan:Pdu48V.CHAN_SHTR_MOTOR_1, type:"CURRENT", scale: 1000.0)

        Shtr_Motor2_V (Channel, description: "Shutter motor 2 voltage", units: "Volts", format: ".2f",
                       hwChan:Pdu48V.CHAN_SHTR_MOTOR_2, type:"VOLTAGE")

        Shtr_Motor2_I (Channel, description: "Shutter motor 2 current", units: "mA", format: ".1f",
                       hwChan:Pdu48V.CHAN_SHTR_MOTOR_2, type:"CURRENT", scale: 1000.0)

    }

    REB_Bulk_PS (RebBulkPsDevice) {

        RebBulkPs_Brd_T (Channel, description: "REB Bulk PS board temperature", units: "\u00b0C", format: ".1f",
                         type:"BOARDTEMP")

        RebBulkPs_0_2_V (Channel, description: "REB Bulk PS 0-2 voltage", units: "Volts", format: ".1f",
                         hwChan:0, type:"VOLTAGE")

        RebBulkPs_0_2_I (Channel, description: "REB Bulk PS 0-2 current", units: "mA", format: ".1f",
                         hwChan:0, type:"CURRENT", scale: 1000.0)

        RebBulkPs_0_2_T (Channel, description: "REB Bulk PS 0-2 temperature", units: "\u00b0C", format: ".1f",
                         hwChan:0, type:"TEMP")

        RebBulkPs_3_5_V (Channel, description: "REB Bulk PS 3-5 voltage", units: "Volts", format: ".1f",
                         hwChan:1, type:"VOLTAGE")

        RebBulkPs_3_5_I (Channel, description: "REB Bulk PS 3-5 current", units: "mA", format: ".1f",
                         hwChan:1, type:"CURRENT", scale: 1000.0)

        RebBulkPs_3_5_T (Channel, description: "REB Bulk PS 3-5 temperature", units: "\u00b0C", format: ".1f",
                         hwChan:1, type:"TEMP")

        RebBulkPs_6_8_V (Channel, description: "REB Bulk PS 6-8 voltage", units: "Volts", format: ".1f",
                         hwChan:2, type:"VOLTAGE")

        RebBulkPs_6_8_I (Channel, description: "REB Bulk PS 6-8 current", units: "mA", format: ".1f",
                         hwChan:2, type:"CURRENT", scale: 1000.0)

        RebBulkPs_6_8_T (Channel, description: "REB Bulk PS 6-8 temperature", units: "\u00b0C", format: ".1f",
                         hwChan:2, type:"TEMP")

        RebBulkPs_9_12_V (Channel, description: "REB Bulk PS 9-12 voltage", units: "Volts", format: ".1f",
                         hwChan:3, type:"VOLTAGE")

        RebBulkPs_9_12_I (Channel, description: "REB Bulk PS 9-12 current", units: "mA", format: ".1f",
                         hwChan:3, type:"CURRENT", scale: 1000.0)

        RebBulkPs_9_12_T (Channel, description: "REB Bulk PS 9-12 temperature", units: "\u00b0C", format: ".1f",
                         hwChan:3, type:"TEMP")
    }

    Maq20 (QbMaq20Device, modules: ["DIOL", "DIOL", "DIOL"],
           utHcuPower: ref("UtHcus"), mechHcuPower: ref("MechHcus"), fesProt: ref("FesProt")) {

       UtHcus (Maq20DiscControl, modIndex: 0)

       MechHcus (Maq20DiscControl, modIndex: 1)

       FesProt (Maq20DiscControl, modIndex: 2)
    }

}
