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 unsigned long numWords, startAddr;
00024 void* genPtr;
00025 char* textBuff;
00026 long slvNumber = -1;
00027 std::string fileName(""), option;
00028 int slot = -1;
00029 unsigned long baseAddress;
00030
00031 if (argc > 1) {
00032 for (int i=1; i<argc; i++) {
00033 option = argv[i];
00034 if (option[0] != '-') break;
00035 switch (option[1]) {
00036 case 's': {
00037 slot = atoi(option.substr(2).c_str());
00038 break;
00039 }
00040 case 'v': {
00041 slvNumber = atoi(option.substr(2).c_str());
00042 break;
00043 }
00044 default: {
00045 break;
00046 }
00047 }
00048 }
00049 }
00050
00051
00052 if (slot < 0 ) {
00053 cout << "Enter slot number (decimal):";
00054 cin >> slot;
00055 while ((slot < 1) || (slot > 21)) {
00056 cout << "Slot number out or range [1:21], re-enter: ";
00057 cin >> slot;
00058 }
00059 }
00060 baseAddress = slot << 24;
00061
00062
00063 RCCVmeInterface *vme1;
00064 try {
00065 vme1 = new RCCVmeInterface();
00066 }
00067 catch (VmeException &v) {
00068 cout << "VmeException creating VME interface." << endl;
00069 cout << "ErrorClass = " << v.getErrorClass() << endl;
00070 cout << "ErrorCode = " << v.getErrorCode() << endl;
00071 }
00072
00073
00074 RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00075
00076
00077 char * myTextBuffer;
00078 try {
00079 myTextBuffer= new char[TEXT_BUFF_SIZE];
00080 }
00081 catch (std::bad_alloc) {
00082 cout << "Unable to allocate text buffer in main.";
00083 }
00084
00085
00086 if (slvNumber < 0 ) {
00087 cout << "Enter slave number (0-3):";
00088 cin >> slvNumber;
00089 while ((slvNumber < 0) || (slvNumber > 3)) {
00090 cout << "Slave number out or range [0:3], re-enter: ";
00091 cin >> slvNumber;
00092 }
00093 }
00094
00095 cout << "Enter starting address (hex without leading 0x):";
00096 cin >> hex >> startAddr;
00097 cout << "Enter number of data words (hex without leading 0x): ";
00098 cin >> hex >> numWords;
00099 long* primData;
00100 try {
00101 primData = new long[5];
00102 }
00103 catch (std::bad_alloc) {
00104 cout << "Unable to allocate echoData in main.";
00105 }
00106
00107 primData[0] = slvNumber;
00108 primData[1] = 1;
00109 primData[2] = startAddr;
00110 primData[3] = DEFAULT;
00111 primData[4] = numWords;
00112
00113 RodPrimitive* rwSlave;
00114 try {
00115 rwSlave= new RodPrimitive(9, 1, RW_SLAVE_MEMORY, R_RW_SLAVE_MEMORY, primData);
00116 }
00117 catch (std::bad_alloc) {
00118 cout << "Unable to allocate RW_SLAVE_MEMORY primitive in main.";
00119 }
00120
00121 primList.insert(primList.begin(), *rwSlave);
00122 try {
00123 primList.bufferBuild();
00124 }
00125 catch (PrimListException &p) {
00126 cout << p.getDescriptor() << " ";
00127 cout << p.getData1() << ", " << p.getData2() << "\n";
00128 };
00129 try {
00130 rod0->sendPrimList(&primList);
00131 }
00132 catch (HpiException &h) {
00133 cout << h;
00134 }
00135 catch (VmeException &v) {
00136 cout << "VmeException in SendPrimList." << endl;
00137 cout << "ErrorClass = " << v.getErrorClass() << endl;
00138 cout << "ErrorCode = " << v.getErrorCode() << endl;
00139 };
00140 delete [] primData;
00141
00142
00143
00144
00145
00146 do {
00147 try {
00148 returnPState = rod0->primHandler();
00149 }
00150 catch (VmeException &v) {
00151 cout << "VmeException in first primHandler call." << endl;
00152 cout << "ErrorClass = " << v.getErrorClass() << endl;
00153 cout << "ErrorCode = " << v.getErrorCode() << endl;
00154 }
00155 try {
00156 returnTState = rod0->textHandler();
00157 }
00158 catch (VmeException &v) {
00159 cout << "VmeException in first textHandler call." << endl;
00160 cout << "ErrorClass = " << v.getErrorClass() << endl;
00161 cout << "ErrorCode = " << v.getErrorCode() << endl;
00162 }
00163 if (returnTState == TEXT_RQ_SET) {
00164 do {
00165 try {
00166 returnTState = rod0->textHandler();
00167 }
00168 catch (VmeException &v) {
00169 cout << "VmeException in second textHandler call." << endl;
00170 cout << "ErrorClass = " << v.getErrorClass() << endl;
00171 cout << "ErrorCode = " << v.getErrorCode() << endl;
00172 }
00173 } while (returnTState != TEXT_READOUT);
00174 rod0->getTextBuffer(myTextBuffer, myTextLength, myTextType);
00175 rod0->clearTextBuffer();
00176 for (int i=0; i<myTextLength; i++) {
00177 cout << myTextBuffer[i];
00178 if (0==(i+1)%64) cout << endl;
00179 }
00180 cout << endl;
00181 }
00182 } while (returnPState != PRIM_EXECUTING);
00183 do {
00184 try {
00185 returnPState = rod0->primHandler();
00186 }
00187 catch (RodException &r) {
00188 cout << r;
00189 }
00190 catch (VmeException &v) {
00191 cout << "VmeException in second primHandler call." << endl;
00192 cout << "ErrorClass = " << v.getErrorClass() << endl;
00193 cout << "ErrorCode = " << v.getErrorCode() << endl;
00194 }
00195 } while (returnPState != PRIM_WAITING);
00196
00197
00198 RodOutList* outList = rod0->getOutList();
00199
00200
00201 UINT32 outLength = UINT32(outList->getLength());
00202 unsigned long* outBody = outList->getBody();
00203 UINT32 outIndex = UINT32(outBody[1]);
00204 UINT32 outNumPrims = outBody[2];
00205 UINT32 outPrimVersion = outBody[3];
00206 cout << "outLength = " << outLength << ", outIndex = " << outIndex <<
00207 ", outNumPrims = " << outNumPrims << ", outPrimVersion = " <<
00208 outPrimVersion <<'\n';
00209 int outPtr = 4;
00210 for (UINT32 j=0; j<outNumPrims; j++) {
00211 UINT32 primLength = outBody[outPtr++];
00212 UINT32 primIndex = outBody[outPtr++];
00213 UINT32 primId = outBody[outPtr++];
00214 UINT32 primVersion = outBody[outPtr++];
00215 cout << "primLength = " << primLength << ", primIndex = " << primIndex <<
00216 ", primId = " << primId << ", primVersion = " << primVersion << '\n';
00217 cout << "RW_SLAVE_MEMORY data: " << endl;
00218 hex(cout);
00219 for (UINT32 i=0; i<primLength-4; i++) {
00220 cout.width(8);
00221 cout << outBody[i+outPtr] <<" ";
00222 if (0 == (i+1)%8) cout << endl;
00223 };
00224 if (0 != (primLength-4)%8) cout << endl;
00225 dec(cout);
00226
00227 cout.fill(' ');
00228 genPtr = static_cast<void*>(outBody);
00229 textBuff = static_cast<char*>(genPtr);
00230 cout << endl << "ASCII dump :" << endl;
00231 for (unsigned int itext = 0; itext< 4*numWords; itext++) {
00232 if ((textBuff[itext]<' ') || (textBuff[itext] > '~')) textBuff[itext] = '.';
00233 cout << textBuff[itext];
00234 if ((itext+1)%64 == 0) cout << endl;
00235 }
00236 cout << endl;
00237 };
00238
00239
00240 primList.clear();
00241 delete rwSlave;
00242 delete [] myTextBuffer;
00243 rod0->deleteOutList();
00244
00245
00246 delete rod0;
00247 delete vme1;
00248
00249 return 0;
00250 }
00251
00252