| 1 |
/** @file |
/** @file |
| 2 |
* $Source: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v $ |
* $Source: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v $ |
| 3 |
* $Id: ArrDumpReader.cpp,v 1.2 2004/07/17 20:03:38 kusanagi Exp $ |
* $Id: ArrDumpReader.cpp,v 2.2.2.2 2005/03/04 10:43:04 kusanagi Exp $ |
| 4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
| 5 |
* |
* |
| 6 |
* Implementation of the ArrDumpReader class. |
* Implementation of the ArrDumpReader class. |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#include <string> |
#include <string> |
| 10 |
#include <log4cpp/Category.hh> |
#include <log4cxx/logger.h> |
| 11 |
#include <fstream> |
#include <fstream> |
| 12 |
#include "stdio.h" |
#include "stdio.h" |
| 13 |
extern "C" { |
extern "C" { |
| 19 |
using namespace pamela; |
using namespace pamela; |
| 20 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
| 21 |
|
|
| 22 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.ArrDumpReader"); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.ArrDumpReader")); |
| 23 |
|
|
| 24 |
/** |
/** |
| 25 |
* Constructor. |
* Constructor. |
| 26 |
*/ |
*/ |
| 27 |
ArrDumpReader::ArrDumpReader(void): |
ArrDumpReader::ArrDumpReader(void): |
| 28 |
TechmodelAlgorithm(PacketType::ArrDump, "TechmodelArrDump") { |
TechmodelAlgorithm(PacketType::ArrDump, "TechmodelArrDump") { |
| 29 |
|
logger->debug(_T("Constructor")); |
| 30 |
ArrDump = new ArrDumpEvent(); |
ArrDump = new ArrDumpEvent(); |
| 31 |
} |
} |
| 32 |
|
|
| 34 |
* Get a string with the version info of the algorithm. |
* Get a string with the version info of the algorithm. |
| 35 |
*/ |
*/ |
| 36 |
std::string ArrDumpReader::GetVersionInfo(void) const { |
std::string ArrDumpReader::GetVersionInfo(void) const { |
| 37 |
return "$Header: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v 1.2 2004/07/17 20:03:38 kusanagi Exp $\n"; |
return "$Header: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v 2.2.2.2 2005/03/04 10:43:04 kusanagi Exp $\n"; |
| 38 |
} |
} |
| 39 |
|
|
| 40 |
/** |
/** |
| 42 |
* event reader routines for all packet types. |
* event reader routines for all packet types. |
| 43 |
*/ |
*/ |
| 44 |
void ArrDumpReader::Init(PamelaRun *run) { |
void ArrDumpReader::Init(PamelaRun *run) { |
| 45 |
|
logger->debug(_T("Initialize")); |
| 46 |
SetInputStream(run); |
SetInputStream(run); |
| 47 |
run->WriteSubPacket(this, &ArrDump, ArrDump->Class()); |
run->WriteSubPacket(this, &ArrDump, ArrDump->Class()); |
| 48 |
} |
} |
| 50 |
/** |
/** |
| 51 |
* Unpack the ArrDump event from an input file. |
* Unpack the ArrDump event from an input file. |
| 52 |
*/ |
*/ |
| 53 |
void ArrDumpReader::RunEvent(int EventNumber, long int length) { |
void ArrDumpReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
| 54 |
|
|
| 55 |
char *subData; |
char subData[length]; |
| 56 |
char eventCRC[2]; |
UINT16 subCRC; //CRC of the data |
| 57 |
UINT16 subCRC; //CRC of the data |
UINT16 readCRC; //CRC read from the end of the subpacket |
| 58 |
UINT16 readCRC; //CRC read from the end of the subpacket |
long int dataLength = length - 2; |
|
long int dataLength; |
|
| 59 |
|
|
| 60 |
//the 2 bytes subtracted belong to the final event CRC bytes |
InputFile->read(subData, sizeof(unsigned char)*length); |
| 61 |
dataLength = length - (long int)2; |
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); |
| 62 |
|
readCRC = (((UINT16)(subData[dataLength]<<8))&0xFF00) + (((UINT16)subData[dataLength - 1])&0x00FF); |
|
subData = new char[dataLength]; |
|
|
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
|
|
subCRC = CM_Compute_CRC16(0, (BYTE*)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); |
|
| 63 |
|
|
| 64 |
//finally check if the RecordCRC is correct and finally update the partialCRC |
//if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for ArrDump Packet "); |
| 65 |
if (subCRC == readCRC){ |
/*Pamela CPU group request to disable for a while CRC control to check values because |
| 66 |
ArrDumpRecord* rec; |
the data seems to be well formatted but perhaps there is just a mistake on CRC evaluation |
| 67 |
long int offset = 0; |
into the PAMELA CPU program |
| 68 |
int i = 0; |
*/ |
| 69 |
int size; |
if (subCRC != readCRC) { |
| 70 |
ArrDump->Records->Clear(); |
logger->error(" Wrong CRC for ArrDump Packet but I process it anyway because of CPU DEBUG"); |
| 71 |
TClonesArray &recs = *(ArrDump->Records); |
} |
| 72 |
while (offset < dataLength){ |
|
| 73 |
rec = new(recs[i++]) ArrDumpRecord(); //add a new TmtcRecord |
ArrDumpRecord* rec; |
| 74 |
rec->Arr_ID = ((UINT8)subData[offset])&0xFF; |
ArrDump->PARAMETER_STAMP = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); |
| 75 |
rec->Arr_len = (((UINT16)subData[offset+1]<<8)&0xFF00) + ((UINT16)subData[offset+2])&0x00FF; |
long int offset = 4; |
| 76 |
rec->Data = new UINT32[rec->Arr_len]; |
int i = 0; |
| 77 |
size = sizeof(UINT32)*(rec->Arr_len); |
int size; |
| 78 |
memcpy(rec->Data, (UINT32*)(subData+offset+3), size); |
ArrDump->Records->Clear(); |
| 79 |
offset = offset + size + 3; |
TClonesArray &recs = *(ArrDump->Records); |
| 80 |
} |
while (offset < dataLength){ |
| 81 |
free(subData); |
rec = new(recs[i++]) ArrDumpRecord(); //add a new TmtcRecord |
| 82 |
} else { |
rec->Arr_ID = ((UINT8)subData[offset])&0xFF; |
| 83 |
cat << log4cpp::Priority::ERROR |
rec->Arr_len = (((UINT16)subData[offset+1]<<8)&0xFF00) + ((UINT16)subData[offset+2])&0x00FF; |
| 84 |
<< "Wrong CRC on Subpacket in ArrDump Packet " |
size = sizeof(UINT32)*(rec->Arr_len); |
| 85 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
rec->Data = new TArrayI((int)rec->Arr_len, (int*)(subData+offset+3)); |
| 86 |
|
offset = offset + size + 3; |
| 87 |
} |
} |
| 88 |
|
delete [] subData; |
| 89 |
} |
} |