/** @file * $Source: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v $ * $Id: ArrDumpReader.cpp,v 2.2 2005/01/03 14:20:09 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the ArrDumpReader class. */ #include #include #include #include "stdio.h" extern "C" { #include "CRC.h" } #include "ReaderAlgorithms.h" using namespace pamela; using namespace pamela::techmodel; static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.ArrDumpReader")); /** * Constructor. */ ArrDumpReader::ArrDumpReader(void): TechmodelAlgorithm(PacketType::ArrDump, "TechmodelArrDump") { logger->debug(_T("Constructor")); ArrDump = new ArrDumpEvent(); } /** * Get a string with the version info of the algorithm. */ std::string ArrDumpReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v 2.2 2005/01/03 14:20:09 kusanagi Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void ArrDumpReader::Init(PamelaRun *run) { logger->debug(_T("Initialize")); SetInputStream(run); run->WriteSubPacket(this, &ArrDump, ArrDump->Class()); } /** * Unpack the ArrDump event from an input file. */ void ArrDumpReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ char subData[length]; UINT16 subCRC; //CRC of the data UINT16 readCRC; //CRC read from the end of the subpacket long int dataLength = length - 2; InputFile->read(subData, sizeof(unsigned char)*length); subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for ArrDump Packet "); ArrDumpRecord* rec; long int offset = 0; int i = 0; int size; ArrDump->Records->Clear(); TClonesArray &recs = *(ArrDump->Records); while (offset < dataLength){ rec = new(recs[i++]) ArrDumpRecord(); //add a new TmtcRecord rec->Arr_ID = ((UINT8)subData[offset])&0xFF; rec->Arr_len = (((UINT16)subData[offset+1]<<8)&0xFF00) + ((UINT16)subData[offset+2])&0x00FF; size = sizeof(UINT32)*(rec->Arr_len); rec->Data = new TArrayI((int)rec->Arr_len, (int*)(subData+offset+3)); offset = offset + size + 3; } //delete [] subData; }