1 |
mocchiut |
1.1 |
/** @file |
2 |
|
|
* $Source: /repository/PamOffLineSW/techmodel/TsbTReader.cpp,v $ |
3 |
|
|
* $Id: TsbTReader.cpp,v 1.5 2008-03-04 18:09:31 messineo Exp $ |
4 |
|
|
* $Author: messineo $ |
5 |
|
|
* |
6 |
|
|
* Implementation of the TsbTReader class. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
extern "C" { |
10 |
|
|
#include "CRC.h" |
11 |
|
|
} |
12 |
|
|
#include "ReaderAlgorithms.h" |
13 |
|
|
|
14 |
|
|
using namespace pamela::techmodel; |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* Constructor. |
19 |
|
|
*/ |
20 |
|
|
TsbTReader::TsbTReader(void): |
21 |
|
|
TechmodelAlgorithm(PacketType::TsbT, "TechmodelTsbT") { |
22 |
|
|
TsbT = new TsbTEvent(); |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
/** |
26 |
|
|
* Get a string with the version info of the algorithm. |
27 |
|
|
*/ |
28 |
|
|
std::string TsbTReader::GetVersionInfo(void) const { |
29 |
|
|
return "$Header: /repository/PamOffLineSW/techmodel/TsbTReader.cpp,v 1.5 2008-03-04 18:09:31 messineo Exp $\n"; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
/** |
33 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
34 |
|
|
* event reader routines for all packet types. |
35 |
|
|
*/ |
36 |
|
|
void TsbTReader::Init(PamelaRun *run) { |
37 |
|
|
run->WriteSubPacket(this, &TsbT, TsbT->Class()); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Unpack the TsbT event |
42 |
|
|
*/ |
43 |
|
|
void TsbTReader::PKT_RunEvent(char* subData, long int length) throw (WrongCRCException){ |
44 |
|
|
std::stringstream oss; |
45 |
|
|
string msg; |
46 |
|
|
|
47 |
|
|
UINT16 subCRC; //calculated CRC of the data |
48 |
|
|
UINT16 readCRC; //CRC read from the end of the subpacket |
49 |
|
|
long int dataLength = length - 2; //the block of data |
50 |
|
|
subCRC = CM_Compute_CRC16(0, (UINT8*)subData, dataLength); |
51 |
|
|
readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); |
52 |
|
|
|
53 |
|
|
// if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for TsbT Packet "); |
54 |
|
|
if (subCRC != readCRC) |
55 |
|
|
{ |
56 |
|
|
oss.str(""); |
57 |
|
|
oss<<"Wrong CRC for TsbT Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC; |
58 |
|
|
msg=oss.str(); |
59 |
|
|
PamOffLineSW::mainLogUtil->logError(msg); |
60 |
|
|
throw WrongCRCException(" Wrong CRC for TsbT Packet. THE PACKET IS DISCARDED "); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
TsbTRecord* rec; |
65 |
|
|
TsbT->Records->Clear(); |
66 |
|
|
TClonesArray &recs = *(TsbT->Records); |
67 |
|
|
|
68 |
|
|
int i = 0; |
69 |
|
|
long int offset = 0; //dataLength/31; |
70 |
|
|
while (offset < dataLength){ |
71 |
|
|
rec = new(recs[i++]) TsbTRecord(); //add a new TsbT |
72 |
|
|
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); |
73 |
|
|
rec->STATUS_CODE = subData[offset+4]; |
74 |
|
|
for (int j=0; j < 13; j++){ |
75 |
|
|
rec->TEMPERATURES[j] = ((((UINT16)subData[offset+5+(2*j)]<<8)&0xFF00) + (((UINT16)subData[offset+6+(2*j)])&0x00FF)); |
76 |
|
|
} |
77 |
|
|
offset = offset + 31; |
78 |
|
|
} |
79 |
|
|
/* |
80 |
|
|
if (subCRC != readCRC) |
81 |
|
|
{ |
82 |
|
|
oss.str(""); |
83 |
|
|
oss<<"Wrong CRC for TsbT Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC; |
84 |
|
|
msg=oss.str(); |
85 |
|
|
PamOffLineSW::mainLogUtil->logWarning(msg); |
86 |
|
|
throw WrongCRCException_PKTUsed(" Wrong CRC for TsbT Packet. "); |
87 |
|
|
} |
88 |
|
|
*/ |
89 |
|
|
|
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|