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

Annotation of /yoda/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.1 - (hide annotations) (download)
Fri Dec 3 22:08:01 2004 UTC (20 years ago) by kusanagi
Branch: MAIN
Changes since 2.0: +5 -10 lines
Finally added a real group of Exception classes
Re-strucuted all the log systems (for better performances on unpacking)
Minor changes following the packets changes

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Source: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v $
3 kusanagi 2.1 * $Id: TmtcReader.cpp,v 2.0 2004/09/21 20:50:54 kusanagi Exp $
4 kusanagi 1.2 * $Author: kusanagi $
5 kusanagi 1.1 *
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 kusanagi 1.4 #include <log4cxx/logger.h>
13 kusanagi 1.1 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 kusanagi 1.4 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.TmtcReader"));
28 kusanagi 1.1
29     /**
30     * Constructor.
31     */
32     TmtcReader::TmtcReader(void):
33     TechmodelAlgorithm(PacketType::Tmtc, "TechmodelTmtcReader") {
34 kusanagi 1.4 logger->debug(_T("Constructor"));
35 kusanagi 1.1 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 kusanagi 2.1 "$Header: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v 2.0 2004/09/21 20:50:54 kusanagi Exp $\n";
44 kusanagi 1.1 }
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 kusanagi 2.1 void TmtcReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){
59 kusanagi 1.1
60     /*
61     //Just to test crc
62     char tempbuff[length];
63     InputFile->read(tempbuff, sizeof(tempbuff));
64     UINT16 subCRC = 0;
65     for (int jj = 0; jj < length ; jj++){
66     subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(tempbuff+jj), 1);
67     }
68     //Just to test crc
69     */
70    
71     int i, j;
72 kusanagi 1.2 char subData[TMTC_SUB_LENGTH];
73 kusanagi 1.1 char CRCbuff[TMTC_SUBCRC_LENGTH];
74     char eventCRC[TMTC_CRC_LENGTH];
75     int numRecords = (length-TMTC_CRC_LENGTH)/(TMTC_SUB_LENGTH + TMTC_SUBCRC_LENGTH); //subtract the last two bytes because are the final CRC
76     long int start;
77 kusanagi 1.2
78     TmtcRecord* rec;
79 kusanagi 1.1 Tmtc->Records->Clear();
80     TClonesArray &recs = *(Tmtc->Records);
81 kusanagi 1.2
82 kusanagi 1.1 UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
83     UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
84    
85 kusanagi 1.2 /* char tempData[length-TMTC_CRC_LENGTH];
86     InputFile->read(tempData, sizeof(tempData));
87     partialCRC = CM_Compute_CRC16(0, (UINT8*)tempData, (length-TMTC_CRC_LENGTH));
88     */
89 kusanagi 1.1
90     for(i = 0; i < numRecords; i++) {
91     start = InputFile->tellg();
92 kusanagi 1.2 InputFile->read(subData, sizeof(subData));
93 kusanagi 1.1 InputFile->read(CRCbuff, sizeof(CRCbuff));
94    
95 kusanagi 1.2 /* for (int jj = 0; jj < TMTC_SUB_LENGTH ; jj++){
96     partialCRC = CM_Compute_CRC16(0, (UINT8*)tempData, (length-TMTC_CRC_LENGTH));
97     }
98     */
99    
100     partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
101 kusanagi 1.1 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 kusanagi 1.2 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0]){
105     rec = new(recs[i]) TmtcRecord(); //add a new TmtcRecord
106     rec->TM_RECORD_OBT = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + ((UINT32)subData[3])&0x000000FF;
107 kusanagi 1.1
108     for(j = 0; j < 16; j++) {
109 kusanagi 1.2 rec->TM_DEA_ANA[j] = (((UINT16)subData[4+j]<<8)&0xFF00) + (((UINT16)subData[5+j])&0x00FF);
110 kusanagi 1.1 rec->TM_DEA_ANA_P[j] = (float)(rec->TM_DEA_ANA[j]*0.02);
111    
112 kusanagi 1.2 rec->TM_TH_ANA[j] = subData[36+j]; //36 is the size of TM_DEA_ANA + OBT
113 kusanagi 1.1 rec->TM_TH_ANA_P[j] = convert_th(rec->TM_TH_ANA[j]);
114     }
115    
116 kusanagi 1.2 rec->TM_BIL_DIAG_ACQ = subData[53];
117     rec->TM_CC_DIAG_ACQ = (((UINT32)subData[54]<<24)&0xFF000000) + (((UINT32)subData[55]<<16)&0x00FF0000) + (((UINT32)subData[56]<<8)&0x0000FF00) + ((UINT32)subData[57])&0x000000FF;
118 kusanagi 1.1 } else {
119 kusanagi 1.4 stringstream oss;
120 kusanagi 2.1 oss.str("");
121 kusanagi 1.4 oss << "Wrong CRC on Subpacket int TMTC Packet starting at position"
122     << start;
123     logger->warn(oss.str().c_str());
124 kusanagi 1.1 }
125     }
126     InputFile->read(eventCRC, sizeof(eventCRC));
127     readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
128 kusanagi 2.1 if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for TMTC Packet ");
129 kusanagi 1.1 }
130    
131    
132     float TmtcReader::convert_th(int TH) {
133     float a,q,deltax,deltay;
134     static int chiama_fun=0;
135     float gradi[22],grado=-1;
136     int adc[22]={4095, 4036,2976,2213,1662,1259,983,742,576,450,
137     354, 281,224,179,145, 117 ,95, 77, 64, 52,
138     43, 35};
139     int maxpos=-1,minpos=-1,i;
140    
141     chiama_fun++;
142     for (i=0;i<22;i++)
143     {
144     gradi[i]=-35+(i*5);
145     }
146     if (TH==4095)
147     {
148     grado=-35.;
149     }
150     else
151     {
152    
153     for (i=0;i<22;i++)
154     {
155     if (TH>=adc[i])
156     {
157     minpos=i;
158     maxpos=i-1;
159     break;
160     }
161     }
162     // grado=gradi[maxpos]-1./(adc[maxpos]-adc[minpos])*((float)TH-(float)adc[maxpos]) ;
163    
164     deltax=adc[maxpos]-adc[minpos];
165     deltay=gradi[maxpos]-gradi[minpos];
166     a=deltay/deltax;
167     q=gradi[maxpos]-a*adc[maxpos];
168     grado=a*TH+q;
169     }
170     return (grado);
171     }

  ViewVC Help
Powered by ViewVC 1.1.23