# per IOC database for stripline BPMs

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

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

record(sub, "VIOC:L206: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C0 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL21:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL21:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL21:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL21")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL21:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL21:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL21:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL21:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL21: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C1 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL22:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL22:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL22:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL22")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL22:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL22:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL22:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL22:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL22: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C2 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL23:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL23:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL23:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL23")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL23:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL23:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL23:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL23:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL23: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C3 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL24:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL24:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL24:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL24")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL24:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL24:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL24:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL24:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL24: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C4 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL25:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL25:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL25:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL25")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL25:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL25:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL25:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL25:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL25: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C5 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL26:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL26:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL26:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL26")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL26:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL26:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL26:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL26:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL26: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C6 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL27:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL27:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL27:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL27")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL27:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL2:SBPM:HL27:PSI_CTRL")
{
	field(INPA, "HL2:SBPM:HL27:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL2:SBPM:HL27:PSI_SEL.L PP")
}
record(longout, "HL2:SBPM:HL27: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28:TYLO") {
  field(DESC, "Yellow arrival time")
  field(DTYP, "Raw Bpm Signal")
  field(EGU, "ADC Clocks")
# 'card' selects PAD number, 'signal' selects cal coeff
  field(INP, "#C7 S7")
  field(SCAN, "10 second")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "128")
  field(LOLO, "5")
  field(LOW, "8")
  field(HIGH, "60")
  field(HIHI, "70")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
  field(HSV, "MINOR")
  field(HHSV, "MAJOR")
}

record(ao, "HL2:SBPM:HL28:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL2:SBPM:HL28:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

record(stringin, "SBPMHL28:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL2:SBPM:HL28")
  field(PINI, "YES")
}

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

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

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

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

# Switch simulation record HL2:SBPM:HL28:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

record(longout, "HL2:SBPM:HL21:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL21:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL21:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL21:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL21:VERS PP")
    field(FLNK, "HL2:SBPM:HL21:AFE_COMM")
}

record(bi, "HL2:SBPM:HL21:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL21:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL22:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL22:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL22:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL22:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL22:VERS PP")
    field(FLNK, "HL2:SBPM:HL22:AFE_COMM")
}

record(bi, "HL2:SBPM:HL22:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL22:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL23:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL23:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL23:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL23:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL23:VERS PP")
    field(FLNK, "HL2:SBPM:HL23:AFE_COMM")
}

record(bi, "HL2:SBPM:HL23:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL23:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL24:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL24:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL24:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL24:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL24:VERS PP")
    field(FLNK, "HL2:SBPM:HL24:AFE_COMM")
}

record(bi, "HL2:SBPM:HL24:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL24:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL25:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL25:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL25:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL25:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL25:VERS PP")
    field(FLNK, "HL2:SBPM:HL25:AFE_COMM")
}

record(bi, "HL2:SBPM:HL25:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL25:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL26:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL26:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL26:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL26:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL26:VERS PP")
    field(FLNK, "HL2:SBPM:HL26:AFE_COMM")
}

record(bi, "HL2:SBPM:HL26:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL26:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL27:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL27:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL27:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL27:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL27:VERS PP")
    field(FLNK, "HL2:SBPM:HL27:AFE_COMM")
}

record(bi, "HL2:SBPM:HL27:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL27:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

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

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

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

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

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

record(longout, "HL2:SBPM:HL28:CLAOL") {
	field(DESC, "CLAO Propagator")
	field(DTYP, "Soft Channel")
	field(DOL,  "HL2:SBPM:HL28:CLAO CP")
	field(OMSL, "closed_loop")
	field(OUT,  "HL2:SBPM:HL28:ATTC.C PP")
	field(EGU,  "dB")
}

record(calc, "HL2:SBPM:HL28:AFE_COMM_CALC") {
    field(DESC, "AFE communication error")
    field(SCAN, "10 second")
    field(CALC, "(A>0 && A<255)?1:0")
    field(INPA, "HL2:SBPM:HL28:VERS PP")
    field(FLNK, "HL2:SBPM:HL28:AFE_COMM")
}

record(bi, "HL2:SBPM:HL28:AFE_COMM") {
    field(DESC, "AFE communication error")
    field(INP,  "HL2:SBPM:HL28:AFE_COMM_CALC")
    field(ZNAM, "Fault")
    field(ZSV,  "MAJOR")
    field(ONAM, "Ok")
}
# Records only needed for RTM AFE

record(longout, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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")
}
# Registers on Struck AMC

# Digitizer AMC FW version
record(stringin, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL21: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL22: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL23: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL24: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL25: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL26: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL27: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28: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, "HL2:SBPM:HL28:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C7S0@0x4FC(8)")
	field(PINI, "YES")
}
