| [3757] | 1 | #ifndef  RACQUETH_H_SEEN
 | 
|---|
 | 2 | #define  RACQUETH_H_SEEN
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | //----------------------------------------------------------------
 | 
|---|
 | 5 | // ---- classes de threads pour lecture/ecriture des paquets (transfert DMA) 
 | 
|---|
 | 6 | //      et ecriture disque pour acquisition   BAORadio       -----
 | 
|---|
 | 7 | // LAL -      R. Ansari - Juin/Juillet 2008 
 | 
|---|
 | 8 | //----------------------------------------------------------------
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include "racqumem.h"
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | #include <vector>
 | 
|---|
 | 13 | #include <iostream>
 | 
|---|
 | 14 | #include "sopnamsp.h"
 | 
|---|
 | 15 | #include "zthread.h"
 | 
|---|
 | 16 | #include "pciewrap.h"
 | 
|---|
 | 17 | #include "swrapsock.h"
 | 
|---|
 | 18 | #include "brtypes.h"
 | 
|---|
 | 19 | #include "brpaqu.h"
 | 
|---|
 | 20 | #include "brparam.h"
 | 
|---|
 | 21 | #include "minifits.h"
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | using namespace std;
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | // Quelques definitions globales
 | 
|---|
 | 26 | // Nombre maximum de fibres geres par les classes PCIEToEthernet ...
 | 
|---|
 | 27 | //  ATTENTION cette definition (MAXANAFIB) se trouve dans plusieurs fichiers 
 | 
|---|
 | 28 | #ifndef MAXNBFIB
 | 
|---|
| [3775] | 29 | #define MAXNBFIB  32  
 | 
|---|
| [3757] | 30 | #endif
 | 
|---|
 | 31 | //  ATTENTION cette definition (MAXANAFIB) se trouve dans plusieurs fichiers 
 | 
|---|
 | 32 | #ifndef MAXANAFIB 
 | 
|---|
 | 33 | #define MAXANAFIB  32
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | #ifndef BRSPORTID
 | 
|---|
 | 37 | #define BRSPORTID 6912
 | 
|---|
 | 38 | #endif
 | 
|---|
 | 39 | #ifndef BRTCPMSGLEN
 | 
|---|
 | 40 | #define BRTCPMSGLEN 128
 | 
|---|
 | 41 | #endif
 | 
|---|
| [3762] | 42 | #ifndef BRTCPMSGLEN2
 | 
|---|
 | 43 | #define BRTCPMSGLEN2 64
 | 
|---|
 | 44 | #endif
 | 
|---|
| [3757] | 45 | 
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | //----------------------------------------------------------------------------------
 | 
|---|
 | 48 | // Classe thread de lecture PCI-Express et recopie sur interface reseau (Ethernet)
 | 
|---|
 | 49 | //----------------------------------------------------------------------------------
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | class PCIEToEthernet : public ZThread {
 | 
|---|
 | 52 | public:
 | 
|---|
| [3913] | 53 |   // Specification de destinations : nom_de_machine ou numero IP (192.168.55.2 ...)
 | 
|---|
 | 54 |   //  Meme series de destination pour toutes les fibres (DMA) 
 | 
|---|
 | 55 |   PCIEToEthernet(vector<PCIEWrapperInterface*> vec_pciw, vector<string>& destname, BRParList const& par, int portid=BRSPORTID);
 | 
|---|
 | 56 |   //  Une serie  de destinations pour chaque fibres
 | 
|---|
 | 57 |   PCIEToEthernet(vector<PCIEWrapperInterface*> vec_pciw, vector< vector<string> >& destname, BRParList const& par, int portid=BRSPORTID);
 | 
|---|
| [3757] | 58 |   virtual ~PCIEToEthernet();
 | 
|---|
 | 59 |   virtual void run(); 
 | 
|---|
 | 60 |    void Stop();
 | 
|---|
 | 61 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 62 | 
 | 
|---|
| [3883] | 63 |   inline int SetPrintLevel(int lev=0, uint_8 prtmodulo=50000) 
 | 
|---|
 | 64 |     { prtlev_=lev;   prtmodulo_=prtmodulo;  return 0; }
 | 
|---|
| [3759] | 65 | 
 | 
|---|
| [3757] | 66 | protected: 
 | 
|---|
| [3913] | 67 |   virtual void InitConnections();
 | 
|---|
| [3909] | 68 |   virtual size_t SendToTargets(int fib, Byte* data, size_t len, bool fgfin=false);
 | 
|---|
 | 69 |   virtual void CleanUpEndSendAllLinks();
 | 
|---|
| [3758] | 70 | 
 | 
|---|
| [3757] | 71 |   BRParList par_;   // Parametres divers d'acquisition 
 | 
|---|
 | 72 | 
 | 
|---|
| [3897] | 73 |   uint_8 nmaxpaq_;  // Nombre maxi de paquets traites - DOIT etre mutiple de mmgr.NbPaquets()
 | 
|---|
| [3757] | 74 |   BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
 | 
|---|
 | 75 |   bool stop_;  
 | 
|---|
 | 76 |   unsigned int sizeFr_ ;
 | 
|---|
 | 77 |   vector<PCIEWrapperInterface *> vec_pciw_;
 | 
|---|
| [3913] | 78 |   vector< vector<string> > destname_; 
 | 
|---|
| [3757] | 79 |   int tcpportid_;
 | 
|---|
 | 80 |   vector< vector<ClientSocket> > vvec_skt_;
 | 
|---|
| [3897] | 81 |   vector< vector<uint_8> > vvec_errorcnt_;
 | 
|---|
 | 82 |   vector< uint_8 > vec_cntpaq_; 
 | 
|---|
| [3909] | 83 |   vector< bool > vfgmsgfin_;   // true -> message fin envoye pour la fibre correspondante  
 | 
|---|
| [3757] | 84 |   uint_4 packSize_;
 | 
|---|
 | 85 |   uint_4 packSizeInMgr_;
 | 
|---|
 | 86 |   uint_4 nbDma_;
 | 
|---|
| [3758] | 87 |   uint_8 totrdsnd_;
 | 
|---|
| [3762] | 88 |   bool fgdirectsend_;  //  true -> direct transfer of DMA data to ethernet
 | 
|---|
| [3764] | 89 | 
 | 
|---|
| [3911] | 90 |   string stopreason_;   // message descriptif de la raison d'arret 
 | 
|---|
 | 91 | 
 | 
|---|
| [3883] | 92 |   int prtlev_;    // print level 
 | 
|---|
 | 93 |   uint_8 prtmodulo_;   // print periodicity (modulo) 
 | 
|---|
| [3757] | 94 | };
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | //------------------------------------------------------------------
 | 
|---|
 | 97 | // Classe thread de lecture sur interface reseau (Ethernet) 
 | 
|---|
 | 98 | //------------------------------------------------------------------
 | 
|---|
 | 99 | class EthernetReader : public ZThread {
 | 
|---|
 | 100 | public:
 | 
|---|
| [3897] | 101 |   EthernetReader(RAcqMemZoneMgr& mem, BRParList const& par, int portid=BRSPORTID);
 | 
|---|
 | 102 |   virtual ~EthernetReader(); 
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 |   // Configuration du mode de lecture des paquets 
 | 
|---|
 | 105 |   // Si force_samefc=true, on essaye de lire des paquets avec meme FrameCounter, sans depasser une 
 | 
|---|
 | 106 |   // difference maximum de maxdiff_paqnum entre nombre de paquets lus sur chaque fibre
 | 
|---|
| [3909] | 107 |   //  - force_samefc=false : lecture des paquet sans alignement des FrameCounter 
 | 
|---|
 | 108 |   //  - force_samefc=true : lecture paquets avec alignement des FrameCounter
 | 
|---|
 | 109 |   //     + mode par defaut : maxdiff_paqnum=0, maxresync=0 -> on cherche a aligner FrameCounter sur les 
 | 
|---|
 | 110 |   //     differents liens ethernet 
 | 
|---|
 | 111 |   //     + maxdiff_paqnum>0 : difference maximum de nombre de paquets entre les differents liens
 | 
|---|
 | 112 |   //     + maxresync>0 : Mode de lecture avec resynchronisation du nombre de paquets , nombre 
 | 
|---|
 | 113 |   //       maxi de resynchronisation - 
 | 
|---|
 | 114 |   //  Modes conseilles : false   -  true,0,0  - true,10,0        
 | 
|---|
| [3901] | 115 |   inline void SetReadMode(bool force_samefc=false, uint_4 maxdiff_paqnum=0, uint_4 maxresync=0)
 | 
|---|
| [3897] | 116 |   { rdsamefc_=force_samefc; sfc_maxdpc_=maxdiff_paqnum; sfc_maxresync_=maxresync; }
 | 
|---|
| [3899] | 117 |   //  En activant le flag, le reader ne se termine qu'avec la reception des message END sur chaque lien 
 | 
|---|
 | 118 |   inline void WaitENDMsg4Terminate(bool waitendmsg=false) 
 | 
|---|
 | 119 |   { waitendmsg_=waitendmsg; }
 | 
|---|
| [3897] | 120 | 
 | 
|---|
| [3757] | 121 |   virtual void run();
 | 
|---|
 | 122 |   inline void Stop() { stop_ = true; }
 | 
|---|
 | 123 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 124 | 
 | 
|---|
| [3883] | 125 |   inline int SetPrintLevel(int lev=0, uint_8 prtmodulo=50000) 
 | 
|---|
 | 126 |     { prtlev_=lev;   prtmodulo_=prtmodulo;  return 0; }
 | 
|---|
| [3759] | 127 | 
 | 
|---|
| [3757] | 128 | protected:
 | 
|---|
 | 129 |   bool ReadNextAllFibers();      // Renvoie true si probleme 
 | 
|---|
 | 130 |   bool ReadNext(int fib);   // Renvoie true si probleme 
 | 
|---|
| [3897] | 131 |   void CleanUpAllSockets();  // pour finir la lecture de toutes les fibres 
 | 
|---|
| [3759] | 132 |   size_t ReceiveFromSocket(int fib, char* data, size_t len);
 | 
|---|
 | 133 | 
 | 
|---|
| [3901] | 134 |   bool ReadNextAllFibersWithSync();      // Renvoie true si probleme 
 | 
|---|
| [3897] | 135 | // recale les links en cas d'ecart important entre nb de paquets lu sur chaque lien
 | 
|---|
 | 136 |   int SkipAndSyncLinks();   // Renvoie 0 si rien fait, 1 si skip fait, 9 si probleme  
 | 
|---|
 | 137 | 
 | 
|---|
| [3757] | 138 |   // Permet d'avancer d'un paquet dans la zone - renvoie true si probleme
 | 
|---|
 | 139 |   inline bool MoveToNextTarget()  {
 | 
|---|
 | 140 |     if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) 
 | 
|---|
 | 141 |       if (MZoneManage()) return true;
 | 
|---|
 | 142 |     targ_npaq_++;
 | 
|---|
 | 143 |     return false;
 | 
|---|
 | 144 |   }
 | 
|---|
 | 145 |   inline Byte* GetPaquetTarget(int numfib)  {
 | 
|---|
 | 146 |     if ((mmbufib_[numfib] == NULL )||(targ_npaq_ > max_targ_npaq)||(targ_npaq_ == 0))  return NULL; 
 | 
|---|
 | 147 |     Byte* rb=mmbufib_[numfib]+(targ_npaq_-1)*packsize_;
 | 
|---|
 | 148 |     return rb;
 | 
|---|
 | 149 |   }
 | 
|---|
 | 150 |   bool MZoneManage(bool clean=false);  // Renvoie true si probleme
 | 
|---|
 | 151 | 
 | 
|---|
 | 152 |   RAcqMemZoneMgr& memgr_;
 | 
|---|
 | 153 |   BRParList par_;   // Parametres divers d'acquisition 
 | 
|---|
 | 154 |   int tcpportid_;
 | 
|---|
| [3897] | 155 |   ServerSocket* srv_sokp_;  // Le socket serveur  
 | 
|---|
 | 156 |   vector< Socket > vsok_;  //  Les sockets de lecture pour chaque lien ethernet (1 lien= 1 fibre a l'envoi) 
 | 
|---|
| [3909] | 157 |   vector< int > vfibid_;   //  Identificateur des fibres transmis par l'emetteur 
 | 
|---|
| [3897] | 158 |   vector< uint_8 > vec_cntpaq_;   // vecteur de compteurs de paquet ( 1 compteur / lien ) 
 | 
|---|
 | 159 |   vector< uint_4 > vec_fgsokend_;    // vecteur de flag, >0 : fin de reception (ou ereur) sur le lien 
 | 
|---|
 | 160 |   bool gl_fgsokend;          // true -> au moins l'un de liens a termine 
 | 
|---|
| [3757] | 161 |   bool stop_;
 | 
|---|
 | 162 |   bool rdsamefc_;  // if true, read paquets with same value of FrameCounter on different fibers/link 
 | 
|---|
| [3897] | 163 |   uint_4 sfc_maxdpc_;   // difference maxi entre nombre de paquets lu sur les liens 
 | 
|---|
 | 164 |   uint_4 sfc_maxresync_;  // nb maximum de tentatives de resynchronisation 
 | 
|---|
 | 165 | 
 | 
|---|
| [3757] | 166 |   uint_8 totnbytesrd_;
 | 
|---|
 | 167 |   uint_8 totnpaqrd_;
 | 
|---|
 | 168 |   uint_8 totsamefc_;   // nombre total de paquets avec meme framecounter  
 | 
|---|
 | 169 | 
 | 
|---|
| [3897] | 170 |   uint_8 totnbresync_;   // nombre total de saut+resynchronisation 
 | 
|---|
 | 171 | 
 | 
|---|
| [3757] | 172 |   vector<BRPaquet> vpaq_; 
 | 
|---|
 | 173 |   vector<BRPaqChecker> vpchk_;
 | 
|---|
 | 174 |   vector<uint_8> curfc_;       // Numeros des FrameCounter des paquets courants
 | 
|---|
 | 175 |   vector<uint_8> totnpqrd_;    // nombre total de paquets lus / lien 
 | 
|---|
 | 176 |   vector<uint_8> totnpqok_;    // nombre total de paquets OK / lien   
 | 
|---|
 | 177 | 
 | 
|---|
 | 178 |   uint_4 packsize_;
 | 
|---|
 | 179 |   int mid_;  // Identificateur zone memoire
 | 
|---|
 | 180 |   uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire 
 | 
|---|
 | 181 |   uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
 | 
|---|
 | 182 |   Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr 
 | 
|---|
 | 183 |   Byte* mmbufib_[MAXANAFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr 
 | 
|---|
 | 184 | 
 | 
|---|
| [3897] | 185 |   // zone tampon contenant zero si lecture sur fibre est fini 
 | 
|---|
 | 186 |   char* dummybuff_;
 | 
|---|
| [3898] | 187 |   string stopreason_;   // message descriptif de la raison d'arret 
 | 
|---|
| [3897] | 188 | 
 | 
|---|
| [3899] | 189 |   bool waitendmsg_;   // si true, attendre le message  END message sur chaque lien avant de s'arreter 
 | 
|---|
 | 190 |  
 | 
|---|
| [3883] | 191 |   int prtlev_;   // print level 
 | 
|---|
 | 192 |   uint_8 prtmodulo_;   // print periodicity (modulo) 
 | 
|---|
| [3757] | 193 | };
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 | 
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 | #endif
 | 
|---|