/[PAMELA software]/chewbacca/PamOffLineSW/PacketSemanticAnalyzer.cpp
ViewVC logotype

Annotation of /chewbacca/PamOffLineSW/PacketSemanticAnalyzer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Aug 4 13:58:09 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, v9r00, v9r01, HEAD
Changes since 1.5: +2 -2 lines
Changed to work with GCC 4.x (gfortran) + ROOT >= 5.24

1 mocchiut 1.1 //============================================================================
2 mocchiut 1.6 // $Id: PacketSemanticAnalyzer.cpp,v 1.5 2009/07/30 08:16:20 mocchiut Exp $
3 mocchiut 1.1 // Description :
4     //============================================================================
5     #include "PacketSemanticAnalyzer.h"
6    
7     namespace PamOffLineSW
8     {
9    
10     extern unsigned long int step_pkt_number;
11     extern unsigned long int step_pkt_obt;
12 mocchiut 1.2 extern unsigned long int max_pkt_number;
13     extern unsigned long int max_pkt_obt;
14 mocchiut 1.1 extern bool is_new_route;
15     extern bool do_cont_check;
16    
17     extern LogUtil* mainLogUtil;
18     extern long int iNumCadres; //cadre's number
19     extern unsigned long long int iByte_tot;// how many bytes I have read till now
20    
21     PacketSemanticAnalyzer PacketSemanticAnalyzer::instance;
22    
23     PacketSemanticAnalyzer::PacketSemanticAnalyzer()
24     {
25     //set current values and last values to zero
26     setCurrentValues(0,0);
27     setLastValue();
28     pkt_type=0;
29     pktType=NULL;
30     }
31    
32     PacketSemanticAnalyzer::~PacketSemanticAnalyzer()
33     {
34     }
35    
36     //unused, the values are set in PamOffLineSW_Main.cpp
37     void PacketSemanticAnalyzer::setStepValue(unsigned long int dpn, unsigned long int dpo )
38     {
39     step_pkt_number=dpn;
40     step_pkt_obt=dpo;
41     }
42    
43     void PacketSemanticAnalyzer::setLastValue()
44     {
45     last_pkt_number=pkt_number;
46     last_pkt_obt=pkt_obt;
47     }
48    
49     void PacketSemanticAnalyzer::setCurrentValues(unsigned long int ex_pkt_number, unsigned long int ex_pkt_obt)
50     {
51     pkt_number=ex_pkt_number;
52     pkt_obt=ex_pkt_obt;
53     }
54    
55    
56     void PacketSemanticAnalyzer::extractValuesfromPKT(char * hpamPkt)
57     {
58    
59     /**/
60     //all the check can also be done using pamela::techmodel::EventReader* reader;
61     //PacketUser::getInstance().reader->PKT_UnpackPscuHeader(hpamPkt);
62     //std::cout<<PacketUser::getInstance().reader->Header->GetPscuHeader()->Print()<<std::endl;
63 mocchiut 1.6 //reader->Header->GetCounter()->PrintCounters();
64 mocchiut 1.1 //const PacketType* type = reader->Header->GetPscuHeader()->GetPacketType();
65     //int len= reader->Header->GetPscuHeader()->GetPacketLenght();
66     //if(reader){delete reader; reader = NULL;}
67    
68     /**/
69     unsigned long int ex_pkt_number=(unsigned long int)(unsigned char)(hpamPkt[7])+
70     256*(unsigned long int)(unsigned char)(hpamPkt[6])+
71     256*256*(unsigned long int)(unsigned char)(hpamPkt[5]);
72     //unsigned int Counter = (((UINT32)buff[5]<<16)&0x00FF0000) + (((UINT32)buff[6]<<8)&0x0000FF00) + (((UINT32)buff[7])&0x000000FF);
73    
74     unsigned long int ex_pkt_obt=(unsigned long int)(unsigned char)(hpamPkt[11])+
75     256*(unsigned long int)(unsigned char)(hpamPkt[10])+
76     256*256*(unsigned long int)(unsigned char)(hpamPkt[9])+
77     256*256*256*(unsigned long int)(unsigned char)(hpamPkt[8]);
78    
79     //unsigned int OrbitalTime = (((UINT32)buff[8]<<24)&0xFF000000) + (((UINT32)buff[9]<<16)&0x00FF0000) + (((UINT32)buff[10]<<8)&0x0000FF00) + (((UINT32)buff[11])&0x000000FF);
80    
81     setCurrentValues(ex_pkt_number,ex_pkt_obt);
82    
83     //if hpamPkt[3] != hpamPkt[4] the pkt is not good, it was discarded in R3
84     pkt_type=(unsigned char)(hpamPkt[3]);
85     pktType = GetPacketType(pkt_type);
86     }
87    
88     // PacketSemanticAnalyzer:
89     // return false if there is a DISCONTINUITY
90     // packet counter has priority on obt.
91     bool PacketSemanticAnalyzer::analysePKT()
92     {
93    
94     if(!pktType){
95     stringstream oss;
96     oss.str()="";
97     oss<<"PacketType "<<(int)pkt_type <<" not recognised. Packed skipped. The end of this packet is at byte: "<<iByte_tot<<" in cadre "<<iNumCadres;
98     string msg = oss.str();
99     mainLogUtil->logError(msg);
100     // the packet will not be used in the next module.
101     //I don't call setLastValue(), I can't trust on this packet
102     return true;
103     }
104    
105     //IF I FOUND A NEW DOWNLOAD IN THE INPUT FILE, discontinuity
106     if(is_new_route){
107     setLastValue();
108     return false;
109     }
110    
111     if(!do_cont_check){
112     setLastValue();//maybe I don't need it
113     return true;
114     }
115    
116     long int delta_pc;
117     long int delta_pt;
118     bool cons=true;
119    
120 mocchiut 1.2 //TODO check here ...
121 mocchiut 1.1 //USE ONLY PKT_NUMBER and not the OBT ...
122     //correct value is step_pkt_number = 5 and step_pkt_obt =0
123     delta_pc = pkt_number-last_pkt_number;
124    
125     if((step_pkt_number==0)||
126 mocchiut 1.5 ((delta_pc>0)&&(delta_pc<=(long long int)step_pkt_number)) ||
127     ((delta_pc<0)&&(-delta_pc>=(long long int)(max_pkt_number-step_pkt_number)))//delta_pc < 0 et pkt_number small and last_pkt_number big
128 mocchiut 1.1 )
129     {
130     //cons=true;
131     delta_pt=pkt_obt-last_pkt_obt;
132    
133     //delta_pt=0 is OK
134     if((step_pkt_obt==0)||
135 mocchiut 1.5 ((delta_pt>=0)&&(delta_pt<=(long long int)step_pkt_obt)) ||
136     ((delta_pt<0)&&(-delta_pt>=(long long int)(max_pkt_obt-step_pkt_obt)))//delta_pt < 0 et pkt_obt small and last_pkt_obt big
137 mocchiut 1.1 )
138     {
139     cons=true;
140     }
141     else
142     {
143     cons=false;
144     }
145     }
146     else
147     {
148     cons=false;
149     }
150    
151     setLastValue();
152     return cons;
153     }
154    
155     //here headerPkt is the header (16 bytes) pamPKT is the rest of the packet of lenght = length
156     void PacketSemanticAnalyzer::managePKT(char*& headerPkt, char*& pamPkt, long int length, bool isPKTGood)
157     {
158     bool isCons = true;
159     //here we retrieve the informations mostly from the header
160     extractValuesfromPKT(headerPkt);
161     //here I use the information retrieved to decide if the current packet is continuos
162     isCons=analysePKT();
163    
164     //The quality of the packet isPKTGood and the information about "CONTINUITY"
165     //are sent to the "user module" where I will save/use it.
166     PacketUser::getInstance().usePKT(headerPkt, pamPkt, length, isCons, isPKTGood,
167     pktType, pkt_number, pkt_obt);
168    
169     //just to be sure ...
170     if(pamPkt){ delete[] pamPkt; pamPkt = NULL;}
171     if(headerPkt){ delete[] headerPkt; headerPkt = NULL;}
172     }
173    
174     /**
175     * Get the packet type, this function is analogous to the one in ../event/PacketType.h
176     */
177     const PacketType* PacketSemanticAnalyzer::GetPacketType(unsigned char pkt_type) {
178     switch (pkt_type) {
179     case 0x07: return PacketType::PhysEndRun;//warning nel computo CRC
180     case 0x08: return PacketType::CalibCalPulse1;
181     case 0x09: return PacketType::CalibCalPulse2;
182     case 0x10: return PacketType::Physics;
183     case 0x11: return PacketType::CalibTrkBoth;
184     case 0x12: return PacketType::CalibTrk1;
185     case 0x13: return PacketType::CalibTrk2;
186     case 0x16: return PacketType::CalibTof;
187     case 0x17: return PacketType::CalibS4;
188     case 0x18: return PacketType::CalibCalPed;
189     case 0x19: return PacketType::Calib1_Ac1;
190     case 0x1A: return PacketType::Calib2_Ac1;
191     case 0x1B: return PacketType::Calib1_Ac2;
192     case 0x1C: return PacketType::Calib2_Ac2;
193     case 0x1D: return PacketType::CalibCal;
194     case 0x20: return PacketType::RunHeader;
195     case 0x21: return PacketType::RunTrailer;
196     case 0x22: return PacketType::CalibHeader;
197     case 0x23: return PacketType::CalibTrailer;
198     case 0x24: return PacketType::InitHeader;
199     case 0x25: return PacketType::InitTrailer;
200     case 0x30: return PacketType::EventTrk;
201     case 0x50: return PacketType::Log;
202     case 0x51: return PacketType::VarDump;
203     case 0x52: return PacketType::ArrDump;
204     case 0x53: return PacketType::TabDump;
205     case 0x54: return PacketType::Tmtc;
206     case 0x55: return PacketType::Mcmd;
207     case 0x60: return PacketType::ForcedFECmd;
208     case 0x70: return PacketType::Ac1Init;
209     case 0x71: return PacketType::CalInit;
210     case 0x72: return PacketType::TrkInit;
211     case 0x73: return PacketType::TofInit;
212     case 0x74: return PacketType::TrgInit;
213     case 0x75: return PacketType::NdInit;
214     case 0x76: return PacketType::S4Init;
215     case 0x77: return PacketType::Ac2Init;
216     case 0x81: return PacketType::CalAlarm;
217     case 0x82: return PacketType::Ac1Alarm;
218     case 0x83: return PacketType::TrkAlarm;
219     case 0x84: return PacketType::TrgAlarm;
220     case 0x85: return PacketType::TofAlarm;
221     case 0x86: return PacketType::S4Alarm;
222     case 0x89: return PacketType::Ac2Alarm;
223     case 0xA1: return PacketType::TsbT;
224     case 0xAB: return PacketType::TsbB;
225     default: {
226     return NULL;
227     }
228     }
229    
230     }
231    
232    
233     PacketSemanticAnalyzer& PacketSemanticAnalyzer::getInstance()
234     {
235     return instance;
236     }
237    
238    
239     }
240    

  ViewVC Help
Powered by ViewVC 1.1.23