/*************************************************************************** * * Title : primFunction_sendData.c * Version 0.0, * * Description: * Related files: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "primFunc_sendData.h" #include "fileUtility.h" #include "globalDefinitions.h" #include "uirUtility.h" #include "primParamsUir.h" #include #include "primFunctionInit.h" #include "vmeHpiUtility.h" #include "hostUtility.h" #include "comRegDfns.h" #include "RWlists.h" /****************************************************************************** * Definitions * ******************************************************************************/ /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * primFunction_sendData() *============================================================================= * * * */ ERROR_ID primFunction_sendData(PRIM_FUNC_OPTION funcOption, struct PRIM_TABLE *primTable, void *primitive, UINT32 inputParameter, UINT8 slotNumber){ FILE *file; ERROR_ID errorId=SUCCESS; char errorMessage[200]; int status; char *fileName; long fileSize; struct MSG_HEAD* primHeader=(struct MSG_HEAD*) primitive; UINT32 *primDataPtr=(UINT32*)((UINT32)primHeader+sizeof(struct MSG_HEAD)); struct HOST *host; UINT32 primBodyLength; UINT32 primitiveId; int outputFile; struct SEND_DATA_PARAMS *sendData=&primTable->params.sendData; char subdir[PATHNAME_LENGTH]; const int panel=global.panel.primEdit[getPrimArrayId(SEND_DATA)]; UINT32 i, j; UINT32 dataLength; int outFileOption; UINT32 objectId; int paramsLength; unsigned int elementSize; unsigned int fifoIdAndBank; UINT32 expectedBytesXfrd; UINT32 *replyDataPtr; DSP_TYPE dspType; struct SEND_DATA_OUT *sendDataOut; if(R_SEND_DATA!=R_SEND_DATA_HOST){ ERROR_CHECK(PROGRAM_ERROR, primitive SEND_DATA - wrong revision number); return(PROGRAM_ERROR); } switch(funcOption){ case PRIM_PANEL_TO_TABLE: GetCtrlVal(panel, SEND_DATAP_DATA_TYPE, &sendData->inputParams.dataType); GetCtrlVal(panel, SEND_DATAP_AUX, &sendData->inputParams.auxVal); GetCtrlVal(panel, SEND_DATAP_REPBUFF_FLAG, &sendData->inputParams.repBufferFlag); GetCtrlVal(panel, SEND_DATAP_TIMEOUT, &sendData->inputParams.timeout); GetCtrlVal(panel, SEND_DATAP_OUT_FILE, sendData->outDataFileName); /* NO BREAK HERE!!!*/ case PRIM_PARAMS_TO_TABLE: /* add table headers - don't set indexes!!! */ primTable->inPrimHeader.length=SIZEOF(struct MSG_HEAD)+SIZEOF(struct SEND_DATA_IN); primTable->inPrimHeader.id=SEND_DATA; primTable->inPrimHeader.primRevision=R_SEND_DATA_HOST; primTable->replyLength=SIZEOF(struct MSG_HEAD)+SIZEOF(struct SEND_DATA_OUT); break; case PRIM_TABLE_TO_PANEL: if(primTable->inPrimHeader.primRevision!=R_SEND_DATA){ ERROR_CHECK(PROGRAM_ERROR, primitive SEND_DATA - wrong revision number); return(PROGRAM_ERROR); } SetCtrlVal(panel, SEND_DATAP_DATA_TYPE, sendData->inputParams.dataType); SetCtrlVal(panel, SEND_DATAP_AUX, sendData->inputParams.auxVal); SetCtrlVal(panel, SEND_DATAP_REPBUFF_FLAG, sendData->inputParams.repBufferFlag); SetCtrlVal(panel, SEND_DATAP_TIMEOUT, sendData->inputParams.timeout); SetCtrlVal(panel, SEND_DATAP_OUT_FILE, sendData->outDataFileName); if(sendData->outDataFileName[0]==0){ SetCtrlVal(panel, SEND_DATAP_OUTPUT_OPT, 0); status=SetInputMode(panel, SEND_DATAP_OUT_FILE, 0); UIR_STATUS_CHECK(status, SetInputMode()); }else{ SetCtrlVal(panel, SEND_DATAP_OUTPUT_OPT, 1); status=SetInputMode(panel, SEND_DATAP_OUT_FILE, 1); UIR_STATUS_CHECK(status, SetInputMode()); } break; case PRIM_BUILD: /* copy data */ *(struct SEND_DATA_IN*)(primDataPtr)=sendData->inputParams; break; case REP_DATA_PROCESS: dspType=(DSP_TYPE) inputParameter; host=global.host[HOST_INDEX(slotNumber)]; sendDataOut= (struct SEND_DATA_OUT*) primDataPtr; // DEBUG code // sprintf(errorMessage, "dataPtr: %p; dataLength: %u", sendDataOut->dataPtr, sendDataOut->dataLength); // status = MessagePopup ("Debug message", errorMessage); // UIR_STATUS_CHECK(status, MessagePopup()); // DEBUG code if(((UINT32)sendDataOut->dataPtr)==DEFAULT){ /* reply data in ReplyBuffer */ replyDataPtr=primDataPtr+(sizeof(struct SEND_DATA_OUT)/4); }else{ /* read reply data */ replyDataPtr=calloc(sendDataOut->dataLength, sizeof(UINT32)); if(replyDataPtr==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); return(PROGRAM_ERROR); } if(dspType==MASTER_DSP){ errorId=RWmaster(READ, host->slotNumber, (UINT32)sendDataOut->dataPtr, replyDataPtr, sendDataOut->dataLength, HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId, RWmaster()); }else{ /* slave DSP */ /* read data */ errorId=RWslave(READ, host->slotNumber, (UINT8)dspType, (UINT32)sendDataOut->dataPtr, replyDataPtr, sendDataOut->dataLength, 0); ERROR_CHECK(errorId, RWslave()); } } /* process data */ if((sendData->outDataFileName[0]!=0)&&(errorId==SUCCESS)){ /* save reply data to file */ strcpy(subdir, host->dataDir); strcat(subdir, sendData->outDataFileName); errorId=writeToBinFile(subdir, 0, replyDataPtr, sendDataOut->dataLength*sizeof(UINT32)); ERROR_CHECK(errorId, writeToBinFile()); } if(((UINT32)sendDataOut->dataPtr)!=DEFAULT){ free(replyDataPtr); /* !!!! */ } break; case WRITE_TO_FILE: file=(FILE*)inputParameter; fprintf(file, "dataType= %d, auxVal= 0x%X, repBufferFlag= %d, timeout= 0x%X\n", sendData->inputParams.dataType, sendData->inputParams.auxVal, sendData->inputParams.repBufferFlag, sendData->inputParams.timeout); fprintf(file, "outDataFileName[]= %s\n", sendData->outDataFileName); break; case READ_FROM_FILE: file=(FILE*)inputParameter; status=fscanf(file, "dataType= %d, auxVal= 0x%X, repBufferFlag= %d, timeout= 0x%X\n", &sendData->inputParams.dataType, &sendData->inputParams.auxVal, &sendData->inputParams.repBufferFlag, &sendData->inputParams.timeout); if(status==-1) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} status=readLineFromIndex(file, strlen("outDataFileName[]= "), PATHNAME_LENGTH, sendData->outDataFileName); if(status!=0) {ERROR_CHECK(FATAL_ERROR, Read from prim file error!); return(FATAL_ERROR);} break; default: ; } return(errorId); } /******************************************************************************/