# per IOC database for stripline BPMs

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

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

record(sub, "VIOC:BC1: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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(bo, "HL1:SBPM:HL07:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL07:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C0 S12")
  field(FLNK, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:V")
}

record(ai, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:PINC")
}

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

record(longin, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL07")
  field(PINI, "YES")
}

record(stringin, "SBPMHL07:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL07")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL07:TMIT_SLOW") {
#alias("HL1:SBPM:HL07:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL07:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL07:SIMC PP")
}

record(calcout, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL07:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL07:TMIT")
  field(INPB, "HL1:SBPM:HL07:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL07:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL07:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL07:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL07:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL07:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL07:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL07:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL07: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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(bo, "HL1:SBPM:HL08:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL08:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C1 S12")
  field(FLNK, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:V")
}

record(ai, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:PINC")
}

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

record(longin, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL08")
  field(PINI, "YES")
}

record(stringin, "SBPMHL08:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL08")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL08:TMIT_SLOW") {
#alias("HL1:SBPM:HL08:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL08:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL08:SIMC PP")
}

record(calcout, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL08:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL08:TMIT")
  field(INPB, "HL1:SBPM:HL08:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL08:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL08:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL08:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL08:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL08:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL08:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL08:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL08: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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(bo, "HL1:EBPM:HL1A:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:EBPM:HL1A:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C2 S12")
  field(FLNK, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:V")
}

record(ai, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:PINC")
}

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

record(longin, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "EBPMHL1A")
  field(PINI, "YES")
}

record(stringin, "EBPMHL1A:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:EBPM:HL1A")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:EBPM:HL1A:TMIT_SLOW") {
#alias("HL1:EBPM:HL1A:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:EBPM:HL1A:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:EBPM:HL1A:SIMC PP")
}

record(calcout, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:USCL")
  field(INPL, "0")
}

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

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

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

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

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

record(aao, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:EBPM:HL1A:TMIT")
  field(INPB, "HL1:EBPM:HL1A:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:EBPM:HL1A:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:EBPM:HL1A:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:EBPM:HL1A:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:SIM.L     PP")
  field(LNK4, "HL1:EBPM:HL1A:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:EBPM:HL1A:PSI_CTRL")
{
	field(INPA, "HL1:EBPM:HL1A:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:EBPM:HL1A:PSI_SEL.L PP")
}
record(longout, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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(bo, "HL1:EBPM:HL1B:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:EBPM:HL1B:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C3 S12")
  field(FLNK, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:V")
}

record(ai, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:PINC")
}

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

record(longin, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "EBPMHL1B")
  field(PINI, "YES")
}

record(stringin, "EBPMHL1B:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:EBPM:HL1B")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:EBPM:HL1B:TMIT_SLOW") {
#alias("HL1:EBPM:HL1B:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:EBPM:HL1B:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:EBPM:HL1B:SIMC PP")
}

record(calcout, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:USCL")
  field(INPL, "0")
}

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

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

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

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

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

record(aao, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:EBPM:HL1B:TMIT")
  field(INPB, "HL1:EBPM:HL1B:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:EBPM:HL1B:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:EBPM:HL1B:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:EBPM:HL1B:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:SIM.L     PP")
  field(LNK4, "HL1:EBPM:HL1B:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:EBPM:HL1B:PSI_CTRL")
{
	field(INPA, "HL1:EBPM:HL1B:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:EBPM:HL1B:PSI_SEL.L PP")
}
record(longout, "HL1:EBPM:HL1B: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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(bo, "HL1:SBPM:HL09:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL09:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C4 S12")
  field(FLNK, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:V")
}

record(ai, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:PINC")
}

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

record(longin, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL09")
  field(PINI, "YES")
}

record(stringin, "SBPMHL09:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL09")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL09:TMIT_SLOW") {
#alias("HL1:SBPM:HL09:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL09:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL09:SIMC PP")
}

record(calcout, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL09:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL09:TMIT")
  field(INPB, "HL1:SBPM:HL09:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL09:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL09:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL09:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL09:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL09:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL09:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL09:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL09: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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(bo, "HL1:SBPM:HL10:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL10:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C5 S12")
  field(FLNK, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:V")
}

record(ai, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:PINC")
}

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

record(longin, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL10")
  field(PINI, "YES")
}

record(stringin, "SBPMHL10:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL10")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL10:TMIT_SLOW") {
#alias("HL1:SBPM:HL10:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL10:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL10:SIMC PP")
}

record(calcout, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL10:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL10:TMIT")
  field(INPB, "HL1:SBPM:HL10:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL10:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL10:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL10:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL10:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL10:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL10:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL10:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL10: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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(bo, "HL1:SBPM:HL11:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL11:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C6 S12")
  field(FLNK, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:V")
}

record(ai, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:PINC")
}

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

record(longin, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL11")
  field(PINI, "YES")
}

record(stringin, "SBPMHL11:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL11")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL11:TMIT_SLOW") {
#alias("HL1:SBPM:HL11:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL11:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL11:SIMC PP")
}

record(calcout, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL11:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL11:TMIT")
  field(INPB, "HL1:SBPM:HL11:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL11:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL11:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL11:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL11:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL11:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL11:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL11:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL11: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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(bo, "HL1:SBPM:HL12:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HL12:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C7 S12")
  field(FLNK, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:V")
}

record(ai, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:PINC")
}

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

record(longin, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL12")
  field(PINI, "YES")
}

record(stringin, "SBPMHL12:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HL12")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HL12:TMIT_SLOW") {
#alias("HL1:SBPM:HL12:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HL12:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HL12:SIMC PP")
}

record(calcout, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HL12:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HL12:TMIT")
  field(INPB, "HL1:SBPM:HL12:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HL12:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HL12:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HL12:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HL12:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HL12:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HL12:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HL12:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HL12: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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(bo, "HL1:SBPM:HB02:PCEN") {
  field(DESC, "Enable Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL1:SBPM:HB02:CALC.K NPP MS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(VAL, "0")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

record(bo, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:Y") {
  field(DESC, "Y Position")
  field(EGU, "mm")
  field(DTYP, "Raw Bpm Signal")
  field(INP, "#C8 S12")
  field(FLNK, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:V")
}

record(ai, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:PINC")
}

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

record(longin, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:RSTA_ALH")
}


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

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

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

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

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

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

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

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

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


record(mbbo, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHB02")
  field(PINI, "YES")
}

record(stringin, "SBPMHB02:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL1:SBPM:HB02")
  field(PINI, "YES")
}

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

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

record(ai, "HL1:SBPM:HB02:TMIT_SLOW") {
#alias("HL1:SBPM:HB02:TMIT1H")
  field(DESC, "TMIT snapshot for display")
  field(INP, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:SIMOFF") {
  field(DESC, "Sim Off Propagator")
  field(INPA, "HL1:SBPM:HB02:ACCESS.RVAL")
  field(CALC, "A")
  field(OCAL, "0")
  field(OOPT, "When Zero")
  field(DOPT, "Use OCAL")
  field(OUT,  "HL1:SBPM:HB02:SIMC PP")
}

record(calcout, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:USCL")
  field(INPL, "0")
}

# Switch simulation record HL1:SBPM:HB02:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

record(aao, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:Z") {
  field(DESC, "Z Position")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

# MPS interface
record(bo, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:MPSIGNRCALC") {
  field(DESC, "MPS ignore if TMIT too low")
  field(CALC, "A<B")
  field(INPA, "HL1:SBPM:HB02:TMIT")
  field(INPB, "HL1:SBPM:HB02:T_MPS_THRES_L")
  field(HIHI, "1")
  field(HHSV, "MAJOR")
  field(ASG, "")
}

record(bi, "HL1:SBPM:HB02:MPSIGNORE") {
  field(DESC, "MPS ignore if TMIT too low")
  field(DTYP, "Raw Soft Channel")
  field(SCAN, "1 second")
  field(INP, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:XAOFF") {
  field(DESC, "X.AOFF val")
#  field(OUT, "HL1:SBPM:HB02:X.AOFF")
  field(PINI, "YES")
  field(EGU, "mm")
  field(PREC, "4")
  field(FLNK, "HL1:SBPM:HB02:XOFF")
  info(autosaveFields, "VAL")
}

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:SIM.L     PP")
  field(LNK4, "HL1:SBPM:HB02:SIM.SCAN  PP")

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL1:SBPM:HB02:PSI_CTRL")
{
	field(INPA, "HL1:SBPM:HB02:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL1:SBPM:HB02:PSI_SEL.L PP")
}
record(longout, "HL1:SBPM:HB02: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.
#     HL1:SBPM:HL07:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL07:ACTL.DOL <---- HL1:SBPM:HL07:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL07:ATTOL.DOL<---- HL1:SBPM:HL07:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL07:CLAOL.DOL<---- HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL07:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL07: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:
#  HL1:SBPM:HL07:ATT1 = A1
#  HL1:SBPM:HL07:ATT2 = A2
#  HL1:SBPM:HL07:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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.
#     HL1:SBPM:HL08:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL08:ACTL.DOL <---- HL1:SBPM:HL08:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL08:ATTOL.DOL<---- HL1:SBPM:HL08:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL08:CLAOL.DOL<---- HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:ATTINIT")
}

record(longout, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+6,qspiAfe")
}

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL08:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL08: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:
#  HL1:SBPM:HL08:ATT1 = A1
#  HL1:SBPM:HL08:ATT2 = A2
#  HL1:SBPM:HL08:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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.
#     HL1:EBPM:HL1A:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:EBPM:HL1A:ACTL.DOL <---- HL1:EBPM:HL1A:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:EBPM:HL1A:ATTOL.DOL<---- HL1:EBPM:HL1A:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:EBPM:HL1A:CLAOL.DOL<---- HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:EBPM:HL1A:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:EBPM:HL1A: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:
#  HL1:EBPM:HL1A:ATT1 = A1
#  HL1:EBPM:HL1A:ATT2 = A2
#  HL1:EBPM:HL1A:CALA = CA
#

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

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

record(longout, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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.
#     HL1:EBPM:HL1B:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:EBPM:HL1B:ACTL.DOL <---- HL1:EBPM:HL1B:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:EBPM:HL1B:ATTOL.DOL<---- HL1:EBPM:HL1B:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:EBPM:HL1B:CLAOL.DOL<---- HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:EBPM:HL1B:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:EBPM:HL1B: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:
#  HL1:EBPM:HL1B:ATT1 = A1
#  HL1:EBPM:HL1B:ATT2 = A2
#  HL1:EBPM:HL1B:CALA = CA
#

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

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

record(longout, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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.
#     HL1:SBPM:HL09:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL09:ACTL.DOL <---- HL1:SBPM:HL09:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL09:ATTOL.DOL<---- HL1:SBPM:HL09:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL09:CLAOL.DOL<---- HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL09:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL09: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:
#  HL1:SBPM:HL09:ATT1 = A1
#  HL1:SBPM:HL09:ATT2 = A2
#  HL1:SBPM:HL09:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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.
#     HL1:SBPM:HL10:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL10:ACTL.DOL <---- HL1:SBPM:HL10:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL10:ATTOL.DOL<---- HL1:SBPM:HL10:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL10:CLAOL.DOL<---- HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL10:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL10: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:
#  HL1:SBPM:HL10:ATT1 = A1
#  HL1:SBPM:HL10:ATT2 = A2
#  HL1:SBPM:HL10:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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.
#     HL1:SBPM:HL11:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL11:ACTL.DOL <---- HL1:SBPM:HL11:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL11:ATTOL.DOL<---- HL1:SBPM:HL11:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL11:CLAOL.DOL<---- HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL11:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL11: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:
#  HL1:SBPM:HL11:ATT1 = A1
#  HL1:SBPM:HL11:ATT2 = A2
#  HL1:SBPM:HL11:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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.
#     HL1:SBPM:HL12:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HL12:ACTL.DOL <---- HL1:SBPM:HL12:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL12:ATTOL.DOL<---- HL1:SBPM:HL12:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HL12:CLAOL.DOL<---- HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HL12:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HL12: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:
#  HL1:SBPM:HL12:ATT1 = A1
#  HL1:SBPM:HL12:ATT2 = A2
#  HL1:SBPM:HL12:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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.
#     HL1:SBPM:HB02:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL1:SBPM:HB02:ACTL.DOL <---- HL1:SBPM:HB02:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HB02:ATTOL.DOL<---- HL1:SBPM:HB02:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL1:SBPM:HB02:CLAOL.DOL<---- HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:ATTINIT")
}

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL1:SBPM:HB02:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL1:SBPM:HB02: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:
#  HL1:SBPM:HB02:ATT1 = A1
#  HL1:SBPM:HB02:ATT2 = A2
#  HL1:SBPM:HB02:CALA = CA
#

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

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

record(longout, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL07: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:SBPM:HL08: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1A: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:EBPM:HL1B: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL09: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL10: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL11: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HL12: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02: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, "HL1:SBPM:HB02:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C8S0@0x4FC(8)")
	field(PINI, "YES")
}
