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

Contents of /yoda/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sat Jul 17 20:03:38 2004 UTC (20 years, 4 months ago) by kusanagi
Branch: MAIN
Changes since 1.1: +27 -22 lines
*** empty log message ***

1 /** @file
2 * $Source: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v $
3 * $Id: TmtcReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 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
12
13
14 #include <string>
15 #include <log4cpp/Category.hh>
16 extern "C" {
17 #include <sys/time.h>
18 #include "CRC.h"
19 }
20
21 #include <fstream>
22 #include "stdio.h"
23 #include "ReaderAlgorithms.h"
24
25 #include "event/tmtc/TmtcRecord.h"
26
27 using namespace pamela;
28 using namespace pamela::techmodel;
29
30 static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TmtcReader");
31
32 /**
33 * Constructor.
34 */
35 TmtcReader::TmtcReader(void):
36 TechmodelAlgorithm(PacketType::Tmtc, "TechmodelTmtcReader") {
37 cat << log4cpp::Priority::DEBUG
38 << "Constructor "
39 << "\n " << log4cpp::CategoryStream::ENDLINE;
40 Tmtc = new TmtcEvent();
41 }
42
43 /**
44 * Get a string with the version info of the algorithm.
45 */
46 std::string TmtcReader::GetVersionInfo(void) const {
47 return
48 "$Header: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n";
49 }
50
51 /**
52 * Initialize the algorithm with a special run. This will initialize the
53 * event reader routines for all packet types.
54 */
55 void TmtcReader::Init(PamelaRun *run) {
56 SetInputStream(run);
57 run->WriteSubPacket(this, &Tmtc, Tmtc->Class());
58 }
59
60 /**
61 * Unpack the Tmtc event from an input file.
62 */
63 void TmtcReader::RunEvent(int EventNumber, long int length) {
64
65 /*
66 //Just to test crc
67 char tempbuff[length];
68 InputFile->read(tempbuff, sizeof(tempbuff));
69 UINT16 subCRC = 0;
70 for (int jj = 0; jj < length ; jj++){
71 subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(tempbuff+jj), 1);
72 }
73 //Just to test crc
74 */
75
76 int i, j;
77 char subData[TMTC_SUB_LENGTH];
78 char CRCbuff[TMTC_SUBCRC_LENGTH];
79 char eventCRC[TMTC_CRC_LENGTH];
80 int numRecords = (length-TMTC_CRC_LENGTH)/(TMTC_SUB_LENGTH + TMTC_SUBCRC_LENGTH); //subtract the last two bytes because are the final CRC
81 long int start;
82
83 TmtcRecord* rec;
84 Tmtc->Records->Clear();
85 TClonesArray &recs = *(Tmtc->Records);
86
87 UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
88 UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
89
90 /* char tempData[length-TMTC_CRC_LENGTH];
91 InputFile->read(tempData, sizeof(tempData));
92 partialCRC = CM_Compute_CRC16(0, (UINT8*)tempData, (length-TMTC_CRC_LENGTH));
93 */
94
95 for(i = 0; i < numRecords; i++) {
96 start = InputFile->tellg();
97 InputFile->read(subData, sizeof(subData));
98 InputFile->read(CRCbuff, sizeof(CRCbuff));
99
100 /* for (int jj = 0; jj < TMTC_SUB_LENGTH ; jj++){
101 partialCRC = CM_Compute_CRC16(0, (UINT8*)tempData, (length-TMTC_CRC_LENGTH));
102 }
103 */
104
105 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
106 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
107
108 //This == CRCBuff is not really parametric take care if have to change the static lengths
109 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0]){
110 rec = new(recs[i]) TmtcRecord(); //add a new TmtcRecord
111 rec->TM_RECORD_OBT = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + ((UINT32)subData[3])&0x000000FF;
112
113 for(j = 0; j < 16; j++) {
114 rec->TM_DEA_ANA[j] = (((UINT16)subData[4+j]<<8)&0xFF00) + (((UINT16)subData[5+j])&0x00FF);
115 rec->TM_DEA_ANA_P[j] = (float)(rec->TM_DEA_ANA[j]*0.02);
116
117 rec->TM_TH_ANA[j] = subData[36+j]; //36 is the size of TM_DEA_ANA + OBT
118 rec->TM_TH_ANA_P[j] = convert_th(rec->TM_TH_ANA[j]);
119 }
120
121 rec->TM_BIL_DIAG_ACQ = subData[53];
122 rec->TM_CC_DIAG_ACQ = (((UINT32)subData[54]<<24)&0xFF000000) + (((UINT32)subData[55]<<16)&0x00FF0000) + (((UINT32)subData[56]<<8)&0x0000FF00) + ((UINT32)subData[57])&0x000000FF;
123 //free(subData);
124 } else {
125 cat << log4cpp::Priority::ERROR
126 << "Wrong CRC on Subpacket int TMTC Packet starting at position " << start
127 << "\n " << log4cpp::CategoryStream::ENDLINE;
128 }
129 }
130 InputFile->read(eventCRC, sizeof(eventCRC));
131 readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
132 if(!(partialCRC == readCRC)) {
133 cat << log4cpp::Priority::ERROR
134 << "The test of calculated CRC with one wrote on file FAILED!!"
135 << "\n " << log4cpp::CategoryStream::ENDLINE;
136 }
137 }
138
139
140 float TmtcReader::convert_th(int TH) {
141 float a,q,deltax,deltay;
142 static int chiama_fun=0;
143 float gradi[22],grado=-1;
144 int adc[22]={4095, 4036,2976,2213,1662,1259,983,742,576,450,
145 354, 281,224,179,145, 117 ,95, 77, 64, 52,
146 43, 35};
147 int maxpos=-1,minpos=-1,i;
148
149 chiama_fun++;
150 for (i=0;i<22;i++)
151 {
152 gradi[i]=-35+(i*5);
153 }
154 if (TH==4095)
155 {
156 grado=-35.;
157 }
158 else
159 {
160
161 for (i=0;i<22;i++)
162 {
163 if (TH>=adc[i])
164 {
165 minpos=i;
166 maxpos=i-1;
167 break;
168 }
169 }
170 // grado=gradi[maxpos]-1./(adc[maxpos]-adc[minpos])*((float)TH-(float)adc[maxpos]) ;
171
172 deltax=adc[maxpos]-adc[minpos];
173 deltay=gradi[maxpos]-gradi[minpos];
174 a=deltay/deltax;
175 q=gradi[maxpos]-a*adc[maxpos];
176 grado=a*TH+q;
177 }
178 return (grado);
179 }

  ViewVC Help
Powered by ViewVC 1.1.23