00001
00002
00003
00004
00005
00006
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>
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
00029 int compareArrays(UInt32 *a1, UInt32 *a2, int size);
00030
00031
00032 void testReadMemBlock(pit_driver * pit, UInt19 startAdress = 0x1800000, UInt19 numberOfWords= 0x1000, UInt19 blockSize = 1024);
00033
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
00043
00044 log4cpp::Appender* fileApp = new log4cpp::FileAppender("FileAppender","./pit.log");
00045
00046 log4cpp::Appender* dimApp = new log4cpp::DimAppender("DimAppender", DIM_LOG_NAME);
00047
00048 log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
00049
00050
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
00057 log4cpp::Category& logger = log4cpp::Category::getInstance("pitLog");
00058
00059
00060
00061
00062
00063
00064 logger.setAdditivity(true);
00065
00066
00067
00068
00069 logger.addAppender(*fileApp);
00070 logger.addAppender(dimApp);
00072
00073
00074 logger.setPriority(log4cpp::Priority::DEBUG);
00075 dimApp->setThreshold(log4cpp::Priority::DEBUG);
00076
00077
00078
00079 pit_configuration& configurator = pit_configuration::getInstance();
00080
00081
00082 DimServer::start("pit_feDimServer");
00083
00084 configurator.openCoordinateTableFile("tableFile.txt");
00085
00086
00087
00088 pit_driver *pit = new pit_driver();
00089
00090
00091
00092
00093
00094
00095
00096 const int cmdLineMax=256;
00097 char command[cmdLineMax];
00098
00099
00100
00101
00102 while(1){
00103
00104
00105 if ( pit_keyboard::kbhit() ){
00106
00107 cin.get(command, cmdLineMax, '\n');
00108 if (strcmp(command, "quit")==0)break;
00109 pit->executeCommand(command);
00110 cin.ignore();
00111
00112 }
00113
00114 pit->checkDimCommands();
00115
00116 sleepMilli(300);
00117 }
00118
00119
00120
00121
00122 delete pit;
00123
00124
00125 log4cpp::Appender::closeAll();
00126 log4cpp::Category::shutdown();
00127
00128
00129
00130
00131
00132 return(0);
00133
00134 }
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
00183
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
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 }