From 7ffc84aceba2fc4cccb12ea64dde9afc76681955 Mon Sep 17 00:00:00 2001 From: jwlodek Date: Mon, 5 Nov 2018 15:21:11 -0500 Subject: [PATCH] reworked ADUVC to take image size and framerate as parameters --- adUVCApp/src/ADUVC.cpp | 37 +++++++++++++++++---------- adUVCApp/src/ADUVC.h | 2 +- iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd | 10 +++++--- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/adUVCApp/src/ADUVC.cpp b/adUVCApp/src/ADUVC.cpp index f1fa8ee..8b31182 100755 --- a/adUVCApp/src/ADUVC.cpp +++ b/adUVCApp/src/ADUVC.cpp @@ -51,8 +51,8 @@ static const double ONE_BILLION = 1.E9; * @params: all passed into constructor * @return: status */ -extern "C" int ADUVCConfig(const char* portName, const char* serial, int vendorID, int productID, int framerate, int maxBuffers, size_t maxMemory, int priority, int stackSize){ - new ADUVC(portName, serial, vendorID, productID, framerate, maxBuffers, maxMemory, priority, stackSize); +extern "C" int ADUVCConfig(const char* portName, const char* serial, int vendorID, int productID, int framerate, int xsize, int ysize, int maxBuffers, size_t maxMemory, int priority, int stackSize){ + new ADUVC(portName, serial, vendorID, productID, framerate, xsize, ysize, maxBuffers, maxMemory, priority, stackSize); return(asynSuccess); } @@ -207,8 +207,14 @@ void ADUVC::newFrameCallbackWrapper(uvc_frame_t* frame, void* ptr){ */ uvc_error_t ADUVC::acquireStart(){ static const char* functionName = "acquireStart"; - //Temp for testing. Resolution, framerate, and format will be selectable in final release versions. - deviceStatus = uvc_get_stream_ctrl_format_size(pdeviceHandle, &deviceStreamCtrl, UVC_FRAME_FORMAT_MJPEG, 640, 480, 30); + // get values for image format from PVs set in IOC shell + int framerate; + int xsize; + int ysize; + getIntegerParam(ADUVC_Framerate, &framerate); + getIntegerParam(ADSizeX, &xsize); + getIntegerParam(ADSizeY, &ysize); + deviceStatus = uvc_get_stream_ctrl_format_size(pdeviceHandle, &deviceStreamCtrl, UVC_FRAME_FORMAT_MJPEG, xsize, ysize, framerate); if(deviceStatus<0){ reportUVCError(deviceStatus, functionName); setIntegerParam(ADAcquire, 0); @@ -555,7 +561,7 @@ void ADUVC::report(FILE* fp, int details){ * @params: priority -> what thread priority this driver will execute with * @params: stackSize -> size of the driver on the stack */ -ADUVC::ADUVC(const char* portName, const char* serial, int vendorID, int productID, int framerate, int maxBuffers, size_t maxMemory, int priority, int stackSize) +ADUVC::ADUVC(const char* portName, const char* serial, int vendorID, int productID, int framerate, int xsize, int ysize, int maxBuffers, size_t maxMemory, int priority, int stackSize) : ADDriver(portName, 1, (int)NUM_UVC_PARAMS, maxBuffers, maxMemory, asynEnumMask, asynEnumMask, ASYN_CANBLOCK, 1, priority, stackSize){ static const char* functionName = "ADUVC"; @@ -568,8 +574,11 @@ ADUVC::ADUVC(const char* portName, const char* serial, int vendorID, int product createParam(ADUVC_VendorIDString, asynParamInt32, &ADUVC_VendorID); createParam(ADUVC_ProductIDString, asynParamInt32, &ADUVC_ProductID); - // set initial params + // set initial size and framerate params setIntegerParam(ADUVC_Framerate, framerate); + setIntegerParam(ADSizeX, xsize); + setIntegerParam(ADSizeY, ysize); + setIntegerParam(ADUVC_VendorID, vendorID); setIntegerParam(ADUVC_ProductID, productID); printf("%d\n", productID); @@ -624,28 +633,30 @@ static const iocshArg UVCConfigArg1 = { "Serial number", iocshArgString }; static const iocshArg UVCConfigArg2 = { "Vendor ID", iocshArgInt }; static const iocshArg UVCConfigArg3 = { "Product ID", iocshArgInt }; static const iocshArg UVCConfigArg4 = { "Framerate", iocshArgInt }; -static const iocshArg UVCConfigArg5 = { "maxBuffers", iocshArgInt }; -static const iocshArg UVCConfigArg6 = { "maxMemory", iocshArgInt }; -static const iocshArg UVCConfigArg7 = { "priority", iocshArgInt }; -static const iocshArg UVCConfigArg8 = { "stackSize", iocshArgInt }; +static const iocshArg UVCConfigArg5 = { "XSize", iocshArgInt }; +static const iocshArg UVCConfigArg6 = { "YSize", iocshArgInt }; +static const iocshArg UVCConfigArg7 = { "maxBuffers", iocshArgInt }; +static const iocshArg UVCConfigArg8 = { "maxMemory", iocshArgInt }; +static const iocshArg UVCConfigArg9 = { "priority", iocshArgInt }; +static const iocshArg UVCConfigArg10 = { "stackSize", iocshArgInt }; /* Array of config args */ static const iocshArg * const UVCConfigArgs[] = { &UVCConfigArg0, &UVCConfigArg1, &UVCConfigArg2, &UVCConfigArg3, &UVCConfigArg4, &UVCConfigArg5, - &UVCConfigArg6, &UVCConfigArg7, &UVCConfigArg8 }; + &UVCConfigArg6, &UVCConfigArg7, &UVCConfigArg8, &UVCConfigArg9, &UVCConfigArg10 }; /* what function to call at config */ static void configUVCCallFunc(const iocshArgBuf *args) { ADUVCConfig(args[0].sval, args[1].sval, args[2].ival, args[3].ival, - args[4].ival, args[5].ival, args[6].ival, args[7].ival, args[8].ival); + args[4].ival, args[5].ival, args[6].ival, args[7].ival, args[8].ival, args[9].ival, args[10].ival); } /* information about the configuration function */ -static const iocshFuncDef configUVC = { "ADUVCConfig", 8, UVCConfigArgs }; +static const iocshFuncDef configUVC = { "ADUVCConfig", 10, UVCConfigArgs }; /* IOC register function */ diff --git a/adUVCApp/src/ADUVC.h b/adUVCApp/src/ADUVC.h index 14e8cd6..2acf677 100755 --- a/adUVCApp/src/ADUVC.h +++ b/adUVCApp/src/ADUVC.h @@ -44,7 +44,7 @@ class ADUVC : ADDriver{ public: // Constructor - ADUVC(const char* portName, const char* serial, int vendorID, int productID, int framerate, int maxBuffers, size_t maxMemory, int priority, int stackSize); + ADUVC(const char* portName, const char* serial, int vendorID, int productID, int framerate, int xsize, int ysize, int maxBuffers, size_t maxMemory, int priority, int stackSize); //TODO: add overrides of ADDriver functions diff --git a/iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd b/iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd index 2357daa..1ef0819 100755 --- a/iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd +++ b/iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd @@ -15,6 +15,8 @@ epicsEnvSet("QSIZE", "30") epicsEnvSet("XSIZE", "640") # The maximim image height; used for column profiles in the NDPluginStats plugin epicsEnvSet("YSIZE", "480") +# The framerate at which the stream will operate +epicsEnvSet("FRAMERATE", "30"); # The maximum number of time seried points in the NDPluginStats plugin epicsEnvSet("NCHANS", "2048") # The maximum number of frames buffered in the NDPluginCircularBuff plugin @@ -34,6 +36,8 @@ epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES", 10000000) # * @params: vendorID -> id of device vendor # * @params: productID -> id number for device to connect to # * @params: framerate -> framerate at which camera should operate +# * @params: xsize -> width of image +# * @params: ysize -> height of image # * @params: maxBuffers -> max buffer size for NDArrays # * @params: maxMemory -> maximum memory allocated for driver # * @params: priority -> what thread priority this driver will execute with @@ -41,12 +45,12 @@ epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES", 10000000) # */ # If searching for device by serial number, put 0 and 0 for vendor/productID -# ADUVCConfig(const char* portName, const char* serial, int vendorID, int productID, int framerate, int maxBuffers, size_t maxMemory, int priority, int stackSize) -#ADUVCConfig("$(PORT)", "10e536e9e4c4ee70", 0, 0, 30, 0, 0, 0, 0) +# ADUVCConfig(const char* portName, const char* serial, int vendorID, int productID, int framerate, int xsize, int ysize, int maxBuffers, size_t maxMemory, int priority, int stackSize) +#ADUVCConfig("$(PORT)", "10e536e9e4c4ee70", 0, 0, "$(FRAMERATE)", "$(XSIZE)", "$(YSIZE)", 0, 0, 0, 0) #epicsThreadSleep(2) # If searching for device by product ID put "" or empty string for serial number -ADUVCConfig("$(PORT)", "", 0, 25344, 30, 0, 0, 0, 0) +ADUVCConfig("$(PORT)", "", 3141, 25344, "$(FRAMERATE)", "$(XSIZE)", "$(YSIZE)", 0, 0, 0, 0) epicsThreadSleep(2) asynSetTraceIOMask($(PORT), 0, 2)