pixeltrigger.cpp

Go to the documentation of this file.
00001 //============================================================================
00002 // Name        : pixeltrigger.cpp
00003 // Author      : Gianluca and Cesar
00004 // Version     :
00005 // Copyright   : GNU License is good for you
00006 // Description : Hello World in C++, Ansi-style
00007 //============================================================================
00008 
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <sstream>
00013 #include <log4cpp/BasicConfigurator.hh>
00014 #include <log4cpp/Category.hh>
00015 #include <log4cpp/FileAppender.hh>
00016 #include <log4cpp/PatternLayout.hh>
00017 #include <sstream>
00018 #include <dis.hxx>                      //dim server stuff 
00019 
00020 #include "pit_def.h"
00021 #include "pit_driver.h"
00022 #include "pit_comm.h"
00023 #include "pit_configuration.h"
00024 #include "pit_keyboard.h"
00025 #include "DimAppender.h"
00026 
00027 using namespace std;
00028 // Compares two arrays of 32 bit registers, useful for the stress testing
00029 int compareArrays(UInt32 *a1, UInt32 *a2, int size);
00030 
00031 // function to stress test a memory block in the hardware 
00032 void testReadMemBlock(pit_driver * pit, UInt19 startAdress = 0x1800000, UInt19 numberOfWords= 0x1000, UInt19 blockSize = 1024);
00033 // it reads 0x1000 words from the hardware, but word by word and not using the read block functionality 
00034 void testReadWord(pit_driver * pit, UInt19 startAdress = 0x1800000, UInt19 numberOfWords= 0x1000);
00035 
00036 void simulate_values(pit_driver *pit);
00037 
00038 int main(void){
00039 
00040 
00041 
00042         // Logger instantiation, using log4cpp library
00043         // create appender to log file
00044         log4cpp::Appender* fileApp = new log4cpp::FileAppender("FileAppender","./pit.log");
00045         // creates a dim appender class
00046         log4cpp::Appender* dimApp = new log4cpp::DimAppender("DimAppender", DIM_LOG_NAME);
00047         // create a PatternLayout
00048         log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
00049 
00050         // set the format
00051         layout->setConversionPattern("%d{%Y %b %d %a %H:%M:%S,%l} %p %c %x: %m%n");
00052 
00053         fileApp->setLayout(layout);
00054         dimApp->setLayout(layout);
00055 
00056         //log4cpp::BasicConfigurator::configure();
00057         log4cpp::Category& logger = log4cpp::Category::getInstance("pitLog");
00058 
00059 
00060         //log4cpp::Appender* dimApp2 = new log4cpp::DimAppender("dummylog", "dummyService");
00061         //log4cpp::Appender* dimApp3 = new log4cpp::DimAppender("DimAppender3", "yetAnotherLogService");
00062 
00063                 
00064         logger.setAdditivity(true);
00065 
00066                 // there is some kind of problem while using the fileAppender 
00067                 // if there are more than one appender in the category
00068                 // so here we are not passing the 
00069         logger.addAppender(*fileApp);
00070         logger.addAppender(dimApp);                                     // adds the dim appender
00072         //logger.addAppender(dimApp3);                          // adds the dim appender
00073          
00074         logger.setPriority(log4cpp::Priority::DEBUG); //here the logginess can be changed
00075         dimApp->setThreshold(log4cpp::Priority::DEBUG);// here we can set the priority of the dim logging
00076         
00077 
00078         //Get the instance of the configuration handler
00079         pit_configuration& configurator = pit_configuration::getInstance();
00080 
00081         // starts here DIM server
00082         DimServer::start("pit_feDimServer");
00083 
00084         configurator.openCoordinateTableFile("tableFile.txt");
00085 
00086 
00087         //Create hierarchy of driver objects
00088         pit_driver *pit = new pit_driver();
00089         //configurator.dumpCoordinateTableToFile("defaultCoordinates.txt");
00090         //configurator.dumpRequiredLinksToFile("defaultRequiredLinks.txt");
00091 
00092 
00093 
00094         //*******************************************************************************
00095 
00096         const int cmdLineMax=256;
00097         char command[cmdLineMax];                       // command line buffer maximun number of chars 256
00098 
00099 
00100 
00101         // main execution loop
00102         while(1){
00103 
00104                 // if there is any command line executes also the command 
00105                 if ( pit_keyboard::kbhit() ){
00106 
00107                         cin.get(command, cmdLineMax, '\n');
00108                         if (strcmp(command, "quit")==0)break;
00109                         pit->executeCommand(command);   // parses and executes the command line
00110                         cin.ignore();                                   // this ignore will make it ignore the last '\n' that it is still in the buffer
00111                         // took some time but found it out :), now it works!!!
00112                 }
00113                 // checks if there are dim commands and executes 
00114                 pit->checkDimCommands();
00115                 // sleeps for 300 milliseconds
00116                 sleepMilli(300);
00117         }
00118 
00119         //*******************************************************************************
00120 
00121 
00122         delete pit;
00123 
00124                         // cleans all things conencted to the log4cpp
00125         log4cpp::Appender::closeAll();
00126         log4cpp::Category::shutdown();
00127         
00128 
00129         // there is some kind of bug in the fileAppender class so I cannot delete it or even close the file
00130         //fileApp.close();
00131         //delete fileApp;
00132         return(0);
00133 
00134 }/* end main */
00135 
00136 
00137 
00138 int compareArrays(UInt32 *a1, UInt32 *a2, int size){
00139         int out = 0;
00140         for (int index = 0 ; index < size ; index ++){
00141 
00142                 if (a1[index]!= a2[index]){
00143                         cout<< "\t error " << index << " : " << a1[index]<< "\t,"<< a2[index]<< endl;
00144                         out ++;
00145                 }
00146         }
00147 
00148         return out;
00149 }
00150 
00151 
00152 
00153 void testReadWord(pit_driver * pit, UInt19 startAdress, UInt19 numberOfWords){
00154 
00155         UInt32 inputData ;
00156         UInt32 outputData;
00157 
00158         int errors = 0;
00159         for (UInt32 address = 0 ; address <  numberOfWords ; address ++){
00160 
00161                 outputData = address;
00162                 pit->commFEE->PITWriteBlock( startAdress + address, 1, &outputData);
00163                 pit->commFEE->PITReadBlock(  startAdress + address, 1, &inputData);
00164 
00165                 if (inputData != outputData){
00166                         cout << "error address "<< hex << address <<" : " ;
00167                         cout << hex << outputData<<" , "<< inputData <<endl;
00168                         errors ++;
00169                 }
00170 
00171 
00172         }
00173         cout << "test read word: "<< dec << errors << " errors found"<<endl;
00174 
00175 }
00176 
00177 void testReadMemBlock(pit_driver * pit, UInt19 startAdress, UInt19 numberOfWords, UInt19 blockSize){
00178 
00179         UInt32 inputData[blockSize] ;
00180         UInt32 outputData[blockSize];
00181 
00182         // initializes the block to read, all blocks will write the same information
00183         // 0, 1, 2 .. size of the block
00184         for (unsigned int index = 0 ; index < blockSize ; index ++){
00185                 outputData[index]= index;
00186         }
00187 
00188         int blockErrors = 0;
00189         int wordErrors=0;
00190 
00191         for (UInt32 address = 0 ; address <  numberOfWords ; address +=blockSize){
00192 
00193                 pit->commFEE->PITWriteBlock( startAdress + address, blockSize, outputData);
00194                 pit->commFEE->PITReadBlock(  startAdress + address, blockSize, inputData);
00195                 //cout << "block " << hex << startAdress + address << " size "<<dec<<blockSize<< " :\n";
00196 
00197                 int error=compareArrays(outputData, inputData, blockSize);
00198                 if (error){
00199                         blockErrors ++;
00200                         wordErrors+=error;
00201                 }
00202 
00203         }
00204 
00205         cout << "test read block errors:  "<< dec << blockErrors << " errors found"<<endl;
00206         cout << "test read word errors:  "<< dec << wordErrors << " errors found"<<endl;
00207 }
00208 
00209 void simulate_values(pit_driver *pit){
00210         int board = 0;
00211         UInt28 baseAddress = OPTIN_BOARDS_BASE_ADDRESS + board*OPTIN_BOARDS_OFFSET;
00212 
00213         for (int link = 0 ; link < NUMBER_OPTICAL_LINKS ; link ++){
00214                 UInt28 addressSetting = baseAddress  + LINK_SETTING_OFFSET +link;
00215                 UInt28 addressStatus=  baseAddress + LINK_STATUS_OFFSET + link;
00216                 pit->commFEE->PITWriteWord(addressStatus, 0xffffffff);
00217                 pit->commFEE->PITWriteWord(addressSetting, 0x0);
00218         }
00219 
00220 }

Generated on Sat Mar 29 22:55:55 2008 for pixelTrigger by  doxygen 1.5.0