1 |
/** @file |
/** @file |
2 |
* $Source: /home/cvsmanager/yoda/techmodel/McmdReader.cpp,v $ |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/McmdReader.cpp,v $ |
3 |
* $Id: McmdReader.cpp,v 1.3 2004/08/24 16:01:57 kusanagi Exp $ |
* $Id: McmdReader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
5 |
* |
* |
6 |
* Implementation of the McmdReader class. |
* Implementation of the McmdReader class. |
7 |
*/ |
*/ |
8 |
|
|
|
#define BYTE unsigned char |
|
|
#include <string> |
|
|
#include <log4cpp/Category.hh> |
|
9 |
extern "C" { |
extern "C" { |
10 |
#include <sys/time.h> |
#include "CRC.h" |
|
#include "CRC.h" |
|
11 |
} |
} |
|
|
|
|
#include <fstream> |
|
|
#include "stdio.h" |
|
12 |
#include "ReaderAlgorithms.h" |
#include "ReaderAlgorithms.h" |
|
|
|
|
#include "event/mcmd/McmdRecord.h" |
|
|
|
|
|
using namespace pamela; |
|
13 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
14 |
|
|
15 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.McmdReader"); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.McmdReader")); |
16 |
|
static std::stringstream oss; |
17 |
/** |
/** |
18 |
* Constructor. |
* Constructor. |
19 |
*/ |
*/ |
20 |
McmdReader::McmdReader(void): |
McmdReader::McmdReader(void): |
21 |
TechmodelAlgorithm(PacketType::Mcmd, "Mcmd") { |
TechmodelAlgorithm(PacketType::Mcmd, "Mcmd") { |
22 |
cat << log4cpp::Priority::DEBUG |
logger->debug(_T("Constructor")); |
|
<< "Constructor " |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
23 |
Mcmd = new McmdEvent(); |
Mcmd = new McmdEvent(); |
24 |
} |
} |
25 |
|
|
28 |
*/ |
*/ |
29 |
std::string McmdReader::GetVersionInfo(void) const { |
std::string McmdReader::GetVersionInfo(void) const { |
30 |
return |
return |
31 |
"$Header: /home/cvsmanager/yoda/techmodel/McmdReader.cpp,v 1.3 2004/08/24 16:01:57 kusanagi Exp $\n"; |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/McmdReader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $\n"; |
32 |
} |
} |
33 |
|
|
34 |
/** |
/** |
36 |
* event reader routines for all packet types. |
* event reader routines for all packet types. |
37 |
*/ |
*/ |
38 |
void McmdReader::Init(PamelaRun *run) { |
void McmdReader::Init(PamelaRun *run) { |
39 |
|
logger->debug(_T("Initialize")); |
40 |
SetInputStream(run); |
SetInputStream(run); |
41 |
run->WriteSubPacket(this, &Mcmd, Mcmd->Class()); |
run->WriteSubPacket(this, &Mcmd, Mcmd->Class()); |
42 |
} |
} |
64 |
* @Event Number |
* @Event Number |
65 |
* @length is the size in bytes of the event (or packet) |
* @length is the size in bytes of the event (or packet) |
66 |
*/ |
*/ |
67 |
void McmdReader::RunEvent(int EventNumber, long int length) { |
void McmdReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
68 |
|
|
69 |
int i = 0; |
int i = 0; |
70 |
char OBT[4]; |
char OBT[4]; |
119 |
// else set subData to 0 |
// else set subData to 0 |
120 |
//if(dataLength > 0){ |
//if(dataLength > 0){ |
121 |
subData = new char[dataLength]; |
subData = new char[dataLength]; |
122 |
|
memset(subData, 0, dataLength*sizeof(char)); |
123 |
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
124 |
for (int jj = 0; jj < dataLength ; jj++){ |
for (int jj = 0; jj < dataLength ; jj++){ |
125 |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(subData+jj), 1); |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(subData+jj), 1); |
156 |
rec->endID = (BYTE)subTrailer[1]; |
rec->endID = (BYTE)subTrailer[1]; |
157 |
|
|
158 |
rec->McmdData = new TArrayC(dataLength, subData); |
rec->McmdData = new TArrayC(dataLength, subData); |
|
//memcpy(rec->McmdData, (BYTE*)subData, sizeof(rec->McmdData)); |
|
|
//rec->setMcmdData((BYTE*)&subData); |
|
159 |
delete [] subData; |
delete [] subData; |
160 |
} else { |
} else { |
161 |
cat << log4cpp::Priority::ERROR |
oss.str(""); |
162 |
<< "Wrong CRC on Subpacket int MCMD Packet starting at position " << start |
oss << "Wrong CRC on Subpacket internal to TMTC Packet starting at position" |
163 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< start; |
164 |
|
logger->warn(oss.str().c_str()); |
165 |
} |
} |
166 |
} |
} |
167 |
//in the end compare the calculated partial CRC with the MCMD packet CRC |
//in the end compare the calculated partial CRC with the MCMD packet CRC |
168 |
InputFile->read(eventCRC, sizeof(eventCRC)); |
InputFile->read(eventCRC, sizeof(eventCRC)); |
169 |
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
170 |
|
|
171 |
if(!(partialCRC == readCRC)) { |
if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for MCMD Packet "); |
172 |
cat << log4cpp::Priority::ERROR |
/*if(!(partialCRC == readCRC)) { |
173 |
<< "Wrong CRC for CalibS4 Packet" |
throw WrongCRCException(); |
174 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
}*/ |
|
} |
|
175 |
} |
} |
176 |
|
|
177 |
|
|