Node('PEUS.psi.ch',
     'ultrasound, pulse_echo configuration',
     interface='5000',
)

Mod('u',
    'frappy_psi.ultrasound.PulseEcho',
    'ultrasound acquisition loop',
    freq='f',
    # pollinterval=0.1,
    time=900.0,
    size=5000.0,
    nr=500,
    sr=32768,
    bw=1e7,
)

Mod('fio',
    'frappy_psi.ultrasound.FreqStringIO', '',
    uri='serial:///dev/ttyS1?baudrate=57600',
)

Mod('f',
    'frappy_psi.ultrasound.Frequency',
    'writable for frequency',
    output='R',  # L for LF (bnc), R for RF (type N)
    io='fio',
    amp=0.5, # VPP
)

Mod('fdif',
    'frappy_psi.ultrasound.FrequencyDif',
    'writable for frequency minus base frequency',
    freq='f',
    base=41490200.0,
)

# Mod('curves',
#     'frappy_psi.ultrasound.Curves',
#     't, I, Q and pulse arrays for plot',
# )

def roi(name, time, size, components='iqpa', enable=True, control=False, freq=None, **kwds):
    description = 'I/Q of region {name}'
    if freq:
        kwds.update(cls='frappy_psi.ultrasound.ControlRoi',
                    description=f'{description} as control loop',
                    freq=freq, **kwds)
    else:
        kwds.update(cls='frappy_psi.ultrasound.Roi',
                    description=description, **kwds)
    kwds.update({c: name + c for c in components})
    Mod(name,
        main='u',
        time=time,
        size=size,
        enable=enable,
        **kwds,
        )
    for c in components:
        Mod(name + c,
            'frappy.modules.Readable',
            f'{name}{c} component',
        )

# control loop
roi('roi0', 2450, 300, freq='f', maxstep=100000, minstep=4000)
# other rois
roi('roi1', 5950, 300)
roi('roi2', 9475, 300)
roi('roi3', 12900, 300)
#roi('roi4', 400, 30, False)
#roi('roi5', 400, 30, False)
#roi('roi6', 400, 30, False)
#roi('roi7', 400, 30, False)
#roi('roi8', 400, 30, False)
#roi('roi9', 400, 30, False)

Mod('delay',
    'frappy_psi.dg645.Delay',
    'delay line with 2 channels',
    uri='serial:///dev/ttyS2',
    on1=1e-09,
    on2=1e-09,
    off1=4e-07,
    off2=6e-07,
)
