EchoSlaveTest.cxx

00001 #define USELIBRARY
00002 
00003 #include <iostream>
00004 
00005 #include "../TApi.h"
00006 
00007 using namespace std;
00008 
00009 int main (int argc, char **argv) {
00010   TApi tapi;
00011 
00012   tapi.initialiseAll(0);
00013 
00014   bool cont = true;
00015 
00016   int repetitions = 1;
00017   int length = 2;
00018 
00019   if(argc > 1) {
00020     for(int i=1; i<argc; i++) {
00021       if(argv[i][0] == '-') {
00022         switch(argv[i][1]) {
00023         case 'r':
00024           repetitions = atoi(&argv[i][2]);
00025           break;
00026         case 'l':
00027           length = atoi(&argv[i][2]);
00028           break;
00029         }
00030       }
00031     }
00032   }
00033 
00034   // Create and Send a simple ECHO primitive
00035   unsigned long *echoData; // [2] = {0xDEADF00D,0};
00036 
00037   echoData = new unsigned long[length];
00038 
00039   if(length < 3) {
00040     if(length > 0) echoData[0] = 0xDEADF00D;
00041     if(length > 1) echoData[1] = 0x0;
00042   } else {
00043     for (int i=0; i<length; i++) {
00044       echoData[i] = 0xBEAD0000 + i;
00045     }
00046   }
00047 
00048   tapi.createDebugPrimList();
00049 
00050   const int ECHO = 0;
00051   const int R_ECHO = 100;
00052 
00053   tapi.addDebugPrimList(4 + length, 1, ECHO, R_ECHO, echoData);
00054 
00055   // Send echo primitive
00056 
00057   cout << "ECHO3 sending standard primlist\n";
00058 
00059   cout << " Sending slave echo primlists\n";
00060 
00061   try {
00062     for(int rep = 0; rep<repetitions && cont; rep++) {
00063       // Send echo primitive via slave DSP
00064 
00065       try {
00067         if(cont)
00068           tapi.sendDebugSlavePrimList(0, 0, 1, 1);
00069       } catch(...) {
00070         cout << "Exception sending echo primitive\n";
00071         cont = false;
00072       }
00073 
00074       try {
00075         if(cont) { 
00076 //           cerr << "Going to await response\n";
00077           tapi.awaitResponse(0);
00078 //           cerr << "Done await response\n";
00079         }
00080       } catch(...) {
00081         cout << "Exception awaiting echo response\n";
00082         cont = false;
00083       }
00084 
00085       unsigned long outLength;
00086 
00087       unsigned long *outBody = tapi.getResponse(0, &outLength);
00088       // Decode the reponse
00089       if(outBody) {
00090         if(rep == 0) {
00091           // Print raw hex data
00092           hex(cout);
00093           for (unsigned int i=0; i<outLength; i++) {
00094             cout.width(8);
00095             cout << outBody[i] << " ";
00096             if (0 == (i+1)%8) cout << endl; 
00097           }
00098           if (0 != (outLength)%8) cout << endl;
00099           dec(cout);
00100 
00101           // User processing slightly more difficult as have to
00102           // read the outlist returned by the slave
00103         }
00104 
00105         bool correct = true;
00106         for(int i=0; i<length; i++) {
00107           if(outBody[i+16] != echoData[i]) {
00108             correct = false;
00109 
00110             cout << "Check failed! " << rep << " + " << i << "\n";
00111             cout << hex << " 0x" << outBody[i+16] << " != 0x" << echoData[i] << dec << "\n";
00112 
00113             break;
00114           }
00115         }
00116 
00117         if(correct) cerr << ".";
00118 
00119         delete [] outBody;
00120       } else {
00121         cout << "Response was null\n";
00122       }
00123     }
00124     cout << "Complete\n";
00125   } catch(...) { // SctPixelRod::BaseException &b) {
00126     cout << "Got exception!" << endl;
00127   }
00128 
00129   try {
00130     cerr << "Check text buffers...\n";
00131     tapi.awaitResponse(0, 1);
00132     cerr << "Done await response\n";
00133   } catch(...) {
00134     cout << "Exception checking text buffers?\n";
00135   }
00136 
00137   tapi.shutdownAll();
00138 }
00139 

Generated on Mon Feb 6 14:01:19 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6