#
# For LCLS, which contains many BPM eiocs (many clients of this
# database), this db is loaded into a soft ioc instead of one of
# the BPM iocs to reduce the number of channel access links on that ioc.
#

# a few records to host the 'announced charge'
# so that everybody can adjust their gains
record(ao, "VIOC:L001:BPM01:QANN") {
	field(DESC, "Announced Beam Charge")
	field(ADEL, ".01")
	field(LOPR, ".01")
	field(DRVL, ".01")
	field(HOPR, "2")
	field(DRVH, "1")
	field(PREC, "3")
	field(VAL,  ".1")
	field(EGU,  "nC")
	field(PINI, "YES")
        field(FLNK, "VIOC:L001:BPM01:QANNSET PP")
  	info(autosaveFields, "VAL HIHI HIGH LOW LOLO HHSV HSV LSV LLSV DRVH")
}

# Make proxy record to write QANN in order
# to limit access to QANN.DRVH (HW protection)
# QANNSET value will be used to set eioc attenuators
record(ao, "VIOC:L001:BPM01:QANNSET") {
        field(DESC, "Set QANN")
        field(DOL, "VIOC:L001:BPM01:QANN")
        field(OMSL, "closed_loop")
	field(OUT,  "VIOC:L001:BPM01:ATTR.A PP")
	field(ADEL, ".01")
	field(LOPR, ".01")
	field(DRVL, ".01")
	field(HOPR, "2")
	field(DRVH, "1")
	field(PREC, "3")
	field(VAL,  ".1")
	field(EGU,  "nC")
        field(VAL, "1")
        field(ASG, "EOICDESK")
 	field(FLNK, "VIOC:L001:BPM01:QANNF")
  	info(autosaveFields, "DRVH")
}

# Record to copy selected QANNSET fields to QANN
# Sync QANN.DRVH to 'real' QANNSET.DRVH
# Just DRVH for now; want to keep alarms with
# accessible QANN
record(seq, "VIOC:L001:BPM01:QANNF") {
    	field(DESC, "Update QANN fields")
        field(SELM, "All")
     	field(DOL1, "VIOC:L001:BPM01:QANNSET.DRVH CP")
        field(LNK1, "VIOC:L001:BPM01:QANN.DRVH PP")
}


record(ao, "VIOC:L001:BPM01:QREF") {
	field(DESC, "Ann. Charge Ref. Val.")
	field(OUT,  "VIOC:L001:BPM01:ATTR.B PP")
	field(ADEL, ".01")
	field(LOPR, ".01")
	field(DRVL, ".01")
	field(HOPR, "100")
	field(DRVH, "100")
	field(PREC, "3")
	field(VAL,  ".1")
	field(EGU,  "nC")
	field(PINI, "YES")
        field(ASG, "EOICDESK")
  	info(autosaveFields, "VAL")
}

record(calc, "VIOC:L001:BPM01:ATTR") {
	field(DESC, "Reference Attenuation")
	field(EGU,  "dB")
	field(CALC, "20*LOG(a/b)")
        field(ASG, "EOICDESK")
}

record(calcout, "VIOC:L001:BPM01:QANNH") {
  field(DESC, "Calculates QANN.HIHI,.HIGH")
  field(SCAN, "Passive")
  field(CALC, "A*B")
#Feedback charge setpoint
  field(INPA, "FBCK:BCI0:1:CHRGSP CPP")
#Upper limits coefficient
  field(B, "1.1")
  field(OUT, "VIOC:L001:BPM01:QANNHFO PP")
  field(OOPT, "Every Time")
  field(PINI, "YES")
  info(autosaveFields, "INPA B")
}

record(dfanout, "VIOC:L001:BPM01:QANNHFO") {
  field(DESC, "Fanout to QANN.HIHI,HIGH")
  field(OUTA, "VIOC:L001:BPM01:QANN.HIHI PP")
  field(OUTB, "VIOC:L001:BPM01:QANN.HIGH PP")
}

record(calcout, "VIOC:L001:BPM01:QANNL") {
  field(DESC, "Calculates QANN.LOLO,.LOW")
  field(SCAN, "Passive")
  field(CALC, "A*B")
#Feedback charge setpoint
  field(INPA, "FBCK:BCI0:1:CHRGSP CPP")
#Lower limits coefficient
  field(B, "0.9")
  field(OUT, "VIOC:L001:BPM01:QANNLFO PP")
  field(OOPT, "Every Time")
  field(PINI, "YES")
  info(autosaveFields, "INPA B")
}

record(dfanout, "VIOC:L001:BPM01:QANNLFO") {
  field(DESC, "Fanout to QANN.LOLO,LOW")
  field(OUTA, "VIOC:L001:BPM01:QANN.LOLO PP")
  field(OUTB, "VIOC:L001:BPM01:QANN.LOW PP")
}

# Two records for users who prefer bunch charge in # of electrons
# Users set QANNEL, which sets QANN (changes to QANN bypassing QANNNEL
# will be lost). Must restore QANNEL on reboot. 
# New macro qann for QANN PV, which has default of "" to remain 
# backward-compatible with existing db substitutions files.
# IMPORTANT: Only those wishing to use QANNEL should define value for qann macro,
# otherwise QANN will be set to QANNEL's default on boot.
record(ao, "VIOC:L001:BPM01:QANNNEL") {
	field(DESC, "Announced Beam Charge")
	field(ADEL, "1E7")
	field(LOPR, "6.25E7")
	field(DRVL, "6.25E7")
	field(HOPR, "2E10")
	field(DRVH, "2E10")
	field(VAL,  "6.25E8")
	field(EGU,  "Nel")
	field(PINI, "YES")
	field(FLNK, "VIOC:L001:BPM01:QANNNELC")
  	info(autosaveFields, "VAL")
}

record(calcout, "VIOC:L001:BPM01:QANNNELC") {
	field(DESC, "Convert beam charge units")
	field(CALC, "A*1E9*1.6E-19")
	field(INPA, "VIOC:L001:BPM01:QANNNEL")
	field(OUT,  "VIOC:L001:BPM01:QANN PP")
	field(OOPT, "Every Time")
	field(FLNK, "VIOC:L001:BPM01:QANN PP")
}
# per IOC database for stripline BPMs

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

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

record(sub, "VIOC:L001:BPM01: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:001: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, "HL01:BPMS:001:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:001: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, "HL01:BPMS:001:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:001:ATT1 CP")
  field(INPC, "HL01:BPMS:001: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, "HL01:BPMS:001:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:001: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, "HL01:BPMS:001:PINC")
}

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

record(longin, "HL01:BPMS:001: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, "HL01:BPMS:001:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:001: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, "HL01:BPMS:001:PHI_SEQ")
}

record(ao, "HL01:BPMS:001: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, "HL01:BPMS:001:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:001: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, "HL01:BPMS:001:UOFF_SEQ")
}

record(ao, "HL01:BPMS:001: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, "HL01:BPMS:001:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01001")
  field(PINI, "YES")
}

record(stringin, "BPMHL01001:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:001")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:001: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, "HL01:BPMS:001:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:001:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:001:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:001:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:001:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:001: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:002: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, "HL01:BPMS:002:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:002: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, "HL01:BPMS:002:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:002:ATT1 CP")
  field(INPC, "HL01:BPMS:002: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, "HL01:BPMS:002:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:002: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, "HL01:BPMS:002:PINC")
}

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

record(longin, "HL01:BPMS:002: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, "HL01:BPMS:002:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:002: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, "HL01:BPMS:002:PHI_SEQ")
}

record(ao, "HL01:BPMS:002: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, "HL01:BPMS:002:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:002: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, "HL01:BPMS:002:UOFF_SEQ")
}

record(ao, "HL01:BPMS:002: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, "HL01:BPMS:002:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01002")
  field(PINI, "YES")
}

record(stringin, "BPMHL01002:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:002")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:002: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, "HL01:BPMS:002:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:002:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:002:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:002:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:002:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:002: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:003: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, "HL01:BPMS:003:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:003: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, "HL01:BPMS:003:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:003:ATT1 CP")
  field(INPC, "HL01:BPMS:003: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, "HL01:BPMS:003:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:003: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, "HL01:BPMS:003:PINC")
}

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

record(longin, "HL01:BPMS:003: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, "HL01:BPMS:003:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:003: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, "HL01:BPMS:003:PHI_SEQ")
}

record(ao, "HL01:BPMS:003: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, "HL01:BPMS:003:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:003: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, "HL01:BPMS:003:UOFF_SEQ")
}

record(ao, "HL01:BPMS:003: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, "HL01:BPMS:003:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01003")
  field(PINI, "YES")
}

record(stringin, "BPMHL01003:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:003")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:003: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, "HL01:BPMS:003:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:003:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:003:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:003:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:003:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:003: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:004: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, "HL01:BPMS:004:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:004: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, "HL01:BPMS:004:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:004:ATT1 CP")
  field(INPC, "HL01:BPMS:004: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, "HL01:BPMS:004:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:004: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, "HL01:BPMS:004:PINC")
}

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

record(longin, "HL01:BPMS:004: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, "HL01:BPMS:004:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:004: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, "HL01:BPMS:004:PHI_SEQ")
}

record(ao, "HL01:BPMS:004: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, "HL01:BPMS:004:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:004: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, "HL01:BPMS:004:UOFF_SEQ")
}

record(ao, "HL01:BPMS:004: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, "HL01:BPMS:004:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01004")
  field(PINI, "YES")
}

record(stringin, "BPMHL01004:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:004")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:004: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, "HL01:BPMS:004:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:004:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:004:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:004:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:004:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:004: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:005: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, "HL01:BPMS:005:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:005: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, "HL01:BPMS:005:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:005:ATT1 CP")
  field(INPC, "HL01:BPMS:005: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, "HL01:BPMS:005:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:005: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, "HL01:BPMS:005:PINC")
}

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

record(longin, "HL01:BPMS:005: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, "HL01:BPMS:005:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:005: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, "HL01:BPMS:005:PHI_SEQ")
}

record(ao, "HL01:BPMS:005: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, "HL01:BPMS:005:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:005: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, "HL01:BPMS:005:UOFF_SEQ")
}

record(ao, "HL01:BPMS:005: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, "HL01:BPMS:005:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01005")
  field(PINI, "YES")
}

record(stringin, "BPMHL01005:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:005")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:005: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, "HL01:BPMS:005:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:005:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:005:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:005:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:005:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:005: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:006: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, "HL01:BPMS:006:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:006: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, "HL01:BPMS:006:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:006:ATT1 CP")
  field(INPC, "HL01:BPMS:006: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, "HL01:BPMS:006:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:006: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, "HL01:BPMS:006:PINC")
}

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

record(longin, "HL01:BPMS:006: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, "HL01:BPMS:006:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:006: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, "HL01:BPMS:006:PHI_SEQ")
}

record(ao, "HL01:BPMS:006: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, "HL01:BPMS:006:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:006: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, "HL01:BPMS:006:UOFF_SEQ")
}

record(ao, "HL01:BPMS:006: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, "HL01:BPMS:006:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01006")
  field(PINI, "YES")
}

record(stringin, "BPMHL01006:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:006")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:006: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, "HL01:BPMS:006:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:006:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:006:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:006:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:006:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:006: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007:PINC_ADJ") {
  field(DESC, "Adjust Pinc. Corr.")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:007: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, "HL01:BPMS:007:QSCL") {
  field(DESC, "TMIT/Charge Scale")
  field(DTYP, "Soft Channel")
  field(OUT, "HL01:BPMS:007: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, "HL01:BPMS:007:QSCA") {
  field(DESC, "TMIT ATT Adj. Scale")
  field(INPB, "HL01:BPMS:007:ATT1 CP")
  field(INPC, "HL01:BPMS:007: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, "HL01:BPMS:007:TMIT.ASLO CA")
  field(EGU, "Nel")
  field(PREC, "3")
  info(autosaveFields, "D")
}

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

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


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

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

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

record(ai, "HL01:BPMS:007: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, "HL01:BPMS:007:PINC")
}

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

record(longin, "HL01:BPMS:007: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, "HL01:BPMS:007:RSTA_ALH")
}


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

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

record(ao, "HL01:BPMS:007: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, "HL01:BPMS:007:PHI_SEQ")
}

record(ao, "HL01:BPMS:007: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, "HL01:BPMS:007:PSI_SEQ")
}

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

record(ao, "HL01:BPMS:007: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, "HL01:BPMS:007:UOFF_SEQ")
}

record(ao, "HL01:BPMS:007: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, "HL01:BPMS:007:VOFF_SEQ")
}

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

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


record(mbbo, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007:MADN") {
  field(DESC, "MAD Name")
  field(VAL, "BPMHL01007")
  field(PINI, "YES")
}

record(stringin, "BPMHL01007:NAME") {
  field(DESC, "BPM Name")
  field(VAL, "HL01:BPMS:007")
  field(PINI, "YES")
}

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

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

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

record(calcout, "HL01:BPMS:007: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, "HL01:BPMS:007:USCL")
  field(INPL, "0")
}

# Switch simulation record HL01:BPMS:007:SIMCSEQ moved to
# bpmCavity.db.part and bpmStripl.db.part 

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

# Drive the SEL record when the 'ctrl' PV changes
# Use a CA link to monitor such changes
record(calcout,  "HL01:BPMS:007:PSI_CTRL")
{
	field(INPA, "HL01:BPMS:007:PARMSEL CP")
	field(CALC, "A+1")
	field(DOPT, "Use CALC")
	field(OOPT, "On Change")
	field(OUT,  "HL01:BPMS:007:PSI_SEL.L PP")
}
record(longout, "HL01:BPMS:007: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.
#     HL01:BPMS:001:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:001:ACTL.DOL <---- HL01:BPMS:001:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:001:ATTOL.DOL<---- HL01:BPMS:001:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:001:CLAOL.DOL<---- HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE0+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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.
#     HL01:BPMS:002:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:002:ACTL.DOL <---- HL01:BPMS:002:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:002:ATTOL.DOL<---- HL01:BPMS:002:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:002:CLAOL.DOL<---- HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE1+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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.
#     HL01:BPMS:003:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:003:ACTL.DOL <---- HL01:BPMS:003:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:003:ATTOL.DOL<---- HL01:BPMS:003:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:003:CLAOL.DOL<---- HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE2+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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.
#     HL01:BPMS:004:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:004:ACTL.DOL <---- HL01:BPMS:004:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:004:ATTOL.DOL<---- HL01:BPMS:004:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:004:CLAOL.DOL<---- HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE3+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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.
#     HL01:BPMS:005:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:005:ACTL.DOL <---- HL01:BPMS:005:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:005:ATTOL.DOL<---- HL01:BPMS:005:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:005:CLAOL.DOL<---- HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE4+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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.
#     HL01:BPMS:006:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:006:ACTL.DOL <---- HL01:BPMS:006:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:006:ATTOL.DOL<---- HL01:BPMS:006:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:006:CLAOL.DOL<---- HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE5+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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.
#     HL01:BPMS:007:ATT.DOL  <---- VIOC:L001:BPM01:ATTR CPP    // DEFINED IN: [depends on 'chrg' macro substitution].
#     HL01:BPMS:007:ACTL.DOL <---- HL01:BPMS:007:ACCESS.RVAL CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:007:ATTOL.DOL<---- HL01:BPMS:007:ATTO CP // DEFINED IN: associated main IOC database 'IOC-<loc>-BP<unit>bpm.db'
#     HL01:BPMS:007:CLAOL.DOL<---- HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007:CALT") {
	field(DESC, "AFE CAL Soft Trigger")
	field(DTYP, "BusAddress")
# address is chip-select << 8 + register
	field(OUT,  "#C0S0@AFE6+6,qspiAfe")
}

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

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

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

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

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

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

record(longout, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:001: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:002: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:003: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:004: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:005: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:006: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007: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, "HL01:BPMS:007:SUBSYS") {
	field(DESC, "Subsystem type")
	field(DTYP, "sis8300Digi")
# address is digitizer base address + register
	field(INP,  "#C6S0@0x4FC(8)")
	field(PINI, "YES")
}
