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

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

Amelioration programme mfits2pec.cc - Reza 06/04/2009

File size: 5.8 KB
RevLine 
[3537]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
[3592]14
[3537]15using namespace std;
16
[3592]17// On definit une classe TwoByteComplex() pour manipuler une paire de byte
18// representant partie relle et imaginaire d'un nombre complexe
19// Remarque Byte = unsigned char
20// Remarque SByte = char = signed char
21class TwoByteComplex {
22 public:
23 explicit TwoByteComplex() { val_[0] = val_[1] = 0; }
24 // explicit TwoByteComplex(TwoByteComplex const & a) { val_[0] = a.val_[0]; val_[1] = 0; }
25 explicit TwoByteComplex(Byte re, Byte im) { val_[0] = re; val_[1] = im; }
26 explicit TwoByteComplex(SByte re, SByte im) { val_[0] = re; val_[1] = im; }
27 explicit TwoByteComplex(int re, int im) { val_[0] = re; val_[1] = im; }
28 explicit TwoByteComplex(float re, float im) { val_[0] = re; val_[1] = im; }
29 explicit TwoByteComplex(double re, double im) { val_[0] = re; val_[1] = im; }
30
31 inline Byte& realB() { return val_[0]; }
32 inline Byte& imagB() { return val_[1]; }
33
34 inline SByte realSB() { return ((SByte*)val_)[0]; }
35 inline SByte imagSB() { return ((SByte*)val_)[1]; }
36
37 inline int realI() { return ((SByte*)val_)[0]; }
38 inline int imagI() { return ((SByte*)val_)[1]; }
39
40 inline double realD() { return ((SByte*)val_)[0]; }
41 inline double imagD() { return ((SByte*)val_)[1]; }
42
43 Byte val_[2];
44};
45
46// Actuellement apres test Nancay un mot de 4octects est mis avant le header
47#define OFFSET 0
[3537]48// Taille entete/trailer en octets
49#define BRHDRSIZE 24
50// Actuellement le trailer est vire ...
[3592]51// Reza, 28 Jan 2009 le trailer fait 16 octets
52#define BRTRLSIZE 16
53/* REZA passe a 16 octets #define BRTRLSIZE 40 */
54//Offset Mode Acq
55#define BRMODACQOFF 20 /*RezaMOD #define BRMODACQOFF 24 */
56// Offset ChanId
57#define BRCHANIDOFF 20 /*RezaMOD #define BRCHANIDOFF 24 */
[3537]58// Offset du time-tag
[3592]59#define BRTMTAGOFF 12 /*RezaMOD #define BRTMTAGOFF 16 */
60// offset FrameCounter
61#define BRFRCPTOFF 16 /*RezaMOD#define BRFRCPTOFF 20 */
62// offset Paquet Id
63#define BRPKTIDOFF 20 /*RezaMOD #define BRPKTIDOFF 24 */
64// offset paquet lenght = FrameDataLength
65#define BRPKTLENOFF 8 /*RezaMOD #define BRPKTLENOFF 12 */
66// offset position chariot ???
67//#define BRPCOFF 16
[3537]68
[3592]69enum ChannelID
70 {
71 None=0,
72 Ch1,
73 Ch2,
74 Ch1_2,
75 Ch3,
76 Ch4,
77 Ch3_4
78 };
79enum ModeAcq
80 {
81 RawData=1,
82 FFT
83 };
84
85// Definition des actions sur la conversion de format (swap...) des donnees arrivant
86enum BRDataFmtConv {
87 BR_DoNothing,
88 BR_Copy,
89 BR_SwapAll,
90 BR_SwapHDR,
91 BR_FFTOneChan,
92 BR_FFTTwoChan,
93 BR_Swap32,
94 BR_FFTOneChan32,
95 BR_FFTTwoChan32,
96 BR_FFTOneChanNoSwap,
97 BR_FFTTwoChanNoSwap
98};
99
[3537]100// Structure correspondant a HEADER-DATA-TRAILER
101class BRPaquet {
102 public:
[3592]103 BRPaquet(Byte* src, Byte* dst, int paqsz=4096, BRDataFmtConv fgswap=BR_SwapAll);
104 BRPaquet(Byte* srcdst, int paqsz=4096);
[3537]105 // ~BRPaquet();
106
107 // Acces diverses tailles
108 inline int PaquetSize() { return sz_; }
109 inline int DataSize() { return sz_-(BRHDRSIZE+BRTRLSIZE); }
110 inline int HeaderSize() { return BRHDRSIZE; }
111 inline int TrailerSize() { return BRTRLSIZE; }
112
113 // Acces differentes zone memoire
[3592]114 inline Byte* Data() { return dst_+BRHDRSIZE+OFFSET; }
115 inline Byte* Data1() { return dst_+BRHDRSIZE+OFFSET; }
116 inline Byte* Data2() { return dst_+BRHDRSIZE+(DataSize()/2)+OFFSET; }
117 inline Byte* Header() { return dst_+OFFSET; }
118 inline Byte* Trailer() { return (dst_+sz_-BRTRLSIZE+OFFSET); }
[3537]119
120 // Valeurs differentes zones HDR/TRL
[3592]121 inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
122 inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
123 inline UInt16 ModeAcq() {return *((UInt16*)(dst_+(BRMODACQOFF+OFFSET)));}
124 inline UInt16 ChanId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0x1800)>> 12) ;}
125 inline UInt16 ChipId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0xC00)>> 10) ;}
[3537]126
[3592]127 inline UInt32 TimeTag1() {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
128 inline UInt32 FrameCounter() {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
129 inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
130
131 inline UInt32 PaqId() {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
132 inline UInt16 PaqLen() {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
133
134
135 // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
136
[3537]137 // pour faire un print de la structure
138 void Print(ostream & os, int nelt=8, bool prht=true);
[3592]139 UInt16 ChannelID();
140 UInt16 ModeAcquisition();
[3537]141
[3592]142 // fonction appelee par le constructeur pour reordonner les donnees FFT
143 static void ReorderFFTData(Byte* src, Byte* dst, int sz);
144 static void ReorderFFTData32(Byte* src, Byte* dst, int sz);
145 static void ReorderFFTDataNoSwap(Byte* src, Byte* dst, int sz);
146 static const char* FmtConvToString(BRDataFmtConv fgswap);
147// protected:
[3537]148 // donnees membres
149 int sz_; //taille du paquet
150 Byte* dst_;
151};
152
[3592]153// --------------------------------------------------------------------------
154// Classe pour effectuer des verifications d'integrite sur les paquets/frames
155// --------------------------------------------------------------------------
156
157class BRPaqChecker {
158public:
159 BRPaqChecker();
160 ~BRPaqChecker();
161 // Verifie le paquet, renvoie true si OK
162 bool Check(BRPaquet& paq);
163 // Imprime le compte de paquets ...
164 ostream & Print(ostream& os);
165
166 unsigned long long totnframes; // Nombre totale de frames/paquets traites
167 unsigned long long nframeok; // Nombre totale de frames/paquets avec HDR/TRL OK
168 unsigned long long lostframes; // Nombre totale de frames/paquets perdus
169 unsigned int frclst; // derniere valeur du frame-counter
170};
171
[3537]172#endif
[3592]173
174
Note: See TracBrowser for help on using the repository browser.