1 |
kusanagi |
1.1 |
/** @file |
2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v $ |
3 |
kusanagi |
2.0 |
* $Id: LogReader.cpp,v 1.5 2004/09/21 20:24:33 kusanagi Exp $ |
4 |
kusanagi |
1.2 |
* $Author: kusanagi $ |
5 |
kusanagi |
1.1 |
* |
6 |
|
|
* Implementation of the LogReader class. |
7 |
|
|
* ToBeDone: |
8 |
|
|
* Control the CRC for the entire data Packet not just for single records |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
#define UINT unsigned int |
12 |
|
|
#define BYTE unsigned char |
13 |
|
|
#include <string> |
14 |
kusanagi |
1.5 |
#include <log4cxx/logger.h> |
15 |
kusanagi |
1.1 |
extern "C" { |
16 |
|
|
#include <sys/time.h> |
17 |
|
|
#include "CRC.h" |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
#include <fstream> |
21 |
|
|
#include "stdio.h" |
22 |
|
|
#include "ReaderAlgorithms.h" |
23 |
|
|
|
24 |
|
|
#include "event/log/LogRecord.h" |
25 |
|
|
|
26 |
|
|
using namespace pamela; |
27 |
|
|
using namespace pamela::techmodel; |
28 |
|
|
|
29 |
kusanagi |
1.5 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.LogReader")); |
30 |
kusanagi |
1.1 |
|
31 |
|
|
/** |
32 |
|
|
* Constructor. |
33 |
|
|
*/ |
34 |
|
|
LogReader::LogReader(void): |
35 |
|
|
TechmodelAlgorithm(PacketType::Log, "TechmodelLogReader") { |
36 |
kusanagi |
1.5 |
logger->debug(_T("Constructor")); |
37 |
kusanagi |
1.1 |
Log = new LogEvent(); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Get a string with the version info of the algorithm. |
42 |
|
|
*/ |
43 |
|
|
std::string LogReader::GetVersionInfo(void) const { |
44 |
|
|
return |
45 |
kusanagi |
2.0 |
"$Header: /home/cvsmanager/yoda/techmodel/LogReader.cpp,v 1.5 2004/09/21 20:24:33 kusanagi Exp $\n"; |
46 |
kusanagi |
1.1 |
} |
47 |
|
|
|
48 |
|
|
/** |
49 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
50 |
|
|
* event reader routines for all packet types. |
51 |
|
|
*/ |
52 |
|
|
void LogReader::Init(PamelaRun *run) { |
53 |
kusanagi |
1.5 |
logger->debug(_T("Initialize")); |
54 |
kusanagi |
1.1 |
SetInputStream(run); |
55 |
|
|
run->WriteSubPacket(this, &Log, Log->Class()); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Unpack the Log event from an input file. |
60 |
|
|
*/ |
61 |
|
|
void LogReader::RunEvent(int EventNumber, long int length) { |
62 |
kusanagi |
1.2 |
char *subData; |
63 |
|
|
char eventCRC[2]; |
64 |
|
|
UINT16 subCRC; //CRC of the data |
65 |
|
|
UINT16 readCRC; //CRC read from the end of the subpacket |
66 |
|
|
long int dataLength; |
67 |
|
|
|
68 |
|
|
//the 2 bytes subtracted belong to the final event CRC bytes |
69 |
|
|
dataLength = length - (long int)2; |
70 |
|
|
|
71 |
|
|
subData = new char[dataLength]; |
72 |
|
|
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
73 |
|
|
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); |
74 |
|
|
|
75 |
|
|
//took the final CRC to compare it with the previous calculated CRC of the data |
76 |
|
|
InputFile->read(eventCRC, sizeof(eventCRC)); |
77 |
|
|
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
78 |
kusanagi |
1.1 |
|
79 |
kusanagi |
1.2 |
if (subCRC == readCRC){ |
80 |
|
|
LogRecord* rec; |
81 |
|
|
long int offset = 0; |
82 |
|
|
int i = 0; |
83 |
|
|
Log->Records->Clear(); |
84 |
|
|
TClonesArray &recs = *(Log->Records); |
85 |
|
|
while (offset < dataLength){ |
86 |
|
|
rec = new(recs[i++]) LogRecord(); //add a new Log |
87 |
kusanagi |
1.3 |
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); |
88 |
|
|
rec->MASKTYPE = (((UINT8)subData[offset+4]<<8)&0xFF); |
89 |
|
|
rec->FILE_ID = (((UINT8)subData[offset+5]<<8)&0xFF); |
90 |
|
|
rec->LINE_NO = ((((UINT16)subData[offset+6]<<8)&0xFF00) + (((UINT16)subData[offset+7])&0x00FF)); |
91 |
|
|
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); |
92 |
|
|
offset = offset + 12; |
93 |
kusanagi |
1.2 |
} |
94 |
|
|
} else { |
95 |
kusanagi |
1.5 |
std::stringstream oss; |
96 |
|
|
oss.flush(); |
97 |
|
|
oss << "Wrong CRC on Subpacket internal to Log Packet";// starting at position"; |
98 |
|
|
//<< start; |
99 |
|
|
logger->warn(oss.str().c_str()); |
100 |
kusanagi |
1.2 |
} |
101 |
kusanagi |
1.4 |
delete [] subData; |
102 |
kusanagi |
1.1 |
} |