Echo2Test.cxx

00001 #define USELIBRARY
00002 
00003 #include <iostream>
00004 
00005 #include "../TApi.h"
00006 
00007 void readResponse(TApi &tapi);
00008 
00009 using namespace std;
00010 
00011 //  TApi *tapi;
00012 
00013 int main () {
00014   TApi tapi;
00015 
00016   tapi.initialiseAll(0);
00017 
00018   // Create and Send ECHO primitives
00019 
00020   unsigned long echo1Data[2] = {0xABCDF00D,0};
00021   tapi.echo(0, 2, echo1Data);
00022   readResponse(tapi);
00023 
00024   unsigned long echo2Data[3] = {0xFFFFFFFF, 0xA0A0A0A0, 0x55555555};
00025   tapi.echo(0, 3, echo2Data);
00026   readResponse(tapi);
00027 
00028   unsigned long echo3Data[4] = {0xABCDEF77, 0x01234567, 0x89ABCDEF, 0xA5A5A5A5};
00029   tapi.echo(0, 4, echo3Data);
00030   readResponse(tapi);
00031 
00032   // Tidy up
00033   tapi.shutdownAll();
00034   //  delete tapi;
00035 
00036   return 0;  
00037 }
00038 
00039 void readResponse(TApi &tapi) {
00040   tapi.awaitResponse(0);
00041 
00042   unsigned long length;
00043 
00044   unsigned long *response = tapi.getResponse(0, &length);
00045 
00046   unsigned long outIndex = (unsigned long)(response[1]);
00047   unsigned long outNumPrims = response[2];
00048   unsigned long outPrimVersion = response[3];
00049   cout << "outLength = " << length << ", outIndex = " << outIndex << 
00050     ", outNumPrims = " << outNumPrims << ", outPrimVersion = " << 
00051     outPrimVersion <<'\n';
00052   int outPtr = 4;
00053   for (unsigned int j=0; j<outNumPrims; j++) {
00054     unsigned long primLength = response[outPtr++];
00055     unsigned long primIndex = response[outPtr++];
00056     unsigned long primId = response[outPtr++];
00057     unsigned long primVersion = response[outPtr++];
00058     cout << "primLength = " << primLength << ", primIndex = " << primIndex << 
00059       ", primId = " << primId << ", primVersion = " << primVersion << '\n';
00060     cout << "ECHO data: ";
00061     hex(cout);
00062     for (unsigned int i=0; i<primLength-4; i++) {
00063       cout.width(8);
00064       cout << response[outPtr++] <<" ";
00065       if (0 == (i+1)%8) cout << endl; 
00066     };
00067     if (0 != (primLength-4)%8) cout << endl;
00068     dec(cout);
00069   }
00070 
00071   delete [] response;
00072 }

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