00001
00002
00003 #include <iostream>
00004 using namespace std;
00005
00006 #include <ctype.h>
00007
00008 #include "RodModule.h"
00009
00010 #include "primParams.h"
00011 #include "RCCVmeInterface.h"
00012 #include "parameters.h"
00013
00014 int main(int argc, char *argv[]) {
00015
00016 using namespace SctPixelRod;
00017
00018 RodPrimList primList(1);
00019 long myTextLength;
00020 TEXT_BUFFER_TYPE myTextType;
00021 PrimState returnPState;
00022 TextBuffState returnTState;
00023
00024 std::string fileName(""), option;
00025 int slot = -1;
00026 unsigned long baseAddress;
00027
00028 if (argc > 1) {
00029 for (int i=1; i<argc; i++) {
00030 option = argv[i];
00031 if (option[0] != '-') break;
00032 switch (option[1]) {
00033 case 's': {
00034 slot = atoi(option.substr(2).c_str());
00035 break;
00036 }
00037 default: {
00038 break;
00039 }
00040 }
00041 }
00042 }
00043
00044
00045 if (slot < 0 ) {
00046 cout << "Enter slot number (decimal):";
00047 cin >> slot;
00048 while ((slot < 1) || (slot > 21)) {
00049 cout << "Slot number out or range [1:21], re-enter: ";
00050 cin >> slot;
00051 }
00052 }
00053 baseAddress = slot << 24;
00054
00055
00056 RCCVmeInterface *vme1;
00057 try {
00058 vme1 = new RCCVmeInterface();
00059 }
00060 catch (VmeException &v) {
00061 cout << "VmeException creating VME interface." << endl;
00062 cout << "ErrorClass = " << v.getErrorClass() << endl;
00063 cout << "ErrorCode = " << v.getErrorCode() << endl;
00064 }
00065
00066
00067 RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00068 try{
00069 rod0->initialize();
00070 }
00071 catch (HpiException &h) {
00072 hex(cout);
00073 cout << h.getDescriptor() << '\n';
00074 cout << "calcAddr: " << h.getCalcAddr() << ", readAddr: " <<
00075 h.getReadAddr() << '\n';
00076 dec(cout);
00077 }
00078 catch (VmeException &v) {
00079 cout << "VmeException creating RodModule." << endl;
00080 cout << "ErrorClass = " << v.getErrorClass() << endl;
00081 cout << "ErrorCode = " << v.getErrorCode() << endl;
00082 }
00083 catch (RodException &r) {
00084 cout << r.getDescriptor() <<", " << r.getData1() << ", " << r.getData2()
00085 << '\n';
00086 }
00087
00088
00089 char * myTextBuffer;
00090 try {
00091 myTextBuffer= new char[TEXT_BUFF_SIZE];
00092 }
00093 catch (std::bad_alloc) {
00094 cout << "Unable to allocate text buffer in main.";
00095 }
00096
00097 long echoData1[2] = {0xDEADF00D,0};
00098 RodPrimitive* echo1;
00099 try {
00100 echo1= new RodPrimitive(6, 1, ECHO, R_ECHO, echoData1);
00101 }
00102 catch (std::bad_alloc) {
00103 cout << "Unable to allocate echo1 primitive in main.";
00104 }
00105 primList.insert(primList.begin(), *echo1);
00106 long echoData2[3] = {0x01234567, 0x89abcdef, 0xa0a0a0a0};
00107 RodPrimitive* echo2;
00108 try {
00109 echo2= new RodPrimitive(7, 2, ECHO, R_ECHO, echoData2);
00110 }
00111 catch (std::bad_alloc) {
00112 cout << "Unable to allocate echo2 primitive in main.";
00113 }
00114 primList.insert(primList.end(), *echo2);
00115 long echoData3[4] = {0xa5a5a5a5, 0x0f0f0f0f, 0x11111111, 0x77777777};
00116 RodPrimitive* echo3;
00117 try {
00118 echo3= new RodPrimitive(8, 3, ECHO, R_ECHO, echoData3);
00119 }
00120 catch (std::bad_alloc) {
00121 cout << "Unable to allocate echo3 primitive in main.";
00122 }
00123 primList.insert(primList.end(), *echo3);
00124 try {
00125 primList.bufferBuild();
00126 }
00127 catch (PrimListException &p) {
00128 cout << p.getDescriptor() << " ";
00129 cout << p.getData1() << ", " << p.getData2() << "\n";
00130 };
00131 try {
00132 rod0->sendPrimList(&primList);
00133 }
00134 catch (HpiException &h) {
00135 hex(cout);
00136 cout << h.getDescriptor() << '\n';
00137 cout << "calcAddr: " << h.getCalcAddr() << ", readAddr: " <<
00138 h.getReadAddr() << '\n';
00139 dec(cout);
00140 }
00141 catch (VmeException &v) {
00142 cout << "VmeException in SendPrimList." << endl;
00143 cout << "ErrorClass = " << v.getErrorClass() << endl;
00144 cout << "ErrorCode = " << v.getErrorCode() << endl;
00145 };
00146
00147
00148
00149
00150
00151 do {
00152 try {
00153 returnPState = rod0->primHandler();
00154 }
00155 catch (VmeException &v) {
00156 cout << "VmeException in first primHandler call." << endl;
00157 cout << "ErrorClass = " << v.getErrorClass() << endl;
00158 cout << "ErrorCode = " << v.getErrorCode() << endl;
00159 }
00160 try {
00161 returnTState = rod0->textHandler();
00162 }
00163 catch (VmeException &v) {
00164 cout << "VmeException in first textHandler call." << endl;
00165 cout << "ErrorClass = " << v.getErrorClass() << endl;
00166 cout << "ErrorCode = " << v.getErrorCode() << endl;
00167 }
00168 if (returnTState == TEXT_RQ_SET) {
00169 do {
00170 try {
00171 returnTState = rod0->textHandler();
00172 }
00173 catch (VmeException &v) {
00174 cout << "VmeException in second textHandler call." << endl;
00175 cout << "ErrorClass = " << v.getErrorClass() << endl;
00176 cout << "ErrorCode = " << v.getErrorCode() << endl;
00177 }
00178 } while (returnTState != TEXT_READOUT);
00179 rod0->getTextBuffer(myTextBuffer, myTextLength, myTextType);
00180 rod0->clearTextBuffer();
00181 for (int i=0; i<myTextLength; i++) {
00182 cout << myTextBuffer[i];
00183 if (0==(i+1)%64) cout << endl;
00184 }
00185 cout << endl;
00186 }
00187 } while (returnPState != PRIM_EXECUTING);
00188 do {
00189 try {
00190 returnPState = rod0->primHandler();
00191 }
00192 catch (RodException &r) {
00193 cout << r.getDescriptor() <<", " << r.getData1() << ", " << r.getData2()
00194 << '\n';
00195 }
00196 catch (VmeException &v) {
00197 cout << "VmeException in second primHandler call." << endl;
00198 cout << "ErrorClass = " << v.getErrorClass() << endl;
00199 cout << "ErrorCode = " << v.getErrorCode() << endl;
00200 }
00201 } while (returnPState != PRIM_WAITING);
00202
00203
00204 RodOutList* outList = rod0->getOutList();
00205
00206
00207 UINT32 outLength = UINT32(outList->getLength());
00208 unsigned long* outBody = outList->getBody();
00209 UINT32 outIndex = UINT32(outBody[1]);
00210 UINT32 outNumPrims = outBody[2];
00211 UINT32 outPrimVersion = outBody[3];
00212 cout << "outLength = " << outLength << ", outIndex = " << outIndex <<
00213 ", outNumPrims = " << outNumPrims << ", outPrimVersion = " <<
00214 outPrimVersion <<'\n';
00215 int outPtr = 4;
00216 for (unsigned int j=0; j<outNumPrims; j++) {
00217 UINT32 primLength = outBody[outPtr++];
00218 UINT32 primIndex = outBody[outPtr++];
00219 UINT32 primId = outBody[outPtr++];
00220 UINT32 primVersion = outBody[outPtr++];
00221 cout << "primLength = " << primLength << ", primIndex = " << primIndex <<
00222 ", primId = " << primId << ", primVersion = " << primVersion << '\n';
00223 cout << "ECHO data: ";
00224 hex(cout);
00225 for (unsigned int i=0; i<primLength-4; i++) {
00226 cout.width(8);
00227 cout << outBody[i+outPtr] <<" ";
00228 if (0 == (i+1)%8) cout << endl;
00229 };
00230 outPtr += primLength-4;
00231 if (0 != (primLength-4)%8) cout << endl;
00232 dec(cout);
00233 };
00234
00235
00236 unsigned long* myOutBody;
00237 try {
00238 myOutBody= new unsigned long[outLength];
00239 }
00240 catch (std::bad_alloc) {
00241 cout << "Unable to allocate myOutBody in main." << endl;
00242 }
00243 for (unsigned int i=0; i<outLength; i++) {
00244 myOutBody[i] = outBody[i];
00245 };
00246
00247
00248 primList.clear();
00249 delete myOutBody;
00250 delete echo3;
00251 delete echo2;
00252 delete echo1;
00253 delete [] myTextBuffer;
00254 rod0->deleteOutList();
00255
00256
00257 delete rod0;
00258 delete vme1;
00259
00260 return 0;
00261 }
00262
00263