/****************************************************************************** * * Title : commandListExecution.c * Version 0.0 * * Description: HostControl thread. * * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include "commandListDefinitions.h" #include "globalDefinitions.h" #include "threadUtility.h" #include "errorHandler.h" #include "rodInit.h" #include "uirUtility.h" #include "mainUir.h" #include "vmeHpiUtility.h" #include "commandStatusMessage.h" #include "commandListExecution.h" #include #include "RWlists.h" /****************************************************************************** * Static Function Declarations * ******************************************************************************/ static void commandListExecution(struct HOST *host, char commandListFile[], char commandStatusFile[]); /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * hostControl_thread() *============================================================================= * * Thist thread performs any host[n] control specific tasks, * which cannot be executed directly in mainThread(GUI!). * It's currently driven by commands issued from UserInteface. * * Input: ->host - pointer to host struct variable defined in * hostDefinitions.h; * Output: -> can return only SUCCESS. * * Note: This is a thread routine - calling is WIN32 dependent(WINAPI), so * number of input parameters (1), input type (32b. pointer to input parameters), * and return type (DWORD, ERROR_ID is 32b) are MANDATORY. * */ ERROR_ID WINAPI cmdListExec_thread(struct HOST* host){ ERROR_ID errorId; int status; char commandListFile[PATHNAME_LENGTH]; char commandStatusFile[PATHNAME_LENGTH]; char string[300]; /* get command list status file names */ strcpy(commandStatusFile, host->dataDir); sprintf(string, COMMAND_STATUS_FILE_NAME"%d.TXT", host->slotNumber); strcat(commandStatusFile, string); strcpy(commandListFile, host->dataDir); sprintf(string, COMMAND_LIST_FILE_NAME"%d.cl", host->slotNumber); strcat(commandListFile, string); host->commandStatusFile=commandStatusFile; while(1){ /* suspend thread */ host->cmdListExecState=CMDLISTEXEC_IDLE; displayCmdListExecBusy(host); errorId=suspendThread(GetCurrentThread()); ERROR_CHECK(errorId, suspendThread()); if(errorId!=SUCCESS) continue; if((global.option.programExit==TRUE)||(host->option.hostExit==TRUE)){ break; } if(host->cmdListExecState!=CMDLISTEXEC_BUSY) continue; else{ commandListExecution(host, commandListFile, commandStatusFile); } } return(SUCCESS); } /****************************************************************************** * Static functions * ******************************************************************************/ /*============================================================================= * commandListExecution() *============================================================================= * * Command list execution routine. * */ static void commandListExecution(struct HOST *host, char commandListFile[PATHNAME_LENGTH], char commandStatusFile[PATHNAME_LENGTH]){ ERROR_ID errorId; int status; int commandIndex; struct COMMAND *command; UINT32 commandRepCount; UINT32 commandListRepCount; char inputText[1000]; char *cfile; //UINT32 length; int ifError; UINT32 tempValue; if(host->cListFile[0]==0){ /* save command list */ errorId=writeCmdListFile(commandListFile, &host->commandList); ERROR_CHECK(errorId, writeCmdListFile()); cfile=commandListFile; }else{ cfile=host->cListFile; } SetCtrlVal(host->panel.commandListStatus, CLISTP_NUM_COMMANDS, host->commandList.commandCount); sprintf(inputText,"******************* Date:%s, Time:%s *******************\n%s\nCLIST START (NumCmds:%d; ListRep:%d)\n", DateStr(), TimeStr(), cfile, host->commandList.commandCount, host->option.commandListRepetitions); errorId=commandStatusMessage(host, commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); for(commandListRepCount=0; commandListRepCount<=host->option.commandListRepetitions; ++commandListRepCount){ if(host->cmdListExecState==CMDLISTEXEC_ABORT) break; GET_AND_SET_CTRL_VAL(host->panel.commandListStatus, CLISTP_LIST_REP_COUNTER, commandListRepCount, &tempValue); for(commandIndex=0; commandIndexcommandList.commandCount; ++commandIndex){ if(host->cmdListExecState==CMDLISTEXEC_ABORT) break; GET_AND_SET_CTRL_VAL(host->panel.commandListStatus, CLISTP_COMMAND_INDEX, commandIndex, &tempValue); command=&host->commandList.command[commandIndex]; host->option.commandRepetitions=command->numRepetitions; status=SetInputMode(host->panel.commandListStatus, CLISTP_CMDREP_COUNT, command->id!=SEND_PRIM_LIST_COMMAND_ID); UIR_STATUS_CHECK(status, SetInputMode()); GET_AND_SET_CTRL_VAL(host->panel.commandListStatus, CLISTP_COMMAND_RING, command->id, &tempValue); GET_AND_SET_CTRL_VAL(host->panel.commandListStatus, CLISTP_CMDREP, command->numRepetitions, &tempValue); /* execute command */ for(commandRepCount=0; commandRepCount<=host->option.commandRepetitions; ++commandRepCount){ if(host->cmdListExecState==CMDLISTEXEC_ABORT) break; GET_AND_SET_CTRL_VAL(host->panel.commandListStatus, CLISTP_CMDREP_COUNT, commandRepCount, &tempValue); switch(command->id){ case SEND_PRIM_LIST_COMMAND_ID: /* no break */ case COMPARE_FILES_COMMAND_ID: /* no break */ case RUN_CHILD_COMMAND_LIST_ID: /* no break */ case RUN_EXTERNAL_PROGRAM_ID: /* no break */ case DELAY_COMMAND_ID: /* no break */ errorId=(*global.commandFunction[command->id])(COMMAND_EXECUTION, command, host->slotNumber, 0); HOST_ERROR_CHECK(errorId, host, commandFunction()); if(errorId!=SUCCESS){ sprintf(inputText,"##COMMAND ERROR (CmdIndex:%d; ListRepCount:%d); Date:%s, Time:%s\n", commandIndex, commandListRepCount, DateStr(), TimeStr()); errorId=commandStatusMessage(host, commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); GetCtrlVal(host->panel.commandListStatus, CLISTP_IF_ERROR, &ifError); /* overload continueIfError */ switch(ifError){ case IF_ERROR_DEFAULT: /* default */ /* do nothing - hold value defined in the list */ break; case IF_ERROR_STOP: /* stop */ command->continueIfError=0; break; case IF_ERROR_CONTINUE: /* continue */ command->continueIfError=1; break; } if(command->continueIfError){ continue; }else{ SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 1); errorId=suspendThread(GetCurrentThread()); ERROR_CHECK(errorId, suspendThread()); SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 0); } } if(command->id!=SEND_PRIM_LIST_COMMAND_ID){ break; } /* else no break */ default: if(command->id!=SEND_PRIM_LIST_COMMAND_ID){ /* command is executed in communicationLoop */ host->command=command; host->commandReady=1; } /* wait for reply */ errorId=waitForEvent(host->commandDone_event); ERROR_CHECK(errorId, waitForEvent()); if(host->commandStatus!=SUCCESS){ sprintf(inputText,"##COMMAND ERROR (CmdIndex:%d; ListRepCount:%d); Date:%s, Time:%s\n", commandIndex, commandListRepCount, DateStr(), TimeStr()); errorId=commandStatusMessage(host, commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); GetCtrlVal(host->panel.commandListStatus, CLISTP_IF_ERROR, &ifError); /* overload continueIfError */ switch(ifError){ case IF_ERROR_DEFAULT: /* default */ /* do nothing - hold value defined in the list */ break; case IF_ERROR_STOP: /* stop */ command->continueIfError=0; break; case IF_ERROR_CONTINUE: /* continue */ command->continueIfError=1; break; } if(command->continueIfError){ continue; }else{ SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 1); errorId=suspendThread(GetCurrentThread()); ERROR_CHECK(errorId, suspendThread()); SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 0); } } break; } if(command->id==SEND_PRIM_LIST_COMMAND_ID) break; /* repeated in primList building or listHandler */ } } } sprintf(inputText,"CLIST END (CmdIndex:%d; ListRepCount:%d)\n=================== Time:%s =====================\n", commandIndex, commandListRepCount, TimeStr()); errorId=commandStatusMessage(host, commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); return; } /******************************************************************************/