from artiq.experiment import *

class DDSPhase(EnvExperiment):
    def build(self):
        self.setattr_device("core")
        self.rf0 = self.get_device("urukul0_ch0")  # -5dBm for input transform
        self.rf1 = self.get_device("urukul0_ch1")  # -20dBm
        self.rf2 = self.get_device("urukul0_ch2")  # -40~dBm for output at 0dB (with external 20db attenuator)
        self.rf3 = self.get_device("urukul0_ch3")  # -3.18dB for output at 33dB

    @kernel
    def run(self):
        self.core.reset()
        self.rf0.cpld.init()

        self.rf0.init()
        self.rf0.set_att(16.)  # -5dBm for input transform

        self.rf3.init()
        #self.rf3.set_att(14.)  # -3.18dBm for 33dBm
        self.rf3.set_att(23.)  # -8.18dBm? doesnt trip!

        self.rf1.init()
        self.rf1.set_att(31.)

        self.rf2.init()
        self.rf2.set_att(30.)

        freq = 200 * MHz

        self.rf0.set(freq, phase=0.)
        self.rf1.set(freq, phase=0.)
        self.rf2.set(freq, phase=0.)
        self.rf3.set(freq, phase=0.)

        self.rf0.sw.on()
        self.rf1.sw.on()
        self.rf2.sw.on()
        self.rf3.sw.on()
