Generic hardware access library
|
00001 #include "hal/VME64xAddressTableASCIIReader.hh" 00002 #include <fstream> 00003 #include <iomanip> 00004 #include <sstream> 00005 00006 HAL::VME64xAddressTableASCIIReader::VME64xAddressTableASCIIReader( std::string fileName ) 00007 throw (HAL::NoSuchFileException, 00008 HAL::IllegalValueException) 00009 : HAL::AddressTableReader() { 00010 00011 // some preparation to read the file: 00012 const int MaxLength=1024; 00013 char buffer[MaxLength]; 00014 std::ifstream FileStream( fileName.c_str() ); 00015 if ( ! FileStream ) { 00016 std::string text = "Cannot open file : " + fileName + " (HAL::VME64xAddressTableASCIIReader::VME64xAddressTableASCIIReader)"; 00017 throw (HAL::NoSuchFileException( text, __FILE__, __LINE__, __FUNCTION__ )); 00018 } 00019 // prepare the loop over all lines of the ascii file: 00020 std::string key, addressSpaceStr, description; 00021 AddressSpace addressSpace; 00022 uint32_t address, window_width, mask, isReadable, isWritable; 00023 char charbuf[MaxLength]; 00024 // loop over all lines of the file: 00025 while ( ! FileStream.eof() ) { 00026 FileStream.getline(buffer, MaxLength); 00027 if ( FileStream.eof() ) break; 00028 //skip all white space at beginning of buffer: 00029 int ic = 0; 00030 while ( buffer[ic] == ' ' || 00031 buffer[ic] == '\t' ) { 00032 ic++; 00033 } 00034 if (buffer[ic] == '*') continue; 00035 if (buffer[ic] == '\n') continue; // should never happen since \n is not extracted with getline 00036 if ((uint32_t)buffer[ic] == 0xd) continue; // in case of some windows edited ascii files.... 00037 if (buffer[ic] == 0x00) continue; 00038 00039 std::istringstream Line(buffer); 00040 Line >> key ; 00041 Line >> addressSpaceStr; 00042 Line >> std::dec >> window_width, 00043 Line >> std::hex >> address; 00044 Line >> std::hex >> mask; 00045 Line >> isReadable; 00046 Line >> isWritable; 00047 Line >> std::ws; 00048 Line.getline(charbuf, MaxLength); 00049 description = std::string(charbuf); 00050 if ( strcasecmp( addressSpaceStr.c_str(), "memory" ) == 0 ) { 00051 addressSpace = MEMORY; 00052 } else if ( strcasecmp( addressSpaceStr.c_str(), "configuration") == 0 ) { 00053 addressSpace = CONFIGURATION; 00054 } else { 00055 std::string text = "No such address-space in VME64x : " + addressSpaceStr + 00056 "\npossible spaces are 'memory' and 'configuration'." + 00057 "\n (HAL::VME64xAddressTableASCIIReader::VME64xAddressTableASCIIReader)"; 00058 throw (HAL::IllegalValueException( text, __FILE__, __LINE__, __FUNCTION__ )); 00059 } 00060 // it will be destroyed in the desructor of the AddresstableItem 00061 HAL::VME64xHardwareAddress* addressPointer = new HAL::VME64xHardwareAddress(address, addressSpace, 00062 window_width, window_width); 00063 HAL::AddressTableItem* itemPointer = 00064 new HAL::AddressTableItem(key, description, *addressPointer, 00065 mask, isWritable, isReadable); 00066 itemPointerList.push_back(itemPointer); 00067 } 00068 FileStream.close(); 00069 }