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

MdspSnap.cxx

00001 
00009 #include <iostream>
00010 using namespace std;
00011 
00012 #include <ctype.h>
00013 
00014 #include "RodModule.h"
00015 
00016 #include "RCCVmeInterface.h"
00017 
00018 int main(int argc, char *argv[]) {
00019 
00020 using namespace SctPixelRod;
00021 
00022   const unsigned long mapSize=0xc00040;         // Map size
00023   const long numSlaves=4;                       // Number of slaves
00024   unsigned long numWords;                       // Number of words to dump
00025   long dspStart;                                // Address limits to dump
00026   unsigned long statusVal;
00027   unsigned long txtAddress[4] = {ERR_BUFF_BASE, INFO_BUFF_BASE, \
00028           DIAG_BUFF_BASE, XFER_BUFF_BASE};
00029   void* genPtr;
00030   char* textBuff;
00031 
00032   std::string fileName(""), option;
00033   int slot = -1;
00034   unsigned long baseAddress;
00035 
00036   if (argc > 1) {
00037     for (int i=1; i<argc; i++) {
00038       option = argv[i];
00039       if (option[0] != '-') break;
00040       switch (option[1]) {
00041         case 's': {
00042           slot = atoi(option.substr(2).c_str());
00043           break;
00044         }
00045         default: {
00046           break;
00047         }
00048       }
00049     }
00050   }
00051 
00052 // Prompt for slot number
00053   if (slot < 0 ) {
00054     cout << "Enter slot number (decimal):"; 
00055     cin >> slot;
00056     while ((slot < 1) || (slot > 21)) {
00057       cout << "Slot number out or range [1:21], re-enter: ";
00058       cin >> slot;
00059     }
00060   }
00061   baseAddress = slot << 24;
00062 
00063 // Create VME interface
00064   RCCVmeInterface *vme1 = new RCCVmeInterface();
00065   
00066 // Create RodModule but do not initialize it
00067   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00068 
00069   dspStart = PRIM_BUFF_BASE;
00070   numWords = rod0->mdspSingleRead(dspStart);
00071   if (numWords > PRIM_BUFF_SIZE) numWords = PRIM_BUFF_SIZE;
00072   unsigned long * buffer = new unsigned long[numWords];
00073   rod0->mdspBlockRead(dspStart, buffer, numWords);
00074   
00075 // output the data and delete the buffer
00076   cout << "PRIM Buffer:" << endl;
00077   hex(cout);
00078   cout.fill('0');
00079   for (unsigned int i=0; i<numWords; i+=8) {
00080     cout.width(8); cout << buffer[i]   << ' ';
00081     cout.width(8); cout << buffer[i+1] << ' ';
00082     cout.width(8); cout << buffer[i+2] << ' ';
00083     cout.width(8); cout << buffer[i+3] << ' ';
00084     cout.width(8); cout << buffer[i+4] << ' ';
00085     cout.width(8); cout << buffer[i+5] << ' ';
00086     cout.width(8); cout << buffer[i+6] << ' ';
00087     cout.width(8); cout << buffer[i+7] << endl;
00088   }
00089   dec(cout);
00090   cout.fill(' ');
00091   delete [] buffer;
00092     
00093 // Get the REPLY buffer
00094     dspStart = REPLY_BUFF_BASE;
00095     numWords = rod0->mdspSingleRead(dspStart);
00096     if (numWords > REPLY_BUFF_SIZE) numWords = REPLY_BUFF_SIZE;
00097     buffer = new unsigned long[numWords];
00098     rod0->mdspBlockRead(dspStart, buffer, numWords);
00099   
00100 // output the data and delete the buffer
00101     cout << "REPLY Buffer:" << endl;
00102   hex(cout);
00103   cout.fill('0');
00104   for (unsigned int i=0; i<numWords; i+=8) {
00105     cout.width(8); cout << buffer[i]   << ' ';
00106     cout.width(8); cout << buffer[i+1] << ' ';
00107     cout.width(8); cout << buffer[i+2] << ' ';
00108     cout.width(8); cout << buffer[i+3] << ' ';
00109     cout.width(8); cout << buffer[i+4] << ' ';
00110     cout.width(8); cout << buffer[i+5] << ' ';
00111     cout.width(8); cout << buffer[i+6] << ' ';
00112     cout.width(8); cout << buffer[i+7] << endl;
00113   }
00114   dec(cout);
00115   cout.fill(' ');
00116   delete [] buffer;
00117 
00118 // Read and print the status and command registers  
00119   hex(cout);
00120   for (int i=0; i<3; i++) {
00121     statusVal = rod0->mdspSingleRead(STATUS_REG[i]);
00122     cout << "Status register " << i << " (hex)  = ";
00123     cout.width(8);
00124     cout << statusVal << endl;
00125   }
00126   for (int i=0; i<2; i++) {
00127     statusVal = rod0->mdspSingleRead(COMMAND_REG[i]);
00128     cout << "Command register " << i << " (hex) = ";
00129     cout.width(8);
00130     cout << statusVal << endl;
00131   }
00132   dec(cout);
00133     
00134 // Read and print all four text buffers in both hex and ascii
00135   numWords = 512;  
00136   for (int ibuf=0; ibuf<4; ibuf++) {
00137     dspStart = txtAddress[ibuf];
00138     unsigned long * buffer = new unsigned long[numWords];
00139     rod0->mdspBlockRead(dspStart, buffer, numWords);
00140     switch(ibuf) {
00141       case 0: cout << endl << "Hexadecimal dump of ERR buffer:" << endl;
00142               break;
00143       case 1: cout << endl << "Hexadecimal dump of INFO buffer:" << endl;
00144               break;
00145       case 2: cout << endl << "Hexadecimal dump of DIAG buffer:" << endl;
00146               break;
00147       case 3: cout << endl << "Hexadecimal dump of XFER buffer:" << endl;
00148               break;
00149       }
00150     hex(cout);
00151     cout.fill('0');
00152     for (unsigned int i=0; i<numWords; i+=8) {
00153       cout.width(8); cout << buffer[i]   << ' ';
00154       cout.width(8); cout << buffer[i+1] << ' ';
00155       cout.width(8); cout << buffer[i+2] << ' ';
00156       cout.width(8); cout << buffer[i+3] << ' ';
00157       cout.width(8); cout << buffer[i+4] << ' ';
00158       cout.width(8); cout << buffer[i+5] << ' ';
00159       cout.width(8); cout << buffer[i+6] << ' ';
00160       cout.width(8); cout << buffer[i+7] << endl;
00161     }
00162     dec(cout);
00163     cout.fill(' ');
00164     genPtr = static_cast<void*>(buffer);
00165     textBuff = static_cast<char*>(genPtr);
00166     switch(ibuf) {
00167       case 0: cout << endl << "ASCII dump of ERR buffer:" << endl;
00168               break;
00169       case 1: cout << endl << "ASCII dump of INFO buffer:" << endl;
00170               break;
00171       case 2: cout << endl << "ASCII dump of DIAG buffer:" << endl;
00172               break;
00173       case 3: cout << endl << "ASCII dump of XFER buffer:" << endl;
00174               break;
00175       }
00176       for (unsigned int itext = 0; itext< 4*numWords; itext++) {
00177         if ((textBuff[itext]<' ') || (textBuff[itext] > '~')) textBuff[itext] = '.';
00178         cout << textBuff[itext];
00179         if ((itext+1)%64 == 0) cout << endl;
00180       }
00181       cout << endl;
00182         
00183     delete [] buffer;
00184   }
00185     
00186 // Clean up before exiting
00187   delete rod0;
00188   delete vme1;
00189 
00190   return 0;  
00191 }
00192 
00193 

Generated on Fri Sep 16 18:01:53 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5