| 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); | 
|---|
| 64 |  | 
|---|
| 65 | BRParList par_;   // Parametres divers d'acquisition | 
|---|
| 66 |  | 
|---|
| 67 | uint_8 nmaxpaq_;  // Nombre maxi de paquets traites | 
|---|
| 68 | BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet | 
|---|
| 69 | bool stop_; | 
|---|
| 70 | unsigned int sizeFr_ ; | 
|---|
| 71 | vector<PCIEWrapperInterface *> vec_pciw_; | 
|---|
| 72 | vector<string> destname_; | 
|---|
| 73 | int tcpportid_; | 
|---|
| 74 | vector< vector<ClientSocket> > vvec_skt_; | 
|---|
| 75 | vector< uint_4 > vec_cntpaq_; | 
|---|
| 76 | uint_4 packSize_; | 
|---|
| 77 | uint_4 packSizeInMgr_; | 
|---|
| 78 | uint_4 nbDma_; | 
|---|
| 79 | uint_8 totrdsnd_; | 
|---|
| 80 | bool fgdirectsend_;  //  true -> direct transfer of DMA data to ethernet | 
|---|
| 81 |  | 
|---|
| 82 | int prtlev_;    // print level | 
|---|
| 83 | uint_8 prtmodulo_;   // print periodicity (modulo) | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | //------------------------------------------------------------------ | 
|---|
| 87 | // Classe thread de lecture sur interface reseau (Ethernet) | 
|---|
| 88 | //------------------------------------------------------------------ | 
|---|
| 89 | class EthernetReader : public ZThread { | 
|---|
| 90 | public: | 
|---|
| 91 | EthernetReader(RAcqMemZoneMgr& mem, BRParList const& par, int portid=BRSPORTID, bool rdsamefc=false); | 
|---|
| 92 | virtual void run(); | 
|---|
| 93 | inline void Stop() { stop_ = true; } | 
|---|
| 94 | inline void STOP() { stop_ = true; } | 
|---|
| 95 |  | 
|---|
| 96 | inline int SetPrintLevel(int lev=0, uint_8 prtmodulo=50000) | 
|---|
| 97 | { prtlev_=lev;   prtmodulo_=prtmodulo;  return 0; } | 
|---|
| 98 |  | 
|---|
| 99 | protected: | 
|---|
| 100 | bool ReadNextAllFibers();      // Renvoie true si probleme | 
|---|
| 101 | bool ReadNext(int fib);   // Renvoie true si probleme | 
|---|
| 102 | size_t ReceiveFromSocket(int fib, char* data, size_t len); | 
|---|
| 103 |  | 
|---|
| 104 | // Permet d'avancer d'un paquet dans la zone - renvoie true si probleme | 
|---|
| 105 | inline bool MoveToNextTarget()  { | 
|---|
| 106 | if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) | 
|---|
| 107 | if (MZoneManage()) return true; | 
|---|
| 108 | targ_npaq_++; | 
|---|
| 109 | return false; | 
|---|
| 110 | } | 
|---|
| 111 | inline Byte* GetPaquetTarget(int numfib)  { | 
|---|
| 112 | if ((mmbufib_[numfib] == NULL )||(targ_npaq_ > max_targ_npaq)||(targ_npaq_ == 0))  return NULL; | 
|---|
| 113 | Byte* rb=mmbufib_[numfib]+(targ_npaq_-1)*packsize_; | 
|---|
| 114 | return rb; | 
|---|
| 115 | } | 
|---|
| 116 | bool MZoneManage(bool clean=false);  // Renvoie true si probleme | 
|---|
| 117 |  | 
|---|
| 118 | RAcqMemZoneMgr& memgr_; | 
|---|
| 119 | BRParList par_;   // Parametres divers d'acquisition | 
|---|
| 120 | int tcpportid_; | 
|---|
| 121 | vector< Socket > vsok_;  //  Les sockets de lecture pour chaque fibre/lien | 
|---|
| 122 | vector< uint_4 > vec_cntpaq_; | 
|---|
| 123 | bool stop_; | 
|---|
| 124 | bool rdsamefc_;  // if true, read paquets with same value of FrameCounter on different fibers/link | 
|---|
| 125 | uint_8 totnbytesrd_; | 
|---|
| 126 | uint_8 totnpaqrd_; | 
|---|
| 127 | uint_8 totsamefc_;   // nombre total de paquets avec meme framecounter | 
|---|
| 128 |  | 
|---|
| 129 | vector<BRPaquet> vpaq_; | 
|---|
| 130 | vector<BRPaqChecker> vpchk_; | 
|---|
| 131 | vector<uint_8> curfc_;       // Numeros des FrameCounter des paquets courants | 
|---|
| 132 | vector<uint_8> totnpqrd_;    // nombre total de paquets lus / lien | 
|---|
| 133 | vector<uint_8> totnpqok_;    // nombre total de paquets OK / lien | 
|---|
| 134 |  | 
|---|
| 135 | uint_4 packsize_; | 
|---|
| 136 | int mid_;  // Identificateur zone memoire | 
|---|
| 137 | uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire | 
|---|
| 138 | uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_ | 
|---|
| 139 | Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr | 
|---|
| 140 | Byte* mmbufib_[MAXANAFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr | 
|---|
| 141 |  | 
|---|
| 142 | int prtlev_;   // print level | 
|---|
| 143 | uint_8 prtmodulo_;   // print periodicity (modulo) | 
|---|
| 144 | }; | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 |  | 
|---|
| 148 | #endif | 
|---|