--- yoda/techmodel/LogReader.cpp 2004/12/09 08:48:41 2.2 +++ yoda/techmodel/LogReader.cpp 2006/02/04 12:37:45 5.1 @@ -1,7 +1,7 @@ /** @file * $Source: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v $ - * $Id: LogReader.cpp,v 2.1 2004/12/03 22:08:00 kusanagi Exp $ - * $Author: kusanagi $ + * $Id: LogReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $ + * $Author: Maurizio Nagni $ * * Implementation of the LogReader class. * ToBeDone: @@ -41,7 +41,7 @@ */ std::string LogReader::GetVersionInfo(void) const { return - "$Header: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v 2.1 2004/12/03 22:08:00 kusanagi Exp $\n"; + "$Header: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $\n"; } /** @@ -58,22 +58,22 @@ * Unpack the Log event from an input file. */ void LogReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ - char *subData; - char eventCRC[2]; - UINT16 subCRC; //CRC of the data + + char subData[length]; + UINT16 subCRC; //calculated CRC of the data UINT16 readCRC; //CRC read from the end of the subpacket - long int dataLength; - - //the 2 bytes subtracted belong to the final event CRC bytes - dataLength = length - (long int)2; - - subData = new char[dataLength]; - InputFile->read(subData, sizeof(unsigned char)*dataLength); - subCRC = CM_Compute_CRC16(0, (BYTE*)&subData, dataLength); + long int dataLength = length - 2; //the block of data + + InputFile->read(subData, sizeof(subData)); + subCRC = CM_Compute_CRC16(0, (UINT8*)subData, dataLength); //took the final CRC to compare it with the previous calculated CRC of the data - InputFile->read(eventCRC, sizeof(eventCRC)); - readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); + readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); + + if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for Log Packet "); + /*if (subCRC != readCRC) { + logger->error("WRONG CRC FOR LOG PACKET. Processed anyway for CPU debugging"); + }*/ Log->COMPILATION_TIMESTAMP = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); long int offset = 4; @@ -91,5 +91,4 @@ rec->INFO1 = (((UINT32)subData[offset+8]<<24)&0xFF000000) + (((UINT32)subData[offset+9]<<16)&0x00FF0000) + (((UINT32)subData[offset+10]<<8)&0x0000FF00) + (((UINT32)subData[offset+11])&0x000000FF); offset = offset + 12; } - delete [] subData; }