Node('leidenexp.psi.ch',
    '''Leiden Dilution''',
)

#ah2550_uri = 'linse-leiden-ts:3001'  # capacitance bridge AH 2550
ah2700_uri = 'linse-leiden-ts:3002'  # capacitance bridge AH 2700
sourcemeter_uri = 'linse-leiden-ts:3001' # k2601b used for HC experiment as heater
srbridge_uri = 'linse-leiden-ts:3008'  # Stanford Research Resistance Bridge
calib_uri = 'linse-leiden-ts:3006'
# ls370 on port 3004: see  ~/sea/tcl/leiden.config

sea_cfg = 'leidenexp.addon'

Mod('sea_main',
    'frappy_psi.sea.SeaClient',
    'main sea connection for leiden.config',
    config = 'leiden.config',
    service = 'main',
)

for name in ['T3K', 'Tstill', 'T50mK', 'Tmxhigh',
             'Tpt50', 'Tpt3high', 'Tpt3low']:
    mname = name.replace('T','T_')
    kwds = {}
    if name == 'Tmxlow':
        kwds['meaning'] = ['temperature', 20]
    Mod(mname,
        'frappy_psi.sea.SeaReadable', '',
        io='sea_main',
        sea_object='tt',
        rel_paths=[name],
        value=Param(unit='K'),
        extra_modules = ['raw'],
        **kwds
    )
    Mod(name.replace('T', 'R_'),
        'frappy_psi.sea.SeaReadable', '',
        io='sea_main',
        value=Param(unit='Ohm'),
        single_module=f'{mname}.raw'
    )

# "if not <title>" means disabled, "if <title>" means enabled

if 'calibsetup':
    IO('io_cal', leiden_uri)

    Mod('V_cmn',
        'frappy_psi.lakeshore340.RawSensor',
        'voltage for cmn',
        io = 'io_cal',
        value = Param(unit='V'),
        channel = 'B'
    )

    Mod('T_cmn',
        'frappy_psi.softcal.Function',
        '',
        value=Param(unit='K'),
        rawsensor='V_cmn'
        formula='0.85e-3 + 16.33005 / (1000 * x - 60.83)'
    )

    Mod('V_fixp',
        'frappy_psi.lakeshore340.RawSensor',
        'voltage for fixp',
        io = 'io_cal',
        value = Param(unit='V'),
        channel = 'A'
    )

    Mod('io_mixhtr',
        'frappy.core.Proxy',
        'proxy to main frappy server',
        remote_class = 'frappy_psi.dilhtr.IO',
        uri = f'tcp://localhost:15118',
        module='io_htr',
    )

    Mod('mix_htr4cmn',
        'frappy_psi.dilhtr.WrappedHeater',
        'mix heater',
        io='io_mixhtr',
    )

    Mod('drive_cmn',
        'frappy_psi.picontrol.PIctrl',
        'controlled cmn temperature',
        input_module = 'T_cmn',
        output_module = 'mix_htr4cmn',
        output_min = 0,
        output_max = 3e-2,
        p = 2,
        itime = 120,
    )

    #Mod('drive_fixp',
    #    'frappy_psi.picontrol.PI',
    #    'controlled fixpoint voltage',
    #    value=Param(unit='V'),
    #    input_module = 'V_fixp',
    #    output_module = 'drive_mix',
    #    output_min = 0.0,
    #    output_max = 0.01,
    #    p = 1,
    #    itime = 120,
    #)

if 'sr_bridge':
    IO('io_sr', srbridge_uri)

    Mod('res1',
        'frappy_psi.bridge.Resistance',
        'please add description',
        io='io_sr',
        port=1,
    )

    Mod('T_res1',
        'frappy_psi.softcal.Sensor',
        '',
        rawsensor='res1',
        calcurve='RCW575a',
    )

    Mod('res2',
        'frappy_psi.bridge.Resistance',
        'please add description',
        io='io_sr',
        port=3,
    )

    Mod('T_res2',
        'frappy_psi.softcal.Sensor',
        '',
        rawsensor='res2',
        calcurve='RC550a',
    )

    Mod('phase1',
        'frappy_psi.bridge.Phase',
        'please add description',
        resistance='res1',
    )

    Mod('phase2',
        'frappy_psi.bridge.Phase',
        'please add description',
        resistance='res2',
    )

    Mod('dev1',
        'frappy_psi.bridge.Deviation',
        'please add description',
        resistance='res1',
    )

    Mod('dev2',
        'frappy_psi.bridge.Deviation',
        'please add description',
        resistance='res2',
    )


if 'keihley 2601b':
    IO('io_sm', sourcemeter_uri)

    Mod('source',
        'frappy_psi.k2601b.SourceMeter'
        '',
        description = "keithley sourcemeter",
        mode = 2,
        vlimit = 0.5,
        ilimit = .0005,
        io = 'io_sm',
    )

    Mod('hvolt',
        'frappy_psi.k2601b.Voltage'
        '',
        description = "Heater Voltage",
        active = False,
        limit = 1.0,
        target = 0.0,
        sourcemeter = 'source',
        io = 'io_sm',
    )

    Mod('hcur',
        'frappy_psi.k2601b.Current'
        '',
        description = "Heater Current Source",
        active = True,
        limit = 0.0001,
        target = 0.0,
        sourcemeter = 'source',
        io = 'io_sm',
    )

    Mod('hres',
        'frappy_psi.k2601b.Resistivity'
        '',
        description = "Heater Resistance",
        io = 'io_sm',
    )

    Mod('hpow',
        'frappy_psi.k2601b.Power'
        '',
        description = "Heater Power",
        io = 'io_sm',
    )


if 'cap ah2700':
    # TODO: adapt names (cap...) to your experiment

    IO('io_ah2700', ah2700_uri)

    Mod('cap',
        'frappy_psi.ahcapbridge.AH2700',
        'capacitance',
        acquisition_key='averexp',
        io='io_ah2700',
        loss_module = 'loss',
        freq_module = 'freq',
    )

    Mod('capvolt',
        'frappy_psi.ahcapbridge.Voltage',
        'excitation voltage',
        cap = 'cap',
    )

if not 'cap_ah2550':
    IO('io_ah2550', ah2550_uri)

    Mod('cap2',
        'frappy_psi.ahcapbridge.AH2550',
        'capacitance',
        acquisition_key='averexp',
        io='io_ah2550',
        loss_module = 'loss2',
    )
