esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% LNA.MAC
#
#%NAME%
#  Macros for operating and testing the LNA unit
#
#%CATEGORY% Other hardware
#
#%OVERVIEW%
#
#  An interactive macro %B%lna%B% can be used for device configuration and
#  monitoring.
#  %BR%
#  More than one LNA unit can be operated through this macro set.
#
#%EXAMPLE%
#  %DL%
#  %DT%lnasetup ldet1 2 address=LNADET1
#  %DD%Configures a LNA unit connected to the serial line #2 with address
#      LNADET1 and assigns the name \"ldet1\" to it .
#  %DT%lnasetup ldet2 id33/serlna/0 address=2
#  %DD%Configures a LNA unit connected in the second position of a daisychain
#      accesed by the ESRF device id33/serlna/0 
#      and assigns the name \"ldet2\" to it .
#  %DT%lna
#  %DD%Starts the interactive test program with the default unit.
#  %XDL%
#
#%DEPENDENCIES%
#  These macros make use of the following macro sets:
#  %UL%
#  %LI%stlist.mac
#  %LI%isgdevice.mac
#  %LI%isg.mac
#  %XUL%

#%SETUP%
# A %B%lnasetup%B% macro must be included in the setup file for every LNA
# unit configured. Each unit is identified by its name that must be a unique
# isgdevice identifier. 
#%END%

#$Log: lna.mac,v $
#Revision 1.2  2008/07/17 15:14:56  rey
#doc changes
#
#Revision 1.1  2003/02/21 16:38:25  fajardo
#Initial revision
#

jtdo("isgdevice.mac")
jtdo("isg.mac")

#%UU% <lna_name> <serline> [<parameter>=<value> ...]
#%MDESC%
#  Configures a lna unit connected to <serline> with the name <lna_name>.
#  The following optional parameters can be also set.
#  %UL%
#  %LI%Valid parameters:%DL%
#    %DT%address=<addr>
#    %DD%This parameter allows to address a particular unit when the serial 
#        line is shared by several isgdevices in dasychain.
#        If <addr> is a non-numerical value, it is treated as the isgdevice
#        address set by the ADDR command and stored internally in the unit.
#        On the other hand if <addr> is a numerical value it indicates the 
#        relative position of the module in the serial line chain starting
#        from 0.
#        If this parameter is not specified, %B%spec%B% looks for the 
#        first unit in the chain.
#    %XDL%
#  %XUL%
def lnasetup '{
   local retval

   if ($# == 0 || (retval = _lnasetup("$*"))) {
      if (SETUP) print "Error in line: $0 $*"
      if (retval < 0) {
         print "Usage:  $0 lna_mne serial_line [parameter=value ...]"
         if (yesno("\nDisplay online help", 0)) eval("help local lna")
      }
   } 
}'


def _lnasetup(args) '{
   global LNA[]
   global LNA_AUX[]

   local i nparam auxlist0[] auxlist1[] larr 
   local serlin isgdev isgname 

   nparam = split(args, auxlist0)
   for (i = 0; i < nparam; i++) {
      if (split(auxlist0[i], larr, "=") > 1){
         delete auxlist0[i]
         auxlist1[larr[0]] = larr[1]
      } else if (i > 1) {
         delete auxlist0[i]
         auxlist1[larr[0]] = "yes"
      }
   }
   if (!((0 in auxlist0) && (1 in auxlist0))) {
      printf("Bad parameters\n")
      return(-1)
   }
   isgname = auxlist0[0]
   serlin = auxlist0[1]

   if ("address" in auxlist1){
      if (auxlist1["address"] + 0 == auxlist1["address"]) 
         isgdev = isgdevice_add(isgname, serlin , 0, auxlist1["address"])
      else 
         isgdev = isgdevice_add(isgname, serlin , 1, auxlist1["address"])
      delete auxlist1["address"]
   } else 
      isgdev = isgdevice_add(isgname, serlin , 3, "LNA")

   if (isgdev <= 0 || isgdevice_check(isgname, 3, "LNA") == 0) {
      printf("No LNA device found at : %s\n", serlin)
      return(1)
   }

   if (LNA_AUX["setup_n"] != SETUP_N) {
      list_init LNA
      LNA_AUX["setup_n"] = SETUP_N
   }

   if (list_add(LNA, isgname) <= 0) {
      printf("Invalid LNA name: %s\n", isgname)
      return(-1)
   }

   LNA[isgname]["setup"] = "lnasetup " args

   setup_tail("lna", isgname)

   i = ""
   for (i in auxlist1) {
      print "Invalid parameter: " i "=" auxlist1[i]
   } 
   if (i != "")
      return(-1)
   else
      return(0)
}'

def lnaunsetup '{
   local isgname

   isgname = "$1"
   cdef("", "", isgname, "delete")
   isgdevice_remove(isgname)

   list_remove(LNA, isgname)
   if (list_n(LNA) <= 0)
      unglobal LNA LNA_AUX
}'

def lna_setdefault(isgname) '{
   if (LNA[0] <= 0) {
      print "No LNA devices configured. Use first \`lnasetup\'."
      return(0)
   }
   if (isgname != "") {
      LNA_AUX["default"] = isgname
      if (!list_check(LNA, isgname)) {
         print "\`" isgname "\' is not a valid LNA unit."
      }
   } 
   if (!list_check(LNA, LNA_AUX["default"])) {
      LNA_AUX["default"] = LNA[1]
      print "Setting \`" LNA_AUX["default"] "\' as default LNA unit."
   }
   return(1)
}'

#%UU% [<device_name>]
#%MDESC%
#  Macro that runs the interactive loop. %B%lna%B% refresh certain
#  information on the screen and at the same time accepts commands 
#  from the standard input. 
#  %BR%
#
def lna '{
   local isgname options

   isgname = $#? "$1": ""
   if (!$# || list_check(LNA, isgname) > 0){
      if (lna_setdefault(isgname)) {
         isgname = LNA_AUX["default"]
         LNA[isgname]["prompt"] = "(" LNA_AUX["default"] ")"
      }
   } else if ((serdev = isgdevice_add("LNA", "$1", 3, "LNA")) > 0) {
      isgname = "LNA"
      LNA[isgname]["prompt"] = ""
   } else {
      print "No LNA unit found."
      isgname = ""
   }
   if (!isgname) {
      print "Usage: $0 lna_name" 
      print "  or   $0 serial_line" 
      if (yesno("\nDisplay online help", 0))
         eval("help local lna")
   } else {
      rdef isg_prompt  "lna_prompt"
      rdef isg_update  "lna_update"
      rdef isg_show    "lna_show_comm"
      rdef isg_process "lna_process_comm"
   
      isg_main(isgname, options, 0, LNA[isgname]["update"])
   }
}'

def lna_update '{
   update_flag = lna_getstate(isgname)
}'

def lna_getstate(isgname) '{
   local state refstat

   if ((state = isgdevice_comm(isgname, "?STATE")) == ISGDEV_ERR)
      state = "???"

   if ((refstat = isgdevice_comm(isgname, "?REFSTAT")) == ISGDEV_ERR)
      refstate = "???"

   if (state != LNA[isgname]["state"] || refstat != LNA[isgname]["refstat"]) {
      LNA[isgname]["state"] = state
      LNA[isgname]["refstat"] = refstat
      return(1)
   } else
      return(0)
}'


#%IU%
#%MDESC%
#  Displays the prompt on the screen. If the "update" flag is set also
#  displays the board status.
#
def lna_prompt '
   printf("LNA%s: %s - %s - %s", LNA[isgname]["prompt"], date(), \
                     LNA[isgname]["state"], LNA[isgname]["refstat"])
'

def lna_show_comm '
   isg_show_comm(".c, .config",   "Display spec setup")
'

#%IU%
#%MDESC%
#
def lna_process_comm '
   if (comm[0] == ".config" || comm[0] == ".c") {
      local aux

      print
      printf("\tSerial line: %s\n", ISGDEV_CONF[isgname]["serlin"])
      printf("\tPosition   : %d\n", ISGDEV_CONF[isgname]["pos"])
      print
      printf("\tSetup line: %s\n", LNA[isgname]["setup"])
      return(1)
   } 
'


#%MACROS%

#%AUTHOR% P.Fajardo, (Original 12/02).
#  $Revision: 1.2 $ / $Date: 2008/07/17 15:14:56 $
#%TOC%