# per IOC database for stripline BPMs

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

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

record(sub, "VIOC:L411: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL64:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL64:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL64:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL64:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL64:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL64:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL64:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL64:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "0")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL64:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL64")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL64:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL64:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL64:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL64:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL64:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL65:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL65:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL65:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL65:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL65:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL65:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL65:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL65:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "1")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL65:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL65")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL65:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL65:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL65:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL65:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL65:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL66:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL66:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL66:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL66:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL66:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL66:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL66:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL66:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "2")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL66:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL66")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL66:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL66:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL66:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL66:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL66:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL67:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL67:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL67:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL67:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL67:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL67:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL67:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL67:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "3")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL67:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL67")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL67:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL67:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL67:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL67:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL67:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL68:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL68:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL68:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL68:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL68:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL68:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL68:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL68:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "4")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL68:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL68")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL68:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL68:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL68:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL68:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL68:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL69:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL69:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL69:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL69:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL69:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL69:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL69:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL69:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "5")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL69:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMHL69")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL69:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL69:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL69:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL69:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL69:PARMSEL") {
	field(VAL, "0")
	field(PINI, "YES")
}
#! Generated by VisualDCT v2.5
#! DBDSTART
#! DBDEND


# per BPM database for stripline BPMs

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

#############################################
# This is the head of the processing chain for
# diagnostics.
##############################################
record(ai, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:RED")
# HOPR for the energy algorithm is determined as follows:
#
#                      inf        inf
#  1) Fourier relation / h^2 dt = / |H|^2 df = 2 B
#                     0         -inf
#
#  1a) It can be shown that the maximum of the impuls response
#      ha is ~ 2 B
#                               
#  2) The digitizer produces the numbers
#
#     Ai = 2^s (hi/ha)
#
#     where ha is the maximum of the impuls response
#     and 2^s is a scale factor.
#     
#  3) 'Energy algorithm' calculates S = sum( Ai^2 )
#
#                                                     inf
#  4) S = (2^s / ha)^2 sum(hi^2) = K sum(hi^2) Dt ~ K / h^2 dt
#                                                    0
#
#     with K = (2^s / ha)^2 fs
#
#  5) From 4) and 1a) ->  S ~ K ha and therefore
#
#  6) S = 2^(2s) fs/ha = 2^(2s) fs/(2 B)
#
#  7) The strip signals are sqrt(S); hence HOPR is about
#
#     HOPR ~ 2^s  sqrt( fs/2/B )
#
#     with 2^s = 32768, fs=120MHz, B=10MHz it follows
#     that HOPR ~ 1E5; we add some margin...
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:BLU")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:YLO")
  field(PREC, "1")
  field(LOPR, "0")
  field(HOPR, "1.4E5")
  field(LOLO, "1000")
  field(LOW, "2000")
  field(LLSV, "MAJOR")
  field(LSV, "MINOR")
}

record(ai, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL4:SBPM:HL70:CALC.K PP MS")
  field(VAL, "0")
  field(DRVL, "0")
  field(DRVH, "2")
  field(PINI, "YES")
  info(autosaveFields, "VAL")
}

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

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

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

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

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

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


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

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

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

record(calc, "HL4:SBPM:HL70:STA_ALH") {
  field(DESC, "Status Summary")
  field(SCAN, "1 second")
  field(CALC, "0")
  field(INPA, "HL4:SBPM:HL70:RSTA_ALH.SEVR MS NPP")
  field(INPB, "HL4:SBPM:HL70:GRU.SEVR  MS NPP")
  field(INPC, "HL4:SBPM:HL70:GRV.SEVR  MS NPP")
  field(INPD, "HL4:SBPM:HL70:CHK.SEVR MS NPP")
  field(INPE, "")
  field(INPF, "HL4:SBPM:HL70:AFE_COMM.SEVR MS NPP")  
}

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

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

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

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

record(sub, "HL4:SBPM:HL70:CALC") {
  field(SNAM, "drvBpmBvectSetupSub")
# E: phi F: psi
# BPM channel number in L
  field(INPL, "6")
  field(SCAN, "Passive")
}

record(bo, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:Y")
  field(PREC, "4")
  field(LOPR, "-12")
  field(HOPR, "+12")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "ASLO LOLO LOW HIGH HIHI HHSV LLSV")
}

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

record(ai, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:EFX.PROC")
  field(ASG,  "")
  field(TSE, "-2")
  info(autosaveFields, "LOLO LOW HIGH HIHI HHSV LLSV ")
}


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

# leave RWAV in it's own lockset; don't FLNK
# to 'U' & friends
record(waveform, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:V")
}

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

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

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


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

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

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

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

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

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

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

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

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


record(mbbo, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:SIMOFF")
  info(autosaveFields, "RVAL")
}

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

# Convenience record holding the MAD name
record(stringin, "HL4:SBPM:HL70:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "SBPMSL70")
  field(PINI, "YES")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


# Records to set MPS thresholds
record(ao, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:FNET") {
  field(DESC, "BPM data on FNET")
  field(VAL, "$(FN,undefined)")
  field(ZNAM, "NO")
  field(ONAM, "YES")
  field(PINI, "YES")
}

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

# Switch simulation record 
record(seq, "HL4:SBPM:HL70:SIMCSEQ") {
  field(DESC, "BPM Sim Ctl Seq")
  field(SELM, "Mask")
  field(SELN, "0")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL4:SBPM:HL70:PSI_CTRL")
{
	field(INPA, "HL4:SBPM:HL70:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL4:SBPM:HL70:PSI_SEL.L PP")
}
record(longout, "HL4:SBPM:HL70: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.
#     HL4:SBPM:HL64:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL64:ACTL.DOL <---- HL4:SBPM:HL64:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL64:ATTOL.DOL<---- HL4:SBPM:HL64:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL64:CLAOL.DOL<---- HL4:SBPM:HL64:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL64:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL64:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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.
#     HL4:SBPM:HL65:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL65:ACTL.DOL <---- HL4:SBPM:HL65:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL65:ATTOL.DOL<---- HL4:SBPM:HL65:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL65:CLAOL.DOL<---- HL4:SBPM:HL65:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL65:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL65:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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.
#     HL4:SBPM:HL66:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL66:ACTL.DOL <---- HL4:SBPM:HL66:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL66:ATTOL.DOL<---- HL4:SBPM:HL66:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL66:CLAOL.DOL<---- HL4:SBPM:HL66:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL66:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL66:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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.
#     HL4:SBPM:HL67:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL67:ACTL.DOL <---- HL4:SBPM:HL67:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL67:ATTOL.DOL<---- HL4:SBPM:HL67:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL67:CLAOL.DOL<---- HL4:SBPM:HL67:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL67:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL67:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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.
#     HL4:SBPM:HL68:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL68:ACTL.DOL <---- HL4:SBPM:HL68:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL68:ATTOL.DOL<---- HL4:SBPM:HL68:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL68:CLAOL.DOL<---- HL4:SBPM:HL68:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL68:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL68:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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.
#     HL4:SBPM:HL69:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL69:ACTL.DOL <---- HL4:SBPM:HL69:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL69:ATTOL.DOL<---- HL4:SBPM:HL69:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL69:CLAOL.DOL<---- HL4:SBPM:HL69:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL69:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL69:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

record(longout, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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.
#     HL4:SBPM:HL70:ATT.DOL  <---- VIOC:GUN:BPM:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL4:SBPM:HL70:ACTL.DOL <---- HL4:SBPM:HL70:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL70:ATTOL.DOL<---- HL4:SBPM:HL70:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL4:SBPM:HL70:CLAOL.DOL<---- HL4:SBPM:HL70:CLAO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#
#
#
#  Additional macros added to support other architectures. These macros do NOT need to be populated for PAD AFEs
#  because the default value is set for them:
#
# 	instance - AFE identifier (0,1,... or identifying string)
#	devsup   - device support name (qspiAfe for 'generic' suppport used by SLAC RTM and XTA AFE)
#       type     - AFE flavor, 0 for PAD, 1 for XTA, 2 for RTM

#

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

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

# Total attenuation (but ATTO is still added to this)
record(longout, "HL4:SBPM:HL70:ATT") {
	field(DESC, "AFE Total Attenuation")
	field(OUT,  "HL4:SBPM:HL70:ATTC.A PP")
	field(DRVL, "0")
	field(DRVH, "30")
	field(LOPR, "0")
	field(HOPR, "30")
	field(EGU,  "dB")
	field(DOL,  "VIOC:GUN:BPM:ATTR CPP")
	field(OMSL, "supervisory")
	field(VAL,  "30")
}

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

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

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

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

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

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

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

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

# Digitizer AMC FW version
record(stringin, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL64: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL65: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL66: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL67: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL68: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL69: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70: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, "HL4:SBPM:HL70:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4FC(8)")
	field(PINI, "YES")
}
