/****************************************************************************** * * Title : rccMain.c * Version 0.0 * * Description: RCC main program function - main process. * Related files: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include #include "errorHandler.h" #include "loadExitHost.h" #include #include #include #include "mainUir.h" #include "uirUtility.h" #include /****************************************************************************** * Global Variable Declarations * ******************************************************************************/ struct GLOBAL_VARIABLES global; /*============================================================================= ******************************* RCC MAIN() *********************************** *============================================================================= * * * */ int main (int argc, char *argv[]){ /* local variable declaration */ ERROR_ID errorId; int status; char errorMessage[200]; int programHandle; /*------------------- Rcc initialization -----------------*/ /* clear global struct */ memset(&global,0,sizeof(struct GLOBAL_VARIABLES)); /* init critical sections which protect shared resources */ InitializeCriticalSection(&global.saveToErrorFileCriticalSection); InitializeCriticalSection(&global.vmeAccessCriticalSection ); /* get main project directory */ status=GetProjectDir(global.mainDir); global.mainDir[strlen(global.mainDir)-strlen(RCC_SUBDIR)+1]=0; if(status!=0){ printf("Invalid project directory(%s)!!.", global.mainDir); printf("\nPress any key to quit."); getchar(); return(-1); } /* get error file name */ strcpy(global.errorFileName, global.mainDir); strcat(global.errorFileName, ERROR_FILE_NAME); LOAD_PANEL(&global.panel.error,0, "mainUir.uir", ERROR_PAN); if(ConfirmPopup ("ConfirmPopup", "Run RESMAN and InitVXIlibrary()?")){ global.option.vme=1; }else{ global.option.vme=0; } if(global.option.vme){ /* run resource manager */ status=LaunchExecutableEx(VME_RESOURCE_MANAGER, LE_SHOWNORMAL, &programHandle); if(status==-3) status=LaunchExecutableEx(VME_RESOURCE_MANAGER_2, LE_SHOWNORMAL, &programHandle); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "LaunchExecutable()", status, ""); }else{ while(1){ status=ExecutableHasTerminated(programHandle); if(status==1) break; Sleep(200); } } /* * VXI initialization */ status=InitVXIlibrary(); if(status!=0){ errorId=FATAL_ERROR; programError(__FILE__, __LINE__, errorId, "InitVXIlibrary()", status,""); return(errorId); } } errorId=hostGlobalInit(&global); ERROR_CHECK(errorId, hostInit()); if(errorId!=SUCCESS) return(errorId); /* start user interface */ global.uirReturnCode=RunUserInterface (); /*----------------------- Rcc exit -----------------------*/ errorId=shutdownApplication(&global); ERROR_CHECK(errorId, shutdownApplication()); if(global.option.vme){ /* * Close VXI */ status=CloseVXIlibrary(); if(status!=0){ errorId=FATAL_ERROR; programError(__FILE__, __LINE__, errorId, "CloseVXIlibrary()", status,""); } } /* delete critical sections */ DeleteCriticalSection(&global.saveToErrorFileCriticalSection); DeleteCriticalSection(&global.vmeAccessCriticalSection); /* * Free dynamic memory buffers (memory access GUI) */ if(global.masterMemoryRead!=NULL){ free(global.masterMemoryRead); global.masterMemoryRead=NULL; } if(global.masterMemoryRead!=NULL){ free(global.masterMemoryRead); global.masterMemoryRead=NULL; } if(global.slaveMemoryRead!=NULL){ free(global.slaveMemoryRead); global.slaveMemoryRead=NULL; } if(global.slaveMemoryRead!=NULL){ free(global.slaveMemoryRead); global.slaveMemoryRead=NULL; } if(global.vmeMemoryRead!=NULL){ free(global.vmeMemoryRead); global.vmeMemoryRead=NULL; } if(global.vmeMemoryWrite!=NULL){ free(global.vmeMemoryWrite); global.vmeMemoryWrite=NULL; } return 0; } /******************************************************************************/