# per IOC database for stripline BPMs

#record(sub, "VIOC:DF2H:BPM:FIDP") {
#	field(DESC, "BPM Fiducial Processing")
#	field(SNAM, "bpmEvrFidProcess")
#	#This tells us if there is beam during this cycle...
#	field(INPA, "VIOC:DF2H:BPM:MODIFIER5.R")
#}

#record(mbbo, "VIOC:DF2H:BPM:PATTERNSIM") {
#	field(DESC, "Pattern Simulation")
#	field(ZRST, "Off")
#	field(ONST, "Soft")
#	field(TWST, "Raw")
#	field(DOL,  "0")
#	field(PINI, "YES")
#}

record(sub, "VIOC:DF2H:BPM:EVTM") {
	field(SNAM, "subEventTestTiming")
	field(SCAN, "Event")
	field(EVNT, "40")
}

#! 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, "HL3B:SBPM:HL51:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C0 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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C0 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C0 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C0 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, "HL3B:SBPM:HL51:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C0 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:SBPM:HL51: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, "#C0 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:SBPM:HL51: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, "#C0 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, "HL3B:SBPM:HL51: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, "#C0 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, "HL3B:SBPM:HL51: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, "#C0 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, "HL3B:SBPM:HL51: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, "#C0 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(ao, "HL3B:SBPM:HL51:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL51:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:SBPM:HL51:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:SBPM:HL51:ATT1 CP")
  field(INPC, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:SBPM:HL51:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL51:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL51:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:SBPM:HL51:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:SBPM:HL51:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL51:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:SBPM:HL51:Y.SEVR    MS NPP")
  field(INPD, "HL3B:SBPM:HL51:X.SEVR    MS NPP")
  field(INPE, "HL3B:SBPM:HL51:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:SBPM:HL51:TRED.SEVR MS NPP")
  field(INPG, "HL3B:SBPM:HL51:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:SBPM:HL51:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:SBPM:HL51:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:SBPM:HL51:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL51:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:SBPM:HL51:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:SBPM:HL51:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:SBPM:HL51:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:SBPM:HL51:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL51:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL51:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "0")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:SBPM:HL51:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C0S0")
  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, "HL3B:SBPM:HL51:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 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, "HL3B:SBPM:HL51:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:SBPM:HL51:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:SBPM:HL51:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:SBPM:HL51:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C0 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, "HL3B:SBPM:HL51:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 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, "HL3B:SBPM:HL51:V")
}

record(ai, "HL3B:SBPM:HL51:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:SBPM:HL51:PINC")
}

record(ai, "HL3B:SBPM:HL51:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:SBPM:HL51:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C0S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:SBPM:HL51:RSTA_ALH")
}


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

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

record(ao, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:PHI_SEQ")
}

record(ao, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:PSI_SEQ")
}

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

record(ao, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:UOFF_SEQ")
}

record(ao, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:SBPM:HL51:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C0 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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL51")
  field(PINI, "YES")
}

record(stringin, "SBPMHL51:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:SBPM:HL51")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:SBPM:HL51:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "0")
#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, "HL3B:SBPM:HL51:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:SBPM:HL51:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:SBPM:HL51:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL51:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:SBPM:HL51:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL51:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:SBPM:HL51:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C0 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, "HL3B:SBPM:HL51:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:SBPM:HL51:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:SBPM:HL51:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:SBPM:HL51:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:SIM.L     PP")
  field(LNK4, "HL3B:SBPM:HL51:SIM.SCAN  PP")

  field(LNK5, "HL3B:SBPM:HL51:SIM.SCAN  PP")
  field(LNK6, "HL3B:SBPM:HL51:SIM.L     PP")
  field(LNK7, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:UOFF")
	field(DOL2, "HL3B:SBPM:HL51:UOFF")
	field(DOL3, "HL3B:SBPM:HL51:UOFF")
	field(DOL4, "HL3B:SBPM:HL51:UOFF")
	field(DOL5, "HL3B:SBPM:HL51:UOFF")
	field(DOL6, "HL3B:SBPM:HL51:UOFF")
	field(DOL7, "HL3B:SBPM:HL51:UOFF")
	field(DOL8, "HL3B:SBPM:HL51:UOFF")
	field(DOL9, "HL3B:SBPM:HL51:UOFF")
	field(DOLA, "HL3B:SBPM:HL51:UOFF")
	field(LNK1, "HL3B:SBPM:HL51:UOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:UOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:UOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:UOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:UOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:UOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:UOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:UOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:UOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:UOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL51:U.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL51:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:UOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:VOFF")
	field(DOL2, "HL3B:SBPM:HL51:VOFF")
	field(DOL3, "HL3B:SBPM:HL51:VOFF")
	field(DOL4, "HL3B:SBPM:HL51:VOFF")
	field(DOL5, "HL3B:SBPM:HL51:VOFF")
	field(DOL6, "HL3B:SBPM:HL51:VOFF")
	field(DOL7, "HL3B:SBPM:HL51:VOFF")
	field(DOL8, "HL3B:SBPM:HL51:VOFF")
	field(DOL9, "HL3B:SBPM:HL51:VOFF")
	field(DOLA, "HL3B:SBPM:HL51:VOFF")
	field(LNK1, "HL3B:SBPM:HL51:VOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:VOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:VOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:VOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:VOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:VOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:VOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:VOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:VOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:VOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL51:V.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL51:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:VOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:USCL")
	field(DOL2, "HL3B:SBPM:HL51:USCL")
	field(DOL3, "HL3B:SBPM:HL51:USCL")
	field(DOL4, "HL3B:SBPM:HL51:USCL")
	field(DOL5, "HL3B:SBPM:HL51:USCL")
	field(DOL6, "HL3B:SBPM:HL51:USCL")
	field(DOL7, "HL3B:SBPM:HL51:USCL")
	field(DOL8, "HL3B:SBPM:HL51:USCL")
	field(DOL9, "HL3B:SBPM:HL51:USCL")
	field(DOLA, "HL3B:SBPM:HL51:USCL")
	field(LNK1, "HL3B:SBPM:HL51:USCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:USCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:USCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:USCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:USCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:USCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:USCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:USCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:USCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:USCL_SEL")
	field(OUTA, "HL3B:SBPM:HL51:U.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL51:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:USCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:VSCL")
	field(DOL2, "HL3B:SBPM:HL51:VSCL")
	field(DOL3, "HL3B:SBPM:HL51:VSCL")
	field(DOL4, "HL3B:SBPM:HL51:VSCL")
	field(DOL5, "HL3B:SBPM:HL51:VSCL")
	field(DOL6, "HL3B:SBPM:HL51:VSCL")
	field(DOL7, "HL3B:SBPM:HL51:VSCL")
	field(DOL8, "HL3B:SBPM:HL51:VSCL")
	field(DOL9, "HL3B:SBPM:HL51:VSCL")
	field(DOLA, "HL3B:SBPM:HL51:VSCL")
	field(LNK1, "HL3B:SBPM:HL51:VSCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:VSCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:VSCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:VSCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:VSCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:VSCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:VSCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:VSCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:VSCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:VSCL_SEL")
	field(OUTA, "HL3B:SBPM:HL51:V.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL51:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:VSCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:PHI")
	field(DOL2, "HL3B:SBPM:HL51:PHI")
	field(DOL3, "HL3B:SBPM:HL51:PHI")
	field(DOL4, "HL3B:SBPM:HL51:PHI")
	field(DOL5, "HL3B:SBPM:HL51:PHI")
	field(DOL6, "HL3B:SBPM:HL51:PHI")
	field(DOL7, "HL3B:SBPM:HL51:PHI")
	field(DOL8, "HL3B:SBPM:HL51:PHI")
	field(DOL9, "HL3B:SBPM:HL51:PHI")
	field(DOLA, "HL3B:SBPM:HL51:PHI")
	field(LNK1, "HL3B:SBPM:HL51:PHI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:PHI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:PHI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:PHI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:PHI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:PHI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:PHI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:PHI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:PHI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:PHI_SEL")
	field(OUTA, "HL3B:SBPM:HL51:CALC.E CA")
	field(OUTB, "HL3B:SBPM:HL51:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:PHI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL51:PSI")
	field(DOL2, "HL3B:SBPM:HL51:PSI")
	field(DOL3, "HL3B:SBPM:HL51:PSI")
	field(DOL4, "HL3B:SBPM:HL51:PSI")
	field(DOL5, "HL3B:SBPM:HL51:PSI")
	field(DOL6, "HL3B:SBPM:HL51:PSI")
	field(DOL7, "HL3B:SBPM:HL51:PSI")
	field(DOL8, "HL3B:SBPM:HL51:PSI")
	field(DOL9, "HL3B:SBPM:HL51:PSI")
	field(DOLA, "HL3B:SBPM:HL51:PSI")
	field(LNK1, "HL3B:SBPM:HL51:PSI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL51:PSI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL51:PSI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL51:PSI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL51:PSI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL51:PSI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL51:PSI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL51:PSI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL51:PSI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL51:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51: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,  "HL3B:SBPM:HL51:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL51:PSI_SEL")
	field(OUTA, "HL3B:SBPM:HL51:CALC.F CA")
	field(OUTB, "HL3B:SBPM:HL51:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL51:PSI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL51:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL51:PSI_SEL.L PP")
}
record(longout, "HL3B:SBPM:HL51:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:EBPM:HL3A:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C1 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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C1 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C1 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C1 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, "HL3B:EBPM:HL3A:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C1 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:EBPM:HL3A: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, "#C1 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:EBPM:HL3A: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, "#C1 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, "HL3B:EBPM:HL3A: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, "#C1 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, "HL3B:EBPM:HL3A: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, "#C1 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, "HL3B:EBPM:HL3A: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, "#C1 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(ao, "HL3B:EBPM:HL3A:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:EBPM:HL3A:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:EBPM:HL3A:ATT1 CP")
  field(INPC, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:EBPM:HL3A:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3A:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:EBPM:HL3A:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:EBPM:HL3A:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:EBPM:HL3A:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:EBPM:HL3A:Y.SEVR    MS NPP")
  field(INPD, "HL3B:EBPM:HL3A:X.SEVR    MS NPP")
  field(INPE, "HL3B:EBPM:HL3A:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:EBPM:HL3A:TRED.SEVR MS NPP")
  field(INPG, "HL3B:EBPM:HL3A:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:EBPM:HL3A:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:EBPM:HL3A:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:EBPM:HL3A:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:EBPM:HL3A:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:EBPM:HL3A:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:EBPM:HL3A:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:EBPM:HL3A:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:EBPM:HL3A:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:EBPM:HL3A:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:EBPM:HL3A:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "1")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:EBPM:HL3A:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C1S0")
  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, "HL3B:EBPM:HL3A:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 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, "HL3B:EBPM:HL3A:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:EBPM:HL3A:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:EBPM:HL3A:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:EBPM:HL3A:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C1 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, "HL3B:EBPM:HL3A:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 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, "HL3B:EBPM:HL3A:V")
}

record(ai, "HL3B:EBPM:HL3A:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:EBPM:HL3A:PINC")
}

record(ai, "HL3B:EBPM:HL3A:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:EBPM:HL3A:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C1S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:EBPM:HL3A:RSTA_ALH")
}


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

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

record(ao, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:PHI_SEQ")
}

record(ao, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:PSI_SEQ")
}

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

record(ao, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:UOFF_SEQ")
}

record(ao, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:EBPM:HL3A:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C1 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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "EBPMHL3A")
  field(PINI, "YES")
}

record(stringin, "EBPMHL3A:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:EBPM:HL3A")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:EBPM:HL3A:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "1")
#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, "HL3B:EBPM:HL3A:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:EBPM:HL3A:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:EBPM:HL3A:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:EBPM:HL3A:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3A:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:EBPM:HL3A:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C1 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, "HL3B:EBPM:HL3A:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:EBPM:HL3A:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:EBPM:HL3A:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:EBPM:HL3A:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:SIM.L     PP")
  field(LNK4, "HL3B:EBPM:HL3A:SIM.SCAN  PP")

  field(LNK5, "HL3B:EBPM:HL3A:SIM.SCAN  PP")
  field(LNK6, "HL3B:EBPM:HL3A:SIM.L     PP")
  field(LNK7, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:UOFF")
	field(DOL2, "HL3B:EBPM:HL3A:UOFF")
	field(DOL3, "HL3B:EBPM:HL3A:UOFF")
	field(DOL4, "HL3B:EBPM:HL3A:UOFF")
	field(DOL5, "HL3B:EBPM:HL3A:UOFF")
	field(DOL6, "HL3B:EBPM:HL3A:UOFF")
	field(DOL7, "HL3B:EBPM:HL3A:UOFF")
	field(DOL8, "HL3B:EBPM:HL3A:UOFF")
	field(DOL9, "HL3B:EBPM:HL3A:UOFF")
	field(DOLA, "HL3B:EBPM:HL3A:UOFF")
	field(LNK1, "HL3B:EBPM:HL3A:UOFF_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:UOFF_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:UOFF_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:UOFF_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:UOFF_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:UOFF_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:UOFF_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:UOFF_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:UOFF_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:UOFF_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:U.AOFF CA")
	field(OUTB, "HL3B:EBPM:HL3A:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:UOFF_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:VOFF")
	field(DOL2, "HL3B:EBPM:HL3A:VOFF")
	field(DOL3, "HL3B:EBPM:HL3A:VOFF")
	field(DOL4, "HL3B:EBPM:HL3A:VOFF")
	field(DOL5, "HL3B:EBPM:HL3A:VOFF")
	field(DOL6, "HL3B:EBPM:HL3A:VOFF")
	field(DOL7, "HL3B:EBPM:HL3A:VOFF")
	field(DOL8, "HL3B:EBPM:HL3A:VOFF")
	field(DOL9, "HL3B:EBPM:HL3A:VOFF")
	field(DOLA, "HL3B:EBPM:HL3A:VOFF")
	field(LNK1, "HL3B:EBPM:HL3A:VOFF_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:VOFF_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:VOFF_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:VOFF_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:VOFF_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:VOFF_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:VOFF_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:VOFF_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:VOFF_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:VOFF_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:V.AOFF CA")
	field(OUTB, "HL3B:EBPM:HL3A:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:VOFF_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:USCL")
	field(DOL2, "HL3B:EBPM:HL3A:USCL")
	field(DOL3, "HL3B:EBPM:HL3A:USCL")
	field(DOL4, "HL3B:EBPM:HL3A:USCL")
	field(DOL5, "HL3B:EBPM:HL3A:USCL")
	field(DOL6, "HL3B:EBPM:HL3A:USCL")
	field(DOL7, "HL3B:EBPM:HL3A:USCL")
	field(DOL8, "HL3B:EBPM:HL3A:USCL")
	field(DOL9, "HL3B:EBPM:HL3A:USCL")
	field(DOLA, "HL3B:EBPM:HL3A:USCL")
	field(LNK1, "HL3B:EBPM:HL3A:USCL_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:USCL_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:USCL_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:USCL_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:USCL_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:USCL_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:USCL_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:USCL_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:USCL_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:USCL_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:U.ASLO CA")
	field(OUTB, "HL3B:EBPM:HL3A:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:USCL_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:VSCL")
	field(DOL2, "HL3B:EBPM:HL3A:VSCL")
	field(DOL3, "HL3B:EBPM:HL3A:VSCL")
	field(DOL4, "HL3B:EBPM:HL3A:VSCL")
	field(DOL5, "HL3B:EBPM:HL3A:VSCL")
	field(DOL6, "HL3B:EBPM:HL3A:VSCL")
	field(DOL7, "HL3B:EBPM:HL3A:VSCL")
	field(DOL8, "HL3B:EBPM:HL3A:VSCL")
	field(DOL9, "HL3B:EBPM:HL3A:VSCL")
	field(DOLA, "HL3B:EBPM:HL3A:VSCL")
	field(LNK1, "HL3B:EBPM:HL3A:VSCL_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:VSCL_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:VSCL_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:VSCL_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:VSCL_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:VSCL_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:VSCL_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:VSCL_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:VSCL_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:VSCL_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:V.ASLO CA")
	field(OUTB, "HL3B:EBPM:HL3A:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:VSCL_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:PHI")
	field(DOL2, "HL3B:EBPM:HL3A:PHI")
	field(DOL3, "HL3B:EBPM:HL3A:PHI")
	field(DOL4, "HL3B:EBPM:HL3A:PHI")
	field(DOL5, "HL3B:EBPM:HL3A:PHI")
	field(DOL6, "HL3B:EBPM:HL3A:PHI")
	field(DOL7, "HL3B:EBPM:HL3A:PHI")
	field(DOL8, "HL3B:EBPM:HL3A:PHI")
	field(DOL9, "HL3B:EBPM:HL3A:PHI")
	field(DOLA, "HL3B:EBPM:HL3A:PHI")
	field(LNK1, "HL3B:EBPM:HL3A:PHI_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:PHI_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:PHI_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:PHI_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:PHI_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:PHI_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:PHI_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:PHI_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:PHI_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:PHI_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:CALC.E CA")
	field(OUTB, "HL3B:EBPM:HL3A:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:PHI_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3A:PSI")
	field(DOL2, "HL3B:EBPM:HL3A:PSI")
	field(DOL3, "HL3B:EBPM:HL3A:PSI")
	field(DOL4, "HL3B:EBPM:HL3A:PSI")
	field(DOL5, "HL3B:EBPM:HL3A:PSI")
	field(DOL6, "HL3B:EBPM:HL3A:PSI")
	field(DOL7, "HL3B:EBPM:HL3A:PSI")
	field(DOL8, "HL3B:EBPM:HL3A:PSI")
	field(DOL9, "HL3B:EBPM:HL3A:PSI")
	field(DOLA, "HL3B:EBPM:HL3A:PSI")
	field(LNK1, "HL3B:EBPM:HL3A:PSI_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3A:PSI_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3A:PSI_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3A:PSI_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3A:PSI_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3A:PSI_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3A:PSI_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3A:PSI_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3A:PSI_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3A:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A: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,  "HL3B:EBPM:HL3A:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3A:PSI_SEL")
	field(OUTA, "HL3B:EBPM:HL3A:CALC.F CA")
	field(OUTB, "HL3B:EBPM:HL3A:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3A:PSI_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3A:PSI_SEL.L PP")
}
record(longout, "HL3B:EBPM:HL3A:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:EBPM:HL3B:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C2 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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C2 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C2 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C2 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, "HL3B:EBPM:HL3B:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C2 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:EBPM:HL3B: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, "#C2 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:EBPM:HL3B: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, "#C2 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, "HL3B:EBPM:HL3B: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, "#C2 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, "HL3B:EBPM:HL3B: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, "#C2 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, "HL3B:EBPM:HL3B: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, "#C2 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(ao, "HL3B:EBPM:HL3B:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:EBPM:HL3B:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:EBPM:HL3B:ATT1 CP")
  field(INPC, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:EBPM:HL3B:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3B:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:EBPM:HL3B:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:EBPM:HL3B:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:EBPM:HL3B:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:EBPM:HL3B:Y.SEVR    MS NPP")
  field(INPD, "HL3B:EBPM:HL3B:X.SEVR    MS NPP")
  field(INPE, "HL3B:EBPM:HL3B:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:EBPM:HL3B:TRED.SEVR MS NPP")
  field(INPG, "HL3B:EBPM:HL3B:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:EBPM:HL3B:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:EBPM:HL3B:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:EBPM:HL3B:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:EBPM:HL3B:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:EBPM:HL3B:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:EBPM:HL3B:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:EBPM:HL3B:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:EBPM:HL3B:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:EBPM:HL3B:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:EBPM:HL3B:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "2")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:EBPM:HL3B:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C2S0")
  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, "HL3B:EBPM:HL3B:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C2 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, "HL3B:EBPM:HL3B:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:EBPM:HL3B:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C2 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:EBPM:HL3B:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:EBPM:HL3B:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C2 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, "HL3B:EBPM:HL3B:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C2 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, "HL3B:EBPM:HL3B:V")
}

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

record(ai, "HL3B:EBPM:HL3B:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C2 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:EBPM:HL3B:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C2S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:EBPM:HL3B:RSTA_ALH")
}


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

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

record(ao, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:PHI_SEQ")
}

record(ao, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:PSI_SEQ")
}

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

record(ao, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:UOFF_SEQ")
}

record(ao, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:EBPM:HL3B:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C2 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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "EBPMHL3B")
  field(PINI, "YES")
}

record(stringin, "EBPMHL3B:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:EBPM:HL3B")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:EBPM:HL3B:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "2")
#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, "HL3B:EBPM:HL3B:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:EBPM:HL3B:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:EBPM:HL3B:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:EBPM:HL3B:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:EBPM:HL3B:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:EBPM:HL3B:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C2 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, "HL3B:EBPM:HL3B:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:EBPM:HL3B:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:EBPM:HL3B:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:EBPM:HL3B:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:SIM.L     PP")
  field(LNK4, "HL3B:EBPM:HL3B:SIM.SCAN  PP")

  field(LNK5, "HL3B:EBPM:HL3B:SIM.SCAN  PP")
  field(LNK6, "HL3B:EBPM:HL3B:SIM.L     PP")
  field(LNK7, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:UOFF")
	field(DOL2, "HL3B:EBPM:HL3B:UOFF")
	field(DOL3, "HL3B:EBPM:HL3B:UOFF")
	field(DOL4, "HL3B:EBPM:HL3B:UOFF")
	field(DOL5, "HL3B:EBPM:HL3B:UOFF")
	field(DOL6, "HL3B:EBPM:HL3B:UOFF")
	field(DOL7, "HL3B:EBPM:HL3B:UOFF")
	field(DOL8, "HL3B:EBPM:HL3B:UOFF")
	field(DOL9, "HL3B:EBPM:HL3B:UOFF")
	field(DOLA, "HL3B:EBPM:HL3B:UOFF")
	field(LNK1, "HL3B:EBPM:HL3B:UOFF_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:UOFF_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:UOFF_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:UOFF_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:UOFF_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:UOFF_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:UOFF_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:UOFF_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:UOFF_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:UOFF_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:U.AOFF CA")
	field(OUTB, "HL3B:EBPM:HL3B:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:UOFF_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:VOFF")
	field(DOL2, "HL3B:EBPM:HL3B:VOFF")
	field(DOL3, "HL3B:EBPM:HL3B:VOFF")
	field(DOL4, "HL3B:EBPM:HL3B:VOFF")
	field(DOL5, "HL3B:EBPM:HL3B:VOFF")
	field(DOL6, "HL3B:EBPM:HL3B:VOFF")
	field(DOL7, "HL3B:EBPM:HL3B:VOFF")
	field(DOL8, "HL3B:EBPM:HL3B:VOFF")
	field(DOL9, "HL3B:EBPM:HL3B:VOFF")
	field(DOLA, "HL3B:EBPM:HL3B:VOFF")
	field(LNK1, "HL3B:EBPM:HL3B:VOFF_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:VOFF_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:VOFF_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:VOFF_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:VOFF_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:VOFF_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:VOFF_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:VOFF_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:VOFF_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:VOFF_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:V.AOFF CA")
	field(OUTB, "HL3B:EBPM:HL3B:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:VOFF_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:USCL")
	field(DOL2, "HL3B:EBPM:HL3B:USCL")
	field(DOL3, "HL3B:EBPM:HL3B:USCL")
	field(DOL4, "HL3B:EBPM:HL3B:USCL")
	field(DOL5, "HL3B:EBPM:HL3B:USCL")
	field(DOL6, "HL3B:EBPM:HL3B:USCL")
	field(DOL7, "HL3B:EBPM:HL3B:USCL")
	field(DOL8, "HL3B:EBPM:HL3B:USCL")
	field(DOL9, "HL3B:EBPM:HL3B:USCL")
	field(DOLA, "HL3B:EBPM:HL3B:USCL")
	field(LNK1, "HL3B:EBPM:HL3B:USCL_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:USCL_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:USCL_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:USCL_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:USCL_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:USCL_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:USCL_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:USCL_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:USCL_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:USCL_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:U.ASLO CA")
	field(OUTB, "HL3B:EBPM:HL3B:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:USCL_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:VSCL")
	field(DOL2, "HL3B:EBPM:HL3B:VSCL")
	field(DOL3, "HL3B:EBPM:HL3B:VSCL")
	field(DOL4, "HL3B:EBPM:HL3B:VSCL")
	field(DOL5, "HL3B:EBPM:HL3B:VSCL")
	field(DOL6, "HL3B:EBPM:HL3B:VSCL")
	field(DOL7, "HL3B:EBPM:HL3B:VSCL")
	field(DOL8, "HL3B:EBPM:HL3B:VSCL")
	field(DOL9, "HL3B:EBPM:HL3B:VSCL")
	field(DOLA, "HL3B:EBPM:HL3B:VSCL")
	field(LNK1, "HL3B:EBPM:HL3B:VSCL_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:VSCL_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:VSCL_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:VSCL_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:VSCL_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:VSCL_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:VSCL_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:VSCL_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:VSCL_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:VSCL_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:V.ASLO CA")
	field(OUTB, "HL3B:EBPM:HL3B:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:VSCL_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:PHI")
	field(DOL2, "HL3B:EBPM:HL3B:PHI")
	field(DOL3, "HL3B:EBPM:HL3B:PHI")
	field(DOL4, "HL3B:EBPM:HL3B:PHI")
	field(DOL5, "HL3B:EBPM:HL3B:PHI")
	field(DOL6, "HL3B:EBPM:HL3B:PHI")
	field(DOL7, "HL3B:EBPM:HL3B:PHI")
	field(DOL8, "HL3B:EBPM:HL3B:PHI")
	field(DOL9, "HL3B:EBPM:HL3B:PHI")
	field(DOLA, "HL3B:EBPM:HL3B:PHI")
	field(LNK1, "HL3B:EBPM:HL3B:PHI_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:PHI_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:PHI_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:PHI_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:PHI_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:PHI_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:PHI_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:PHI_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:PHI_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:PHI_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:CALC.E CA")
	field(OUTB, "HL3B:EBPM:HL3B:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:PHI_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:EBPM:HL3B:PSI")
	field(DOL2, "HL3B:EBPM:HL3B:PSI")
	field(DOL3, "HL3B:EBPM:HL3B:PSI")
	field(DOL4, "HL3B:EBPM:HL3B:PSI")
	field(DOL5, "HL3B:EBPM:HL3B:PSI")
	field(DOL6, "HL3B:EBPM:HL3B:PSI")
	field(DOL7, "HL3B:EBPM:HL3B:PSI")
	field(DOL8, "HL3B:EBPM:HL3B:PSI")
	field(DOL9, "HL3B:EBPM:HL3B:PSI")
	field(DOLA, "HL3B:EBPM:HL3B:PSI")
	field(LNK1, "HL3B:EBPM:HL3B:PSI_SEL.A PP")
	field(LNK2, "HL3B:EBPM:HL3B:PSI_SEL.B PP")
	field(LNK3, "HL3B:EBPM:HL3B:PSI_SEL.C PP")
	field(LNK4, "HL3B:EBPM:HL3B:PSI_SEL.D PP")
	field(LNK5, "HL3B:EBPM:HL3B:PSI_SEL.E PP")
	field(LNK6, "HL3B:EBPM:HL3B:PSI_SEL.F PP")
	field(LNK7, "HL3B:EBPM:HL3B:PSI_SEL.G PP")
	field(LNK8, "HL3B:EBPM:HL3B:PSI_SEL.H PP")
	field(LNK9, "HL3B:EBPM:HL3B:PSI_SEL.I PP")
	field(LNKA, "HL3B:EBPM:HL3B:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B: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,  "HL3B:EBPM:HL3B:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:EBPM:HL3B:PSI_SEL")
	field(OUTA, "HL3B:EBPM:HL3B:CALC.F CA")
	field(OUTB, "HL3B:EBPM:HL3B:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:EBPM:HL3B:PSI_CTRL")
{
	field(INPA, "HL3B:EBPM:HL3B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:EBPM:HL3B:PSI_SEL.L PP")
}
record(longout, "HL3B:EBPM:HL3B:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:SBPM:HL52:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C3 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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C3 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C3 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C3 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, "HL3B:SBPM:HL52:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C3 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:SBPM:HL52: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, "#C3 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:SBPM:HL52: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, "#C3 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, "HL3B:SBPM:HL52: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, "#C3 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, "HL3B:SBPM:HL52: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, "#C3 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, "HL3B:SBPM:HL52: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, "#C3 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(ao, "HL3B:SBPM:HL52:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL52:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:SBPM:HL52:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:SBPM:HL52:ATT1 CP")
  field(INPC, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:SBPM:HL52:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL52:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL52:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:SBPM:HL52:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:SBPM:HL52:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL52:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:SBPM:HL52:Y.SEVR    MS NPP")
  field(INPD, "HL3B:SBPM:HL52:X.SEVR    MS NPP")
  field(INPE, "HL3B:SBPM:HL52:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:SBPM:HL52:TRED.SEVR MS NPP")
  field(INPG, "HL3B:SBPM:HL52:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:SBPM:HL52:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:SBPM:HL52:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:SBPM:HL52:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL52:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:SBPM:HL52:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:SBPM:HL52:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:SBPM:HL52:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:SBPM:HL52:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL52:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL52:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "3")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:SBPM:HL52:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C3S0")
  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, "HL3B:SBPM:HL52:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 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, "HL3B:SBPM:HL52:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:SBPM:HL52:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:SBPM:HL52:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:SBPM:HL52:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C3 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, "HL3B:SBPM:HL52:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 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, "HL3B:SBPM:HL52:V")
}

record(ai, "HL3B:SBPM:HL52:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:SBPM:HL52:PINC")
}

record(ai, "HL3B:SBPM:HL52:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:SBPM:HL52:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C3S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:SBPM:HL52:RSTA_ALH")
}


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

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

record(ao, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:PHI_SEQ")
}

record(ao, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:PSI_SEQ")
}

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

record(ao, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:UOFF_SEQ")
}

record(ao, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:SBPM:HL52:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C3 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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL52")
  field(PINI, "YES")
}

record(stringin, "SBPMHL52:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:SBPM:HL52")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:SBPM:HL52:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "3")
#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, "HL3B:SBPM:HL52:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:SBPM:HL52:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:SBPM:HL52:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL52:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:SBPM:HL52:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL52:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:SBPM:HL52:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C3 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, "HL3B:SBPM:HL52:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:SBPM:HL52:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:SBPM:HL52:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:SBPM:HL52:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:SIM.L     PP")
  field(LNK4, "HL3B:SBPM:HL52:SIM.SCAN  PP")

  field(LNK5, "HL3B:SBPM:HL52:SIM.SCAN  PP")
  field(LNK6, "HL3B:SBPM:HL52:SIM.L     PP")
  field(LNK7, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:UOFF")
	field(DOL2, "HL3B:SBPM:HL52:UOFF")
	field(DOL3, "HL3B:SBPM:HL52:UOFF")
	field(DOL4, "HL3B:SBPM:HL52:UOFF")
	field(DOL5, "HL3B:SBPM:HL52:UOFF")
	field(DOL6, "HL3B:SBPM:HL52:UOFF")
	field(DOL7, "HL3B:SBPM:HL52:UOFF")
	field(DOL8, "HL3B:SBPM:HL52:UOFF")
	field(DOL9, "HL3B:SBPM:HL52:UOFF")
	field(DOLA, "HL3B:SBPM:HL52:UOFF")
	field(LNK1, "HL3B:SBPM:HL52:UOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:UOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:UOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:UOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:UOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:UOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:UOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:UOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:UOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:UOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL52:U.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL52:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:UOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:VOFF")
	field(DOL2, "HL3B:SBPM:HL52:VOFF")
	field(DOL3, "HL3B:SBPM:HL52:VOFF")
	field(DOL4, "HL3B:SBPM:HL52:VOFF")
	field(DOL5, "HL3B:SBPM:HL52:VOFF")
	field(DOL6, "HL3B:SBPM:HL52:VOFF")
	field(DOL7, "HL3B:SBPM:HL52:VOFF")
	field(DOL8, "HL3B:SBPM:HL52:VOFF")
	field(DOL9, "HL3B:SBPM:HL52:VOFF")
	field(DOLA, "HL3B:SBPM:HL52:VOFF")
	field(LNK1, "HL3B:SBPM:HL52:VOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:VOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:VOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:VOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:VOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:VOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:VOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:VOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:VOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:VOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL52:V.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL52:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:VOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:USCL")
	field(DOL2, "HL3B:SBPM:HL52:USCL")
	field(DOL3, "HL3B:SBPM:HL52:USCL")
	field(DOL4, "HL3B:SBPM:HL52:USCL")
	field(DOL5, "HL3B:SBPM:HL52:USCL")
	field(DOL6, "HL3B:SBPM:HL52:USCL")
	field(DOL7, "HL3B:SBPM:HL52:USCL")
	field(DOL8, "HL3B:SBPM:HL52:USCL")
	field(DOL9, "HL3B:SBPM:HL52:USCL")
	field(DOLA, "HL3B:SBPM:HL52:USCL")
	field(LNK1, "HL3B:SBPM:HL52:USCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:USCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:USCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:USCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:USCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:USCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:USCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:USCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:USCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:USCL_SEL")
	field(OUTA, "HL3B:SBPM:HL52:U.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL52:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:USCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:VSCL")
	field(DOL2, "HL3B:SBPM:HL52:VSCL")
	field(DOL3, "HL3B:SBPM:HL52:VSCL")
	field(DOL4, "HL3B:SBPM:HL52:VSCL")
	field(DOL5, "HL3B:SBPM:HL52:VSCL")
	field(DOL6, "HL3B:SBPM:HL52:VSCL")
	field(DOL7, "HL3B:SBPM:HL52:VSCL")
	field(DOL8, "HL3B:SBPM:HL52:VSCL")
	field(DOL9, "HL3B:SBPM:HL52:VSCL")
	field(DOLA, "HL3B:SBPM:HL52:VSCL")
	field(LNK1, "HL3B:SBPM:HL52:VSCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:VSCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:VSCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:VSCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:VSCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:VSCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:VSCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:VSCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:VSCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:VSCL_SEL")
	field(OUTA, "HL3B:SBPM:HL52:V.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL52:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:VSCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:PHI")
	field(DOL2, "HL3B:SBPM:HL52:PHI")
	field(DOL3, "HL3B:SBPM:HL52:PHI")
	field(DOL4, "HL3B:SBPM:HL52:PHI")
	field(DOL5, "HL3B:SBPM:HL52:PHI")
	field(DOL6, "HL3B:SBPM:HL52:PHI")
	field(DOL7, "HL3B:SBPM:HL52:PHI")
	field(DOL8, "HL3B:SBPM:HL52:PHI")
	field(DOL9, "HL3B:SBPM:HL52:PHI")
	field(DOLA, "HL3B:SBPM:HL52:PHI")
	field(LNK1, "HL3B:SBPM:HL52:PHI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:PHI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:PHI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:PHI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:PHI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:PHI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:PHI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:PHI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:PHI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:PHI_SEL")
	field(OUTA, "HL3B:SBPM:HL52:CALC.E CA")
	field(OUTB, "HL3B:SBPM:HL52:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:PHI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL52:PSI")
	field(DOL2, "HL3B:SBPM:HL52:PSI")
	field(DOL3, "HL3B:SBPM:HL52:PSI")
	field(DOL4, "HL3B:SBPM:HL52:PSI")
	field(DOL5, "HL3B:SBPM:HL52:PSI")
	field(DOL6, "HL3B:SBPM:HL52:PSI")
	field(DOL7, "HL3B:SBPM:HL52:PSI")
	field(DOL8, "HL3B:SBPM:HL52:PSI")
	field(DOL9, "HL3B:SBPM:HL52:PSI")
	field(DOLA, "HL3B:SBPM:HL52:PSI")
	field(LNK1, "HL3B:SBPM:HL52:PSI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL52:PSI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL52:PSI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL52:PSI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL52:PSI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL52:PSI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL52:PSI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL52:PSI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL52:PSI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL52:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52: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,  "HL3B:SBPM:HL52:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL52:PSI_SEL")
	field(OUTA, "HL3B:SBPM:HL52:CALC.F CA")
	field(OUTB, "HL3B:SBPM:HL52:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL52:PSI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL52:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL52:PSI_SEL.L PP")
}
record(longout, "HL3B:SBPM:HL52:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:SBPM:HL53:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C4 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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C4 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C4 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C4 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, "HL3B:SBPM:HL53:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C4 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:SBPM:HL53: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, "#C4 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:SBPM:HL53: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, "#C4 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, "HL3B:SBPM:HL53: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, "#C4 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, "HL3B:SBPM:HL53: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, "#C4 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, "HL3B:SBPM:HL53: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, "#C4 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(ao, "HL3B:SBPM:HL53:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL53:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:SBPM:HL53:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:SBPM:HL53:ATT1 CP")
  field(INPC, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:SBPM:HL53:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL53:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL53:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:SBPM:HL53:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:SBPM:HL53:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL53:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:SBPM:HL53:Y.SEVR    MS NPP")
  field(INPD, "HL3B:SBPM:HL53:X.SEVR    MS NPP")
  field(INPE, "HL3B:SBPM:HL53:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:SBPM:HL53:TRED.SEVR MS NPP")
  field(INPG, "HL3B:SBPM:HL53:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:SBPM:HL53:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:SBPM:HL53:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:SBPM:HL53:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL53:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:SBPM:HL53:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:SBPM:HL53:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:SBPM:HL53:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:SBPM:HL53:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL53:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL53:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "4")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:SBPM:HL53:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C4S0")
  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, "HL3B:SBPM:HL53:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 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, "HL3B:SBPM:HL53:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:SBPM:HL53:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:SBPM:HL53:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:SBPM:HL53:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C4 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, "HL3B:SBPM:HL53:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 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, "HL3B:SBPM:HL53:V")
}

record(ai, "HL3B:SBPM:HL53:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:SBPM:HL53:PINC")
}

record(ai, "HL3B:SBPM:HL53:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:SBPM:HL53:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C4S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:SBPM:HL53:RSTA_ALH")
}


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

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

record(ao, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:PHI_SEQ")
}

record(ao, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:PSI_SEQ")
}

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

record(ao, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:UOFF_SEQ")
}

record(ao, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:SBPM:HL53:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C4 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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL53")
  field(PINI, "YES")
}

record(stringin, "SBPMHL53:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:SBPM:HL53")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:SBPM:HL53:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "4")
#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, "HL3B:SBPM:HL53:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:SBPM:HL53:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:SBPM:HL53:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL53:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:SBPM:HL53:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL53:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:SBPM:HL53:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C4 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, "HL3B:SBPM:HL53:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:SBPM:HL53:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:SBPM:HL53:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:SBPM:HL53:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:SIM.L     PP")
  field(LNK4, "HL3B:SBPM:HL53:SIM.SCAN  PP")

  field(LNK5, "HL3B:SBPM:HL53:SIM.SCAN  PP")
  field(LNK6, "HL3B:SBPM:HL53:SIM.L     PP")
  field(LNK7, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:UOFF")
	field(DOL2, "HL3B:SBPM:HL53:UOFF")
	field(DOL3, "HL3B:SBPM:HL53:UOFF")
	field(DOL4, "HL3B:SBPM:HL53:UOFF")
	field(DOL5, "HL3B:SBPM:HL53:UOFF")
	field(DOL6, "HL3B:SBPM:HL53:UOFF")
	field(DOL7, "HL3B:SBPM:HL53:UOFF")
	field(DOL8, "HL3B:SBPM:HL53:UOFF")
	field(DOL9, "HL3B:SBPM:HL53:UOFF")
	field(DOLA, "HL3B:SBPM:HL53:UOFF")
	field(LNK1, "HL3B:SBPM:HL53:UOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:UOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:UOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:UOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:UOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:UOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:UOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:UOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:UOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:UOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL53:U.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL53:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:UOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:VOFF")
	field(DOL2, "HL3B:SBPM:HL53:VOFF")
	field(DOL3, "HL3B:SBPM:HL53:VOFF")
	field(DOL4, "HL3B:SBPM:HL53:VOFF")
	field(DOL5, "HL3B:SBPM:HL53:VOFF")
	field(DOL6, "HL3B:SBPM:HL53:VOFF")
	field(DOL7, "HL3B:SBPM:HL53:VOFF")
	field(DOL8, "HL3B:SBPM:HL53:VOFF")
	field(DOL9, "HL3B:SBPM:HL53:VOFF")
	field(DOLA, "HL3B:SBPM:HL53:VOFF")
	field(LNK1, "HL3B:SBPM:HL53:VOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:VOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:VOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:VOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:VOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:VOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:VOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:VOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:VOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:VOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL53:V.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL53:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:VOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:USCL")
	field(DOL2, "HL3B:SBPM:HL53:USCL")
	field(DOL3, "HL3B:SBPM:HL53:USCL")
	field(DOL4, "HL3B:SBPM:HL53:USCL")
	field(DOL5, "HL3B:SBPM:HL53:USCL")
	field(DOL6, "HL3B:SBPM:HL53:USCL")
	field(DOL7, "HL3B:SBPM:HL53:USCL")
	field(DOL8, "HL3B:SBPM:HL53:USCL")
	field(DOL9, "HL3B:SBPM:HL53:USCL")
	field(DOLA, "HL3B:SBPM:HL53:USCL")
	field(LNK1, "HL3B:SBPM:HL53:USCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:USCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:USCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:USCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:USCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:USCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:USCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:USCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:USCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:USCL_SEL")
	field(OUTA, "HL3B:SBPM:HL53:U.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL53:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:USCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:VSCL")
	field(DOL2, "HL3B:SBPM:HL53:VSCL")
	field(DOL3, "HL3B:SBPM:HL53:VSCL")
	field(DOL4, "HL3B:SBPM:HL53:VSCL")
	field(DOL5, "HL3B:SBPM:HL53:VSCL")
	field(DOL6, "HL3B:SBPM:HL53:VSCL")
	field(DOL7, "HL3B:SBPM:HL53:VSCL")
	field(DOL8, "HL3B:SBPM:HL53:VSCL")
	field(DOL9, "HL3B:SBPM:HL53:VSCL")
	field(DOLA, "HL3B:SBPM:HL53:VSCL")
	field(LNK1, "HL3B:SBPM:HL53:VSCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:VSCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:VSCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:VSCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:VSCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:VSCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:VSCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:VSCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:VSCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:VSCL_SEL")
	field(OUTA, "HL3B:SBPM:HL53:V.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL53:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:VSCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:PHI")
	field(DOL2, "HL3B:SBPM:HL53:PHI")
	field(DOL3, "HL3B:SBPM:HL53:PHI")
	field(DOL4, "HL3B:SBPM:HL53:PHI")
	field(DOL5, "HL3B:SBPM:HL53:PHI")
	field(DOL6, "HL3B:SBPM:HL53:PHI")
	field(DOL7, "HL3B:SBPM:HL53:PHI")
	field(DOL8, "HL3B:SBPM:HL53:PHI")
	field(DOL9, "HL3B:SBPM:HL53:PHI")
	field(DOLA, "HL3B:SBPM:HL53:PHI")
	field(LNK1, "HL3B:SBPM:HL53:PHI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:PHI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:PHI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:PHI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:PHI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:PHI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:PHI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:PHI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:PHI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:PHI_SEL")
	field(OUTA, "HL3B:SBPM:HL53:CALC.E CA")
	field(OUTB, "HL3B:SBPM:HL53:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:PHI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL53:PSI")
	field(DOL2, "HL3B:SBPM:HL53:PSI")
	field(DOL3, "HL3B:SBPM:HL53:PSI")
	field(DOL4, "HL3B:SBPM:HL53:PSI")
	field(DOL5, "HL3B:SBPM:HL53:PSI")
	field(DOL6, "HL3B:SBPM:HL53:PSI")
	field(DOL7, "HL3B:SBPM:HL53:PSI")
	field(DOL8, "HL3B:SBPM:HL53:PSI")
	field(DOL9, "HL3B:SBPM:HL53:PSI")
	field(DOLA, "HL3B:SBPM:HL53:PSI")
	field(LNK1, "HL3B:SBPM:HL53:PSI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL53:PSI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL53:PSI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL53:PSI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL53:PSI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL53:PSI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL53:PSI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL53:PSI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL53:PSI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL53:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53: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,  "HL3B:SBPM:HL53:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL53:PSI_SEL")
	field(OUTA, "HL3B:SBPM:HL53:CALC.F CA")
	field(OUTB, "HL3B:SBPM:HL53:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL53:PSI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL53:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL53:PSI_SEL.L PP")
}
record(longout, "HL3B:SBPM:HL53:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:SBPM:HL54:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C5 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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C5 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C5 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C5 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, "HL3B:SBPM:HL54:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C5 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:SBPM:HL54: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, "#C5 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:SBPM:HL54: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, "#C5 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, "HL3B:SBPM:HL54: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, "#C5 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, "HL3B:SBPM:HL54: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, "#C5 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, "HL3B:SBPM:HL54: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, "#C5 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(ao, "HL3B:SBPM:HL54:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL54:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:SBPM:HL54:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:SBPM:HL54:ATT1 CP")
  field(INPC, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:SBPM:HL54:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL54:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL54:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:SBPM:HL54:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:SBPM:HL54:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL54:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:SBPM:HL54:Y.SEVR    MS NPP")
  field(INPD, "HL3B:SBPM:HL54:X.SEVR    MS NPP")
  field(INPE, "HL3B:SBPM:HL54:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:SBPM:HL54:TRED.SEVR MS NPP")
  field(INPG, "HL3B:SBPM:HL54:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:SBPM:HL54:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:SBPM:HL54:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:SBPM:HL54:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL54:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:SBPM:HL54:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:SBPM:HL54:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:SBPM:HL54:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:SBPM:HL54:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL54:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL54:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "5")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:SBPM:HL54:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C5S0")
  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, "HL3B:SBPM:HL54:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 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, "HL3B:SBPM:HL54:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:SBPM:HL54:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:SBPM:HL54:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:SBPM:HL54:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C5 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, "HL3B:SBPM:HL54:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 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, "HL3B:SBPM:HL54:V")
}

record(ai, "HL3B:SBPM:HL54:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:SBPM:HL54:PINC")
}

record(ai, "HL3B:SBPM:HL54:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:SBPM:HL54:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C5S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:SBPM:HL54:RSTA_ALH")
}


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

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

record(ao, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:PHI_SEQ")
}

record(ao, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:PSI_SEQ")
}

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

record(ao, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:UOFF_SEQ")
}

record(ao, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:SBPM:HL54:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C5 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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL54")
  field(PINI, "YES")
}

record(stringin, "SBPMHL54:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:SBPM:HL54")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:SBPM:HL54:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "5")
#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, "HL3B:SBPM:HL54:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:SBPM:HL54:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:SBPM:HL54:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL54:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:SBPM:HL54:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL54:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:SBPM:HL54:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C5 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, "HL3B:SBPM:HL54:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:SBPM:HL54:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:SBPM:HL54:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:SBPM:HL54:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:SIM.L     PP")
  field(LNK4, "HL3B:SBPM:HL54:SIM.SCAN  PP")

  field(LNK5, "HL3B:SBPM:HL54:SIM.SCAN  PP")
  field(LNK6, "HL3B:SBPM:HL54:SIM.L     PP")
  field(LNK7, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:UOFF")
	field(DOL2, "HL3B:SBPM:HL54:UOFF")
	field(DOL3, "HL3B:SBPM:HL54:UOFF")
	field(DOL4, "HL3B:SBPM:HL54:UOFF")
	field(DOL5, "HL3B:SBPM:HL54:UOFF")
	field(DOL6, "HL3B:SBPM:HL54:UOFF")
	field(DOL7, "HL3B:SBPM:HL54:UOFF")
	field(DOL8, "HL3B:SBPM:HL54:UOFF")
	field(DOL9, "HL3B:SBPM:HL54:UOFF")
	field(DOLA, "HL3B:SBPM:HL54:UOFF")
	field(LNK1, "HL3B:SBPM:HL54:UOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:UOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:UOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:UOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:UOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:UOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:UOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:UOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:UOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:UOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL54:U.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL54:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:UOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:VOFF")
	field(DOL2, "HL3B:SBPM:HL54:VOFF")
	field(DOL3, "HL3B:SBPM:HL54:VOFF")
	field(DOL4, "HL3B:SBPM:HL54:VOFF")
	field(DOL5, "HL3B:SBPM:HL54:VOFF")
	field(DOL6, "HL3B:SBPM:HL54:VOFF")
	field(DOL7, "HL3B:SBPM:HL54:VOFF")
	field(DOL8, "HL3B:SBPM:HL54:VOFF")
	field(DOL9, "HL3B:SBPM:HL54:VOFF")
	field(DOLA, "HL3B:SBPM:HL54:VOFF")
	field(LNK1, "HL3B:SBPM:HL54:VOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:VOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:VOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:VOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:VOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:VOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:VOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:VOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:VOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:VOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL54:V.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL54:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:VOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:USCL")
	field(DOL2, "HL3B:SBPM:HL54:USCL")
	field(DOL3, "HL3B:SBPM:HL54:USCL")
	field(DOL4, "HL3B:SBPM:HL54:USCL")
	field(DOL5, "HL3B:SBPM:HL54:USCL")
	field(DOL6, "HL3B:SBPM:HL54:USCL")
	field(DOL7, "HL3B:SBPM:HL54:USCL")
	field(DOL8, "HL3B:SBPM:HL54:USCL")
	field(DOL9, "HL3B:SBPM:HL54:USCL")
	field(DOLA, "HL3B:SBPM:HL54:USCL")
	field(LNK1, "HL3B:SBPM:HL54:USCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:USCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:USCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:USCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:USCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:USCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:USCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:USCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:USCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:USCL_SEL")
	field(OUTA, "HL3B:SBPM:HL54:U.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL54:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:USCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:VSCL")
	field(DOL2, "HL3B:SBPM:HL54:VSCL")
	field(DOL3, "HL3B:SBPM:HL54:VSCL")
	field(DOL4, "HL3B:SBPM:HL54:VSCL")
	field(DOL5, "HL3B:SBPM:HL54:VSCL")
	field(DOL6, "HL3B:SBPM:HL54:VSCL")
	field(DOL7, "HL3B:SBPM:HL54:VSCL")
	field(DOL8, "HL3B:SBPM:HL54:VSCL")
	field(DOL9, "HL3B:SBPM:HL54:VSCL")
	field(DOLA, "HL3B:SBPM:HL54:VSCL")
	field(LNK1, "HL3B:SBPM:HL54:VSCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:VSCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:VSCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:VSCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:VSCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:VSCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:VSCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:VSCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:VSCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:VSCL_SEL")
	field(OUTA, "HL3B:SBPM:HL54:V.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL54:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:VSCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:PHI")
	field(DOL2, "HL3B:SBPM:HL54:PHI")
	field(DOL3, "HL3B:SBPM:HL54:PHI")
	field(DOL4, "HL3B:SBPM:HL54:PHI")
	field(DOL5, "HL3B:SBPM:HL54:PHI")
	field(DOL6, "HL3B:SBPM:HL54:PHI")
	field(DOL7, "HL3B:SBPM:HL54:PHI")
	field(DOL8, "HL3B:SBPM:HL54:PHI")
	field(DOL9, "HL3B:SBPM:HL54:PHI")
	field(DOLA, "HL3B:SBPM:HL54:PHI")
	field(LNK1, "HL3B:SBPM:HL54:PHI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:PHI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:PHI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:PHI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:PHI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:PHI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:PHI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:PHI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:PHI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:PHI_SEL")
	field(OUTA, "HL3B:SBPM:HL54:CALC.E CA")
	field(OUTB, "HL3B:SBPM:HL54:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:PHI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL54:PSI")
	field(DOL2, "HL3B:SBPM:HL54:PSI")
	field(DOL3, "HL3B:SBPM:HL54:PSI")
	field(DOL4, "HL3B:SBPM:HL54:PSI")
	field(DOL5, "HL3B:SBPM:HL54:PSI")
	field(DOL6, "HL3B:SBPM:HL54:PSI")
	field(DOL7, "HL3B:SBPM:HL54:PSI")
	field(DOL8, "HL3B:SBPM:HL54:PSI")
	field(DOL9, "HL3B:SBPM:HL54:PSI")
	field(DOLA, "HL3B:SBPM:HL54:PSI")
	field(LNK1, "HL3B:SBPM:HL54:PSI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL54:PSI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL54:PSI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL54:PSI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL54:PSI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL54:PSI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL54:PSI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL54:PSI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL54:PSI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL54:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54: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,  "HL3B:SBPM:HL54:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL54:PSI_SEL")
	field(OUTA, "HL3B:SBPM:HL54:CALC.F CA")
	field(OUTB, "HL3B:SBPM:HL54:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL54:PSI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL54:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL54:PSI_SEL.L PP")
}
record(longout, "HL3B:SBPM:HL54:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL3B:SBPM:HL55:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C6 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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C6 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C6 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C6 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, "HL3B:SBPM:HL55:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C6 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL3B:SBPM:HL55: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, "#C6 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL3B:SBPM:HL55: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, "#C6 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, "HL3B:SBPM:HL55: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, "#C6 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, "HL3B:SBPM:HL55: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, "#C6 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, "HL3B:SBPM:HL55: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, "#C6 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(ao, "HL3B:SBPM:HL55:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL55:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL3B:SBPM:HL55:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL3B:SBPM:HL55:ATT1 CP")
  field(INPC, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL3B:SBPM:HL55:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL55:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL55:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL3B:SBPM:HL55:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL3B:SBPM:HL55:RSTA.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL55:TMIT.SEVR MS NPP")
  field(INPC, "HL3B:SBPM:HL55:Y.SEVR    MS NPP")
  field(INPD, "HL3B:SBPM:HL55:X.SEVR    MS NPP")
  field(INPE, "HL3B:SBPM:HL55:TGRN.SEVR MS NPP")
  field(INPF, "HL3B:SBPM:HL55:TRED.SEVR MS NPP")
  field(INPG, "HL3B:SBPM:HL55:TBLU.SEVR MS NPP")
  field(INPH, "HL3B:SBPM:HL55:TYLO.SEVR MS NPP")
  field(INPI, "HL3B:SBPM:HL55:GRU.SEVR  MS NPP")
  field(INPJ, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL3B:SBPM:HL55:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL3B:SBPM:HL55:GRU.SEVR  MS NPP")
  field(INPC, "HL3B:SBPM:HL55:GRV.SEVR  MS NPP")
  field(INPD, "HL3B:SBPM:HL55:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL3B:SBPM:HL55:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL3B:SBPM:HL55:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL55:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL3B:SBPM:HL55:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "6")
  field(SCAN, "Passive")
}

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

record(ao, "HL3B:SBPM:HL55:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C6S0")
  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, "HL3B:SBPM:HL55:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 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, "HL3B:SBPM:HL55:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL3B:SBPM:HL55:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL3B:SBPM:HL55:EFX.PROC")
  field(ASG,  "")
  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, "HL3B:SBPM:HL55:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C6 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, "HL3B:SBPM:HL55:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 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, "HL3B:SBPM:HL55:V")
}

record(ai, "HL3B:SBPM:HL55:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL3B:SBPM:HL55:PINC")
}

record(ai, "HL3B:SBPM:HL55:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 S10")
  field(SCAN, "Passive")
}

record(longin, "HL3B:SBPM:HL55:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C6S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL3B:SBPM:HL55:RSTA_ALH")
}


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

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

record(ao, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:PHI_SEQ")
}

record(ao, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:PSI_SEQ")
}

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

record(ao, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:UOFF_SEQ")
}

record(ao, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:VOFF_SEQ")
}

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

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


record(mbbo, "HL3B:SBPM:HL55:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C6 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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL55")
  field(PINI, "YES")
}

record(stringin, "SBPMHL55:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL3B:SBPM:HL55")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL3B:SBPM:HL55:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "6")
#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, "HL3B:SBPM:HL55:USCL")
  field(INPL, "0")
}

# Switch simulation record HL3B:SBPM:HL55:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL3B:SBPM:HL55:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL55:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL3B:SBPM:HL55:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL3B:SBPM:HL55:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL3B:SBPM:HL55:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C6 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, "HL3B:SBPM:HL55:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL3B:SBPM:HL55:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL3B:SBPM:HL55:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL3B:SBPM:HL55:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:SIM.L     PP")
  field(LNK4, "HL3B:SBPM:HL55:SIM.SCAN  PP")

  field(LNK5, "HL3B:SBPM:HL55:SIM.SCAN  PP")
  field(LNK6, "HL3B:SBPM:HL55:SIM.L     PP")
  field(LNK7, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:UOFF")
	field(DOL2, "HL3B:SBPM:HL55:UOFF")
	field(DOL3, "HL3B:SBPM:HL55:UOFF")
	field(DOL4, "HL3B:SBPM:HL55:UOFF")
	field(DOL5, "HL3B:SBPM:HL55:UOFF")
	field(DOL6, "HL3B:SBPM:HL55:UOFF")
	field(DOL7, "HL3B:SBPM:HL55:UOFF")
	field(DOL8, "HL3B:SBPM:HL55:UOFF")
	field(DOL9, "HL3B:SBPM:HL55:UOFF")
	field(DOLA, "HL3B:SBPM:HL55:UOFF")
	field(LNK1, "HL3B:SBPM:HL55:UOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:UOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:UOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:UOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:UOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:UOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:UOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:UOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:UOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:UOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL55:U.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL55:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:UOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:VOFF")
	field(DOL2, "HL3B:SBPM:HL55:VOFF")
	field(DOL3, "HL3B:SBPM:HL55:VOFF")
	field(DOL4, "HL3B:SBPM:HL55:VOFF")
	field(DOL5, "HL3B:SBPM:HL55:VOFF")
	field(DOL6, "HL3B:SBPM:HL55:VOFF")
	field(DOL7, "HL3B:SBPM:HL55:VOFF")
	field(DOL8, "HL3B:SBPM:HL55:VOFF")
	field(DOL9, "HL3B:SBPM:HL55:VOFF")
	field(DOLA, "HL3B:SBPM:HL55:VOFF")
	field(LNK1, "HL3B:SBPM:HL55:VOFF_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:VOFF_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:VOFF_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:VOFF_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:VOFF_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:VOFF_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:VOFF_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:VOFF_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:VOFF_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:VOFF_SEL")
	field(OUTA, "HL3B:SBPM:HL55:V.AOFF CA")
	field(OUTB, "HL3B:SBPM:HL55:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:VOFF_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:USCL")
	field(DOL2, "HL3B:SBPM:HL55:USCL")
	field(DOL3, "HL3B:SBPM:HL55:USCL")
	field(DOL4, "HL3B:SBPM:HL55:USCL")
	field(DOL5, "HL3B:SBPM:HL55:USCL")
	field(DOL6, "HL3B:SBPM:HL55:USCL")
	field(DOL7, "HL3B:SBPM:HL55:USCL")
	field(DOL8, "HL3B:SBPM:HL55:USCL")
	field(DOL9, "HL3B:SBPM:HL55:USCL")
	field(DOLA, "HL3B:SBPM:HL55:USCL")
	field(LNK1, "HL3B:SBPM:HL55:USCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:USCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:USCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:USCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:USCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:USCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:USCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:USCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:USCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:USCL_SEL")
	field(OUTA, "HL3B:SBPM:HL55:U.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL55:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:USCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:VSCL")
	field(DOL2, "HL3B:SBPM:HL55:VSCL")
	field(DOL3, "HL3B:SBPM:HL55:VSCL")
	field(DOL4, "HL3B:SBPM:HL55:VSCL")
	field(DOL5, "HL3B:SBPM:HL55:VSCL")
	field(DOL6, "HL3B:SBPM:HL55:VSCL")
	field(DOL7, "HL3B:SBPM:HL55:VSCL")
	field(DOL8, "HL3B:SBPM:HL55:VSCL")
	field(DOL9, "HL3B:SBPM:HL55:VSCL")
	field(DOLA, "HL3B:SBPM:HL55:VSCL")
	field(LNK1, "HL3B:SBPM:HL55:VSCL_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:VSCL_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:VSCL_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:VSCL_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:VSCL_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:VSCL_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:VSCL_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:VSCL_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:VSCL_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:VSCL_SEL")
	field(OUTA, "HL3B:SBPM:HL55:V.ASLO CA")
	field(OUTB, "HL3B:SBPM:HL55:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:VSCL_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:PHI")
	field(DOL2, "HL3B:SBPM:HL55:PHI")
	field(DOL3, "HL3B:SBPM:HL55:PHI")
	field(DOL4, "HL3B:SBPM:HL55:PHI")
	field(DOL5, "HL3B:SBPM:HL55:PHI")
	field(DOL6, "HL3B:SBPM:HL55:PHI")
	field(DOL7, "HL3B:SBPM:HL55:PHI")
	field(DOL8, "HL3B:SBPM:HL55:PHI")
	field(DOL9, "HL3B:SBPM:HL55:PHI")
	field(DOLA, "HL3B:SBPM:HL55:PHI")
	field(LNK1, "HL3B:SBPM:HL55:PHI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:PHI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:PHI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:PHI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:PHI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:PHI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:PHI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:PHI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:PHI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:PHI_SEL")
	field(OUTA, "HL3B:SBPM:HL55:CALC.E CA")
	field(OUTB, "HL3B:SBPM:HL55:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:PHI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL3B:SBPM:HL55:PSI")
	field(DOL2, "HL3B:SBPM:HL55:PSI")
	field(DOL3, "HL3B:SBPM:HL55:PSI")
	field(DOL4, "HL3B:SBPM:HL55:PSI")
	field(DOL5, "HL3B:SBPM:HL55:PSI")
	field(DOL6, "HL3B:SBPM:HL55:PSI")
	field(DOL7, "HL3B:SBPM:HL55:PSI")
	field(DOL8, "HL3B:SBPM:HL55:PSI")
	field(DOL9, "HL3B:SBPM:HL55:PSI")
	field(DOLA, "HL3B:SBPM:HL55:PSI")
	field(LNK1, "HL3B:SBPM:HL55:PSI_SEL.A PP")
	field(LNK2, "HL3B:SBPM:HL55:PSI_SEL.B PP")
	field(LNK3, "HL3B:SBPM:HL55:PSI_SEL.C PP")
	field(LNK4, "HL3B:SBPM:HL55:PSI_SEL.D PP")
	field(LNK5, "HL3B:SBPM:HL55:PSI_SEL.E PP")
	field(LNK6, "HL3B:SBPM:HL55:PSI_SEL.F PP")
	field(LNK7, "HL3B:SBPM:HL55:PSI_SEL.G PP")
	field(LNK8, "HL3B:SBPM:HL55:PSI_SEL.H PP")
	field(LNK9, "HL3B:SBPM:HL55:PSI_SEL.I PP")
	field(LNKA, "HL3B:SBPM:HL55:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55: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,  "HL3B:SBPM:HL55:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL3B:SBPM:HL55:PSI_SEL")
	field(OUTA, "HL3B:SBPM:HL55:CALC.F CA")
	field(OUTB, "HL3B:SBPM:HL55:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL3B:SBPM:HL55:PSI_CTRL")
{
	field(INPA, "HL3B:SBPM:HL55:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL3B:SBPM:HL55:PSI_SEL.L PP")
}
record(longout, "HL3B:SBPM:HL55:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL4:SBPM:HL56:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C7 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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C7 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C7 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C7 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, "HL4:SBPM:HL56:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C7 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL4:SBPM:HL56: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, "#C7 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL4:SBPM:HL56: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, "#C7 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, "HL4:SBPM:HL56: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, "#C7 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, "HL4:SBPM:HL56: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, "#C7 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, "HL4:SBPM:HL56: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, "#C7 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(ao, "HL4:SBPM:HL56:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL56:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL4:SBPM:HL56:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL4:SBPM:HL56:ATT1 CP")
  field(INPC, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL4:SBPM:HL56:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL56:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL56:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL4:SBPM:HL56:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL4:SBPM:HL56:RSTA.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL56:TMIT.SEVR MS NPP")
  field(INPC, "HL4:SBPM:HL56:Y.SEVR    MS NPP")
  field(INPD, "HL4:SBPM:HL56:X.SEVR    MS NPP")
  field(INPE, "HL4:SBPM:HL56:TGRN.SEVR MS NPP")
  field(INPF, "HL4:SBPM:HL56:TRED.SEVR MS NPP")
  field(INPG, "HL4:SBPM:HL56:TBLU.SEVR MS NPP")
  field(INPH, "HL4:SBPM:HL56:TYLO.SEVR MS NPP")
  field(INPI, "HL4:SBPM:HL56:GRU.SEVR  MS NPP")
  field(INPJ, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL56:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL56:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL56:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL56:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL4:SBPM:HL56:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL4:SBPM:HL56:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL4:SBPM:HL56:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL4:SBPM:HL56:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "7")
  field(SCAN, "Passive")
}

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

record(ao, "HL4:SBPM:HL56:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C7S0")
  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, "HL4:SBPM:HL56:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 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, "HL4:SBPM:HL56:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL56:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL4:SBPM:HL56:EFX.PROC")
  field(ASG,  "")
  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, "HL4:SBPM:HL56:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C7 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, "HL4:SBPM:HL56:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 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, "HL4:SBPM:HL56:V")
}

record(ai, "HL4:SBPM:HL56:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL4:SBPM:HL56:PINC")
}

record(ai, "HL4:SBPM:HL56:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 S10")
  field(SCAN, "Passive")
}

record(longin, "HL4:SBPM:HL56:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C7S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL4:SBPM:HL56:RSTA_ALH")
}


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

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

record(ao, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:PHI_SEQ")
}

record(ao, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:PSI_SEQ")
}

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

record(ao, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:UOFF_SEQ")
}

record(ao, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:VOFF_SEQ")
}

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

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


record(mbbo, "HL4:SBPM:HL56:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C7 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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL56")
  field(PINI, "YES")
}

record(stringin, "SBPMHL56:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL4:SBPM:HL56")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL4:SBPM:HL56:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "7")
#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, "HL4:SBPM:HL56:USCL")
  field(INPL, "0")
}

# Switch simulation record HL4:SBPM:HL56:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL4:SBPM:HL56:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL56:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL4:SBPM:HL56:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL56:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL4:SBPM:HL56:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C7 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, "HL4:SBPM:HL56:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL4:SBPM:HL56:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL4:SBPM:HL56:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL4:SBPM:HL56:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:SIM.L     PP")
  field(LNK4, "HL4:SBPM:HL56:SIM.SCAN  PP")

  field(LNK5, "HL4:SBPM:HL56:SIM.SCAN  PP")
  field(LNK6, "HL4:SBPM:HL56:SIM.L     PP")
  field(LNK7, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:UOFF")
	field(DOL2, "HL4:SBPM:HL56:UOFF")
	field(DOL3, "HL4:SBPM:HL56:UOFF")
	field(DOL4, "HL4:SBPM:HL56:UOFF")
	field(DOL5, "HL4:SBPM:HL56:UOFF")
	field(DOL6, "HL4:SBPM:HL56:UOFF")
	field(DOL7, "HL4:SBPM:HL56:UOFF")
	field(DOL8, "HL4:SBPM:HL56:UOFF")
	field(DOL9, "HL4:SBPM:HL56:UOFF")
	field(DOLA, "HL4:SBPM:HL56:UOFF")
	field(LNK1, "HL4:SBPM:HL56:UOFF_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:UOFF_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:UOFF_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:UOFF_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:UOFF_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:UOFF_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:UOFF_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:UOFF_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:UOFF_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:UOFF_SEL")
	field(OUTA, "HL4:SBPM:HL56:U.AOFF CA")
	field(OUTB, "HL4:SBPM:HL56:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:UOFF_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:VOFF")
	field(DOL2, "HL4:SBPM:HL56:VOFF")
	field(DOL3, "HL4:SBPM:HL56:VOFF")
	field(DOL4, "HL4:SBPM:HL56:VOFF")
	field(DOL5, "HL4:SBPM:HL56:VOFF")
	field(DOL6, "HL4:SBPM:HL56:VOFF")
	field(DOL7, "HL4:SBPM:HL56:VOFF")
	field(DOL8, "HL4:SBPM:HL56:VOFF")
	field(DOL9, "HL4:SBPM:HL56:VOFF")
	field(DOLA, "HL4:SBPM:HL56:VOFF")
	field(LNK1, "HL4:SBPM:HL56:VOFF_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:VOFF_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:VOFF_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:VOFF_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:VOFF_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:VOFF_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:VOFF_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:VOFF_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:VOFF_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:VOFF_SEL")
	field(OUTA, "HL4:SBPM:HL56:V.AOFF CA")
	field(OUTB, "HL4:SBPM:HL56:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:VOFF_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:USCL")
	field(DOL2, "HL4:SBPM:HL56:USCL")
	field(DOL3, "HL4:SBPM:HL56:USCL")
	field(DOL4, "HL4:SBPM:HL56:USCL")
	field(DOL5, "HL4:SBPM:HL56:USCL")
	field(DOL6, "HL4:SBPM:HL56:USCL")
	field(DOL7, "HL4:SBPM:HL56:USCL")
	field(DOL8, "HL4:SBPM:HL56:USCL")
	field(DOL9, "HL4:SBPM:HL56:USCL")
	field(DOLA, "HL4:SBPM:HL56:USCL")
	field(LNK1, "HL4:SBPM:HL56:USCL_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:USCL_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:USCL_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:USCL_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:USCL_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:USCL_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:USCL_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:USCL_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:USCL_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:USCL_SEL")
	field(OUTA, "HL4:SBPM:HL56:U.ASLO CA")
	field(OUTB, "HL4:SBPM:HL56:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:USCL_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:VSCL")
	field(DOL2, "HL4:SBPM:HL56:VSCL")
	field(DOL3, "HL4:SBPM:HL56:VSCL")
	field(DOL4, "HL4:SBPM:HL56:VSCL")
	field(DOL5, "HL4:SBPM:HL56:VSCL")
	field(DOL6, "HL4:SBPM:HL56:VSCL")
	field(DOL7, "HL4:SBPM:HL56:VSCL")
	field(DOL8, "HL4:SBPM:HL56:VSCL")
	field(DOL9, "HL4:SBPM:HL56:VSCL")
	field(DOLA, "HL4:SBPM:HL56:VSCL")
	field(LNK1, "HL4:SBPM:HL56:VSCL_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:VSCL_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:VSCL_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:VSCL_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:VSCL_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:VSCL_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:VSCL_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:VSCL_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:VSCL_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:VSCL_SEL")
	field(OUTA, "HL4:SBPM:HL56:V.ASLO CA")
	field(OUTB, "HL4:SBPM:HL56:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:VSCL_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:PHI")
	field(DOL2, "HL4:SBPM:HL56:PHI")
	field(DOL3, "HL4:SBPM:HL56:PHI")
	field(DOL4, "HL4:SBPM:HL56:PHI")
	field(DOL5, "HL4:SBPM:HL56:PHI")
	field(DOL6, "HL4:SBPM:HL56:PHI")
	field(DOL7, "HL4:SBPM:HL56:PHI")
	field(DOL8, "HL4:SBPM:HL56:PHI")
	field(DOL9, "HL4:SBPM:HL56:PHI")
	field(DOLA, "HL4:SBPM:HL56:PHI")
	field(LNK1, "HL4:SBPM:HL56:PHI_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:PHI_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:PHI_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:PHI_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:PHI_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:PHI_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:PHI_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:PHI_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:PHI_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:PHI_SEL")
	field(OUTA, "HL4:SBPM:HL56:CALC.E CA")
	field(OUTB, "HL4:SBPM:HL56:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:PHI_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL56:PSI")
	field(DOL2, "HL4:SBPM:HL56:PSI")
	field(DOL3, "HL4:SBPM:HL56:PSI")
	field(DOL4, "HL4:SBPM:HL56:PSI")
	field(DOL5, "HL4:SBPM:HL56:PSI")
	field(DOL6, "HL4:SBPM:HL56:PSI")
	field(DOL7, "HL4:SBPM:HL56:PSI")
	field(DOL8, "HL4:SBPM:HL56:PSI")
	field(DOL9, "HL4:SBPM:HL56:PSI")
	field(DOLA, "HL4:SBPM:HL56:PSI")
	field(LNK1, "HL4:SBPM:HL56:PSI_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL56:PSI_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL56:PSI_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL56:PSI_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL56:PSI_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL56:PSI_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL56:PSI_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL56:PSI_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL56:PSI_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL56:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56: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,  "HL4:SBPM:HL56:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL56:PSI_SEL")
	field(OUTA, "HL4:SBPM:HL56:CALC.F CA")
	field(OUTB, "HL4:SBPM:HL56:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL56:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL56:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL56:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL56:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! 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, "HL4:SBPM:HL57:GRN") {
  field(DESC, "GRN Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C8 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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:RED") {
  field(DESC, "RED Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C8 S1")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:BLU") {
  field(DESC, "BLU Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C8 S2")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:YLO") {
  field(DESC, "YLO Strip Amplitude")
  field(DTYP, "Raw Bpm Signal")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "#C8 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, "HL4:SBPM:HL57:REDW") {
  field(DESC, "Raw CAL RED Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP, "#C8 S1")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "1 second")
}

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

record(waveform, "HL4:SBPM:HL57: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, "#C8 S7")
  field(NELM, "512")
  field(FTVL, "SHORT")
  field(EGU, "Counts")
  field(HOPR, "32768")
  field(LOPR, "-32767")
  field(SCAN, "Passive")
}

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

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

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

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

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

record(ai, "HL4:SBPM:HL57: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, "#C8 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, "HL4:SBPM:HL57: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, "#C8 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, "HL4:SBPM:HL57: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, "#C8 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, "HL4:SBPM:HL57: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, "#C8 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(ao, "HL4:SBPM:HL57:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL57:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  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, "HL4:SBPM:HL57:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL4:SBPM:HL57:ATT1 CP")
  field(INPC, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

record(ao,    "HL4:SBPM:HL57:ATT2SIMP") {
	field(DESC, "ATT2 Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL57:ATT2   CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:ASIM") {
  field(DESC, "Q Simul Attenuator")
  field(DTYP, "Soft Channel")
  field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:WSIM") {
  field(DESC, "BPM W Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL57:SIM.G PP")
  field(VAL, "0.07")
  field(EGU, "%")
  field(PINI, "YES")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "0.25")
}


record(sel, "HL4:SBPM:HL57:STA") {
  field(DESC, "Status Summary")
  field(SELM, "High Signal")
  field(INPA, "HL4:SBPM:HL57:RSTA.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL57:TMIT.SEVR MS NPP")
  field(INPC, "HL4:SBPM:HL57:Y.SEVR    MS NPP")
  field(INPD, "HL4:SBPM:HL57:X.SEVR    MS NPP")
  field(INPE, "HL4:SBPM:HL57:TGRN.SEVR MS NPP")
  field(INPF, "HL4:SBPM:HL57:TRED.SEVR MS NPP")
  field(INPG, "HL4:SBPM:HL57:TBLU.SEVR MS NPP")
  field(INPH, "HL4:SBPM:HL57:TYLO.SEVR MS NPP")
  field(INPI, "HL4:SBPM:HL57:GRU.SEVR  MS NPP")
  field(INPJ, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:ATTO") {
  field(DESC, "AFE Tot. Att. Offset")
# fetched via inlink
#field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:CLAO") {
  field(DESC, "AFE Cal. Att. Offset")
# fetched via inlink
#field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL57:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL57:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL57:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL57:CHK.SEVR MS NPP")
}

# snapshot PV for the bpm values display
record(ai, "HL4:SBPM:HL57:GRN_SLOW") {
  field(DESC, "GRN snapshot for display")
  field(INP, "HL4:SBPM:HL57:GRN NPP MS")
  field(EGU, "raw")
  field(SCAN, "1 second")
  field(FLNK, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:RED_SLOW") {
  field(DESC, "RED snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL4:SBPM:HL57:RED NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:BLU_SLOW") {
  field(DESC, "BLU snapshot for display")
# 'card' selects PAD number, 'signal' selects strip
  field(INP, "HL4:SBPM:HL57:BLU NPP MS")
  field(EGU, "raw")
  field(SCAN, "Passive")
  field(FLNK, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:YLO_SLOW") {
  field(DESC, "YLO snapshot for display")
  field(INP, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "8")
  field(SCAN, "Passive")
}

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

record(ao, "HL4:SBPM:HL57:UDR_THRES") {
  field(DESC, "Detection Underrange Threshold")
  field(DTYP, "Bpm Parameters")
  field(OUT,  "#C8S0")
  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, "HL4:SBPM:HL57:X") {
  field(DESC, "X Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 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, "HL4:SBPM:HL57:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL57:TMIT") {
  field(DESC, "Charge Estimate")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 S13")
  field(EGU, "Nel")
  field(PREC, "3")
  field(LOPR, "0")
  field(HOPR, "1E11")
# FLINK into BSA
  field(FLNK, "HL4:SBPM:HL57:EFX.PROC")
  field(ASG,  "")
  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, "HL4:SBPM:HL57:RWAV") {
  field(DESC, "Raw BPM Data")
  field(DTYP, "WavBuf")
# 'signal' number selects 'beam', 'calX', 'calY'
  field(INP,  "#C8 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, "HL4:SBPM:HL57:U") {
  field(DESC, "Raw U Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 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, "HL4:SBPM:HL57:V")
}

record(ai, "HL4:SBPM:HL57:V") {
  field(DESC, "Raw V Position")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 S9")
  field(SCAN, "Passive")
  field(PREC, "5")
  field(EGU,  "mm")
  field(LOPR, "-0.7")
  field(HOPR, "+0.7")
  field(FLNK, "HL4:SBPM:HL57:PINC")
}

record(ai, "HL4:SBPM:HL57:PINC") {
  field(DESC, "Pin Cushion Corr.")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 S10")
  field(SCAN, "Passive")
}

record(longin, "HL4:SBPM:HL57:RSTA") {
  field(DESC, "Status of Raw Processor")
  field(DTYP, "Bpm Raw Status")
  field(INP, "#C8S0")
  field(SCAN, "1 second")
  field(LOLO, "-1")
  field(HIHI, "+1")
  field(HHSV, "INVALID")
  field(LLSV, "INVALID")
  field(FLNK, "HL4:SBPM:HL57:RSTA_ALH")
}


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

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

record(ao, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:PHI_SEQ")
}

record(ao, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:PSI_SEQ")
}

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

record(ao, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:UOFF_SEQ")
}

record(ao, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:VOFF_SEQ")
}

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

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


record(mbbo, "HL4:SBPM:HL57:ACCESS") {
  field(DESC, "BPM On Line")
  field(DTYP, "StreamSwitch")
  field(OUT, "#C8 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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL57")
  field(PINI, "YES")
}

record(stringin, "SBPMHL57:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL4:SBPM:HL57")
  field(PINI, "YES")
}

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

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

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

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

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

record(calcout, "HL4:SBPM:HL57:SIM") {
  field(DESC, "BPM Pos. Simulation")
  field(DTYP, "Strip Signal Simulator")
  field(OUT, "8")
#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, "HL4:SBPM:HL57:USCL")
  field(INPL, "0")
}

# Switch simulation record HL4:SBPM:HL57:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

record(mbbo, "HL4:SBPM:HL57:SIMC") {
  field(DESC, "Stripl Sim Ctl")
  field(DTYP, "Raw Soft Channel")
  field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:XSIM") {
  field(DESC, "BPM X Pos. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL57:SIM.B PP")
  field(VAL, "0.5")
  field(EGU, "mm")
  field(PINI, "YES")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
}

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

record(ao, "HL4:SBPM:HL57:QSIM") {
  field(DESC, "BPM Q Simul.")
  field(DTYP, "Raw Soft Channel")
  field(OUT, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:ROTS") {
  field(DESC, "BPM Rot. Simul.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL57:SIM.E PP")
  field(VAL, "0.")
  field(EGU, "deg")
  field(PINI, "YES")
  field(PREC, "1")
  field(LOPR, "-180")
}

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

record(aao, "HL4:SBPM:HL57:DIGISIMW") {
  field(DESC, "VME Digi Sim. Waveform")
  field(DTYP, "VmeDigi Sim Wav")
  field(OUT,  "#C8 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, "HL4:SBPM:HL57:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

# 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, "HL4:SBPM:HL57:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL4:SBPM:HL57:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL4:SBPM:HL57:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


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

record(bi, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:SIM.L     PP")
  field(LNK4, "HL4:SBPM:HL57:SIM.SCAN  PP")

  field(LNK5, "HL4:SBPM:HL57:SIM.SCAN  PP")
  field(LNK6, "HL4:SBPM:HL57:SIM.L     PP")
  field(LNK7, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:UOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:UOFF")
	field(DOL2, "HL4:SBPM:HL57:UOFF")
	field(DOL3, "HL4:SBPM:HL57:UOFF")
	field(DOL4, "HL4:SBPM:HL57:UOFF")
	field(DOL5, "HL4:SBPM:HL57:UOFF")
	field(DOL6, "HL4:SBPM:HL57:UOFF")
	field(DOL7, "HL4:SBPM:HL57:UOFF")
	field(DOL8, "HL4:SBPM:HL57:UOFF")
	field(DOL9, "HL4:SBPM:HL57:UOFF")
	field(DOLA, "HL4:SBPM:HL57:UOFF")
	field(LNK1, "HL4:SBPM:HL57:UOFF_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:UOFF_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:UOFF_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:UOFF_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:UOFF_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:UOFF_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:UOFF_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:UOFF_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:UOFF_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:UOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:UOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:UOFF_SEL")
	field(OUTA, "HL4:SBPM:HL57:U.AOFF CA")
	field(OUTB, "HL4:SBPM:HL57:UOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:UOFF_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:VOFF_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:VOFF")
	field(DOL2, "HL4:SBPM:HL57:VOFF")
	field(DOL3, "HL4:SBPM:HL57:VOFF")
	field(DOL4, "HL4:SBPM:HL57:VOFF")
	field(DOL5, "HL4:SBPM:HL57:VOFF")
	field(DOL6, "HL4:SBPM:HL57:VOFF")
	field(DOL7, "HL4:SBPM:HL57:VOFF")
	field(DOL8, "HL4:SBPM:HL57:VOFF")
	field(DOL9, "HL4:SBPM:HL57:VOFF")
	field(DOLA, "HL4:SBPM:HL57:VOFF")
	field(LNK1, "HL4:SBPM:HL57:VOFF_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:VOFF_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:VOFF_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:VOFF_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:VOFF_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:VOFF_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:VOFF_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:VOFF_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:VOFF_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:VOFF_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:VOFF_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:VOFF_SEL")
	field(OUTA, "HL4:SBPM:HL57:V.AOFF CA")
	field(OUTB, "HL4:SBPM:HL57:VOFF PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:VOFF_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:USCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:USCL")
	field(DOL2, "HL4:SBPM:HL57:USCL")
	field(DOL3, "HL4:SBPM:HL57:USCL")
	field(DOL4, "HL4:SBPM:HL57:USCL")
	field(DOL5, "HL4:SBPM:HL57:USCL")
	field(DOL6, "HL4:SBPM:HL57:USCL")
	field(DOL7, "HL4:SBPM:HL57:USCL")
	field(DOL8, "HL4:SBPM:HL57:USCL")
	field(DOL9, "HL4:SBPM:HL57:USCL")
	field(DOLA, "HL4:SBPM:HL57:USCL")
	field(LNK1, "HL4:SBPM:HL57:USCL_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:USCL_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:USCL_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:USCL_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:USCL_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:USCL_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:USCL_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:USCL_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:USCL_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:USCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:USCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:USCL_SEL")
	field(OUTA, "HL4:SBPM:HL57:U.ASLO CA")
	field(OUTB, "HL4:SBPM:HL57:USCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:USCL_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:VSCL_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:VSCL")
	field(DOL2, "HL4:SBPM:HL57:VSCL")
	field(DOL3, "HL4:SBPM:HL57:VSCL")
	field(DOL4, "HL4:SBPM:HL57:VSCL")
	field(DOL5, "HL4:SBPM:HL57:VSCL")
	field(DOL6, "HL4:SBPM:HL57:VSCL")
	field(DOL7, "HL4:SBPM:HL57:VSCL")
	field(DOL8, "HL4:SBPM:HL57:VSCL")
	field(DOL9, "HL4:SBPM:HL57:VSCL")
	field(DOLA, "HL4:SBPM:HL57:VSCL")
	field(LNK1, "HL4:SBPM:HL57:VSCL_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:VSCL_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:VSCL_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:VSCL_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:VSCL_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:VSCL_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:VSCL_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:VSCL_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:VSCL_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:VSCL_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:VSCL_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:VSCL_SEL")
	field(OUTA, "HL4:SBPM:HL57:V.ASLO CA")
	field(OUTB, "HL4:SBPM:HL57:VSCL PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:VSCL_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:PHI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:PHI")
	field(DOL2, "HL4:SBPM:HL57:PHI")
	field(DOL3, "HL4:SBPM:HL57:PHI")
	field(DOL4, "HL4:SBPM:HL57:PHI")
	field(DOL5, "HL4:SBPM:HL57:PHI")
	field(DOL6, "HL4:SBPM:HL57:PHI")
	field(DOL7, "HL4:SBPM:HL57:PHI")
	field(DOL8, "HL4:SBPM:HL57:PHI")
	field(DOL9, "HL4:SBPM:HL57:PHI")
	field(DOLA, "HL4:SBPM:HL57:PHI")
	field(LNK1, "HL4:SBPM:HL57:PHI_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:PHI_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:PHI_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:PHI_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:PHI_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:PHI_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:PHI_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:PHI_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:PHI_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:PHI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:PHI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:PHI_SEL")
	field(OUTA, "HL4:SBPM:HL57:CALC.E CA")
	field(OUTB, "HL4:SBPM:HL57:PHI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:PHI_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:PSI_SEQ")
{
	field(DESC, "Propagate Parm -> SEL")
	field(DOL1, "HL4:SBPM:HL57:PSI")
	field(DOL2, "HL4:SBPM:HL57:PSI")
	field(DOL3, "HL4:SBPM:HL57:PSI")
	field(DOL4, "HL4:SBPM:HL57:PSI")
	field(DOL5, "HL4:SBPM:HL57:PSI")
	field(DOL6, "HL4:SBPM:HL57:PSI")
	field(DOL7, "HL4:SBPM:HL57:PSI")
	field(DOL8, "HL4:SBPM:HL57:PSI")
	field(DOL9, "HL4:SBPM:HL57:PSI")
	field(DOLA, "HL4:SBPM:HL57:PSI")
	field(LNK1, "HL4:SBPM:HL57:PSI_SEL.A PP")
	field(LNK2, "HL4:SBPM:HL57:PSI_SEL.B PP")
	field(LNK3, "HL4:SBPM:HL57:PSI_SEL.C PP")
	field(LNK4, "HL4:SBPM:HL57:PSI_SEL.D PP")
	field(LNK5, "HL4:SBPM:HL57:PSI_SEL.E PP")
	field(LNK6, "HL4:SBPM:HL57:PSI_SEL.F PP")
	field(LNK7, "HL4:SBPM:HL57:PSI_SEL.G PP")
	field(LNK8, "HL4:SBPM:HL57:PSI_SEL.H PP")
	field(LNK9, "HL4:SBPM:HL57:PSI_SEL.I PP")
	field(LNKA, "HL4:SBPM:HL57:PSI_SEL.J PP")
	field(SELM, "Specified")
	field(SELL, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57: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,  "HL4:SBPM:HL57:PSI_PROP")
{
	field(OMSL, "closed_loop")
	field(DOL,  "HL4:SBPM:HL57:PSI_SEL")
	field(OUTA, "HL4:SBPM:HL57:CALC.F CA")
	field(OUTB, "HL4:SBPM:HL57:PSI PP")
}

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL57:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL57:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL57:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL57:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
# 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.
#     HL3B:SBPM:HL51:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:SBPM:HL51:ACTL.DOL <---- HL3B:SBPM:HL51:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL51:ATTOL.DOL<---- HL3B:SBPM:HL51:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL51:CLAOL.DOL<---- HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE0+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL51:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE0+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, "HL3B:SBPM:HL51:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE0+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:SBPM:HL51:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:SBPM:HL51:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE0+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, "HL3B:SBPM:HL51:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE0+6,qspiAfe")
}

record(mbbo,   "HL3B:SBPM:HL51:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE0+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, "HL3B:SBPM:HL51:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:SBPM:HL51:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:SBPM:HL51:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:SBPM:HL51:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:SBPM:HL51:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:SBPM:HL51:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:SBPM:HL51:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:SBPM:HL51:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:SBPM:HL51:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:SBPM:HL51:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:SBPM:HL51:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:SBPM:HL51:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:SBPM:HL51:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:SBPM:HL51:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:SBPM:HL51:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:SBPM:HL51:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:SBPM:HL51:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:SBPM:HL51:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:SBPM:HL51:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:SBPM:HL51:CLAO.HOPR")
        field(FLNK, "HL3B:SBPM:HL51:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:SBPM:HL51:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:SBPM:HL51:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:SBPM:HL51:ATT1 = A1
#  HL3B:SBPM:HL51:ATT2 = A2
#  HL3B:SBPM:HL51:CALA = CA
#

record(sub, "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL51:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL51: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, "HL3B:SBPM:HL51:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL51:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL51:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL51:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE0+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, "HL3B:SBPM:HL51:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE0+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, "HL3B:SBPM:HL51:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE0+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")
}
# 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.
#     HL3B:EBPM:HL3A:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:EBPM:HL3A:ACTL.DOL <---- HL3B:EBPM:HL3A:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:EBPM:HL3A:ATTOL.DOL<---- HL3B:EBPM:HL3A:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:EBPM:HL3A:CLAOL.DOL<---- HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:EBPM:HL3A:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+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, "HL3B:EBPM:HL3A:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE1+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:EBPM:HL3A:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:EBPM:HL3A:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+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, "HL3B:EBPM:HL3A:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+6,qspiAfe")
}

record(mbbo,   "HL3B:EBPM:HL3A:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE1+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, "HL3B:EBPM:HL3A:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:EBPM:HL3A:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:EBPM:HL3A:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:EBPM:HL3A:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:EBPM:HL3A:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:EBPM:HL3A:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:EBPM:HL3A:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:EBPM:HL3A:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:EBPM:HL3A:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:EBPM:HL3A:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:EBPM:HL3A:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:EBPM:HL3A:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:EBPM:HL3A:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:EBPM:HL3A:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:EBPM:HL3A:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:EBPM:HL3A:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:EBPM:HL3A:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:EBPM:HL3A:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:EBPM:HL3A:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:EBPM:HL3A:CLAO.HOPR")
        field(FLNK, "HL3B:EBPM:HL3A:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:EBPM:HL3A:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:EBPM:HL3A:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:EBPM:HL3A:ATT1 = A1
#  HL3B:EBPM:HL3A:ATT2 = A2
#  HL3B:EBPM:HL3A:CALA = CA
#

record(sub, "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3A:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3A: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, "HL3B:EBPM:HL3A:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3A:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3A:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:EBPM:HL3A:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE1+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, "HL3B:EBPM:HL3A:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE1+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, "HL3B:EBPM:HL3A:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE1+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")
}
# 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.
#     HL3B:EBPM:HL3B:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:EBPM:HL3B:ACTL.DOL <---- HL3B:EBPM:HL3B:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:EBPM:HL3B:ATTOL.DOL<---- HL3B:EBPM:HL3B:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:EBPM:HL3B:CLAOL.DOL<---- HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE2+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:EBPM:HL3B:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE2+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, "HL3B:EBPM:HL3B:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE2+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:EBPM:HL3B:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:EBPM:HL3B:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE2+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, "HL3B:EBPM:HL3B:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE2+6,qspiAfe")
}

record(mbbo,   "HL3B:EBPM:HL3B:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE2+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, "HL3B:EBPM:HL3B:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:EBPM:HL3B:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:EBPM:HL3B:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:EBPM:HL3B:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:EBPM:HL3B:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:EBPM:HL3B:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:EBPM:HL3B:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:EBPM:HL3B:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:EBPM:HL3B:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:EBPM:HL3B:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:EBPM:HL3B:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:EBPM:HL3B:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:EBPM:HL3B:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:EBPM:HL3B:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:EBPM:HL3B:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:EBPM:HL3B:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:EBPM:HL3B:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:EBPM:HL3B:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:EBPM:HL3B:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:EBPM:HL3B:CLAO.HOPR")
        field(FLNK, "HL3B:EBPM:HL3B:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:EBPM:HL3B:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:EBPM:HL3B:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:EBPM:HL3B:ATT1 = A1
#  HL3B:EBPM:HL3B:ATT2 = A2
#  HL3B:EBPM:HL3B:CALA = CA
#

record(sub, "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3B:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3B: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, "HL3B:EBPM:HL3B:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:EBPM:HL3B:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:EBPM:HL3B:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:EBPM:HL3B:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE2+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, "HL3B:EBPM:HL3B:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE2+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, "HL3B:EBPM:HL3B:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE2+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")
}
# 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.
#     HL3B:SBPM:HL52:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:SBPM:HL52:ACTL.DOL <---- HL3B:SBPM:HL52:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL52:ATTOL.DOL<---- HL3B:SBPM:HL52:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL52:CLAOL.DOL<---- HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE3+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL52:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE3+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, "HL3B:SBPM:HL52:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE3+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:SBPM:HL52:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:SBPM:HL52:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE3+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, "HL3B:SBPM:HL52:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE3+6,qspiAfe")
}

record(mbbo,   "HL3B:SBPM:HL52:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE3+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, "HL3B:SBPM:HL52:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:SBPM:HL52:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:SBPM:HL52:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:SBPM:HL52:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:SBPM:HL52:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:SBPM:HL52:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:SBPM:HL52:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:SBPM:HL52:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:SBPM:HL52:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:SBPM:HL52:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:SBPM:HL52:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:SBPM:HL52:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:SBPM:HL52:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:SBPM:HL52:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:SBPM:HL52:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:SBPM:HL52:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:SBPM:HL52:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:SBPM:HL52:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:SBPM:HL52:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:SBPM:HL52:CLAO.HOPR")
        field(FLNK, "HL3B:SBPM:HL52:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:SBPM:HL52:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:SBPM:HL52:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:SBPM:HL52:ATT1 = A1
#  HL3B:SBPM:HL52:ATT2 = A2
#  HL3B:SBPM:HL52:CALA = CA
#

record(sub, "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL52:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL52: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, "HL3B:SBPM:HL52:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL52:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL52:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL52:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE3+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, "HL3B:SBPM:HL52:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE3+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, "HL3B:SBPM:HL52:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE3+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")
}
# 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.
#     HL3B:SBPM:HL53:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:SBPM:HL53:ACTL.DOL <---- HL3B:SBPM:HL53:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL53:ATTOL.DOL<---- HL3B:SBPM:HL53:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL53:CLAOL.DOL<---- HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE4+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL53:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE4+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, "HL3B:SBPM:HL53:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE4+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:SBPM:HL53:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:SBPM:HL53:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE4+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, "HL3B:SBPM:HL53:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE4+6,qspiAfe")
}

record(mbbo,   "HL3B:SBPM:HL53:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE4+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, "HL3B:SBPM:HL53:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:SBPM:HL53:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:SBPM:HL53:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:SBPM:HL53:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:SBPM:HL53:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:SBPM:HL53:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:SBPM:HL53:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:SBPM:HL53:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:SBPM:HL53:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:SBPM:HL53:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:SBPM:HL53:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:SBPM:HL53:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:SBPM:HL53:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:SBPM:HL53:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:SBPM:HL53:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:SBPM:HL53:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:SBPM:HL53:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:SBPM:HL53:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:SBPM:HL53:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:SBPM:HL53:CLAO.HOPR")
        field(FLNK, "HL3B:SBPM:HL53:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:SBPM:HL53:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:SBPM:HL53:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:SBPM:HL53:ATT1 = A1
#  HL3B:SBPM:HL53:ATT2 = A2
#  HL3B:SBPM:HL53:CALA = CA
#

record(sub, "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL53:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL53: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, "HL3B:SBPM:HL53:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL53:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL53:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL53:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE4+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, "HL3B:SBPM:HL53:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE4+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, "HL3B:SBPM:HL53:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE4+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")
}
# 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.
#     HL3B:SBPM:HL54:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:SBPM:HL54:ACTL.DOL <---- HL3B:SBPM:HL54:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL54:ATTOL.DOL<---- HL3B:SBPM:HL54:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL54:CLAOL.DOL<---- HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE5+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL54:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE5+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, "HL3B:SBPM:HL54:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE5+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:SBPM:HL54:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:SBPM:HL54:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE5+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, "HL3B:SBPM:HL54:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE5+6,qspiAfe")
}

record(mbbo,   "HL3B:SBPM:HL54:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE5+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, "HL3B:SBPM:HL54:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:SBPM:HL54:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:SBPM:HL54:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:SBPM:HL54:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:SBPM:HL54:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:SBPM:HL54:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:SBPM:HL54:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:SBPM:HL54:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:SBPM:HL54:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:SBPM:HL54:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:SBPM:HL54:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:SBPM:HL54:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:SBPM:HL54:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:SBPM:HL54:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:SBPM:HL54:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:SBPM:HL54:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:SBPM:HL54:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:SBPM:HL54:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:SBPM:HL54:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:SBPM:HL54:CLAO.HOPR")
        field(FLNK, "HL3B:SBPM:HL54:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:SBPM:HL54:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:SBPM:HL54:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:SBPM:HL54:ATT1 = A1
#  HL3B:SBPM:HL54:ATT2 = A2
#  HL3B:SBPM:HL54:CALA = CA
#

record(sub, "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL54:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL54: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, "HL3B:SBPM:HL54:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL54:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL54:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL54:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE5+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, "HL3B:SBPM:HL54:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE5+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, "HL3B:SBPM:HL54:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE5+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")
}
# 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.
#     HL3B:SBPM:HL55:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL3B:SBPM:HL55:ACTL.DOL <---- HL3B:SBPM:HL55:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL55:ATTOL.DOL<---- HL3B:SBPM:HL55:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL3B:SBPM:HL55:CLAOL.DOL<---- HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE6+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL55:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE6+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, "HL3B:SBPM:HL55:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE6+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL3B:SBPM:HL55:ATTINIT")
}

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

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

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

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

record(longout, "HL3B:SBPM:HL55:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE6+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, "HL3B:SBPM:HL55:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE6+6,qspiAfe")
}

record(mbbo,   "HL3B:SBPM:HL55:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE6+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, "HL3B:SBPM:HL55:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL3B:SBPM:HL55:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL3B:SBPM:HL55:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL3B:SBPM:HL55:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL3B:SBPM:HL55:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL3B:SBPM:HL55:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL3B:SBPM:HL55:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL3B:SBPM:HL55:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL3B:SBPM:HL55:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL3B:SBPM:HL55:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL3B:SBPM:HL55:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL3B:SBPM:HL55:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL3B:SBPM:HL55:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL3B:SBPM:HL55:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL3B:SBPM:HL55:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL3B:SBPM:HL55:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL3B:SBPM:HL55:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL3B:SBPM:HL55:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL3B:SBPM:HL55:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL3B:SBPM:HL55:CLAO.HOPR")
        field(FLNK, "HL3B:SBPM:HL55:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL3B:SBPM:HL55:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL3B:SBPM:HL55:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL3B:SBPM:HL55:ATT1 = A1
#  HL3B:SBPM:HL55:ATT2 = A2
#  HL3B:SBPM:HL55:CALA = CA
#

record(sub, "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL55:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL55: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, "HL3B:SBPM:HL55:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL3B:SBPM:HL55:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL3B:SBPM:HL55:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL3B:SBPM:HL55:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE6+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, "HL3B:SBPM:HL55:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE6+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, "HL3B:SBPM:HL55:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE6+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")
}
# 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.
#     HL4:SBPM:HL56:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL56:ACTL.DOL <---- HL4:SBPM:HL56:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL56:ATTOL.DOL<---- HL4:SBPM:HL56:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL56:CLAOL.DOL<---- HL4:SBPM:HL56: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, "HL4:SBPM:HL56:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE7+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL4:SBPM:HL56:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE7+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, "HL4:SBPM:HL56:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE7+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL4:SBPM:HL56:ATTINIT")
}

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

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

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

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

record(longout, "HL4:SBPM:HL56:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE7+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, "HL4:SBPM:HL56:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE7+6,qspiAfe")
}

record(mbbo,   "HL4:SBPM:HL56:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE7+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, "HL4:SBPM:HL56:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL4:SBPM:HL56:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL4:SBPM:HL56:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL4:SBPM:HL56:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL4:SBPM:HL56:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL4:SBPM:HL56:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL4:SBPM:HL56:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL4:SBPM:HL56:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL4:SBPM:HL56:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL4:SBPM:HL56:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL4:SBPM:HL56:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL4:SBPM:HL56:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL4:SBPM:HL56:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL4:SBPM:HL56:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL4:SBPM:HL56:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL4:SBPM:HL56:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL4:SBPM:HL56:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL4:SBPM:HL56:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL4:SBPM:HL56:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL4:SBPM:HL56:CLAO.HOPR")
        field(FLNK, "HL4:SBPM:HL56:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL56:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL56:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL4:SBPM:HL56:ATT1 = A1
#  HL4:SBPM:HL56:ATT2 = A2
#  HL4:SBPM:HL56:CALA = CA
#

record(sub, "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL56:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL56: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, "HL4:SBPM:HL56:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL56:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL56:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL4:SBPM:HL56:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE7+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, "HL4:SBPM:HL56:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE7+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, "HL4:SBPM:HL56:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE7+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")
}
# 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.
#     HL4:SBPM:HL57:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL57:ACTL.DOL <---- HL4:SBPM:HL57:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL57:ATTOL.DOL<---- HL4:SBPM:HL57:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL57:CLAOL.DOL<---- HL4:SBPM:HL57: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, "HL4:SBPM:HL57:CALA") {
	field(DESC, "AFE Cal. Att.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE8+1,qspiAfe")
	field(LOPR, "0")
	field(HOPR, "31")
	field(DRVL, "6")
	field(DRVH, "31")
	field(EGU,  "dB")
}

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

record(longout, "HL4:SBPM:HL57:ATT2") {
	field(DESC, "AFE Att. 2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE8+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, "HL4:SBPM:HL57:VERS") {
	field(DESC, "AFE Firmware Vers.")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(INP,  "#C0S0@AFE8+5,qspiAfe")
	field(LOLO, "3")
	field(LLSV, "MAJOR")
	field(PINI, "YES")
	field(FLNK, "HL4:SBPM:HL57:ATTINIT")
}

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

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

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

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

record(longout, "HL4:SBPM:HL57:R2DL") {
	field(DESC, "Ctrl Sw. -> RF2")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE8+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, "HL4:SBPM:HL57:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE8+6,qspiAfe")
}

record(mbbo,   "HL4:SBPM:HL57:CALM") {
        field(DESC, "AFE Cal. Mode")
        field(DTYP, "BusAddress")
        field(OUT,  "#C0S0@AFE8+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, "HL4:SBPM:HL57:ATTINIT") {
        field(DESC, "Set up AFE att limits")
        field(SNAM, "subAttSetup")
        field(FTA,  "LONG")
        field(INPA, "HL4:SBPM:HL57:VERS")
        field(FTVA, "LONG")
        field(OUTA, "HL4:SBPM:HL57:ATT1.HOPR")
        field(FTVB, "LONG")
        field(OUTB, "HL4:SBPM:HL57:ATT1.DRVH")
        field(FTVC, "LONG")
        field(OUTC, "HL4:SBPM:HL57:ATT2.HOPR")
        field(FTVD, "LONG")
        field(OUTD, "HL4:SBPM:HL57:ATT2.DRVH")
        field(FTVE, "LONG")
        field(OUTE, "HL4:SBPM:HL57:ATT.HOPR")
        field(FTVF, "LONG")
        field(OUTF, "HL4:SBPM:HL57:ATT.DRVH")
        field(FTVG, "LONG")
        field(OUTG, "HL4:SBPM:HL57:ATT.VAL")
        field(FTVH, "LONG")
        field(OUTH, "HL4:SBPM:HL57:ATTC.D")
        field(FTVI, "LONG")
        field(OUTI, "HL4:SBPM:HL57:ATTC.E")
        field(FTVJ, "LONG")
        field(OUTJ, "HL4:SBPM:HL57:ATTC.F")
        field(FTVK, "LONG")
        field(OUTK, "HL4:SBPM:HL57:ATTO.DRVL")
        field(FTVL, "LONG")
        field(OUTL, "HL4:SBPM:HL57:ATTO.LOPR")
        field(FTVM, "LONG")
        field(OUTM, "HL4:SBPM:HL57:ATTO.DRVH")
        field(FTVN, "LONG")
        field(OUTN, "HL4:SBPM:HL57:ATTO.HOPR")
        field(FTVO, "LONG")
        field(OUTO, "HL4:SBPM:HL57:CLAO.DRVL")
        field(FTVP, "LONG")
        field(OUTP, "HL4:SBPM:HL57:CLAO.LOPR")
        field(FTVQ, "LONG")
        field(OUTQ, "HL4:SBPM:HL57:CLAO.DRVH")
        field(FTVR, "LONG")
        field(OUTR, "HL4:SBPM:HL57:CLAO.HOPR")
        field(FLNK, "HL4:SBPM:HL57:ATT")
}

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL57:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL57:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR 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:
#  HL4:SBPM:HL57:ATT1 = A1
#  HL4:SBPM:HL57:ATT2 = A2
#  HL4:SBPM:HL57:CALA = CA
#

record(sub, "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:ACTL") {
	field(DESC, "ATT OMSL Ctrl")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL57:ACCESS.RVAL CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL57: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, "HL4:SBPM:HL57:ATTOL") {
	field(DESC, "ATTO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL4:SBPM:HL57:ATTO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL4:SBPM:HL57:ATTC.B PP")
	field(EGU,  "dB")
}

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

record(longout, "HL4:SBPM:HL57:TRIG2BEAM") {
	field(DESC, "Trigger -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE8+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, "HL4:SBPM:HL57:RF2RED") {
	field(DESC, "Red RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE8+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, "HL4:SBPM:HL57:RF2GRN") {
	field(DESC, "Grn RF -> ADC trig")
	field(DTYP, "BusAddress")
	field(OUT,  "#C0S0@AFE8+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")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:SBPM:HL51:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C0S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:SBPM:HL51:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C0S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:SBPM:HL51:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C0S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:SBPM:HL51:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C0S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:EBPM:HL3A:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C1S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:EBPM:HL3A:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C1S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:EBPM:HL3A:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C1S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:EBPM:HL3A:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C1S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:EBPM:HL3B:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C2S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:EBPM:HL3B:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C2S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:EBPM:HL3B:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C2S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:EBPM:HL3B:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C2S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:SBPM:HL52:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C3S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:SBPM:HL52:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C3S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:SBPM:HL52:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C3S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:SBPM:HL52:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C3S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:SBPM:HL53:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C4S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:SBPM:HL53:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C4S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:SBPM:HL53:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C4S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:SBPM:HL53:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C4S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:SBPM:HL54:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C5S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:SBPM:HL54:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C5S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:SBPM:HL54:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C5S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:SBPM:HL54:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C5S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL3B:SBPM:HL55:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL3B:SBPM:HL55:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL3B:SBPM:HL55:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL3B:SBPM:HL55:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL4:SBPM:HL56:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C7S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL4:SBPM:HL56:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C7S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL4:SBPM:HL56:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C7S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL4:SBPM:HL56:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C7S0@0x4FC(8)")
	field(PINI, "YES")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL4:SBPM:HL57:DIGIVERS") {
	field(DESC, "Digitizer Firmware Vers.")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C8S0@0x4F8(8)")
	field(PINI, "YES")
}

# Firmware date
record(stringin, "HL4:SBPM:HL57:DIGIVERS_DATE") {
	field(DESC, "Firmware Vers. Date")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C8S0@0x4FE(8)")
	field(PINI, "YES")
}

# System ID
record(stringin, "HL4:SBPM:HL57:DIGI_SYSID") {
	field(DESC, "Digitizer System ID")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C8S0@0x4FA(8)")
	field(PINI, "YES")
}

# Sub Type
record(stringin, "HL4:SBPM:HL57:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C8S0@0x4FC(8)")
	field(PINI, "YES")
}
