// // CtrlBlock.cpp // #include "afx.h" #include #include "DaqSetup.h" #include "LogFile.h" extern "C" { #include #include "messages.h" } #include "CtrlBlock.h" // #include "DaqEnv.h" // ====================================== // constructor // ====================================== CtrlBlock::CtrlBlock () { for ( int i = 0; i < 4; i++ ) _fileNames[i][0] = '\0'; } // ======================================== // load control block // ======================================== int CtrlBlock::load (int fifoNr, char *fileName) { // --------------------- // open ctrl-file // --------------------- DaqSetup* daq = daq->Instance (); DaqEnv* daqEnv = daq->daqEnv (); if ( daqEnv == 0 ) return 0; CString fileNamePath; if ( daqEnv->getFileDir (CtrlBlkDir, fileName, fileNamePath) == 0 ) { logFile << " file: " << fileNamePath << endl; return 0; } CStdioFile cb_file; if( !cb_file.Open ((char *) (LPCTSTR) fileNamePath, CFile::modeRead) ) { logFile << "Unable to open file " << fileName << endl; sprintf ( &_fileNames[fifoNr][0], "error"); return 0; } else { logFile << " open cb-file " << fileNamePath << endl; sprintf ( &_fileNames[fifoNr][0], "%s", fileName); } // -------------------- // read file // -------------------- char buffer[101]; int nRepeat, setCal, setCom; int lineCount = 0; int i, blkData[2048]; for ( i = 0; i < 2048; i++ ) blkData[i] = 0; while ( cb_file.ReadString (buffer, 100) ) { if ( buffer[0] != '#' ) { if ( sscanf (buffer, "%d %x %x", &nRepeat, &setCal, &setCom) == 3 ) { setCal = 0x000000f0 & (setCal << 4 ); setCal |= 0x0000000f & setCom; while ( lineCount < 2048 && nRepeat > 0 ) { blkData [lineCount] = setCal; ++lineCount; --nRepeat; } } } } cb_file.Close (); // ----------------------- // load block // ----------------------- do_load_control_block (fifoNr, blkData); return 1; } // ======================================== // execute control block // ======================================== void CtrlBlock::execute (int fifoNr, int num_rep) { do_execute_control_block (fifoNr, num_rep); } // ======================================== // name // ======================================== char* CtrlBlock::name (int fifoNr) { if ( fifoNr >= 0 && fifoNr <= 3 ) return &_fileNames[fifoNr][0]; else return NULL; }