[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] | 15 | using namespace std;
|
---|
| 16 |
|
---|
[3623] | 17 | // ------------------------------------------------
|
---|
| 18 | // ----- Classe TwoByteComplex ------
|
---|
[3592] | 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
|
---|
| 23 | class 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 |
|
---|
[3659] | 33 | inline SByte& realB() { return val_[0]; }
|
---|
| 34 | inline SByte& imagB() { return val_[1]; }
|
---|
[3592] | 35 |
|
---|
[3659] | 36 | inline int realI() { return (int)(val_)[0]; }
|
---|
| 37 | inline int imagI() { return (int)(val_)[1]; }
|
---|
[3592] | 38 |
|
---|
[3659] | 39 | inline double realD() { return (double)(val_)[0]; }
|
---|
| 40 | inline double imagD() { return (double)(val_)[1]; }
|
---|
[3592] | 41 |
|
---|
[3659] | 42 | SByte val_[2];
|
---|
[3592] | 43 | };
|
---|
| 44 |
|
---|
[3623] | 45 | // ------------------------------------------------
|
---|
| 46 |
|
---|
| 47 | // OFFSET : au cas ou le firmware reception ajoute des mots avant le header
|
---|
[3592] | 48 | #define OFFSET 0
|
---|
[3537] | 49 | // Taille entete/trailer en octets
|
---|
| 50 | #define BRHDRSIZE 24
|
---|
| 51 | // Actuellement le trailer est vire ...
|
---|
[3592] | 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 */
|
---|
[3537] | 59 | // Offset du time-tag
|
---|
[3592] | 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
|
---|
[3537] | 69 |
|
---|
[3592] | 70 | enum ChannelID
|
---|
| 71 | {
|
---|
| 72 | None=0,
|
---|
| 73 | Ch1,
|
---|
| 74 | Ch2,
|
---|
| 75 | Ch1_2,
|
---|
| 76 | Ch3,
|
---|
| 77 | Ch4,
|
---|
| 78 | Ch3_4
|
---|
| 79 | };
|
---|
| 80 | enum ModeAcq
|
---|
| 81 | {
|
---|
| 82 | RawData=1,
|
---|
| 83 | FFT
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | // Definition des actions sur la conversion de format (swap...) des donnees arrivant
|
---|
| 87 | enum 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,
|
---|
[3658] | 98 | BR_FFTTwoChanNoSwap,
|
---|
| 99 | BR_CpHdrTrl,
|
---|
| 100 | BR_Copy_Reduc,
|
---|
| 101 | BR_FFTOneChanNoSwapReduct,
|
---|
| 102 | BR_FFTTwoChanNoSwapReduct
|
---|
[3592] | 103 | };
|
---|
| 104 |
|
---|
[3537] | 105 | // Structure correspondant a HEADER-DATA-TRAILER
|
---|
| 106 | class BRPaquet {
|
---|
| 107 | public:
|
---|
[3623] | 108 | // Cree d'un objet BRPaquet avec copie/swap depuis src -> dst (si src != NULL)
|
---|
[3658] | 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();
|
---|
[3537] | 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
|
---|
[3623] | 121 | inline Byte* Begin() { return dst_+OFFSET; }
|
---|
[3592] | 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); }
|
---|
[3659] | 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 |
|
---|
[3537] | 138 | // Valeurs differentes zones HDR/TRL
|
---|
[3592] | 139 | inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
|
---|
[3623] | 140 | inline UInt32 HDRMarker2() {return *((UInt32*)(dst_+OFFSET+1));}
|
---|
| 141 | inline UInt64 HDRMarker64() {return *((UInt64*)(dst_+OFFSET));}
|
---|
| 142 |
|
---|
[3592] | 143 | inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
|
---|
[3623] | 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
|
---|
[3592] | 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) ;}
|
---|
[3537] | 151 |
|
---|
[3623] | 152 | inline UInt32 FrameCounter() {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
|
---|
[3592] | 153 | inline UInt32 TimeTag1() {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
|
---|
| 154 | inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
|
---|
[3635] | 155 | inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFULL);}
|
---|
[3592] | 156 |
|
---|
| 157 | inline UInt32 PaqId() {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
|
---|
| 158 | inline UInt16 PaqLen() {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
|
---|
| 159 |
|
---|
[3623] | 160 | UInt16 ChannelID();
|
---|
| 161 | UInt16 ModeAcquisition();
|
---|
[3592] | 162 |
|
---|
| 163 | // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
|
---|
[3623] | 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; }
|
---|
[3592] | 170 |
|
---|
[3537] | 171 | // pour faire un print de la structure
|
---|
[3623] | 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); }
|
---|
[3537] | 175 |
|
---|
[3592] | 176 | // fonction appelee par le constructeur pour reordonner les donnees FFT
|
---|
[3659] | 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);
|
---|
[3592] | 180 | static const char* FmtConvToString(BRDataFmtConv fgswap);
|
---|
| 181 | // protected:
|
---|
[3537] | 182 | // donnees membres
|
---|
| 183 | int sz_; //taille du paquet
|
---|
| 184 | Byte* dst_;
|
---|
[3658] | 185 |
|
---|
[3537] | 186 | };
|
---|
| 187 |
|
---|
[3592] | 188 | // --------------------------------------------------------------------------
|
---|
| 189 | // Classe pour effectuer des verifications d'integrite sur les paquets/frames
|
---|
| 190 | // --------------------------------------------------------------------------
|
---|
| 191 |
|
---|
| 192 | class BRPaqChecker {
|
---|
| 193 | public:
|
---|
[3659] | 194 | // if cktrl==true, check header AND trailer, ==false check header only
|
---|
[3640] | 195 | BRPaqChecker(bool cktrl=true, int maxprt=0);
|
---|
[3592] | 196 | ~BRPaqChecker();
|
---|
[3623] | 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 |
|
---|
[3592] | 204 | // Verifie le paquet, renvoie true si OK
|
---|
[3659] | 205 | bool Check(BRPaquet& paq, UInt64& numframe);
|
---|
| 206 | inline bool Check(BRPaquet& paq) { UInt64 nf; return Check(paq, nf); }
|
---|
| 207 |
|
---|
[3592] | 208 | // Imprime le compte de paquets ...
|
---|
[3640] | 209 | ostream & Print(ostream& os) const;
|
---|
| 210 | inline ostream & Print() const { return Print(cout); }
|
---|
[3592] | 211 |
|
---|
[3659] | 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; }
|
---|
[3623] | 218 |
|
---|
[3659] | 219 | protected:
|
---|
| 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 |
|
---|
[3640] | 226 | bool cktrl_; // Verifie aussi le trailer si true
|
---|
[3659] | 227 | UInt64 cnt_saut; // Nb de fois ou DeltaFrameCounter>1
|
---|
| 228 | UInt32 maxprt_; // Nb maxi de print paquets perdus / probleme
|
---|
[3640] | 229 |
|
---|
[3623] | 230 | UInt64 hdrtag_;
|
---|
| 231 | UInt64 trltag_;
|
---|
[3592] | 232 | };
|
---|
| 233 |
|
---|
[3659] | 234 | // Definition de l'operator << overloading - Appel de Print()
|
---|
[3640] | 235 | inline ostream& operator << (ostream& s, BRPaqChecker const & chk)
|
---|
| 236 | { return chk.Print(s); }
|
---|
| 237 |
|
---|
[3537] | 238 | #endif
|
---|
[3592] | 239 |
|
---|
| 240 |
|
---|