source: Sophya/trunk/AddOn/TAcq/brpaqu.h@ 3670

Last change on this file since 3670 was 3659, checked in by ansari, 16 years ago

amelioration classe BRPaqChecker et ajout methode d'acces en SByte et TwoByteComplex aux donnees de la classe BRPaquet - Reza 19/10/2009

File size: 8.8 KB
Line 
1#ifndef BRPAQU_H_SEEN
2#define BRPAQU_H_SEEN
3
4/* ----------------------------------------
5 Projet BAORadio --- LAL
6 Juin 2008 , M.Taurigna , R. Ansari
7------------------------------------------- */
8
9#include <stdio.h>
10#include <iostream>
11#include <string>
12#include "brtypes.h"
13
14
15using namespace std;
16
17// ------------------------------------------------
18// ----- Classe TwoByteComplex ------
19// On definit une classe TwoByteComplex() pour manipuler une paire de byte
20// representant partie relle et imaginaire d'un nombre complexe
21// Remarque Byte = unsigned char
22// Remarque SByte = char = signed char
23class TwoByteComplex {
24 public:
25 explicit TwoByteComplex() { val_[0] = val_[1] = 0; }
26 // explicit TwoByteComplex(TwoByteComplex const & a) { val_[0] = a.val_[0]; val_[1] = 0; }
27 explicit TwoByteComplex(Byte re, Byte im) { val_[0] = re; val_[1] = im; }
28 explicit TwoByteComplex(SByte re, SByte im) { val_[0] = re; val_[1] = im; }
29 explicit TwoByteComplex(int re, int im) { val_[0] = re; val_[1] = im; }
30 explicit TwoByteComplex(float re, float im) { val_[0] = re; val_[1] = im; }
31 explicit TwoByteComplex(double re, double im) { val_[0] = re; val_[1] = im; }
32
33 inline SByte& realB() { return val_[0]; }
34 inline SByte& imagB() { return val_[1]; }
35
36 inline int realI() { return (int)(val_)[0]; }
37 inline int imagI() { return (int)(val_)[1]; }
38
39 inline double realD() { return (double)(val_)[0]; }
40 inline double imagD() { return (double)(val_)[1]; }
41
42 SByte val_[2];
43};
44
45// ------------------------------------------------
46
47// OFFSET : au cas ou le firmware reception ajoute des mots avant le header
48#define OFFSET 0
49// Taille entete/trailer en octets
50#define BRHDRSIZE 24
51// Actuellement le trailer est vire ...
52// Reza, 28 Jan 2009 le trailer fait 16 octets
53#define BRTRLSIZE 16
54/* REZA passe a 16 octets #define BRTRLSIZE 40 */
55//Offset Mode Acq
56#define BRMODACQOFF 20 /*RezaMOD #define BRMODACQOFF 24 */
57// Offset ChanId
58#define BRCHANIDOFF 20 /*RezaMOD #define BRCHANIDOFF 24 */
59// Offset du time-tag
60#define BRTMTAGOFF 12 /*RezaMOD #define BRTMTAGOFF 16 */
61// offset FrameCounter
62#define BRFRCPTOFF 16 /*RezaMOD#define BRFRCPTOFF 20 */
63// offset Paquet Id
64#define BRPKTIDOFF 20 /*RezaMOD #define BRPKTIDOFF 24 */
65// offset paquet lenght = FrameDataLength
66#define BRPKTLENOFF 8 /*RezaMOD #define BRPKTLENOFF 12 */
67// offset position chariot ???
68//#define BRPCOFF 16
69
70enum ChannelID
71 {
72 None=0,
73 Ch1,
74 Ch2,
75 Ch1_2,
76 Ch3,
77 Ch4,
78 Ch3_4
79 };
80enum ModeAcq
81 {
82 RawData=1,
83 FFT
84 };
85
86// Definition des actions sur la conversion de format (swap...) des donnees arrivant
87enum BRDataFmtConv {
88 BR_DoNothing,
89 BR_Copy,
90 BR_SwapAll,
91 BR_SwapHDR,
92 BR_FFTOneChan,
93 BR_FFTTwoChan,
94 BR_Swap32,
95 BR_FFTOneChan32,
96 BR_FFTTwoChan32,
97 BR_FFTOneChanNoSwap,
98 BR_FFTTwoChanNoSwap,
99 BR_CpHdrTrl,
100 BR_Copy_Reduc,
101 BR_FFTOneChanNoSwapReduct,
102 BR_FFTTwoChanNoSwapReduct
103};
104
105// Structure correspondant a HEADER-DATA-TRAILER
106class BRPaquet {
107 public:
108// Cree d'un objet BRPaquet avec copie/swap depuis src -> dst (si src != NULL)
109 BRPaquet(Byte* src, Byte* dst, int paqsz=16424, BRDataFmtConv fgswap=BR_Copy,int minBin=0,int nbBin=0);
110 // Cree d'un objet BRPaquet de taille paqsz sur la zone dst
111 BRPaquet(Byte* srcdst, int paqsz=16424);
112 // ~BRPaquet();
113
114 // Acces diverses tailles
115 inline int PaquetSize() { return sz_; }
116 inline int DataSize() { return sz_-(BRHDRSIZE+BRTRLSIZE); }
117 inline int HeaderSize() { return BRHDRSIZE; }
118 inline int TrailerSize() { return BRTRLSIZE; }
119
120 // Acces differentes zone memoire
121 inline Byte* Begin() { return dst_+OFFSET; }
122 inline Byte* Data1() { return dst_+BRHDRSIZE+OFFSET; }
123 inline Byte* Data2() { return dst_+BRHDRSIZE+(DataSize()/2)+OFFSET; }
124 inline Byte* Header() { return dst_+OFFSET; }
125 inline Byte* Trailer() { return (dst_+sz_-BRTRLSIZE+OFFSET); }
126
127 // Acces aux differentes zone de donnees en signed byte (-127 ... 127), donnees FFT
128 inline SByte* BeginS() { return (SByte*)(dst_+OFFSET); }
129 inline SByte* Data1S() { return (SByte*)(dst_+BRHDRSIZE+OFFSET); }
130 inline SByte* Data2S() { return (SByte*)(dst_+BRHDRSIZE+(DataSize()/2)+OFFSET); }
131
132 // Acces aux differentes zone de donnees en TwoByteComplex pour donnees FFT
133 inline int DataSizeC() { return (sz_-(BRHDRSIZE+BRTRLSIZE))/2; }
134 inline TwoByteComplex* BeginC() { return (TwoByteComplex*)(dst_+OFFSET); }
135 inline TwoByteComplex* Data1C() { return (TwoByteComplex*)(dst_+BRHDRSIZE+OFFSET); }
136 inline TwoByteComplex* Data2C() { return (TwoByteComplex*)(dst_+BRHDRSIZE+(DataSize()/2)+OFFSET); }
137
138 // Valeurs differentes zones HDR/TRL
139 inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
140 inline UInt32 HDRMarker2() {return *((UInt32*)(dst_+OFFSET+1));}
141 inline UInt64 HDRMarker64() {return *((UInt64*)(dst_+OFFSET));}
142
143 inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
144 inline UInt32 TRLMarker2() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET+1)));}
145 inline UInt64 TRLMarker64() {return *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
146
147// Informations diverses sur le paquet/mode d'acquisition
148 inline UInt16 ModeAcq() {return *((UInt16*)(dst_+(BRMODACQOFF+OFFSET)));}
149 inline UInt16 ChanId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0x1800)>> 12) ;}
150 inline UInt16 ChipId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0xC00)>> 10) ;}
151
152 inline UInt32 FrameCounter() {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
153 inline UInt32 TimeTag1() {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
154 inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
155 inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFULL);}
156
157 inline UInt32 PaqId() {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
158 inline UInt16 PaqLen() {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
159
160 UInt16 ChannelID();
161 UInt16 ModeAcquisition();
162
163 // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
164 // Fonctions utiles pour remplir un objet BRPaquet
165 void SetHDRMarker64(UInt64 htag);
166 void SetTRLMarker64(UInt64 ttag);
167 void SetFrameCounter(UInt32 fc);
168 void SetTimeTag(UInt64 timtag);
169 inline void SetPaqLen(UInt16 len) { *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET))) = len; }
170
171 // pour faire un print de la structure
172 ostream& Print(ostream & os, int nelt=8, bool prht=true);
173 inline ostream& Print(int nelt=8, bool prht=true)
174 { return Print(cout, nelt, prht); }
175
176 // fonction appelee par le constructeur pour reordonner les donnees FFT
177 static void ReorderFFTData(SByte* src, SByte* dst, int sz);
178 static void ReorderFFTData32(SByte* src, SByte* dst, int sz);
179 static void ReorderFFTDataNoSwap(SByte* src, SByte* dst, int sz);
180 static const char* FmtConvToString(BRDataFmtConv fgswap);
181// protected:
182 // donnees membres
183 int sz_; //taille du paquet
184 Byte* dst_;
185
186};
187
188// --------------------------------------------------------------------------
189// Classe pour effectuer des verifications d'integrite sur les paquets/frames
190// --------------------------------------------------------------------------
191
192class BRPaqChecker {
193public:
194 // if cktrl==true, check header AND trailer, ==false check header only
195 BRPaqChecker(bool cktrl=true, int maxprt=0);
196 ~BRPaqChecker();
197
198 UInt64 DefineHDRTag(UInt32 hdr1=0x76543210, UInt32 hdr2=0xFEDCBA98);
199 UInt64 DefineTRLTag(UInt32 trl1=0x55555555, UInt32 trl2=0xAAAAAAAA);
200
201 inline UInt64 HDRTag() { return hdrtag_; }
202 inline UInt64 TRLTag() { return trltag_; }
203
204 // Verifie le paquet, renvoie true si OK
205 bool Check(BRPaquet& paq, UInt64& numframe);
206 inline bool Check(BRPaquet& paq) { UInt64 nf; return Check(paq, nf); }
207
208 // Imprime le compte de paquets ...
209 ostream & Print(ostream& os) const;
210 inline ostream & Print() const { return Print(cout); }
211
212 // Acces aux differents compteurs
213 inline UInt64 NbPaqTotal() { return totnframes; }
214 inline UInt64 NbPaqOK() { return nframeok; }
215 inline UInt64 NbPaqLost() { return lostframes; }
216 inline UInt64 NbGaps() { return cnt_saut; }
217 inline UInt64 LastFrameNum() { return lastframenum; }
218
219protected:
220 UInt64 totnframes; // Nombre totale de frames/paquets traites
221 UInt64 nframeok; // Nombre totale de frames/paquets avec HDR/TRL OK
222 UInt64 lostframes; // Nombre totale de frames/paquets perdus
223 UInt16 frclst; // derniere valeur du frame-counter
224 UInt64 lastframenum; // Dernier numero de frame(=frame-counter, sans modulo 65535)
225
226 bool cktrl_; // Verifie aussi le trailer si true
227 UInt64 cnt_saut; // Nb de fois ou DeltaFrameCounter>1
228 UInt32 maxprt_; // Nb maxi de print paquets perdus / probleme
229
230 UInt64 hdrtag_;
231 UInt64 trltag_;
232};
233
234// Definition de l'operator << overloading - Appel de Print()
235inline ostream& operator << (ostream& s, BRPaqChecker const & chk)
236 { return chk.Print(s); }
237
238#endif
239
240
Note: See TracBrowser for help on using the repository browser.