/[PAMELA software]/chewbacca/PamOffLineSW/techmodel/TsbBReader.cpp
ViewVC logotype

Contents of /chewbacca/PamOffLineSW/techmodel/TsbBReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Tue Sep 23 07:20:27 2008 UTC (16 years, 2 months ago) by mocchiut
Branch point for: v0r00, MAIN
Initial revision

1 /** @file
2 * $Source: /repository/PamOffLineSW/techmodel/TsbBReader.cpp,v $
3 * $Id: TsbBReader.cpp,v 1.5 2008-03-04 18:09:30 messineo Exp $
4 * $Author: messineo $
5 *
6 * Implementation of the TsbBReader 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 TsbBReader::TsbBReader(void):
21 TechmodelAlgorithm(PacketType::TsbB, "TechmodelTsbB") {
22 TsbB = new TsbBEvent();
23 }
24
25 /**
26 * Get a string with the version info of the algorithm.
27 */
28 std::string TsbBReader::GetVersionInfo(void) const {
29 return "$Header: /repository/PamOffLineSW/techmodel/TsbBReader.cpp,v 1.5 2008-03-04 18:09:30 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 TsbBReader::Init(PamelaRun *run) {
37 run->WriteSubPacket(this, &TsbB, TsbB->Class());
38 }
39
40 /**
41 * Unpack the TsbB event
42 */
43 void TsbBReader::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 memset(subData, 0, length*sizeof(char));
51 subCRC = CM_Compute_CRC16(0, (UINT8*)subData, dataLength);
52 readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF);
53
54 // if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for TsbB Packet ");
55 if (subCRC != readCRC)
56 {
57 oss.str("");
58 oss<<"Wrong CRC for TsbB Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC;
59 msg=oss.str();
60 PamOffLineSW::mainLogUtil->logError(msg);
61 throw WrongCRCException(" Wrong CRC for TsbB Packet. THE PACKET IS DISCARDED ");
62 }
63
64 TsbBRecord* rec;
65 TsbB->Records->Clear();
66 TClonesArray &recs = *(TsbB->Records);
67
68 int i = 0;
69 long int offset = 0;
70 while (offset < dataLength){
71 rec = new(recs[i++]) TsbBRecord(); //add a new TsbB
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 < 7; j++){
75 rec->B_FIELD[j] = ((((UINT16)subData[offset+5+(2*j)]<<8)&0xFF00) + (((UINT16)subData[offset+6+(2*j)])&0x00FF));
76 }
77 offset = offset + 19;
78 }
79
80
81 /*
82 if (subCRC != readCRC)
83 {
84 oss.str("");
85 oss<<"Wrong CRC for TsbT Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC;
86 msg=oss.str();
87 PamOffLineSW::mainLogUtil->logWarning(msg);
88 throw WrongCRCException_PKTUsed(" Wrong CRC for TsbT Packet. ");
89 }
90 */
91
92
93 }

  ViewVC Help
Powered by ViewVC 1.1.23