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

Annotation of /yoda/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Jul 6 12:20:23 2004 UTC (20 years, 4 months ago) by kusanagi
Branch: MAIN
Initial revision

1 kusanagi 1.1 /** @file
2     * $Source: /home/cvspamela/yoda/techmodel/TmtcReader.cpp,v $
3     * $Id: TmtcReader.cpp,v 1.8 2004/04/28 09:01:27 nagni Exp $
4     * $Author: nagni $
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/cvspamela/yoda/techmodel/TmtcReader.cpp,v 1.8 2004/04/28 09:01:27 nagni 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 buff[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     Tmtc->Records->Clear();
83     TClonesArray &recs = *(Tmtc->Records);
84     TmtcRecord* rec;
85     UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
86     UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
87     int oldSize = recs.GetSize();
88     recs.ExpandCreate(oldSize+numRecords-1);
89    
90    
91     for(i = 0; i < numRecords; i++) {
92     start = InputFile->tellg();
93     InputFile->read(buff, sizeof(buff));
94     InputFile->read(CRCbuff, sizeof(CRCbuff));
95    
96     /*for (int jj = 0; jj < TMTC_SUB_LENGTH ; jj++){
97     partialCRC = CM_Compute_CRC8_8((char)partialCRC, (unsigned char*)buff[jj], 1);
98     }*/
99    
100     partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&buff, TMTC_SUB_LENGTH);
101     partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
102    
103     //This == CRCBuff is not really parametric take care if have to change the static lengths
104     if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&buff, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0]){
105     rec = new TmtcRecord(); //add a new TmtcRecord
106     rec->TM_RECORD_OBT = (((UINT32)buff[0]<<24)&0xFF000000) + (((UINT32)buff[1]<<16)&0x00FF0000) + (((UINT32)buff[2]<<8)&0x0000FF00) + ((UINT32)buff[3])&0x000000FF;
107    
108     for(j = 0; j < 16; j++) {
109     rec->TM_DEA_ANA[j] = (((UINT16)buff[4+j]<<8)&0xFF00) + (((UINT16)buff[5+j])&0x00FF);
110     rec->TM_DEA_ANA_P[j] = (float)(rec->TM_DEA_ANA[j]*0.02);
111    
112     rec->TM_TH_ANA[j] = buff[36+j]; //36 is the size of TM_DEA_ANA + OBT
113     rec->TM_TH_ANA_P[j] = convert_th(rec->TM_TH_ANA[j]);
114     }
115    
116     rec->TM_BIL_DIAG_ACQ = buff[53];
117     rec->TM_CC_DIAG_ACQ = (((UINT32)buff[54]<<24)&0xFF000000) + (((UINT32)buff[55]<<16)&0x00FF0000) + (((UINT32)buff[56]<<8)&0x0000FF00) + ((UINT32)buff[57])&0x000000FF;
118     recs.AddAt(&(*rec), oldSize+i);
119     } else {
120     cat << log4cpp::Priority::ERROR
121     << "Wrong CRC on Subpacket int TMTC Packet starting at position " << start
122     << "\n " << log4cpp::CategoryStream::ENDLINE;
123     }
124     }
125     InputFile->read(eventCRC, sizeof(eventCRC));
126     readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
127     if(!(partialCRC == readCRC)) {
128     cat << log4cpp::Priority::ERROR
129     << "The test of calculated CRC with one wrote on file FAILED!!"
130     << "\n " << log4cpp::CategoryStream::ENDLINE;
131     }
132     }
133    
134    
135     float TmtcReader::convert_th(int TH) {
136     float a,q,deltax,deltay;
137     static int chiama_fun=0;
138     float gradi[22],grado=-1;
139     int adc[22]={4095, 4036,2976,2213,1662,1259,983,742,576,450,
140     354, 281,224,179,145, 117 ,95, 77, 64, 52,
141     43, 35};
142     int maxpos=-1,minpos=-1,i;
143    
144     chiama_fun++;
145     for (i=0;i<22;i++)
146     {
147     gradi[i]=-35+(i*5);
148     }
149     if (TH==4095)
150     {
151     grado=-35.;
152     }
153     else
154     {
155    
156     for (i=0;i<22;i++)
157     {
158     if (TH>=adc[i])
159     {
160     minpos=i;
161     maxpos=i-1;
162     break;
163     }
164     }
165     // grado=gradi[maxpos]-1./(adc[maxpos]-adc[minpos])*((float)TH-(float)adc[maxpos]) ;
166    
167     deltax=adc[maxpos]-adc[minpos];
168     deltay=gradi[maxpos]-gradi[minpos];
169     a=deltay/deltax;
170     q=gradi[maxpos]-a*adc[maxpos];
171     grado=a*TH+q;
172     }
173     return (grado);
174     }

  ViewVC Help
Powered by ViewVC 1.1.23