/[PAMELA software]/yoda/techmodel/TmtcReader.cpp
ViewVC logotype

Contents of /yoda/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.1 - (show annotations) (download)
Tue Mar 21 21:49:07 2006 UTC (18 years, 8 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA6_2/01, YODA6_2/00, YODA6_1/00
Changes since 6.0: +8 -4 lines
Update: adding the index ' k ', the index of the stored records is indipendent from the index ' i ' relative to the records read.
In this way if a record have a wrong CRC, the ' i ' index increase but the ' k ' dont.

1 /** @file
2 * $Source: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v $
3 * $Id: TmtcReader.cpp,v 6.0 2006/02/07 17:11:10 kusanagi Exp $
4 * $Author: kusanagi $
5 *
6 * Implementation of the TmtcReader class.
7 * ToBeDone:
8 * Control the CRC for the entire data Packet not just for single records
9 */
10
11 #include <string>
12 #include <log4cxx/logger.h>
13 extern "C" {
14 #include <sys/time.h>
15 #include "CRC.h"
16 }
17
18 #include <fstream>
19 #include "stdio.h"
20 #include "ReaderAlgorithms.h"
21
22 #include "event/tmtc/TmtcRecord.h"
23
24 using namespace pamela;
25 using namespace pamela::techmodel;
26
27 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.TmtcReader"));
28
29 /**
30 * Constructor.
31 */
32 TmtcReader::TmtcReader(void):
33 TechmodelAlgorithm(PacketType::Tmtc, "TechmodelTmtcReader") {
34 logger->debug(_T("Constructor"));
35 Tmtc = new TmtcEvent();
36 }
37
38 /**
39 * Get a string with the version info of the algorithm.
40 */
41 std::string TmtcReader::GetVersionInfo(void) const {
42 return
43 "$Header: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v 6.0 2006/02/07 17:11:10 kusanagi Exp $\n";
44 }
45
46 /**
47 * Initialize the algorithm with a special run. This will initialize the
48 * event reader routines for all packet types.
49 */
50 void TmtcReader::Init(PamelaRun *run) {
51 SetInputStream(run);
52 run->WriteSubPacket(this, &Tmtc, Tmtc->Class());
53 }
54
55 /**
56 * Unpack the Tmtc event from an input file.
57 */
58 void TmtcReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){
59
60 int i, j, k;
61 /* The ' k ' indexs the number of recs.
62 * It is needed to be indipendent from ' i ' because in case of CRC error the single record is skipped and ' i ' increase by one, but correct records to be stored are still ' i '.
63 */
64 k = 0;
65 char subData[TMTC_SUB_LENGTH];
66 char CRCbuff[TMTC_SUBCRC_LENGTH];
67 char eventCRC[TMTC_CRC_LENGTH];
68 int numRecords = (length-TMTC_CRC_LENGTH)/(TMTC_SUB_LENGTH + TMTC_SUBCRC_LENGTH); //subtract the last two bytes because are the final CRC
69 long int start;
70
71 TmtcRecord* rec;
72 Tmtc->Records->Clear();
73 TClonesArray &recs = *(Tmtc->Records);
74
75 UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
76 UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
77 for(int i = 0; i < numRecords; i++) {
78 start = InputFile->tellg();
79 InputFile->read(subData, sizeof(subData));
80 InputFile->read(CRCbuff, sizeof(CRCbuff));
81
82 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
83 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
84
85 //This == CRCBuff is not really parametric take care if have to change the static lengths
86 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0]){
87 rec = new(recs[k++]) TmtcRecord(); //add a new TmtcRecord
88 rec->TM_RECORD_OBT = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF);
89 rec->TM_DIAG_AND_BILEVEL_ACQ = (((UINT16)subData[4]<<8)&0x0000FF00) + (((UINT16)subData[5])&0x000000FF);
90
91 for(int j = 0; j < 16; j++) {
92 rec->TM_TH_ANA[j] = ((((UINT16)subData[6 + 2*j]<<8)&0xFF00) + (((UINT16)subData[7 + 2*j])&0x00FF)); //20 is the size of TM_DEA_ANA(16) + OBT(4)
93 }
94
95 for(int j = 0; j < 6; j++) {
96 rec->TM_DEA_ANA[j] = subData[38+j];
97 }
98
99 } else {
100 stringstream oss;
101 oss.str("");
102 oss << "Wrong CRC on Subpacket int TMTC Packet starting at position"
103 << start;
104 logger->warn(oss.str().c_str());
105 }
106 }
107 InputFile->read(eventCRC, sizeof(eventCRC));
108 readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
109 if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for TMTC Packet ");
110 }
111
112 /*
113 float TmtcReader::convert_th(int TH) {
114 float a,q,deltax,deltay;
115 static int chiama_fun=0;
116 float gradi[22],grado=-1;
117 int adc[22]={4095, 4036,2976,2213,1662,1259,983,742,576,450,
118 354, 281,224,179,145, 117 ,95, 77, 64, 52,
119 43, 35};
120 int maxpos=-1,minpos=-1,i;
121
122 chiama_fun++;
123 for (i=0;i<22;i++)
124 {
125 gradi[i]=-35+(i*5);
126 }
127 if (TH==4095)
128 {
129 grado=-35.;
130 }
131 else
132 {
133
134 for (i=0;i<22;i++)
135 {
136 if (TH>=adc[i])
137 {
138 minpos=i;
139 maxpos=i-1;
140 break;
141 }
142 }
143 // grado=gradi[maxpos]-1./(adc[maxpos]-adc[minpos])*((float)TH-(float)adc[maxpos]) ;
144
145 deltax=adc[maxpos]-adc[minpos];
146 deltay=gradi[maxpos]-gradi[minpos];
147 a=deltay/deltax;
148 q=gradi[maxpos]-a*adc[maxpos];
149 grado=a*TH+q;
150 }
151 return (grado);
152 }
153 */

  ViewVC Help
Powered by ViewVC 1.1.23