[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 |
|
---|
| 33 | inline Byte& realB() { return val_[0]; }
|
---|
| 34 | inline Byte& imagB() { return val_[1]; }
|
---|
| 35 |
|
---|
| 36 | inline SByte realSB() { return ((SByte*)val_)[0]; }
|
---|
| 37 | inline SByte imagSB() { return ((SByte*)val_)[1]; }
|
---|
| 38 |
|
---|
| 39 | inline int realI() { return ((SByte*)val_)[0]; }
|
---|
| 40 | inline int imagI() { return ((SByte*)val_)[1]; }
|
---|
| 41 |
|
---|
| 42 | inline double realD() { return ((SByte*)val_)[0]; }
|
---|
| 43 | inline double imagD() { return ((SByte*)val_)[1]; }
|
---|
| 44 |
|
---|
| 45 | Byte val_[2];
|
---|
| 46 | };
|
---|
| 47 |
|
---|
[3623] | 48 | // ------------------------------------------------
|
---|
| 49 |
|
---|
| 50 | // OFFSET : au cas ou le firmware reception ajoute des mots avant le header
|
---|
[3592] | 51 | #define OFFSET 0
|
---|
[3537] | 52 | // Taille entete/trailer en octets
|
---|
| 53 | #define BRHDRSIZE 24
|
---|
| 54 | // Actuellement le trailer est vire ...
|
---|
[3592] | 55 | // Reza, 28 Jan 2009 le trailer fait 16 octets
|
---|
| 56 | #define BRTRLSIZE 16
|
---|
| 57 | /* REZA passe a 16 octets #define BRTRLSIZE 40 */
|
---|
| 58 | //Offset Mode Acq
|
---|
| 59 | #define BRMODACQOFF 20 /*RezaMOD #define BRMODACQOFF 24 */
|
---|
| 60 | // Offset ChanId
|
---|
| 61 | #define BRCHANIDOFF 20 /*RezaMOD #define BRCHANIDOFF 24 */
|
---|
[3537] | 62 | // Offset du time-tag
|
---|
[3592] | 63 | #define BRTMTAGOFF 12 /*RezaMOD #define BRTMTAGOFF 16 */
|
---|
| 64 | // offset FrameCounter
|
---|
| 65 | #define BRFRCPTOFF 16 /*RezaMOD#define BRFRCPTOFF 20 */
|
---|
| 66 | // offset Paquet Id
|
---|
| 67 | #define BRPKTIDOFF 20 /*RezaMOD #define BRPKTIDOFF 24 */
|
---|
| 68 | // offset paquet lenght = FrameDataLength
|
---|
| 69 | #define BRPKTLENOFF 8 /*RezaMOD #define BRPKTLENOFF 12 */
|
---|
| 70 | // offset position chariot ???
|
---|
| 71 | //#define BRPCOFF 16
|
---|
[3537] | 72 |
|
---|
[3592] | 73 | enum ChannelID
|
---|
| 74 | {
|
---|
| 75 | None=0,
|
---|
| 76 | Ch1,
|
---|
| 77 | Ch2,
|
---|
| 78 | Ch1_2,
|
---|
| 79 | Ch3,
|
---|
| 80 | Ch4,
|
---|
| 81 | Ch3_4
|
---|
| 82 | };
|
---|
| 83 | enum ModeAcq
|
---|
| 84 | {
|
---|
| 85 | RawData=1,
|
---|
| 86 | FFT
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 | // Definition des actions sur la conversion de format (swap...) des donnees arrivant
|
---|
| 90 | enum BRDataFmtConv {
|
---|
| 91 | BR_DoNothing,
|
---|
| 92 | BR_Copy,
|
---|
| 93 | BR_SwapAll,
|
---|
| 94 | BR_SwapHDR,
|
---|
| 95 | BR_FFTOneChan,
|
---|
| 96 | BR_FFTTwoChan,
|
---|
| 97 | BR_Swap32,
|
---|
| 98 | BR_FFTOneChan32,
|
---|
| 99 | BR_FFTTwoChan32,
|
---|
| 100 | BR_FFTOneChanNoSwap,
|
---|
[3658] | 101 | BR_FFTTwoChanNoSwap,
|
---|
| 102 | BR_CpHdrTrl,
|
---|
| 103 | BR_Copy_Reduc,
|
---|
| 104 | BR_FFTOneChanNoSwapReduct,
|
---|
| 105 | BR_FFTTwoChanNoSwapReduct
|
---|
[3592] | 106 | };
|
---|
| 107 |
|
---|
[3537] | 108 | // Structure correspondant a HEADER-DATA-TRAILER
|
---|
| 109 | class BRPaquet {
|
---|
| 110 | public:
|
---|
[3623] | 111 | // Cree d'un objet BRPaquet avec copie/swap depuis src -> dst (si src != NULL)
|
---|
[3658] | 112 | BRPaquet(Byte* src, Byte* dst, int paqsz=16424, BRDataFmtConv fgswap=BR_Copy,int minBin=0,int nbBin=0);
|
---|
| 113 | // Cree d'un objet BRPaquet de taille paqsz sur la zone dst
|
---|
| 114 | BRPaquet(Byte* srcdst, int paqsz=16424);
|
---|
| 115 | // ~BRPaquet();
|
---|
[3537] | 116 |
|
---|
| 117 | // Acces diverses tailles
|
---|
| 118 | inline int PaquetSize() { return sz_; }
|
---|
| 119 | inline int DataSize() { return sz_-(BRHDRSIZE+BRTRLSIZE); }
|
---|
| 120 | inline int HeaderSize() { return BRHDRSIZE; }
|
---|
| 121 | inline int TrailerSize() { return BRTRLSIZE; }
|
---|
| 122 |
|
---|
| 123 | // Acces differentes zone memoire
|
---|
[3623] | 124 | inline Byte* Begin() { return dst_+OFFSET; }
|
---|
[3592] | 125 | inline Byte* Data1() { return dst_+BRHDRSIZE+OFFSET; }
|
---|
| 126 | inline Byte* Data2() { return dst_+BRHDRSIZE+(DataSize()/2)+OFFSET; }
|
---|
| 127 | inline Byte* Header() { return dst_+OFFSET; }
|
---|
| 128 | inline Byte* Trailer() { return (dst_+sz_-BRTRLSIZE+OFFSET); }
|
---|
[3537] | 129 |
|
---|
| 130 | // Valeurs differentes zones HDR/TRL
|
---|
[3592] | 131 | inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
|
---|
[3623] | 132 | inline UInt32 HDRMarker2() {return *((UInt32*)(dst_+OFFSET+1));}
|
---|
| 133 | inline UInt64 HDRMarker64() {return *((UInt64*)(dst_+OFFSET));}
|
---|
| 134 |
|
---|
[3592] | 135 | inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
|
---|
[3623] | 136 | inline UInt32 TRLMarker2() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET+1)));}
|
---|
| 137 | inline UInt64 TRLMarker64() {return *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
|
---|
| 138 |
|
---|
| 139 | // Informations diverses sur le paquet/mode d'acquisition
|
---|
[3592] | 140 | inline UInt16 ModeAcq() {return *((UInt16*)(dst_+(BRMODACQOFF+OFFSET)));}
|
---|
| 141 | inline UInt16 ChanId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0x1800)>> 12) ;}
|
---|
| 142 | inline UInt16 ChipId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0xC00)>> 10) ;}
|
---|
[3537] | 143 |
|
---|
[3623] | 144 | inline UInt32 FrameCounter() {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
|
---|
[3592] | 145 | inline UInt32 TimeTag1() {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
|
---|
| 146 | inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
|
---|
[3635] | 147 | inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFULL);}
|
---|
[3592] | 148 |
|
---|
| 149 | inline UInt32 PaqId() {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
|
---|
| 150 | inline UInt16 PaqLen() {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
|
---|
| 151 |
|
---|
[3623] | 152 | UInt16 ChannelID();
|
---|
| 153 | UInt16 ModeAcquisition();
|
---|
[3592] | 154 |
|
---|
| 155 | // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
|
---|
[3623] | 156 | // Fonctions utiles pour remplir un objet BRPaquet
|
---|
| 157 | void SetHDRMarker64(UInt64 htag);
|
---|
| 158 | void SetTRLMarker64(UInt64 ttag);
|
---|
| 159 | void SetFrameCounter(UInt32 fc);
|
---|
| 160 | void SetTimeTag(UInt64 timtag);
|
---|
| 161 | inline void SetPaqLen(UInt16 len) { *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET))) = len; }
|
---|
[3592] | 162 |
|
---|
[3537] | 163 | // pour faire un print de la structure
|
---|
[3623] | 164 | ostream& Print(ostream & os, int nelt=8, bool prht=true);
|
---|
| 165 | inline ostream& Print(int nelt=8, bool prht=true)
|
---|
| 166 | { return Print(cout, nelt, prht); }
|
---|
[3537] | 167 |
|
---|
[3592] | 168 | // fonction appelee par le constructeur pour reordonner les donnees FFT
|
---|
| 169 | static void ReorderFFTData(Byte* src, Byte* dst, int sz);
|
---|
| 170 | static void ReorderFFTData32(Byte* src, Byte* dst, int sz);
|
---|
| 171 | static void ReorderFFTDataNoSwap(Byte* src, Byte* dst, int sz);
|
---|
| 172 | static const char* FmtConvToString(BRDataFmtConv fgswap);
|
---|
| 173 | // protected:
|
---|
[3537] | 174 | // donnees membres
|
---|
| 175 | int sz_; //taille du paquet
|
---|
| 176 | Byte* dst_;
|
---|
[3658] | 177 |
|
---|
[3537] | 178 | };
|
---|
| 179 |
|
---|
[3592] | 180 | // --------------------------------------------------------------------------
|
---|
| 181 | // Classe pour effectuer des verifications d'integrite sur les paquets/frames
|
---|
| 182 | // --------------------------------------------------------------------------
|
---|
| 183 |
|
---|
| 184 | class BRPaqChecker {
|
---|
| 185 | public:
|
---|
[3640] | 186 | BRPaqChecker(bool cktrl=true, int maxprt=0);
|
---|
[3592] | 187 | ~BRPaqChecker();
|
---|
[3623] | 188 |
|
---|
| 189 | UInt64 DefineHDRTag(UInt32 hdr1=0x76543210, UInt32 hdr2=0xFEDCBA98);
|
---|
| 190 | UInt64 DefineTRLTag(UInt32 trl1=0x55555555, UInt32 trl2=0xAAAAAAAA);
|
---|
| 191 |
|
---|
| 192 | inline UInt64 HDRTag() { return hdrtag_; }
|
---|
| 193 | inline UInt64 TRLTag() { return trltag_; }
|
---|
| 194 |
|
---|
[3592] | 195 | // Verifie le paquet, renvoie true si OK
|
---|
| 196 | bool Check(BRPaquet& paq);
|
---|
| 197 | // Imprime le compte de paquets ...
|
---|
[3640] | 198 | ostream & Print(ostream& os) const;
|
---|
| 199 | inline ostream & Print() const { return Print(cout); }
|
---|
[3592] | 200 |
|
---|
| 201 | unsigned long long totnframes; // Nombre totale de frames/paquets traites
|
---|
| 202 | unsigned long long nframeok; // Nombre totale de frames/paquets avec HDR/TRL OK
|
---|
| 203 | unsigned long long lostframes; // Nombre totale de frames/paquets perdus
|
---|
| 204 | unsigned int frclst; // derniere valeur du frame-counter
|
---|
[3623] | 205 |
|
---|
[3640] | 206 | bool cktrl_; // Verifie aussi le trailer si true
|
---|
| 207 | unsigned int cnt_saut; // Nb de fois ou DeltaFrameCounter>1
|
---|
| 208 | unsigned int maxprt_; // Nb maxi de print paquets perdus / probleme
|
---|
| 209 |
|
---|
[3623] | 210 | UInt64 hdrtag_;
|
---|
| 211 | UInt64 trltag_;
|
---|
[3592] | 212 | };
|
---|
| 213 |
|
---|
[3640] | 214 | // Definition de l'operator << overloading - Appel de Prin()
|
---|
| 215 | inline ostream& operator << (ostream& s, BRPaqChecker const & chk)
|
---|
| 216 | { return chk.Print(s); }
|
---|
| 217 |
|
---|
[3537] | 218 | #endif
|
---|
[3592] | 219 |
|
---|
| 220 |
|
---|