Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

XmlTest.cxx

00001 
00025 #include <iostream>
00026 using namespace std;
00027 
00028 #include <ctype.h>
00029 #include <string>
00030 
00031 #include "RodModule.h"
00032 
00033 #include "primParams.h"
00034 #include "RCCVmeInterface.h"
00035 #include "parameters.h"
00036 
00037 int main(int argc, char *argv[]) {
00038 
00039 using namespace SctPixelRod;
00040 
00041   RodPrimList primList(1);                      // Primitive List
00042   long myTextLength;                            // Actual length of text message
00043   TEXT_BUFFER_TYPE myTextType;                  // Buffer type for latest message
00044   PrimState returnPState;
00045   TextBuffState returnTState;
00046   std::string fileName(""), option;
00047   bool initRod = true;
00048   int slot = -1;
00049   unsigned long baseAddress;
00050 
00051   if (argc > 1) {
00052     for (int i=1; i<argc; i++) {
00053       option = argv[i];
00054       if (option[0] != '-') break;
00055       switch (option[1]) {
00056         case 'n': {
00057           initRod = false;
00058           break;
00059         }
00060         case 's': {
00061           slot = atoi(option.substr(2).c_str());
00062           break;
00063         }
00064         case 'f': {
00065           fileName = option.substr(2);
00066           break;
00067         }
00068         default: {
00069           break;
00070         }
00071       }
00072     }
00073   }
00074   
00075 // Prompt for slot number
00076   if (slot < 0 ) {
00077     cout << "Enter slot number (decimal):"; 
00078     cin >> slot;
00079     while ((slot < 1) || (slot > 21)) {
00080       cout << "Slot number out or range [1:21], re-enter: ";
00081       cin >> slot;
00082     }
00083   }
00084   baseAddress = slot << 24;
00085 
00086 // Create VME interface
00087   RCCVmeInterface *vme1;
00088   try {
00089     vme1 = new RCCVmeInterface();
00090   }
00091   catch (VmeException &v) {
00092     cout << "VmeException creating VME interface." << endl;
00093     cout << "ErrorClass = " << v.getErrorClass() << endl;
00094     cout << "ErrorCode = " << v.getErrorCode() << endl; 
00095   }
00096   
00097 // Create RodModule and initialize it
00098   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00099   if (initRod) {
00100     try{
00101       rod0->initialize();
00102     }
00103     catch (HpiException &h) {
00104       cout << h;
00105     }
00106     catch (VmeException &v) {
00107       cout << "VmeException creating RodModule." << endl;
00108       cout << "ErrorClass = " << v.getErrorClass() << endl;
00109       cout << "ErrorCode = " << v.getErrorCode() << endl; 
00110     }
00111     catch (RodException &r) {
00112     cout << r;
00113     }
00114   }
00115 
00116 // Create a buffer for text messages
00117   char * myTextBuffer;
00118   try {
00119     myTextBuffer= new char[TEXT_BUFF_SIZE];
00120   }
00121   catch (std::bad_alloc) {
00122     cout << "Unable to allocate text buffer in main.";
00123   }
00124   
00125 // Read an XML file into primlist buffer
00126   if (fileName == "") {
00127     cout << "Enter name of XML file: ";
00128     cin >> fileName;
00129   }
00130   try {
00131     primList.buildFromXml(fileName);
00132   }
00133   catch (PrimListException &p) {
00134     cout << p.getDescriptor() << " ";
00135     cout << p.getData1() << ", " << p.getData2() << "\n";
00136   };
00137   try {
00138     rod0->sendPrimList(&primList);
00139   }
00140   catch (HpiException &h) {
00141     cout << h;
00142   }
00143   catch (VmeException &v) {
00144     cout << "VmeException in SendPrimList." << endl;
00145     cout << "ErrorClass = " << v.getErrorClass() << endl;
00146     cout << "ErrorCode = " << v.getErrorCode() << endl; 
00147   };
00148   
00149 // Wait for ROD to begin executing and then wait for it to finish executing
00150 // Check for error messages in text buffer and read them out if they exist.
00151 // Note: this is NOT how primHandler and textHandler will be used once we
00152 // go to threads.  This is for debugging the code only.
00153   do {
00154     try {
00155       returnPState = rod0->primHandler();
00156     }
00157     catch (VmeException &v) {
00158       cout << "VmeException in first primHandler call." << endl;
00159       cout << "ErrorClass = " << v.getErrorClass() << endl;
00160       cout << "ErrorCode = " << v.getErrorCode() << endl; 
00161     }
00162     try {
00163       returnTState = rod0->textHandler();
00164     }
00165     catch (VmeException &v) {
00166       cout << "VmeException in first textHandler call." << endl;
00167       cout << "ErrorClass = " << v.getErrorClass() << endl;
00168       cout << "ErrorCode = " << v.getErrorCode() << endl; 
00169     }
00170     if (returnTState == TEXT_RQ_SET) {
00171       do {
00172         try {
00173           returnTState = rod0->textHandler();
00174           }
00175         catch (VmeException &v) {
00176           cout << "VmeException in second textHandler call." << endl;
00177           cout << "ErrorClass = " << v.getErrorClass() << endl;
00178           cout << "ErrorCode = " << v.getErrorCode() << endl; 
00179         }
00180       } while (returnTState != TEXT_READOUT);
00181       rod0->getTextBuffer(myTextBuffer, myTextLength, myTextType);
00182       rod0->clearTextBuffer();
00183       for (int i=0; i<myTextLength; i++) {
00184         cout << myTextBuffer[i];
00185         if (0==(i+1)%64) cout << endl;
00186         }
00187       cout << endl; 
00188     }
00189   } while (returnPState != PRIM_EXECUTING); 
00190   do {
00191     try {
00192       returnPState = rod0->primHandler();
00193     }
00194     catch (RodException &r) {
00195     cout << r;
00196     }
00197     catch (VmeException &v) {
00198       cout << "VmeException in second primHandler call." << endl;
00199       cout << "ErrorClass = " << v.getErrorClass() << endl;
00200       cout << "ErrorCode = " << v.getErrorCode() << endl; 
00201     }
00202   } while (returnPState != PRIM_WAITING); 
00203   
00204 // Retrieve output buffer
00205   RodOutList* outList = rod0->getOutList();
00206   
00207 // Print results (User processing of outList)
00208   UINT32 outLength = UINT32(outList->getLength());
00209   unsigned long* outBody = outList->getBody();
00210   UINT32 outIndex = UINT32(outBody[1]);
00211   UINT32 outNumPrims = outBody[2];
00212   UINT32 outPrimVersion = outBody[3];
00213   cout << "outLength = " << outLength << ", outIndex = " << outIndex << 
00214           ", outNumPrims = " << outNumPrims << ", outPrimVersion = " << 
00215           outPrimVersion <<'\n';
00216   int outPtr = 4;
00217   for (UINT32 j=0; j<outNumPrims; j++) {
00218     UINT32 primLength = outBody[outPtr++];
00219     UINT32 primIndex = outBody[outPtr++];
00220     UINT32 primId = outBody[outPtr++];
00221     UINT32 primVersion = outBody[outPtr++];
00222     cout << "primLength = " << primLength << ", primIndex = " << primIndex << 
00223             ", primId = " << primId << ", primVersion = " << primVersion << '\n';
00224     cout << "ECHO data: " << endl;
00225     hex(cout);
00226     for (UINT32 i=0; i<primLength-4; i++) {
00227       cout.width(8);
00228       cout << outBody[i+outPtr] <<" ";
00229       if (0 == (i+1)%8) cout << endl; 
00230     };
00231     if (0 != (primLength-4)%8) cout << endl;
00232     dec(cout);
00233     outPtr += primLength-4;
00234   };
00235   
00236 // Clean up: clear primList, delete the outList
00237   primList.clear();
00238   delete [] myTextBuffer;
00239   rod0->deleteOutList();
00240   
00241 // Delete the ROD and VME objects before exiting
00242   delete rod0;
00243   delete vme1;
00244 
00245   return 0;  
00246 }
00247 
00248 

Generated on Thu Dec 15 21:14:46 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5