#
# This template is used to monitor and control data from a 
# 5069-IF8 is a analog 8 channel input module that monitors a flow Sensor
#
#
# Macros:
#        LOCA  The sector/area in the accelerator where the sensors are present  
#        UNIT  The PLC/ IOC instance of the subsystem    
#        CR    Crate/panel number 
#        SLOT  I/O module location on the panel
#        CHAN  I/O channel on the I/O module
#        PLC   Name of the ether_ip connection to PLC as defined in st.cmd 
#        ARRAY Array in which data is read
#        INDEX index of the array from PLC where the the data will be read out of
#        DESC  EPICS PV description
#        ALIAS EPICS name for the PV
#        EGU   Engineering units
#        H     High operating range
#        L     Low operating range
#        HH    High alarm limit
#        LL    Low alarm limit
#        HI    High warning limit
#        LO    Low warning limit
#        HY    Alarm deadband.signal hovering at limit not generate many alarm
#        AD    Archiver deadband
#        MO    Monitor deadband
#==============================================================================

#Holds raw sensor readback
record(ai, "PLC:${LOCA}:${UNIT}:CR$(CR)_M${SLOT}_CH${CHAN}") {
  field(DESC, "${DESC}")
  field(SCAN, "1 second")
  field(DTYP, "EtherIP")
  field(FLNK, "${ALIAS}")
  field(INP , "@$(PLC) PEPS$(CR)R$(ARRAY)[$(INDEX)]")
  #PLC will read -328 if sensor is physically disconnected
  field(LOW, "-328")
  field(LSV, "INVALID")
  field(PREC, "2")
}

#Holds mapping between  PLC channel,slot and alias
record(stringout, "PLC:${LOCA}:${UNIT}:CR$(CR)_M${SLOT}_CH${CHAN}_ALIAS") {
    field(VAL,"$(ALIAS)")
    field(PINI,"YES")
}

#Flow PV for user
record(ai, "${ALIAS}") {
  field(DESC, "${DESC}")
  field(PREC, "2")
  field(INP, "PLC:${LOCA}:${UNIT}:CR$(CR)_M${SLOT}_CH${CHAN} CA MS")
  field(EGU, "$(EGU)")
  field(HOPR, "$(H)")
  field(LOPR, "$(L)")
  field(HIHI, "$(HH)")
  field(LOLO, "$(LL)")
  field(HIGH, "$(HI)")
  field(LOW, "$(LO)")
  field(HHSV, "MAJOR")
  field(LLSV, "MAJOR")
  field(HSV, "MINOR")
  field(LSV, "MINOR")
  field(HYST, "$(HY)")
  field(ADEL, "$(AD)")
  field(MDEL, "$(MD)")
  field(PINI,"YES")
  info(autosaveFields,"LOLO LOW HIGH HIHI HYST")
}
