| 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
 | 
|---|
| 29 | #define MAXNBFIB  32  
 | 
|---|
| 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
 | 
|---|
| 42 | #ifndef BRTCPMSGLEN2
 | 
|---|
| 43 | #define BRTCPMSGLEN2 64
 | 
|---|
| 44 | #endif
 | 
|---|
| 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:
 | 
|---|
| 53 |   PCIEToEthernet(vector<PCIEWrapperInterface*> vec_pciw , vector<string>& destname, BRParList const& par, int portid=BRSPORTID);
 | 
|---|
| 54 |   virtual ~PCIEToEthernet();
 | 
|---|
| 55 |   virtual void run(); 
 | 
|---|
| 56 |    void Stop();
 | 
|---|
| 57 |   inline void STOP() { stop_ = true; }  
 | 
|---|
| 58 | 
 | 
|---|
| 59 |   inline int SetPrintLevel(int lev=0, uint_8 prtmodulo=50000) 
 | 
|---|
| 60 |     { prtlev_=lev;   prtmodulo_=prtmodulo;  return 0; }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | protected: 
 | 
|---|
| 63 |   virtual size_t SendToTargets(int fib, Byte* data, size_t len, bool fgfin=false);
 | 
|---|
| 64 |   virtual void CleanUpEndSendAllLinks();
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   BRParList par_;   // Parametres divers d'acquisition 
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   uint_8 nmaxpaq_;  // Nombre maxi de paquets traites - DOIT etre mutiple de mmgr.NbPaquets()
 | 
|---|
| 69 |   BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
 | 
|---|
| 70 |   bool stop_;  
 | 
|---|
| 71 |   unsigned int sizeFr_ ;
 | 
|---|
| 72 |   vector<PCIEWrapperInterface *> vec_pciw_;
 | 
|---|
| 73 |   vector<string> destname_; 
 | 
|---|
| 74 |   int tcpportid_;
 | 
|---|
| 75 |   vector< vector<ClientSocket> > vvec_skt_;
 | 
|---|
| 76 |   vector< vector<uint_8> > vvec_errorcnt_;
 | 
|---|
| 77 |   vector< uint_8 > vec_cntpaq_; 
 | 
|---|
| 78 |   vector< bool > vfgmsgfin_;   // true -> message fin envoye pour la fibre correspondante  
 | 
|---|
| 79 |   uint_4 packSize_;
 | 
|---|
| 80 |   uint_4 packSizeInMgr_;
 | 
|---|
| 81 |   uint_4 nbDma_;
 | 
|---|
| 82 |   uint_8 totrdsnd_;
 | 
|---|
| 83 |   bool fgdirectsend_;  //  true -> direct transfer of DMA data to ethernet
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   string stopreason_;   // message descriptif de la raison d'arret 
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   int prtlev_;    // print level 
 | 
|---|
| 88 |   uint_8 prtmodulo_;   // print periodicity (modulo) 
 | 
|---|
| 89 | };
 | 
|---|
| 90 | 
 | 
|---|
| 91 | //------------------------------------------------------------------
 | 
|---|
| 92 | // Classe thread de lecture sur interface reseau (Ethernet) 
 | 
|---|
| 93 | //------------------------------------------------------------------
 | 
|---|
| 94 | class EthernetReader : public ZThread {
 | 
|---|
| 95 | public:
 | 
|---|
| 96 |   EthernetReader(RAcqMemZoneMgr& mem, BRParList const& par, int portid=BRSPORTID);
 | 
|---|
| 97 |   virtual ~EthernetReader(); 
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   // Configuration du mode de lecture des paquets 
 | 
|---|
| 100 |   // Si force_samefc=true, on essaye de lire des paquets avec meme FrameCounter, sans depasser une 
 | 
|---|
| 101 |   // difference maximum de maxdiff_paqnum entre nombre de paquets lus sur chaque fibre
 | 
|---|
| 102 |   //  - force_samefc=false : lecture des paquet sans alignement des FrameCounter 
 | 
|---|
| 103 |   //  - force_samefc=true : lecture paquets avec alignement des FrameCounter
 | 
|---|
| 104 |   //     + mode par defaut : maxdiff_paqnum=0, maxresync=0 -> on cherche a aligner FrameCounter sur les 
 | 
|---|
| 105 |   //     differents liens ethernet 
 | 
|---|
| 106 |   //     + maxdiff_paqnum>0 : difference maximum de nombre de paquets entre les differents liens
 | 
|---|
| 107 |   //     + maxresync>0 : Mode de lecture avec resynchronisation du nombre de paquets , nombre 
 | 
|---|
| 108 |   //       maxi de resynchronisation - 
 | 
|---|
| 109 |   //  Modes conseilles : false   -  true,0,0  - true,10,0        
 | 
|---|
| 110 |   inline void SetReadMode(bool force_samefc=false, uint_4 maxdiff_paqnum=0, uint_4 maxresync=0)
 | 
|---|
| 111 |   { rdsamefc_=force_samefc; sfc_maxdpc_=maxdiff_paqnum; sfc_maxresync_=maxresync; }
 | 
|---|
| 112 |   //  En activant le flag, le reader ne se termine qu'avec la reception des message END sur chaque lien 
 | 
|---|
| 113 |   inline void WaitENDMsg4Terminate(bool waitendmsg=false) 
 | 
|---|
| 114 |   { waitendmsg_=waitendmsg; }
 | 
|---|
| 115 | 
 | 
|---|
| 116 |   virtual void run();
 | 
|---|
| 117 |   inline void Stop() { stop_ = true; }
 | 
|---|
| 118 |   inline void STOP() { stop_ = true; }  
 | 
|---|
| 119 | 
 | 
|---|
| 120 |   inline int SetPrintLevel(int lev=0, uint_8 prtmodulo=50000) 
 | 
|---|
| 121 |     { prtlev_=lev;   prtmodulo_=prtmodulo;  return 0; }
 | 
|---|
| 122 | 
 | 
|---|
| 123 | protected:
 | 
|---|
| 124 |   bool ReadNextAllFibers();      // Renvoie true si probleme 
 | 
|---|
| 125 |   bool ReadNext(int fib);   // Renvoie true si probleme 
 | 
|---|
| 126 |   void CleanUpAllSockets();  // pour finir la lecture de toutes les fibres 
 | 
|---|
| 127 |   size_t ReceiveFromSocket(int fib, char* data, size_t len);
 | 
|---|
| 128 | 
 | 
|---|
| 129 |   bool ReadNextAllFibersWithSync();      // Renvoie true si probleme 
 | 
|---|
| 130 | // recale les links en cas d'ecart important entre nb de paquets lu sur chaque lien
 | 
|---|
| 131 |   int SkipAndSyncLinks();   // Renvoie 0 si rien fait, 1 si skip fait, 9 si probleme  
 | 
|---|
| 132 | 
 | 
|---|
| 133 |   // Permet d'avancer d'un paquet dans la zone - renvoie true si probleme
 | 
|---|
| 134 |   inline bool MoveToNextTarget()  {
 | 
|---|
| 135 |     if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) 
 | 
|---|
| 136 |       if (MZoneManage()) return true;
 | 
|---|
| 137 |     targ_npaq_++;
 | 
|---|
| 138 |     return false;
 | 
|---|
| 139 |   }
 | 
|---|
| 140 |   inline Byte* GetPaquetTarget(int numfib)  {
 | 
|---|
| 141 |     if ((mmbufib_[numfib] == NULL )||(targ_npaq_ > max_targ_npaq)||(targ_npaq_ == 0))  return NULL; 
 | 
|---|
| 142 |     Byte* rb=mmbufib_[numfib]+(targ_npaq_-1)*packsize_;
 | 
|---|
| 143 |     return rb;
 | 
|---|
| 144 |   }
 | 
|---|
| 145 |   bool MZoneManage(bool clean=false);  // Renvoie true si probleme
 | 
|---|
| 146 | 
 | 
|---|
| 147 |   RAcqMemZoneMgr& memgr_;
 | 
|---|
| 148 |   BRParList par_;   // Parametres divers d'acquisition 
 | 
|---|
| 149 |   int tcpportid_;
 | 
|---|
| 150 |   ServerSocket* srv_sokp_;  // Le socket serveur  
 | 
|---|
| 151 |   vector< Socket > vsok_;  //  Les sockets de lecture pour chaque lien ethernet (1 lien= 1 fibre a l'envoi) 
 | 
|---|
| 152 |   vector< int > vfibid_;   //  Identificateur des fibres transmis par l'emetteur 
 | 
|---|
| 153 |   vector< uint_8 > vec_cntpaq_;   // vecteur de compteurs de paquet ( 1 compteur / lien ) 
 | 
|---|
| 154 |   vector< uint_4 > vec_fgsokend_;    // vecteur de flag, >0 : fin de reception (ou ereur) sur le lien 
 | 
|---|
| 155 |   bool gl_fgsokend;          // true -> au moins l'un de liens a termine 
 | 
|---|
| 156 |   bool stop_;
 | 
|---|
| 157 |   bool rdsamefc_;  // if true, read paquets with same value of FrameCounter on different fibers/link 
 | 
|---|
| 158 |   uint_4 sfc_maxdpc_;   // difference maxi entre nombre de paquets lu sur les liens 
 | 
|---|
| 159 |   uint_4 sfc_maxresync_;  // nb maximum de tentatives de resynchronisation 
 | 
|---|
| 160 | 
 | 
|---|
| 161 |   uint_8 totnbytesrd_;
 | 
|---|
| 162 |   uint_8 totnpaqrd_;
 | 
|---|
| 163 |   uint_8 totsamefc_;   // nombre total de paquets avec meme framecounter  
 | 
|---|
| 164 | 
 | 
|---|
| 165 |   uint_8 totnbresync_;   // nombre total de saut+resynchronisation 
 | 
|---|
| 166 | 
 | 
|---|
| 167 |   vector<BRPaquet> vpaq_; 
 | 
|---|
| 168 |   vector<BRPaqChecker> vpchk_;
 | 
|---|
| 169 |   vector<uint_8> curfc_;       // Numeros des FrameCounter des paquets courants
 | 
|---|
| 170 |   vector<uint_8> totnpqrd_;    // nombre total de paquets lus / lien 
 | 
|---|
| 171 |   vector<uint_8> totnpqok_;    // nombre total de paquets OK / lien   
 | 
|---|
| 172 | 
 | 
|---|
| 173 |   uint_4 packsize_;
 | 
|---|
| 174 |   int mid_;  // Identificateur zone memoire
 | 
|---|
| 175 |   uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire 
 | 
|---|
| 176 |   uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
 | 
|---|
| 177 |   Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr 
 | 
|---|
| 178 |   Byte* mmbufib_[MAXANAFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr 
 | 
|---|
| 179 | 
 | 
|---|
| 180 |   // zone tampon contenant zero si lecture sur fibre est fini 
 | 
|---|
| 181 |   char* dummybuff_;
 | 
|---|
| 182 |   string stopreason_;   // message descriptif de la raison d'arret 
 | 
|---|
| 183 | 
 | 
|---|
| 184 |   bool waitendmsg_;   // si true, attendre le message  END message sur chaque lien avant de s'arreter 
 | 
|---|
| 185 |  
 | 
|---|
| 186 |   int prtlev_;   // print level 
 | 
|---|
| 187 |   uint_8 prtmodulo_;   // print periodicity (modulo) 
 | 
|---|
| 188 | };
 | 
|---|
| 189 | 
 | 
|---|
| 190 | 
 | 
|---|
| 191 | 
 | 
|---|
| 192 | #endif
 | 
|---|