Skip to content

Commit

Permalink
reworked ADUVC to take image size and framerate as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlodek committed Nov 5, 2018
1 parent c05b0f8 commit 7ffc84a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
37 changes: 24 additions & 13 deletions adUVCApp/src/ADUVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";

Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion adUVCApp/src/ADUVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions iocs/adUVCIOC/iocBoot/iocADUVC/st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,19 +36,21 @@ 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
# * @params: stackSize -> size of the driver on the stack
# */

# 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)
Expand Down

0 comments on commit 7ffc84a

Please sign in to comment.