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

Contents of /chewbacca/PamOffLineSW/R4_HEADER_State.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Sep 23 07:20:10 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: v0r00, MAIN
CVS Tags: v1r02, v1r00, v1r01, start, v10RED, v9r00, v9r01, HEAD
Changes since 1.1: +0 -0 lines
Imported sources, 23/09/2008

1 //where I am
2 #include "R4_HEADER_State.h"
3 //manager
4 #include "StateManager.h"
5 //home
6 #include "R0_Init_State.h"
7 //a step after
8 #include "PacketSemanticAnalyzer.h"
9
10 namespace PamOffLineSW
11 {
12 R4_HEADER_State R4_HEADER_State::instance;
13 //extern LogUtil* mainLogUtil;
14 //extern long int iNumCadres; //cadre's number
15 //extern unsigned long long int iByte_tot;// how many bytes I have read till now
16 extern bool isCadreGood;//if the cadre is good
17
18
19 R4_HEADER_State::R4_HEADER_State()
20 {
21 headerPKT =NULL;
22 pamPKT =NULL;
23 pamPKT_length=0;
24 posPamPKT=0;
25
26 isPKTGood=true;
27 }
28
29 R4_HEADER_State::~R4_HEADER_State()
30 {
31 deleteBufferPKT();
32 pamPKT_length=0;
33 posPamPKT=0;
34
35 isPKTGood=true;
36 }
37
38 void R4_HEADER_State::deleteBufferPKT()
39 {
40 if(headerPKT)
41 {
42 delete[] headerPKT;
43 headerPKT =NULL;
44 }
45
46 if(pamPKT)
47 {
48 delete[] pamPKT;
49 pamPKT =NULL;
50 }
51
52 }
53
54
55 void R4_HEADER_State::initBufferPKT(char* headPKT)
56 {
57 //I have found a Pamela Packet Header
58 //I read how many bytes is the packet long
59 long int pack_length = (long int)(unsigned char)(headPKT[14])+
60 256*(long int)(unsigned char)(headPKT[13])+
61 256*256*(long int)(unsigned char)(headPKT[12]);
62
63 pamPKT_length=pack_length;
64
65 deleteBufferPKT();//just to be sure
66
67 // I will save the Pamela Packet and its header in this buffer
68 headerPKT=new char[LENGTH_HEADER_PKT];
69 //I start copying on the buffer the Header
70 for(int i=0;i<LENGTH_HEADER_PKT;i++)
71 {
72 headerPKT[i]=headPKT[i];
73 }
74 // I will save the Pamela Packet without the header in this buffer
75 pamPKT=new char[pamPKT_length];
76 //zerooo
77 for(int i=0;i<pamPKT_length;i++)
78 {
79 pamPKT[i]=0;
80 }
81 posPamPKT=0;
82 if((!isCadreGood)&&(isPKTGood))
83 {
84 isPKTGood = false;
85 }
86 }
87
88 void R4_HEADER_State::readInput(char inputbyte)
89 {
90 //we have identified a Pamela Packet,
91 //we add bytes to the buffer untill we reach the total length
92
93 if((!isCadreGood)&&(isPKTGood))
94 {
95 isPKTGood = false;
96 }
97
98 pamPKT[posPamPKT]=inputbyte;
99
100 //if we reach the end of the Packet
101 if(posPamPKT==(pamPKT_length-1))
102 {
103 //we can use the packet
104 PacketSemanticAnalyzer::getInstance().managePKT(headerPKT, pamPKT, pamPKT_length, isPKTGood);
105
106 //reset isPKTGood to true
107 isPKTGood=true;
108 //delete buffer
109 deleteBufferPKT();
110 //reset values
111 pamPKT_length=0; posPamPKT=0;
112
113 //return to R0 initial state
114 StateManager::getInstance().changeState(&R0_Init_State::getInstance());
115 }
116
117 posPamPKT++;
118 }
119
120 }

  ViewVC Help
Powered by ViewVC 1.1.23