Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited OERCONE ioc to boot using lua, calling scripts from the utilities support modules #433

Merged
merged 6 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion OERCONE/OERCONE-IOC-01App/src/OERCONE-IOC-01Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

#include "epicsExit.h"
#include "epicsThread.h"
#include "iocsh.h"

int main(int argc,char *argv[])
{
if(argc>=2) {
if(argc>=2) {
iocsh(argv[1]);
epicsThreadSleep(.2);
}
Expand Down
2 changes: 2 additions & 0 deletions OERCONE/OERCONE-IOC-01App/src/build.mak
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions OERCONE/configure/RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 5 additions & 45 deletions OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.cmd
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
epicsEnvSet "STREAM_PROTOCOL_PATH" "$(OERCONE)/data"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, remove unused code in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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")
84 changes: 84 additions & 0 deletions OERCONE/iocBoot/iocOERCONE-IOC-01/st-common.lua
Original file line number Diff line number Diff line change
@@ -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()