/****************************************************************************** * * Title : primFunc_histogramSetup.c * Version 0.0, * * Description: Histogram control primitive function. * Related files: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include "primFunc_histogramSetup.h" #include "globalDefinitions.h" #include "uirUtility.h" #include "primParamsUir.h" #include "mainUir.h" #include #include "primFunctionInit.h" #include "RWlists.h" /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * primFunction_histogramSetup() *============================================================================= * * * */ ERROR_ID primFunction_histogramSetup(PRIM_FUNC_OPTION funcOption, struct PRIM_TABLE *primTable, void *primitive, UINT32 inputParameter, UINT8 slotNumber) { FILE *file; struct MSG_HEAD* primHeader= (struct MSG_HEAD*) primitive; UINT32 *primDataPtr=(UINT32*)((UINT32) primHeader +sizeof(struct MSG_HEAD)); ERROR_ID errorId=SUCCESS; char errorMessage[200]; int status; UINT32 primBodyLength; UINT32 primitiveId; struct PRIM_HISTOGRAM_SETUP_PARAMS *histogramSetup = &primTable->params.histogramSetup; const int panel=global.panel.primEdit[getPrimArrayId(HISTOGRAM_SETUP)]; UINT32 i; UINT32 dataLength; char textMessage[200]; char errorText[100]; UINT32 listIndex; int ringIndex; UINT32 fileSize; struct HOST *host; const unsigned int slaveNumber=inputParameter; struct HISTOGRAM_SETUP_OUT *histogramSetupOut; if(R_HISTOGRAM_SETUP!=R_HISTOGRAM_SETUP_HOST){ ERROR_CHECK(PROGRAM_ERROR, primitive HISTOGRAM_SETUP - wrong revision number); return(PROGRAM_ERROR); } switch(funcOption){ case PRIM_PANEL_TO_TABLE: GetCtrlVal(panel, HIST_SETP_BASE, (UINT32 *) &histogramSetup->inputParams.base); GetCtrlVal(panel, HIST_SETP_BINNING, &histogramSetup->inputParams.nBins); GetCtrlVal(panel, HIST_SETP_BIN_SIZE, &histogramSetup->inputParams.binSize); GetCtrlVal(panel, HIST_SETP_ROUTINE, &histogramSetup->inputParams.routineType); GetCtrlVal(panel, HIST_SETP_OPT0, &histogramSetup->inputParams.opt[0]); GetCtrlVal(panel, HIST_SETP_OPT1, &histogramSetup->inputParams.opt[1]); GetCtrlVal(panel, HIST_SETP_OPT2, &histogramSetup->inputParams.opt[2]); GetCtrlVal(panel, HIST_SETP_OPT3, &histogramSetup->inputParams.opt[3]); GetCtrlVal(panel, HIST_SETP_VALID_MODULES_0, &histogramSetup->inputParams.validModules[0]); GetCtrlVal(panel, HIST_SETP_VALID_MODULES_1, &histogramSetup->inputParams.validModules[1]); GetCtrlVal(panel, HIST_SETP_X_PTR, (UINT32*) &histogramSetup->inputParams.xPtr[0]); GetCtrlVal(panel, HIST_SETP_X_PTR_2, (UINT32*) &histogramSetup->inputParams.xPtr[1]); GetCtrlVal(panel, HIST_SETP_DATA_TYPE, &histogramSetup->inputParams.dataType[0]); GetCtrlVal(panel, HIST_SETP_DATA_TYPE_2, &histogramSetup->inputParams.dataType[1]); GetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_00, &histogramSetup->inputParams.moduleRangeMap[0][0]); GetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_01, &histogramSetup->inputParams.moduleRangeMap[0][1]); GetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_10, &histogramSetup->inputParams.moduleRangeMap[1][0]); GetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_11, &histogramSetup->inputParams.moduleRangeMap[1][1]); GetCtrlVal(panel, HIST_SETP_DEFAULT_1, &histogramSetup->default1); GetCtrlVal(panel, HIST_SETP_INP_FILE_1, histogramSetup->inputFile1); GetCtrlVal(panel, HIST_SETP_INP_FILE_2, histogramSetup->inputFile2); /* NO BREAK HERE!!!*/ case PRIM_PARAMS_TO_TABLE: /* add table headers - don't set indexes!!! */ primTable->inPrimHeader.length= SIZEOF(struct HISTOGRAM_SETUP_IN) +SIZEOF(struct MSG_HEAD); if(histogramSetup->default1) { status = getFileSize(histogramSetup->inputFile1, &fileSize); ERROR_CHECK(errorId, getFileSize()); primTable->inPrimHeader.length += (fileSize + 3) / sizeof(UINT32); status = getFileSize(histogramSetup->inputFile2, &fileSize); ERROR_CHECK(errorId, getFileSize()); primTable->inPrimHeader.length += (fileSize + 3) / sizeof(UINT32); } primTable->inPrimHeader.id= HISTOGRAM_SETUP; primTable->inPrimHeader.primRevision= R_HISTOGRAM_SETUP; primTable->replyLength= SIZEOF(struct HISTOGRAM_SETUP_OUT) +SIZEOF(struct MSG_HEAD); break; case PRIM_TABLE_TO_PANEL: if(primTable->inPrimHeader.primRevision != R_HISTOGRAM_SETUP){ ERROR_CHECK(PROGRAM_ERROR, primitive HISTOGRAM_SETUP - wrong revision number); return(PROGRAM_ERROR); } SetCtrlVal(panel, HIST_SETP_BASE, (unsigned int) histogramSetup->inputParams.base); SetCtrlVal(panel, HIST_SETP_BINNING, histogramSetup->inputParams.nBins); SetCtrlVal(panel, HIST_SETP_BIN_SIZE, histogramSetup->inputParams.binSize); SetCtrlVal(panel, HIST_SETP_ROUTINE, histogramSetup->inputParams.routineType); SetCtrlVal(panel, HIST_SETP_OPT0, histogramSetup->inputParams.opt[0]); SetCtrlVal(panel, HIST_SETP_OPT1, histogramSetup->inputParams.opt[1]); SetCtrlVal(panel, HIST_SETP_OPT2, histogramSetup->inputParams.opt[2]); SetCtrlVal(panel, HIST_SETP_OPT3, histogramSetup->inputParams.opt[3]); SetCtrlVal(panel, HIST_SETP_VALID_MODULES_0, histogramSetup->inputParams.validModules[0]); SetCtrlVal(panel, HIST_SETP_VALID_MODULES_1, histogramSetup->inputParams.validModules[1]); SetCtrlVal(panel, HIST_SETP_X_PTR, (unsigned int) histogramSetup->inputParams.xPtr[0]); SetCtrlVal(panel, HIST_SETP_X_PTR_2, (unsigned int) histogramSetup->inputParams.xPtr[1]); SetCtrlVal(panel, HIST_SETP_DATA_TYPE, histogramSetup->inputParams.dataType[0]); SetCtrlVal(panel, HIST_SETP_DATA_TYPE_2, histogramSetup->inputParams.dataType[1]); SetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_00, histogramSetup->inputParams.moduleRangeMap[0][0]); SetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_01, histogramSetup->inputParams.moduleRangeMap[0][1]); SetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_10, histogramSetup->inputParams.moduleRangeMap[1][0]); SetCtrlVal(panel, HIST_SETP_MODULE_RANGE_MAP_11, histogramSetup->inputParams.moduleRangeMap[1][1]); if(histogramSetup->default1) { SetCtrlAttribute(panel, HIST_SETP_X_PTR, ATTR_CTRL_MODE, VAL_INDICATOR); SetCtrlVal(panel, HIST_SETP_X_PTR, DEFAULT); SetInputMode(panel, HIST_SETP_INP_FILE_1, 1); SetCtrlVal(panel, HIST_SETP_DEFAULT_1, histogramSetup->default1); SetCtrlVal(panel, HIST_SETP_INP_FILE_1, histogramSetup->inputFile1); SetCtrlAttribute(panel, HIST_SETP_X_PTR_2, ATTR_CTRL_MODE, VAL_INDICATOR); SetCtrlVal(panel, HIST_SETP_X_PTR_2, DEFAULT); SetInputMode(panel, HIST_SETP_INP_FILE_2, 1); SetCtrlVal(panel, HIST_SETP_INP_FILE_2, histogramSetup->inputFile2); } else { SetCtrlAttribute(panel, HIST_SETP_X_PTR, ATTR_CTRL_MODE, VAL_HOT); SetInputMode(panel, HIST_SETP_INP_FILE_1, 0); SetCtrlAttribute(panel, HIST_SETP_X_PTR_2, ATTR_CTRL_MODE, VAL_HOT); SetInputMode(panel, HIST_SETP_INP_FILE_2, 0); } SetCtrlVal(panel, HIST_SETP_DEFAULT_1, histogramSetup->default1); SetInputMode(panel, HIST_SETP_TEXTMSG_16, histogramSetup->default1); break; case PRIM_BUILD: /* copy data */ *(struct HISTOGRAM_SETUP_IN *) primDataPtr= histogramSetup->inputParams; if(histogramSetup->default1) { primDataPtr+= sizeof(struct HISTOGRAM_SETUP_IN) / sizeof(UINT32); status= getFileSize(histogramSetup->inputFile1, &fileSize); ERROR_CHECK(errorId, getFileSize()); errorId= readFromBinFile(histogramSetup->inputFile1, primDataPtr, fileSize); ERROR_CHECK(errorId, readFromBinFile()); primDataPtr+= (fileSize + 3) / sizeof(UINT32); // integer division status= getFileSize(histogramSetup->inputFile2, &fileSize); ERROR_CHECK(errorId, getFileSize()); errorId= readFromBinFile(histogramSetup->inputFile2, primDataPtr, fileSize); ERROR_CHECK(errorId, readFromBinFile()); // check overall primitive length?? } break; case REP_DATA_PROCESS: /* process reply */ histogramSetupOut=(struct HISTOGRAM_SETUP_OUT *)(primDataPtr); host=global.host[HOST_INDEX(slotNumber)]; //dpsf: SetTableCellVal (host->panel.parent, ROD_HSETUP, MakePoint(1, slaveNumber+1), (unsigned int) histogramSetupOut->ctrlPtr); //dpsf: SetTableCellVal (host->panel.parent, ROD_HSETUP, MakePoint(2, slaveNumber+1), (unsigned int) histogramSetupOut->binCtrPtr); //dpsf: SetTableCellVal (host->panel.parent, ROD_HSETUP, MakePoint(3, slaveNumber+1), (unsigned int) histogramSetupOut->varRangePtr); break; case WRITE_TO_FILE: file=(FILE *) inputParameter; fprintf(file, "*base= 0x%08x, nBins= %d, binSize= %d\n", (UINT32) histogramSetup->inputParams.base, histogramSetup->inputParams.nBins, histogramSetup->inputParams.binSize); fprintf(file, "routine type= %d, dataType[]= { %d, %d }\n", histogramSetup->inputParams.routineType, histogramSetup->inputParams.dataType[0], histogramSetup->inputParams.dataType[1]); fprintf(file, "opt[]= { %d, %d, %d, %d }\n", histogramSetup->inputParams.opt[0], histogramSetup->inputParams.opt[1], histogramSetup->inputParams.opt[2], histogramSetup->inputParams.opt[3]); fprintf(file, "validModules[]= { 0x%X, 0x%X }\n", histogramSetup->inputParams.validModules[0], histogramSetup->inputParams.validModules[1]); fprintf(file, "moduleRangeMap[0][]= { 0x%X, 0x%X }, moduleRangeMap[1][]= { 0x%X, 0x%X }\n", histogramSetup->inputParams.moduleRangeMap[0][0], histogramSetup->inputParams.moduleRangeMap[0][1], histogramSetup->inputParams.moduleRangeMap[1][0], histogramSetup->inputParams.moduleRangeMap[1][1]); fprintf(file, "*xPtr[]= { 0x%X, 0x%X }\n", (UINT32)histogramSetup->inputParams.xPtr[0], (UINT32)histogramSetup->inputParams.xPtr[1]); fprintf(file, "inputFile1[]= %s\n", histogramSetup->inputFile1); fprintf(file, "inputFile2[]= %s\n", histogramSetup->inputFile2); fprintf(file, "default1= %d\n", histogramSetup->default1); break; case READ_FROM_FILE: file=(FILE *)inputParameter; status=fscanf(file, "*base= 0x%08x, nBins= %d, binSize= %d\n", (UINT32 *) &histogramSetup->inputParams.base, &histogramSetup->inputParams.nBins, &histogramSetup->inputParams.binSize); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "routine type= %d, dataType[]= { %d, %d }\n", &histogramSetup->inputParams.routineType, &histogramSetup->inputParams.dataType[0], &histogramSetup->inputParams.dataType[1]); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "opt[]= { %d, %d, %d, %d }\n", &histogramSetup->inputParams.opt[0], &histogramSetup->inputParams.opt[1], &histogramSetup->inputParams.opt[2], &histogramSetup->inputParams.opt[3]); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "validModules[]= { 0x%X, 0x%X }\n", &histogramSetup->inputParams.validModules[0], &histogramSetup->inputParams.validModules[1]); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "moduleRangeMap[0][]= { 0x%X, 0x%X }, moduleRangeMap[1][]= { 0x%X, 0x%X }\n", &histogramSetup->inputParams.moduleRangeMap[0][0], &histogramSetup->inputParams.moduleRangeMap[0][1], &histogramSetup->inputParams.moduleRangeMap[1][0], &histogramSetup->inputParams.moduleRangeMap[1][1]); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "*xPtr[]= { 0x%X, 0x%X }\n", (UINT32 *) &histogramSetup->inputParams.xPtr[0], (UINT32 *) &histogramSetup->inputParams.xPtr[1]); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=readLineFromIndex(file, strlen("inputFile1[]= "), PATHNAME_LENGTH, histogramSetup->inputFile1); if (status!=0) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=readLineFromIndex(file, strlen("inputFile2[]= "), PATHNAME_LENGTH, histogramSetup->inputFile2); if (status!=0) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=fscanf(file, "default1= %d\n", &histogramSetup->default1); if (status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} break; default: ;//error } return(SUCCESS); } /******************************************************************************/