[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,
|
---|
| 101 | BR_FFTTwoChanNoSwap
|
---|
| 102 | };
|
---|
| 103 |
|
---|
[3537] | 104 | // Structure correspondant a HEADER-DATA-TRAILER
|
---|
| 105 | class BRPaquet {
|
---|
| 106 | public:
|
---|
[3623] | 107 | // Cree d'un objet BRPaquet avec copie/swap depuis src -> dst (si src != NULL)
|
---|
[3592] | 108 | BRPaquet(Byte* src, Byte* dst, int paqsz=4096, BRDataFmtConv fgswap=BR_SwapAll);
|
---|
[3623] | 109 | // Cree d'un objet BRPaquet de taille paqsz sur la zone dst
|
---|
[3592] | 110 | BRPaquet(Byte* srcdst, int paqsz=4096);
|
---|
[3623] | 111 | // ~BRPaquet();
|
---|
[3537] | 112 |
|
---|
| 113 | // Acces diverses tailles
|
---|
| 114 | inline int PaquetSize() { return sz_; }
|
---|
| 115 | inline int DataSize() { return sz_-(BRHDRSIZE+BRTRLSIZE); }
|
---|
| 116 | inline int HeaderSize() { return BRHDRSIZE; }
|
---|
| 117 | inline int TrailerSize() { return BRTRLSIZE; }
|
---|
| 118 |
|
---|
| 119 | // Acces differentes zone memoire
|
---|
[3623] | 120 | inline Byte* Begin() { return dst_+OFFSET; }
|
---|
[3592] | 121 | inline Byte* Data1() { return dst_+BRHDRSIZE+OFFSET; }
|
---|
| 122 | inline Byte* Data2() { return dst_+BRHDRSIZE+(DataSize()/2)+OFFSET; }
|
---|
| 123 | inline Byte* Header() { return dst_+OFFSET; }
|
---|
| 124 | inline Byte* Trailer() { return (dst_+sz_-BRTRLSIZE+OFFSET); }
|
---|
[3537] | 125 |
|
---|
| 126 | // Valeurs differentes zones HDR/TRL
|
---|
[3592] | 127 | inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
|
---|
[3623] | 128 | inline UInt32 HDRMarker2() {return *((UInt32*)(dst_+OFFSET+1));}
|
---|
| 129 | inline UInt64 HDRMarker64() {return *((UInt64*)(dst_+OFFSET));}
|
---|
| 130 |
|
---|
[3592] | 131 | inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
|
---|
[3623] | 132 | inline UInt32 TRLMarker2() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET+1)));}
|
---|
| 133 | inline UInt64 TRLMarker64() {return *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
|
---|
| 134 |
|
---|
| 135 | // Informations diverses sur le paquet/mode d'acquisition
|
---|
[3592] | 136 | inline UInt16 ModeAcq() {return *((UInt16*)(dst_+(BRMODACQOFF+OFFSET)));}
|
---|
| 137 | inline UInt16 ChanId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0x1800)>> 12) ;}
|
---|
| 138 | inline UInt16 ChipId() {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0xC00)>> 10) ;}
|
---|
[3537] | 139 |
|
---|
[3623] | 140 | inline UInt32 FrameCounter() {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
|
---|
[3592] | 141 | inline UInt32 TimeTag1() {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
|
---|
| 142 | inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
|
---|
[3635] | 143 | inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFULL);}
|
---|
[3592] | 144 |
|
---|
| 145 | inline UInt32 PaqId() {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
|
---|
| 146 | inline UInt16 PaqLen() {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
|
---|
| 147 |
|
---|
[3623] | 148 | UInt16 ChannelID();
|
---|
| 149 | UInt16 ModeAcquisition();
|
---|
[3592] | 150 |
|
---|
| 151 | // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
|
---|
[3623] | 152 | // Fonctions utiles pour remplir un objet BRPaquet
|
---|
| 153 | void SetHDRMarker64(UInt64 htag);
|
---|
| 154 | void SetTRLMarker64(UInt64 ttag);
|
---|
| 155 | void SetFrameCounter(UInt32 fc);
|
---|
| 156 | void SetTimeTag(UInt64 timtag);
|
---|
| 157 | inline void SetPaqLen(UInt16 len) { *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET))) = len; }
|
---|
[3592] | 158 |
|
---|
[3537] | 159 | // pour faire un print de la structure
|
---|
[3623] | 160 | ostream& Print(ostream & os, int nelt=8, bool prht=true);
|
---|
| 161 | inline ostream& Print(int nelt=8, bool prht=true)
|
---|
| 162 | { return Print(cout, nelt, prht); }
|
---|
[3537] | 163 |
|
---|
[3592] | 164 | // fonction appelee par le constructeur pour reordonner les donnees FFT
|
---|
| 165 | static void ReorderFFTData(Byte* src, Byte* dst, int sz);
|
---|
| 166 | static void ReorderFFTData32(Byte* src, Byte* dst, int sz);
|
---|
| 167 | static void ReorderFFTDataNoSwap(Byte* src, Byte* dst, int sz);
|
---|
| 168 | static const char* FmtConvToString(BRDataFmtConv fgswap);
|
---|
| 169 | // protected:
|
---|
[3537] | 170 | // donnees membres
|
---|
| 171 | int sz_; //taille du paquet
|
---|
| 172 | Byte* dst_;
|
---|
| 173 | };
|
---|
| 174 |
|
---|
[3592] | 175 | // --------------------------------------------------------------------------
|
---|
| 176 | // Classe pour effectuer des verifications d'integrite sur les paquets/frames
|
---|
| 177 | // --------------------------------------------------------------------------
|
---|
| 178 |
|
---|
| 179 | class BRPaqChecker {
|
---|
| 180 | public:
|
---|
| 181 | BRPaqChecker();
|
---|
| 182 | ~BRPaqChecker();
|
---|
[3623] | 183 |
|
---|
| 184 | UInt64 DefineHDRTag(UInt32 hdr1=0x76543210, UInt32 hdr2=0xFEDCBA98);
|
---|
| 185 | UInt64 DefineTRLTag(UInt32 trl1=0x55555555, UInt32 trl2=0xAAAAAAAA);
|
---|
| 186 |
|
---|
| 187 | inline UInt64 HDRTag() { return hdrtag_; }
|
---|
| 188 | inline UInt64 TRLTag() { return trltag_; }
|
---|
| 189 |
|
---|
[3592] | 190 | // Verifie le paquet, renvoie true si OK
|
---|
| 191 | bool Check(BRPaquet& paq);
|
---|
| 192 | // Imprime le compte de paquets ...
|
---|
| 193 | ostream & Print(ostream& os);
|
---|
| 194 |
|
---|
| 195 | unsigned long long totnframes; // Nombre totale de frames/paquets traites
|
---|
| 196 | unsigned long long nframeok; // Nombre totale de frames/paquets avec HDR/TRL OK
|
---|
| 197 | unsigned long long lostframes; // Nombre totale de frames/paquets perdus
|
---|
| 198 | unsigned int frclst; // derniere valeur du frame-counter
|
---|
[3623] | 199 |
|
---|
| 200 | UInt64 hdrtag_;
|
---|
| 201 | UInt64 trltag_;
|
---|
[3592] | 202 | };
|
---|
| 203 |
|
---|
[3537] | 204 | #endif
|
---|
[3592] | 205 |
|
---|
| 206 |
|
---|