diff --git a/OERCONE/OERCONE-IOC-01App/src/OERCONE-IOC-01Main.cpp b/OERCONE/OERCONE-IOC-01App/src/OERCONE-IOC-01Main.cpp index 8c8db457d..6b8d8a632 100644 --- a/OERCONE/OERCONE-IOC-01App/src/OERCONE-IOC-01Main.cpp +++ b/OERCONE/OERCONE-IOC-01App/src/OERCONE-IOC-01Main.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "epicsExit.h" #include "epicsThread.h" @@ -13,7 +15,7 @@ int main(int argc,char *argv[]) { - if(argc>=2) { + if(argc>=2) { iocsh(argv[1]); epicsThreadSleep(.2); } diff --git a/OERCONE/OERCONE-IOC-01App/src/build.mak b/OERCONE/OERCONE-IOC-01App/src/build.mak index 92332232c..ddc111474 100644 --- a/OERCONE/OERCONE-IOC-01App/src/build.mak +++ b/OERCONE/OERCONE-IOC-01App/src/build.mak @@ -32,6 +32,7 @@ $(APPNAME)_DBD += drvAsynIPPort.dbd $(APPNAME)_DBD += calcSupport.dbd ## add other dbd here ## #$(APPNAME)_DBD += xxx.dbd +$(APPNAME)_DBD += luaSupport.dbd # Add all the support libraries needed by this IOC @@ -52,6 +53,7 @@ $(APPNAME)_LIBS += utilities pugixml libjson zlib $(APPNAME)_LIBS += calc sscan $(APPNAME)_LIBS += pcrecpp pcre $(APPNAME)_LIBS += seq pv +$(APPNAME)_LIBS += lua # OERCONE-IOC-01_registerRecordDeviceDriver.cpp derives from OERCONE-IOC-01.dbd $(APPNAME)_SRCS += $(APPNAME)_registerRecordDeviceDriver.cpp diff --git a/OERCONE/configure/RELEASE b/OERCONE/configure/RELEASE index 7c87e2bb3..a884c4b3a 100644 --- a/OERCONE/configure/RELEASE +++ b/OERCONE/configure/RELEASE @@ -62,6 +62,7 @@ SSCAN=$(SUPPORT)/sscan/master STREAMDEVICE=$(SUPPORT)/StreamDevice/master UTILITIES=$(SUPPORT)/utilities/master ZLIB=$(SUPPORT)/zlib/master +LUA=$(SUPPORT)/lua/master # optional extra local definitions here -include $(TOP)/configure/RELEASE.private diff --git a/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.cmd b/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.cmd index 91c2769bd..4458a82a4 100644 --- a/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.cmd +++ b/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.cmd @@ -1,46 +1,6 @@ -epicsEnvSet "STREAM_PROTOCOL_PATH" "$(OERCONE)/data" -epicsEnvSet "DEVICE" "L0" +# Set up lua paths for access in the lua shell +epicsEnvSet("LUA_PATH", "${UTILITIES}/lua") +epicsEnvSet("LUA_SCRIPT_PATH","${TOP}/iocBoot/${IOC}") -##ISIS## Run IOC initialisation -< $(IOCSTARTUP)/init.cmd - -## Device simulation mode IP configuration -$(IFDEVSIM) drvAsynIPPortConfigure("$(DEVICE)", "localhost:$(EMULATOR_PORT=57677)") - -## For recsim: -$(IFRECSIM) drvAsynSerialPortConfigure("$(DEVICE)", "$(PORT=NUL)", 0, 1, 0, 0) - -## For real device: -$(IFNOTDEVSIM) $(IFNOTRECSIM) drvAsynSerialPortConfigure("$(DEVICE)", "$(PORT=NO_PORT_MACRO)", 0, 0, 0, 0) -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)", -1, "baud", "$(BAUD=9600)") -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)", -1, "bits", "$(BITS=8)") -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)", -1, "parity", "$(PARITY=none)") -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)", -1, "stop", "$(STOP=1)") -## Hardware flow control off -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)", 0, "clocal", "Y") -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)",0,"crtscts","N") -## Software flow control off -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)",0,"ixon","N") -$(IFNOTDEVSIM) $(IFNOTRECSIM) asynSetOption("$(DEVICE)",0,"ixoff","N") - -## Load record instances - -##ISIS## Load common DB records -< $(IOCSTARTUP)/dbload.cmd - -## Load our record instances -dbLoadRecords("$(OERCONE)/db/oercone.db","PVPREFIX=$(MYPVPREFIX),P=$(MYPVPREFIX)$(IOCNAME):,RECSIM=$(RECSIM=0),DISABLE=$(DISABLE=0),PORT=$(DEVICE)") -dbLoadRecords("$(OERCONE)/db/unit_setter.db","P=$(MYPVPREFIX)$(IOCNAME):") - - -##ISIS## Stuff that needs to be done after all records are loaded but before iocInit is called -< $(IOCSTARTUP)/preiocinit.cmd - -cd "${TOP}/iocBoot/${IOC}" -iocInit - -## Start any sequence programs -#seq sncxxx,"user=ltu34219" - -##ISIS## Stuff that needs to be done after iocInit is called e.g. sequence programs -< $(IOCSTARTUP)/postiocinit.cmd +# Call into the lua shell to boot the ioc +luash("st-common.lua") diff --git a/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.lua b/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.lua new file mode 100644 index 000000000..e09d3d974 --- /dev/null +++ b/OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.lua @@ -0,0 +1,84 @@ +-- ## Import lua utility functions + +package.path = package.path .. ';' .. os.getenv("UTILITIES") .. '/lua/luaUtils.lua;' +local utils = require("luaUtils") +local getMacroValue = utils.getMacroValue +local setAsynOptions = utils.setAsynOptions +local setHardwareFlowControl = utils.setHardwareFlowControl +local setSoftwareFlowControl = utils.setSoftwareFlowControl + +function oercone_stcommon_main() + + -- ## Get required macros and related vars + local oercone = getMacroValue{macro="OERCONE"} + local iocstartup = getMacroValue{macro="IOCSTARTUP"} + local emulator_port = getMacroValue{macro="EMULATOR_PORT", default="57677"} + + -- ## Set EPICS environment vars + iocsh.epicsEnvSet("STREAM_PROTOCOL_PATH", string.format("%s/data", oercone)) + local device = "L0" + iocsh.epicsEnvSet("DEVICE", device) + + -- ##ISIS## Run IOC initialisation + iocsh.iocshLoad(string.format("%s/init.cmd", iocstartup)) + + -- Get macros required and related vars that required init.cmd to run + local recsim = getMacroValue{macro="RECSIM", default="0"} + local isRecsim = recsim == "1" + local isDevsim = getMacroValue{macro="DEVSIM", default="0"} == "1" + local disable = getMacroValue{macro="DISABLE", default="0"} + local iocname = getMacroValue{macro="IOCNAME"} + local pvprefix = getMacroValue{macro="MYPVPREFIX"} + + -- ## Device simulation mode IP configuration + if (isDevsim) then + iocsh.drvAsynIPPortConfigure(device, string.format("localhost:%s", emulator_port)) + end + + -- ## For recsim: + if (isRecsim) then + local port = getMacroValue{macro="PORT", default="NUL"} + iocsh.drvAsynSerialPortConfigure(device, port, 0, 1 ,0 ,0) + end + + -- ## For real device: + if (not isRecsim and not isDevsim) then + local port = getMacroValue{macro="PORT", default="NO_PORT_MACRO"} + local baud = getMacroValue{macro="BAUD", default="9600"} + local bits = getMacroValue{macro="BITS", default="8"} + local parity = getMacroValue{macro="PARITY", default="none"} + local stop = getMacroValue{macro="STOP", default="1"} + setAsynOptions(device, port, baud, bits, parity, stop) + -- Hardware flow control off + local flowControlOn = false + setHardwareFlowControl(device, flowControlOn) + -- Software flow control off + setSoftwareFlowControl(device, flowControlOn) + end + + -- ## Load record instances + + -- ##ISIS## Load common DB records + iocsh.iocshLoad(string.format("%s/dbload.cmd", iocstartup)) + + -- ## Load our record instances + iocsh.dbLoadRecords( + string.format("%s/db/oercone.db",oercone), + string.format("PVPREFIX=%s,P=%s%s:,RECSIM=%s,DISABLE=%s,PORT=%s", + pvprefix, pvprefix, iocname, recsim, disable, device) + ) + iocsh.dbLoadRecords( + string.format("%s/db/unit_setter.db", oercone), + string.format("P=%s%s:", pvprefix, iocname) + ) + + -- ##ISIS## Stuff that needs to be done after all records are loaded but before iocInit is called + iocsh.iocshLoad(string.format("%s/preiocinit.cmd", iocstartup)) + + iocsh.iocInit() + + -- ##ISIS## Stuff that needs to be done after iocInit is called e.g. sequence programs + iocsh.iocshLoad(string.format("%s/postiocinit.cmd", iocstartup)) +end + +oercone_stcommon_main()