#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

##############################################
# This is the head of the main processing chain
# that runs at the highest priority.
##############################################

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "$(dev,recursive):GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C$(pad,recursive) S0")
  field(EGU, "raw")
#TODO set HOPR/LOPR, alarm limits
  field(SCAN, "I/O Intr")
# The priority determines what scan list we are being
# put on (see drvPadUdpComm.c)
  field(PRIO, "LOW")
  field(FLNK, "$(dev,recursive):RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C$(pad,recursive) S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "$(dev,recursive):BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C$(pad,recursive) S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "$(dev,recursive):YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C$(pad,recursive) S3")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

##############################################
# Slowly-scanned diagnostics
##############################################

#
record(waveform, "$(dev,recursive):REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C$(pad,recursive) S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

record(waveform, "$(dev,recursive):GRNW") {
  field(DESC, "Raw CAL GRN Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C$(pad,recursive) S2")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

record(waveform, "$(dev,recursive):RAWDBG") {
  field(DESC, "Raw BEAM Dbg")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
# do not 'wbscan' for now since e.g., an underrange
# condition on the real signal can happen.
  field(INP, "#C$(pad,recursive) S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

record(waveform, "$(dev,recursive):REDDBG") {
  field(DESC, "Raw CAL RED Dbg")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C$(pad,recursive) S8 @wbscan")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

record(waveform, "$(dev,recursive):GRNDBG") {
  field(DESC, "Raw CAL GRN Dbg")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C$(pad,recursive) S9 @wbscan")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

record(ai, "$(dev,recursive):GRUV") {
  field(DESC, "CAL Gain GRN/RED")
  field(DTYP, "Raw Stripl Calp")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S0")
  field(SCAN, "10 second")
  field(PREC, "4")
  field(LOPR, "0.5")
  field(HOPR, "1.5")
}

record(ai, "$(dev,recursive):GRU") {
  field(DESC, "CAL Gain GRN/BLU")
  field(DTYP, "Raw Stripl Calp")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S1")
  field(SCAN, "10 second")
  field(PREC, "4")
  field(LOPR, "0.5")
  field(HOPR, "1.5")
  info(autosaveFields, "ASLO")
}

record(ai, "$(dev,recursive):GRV") {
  field(DESC, "CAL Gain RED/YLO")
  field(DTYP, "Raw Stripl Calp")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S2")
  field(SCAN, "10 second")
  field(PREC, "4")
  field(LOPR, "0.5")
  field(HOPR, "1.5")
  info(autosaveFields, "ASLO")
}

record(ai, "$(dev,recursive):TGRN") {
  field(DESC, "Green arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S4")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ai, "$(dev,recursive):TRED") {
  field(DESC, "Red arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S5")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ai, "$(dev,recursive):TBLU") {
  field(DESC, "Blue arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S6")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ai, "$(dev,recursive):TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C$(pad,recursive) S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(bo, "$(dev,recursive):PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# QSCL setting:
#
# Q: charge
# Z: impedance
# F: form factor: phi/(2 pi) sin(2 pi f l/c)
#
# Signal =  Q Z F G h(t) = A h(t)  [A] = Vs
#
#                  inf              inf
# Energy =  A^2   / h^2(t) dt = A^2 / |H(w)|^2 dw/2/pi = A^2 B
#                0                 0
#                        
# Measured energy = Sum{ (Vp/32768 * xi)^2 } / fs = S / fs ~ Energy
#
# -> A^2 B = S/fs
#
# With T = sqrt( Sum{ xi^2 } )
#
#    A = sqrt(S)/sqrt(B*fs) = T/sqrt(B*fs) Vp/32768
#
#                      T/32768 Vp
#    Q = A/F/G/Z = -----------------
#                   F G Z sqrt(B*fs)
#
# Vp = { 1.5Vpp/2 (PGA=1) or 2.25Vpp/2 (PGA=0) } / 2 (transformer)
#
# I believe PGA is off (-> Vp ~ .56V)
#
# Z  = 50
#
# G: (calibration uses GRN/BLU -> signal should have the
#    level of the grn/red channels with the additional switch)
#
# Block diagram / parts / gain:
#
# [filt]    [Att1]    [Amp1]   [Att2]    [BPF]      [Amp2]    [pad] [Amp3]   [switch]
# f-17520  hmc540lp3  SBF-5089 hmc540lp3 MBP-140-6-4 SBF-4089  PAT-0 SBF-4089 HMC-197
#
#  -2dB*    -1dB       20dB     -1dB     -4.5         14.8dB   0dB   14.8dB   -0.4dB
#
# *: 1st filter ATT is a wild guess.
#  BPF loss (RLC Catalog, pp.55): (L (nsect+.5) / (% of 3dB BW) + .2) dB
#  with L ~6.2  10MHz/fc=140Mhz filter-> 4.5
#
#  -> Gtot ~ 40.7dB
#
#  subtract cable loss (2dB); Gtot = 86
# 
#                      T/32768 Vp            .56V/32768
#    Q = A/F/G/Z = ----------------- = T/F  ------------------------
#                   F G Z sqrt(B*fs)        86*50*sqrt(10*140)Mhz
#
#      = T/F = 1.06E-7/F nC
#
#    F for a 7% coverage, 4" BPM at 140MHz   .07 sin(2*pi*140e6 4*.0254/3e8)
#      = .021
#
#      => 1.06E-7/.021 nC = 5E-6 nC
#
# (Faraday cup measurement -> (3600/44)^-1 1e-4 -> 1.22E-6
#
record(ao, "$(dev,recursive):QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):QSCA.A PP MS")
# 5.0E-6 / 1.6E-10 [nC/e-]
  field(VAL, "31250")
  field(EGU, "Nel")
  field(PREC, "3")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# Adjust TMIT scale for AFE attenuation
record(calcout, "$(dev,recursive):QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "$(dev,recursive):ATT1 CP")
  field(INPC, "$(dev,recursive):ATT2 CP")
  field(CALC, "A*10^((B+C+D)/20)")
# use CA link to deposit into TMIT.ASLO so
# that TMIT is not forced into linkset
# of this record
  field(OUT, "$(dev,recursive):TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

record(ao,    "$(dev,recursive):ATT1SIMP") {
	field(DESC, "ATT1 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "$(dev,recursive):ATT1   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "$(dev,recursive):ASIM.A PP")
  	field(IVOA, "Set output to IVOV")
	field(IVOV, "0")
	field(EGU,  "dB")
}

record(ao,    "$(dev,recursive):ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "$(dev,recursive):ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "$(dev,recursive):ASIM.C PP")
  	field(IVOA, "Set output to IVOV")
	field(IVOV, "0")
	field(EGU,  "dB")
}

# Attenuate charge either by
# real attenuator settings or
# by fake ones.
# If B, C >= 0 then their
# values will be used instead
# of ATT1, ATT2
record(calcout, "$(dev,recursive):ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "$(dev,recursive):QSIM.ESLO PP")
# ATT1SIM puts value into A
# set to -1 to use real attenuator settings
# and >=0 to use B instead
  field(B,    "-1")
# ATT2SIM puts value into C
# set to -1 to use real attenuator settings
# and >=0 to use D instead
  field(D,    "-1")
  field(CALC, "10^(((B>=0?B:A)+(D>=0?D:C))/20)")
  field(PINI, "YES")
}

record(ao, "$(dev,recursive):WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "$(dev,recursive):STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "$(dev,recursive):RSTA.SEVR MS NPP")
  field(INPB, "$(dev,recursive):TMIT.SEVR MS NPP")
  field(INPC, "$(dev,recursive):Y.SEVR    MS NPP")
  field(INPD, "$(dev,recursive):X.SEVR    MS NPP")
  field(INPE, "$(dev,recursive):TGRN.SEVR MS NPP")
  field(INPF, "$(dev,recursive):TRED.SEVR MS NPP")
  field(INPG, "$(dev,recursive):TBLU.SEVR MS NPP")
  field(INPH, "$(dev,recursive):TYLO.SEVR MS NPP")
  field(INPI, "$(dev,recursive):GRU.SEVR  MS NPP")
  field(INPJ, "$(dev,recursive):GRV.SEVR  MS NPP")
  field(SCAN, "1 second")
}

# This record really belongs on the
# PAD IOC. We keep them here however
# so we can save/restore. It is more
# confusing but shouldn't matter from
# an efficiency standpoint (they are
# rarely changed).
record(longout, "$(dev,recursive):ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "$(dev,recursive):ATTC.B PP")
  field(DRVL, "-10")
  field(DRVH, "30")
  field(LOPR, "-10")
  field(HOPR, "30")
  field(EGU, "dB")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL DRVH HOPR DRVL LOPR")
}

# This record really belongs on the
# PAD IOC. We keep them here however
# so we can save/restore. It is more
# confusing but shouldn't matter from
# an efficiency standpoint (they are
# rarely changed).
record(longout, "$(dev,recursive):CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "$(dev,recursive):ATTC.C PP")
  field(DRVL, "-20")
  field(DRVH, "20")
  field(LOPR, "-20")
  field(HOPR, "20")
  field(EGU, "dB")
  field(VAL, "40")
  field(PINI, "YES")
  info(autosaveFields, "VAL DRVH HOPR DRVL LOPR")
}

record(calc, "$(dev,recursive):STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "$(dev,recursive):RSTA_ALH.SEVR MS NPP")
  field(INPB, "$(dev,recursive):GRU.SEVR  MS NPP")
  field(INPC, "$(dev,recursive):GRV.SEVR  MS NPP")
  field(INPD, "$(dev,recursive):CHK.SEVR MS NPP")
# for optional additional alarm input:
  field(INPE, "$(dev,recursive):FWSTAT_ALH MS")
}

# snapshot PV for the bpm values display
record(ai, "$(dev,recursive):GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "$(dev,recursive):GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "$(dev,recursive):RED_SLOW")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "$(dev,recursive):RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "$(dev,recursive):BLU_SLOW")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "$(dev,recursive):BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "$(dev,recursive):YLO_SLOW")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "$(dev,recursive):YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "$(dev,recursive):YLO NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(sub, "$(dev,recursive):CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "$(pad,recursive)")
  field(SCAN, "Passive")
}

record(bo, "$(dev,recursive):PINC_ENA") {
  field(DESC, "Simple Pincushion Alg")
  field(DTYP, "BusAddress")
  field(OUT,  "#C0S2@drvBpmStriplPincEna,m32")
  field(MASK, "$(padbit,recursive)")
  field(ZNAM, "DISABLED")
  field(ONAM, "ENABLED")
  field(VAL,  "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

record(ao, "$(dev,recursive):UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C$(pad,recursive)S0")
  field(EGU,  "ADC Ticks")
  field(DOL,  "45.26")
  field(PINI, "YES")
  field(DRVL, "0")
  field(DRVH, "32767")
  info(autosaveFields, "VAL")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

######################################
# HEAD of main processing chain
######################################

record(ai, "$(dev,recursive):X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S11")
  field(SCAN, "I/O Intr")
# The priority determines what scan list we are being
# put on (see drvPadUdpComm.c)
  field(PRIO, "HIGH")
  field(FLNK, "$(dev,recursive):Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "$(asg,recursive)")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

record(ai, "$(dev,recursive):Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S12")
  field(FLNK, "$(dev,recursive):TMIT")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "$(asg,recursive)")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

record(ai, "$(dev,recursive):TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "")
  field(ASG,  "$(asg,recursive)")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


######################################
# HEAD of diagnostics processing chain
######################################

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "$(dev,recursive):RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C$(pad,recursive) S0")
  field(SCAN, "I/O Intr")
# use LOW or HIGH to end up on the 'diagnostic' 
# scan list (see drvPadUdpComm.c)
  field(PRIO, "LOW")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU,  "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
}

record(ai, "$(dev,recursive):U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S8")
  field(SCAN, "I/O Intr")
# use LOW or HIGH to end up on the 'diagnostic' 
# scan list (see drvPadUdpComm.c)
  field(PRIO, "LOW")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "$(dev,recursive):V")
}

record(ai, "$(dev,recursive):V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "$(dev,recursive):PINC")
}

record(ai, "$(dev,recursive):PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C$(pad,recursive) S10")
  field(SCAN, "Passive")
}

record(longin, "$(dev,recursive):RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C$(pad,recursive)S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "$(dev,recursive):RSTA_ALH")
}


record(calc, "$(dev,recursive):RSTA_ALH") {
  field(CALC, "A & B")
  field(INPA, "$(dev,recursive):RSTA")
  field(INPB, "0x30F")
  field(HIHI, "1")
  field(LOLO, "-1")
  field(HHSV, "MAJOR")
  field(LLSV, "MAJOR")
  field(SCAN, "Passive")
}

######################################
# Input/Parameteres
######################################

record(ao, "$(dev,recursive):PHI") {
  field(DESC, "Rot Angle")
  field(DTYP, "Soft Channel")
  field(VAL, "0")
  field(EGU, "deg")
  field(PREC, "1")
  field(LOPR, "-180")
  field(HOPR, "+180")
  field(FLNK, "$(dev,recursive):PHI_SEQ")
}

record(ao, "$(dev,recursive):PSI") {
  field(DESC, "Axis Sep. Angle")
  field(DTYP, "Soft Channel")
  field(VAL, "90")
  field(EGU, "deg")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "+180")
  field(FLNK, "$(dev,recursive):PSI_SEQ")
}

#record(dfanout, "$(dev,recursive):PCMM") {
#  field(DESC, "BPM Scale")
#  field(OUTA, "$(dev,recursive):USCL PP MS")
#  field(OUTB, "$(dev,recursive):VSCL PP MS")
#  field(VAL, "12")
#  field(EGU, "mm")
#  field(PREC, "4")
#  field(LOPR, "5")
#  field(HOPR, "15")
#  field(PINI, "YES")
#}

record(ao, "$(dev,recursive):UOFF") {
  field(DESC, "BPM U Offset")
  field(DTYP, "Soft Channel")
  field(VAL, "0")
  field(EGU, "mm")
  field(PREC, "4")
  field(LOPR, "-5")
  field(HOPR, "+5")
  field(FLNK, "$(dev,recursive):UOFF_SEQ")
}

record(ao, "$(dev,recursive):VOFF") {
  field(DESC, "BPM V Offset")
  field(DTYP, "Soft Channel")
  field(VAL, "0")
  field(EGU, "mm")
  field(PREC, "4")
  field(LOPR, "-5")
  field(HOPR, "+5")
  field(FLNK, "$(dev,recursive):VOFF_SEQ")
}

record(ao, "$(dev,recursive):USCL") {
  field(DESC, "BPM U Scale")
  field(DTYP, "Soft Channel")
  field(VAL,  "1")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "$(dev,recursive):USCL_SEQ")
}

record(ao, "$(dev,recursive):VSCL") {
  field(DESC, "BPM V Scale")
  field(DTYP, "Soft Channel")
  field(VAL,  "1")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "$(dev,recursive):VSCL_SEQ")
}


record(mbbo, "$(dev,recursive):ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C$(pad,recursive) S0")
  field(ZRVL, "1")
  field(ZRST, "Running")
  field(ZRSV, "NO_ALARM")
  field(ONVL, "1")
  field(ONST, "Maintenance")
  field(ONSV, "MINOR")
  field(TWVL, "1")
  field(TWST, "Test")
  field(TWSV, "MINOR")
  field(THVL, "0")
  field(THST, "OFFLINE")
  field(THSV, "MAJOR")
# set both, rval and val to get it right
# regardless of whether devsup does conversion
# or not.
  field(RVAL, "0")
  field(VAL,  "0")
  field(PINI, "YES")
  field(FLNK, "$(dev,recursive):SIMOFF")
  info(autosaveFields, "RVAL")
}

#
# Used by higher level software to determine if a PV is in feedback or not.
# May also be used by actuator (magnet and RF) IOC applications to 
# switch output records to "closed_loop" to prevent outside programs from
# changing setpoints when an actuator device is in feedback.
#
record(mbbo, "$(dev,recursive):FBCK")
{
  field(DESC, "Feedback State")
  field(PINI, "YES")
  field(OMSL, "supervisory")
  field(VAL,  "0")
  field(ZRVL, "0")
  field(ONVL, "1")
  field(TWVL, "2")
# Off - this device can be used in feedback but all feedback loops 
# using it are off.
  field(ZRST, "Off")
# On - this device is being used by one or more feedback loops.
  field(ONST, "On")
# Unavailable - this device is not used by any feedback loop.
  field(TWST, "Unavailable")
  info(autosaveFields, "VAL")
}

# Convenience record holding the MAD name
record(stringin, "$(dev,recursive):MADN") {
  field(DESC, "MAD Name")
  field(VAL, "$(maddev,recursive)")
  field(PINI, "YES")
}

record(stringin, "$(maddev,recursive):NAME") {
  field(DESC, "BPM Name")
  field(VAL, "$(dev,recursive)")
  field(PINI, "YES")
}

record(ai, "$(dev,recursive):X_SLOW") {
#alias("$(dev,recursive):X1H")
  field(DESC, "X snapshot for display")
  field(EGU, "mm")
  field(INP, "$(dev,recursive):X MS")
  field(FLNK, "$(dev,recursive):Y_SLOW")
  field(PREC, "4")
  field(SCAN, "1 second")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ai, "$(dev,recursive):Y_SLOW") {
#alias("$(dev,recursive):Y1H")
  field(DESC, "Y snapshot for display")
  field(EGU, "mm")
  field(INP, "$(dev,recursive):Y NPP MS")
  field(FLNK, "$(dev,recursive):TMIT_SLOW")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ai, "$(dev,recursive):TMIT_SLOW") {
#alias("$(dev,recursive):TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "$(dev,recursive):TMIT NPP MS")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
}

# Slowly updating PVs for displays
# May point to either SW- or FW-calculated
# values, depending on architecture
# Set dispsuffix macro to "F" to use FW values
record(ai, "$(dev,recursive):XDISP") {
  field(DESC, "X snapshot for display")
  field(EGU, "mm")
  field(INP, "$(dev,recursive):XF MS CA")
  field(FLNK, "$(dev,recursive):YDISP")
  field(PREC, "4")
  field(SCAN, "1 second")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ai, "$(dev,recursive):YDISP") {
  field(DESC, "Y snapshot for display")
  field(EGU, "mm")
  field(INP, "$(dev,recursive):YF MS CA")
  field(FLNK, "$(dev,recursive):TMITDISP")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ai, "$(dev,recursive):TMITDISP") {
  field(DESC, "TMIT snapshot for display")
  field(INP, "$(dev,recursive):TMITF MS CA")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
}

######################################
# Simulation Parameters + Control
######################################

# switch off simulation when going off-line
record(calcout, "$(dev,recursive):SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "$(dev,recursive):ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "$(dev,recursive):SIMC PP")
}

record(calcout, "$(dev,recursive):SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "$(pad,recursive)")
#CALC & VAL unused; the real calculation is done
#        in device support. The reason this is a
#        calcout rather than sub is that we want
#        to use the OUT link...
  field(CALC, "A")
  field(INPA, "$(dev,recursive):USCL")
  field(INPL, "0")
}

# Switch simulation record $(dev,recursive):SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "$(dev,recursive):SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "$(dev,recursive):SIMCSEQ.SELN PP")
  field(ZRST, "OFF")
  field(ZRVL, "0x0f")
  field(ONST, "ON")
  field(ONVL, "0x1c0")
  field(TWST, "SOFT")
  field(TWVL, "0x030")
  field(MASK, "-1")
  field(NOBT, "16")
  field(VAL,  "0")
  field(RVAL, "0x0f")
  field(PINI, "YES")
}

record(ao, "$(dev,recursive):XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ao, "$(dev,recursive):YSIM") {
  field(DESC, "BPM Y Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):SIM.C PP")
  field(VAL, "0.")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

record(ao, "$(dev,recursive):QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "$(dev,recursive):SIM.D PP")
  field(EGU, "Nel")
  field(ASLO, "6000")
#ESLO is used to add attenuation
  field(LINR, "LINEAR")
  field(VAL, "1E9")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "0")
  field(HOPR, "1E11")
}

record(ao, "$(dev,recursive):ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

record(ao, "$(dev,recursive):PSIS") {
  field(DESC, "BPM Angle. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "$(dev,recursive):SIM.F PP")
  field(VAL, "90")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "0")
}

record(aao, "$(dev,recursive):DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C$(pad,recursive) S0")
  field(FTVL, "SHORT")
  field(EGU,  "Counts")
  field(HOPR, "32678")
  field(LOPR, "-32768")
# 16384 samples/channel * 4 channels
  field(NELM, "65536")
  field(PINI, "NO")
}

#Used by model/database folks to verify BPM

record(ao, "$(dev,recursive):Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "$(dev,recursive):MPSBYP") {
  field(DESC, "MPS Bypass")
  field(DTYP, "BusAddress")
  field(OUT,  "#C0S2@bpmMPS+0,m32")
  field(MASK, "$(padbit,recursive)")
  field(ZNAM, "BYPASSED")
  field(ONAM, "NOT_BYPASSED")
  field(ZSV,  "MAJOR")
  field(OSV,  "NO_ALARM")
  field(VAL,  "0")
  field(PINI, "YES")
  field(ASG,  "$(asg,recursive)")
  info(autosaveFields, "VAL")
}

record(bo, "$(dev,recursive):MPSLTBYP") {
  field(DESC, "MPS Bypass")
  field(DTYP, "BusAddress")
  field(OUT,  "#C1S2@bpmMPS+0,m32")
  field(MASK, "$(padbit,recursive)")
  field(ZNAM, "BYPASSED")
  field(ONAM, "NOT_BYPASSED")
  field(ZSV,  "NO_ALARM")
  field(OSV,  "NO_ALARM")
  field(VAL,  "0")
  field(PINI, "YES")
  field(ASG,  "$(asg,recursive)")
  info(autosaveFields, "VAL")
}

record(calc, "$(dev,recursive):MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "$(dev,recursive):TMIT")
  field(INPB, "$(dev,recursive):T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "$(asg,recursive)")
}

record(bi, "$(dev,recursive):MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "$(dev,recursive):MPSIGNRCALC PP")
  field(ZSV, "NO_ALARM")
  field(OSV, "MAJOR")
  field(ZNAM, "Not ignored")
  field(ONAM, "Ignored")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
}

# Proxy records for users to set X.AOFF, Y.AOFF
# Placed CAS on X and Y for MPS 
# Feb 2010 - CAS has since been removed, but we'll keep 
# these proxy records as they're already in use

record(ao, "$(dev,recursive):XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "$(dev,recursive):X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "$(dev,recursive):XOFF")
  info(autosaveFields, "VAL")
}

record(ao, "$(dev,recursive):YAOFF") {
  field(DESC, "Y.AOFF val")
#  field(OUT, "$(dev,recursive):Y.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "$(dev,recursive):YOFF")
  info(autosaveFields, "VAL")
}

# Add CALC to allow users to maintain
# multiple offsets per plane per BPM

record(calcout, "$(dev,recursive):XOFF") {
  field(DESC, "Add X offsets")
  field(PREC, "4")
  field(CALC, "A+B+C+D")
  field(INPA, "$(dev,recursive):XAOFF")
# B-E reserved for undulator offsets
  field(INPB, "")
  field(INPC, "")
  field(INPD, "")
  field(INPE, "")
  field(EGU, "mm")
  field(OUT, "$(dev,recursive):X.AOFF")
  info(autosaveFields, "B C D E")
}

record(calcout, "$(dev,recursive):YOFF") {
  field(DESC, "Add Y offsets")
  field(PREC, "4")
  field(CALC, "A+B+C+D")
  field(INPA, "$(dev,recursive):YAOFF")
# B-E reserved for undulator offsets
  field(INPB, "")
  field(INPC, "")
  field(INPD, "")
  field(INPE, "")
  field(EGU, "mm")
  field(OUT, "$(dev,recursive):Y.AOFF")
  info(autosaveFields, "B C D E")
}


# Records to set MPS thresholds
record(ao, "$(dev,recursive):X_MPS_THRES_L") {
  field(DESC, "MPS X Threshold Lo")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S0 @Lo")
  field(VAL,  "-1")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}
record(ao, "$(dev,recursive):X_MPS_THRES_H") {
  field(DESC, "MPS X Threshold Hi")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S0 @Hi")
  field(VAL,  "1")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}
record(ao, "$(dev,recursive):Y_MPS_THRES_L") {
  field(DESC, "MPS Y Threshold Lo")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S1 @Lo")
  field(VAL,  "-1")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}
record(ao, "$(dev,recursive):Y_MPS_THRES_H") {
  field(DESC, "MPS Y Threshold Hi")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S1 @Hi")
  field(VAL,  "1")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}
record(ao, "$(dev,recursive):T_MPS_THRES_L") {
  field(DESC, "MPS TMIT Threshold Lo")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S2 @Lo")
  field(VAL,  "9.375e7")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}
record(ao, "$(dev,recursive):T_MPS_THRES_H") {
  field(DESC, "MPS TMIT Threshold Hi")
  field(DTYP, "Bpm Mps Threshold")
  field(OUT,  "#C$(pad,recursive) S2 @Hi")
  field(VAL,  "+1.0E20")
  field(EGU,  "mm")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG, "$(asg,recursive)")
  info(autosaveFields, "VAL")
}

record(bi, "$(dev,recursive):FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

# Record to inform users that BPM
# needs TMIT and/or X/Y scale calibration
record(mbbo, "$(dev,recursive):CHK") {
  field(DESC, "Needs cal/iron")
  field(OMSL, "supervisory")
  field(VAL,  "0")
  field(ZRVL, "0")
  field(ONVL, "1")
  field(TWVL, "2")
  field(THVL, "3")
  field(ZRST, " ")
  field(ONST, "Calibrate")
  field(TWST, "Calibrate&iron")
  field(THST, "Iron")
  field(ZRSV, "NO_ALARM")
  field(ONSV, "MINOR")
  field(TWSV, "MINOR")
  field(THSV, "MINOR")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# Switch simulation record 
record(seq, "$(dev,recursive):SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

  field(DO1,  "1")
  field(DO2,  "0")
  field(DO3,  "0")
  field(DO4,  "0") #Passive

#  field(DO5,  "7") # .5 second
  field(DO5,  "9") # .1 second
  field(DO6,  "2")
  field(DO7,  "1")
  field(DO8,  "10")
  field(DO9,  "0")

# LNK 1, 2, 8, 9 only relevant for PADs
# Default macro values are set for PADs; other
# architectures must pass in "" for lnk1 and lnk2
  field(LNK1, "")
  field(LNK2, "")
  field(LNK3, "$(dev,recursive):SIM.L     PP")
  field(LNK4, "$(dev,recursive):SIM.SCAN  PP")

  field(LNK5, "$(dev,recursive):SIM.SCAN  PP")
  field(LNK6, "$(dev,recursive):SIM.L     PP")
  field(LNK7, "$(dev,recursive):SIM.L     PP")
  field(LNK8, "")
  field(LNK9, "")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):UOFF")
	field(DOL2, "$(dev,recursive):UOFF")
	field(DOL3, "$(dev,recursive):UOFF")
	field(DOL4, "$(dev,recursive):UOFF")
	field(DOL5, "$(dev,recursive):UOFF")
	field(DOL6, "$(dev,recursive):UOFF")
	field(DOL7, "$(dev,recursive):UOFF")
	field(DOL8, "$(dev,recursive):UOFF")
	field(DOL9, "$(dev,recursive):UOFF")
	field(DOLA, "$(dev,recursive):UOFF")
	field(LNK1, "$(dev,recursive):UOFF_SEL.A PP")
	field(LNK2, "$(dev,recursive):UOFF_SEL.B PP")
	field(LNK3, "$(dev,recursive):UOFF_SEL.C PP")
	field(LNK4, "$(dev,recursive):UOFF_SEL.D PP")
	field(LNK5, "$(dev,recursive):UOFF_SEL.E PP")
	field(LNK6, "$(dev,recursive):UOFF_SEL.F PP")
	field(LNK7, "$(dev,recursive):UOFF_SEL.G PP")
	field(LNK8, "$(dev,recursive):UOFF_SEL.H PP")
	field(LNK9, "$(dev,recursive):UOFF_SEL.I PP")
	field(LNKA, "$(dev,recursive):UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):UOFF_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):UOFF_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "0")
	field(B,    "0")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "4")
	field(FLNK, "$(dev,recursive):UOFF_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):UOFF_SEL")
	field(OUTA, "$(dev,recursive):U.AOFF CA")
	field(OUTB, "$(dev,recursive):UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):UOFF_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):UOFF_SEL.L PP")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):VOFF")
	field(DOL2, "$(dev,recursive):VOFF")
	field(DOL3, "$(dev,recursive):VOFF")
	field(DOL4, "$(dev,recursive):VOFF")
	field(DOL5, "$(dev,recursive):VOFF")
	field(DOL6, "$(dev,recursive):VOFF")
	field(DOL7, "$(dev,recursive):VOFF")
	field(DOL8, "$(dev,recursive):VOFF")
	field(DOL9, "$(dev,recursive):VOFF")
	field(DOLA, "$(dev,recursive):VOFF")
	field(LNK1, "$(dev,recursive):VOFF_SEL.A PP")
	field(LNK2, "$(dev,recursive):VOFF_SEL.B PP")
	field(LNK3, "$(dev,recursive):VOFF_SEL.C PP")
	field(LNK4, "$(dev,recursive):VOFF_SEL.D PP")
	field(LNK5, "$(dev,recursive):VOFF_SEL.E PP")
	field(LNK6, "$(dev,recursive):VOFF_SEL.F PP")
	field(LNK7, "$(dev,recursive):VOFF_SEL.G PP")
	field(LNK8, "$(dev,recursive):VOFF_SEL.H PP")
	field(LNK9, "$(dev,recursive):VOFF_SEL.I PP")
	field(LNKA, "$(dev,recursive):VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):VOFF_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):VOFF_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "0")
	field(B,    "0")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "4")
	field(FLNK, "$(dev,recursive):VOFF_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):VOFF_SEL")
	field(OUTA, "$(dev,recursive):V.AOFF CA")
	field(OUTB, "$(dev,recursive):VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):VOFF_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):VOFF_SEL.L PP")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):USCL")
	field(DOL2, "$(dev,recursive):USCL")
	field(DOL3, "$(dev,recursive):USCL")
	field(DOL4, "$(dev,recursive):USCL")
	field(DOL5, "$(dev,recursive):USCL")
	field(DOL6, "$(dev,recursive):USCL")
	field(DOL7, "$(dev,recursive):USCL")
	field(DOL8, "$(dev,recursive):USCL")
	field(DOL9, "$(dev,recursive):USCL")
	field(DOLA, "$(dev,recursive):USCL")
	field(LNK1, "$(dev,recursive):USCL_SEL.A PP")
	field(LNK2, "$(dev,recursive):USCL_SEL.B PP")
	field(LNK3, "$(dev,recursive):USCL_SEL.C PP")
	field(LNK4, "$(dev,recursive):USCL_SEL.D PP")
	field(LNK5, "$(dev,recursive):USCL_SEL.E PP")
	field(LNK6, "$(dev,recursive):USCL_SEL.F PP")
	field(LNK7, "$(dev,recursive):USCL_SEL.G PP")
	field(LNK8, "$(dev,recursive):USCL_SEL.H PP")
	field(LNK9, "$(dev,recursive):USCL_SEL.I PP")
	field(LNKA, "$(dev,recursive):USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):USCL_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):USCL_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "1")
	field(B,    "1")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "4")
	field(FLNK, "$(dev,recursive):USCL_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):USCL_SEL")
	field(OUTA, "$(dev,recursive):U.ASLO CA")
	field(OUTB, "$(dev,recursive):USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):USCL_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):USCL_SEL.L PP")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):VSCL")
	field(DOL2, "$(dev,recursive):VSCL")
	field(DOL3, "$(dev,recursive):VSCL")
	field(DOL4, "$(dev,recursive):VSCL")
	field(DOL5, "$(dev,recursive):VSCL")
	field(DOL6, "$(dev,recursive):VSCL")
	field(DOL7, "$(dev,recursive):VSCL")
	field(DOL8, "$(dev,recursive):VSCL")
	field(DOL9, "$(dev,recursive):VSCL")
	field(DOLA, "$(dev,recursive):VSCL")
	field(LNK1, "$(dev,recursive):VSCL_SEL.A PP")
	field(LNK2, "$(dev,recursive):VSCL_SEL.B PP")
	field(LNK3, "$(dev,recursive):VSCL_SEL.C PP")
	field(LNK4, "$(dev,recursive):VSCL_SEL.D PP")
	field(LNK5, "$(dev,recursive):VSCL_SEL.E PP")
	field(LNK6, "$(dev,recursive):VSCL_SEL.F PP")
	field(LNK7, "$(dev,recursive):VSCL_SEL.G PP")
	field(LNK8, "$(dev,recursive):VSCL_SEL.H PP")
	field(LNK9, "$(dev,recursive):VSCL_SEL.I PP")
	field(LNKA, "$(dev,recursive):VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):VSCL_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):VSCL_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "1")
	field(B,    "1")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "4")
	field(FLNK, "$(dev,recursive):VSCL_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):VSCL_SEL")
	field(OUTA, "$(dev,recursive):V.ASLO CA")
	field(OUTB, "$(dev,recursive):VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):VSCL_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):VSCL_SEL.L PP")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):PHI")
	field(DOL2, "$(dev,recursive):PHI")
	field(DOL3, "$(dev,recursive):PHI")
	field(DOL4, "$(dev,recursive):PHI")
	field(DOL5, "$(dev,recursive):PHI")
	field(DOL6, "$(dev,recursive):PHI")
	field(DOL7, "$(dev,recursive):PHI")
	field(DOL8, "$(dev,recursive):PHI")
	field(DOL9, "$(dev,recursive):PHI")
	field(DOLA, "$(dev,recursive):PHI")
	field(LNK1, "$(dev,recursive):PHI_SEL.A PP")
	field(LNK2, "$(dev,recursive):PHI_SEL.B PP")
	field(LNK3, "$(dev,recursive):PHI_SEL.C PP")
	field(LNK4, "$(dev,recursive):PHI_SEL.D PP")
	field(LNK5, "$(dev,recursive):PHI_SEL.E PP")
	field(LNK6, "$(dev,recursive):PHI_SEL.F PP")
	field(LNK7, "$(dev,recursive):PHI_SEL.G PP")
	field(LNK8, "$(dev,recursive):PHI_SEL.H PP")
	field(LNK9, "$(dev,recursive):PHI_SEL.I PP")
	field(LNKA, "$(dev,recursive):PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):PHI_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):PHI_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "0")
	field(B,    "0")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "1")
	field(FLNK, "$(dev,recursive):PHI_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):PHI_SEL")
	field(OUTA, "$(dev,recursive):CALC.E CA")
	field(OUTB, "$(dev,recursive):PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):PHI_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):PHI_SEL.L PP")
}
# Maintain multiple (up to 10) values of
# a parameter:
# 
# Record holding the parameter $[parm]
# must FLNK -> $[parm]_SEQ
#
# Different values of the parameter 
# $[parm0]..$[parm9] are stored in
# $[parm]_SEL.A .. $[parm]_SEL.J
#
# The actual value of the parameter is
# selected based on the value of a controlling
# PV $[ctrl] using a 'mapping' CALC expression
# $[mapc] to convert the $[ctrl] value into
# the integer range 1..10. 
#
# The selected value of $[parm] is written
# to output link $[outl]
#
# A) When the user writes $[parm] then
#    its value is deposited in the currently
#    selected field of $[parm]_SEL and
#    propagated to $[outl]
#
# B) When the user writes any of $[parm]_SEL.A..J
#    then the value is stored there. If she
#    writes to the currently 'active' field\
#    (as selected by $[ctrl]) then 
#    the $[parm] PV itself is updated and the
#    value is also propagated to $[outl]
#
# C) If the user changes $[ctrl] then the
#    corresponding value $[parm]_SEL.A..J is 
#    propagated to $[outl] and $[parm].
#
# D) At initialization, the value corresponding
#    to the initial setting of $[ctrl] is written
#    to $[outl] and $[parm]
#
# MACROS:
#
# $[parm]  PV holding the parameter
# $[ctrl]  PV that controls the selection of
#          the currently active setting of 
#          $[parm]
# $[outl]  PV where the currently selected 
#          value of $[parm] shall be written-to
#          (if applicable)
# $[prec]  Precision of the $[parm]_SEL variable
#          (should be set to same value as $[parm].PREC)
#
# $[parm0]..$[parm9] initial values of $[parm]
#
# $[mapc]  CALC expression to convert the value
#          of the controlling PV which is available
#          as 'A' to the range 1..10 (or less if
#          less selections are used).
#          E.g., to convert the value of a bo (0/1)
#          you would set mapc to 'A+1' (0..1 -> 1..2)
#
# NOTE:    This sb snippet is loaded/expanded
#          for every parameter under control
#          of $[ctrl]. ALSO, the companion
#          snippet parmCtl.db must be loaded/expanded
#          but only once per controlling PV.
#          

# This record, when scanned (as a result
# of $[parm] being written and processing
# its FLNK to this record] fetches $[parm]
# and deposits the value into the currently
# selected field of the SEL record.
# 
# NOTE: unfortunately, the selection
#       mechanism of the SEQ and SEL
#       records differs: SEQ is 1-based,
#       SEL is 0-based -- now that makes
#       sense, doesn't it?
#
record(seq, "$(dev,recursive):PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "$(dev,recursive):PSI")
	field(DOL2, "$(dev,recursive):PSI")
	field(DOL3, "$(dev,recursive):PSI")
	field(DOL4, "$(dev,recursive):PSI")
	field(DOL5, "$(dev,recursive):PSI")
	field(DOL6, "$(dev,recursive):PSI")
	field(DOL7, "$(dev,recursive):PSI")
	field(DOL8, "$(dev,recursive):PSI")
	field(DOL9, "$(dev,recursive):PSI")
	field(DOLA, "$(dev,recursive):PSI")
	field(LNK1, "$(dev,recursive):PSI_SEL.A PP")
	field(LNK2, "$(dev,recursive):PSI_SEL.B PP")
	field(LNK3, "$(dev,recursive):PSI_SEL.C PP")
	field(LNK4, "$(dev,recursive):PSI_SEL.D PP")
	field(LNK5, "$(dev,recursive):PSI_SEL.E PP")
	field(LNK6, "$(dev,recursive):PSI_SEL.F PP")
	field(LNK7, "$(dev,recursive):PSI_SEL.G PP")
	field(LNK8, "$(dev,recursive):PSI_SEL.H PP")
	field(LNK9, "$(dev,recursive):PSI_SEL.I PP")
	field(LNKA, "$(dev,recursive):PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "$(dev,recursive):PSI_CTRL NPP NMS")
}

# The $[parm]_SEL record holds all possible
# values of $[parm] in the 'A..J' fields.
#
# When processed it updates it's own VAL
# to the currently selected input. Input
# 'L' serves as the (1-based) selector,
# i.e., L==1 selects 'A'->'VAL'.
# 
# When the selected value changes (as a 
# result of SEQ depositing a new value OR
# $[ctrl] changing and updating L) then
# the propagator record attached to the
# FLNK is processed.
#

record(sub, "$(dev,recursive):PSI_SEL")
{
#	field(INAM, "parmSelSubInit")
	field(SNAM, "parmSelSubProc")
	field(A,    "90")
	field(B,    "90")
	field(C,    "")
	field(D,    "")
	field(E,    "")
	field(F,    "")
	field(G,    "")
	field(H,    "")
	field(I,    "")
	field(J,    "")
	field(PREC, "1")
	field(FLNK, "$(dev,recursive):PSI_PROP")
  	info(autosaveFields, "A B C D E F G H I J")
}

#
# Finally the dfanout record 
# fetches the currently selected
# value from SEL and propagates it
# to $[outl]. It also updates
# $[parm] itself so that $[parm]
# always reflects the currently
# selected value.
#
record(dfanout,  "$(dev,recursive):PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "$(dev,recursive):PSI_SEL")
	field(OUTA, "$(dev,recursive):CALC.F CA")
	field(OUTB, "$(dev,recursive):PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "$(dev,recursive):PSI_CTRL")
{
	field(INPA, "$(dev,recursive):PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "$(dev,recursive):PSI_SEL.L PP")
}
record(longout, "$(dev,recursive):PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
# Consider uncommenting CAL_SOFTTRIG 
# during testing
#record(ao, "$(dev,undefined):CAL_SOFTTRIG") {
#  field(DESC, "")
#  field(DTYP, "bpmAlgParm")
#  field(OUT,  "#C$(pad,undefined)S0@SoftTrig")
#  field(VAL,  "0")
#  field(PINI, "NO")
#}

record(aSub, "$(dev,undefined):GRU_SUB") {
  field(DESC, "Calculate and push stripl cal parms")
  field(INAM, "subBpmParmsInit")
  field(SNAM, "subBpmCalParms")
# Process when input(s) change
  field(SCAN, "Passive")
# Inputs
  field(FTA,  "DOUBLE")
  field(INPA, "$(dev,undefined):GRU CPP")
  field(FTB,  "SHORT")
  field(INPB, "$(dev,undefined):GRU.SEVR CPP")
# Calculated results:
# GRU delta (GRU-1):
  field(FTVA, "DOUBLE")
  field(OUTA, "$(dev,undefined):GRU_DELTA PP")
  field(ASG,  "Internal")
}

record(aSub, "$(dev,undefined):GRV_SUB") {
  field(DESC, "Calculate and push stripl cal parms")
  field(INAM, "subBpmParmsInit")
  field(SNAM, "subBpmCalParms")
# Process when input(s) change
  field(SCAN, "Passive")
# Inputs
  field(FTA,  "DOUBLE")
  field(INPA, "$(dev,undefined):GRV CPP")
  field(FTB,  "SHORT")
  field(INPB, "$(dev,undefined):GRV.SEVR CPP")
# Calculated results:
# GRV delta (GRV-1):
  field(FTVA, "DOUBLE")
  field(OUTA, "$(dev,undefined):GRV_DELTA PP")
  field(ASG,  "Internal")
}

record(ao, "$(dev,undefined):GRU_DELTA") {
  field(DESC, "GRU-1")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@DeltaCal_RED")
  field(VAL,  "0")
  field(PREC, "4")
  field(DRVL, "0")
  field(DRVH, "1.99999")
  field(LOLO, "-.00001")
  field(LLSV, "MAJOR")
  field(HIHI, "1.99999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
# Only CAL_PARMS_SUB should set this
  field(ASG,  "NOWRITE")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):GRV_DELTA") {
  field(DESC, "GRV-1")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@DeltaCal_GRN")
  field(VAL,  "0")
  field(DRVL, "0")
  field(DRVH, "1.99999")
  field(LOLO, "-.00001")
  field(LLSV, "MAJOR")
  field(HIHI, "1.99999")
  field(HHSV, "MAJOR")
  field(PREC, "4")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
# Only CAL_PARMS_SUB should set this
  info(autosaveFields, "VAL")  
}

# Alarm summary for FW setpoint ranges
record(aSub, "$(dev,undefined):FWLIMSUB") {
  field(DESC, "FW setpoints within range")
  field(INAM, "subBpmParmsInit")
  field(SNAM, "subBpmMask")
  field(SCAN, "1 second")
# Inputs
  field(FTA,  "USHORT")
  field(INPA, "$(dev,undefined):A11.SEVR CPP")
  field(FTB,  "USHORT")
  field(INPB, "$(dev,undefined):A12.SEVR CPP")
  field(FTC,  "USHORT")
  field(INPC, "$(dev,undefined):A21.SEVR CPP")
  field(FTD,  "USHORT")
  field(INPD, "$(dev,undefined):A22.SEVR CPP")
  field(FTE,  "USHORT")
  field(INPE, "$(dev,undefined):OFF1.SEVR CPP")
  field(FTF,  "USHORT")
  field(INPF, "$(dev,undefined):OFF2.SEVR CPP")
  field(FTG,  "USHORT")
  field(INPG, "$(dev,undefined):QSCLFWINT.SEVR CPP")
  field(FTH,  "USHORT")
  field(INPH, "$(dev,undefined):GRU_DELTA.SEVR CPP")
  field(FTI,  "USHORT")
  field(INPI, "$(dev,undefined):GRV_DELTA.SEVR CPP")
# Output
  field(FTVA, "LONG")
  field(OUTA, "$(dev,undefined):FWLIMSTAT PP")
  field(ASG,  "Internal")
}

record(longin, "$(dev,undefined):FWLIMSTAT") {
  field(DESC, "FW setpoints within range")
  field(INP,  "$(dev,undefined):FWLIMSUB.VALA")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG,  "NOWRITE")
}
#=======================================
# Calculate algorithm parameters and
# various scale factors
#=======================================
# Used by ALG_PARMS_SUB
# May later be consolidated in some way 
record(ao, "$(dev,undefined):XY_FWSCLMULT") {
  field(DESC, "Multiplier in X/Y FW scaling")
  field(OMSL, "supervisory")
  field(VAL,  "0.25")
  field(PREC, "3")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
  info(autosaveFields, "VAL")  
}
record(aSub, "$(dev,undefined):ALG_PARMS_SUB") {
  field(DESC, "Calculate and push BPM alg parms")
  field(INAM, "subBpmParmsInit")
  field(SNAM, "subBpmAlgParms")
# Process when input(s) change
  field(SCAN, "Passive")
# Inputs:
  field(FTA,  "DOUBLE")
  field(INPA, "$(dev,undefined):PSI CPP")
  field(FTB,  "DOUBLE")
  field(INPB, "$(dev,undefined):PHI CPP")
  field(FTC,  "DOUBLE")
  field(INPC, "$(dev,undefined):U.ASLO CPP")
  field(FTD,  "DOUBLE")
  field(INPD, "$(dev,undefined):U.AOFF CPP")
  field(FTE,  "DOUBLE")
  field(INPE, "$(dev,undefined):V.ASLO CPP")
  field(FTF,  "DOUBLE")
  field(INPF, "$(dev,undefined):V.AOFF CPP")
  field(FTG,  "DOUBLE")
  field(INPG, "$(dev,undefined):X.ASLO CPP")
  field(FTH,  "DOUBLE")
  field(INPH, "$(dev,undefined):X.AOFF CPP")
  field(FTI,  "DOUBLE")
  field(INPI, "$(dev,undefined):Y.ASLO CPP")
  field(FTJ,  "DOUBLE")
  field(INPJ, "$(dev,undefined):Y.AOFF CPP")
# Scale X/Y alg parms by (USCL/2/K)
  field(FTK,  "DOUBLE")
  field(INPK, "$(dev,undefined):XY_FWSCLMULT CPP")
# Calculated results:
# Rotation matrix element A11:
  field(FTVA, "DOUBLE")
  field(OUTA, "$(dev,undefined):A11 PP")
# Rotation matrix element A12:
  field(FTVB, "DOUBLE")
  field(OUTB, "$(dev,undefined):A12 PP")
# Rotation matrix element A21:
  field(FTVC, "DOUBLE")
  field(OUTC, "$(dev,undefined):A21 PP")
# Rotation matrix element A22:
  field(FTVD, "DOUBLE")
  field(OUTD, "$(dev,undefined):A22 PP")
# U->X transformation offset:
  field(FTVE, "DOUBLE")
  field(OUTE, "$(dev,undefined):OFF1 PP")
# V->Y transformation offset:
  field(FTVF, "DOUBLE")
  field(OUTF, "$(dev,undefined):OFF2 PP")
  field(FTVG, "DOUBLE")
  field(OUTG, "$(dev,undefined):X_FWSCL PP")
  field(FTVH, "DOUBLE")
  field(OUTH, "$(dev,undefined):Y_FWSCL PP")
# J, K contain unscaled X, Y
# scale factors (e.g. X_FWSCL*2^17)
  field(FTVJ, "DOUBLE")
  field(FTVK, "DOUBLE")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):A11")
}

#=======================================
# BPM rotation matrix and offsets
#=======================================
record(ao, "$(dev,undefined):A11") {
  field(DESC, "U/V->X/Y matrix elem 11")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@A11")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALA")
  field(VAL,  "1")
  field(PREC, "4")
  field(DRVL, "-1.9999")
  field(DRVH, "1.9999")
  field(LOLO, "-1.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "1.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):A12")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):A12") {
  field(DESC, "U/V->X/Y matrix elem 12")
  field(DTYP, "bpmAlgParm")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALB")
  field(OUT,  "#C$(pad,undefined)S0@A12")
  field(VAL,  "0")
  field(PREC, "4")
  field(DRVL, "-1.9999")
  field(DRVH, "1.9999")
  field(LOLO, "-1.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "1.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):A12")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):A21") {
  field(DESC, "U/V->X/Y matrix elem 21")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@A21")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALC")
  field(VAL,  "0")
  field(PREC, "4")
  field(DRVL, "-1.9999")
  field(DRVH, "1.9999")
  field(LOLO, "-1.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "1.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):A22")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):A22") {
  field(DESC, "U/V->X/Y matrix elem 22")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@A22")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALD")
  field(VAL,  "1")
  field(PREC, "4")
  field(DRVL, "-1.9999")
  field(DRVH, "1.9999")
  field(LOLO, "-1.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "1.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):OFF1")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):OFF1") {
  field(DESC, "U->X offset")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@O_1")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALE")
  field(VAL,  "0")
  field(PREC, "4")
  field(DRVL, "-127.9999")
  field(DRVH, "127.9999")
  field(LOLO, "-127.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "127.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):OFF2")
  info(autosaveFields, "VAL")  
}
record(ao, "$(dev,undefined):OFF2") {
  field(DESC, "V->Y offset")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@O_2")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALF")
  field(VAL,  "0")
  field(PREC, "4")
  field(DRVL, "0")
  field(DRVL, "-127.9999")
  field(DRVH, "127.9999")
  field(LOLO, "-127.9999")
  field(LLSV, "MAJOR")
  field(HIHI, "127.9999")
  field(HHSV, "MAJOR")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):X_FWSCL")
  info(autosaveFields, "VAL")  
}

#=======================================
# Scale factors for converting 
# to/from FW data types and units
# Used by software and other clients
#=======================================
record(ao, "$(dev,undefined):X_FWSCL") {
  field(DESC, "Scales X FW raw to mm")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALG")
  field(VAL,  "1")
  field(PREC, "10")
  field(EGU,  "mm/raw")
  field(PINI, "YES")
  field(ASG,  "Internal")
  field(FLNK,  "$(dev,undefined):X_FWSCLFO")
  info(autosaveFields, "VAL")  
}
record(dfanout, "$(dev,undefined):X_FWSCLFO") {
  field(DESC, "Scales X FW raw to mm")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):X_FWSCL MS")
  field(OUTA,  "$(dev,undefined):XF.ASLO")
# Push to BSA slope PV
  field(OUTB,  "$(dev,undefined):X_SLOPE PP")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):Y_FWSCL")
}

record(ao, "$(dev,undefined):Y_FWSCL") {
  field(DESC, "Scales Y FW raw to mm")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):ALG_PARMS_SUB.VALH")
  field(VAL,  "1")
  field(PREC, "10")
  field(EGU,  "mm/raw")
  field(PINI, "YES")
  field(FLNK, "$(dev,undefined):Y_FWSCLFO")
  field(ASG,  "Internal")
  info(autosaveFields, "VAL")  
}
record(dfanout, "$(dev,undefined):Y_FWSCLFO") {
  field(DESC, "Scales Y FW raw to mm")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):Y_FWSCL MS")
  field(OUTA,  "$(dev,undefined):YF.ASLO")
# Push to BSA slope PV
  field(OUTB,  "$(dev,undefined):Y_SLOPE PP")
# Only ALG_PARMS_SUB should set this
  field(ASG,  "Internal")
}

record(ao, "$(dev,undefined):NC2NEL") {
  field(DESC, "nC to Nel")
  field(VAL,  "6241509128.99977")
  field(DOL,  "closed_loop")
  field(PINI, "YES")
  field(ASG,  "NOREAD")
  field(FLNK, "$(dev,undefined):SCLR17")
}
record(ao, "$(dev,undefined):SCLR17") {
  field(DESC, "2^17")
  field(VAL,  ".00000762939453125")
  field(DOL,  "closed_loop")
  field(PINI, "YES")
  field(OUT,  "$(dev,undefined):CHRG_FWSCL PP")
  field(ASG,  "NOREAD")
  field(FLNK, "$(dev,undefined):TMIT_FWSCL_CALC")
}
record(ao, "$(dev,undefined):CHRG_FWSCL") {
  field(DESC, "FW fixed nC to floating nC")
  field(OMSL, "closed_loop")
# BSA needs to divide by 1/2^17
  field(DOL,  "$(dev,undefined):SCLR17")
  field(EGU,  "nC/raw")
  field(PREC, "5")
  field(PINI, "YES")
# Push to BSA slope PV
  field(FLNK,  "$(dev,undefined):CHRG_FWSCLFO")
  field(ASG,  "Internal")
}
record(dfanout, "$(dev,undefined):CHRG_FWSCLFO") {
  field(DESC, "FW fixed nC to floating nC")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):CHRG_FWSCL MS")
  field(OUTA, "$(dev,undefined):CHRGF.ASLO")
# Push to BSA slope PV
# Decided not to implement CHRG BSA
# signal on first implementation, so
# comment out
#  field(OUTB,  "$(dev,undefined):CHRG_SLOPE PP")
  field(ASG,  "Internal")
}

record(calc, "$(dev,undefined):TMIT_FWSCL_CALC") {
  field(DESC, "Fixed-point FW nC to Nel")
  field(CALC, "A*B")
  field(INPA, "$(dev,undefined):NC2NEL")
  field(INPB, "$(dev,undefined):SCLR17")
  field(FLNK, "$(dev,undefined):TMIT_FWSCL")
  field(ASG,  "Internal")
}
record(ao, "$(dev,undefined):TMIT_FWSCL") {
  field(DESC, "Fixed-point FW nC to Nel")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):TMIT_FWSCL_CALC")
  field(VAL,  "1")
  field(PREC, "10")
  field(EGU,  "Nel/nC")
# Push to BSA slope PV
  field(OUT,  "$(dev,undefined):TMIT_SLOPE PP")
  field(ASG,  "Internal")
  field(FLNK, "$(dev,undefined):QSCLFW")
}

#=======================================
# TMIT threshold below which there is not
# enough signal to calculate X/Y and 
# thus X/Y are considered invalid.
# Register is in nC, convert to/from Nel
# for user interface PVs
#=======================================
record(ao, "$(dev,undefined):TMITTHRES") {
  field(DESC, "TMIT thres below which X/Y invalid")
  field(OMSL, "supervisory")
  field(VAL,  "1")
  field(EGU,  "Nel")
  field(PREC, "3")
  field(PINI, "YES")
  field(FLNK, "$(dev,undefined):TMITTHRES_CALC")
  info(autosaveFields, "VAL")  
}
record(calc, "$(dev,undefined):TMITTHRES_CALC") {
  field(DESC, "Convert TMIT thres Nel to nC")
  field(CALC, "A/B")
  field(INPA, "$(dev,undefined):TMITTHRES MS")
  field(INPB, "$(dev,undefined):NC2NEL")
  field(FLNK, "$(dev,undefined):TMITTHRESGO")
  field(ASG,  "Internal")
}
record(ao, "$(dev,undefined):TMITTHRESGO") {
  field(DESC, "TMIT thres below which X/Y invalid")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@TmitThreshold")
  field(PREC, "3")
  field(OMSL, "closed_loop")
  field(DOL,  "$(dev,undefined):TMITTHRES_CALC MS")
  field(EGU,  "nC")
}

record(ai, "$(dev,undefined):TMITTHRESRB_RAW") {
  field(DESC, "TMIT thres below which X/Y invalid")
  field(SCAN, "1 second")
  field(DTYP, "bpmAlgParm")
  field(EGU,  "nC")
  field(INP,  "#C$(pad,undefined)S0@TmitThreshold")
  field(FLNK, "$(dev,undefined):TMITTHRESRB_CALC")
}
record(calc, "$(dev,undefined):TMITTHRESRB_CALC") {
  field(DESC, "Convert TMIT thres nC to Nel")
  field(CALC, "A*B")
  field(INPA, "$(dev,undefined):TMITTHRESRB_RAW MS")
  field(INPB, "$(dev,undefined):NC2NEL")
  field(FLNK, "$(dev,undefined):TMITTHRESRB")
  field(ASG,  "Internal")
}
record(ai, "$(dev,undefined):TMITTHRESRB") {
  field(DESC, "TMIT thres below which X/Y invalid")
  field(INP,  "$(dev,undefined):TMITTHRESRB_CALC MS")
  field(PREC, "3")
  field(EGU,  "Nel")
}

#=======================================
# TMIT 'fudge' factor used to force 
# BPM TMIT to match 'known' TMIT
#=======================================
record(ao, "$(dev,undefined):QSCLFW") {
  field(DESC, "FW TMIT raw to Nel")
  field(OMSL, "supervisory")
  field(VAL,  "47619")
  field(PREC, "4")
  field(DRVL, "0")
  field(LOLO, "0")
  field(LLSV, "MAJOR")
  field(HIHI, "95234")
  field(HHSV, "MAJOR")
  field(FLNK, "$(dev,undefined):QSCLFWINT_CALC")
  info(autosaveFields, "VAL")  
}
record(calc, "$(dev,undefined):QSCLFWINT_CALC") {
  field(DESC, "Calc QSCL for FW reg")
  field(CALC, "A/B")
  field(INPA, "$(dev,undefined):QSCLFW")
  field(INPB, "$(dev,undefined):TMIT_FWSCL")
  field(FLNK, "$(dev,undefined):QSCLFWINT")
  field(ASG,  "Internal")
}
record(ao, "$(dev,undefined):QSCLFWINT") {
  field(DESC, "FW TMIT raw to nC")
  field(DTYP, "bpmAlgParm")
  field(OUT,  "#C$(pad,undefined)S0@TmitScl")
  field(DOL,  "$(dev,undefined):QSCLFWINT_CALC")
  field(OMSL, "closed_loop")
  field(VAL,  "1")
  field(PREC, "4")
  field(DRVL, "0")
  field(DRVH, "1.9999")
  field(LOLO, "0")
  field(LLSV, "MAJOR")
  field(HIHI, "1.9999")
  field(HHSV, "MAJOR")
  field(ASG,  "Internal")
}

#=======================================
# Firmware-calculated X,Y,charge
# Scale factors (FW Raw -> EGU) stored in ASLO. 
# Set by ALG_PARMS_SUB via FWSCL PVs
#=======================================
record(ai, "$(dev,undefined):XF") {
  field(DESC, "Scaled X from FW")
  field(SCAN, "I/O Intr")
  field(DTYP, "bpmSig")
  field(INP, "#C$(pad,undefined)S0")
  field(TSE, "-2")
  field(PREC, "4")
  field(LINR, "LINEAR")
  field(EGU,  "mm")
  field(LOPR, "-12")
  field(HOPR, "12")
  field(FLNK, "$(dev,undefined):YF")
  field(ASG,  "NOWRITE")
}
record(ai, "$(dev,undefined):YF") {
  field(DESC, "Scaled Y from FW")
  field(DTYP, "bpmSig")
  field(INP, "#C$(pad,undefined)S1")
  field(TSE, "-2")
  field(PREC, "4")
  field(EGU,  "mm")
  field(LINR, "LINEAR")
  field(LOPR, "-12")
  field(HOPR, "12")
  field(FLNK, "$(dev,undefined):CHRGF")
  field(ASG,  "NOWRITE")
}
record(ai, "$(dev,undefined):CHRGF") {
  field(DESC, "Scaled TMIT [nC] from FW")
  field(DTYP, "bpmSig")
  field(INP, "#C$(pad,undefined)S2")
  field(TSE, "-2")
  field(PREC, "3")
  field(LINR, "LINEAR")
  field(ASLO, "1")
  field(LOPR, "0")
  field(HOPR, "1.6022")
  field(EGU,  "nC")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
  field(FLNK, "$(dev,undefined):TMITF_CALC")
  field(ASG,  "Internal")
}
record(calc, "$(dev,undefined):TMITF_CALC") {
  field(CALC, "A*B")
  field(INPA, "$(dev,undefined):CHRGF")
  field(INPB, "$(dev,undefined):NC2NEL")
  field(FLNK, "$(dev,undefined):TMITF")
  field(ASG,  "NOWRITE")
}
record(ai, "$(dev,undefined):TMITF") {
  field(DESC, "Scaled TMIT from FW")
  field(INP, "$(dev,undefined):TMITF_CALC")
  field(PREC, "3")
  field(EGU,  "Nel")
  field(LOPR, "0")
  field(HOPR, "1e+11")
  field(FLNK, "$(dev,undefined):RSTA_FW")
  field(ASG,  "NOWRITE")
}
record(ai, "$(dev,undefined):RSTA_FW") {
  field(DESC, "Status word from FW")
  field(DTYP, "bpmSig")
  field(INP,  "#C$(pad,undefined)S3")
  field(LINR, "LINEAR")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
}

record(ai, "$(dev,undefined):CHRGDISP") {
  field(DESC, "CHRG snapshot for display")
  field(SCAN, "1 second")
  field(INP, "$(dev,undefined):CHRGF NPP MS")
  field(EGU, "nC")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.5")
}

#=======================================
# Firmware configuration info
#=======================================
record(mbbi, "$(dev,undefined):FWTYPE") {
  field(DESC, "FW mode")
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@FirmwareConfiguration")
  field(ZRST, "Stripline")
  field(ZRVL, "0")
  field(ONST, "Cavity")
  field(ONVL, "1")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
}
# RTM type for which FW was configured
record(mbbi, "$(dev,undefined):RTMTYPE") {
  field(DESC, "FW mode")
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@FirmwareConfigurationRTM")
  field(ZRST, "None")
  field(ZRVL, "0")
# Digital debug version 1
  field(ONST, "DDV1")
  field(ONVL, "1")
# Digital debug version 2
  field(TWST, "DDV2")
  field(TWVL, "2")
  field(PINI, "YES")
  field(ASG,  "NOWRITE")
}

#=======================================
# Diagnostic control/readback of channel
# multiplexer settings. Correct values
# should be set by defaults yaml file
#=======================================
record(ao, "$(dev,undefined):MUXGRN") {
  field(DTYP, "bpmAlgParm")
  field(OMSL, "supervisory")
  field(OUT,  "#C$(pad,undefined)S0@MuxGRN")
}
record(ao, "$(dev,undefined):MUXRED") {
  field(DTYP, "bpmAlgParm")
  field(OMSL, "supervisory")
  field(OUT,  "#C$(pad,undefined)S0@MuxRED")
}
record(ao, "$(dev,undefined):MUXBLU") {
  field(DTYP, "bpmAlgParm")
  field(OMSL, "supervisory")
  field(OUT,  "#C$(pad,undefined)S0@MuxBLU")
}
record(ao, "$(dev,undefined):MUXYLO") {
  field(DTYP, "bpmAlgParm")
  field(OMSL, "supervisory")
  field(OUT,  "#C$(pad,undefined)S0@MuxYLO")
}
record(ai, "$(dev,undefined):MUXGRNRB") {
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@MuxGRN")
  field(SCAN, "10 second")
}
record(ai, "$(dev,undefined):MUXREDRB") {
  field(SCAN, "10 second")
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@MuxRED")
}
record(ai, "$(dev,undefined):MUXBLURB") {
  field(SCAN, "10 second")
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@MuxBLU")
}
record(ai, "$(dev,undefined):MUXYLORB") {
  field(SCAN, "10 second")
  field(DTYP, "bpmAlgParm")
  field(INP,  "#C$(pad,undefined)S0@MuxYLO")
}

# Temporary--move to carrier db
# Hard-coded to point to carrier 0

#=======================================
# *Temporary location* - these records
# are per-carrier, not per-BPM, so need
# to be moved to per-carrier database.
# Diagnostic control/readback of IP/port
# settings used to send data to client
# along backplane. (For gun system,
# used to send MPS data to BCM card.)
# Correct values should be set by 
# client.yaml file
#=======================================
record(longin, "$(dev,undefined):CLIENTIPRB") {
  field(DESC, "Backplane client IP")
  field(DTYP, "bpmCpCarrier")
  field(SCAN, "1 second")
  field(INP,  "#C0S0@ClientRemoteIp")
}

record(longout, "$(dev,undefined):CLIENTIP") {
  field(DESC, "Backplane client IP")
  field(DTYP, "bpmCpCarrier")
  field(OMSL, "supervisory")
  field(OUT,  "#C0S0@ClientRemoteIp")
  field(PINI, "NO")
}

record(longin, "$(dev,undefined):CLIENTPORTRB") {
  field(DESC, "Backplane client port")
  field(DTYP, "bpmCpCarrier")
  field(SCAN, "1 second")
  field(INP,  "#C0S0@ClientRemotePort")
}
# bpmAfe.db; database for controlling stripline-BPM AFE
# This database should not be loaded on PADs w/o AFE hardware.
#
# THIS FILE WAS GENERATED WITH msi FROM bpmPadAfe.template or bpmVmeDigiAfe.db AND EXPANDED FOR
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#  MODE: a -- Use VME IOC PVs
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# NOTE: The template can be configured by means of proper macro
#       substitutions to 
#        a) operate in 'normal' LCLS stripline BPM mode. In this
#           mode a few CA links to the VME/main IOC are active fetching
#           '$(dev):ACCESS', '$(dev):ATTO' and '$(dev):CLAO' from the
#           main IOC.
#
#        b) standalone mode. In this mode, ACCESS is ignored and 'ATTO' and
#           'CLAO' are instantiated / hosted on the PAD IOC.
#
#        Mode 'a' is chosen by substituting
#        	  'suffix' ='L',
#        	'propomsl' = 'closed_loop'
#        	 'attomsl' = 'supervisory'
#        	   'chrgL' = '<charge PV> CPP'
#        	   'actlL' = '$(dev):ACCESS.RVAL CP'
#        	   'attoL' = '$(dev):ATTO CP'
#        	   'claoL' = '$(dev):CLAO CP'
#
#        Mode 'b' is chosen by substituting
#             'suffix' = '' (empty)
#        	'propomsl' = 'supervisory'
#        	 'attomsl' = 'supervisory'
#        	   'chrgL' = '0'
#        	   'actlL' = '0'
#        	   'attoL' = '0'
#        	   'claoL' = '0'
#
# SUBSTITUTIONS:
#  Substitutions available in main .db file
#    'dev' : device name prefix
#   'chrg' : name of global attenuator PV (for scaling all AFE attenuators with beam charge)(mode a) or '0' (mode b)
#            'chrg' is only available in mode 'a'.
#
#  Substitutions available in the template -- intended to be expanded when generating '.db' with MSI.
#
#  'chrgL' : name of global attenuator PV (for scaling all AFE attenuators with beam charge) + CPP attribute (mode a) or '0' (mode b)
#  'actlL' : name of ACCESS.RVAL PV + CP attribute (mode a) or '0' (mode b)
#  'attoL' : name of ATTO PV + CP attribute (mode a) or '0' (mode b)
#  'claoL' : name of CLAO PV + CP attribute (mode a) or '0' (mode b)
#'attomsl' : default/initial OMSL; if 'supervisory' then the 'ATT' PV controls attenuators
#            if 'closed_loop' then ATT is fetched from it's DOL (=='chrg' PV).
# 'suffix' : see above.
#'propomsl': see above.
#
# LINKS (pointing outside of this file): These links are only used in mode a and set to '0' in mode b.
#     $(dev,recursive):ATT.DOL  <---- $(chrg,recursive) CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     $(dev,recursive):ACTL.DOL <---- $(dev,recursive):ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     $(dev,recursive):ATTOL.DOL<---- $(dev,recursive):ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     $(dev,recursive):CLAOL.DOL<---- $(dev,recursive):CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

record(longout, "$(dev,recursive):CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

record(longout, "$(dev,recursive):ATT1") {
	field(DESC, "AFE Att. 1")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+2,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "15")
	field(DRVL, "0")
	field(DRVH, "15")
	field(EGU,  "dB")
}

record(longout, "$(dev,recursive):ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+3,qspiAfe")
	field(EGU,  "dB")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "0")
	field(DRVH, "31")
	field(EGU,  "dB")
}

# AFE FW versions (decimal):
# 4     original LCLS-I FW version
# >=32  ATT2 has 32 dB range; before 16 dB
# 33    200 MHz board
# 34    140 MHz board w/ 6dB PAD removed
# 35    200 MHz board w/ 6dB PAD removed
# > 64  140 MHz board not used with PAD/coldfire (XTA)
# 8     MicroTCA RTM
record(longin, "$(dev,recursive):VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE$(pad,undefined)+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "$(dev,recursive):ATTINIT")
}

record(longout, "$(dev,recursive):AODL") {
	field(DESC, "Delay Trig -> AMP On")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x10,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVL, "255")
}

record(longout, "$(dev,recursive):R1DL") {
	field(DESC, "Delay AMP On -> RF1")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x11,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVL, "255")
}

record(longout, "$(dev,recursive):RFWD") {
	field(DESC, "RF Pulse Width")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x13,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVL, "255")
	info(autosaveFields, "VAL")
}

record(longout, "$(dev,recursive):OFFT") {
	field(DESC, "Delay RF Off -> Ctrl Sw.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x14,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVL, "255")
}

record(longout, "$(dev,recursive):R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x12,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVL, "255")
}

# This record just issues a CAL trigger
record(longout, "$(dev,recursive):CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE$(pad,undefined)+6,qspiAfe")
}

record(mbbo,   "$(dev,recursive):CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE$(pad,undefined)+0,softTogAfe")
        field(NOBT, "2")
        field(SHFT, "0")
        field(ZRST, "CAL RED")
        field(ZRVL, "0")
        field(ONST, "CAL GRN")
        field(ONVL, "1")
        field(THST, "CAL NONE")
        field(THVL, "3")
# 'soft toggle' mode. NOTE: LSB must match RED or GRN
# which choses the mode to start with
        field(FRST, "CAL TOGGLE")
        field(FRVL, "4")
        field(VAL,  "4")
        field(PINI, "YES")
}

# Subroutine to set up attenuator limits at ioc startup.
# Attenuator ranges vary among AFE types and FW versions
# This record also in bpmVmeDigiAfePart.db
record(aSub, "$(dev,recursive):ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "$(dev,recursive):VERS")
        field(FTVA, "LONG")
        field(OUTA, "$(dev,recursive):ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "$(dev,recursive):ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "$(dev,recursive):ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "$(dev,recursive):ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "$(dev,recursive):ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "$(dev,recursive):ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "$(dev,recursive):ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "$(dev,recursive):ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "$(dev,recursive):ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "$(dev,recursive):ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "$(dev,recursive):ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "$(dev,recursive):ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "$(dev,recursive):ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "$(dev,recursive):ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "$(dev,recursive):CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "$(dev,recursive):CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "$(dev,recursive):CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "$(dev,recursive):CLAO.HOPR")
        field(FLNK, "$(dev,recursive):ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "$(dev,recursive):ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "$(dev,recursive):ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "$(chrg,recursive) CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

# This subroutine record performs the
# following operation (ATTC.D defines
# the breakpoint where ATT1 kicks in 
# -- it depends on losses and gains:
#    BPT = G1 + L1 - L2
# with
#  G1: gain of 1st stage,
#  L1: loss + NF upstream of 1st stage,
#  L2: loss between 1st and 2nd stage + NF of 2nd stage
#
# if L1 : 2dB cable, 3dB 1st Filter, 1dB Att1 residual, 2.8dB NF =  8.8dB
#    L2 : 1dB Att2 residual, 4.5dB BPF, 3dB NF                   =  8.5dB
#    G1 :                                                        = 20.0dB
#
# -> breakpoint ~ 20dB
#
#-----------------------------------------------------------------------------
# New RTM AFE characteristics are different (assume 140 ft LMR: 2.2db/100ft):
#    L1 : 3.1 dB cable, 4.5 dB 1st BPF, 1.1 dB att1, 3.3dB NF    = 12.0dB
#    L2 : 1.1 dB att2, 2.7 dB NF, 1 dB BPF                       =  4.8dB
#    G1 :                                                        = 16.0dB
#
# -> breakpoint ~ 23dB
#
#-----------------------------------------------------------------------------
#
# Semantics of the different fields
#  A: Total attenuation (ATT records deposits value there)
#  B: ATTO
#  C: CLAO
#  D: BPT Breakpoint (see above)
#  E: (ATT1MAX) max. ATT1 attenuation (depends on version, set by ATTINIT)
#  F: (ATT2MAX) max. ATT2 attenuation (depends on version, set by ATTINIT)
#
# if ( (T=ATT+ATTO) > ATT1MAX + ATT2MAX )
#    T = ATT1MAX + ATT2MAX
# endif
#
# if ( (A1 = floor((T - BPT)/2)) < 0 )
#    A1 = 0;
#    A2 = T;
# else
#    if (A1 > ATT1MAX) 
#      A1 = ATT1MAX;
#    endif
#    A2 = T - A1
# endif
#
# if ( A2 > ATT2MAX )
#    A1 = A2-ATT2MAX
#    A2 = ATT2MAX
# endif
#
#    CA = CLAO + ATT1MAX + ATT2MAX - ATT
# if ( CA < 0 )
#    CA = 0
# else if ( CA > ACMAX )
#    CA = ACMAX
# endif
#
# Then, it writes three links:
#  $(dev,recursive):ATT1 = A1
#  $(dev,recursive):ATT2 = A2
#  $(dev,recursive):CALA = CA
#

record(sub, "$(dev,recursive):ATTC") {
	# Note: this record uses it's name to calculate
	# db link addresses to ATT1, ATT2, CALA
	field(DESC, "AFE Total Att. Calc.")
	# initialize fields to max. attenuation:
	# During init:
	#    1. hw initializes to max
	#    2. this record holds max
	#    3. PINI of the placeholder PVs (ATT, ATTO & friends)
	#       trickle in and cause the total attenuation to
	#       go down...
	field(A,    "30")
	field(B,    "0")
	field(C,    "60")
	field(D,    "20")
	field(EGU,  "dB")
	field(INAM, "subAttIni")
	field(SNAM, "subAtt")
}

#propagate 'ACCESS.RVAL' state to 
#attenuator control
#This record is unused in stdalone mode 'b'
record(bo, "$(dev,recursive):ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "$(dev,recursive):ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "$(dev,recursive):ATT.OMSL PP")
}

###
### Keep 'ATTO' and 'CLAO' on the main/VME IOC.
### It is more confusing but then we don't have
### to restore anything across reboots on the PAD
### IOC...
###
### This db now used for AFEs controlled by either
### a VME IOC or a PAD IOC. Use the same db for 
### both for simplicity.
###
### NOTE: We could use the INPB / INPC
###       links of ATTC directly but we DONT.
###       Potentially, ATTC can be processed
###       on every shot -- we don't want the
###       links to be fetched every time for
###       efficiency reasons. Hence the 'propagator'
###       records which monitor ATTO/CLAO and
###       write to ATTC.B ATTC.C only when
###       necessary...
record(longout, "$(dev,recursive):ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "$(dev,recursive):ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "$(dev,recursive):ATTC.B PP")
	field(EGU,  "dB")
}

record(longout, "$(dev,recursive):CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "$(dev,recursive):CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "$(dev,recursive):ATTC.C PP")
	field(EGU,  "dB")
}
# Records only needed for RTM AFE

record(longout, "$(dev,recursive):TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x15,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVH, "255")
	field(PINI, "YES")
	info(autosaveFields, "VAL")
}

record(longout, "$(dev,recursive):RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x16,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVH, "255")
	field(VAL,  "6")
	field(PINI, "YES")
	info(autosaveFields, "VAL")
}

record(longout, "$(dev,recursive):RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE$(pad,undefined)+0x17,qspiAfe")
	field(EGU,  "33ns")
	field(LOPR, "1")
	field(DRVL, "1")
	field(HOPR, "255")
	field(DRVH, "255")
	field(VAL,  "6")
	field(PINI, "YES")
	info(autosaveFields, "VAL")
}
