# checks an incrementor PV to see if it's incrementing.
# the incrementors are updated by ioc processes.
# this will be 0 if old = current (i.e. not incrementing)
# =======================================================
# A has current, B has previous
record(calcout, "$(S):$(N):SCAN") {
  field(CALC, "A=B?0:A+1")
  field(SCAN, "1 second")
  field(INPA, "$(S):$(N):SCAN.VAL")
  field(INPB, "$(S):$(N)CountDelay")
  field(OUT, "$(S):$(N):ALHBCURR.VAL PP")
  field(DOPT, "Use CALC")
  field(OOPT, "Transition To Zero")
  field(PINI, "YES")  
}

record(ai, "$(S):$(N):ALHBCURR") {
  field(INP, "$(S):$(N)Count NPP MS")
  field(SCAN, "Passive")
  field(FLNK, "$(S):$(N):ALHBCHK")
}

# scondam: 20-Sept-2018:
#          If the Heartbeat "Count" PV status is INVALID, ioc may be Dead.
#          Or if "Count" just not updating, ioc may be too slow or Dead.
#          else ioc is alive and heartbeat updating, everything OK.

record(calcout, "$(S):$(N):ALHBCHK") {
  field(CALC, "(C>2)?10:(A=B)?10:0")
  field(INPA, "$(S):$(N):ALHBCURR NPP MS")
  field(INPB, "$(S):$(N):ALHBPREV.VAL NPP MS")
  field(INPC, "$(S):$(N):ALHBCURR.SEVR")
  field(OUT, "$(S):$(N)AlarmStatus.VAL PP")  
  field(OOPT, "On Change")  
  field(FLNK, "$(S):$(N):ALHBERR")
  field(PINI, "YES")
}

# MS will cause this to be invalid if the HBCHK is
record(mbbi, "$(S):$(N):ALHBERR") {
  field(DESC, "$(P) monitoring")
  field(INP, "$(S):$(N):ALHBCHK.VAL NPP MS")
  field(ZRSV, "NO_ALARM")
  field(FRSV, "MAJOR")
  field(TESV, "INVALID")
  field(ZRST, "RUNNING")
  field(FRST, "NOT_RUNNING")
  field(TEST, "Dead")
  field(FLNK, "$(S):$(N):ALHBPREV")
}

record(ai, "$(S):$(N):ALHBPREV") {
  field(INP, "$(S):$(N):ALHBCURR NPP NMS")
}

