--- yoda/techmodel/LogReader.cpp 2004/07/06 12:20:23 1.1 +++ yoda/techmodel/LogReader.cpp 2005/08/29 09:29:03 4.5 @@ -1,7 +1,7 @@ /** @file - * $Source: /home/cvspamela/yoda/techmodel/LogReader.cpp,v $ - * $Id: LogReader.cpp,v 1.2 2004/04/28 09:01:27 nagni Exp $ - * $Author: nagni $ + * $Source: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v $ + * $Id: LogReader.cpp,v 4.4 2005/05/28 10:44:11 kusanagi Exp $ + * $Author: kusanagi $ * * Implementation of the LogReader class. * ToBeDone: @@ -11,7 +11,7 @@ #define UINT unsigned int #define BYTE unsigned char #include -#include +#include extern "C" { #include #include "CRC.h" @@ -20,22 +20,19 @@ #include #include "stdio.h" #include "ReaderAlgorithms.h" - #include "event/log/LogRecord.h" using namespace pamela; using namespace pamela::techmodel; -static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.LogReader"); +static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.LogReader")); /** * Constructor. */ LogReader::LogReader(void): TechmodelAlgorithm(PacketType::Log, "TechmodelLogReader") { - cat << log4cpp::Priority::DEBUG - << "Constructor " - << "\n " << log4cpp::CategoryStream::ENDLINE; + logger->debug(_T("Constructor")); Log = new LogEvent(); } @@ -44,7 +41,7 @@ */ std::string LogReader::GetVersionInfo(void) const { return - "$Header: /home/cvspamela/yoda/techmodel/LogReader.cpp,v 1.2 2004/04/28 09:01:27 nagni Exp $\n"; + "$Header: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v 4.4 2005/05/28 10:44:11 kusanagi Exp $\n"; } /** @@ -52,6 +49,7 @@ * event reader routines for all packet types. */ void LogReader::Init(PamelaRun *run) { + logger->debug(_T("Initialize")); SetInputStream(run); run->WriteSubPacket(this, &Log, Log->Class()); } @@ -59,27 +57,38 @@ /** * Unpack the Log event from an input file. */ -void LogReader::RunEvent(int EventNumber, long int length) { - int i, j; - char buff[9]; - int numRecords = length/9; - TClonesArray &recs = *(Log->Records); - LogRecord* rec; +void LogReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ + + char subData[length]; + UINT16 subCRC; //calculated CRC of the data + UINT16 readCRC; //CRC read from the end of the subpacket + long int dataLength = length - 2; //the block of data - for(i = 0; i < numRecords; i++) { - InputFile->read(buff, sizeof(buff)); - rec = new(recs[i]) LogRecord(); //aggiungo un nuovo TmtcRecord all'evento - rec->LG_RECORD_OBT = (((UINT32)buff[0]<<24)&0xFF000000) + (((UINT32)buff[1]<<16)&0x00FF0000) + (((UINT32)buff[2]<<8)&0x0000FF00) + (((UINT32)buff[3])&0x000000FF); - rec->LG_LINE = (((UINT16)buff[4]<<8)&0xFF00) + (((UINT16)buff[5])&0x00FF); - rec->LG_INFO = (((UINT16)buff[6]<<8)&0xFF00) + (((BYTE)buff[7])&0x00FF); - rec->LG_FILE_ID = ((UINT16)buff[8]); - } - - /*for(i = 0; i < numRecords; i++) { -LogRecord *record = static_cast((recs).At(i)); -cat << log4cpp::Priority::INFO - << "\n Record OBT: " - << record->LG_RECORD_OBT(); + 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 + 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; + int i = 0; + LogRecord* rec; + Log->Records->Clear(); + TClonesArray &recs = *(Log->Records); + + while (offset < dataLength){ + rec = new(recs[i++]) LogRecord(); //add a new Log + rec->RECORD_OBT = (((UINT32)subData[offset]<<24)&0xFF000000) + (((UINT32)subData[offset+1]<<16)&0x00FF0000) + (((UINT32)subData[offset+2]<<8)&0x0000FF00) + (((UINT32)subData[offset+3])&0x000000FF); + rec->MASKTYPE = (((UINT8)subData[offset+4])&0xFF); + rec->FILE_ID = (((UINT8)subData[offset+5])&0xFF); + rec->LINE_NO = ((((UINT16)subData[offset+6]<<8)&0xFF00) + (((UINT16)subData[offset+7])&0x00FF)); + 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; + } +}