Skip to content
Snippets Groups Projects
make_scpi_ioc 3.46 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/bash
    
    set -o nounset
    set -o errexit
    
    function print_the_help {
      echo "USAGE: make_scpi_ioc -n NAME "
      echo "  OPTIONS: "
      echo "            -n,--name  NAME    IOC name (must begin with letter)"
      exit 
    }
    
    function yes_or_no {
      while true; do
        read -p "$* [y/n]: " yn
        case $yn in
          [Yy]*) return 0 ;;
          [Nn]*) echo "No entered" ; return 1 ;;
        esac
      done
    }
    
    NAME=
    
    #if [[ $# -eq 0 ]] ; then
    #  print_the_help
    #  exit 
    #fi
    
    
    POSITIONAL=()
    while [[ $# -gt 0 ]]
    do
      key="$1"
    
      case $key in
        -h|--help)
          shift # past argument
          print_the_help
          ;;
        -n|--name)
          NAME="$2"
          shift # past argument
          shift # past value
          ;;
        #-a|--all)
        #  LOG_ALL_PLOTS=1
        #  shift # past argument
        #  #shift # past value
        #  ;;
        #-o|--online-only)
        #  ONLINE_ONLY=1
        #  shift # past argument
        #  #shift # past value
        #  ;;
        *)    # unknown option
          #POSITIONAL+=("$1") # save it in an array for later
          echo "unknown option $1"
          print_the_help
          shift # past argument
          ;;
      esac
    done
    set -- "${POSITIONAL[@]}" # restore positional parameters
    
    if [[ -z "${NAME}" ]] ; then 
      echo "Error: ioc NAME must be supplied"
      print_the_help
      exit 
    fi
    
    if [ -d "${NAME}" ] 
    then
      echo "Directory ${NAME} exists." 
      echo "Error: cannot overrite ${NAME}"
    else
      echo "Making directory ${NAME}"
      mkdir "${NAME}"
    fi
    cd "${NAME}"
    
    makeSupport.pl -t streamSCPI ${NAME}
    rm -r configure 
    
    makeBaseApp.pl -t ioc ${NAME}
    makeBaseApp.pl -i -t ioc ${NAME}
    
    sed -i '29iCALC = /opt/epics/synApps/support/calc' configure/RELEASE
    sed -i '29iSTREAM = /opt/epics/synApps/support/stream' configure/RELEASE
    sed -i '29iASYN = /opt/epics/synApps/support/asyn' configure/RELEASE
    
    # fix the install ... 
    sed -i '6d' ${NAME}Sup/Makefile
    sed -i "6iDB_INSTALLS += \$\(TOP\)/${NAME}Sup/dev${NAME}.db" ${NAME}Sup/Makefile
    
    
    sed -i "17i${NAME}_DBD += drvVxi11.dbd" ${NAME}App/src/Makefile
    sed -i "17i${NAME}_DBD += calc.dbd" ${NAME}App/src/Makefile
    sed -i "17i${NAME}_DBD += stream.dbd" ${NAME}App/src/Makefile
    #sed -i "17i${NAME}_DBD += stream.dbd" ${NAME}App/src/Makefile
    
    sed -i "39i${NAME}_LIBS += stream asyn calc" ${NAME}App/src/Makefile
    
    cat << EOF > iocBoot/ioc${NAME}/st.cmd
    #!../../bin/linux-x86_64/${NAME}
    
    #- You may have to change ${NAME} to something else
    
    #- everywhere it appears in this file
    
    < envPaths
    epicsEnvSet ("STREAM_PROTOCOL_PATH", ".:\$(TOP)/db:../protocols")
    
    # Allow PV name prefixes and serial port name to be set from the environment
    
    epicsEnvSet "P" "\$(P=${NAME})"
    
    epicsEnvSet "R" "\$(R=test)"
    #epicsEnvSet "TTY" "\$(TTY=/dev/tty.PL2303-000013FA)"
    
    cd "\${TOP}"
    
    ## Register all support components
    
    dbLoadDatabase "dbd/${NAME}.dbd"
    ${NAME}_registerRecordDeviceDriver pdbbase
    
    vxi11Configure ("L0","10.10.241.61",1,1000,"inst0",0)
    
    # If vxi11 isn't fully supported just use TCP:
    #drvAsynIPPortConfigure ("L0", "10.10.241.78:9221")
    
    # Serial port config
    #drvAsynSerialPortConfigure ("L0","/dev/ttyUSB2")
    #asynSetOption ("L0", 0, "baud", "9600")
    #asynSetOption ("L0", 0, "bits", "8")
    #asynSetOption ("L0", 0, "parity", "none")
    #asynSetOption ("L0", 0, "stop", "1")
    #asynSetOption ("L0", 0, "clocal", "Y")
    #asynSetOption ("L0", 0, "crtscts", "N")
    #asynSetTraceMask("L0", 0, 6) 
    #asynSetTraceIOMask("L0", 0, 6) 
    
    ## Load record instances
    
    
    ## Load record instances
    
    #dbLoadRecords("db/dev${NAME}.db","P=\$(P),R=\$(R),PORT=L0,A=0")
    
    
    
    cd "\${TOP}/iocBoot/\${IOC}"
    iocInit
    
    ## Start any sequence programs
    #seq sncxxx,"user=you"
    EOF
    
    
    chmod +x iocBoot/ioc${NAME}/st.cmd