μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProtocolIPbus.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30---------------------------------------------------------------------------
31*/
32
39#ifndef _uhal_ProtocolIPbus_hpp_
40#define _uhal_ProtocolIPbus_hpp_
41
42
43#include <deque>
44#include <functional>
45#include <iosfwd>
46#include <memory>
47#include <stdint.h>
48#include <string>
49#include <utility>
50
52#include "uhal/ClientInterface.hpp" // for PacketLevelError
54
55
56namespace uhal
57{
58 class Buffers;
59 struct URI;
60
61
63 template< uint8_t IPbus_major , uint8_t IPbus_minor >
64 class IPbus;
65
66
68 template< uint8_t IPbus_minor >
69 class IPbus < 1 , IPbus_minor > : public IPbusCore
70 {
71
72 public:
78 IPbus ( const std::string& aId, const URI& aUri );
79
81 virtual ~IPbus();
82
83 protected:
85 virtual void preamble ( std::shared_ptr< Buffers > aBuffers );
86
88 virtual uint32_t getPreambleSize();
89
91 virtual void predispatch ( std::shared_ptr< Buffers > aBuffers );
92
93 public:
102 static uint32_t CalculateHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode = 0 );
103
112 static uint32_t ExpectedHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode = 0 );
113
123 static bool ExtractHeader ( const uint32_t& aHeader , IPbusTransactionType& aType , uint32_t& aWordCount , uint32_t& aTransactionId , uint8_t& aInfoCode );
124
125
126 protected:
127
136 uint32_t implementCalculateHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode );
137
147 bool implementExtractHeader ( const uint32_t& aHeader , IPbusTransactionType& aType , uint32_t& aWordCount , uint32_t& aTransactionId , uint8_t& aInfoCode );
148
151 {
152 return 0;
153 }
154
157 {
158 return 0x1ff;
159 }
160
161 virtual uint32_t getMaxNumberOfBuffers()
162 {
163 return 1;
164 }
165
166 virtual void dispatchExceptionHandler();
167
168 private:
169 std::function<void (std::ostream&, const uint8_t&)> getInfoCodeTranslator() { return translateInfoCode; }
170
171 static void translateInfoCode(std::ostream& aStream, const uint8_t& aErrorCode);
172 };
173
174
175
176 namespace exception
177 {
179 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( IPbus2PacketHeaderMismatch, PacketLevelError, "Exception class to handle the case where the IPbus 2.0 packet header does not match that sent." )
180 }
181
182
184 template< uint8_t IPbus_minor >
185 class IPbus < 2 , IPbus_minor > : public IPbusCore
186 {
187
188 public:
194 IPbus ( const std::string& aId, const URI& aUri );
195
197 virtual ~IPbus();
198
199 protected:
201 virtual void preamble ( std::shared_ptr< Buffers > aBuffers );
202
204 virtual uint32_t getPreambleSize();
205
207 virtual void predispatch ( std::shared_ptr< Buffers > aBuffers );
208
209 public:
218 static uint32_t CalculateHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode = 0 );
219
228 static uint32_t ExpectedHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode = 0 );
229
239 static bool ExtractHeader ( const uint32_t& aHeader , IPbusTransactionType& aType , uint32_t& aWordCount , uint32_t& aTransactionId , uint8_t& aInfoCode );
240
241
242 protected:
243
252 virtual exception::exception* validate ( uint8_t* aSendBufferStart ,
253 uint8_t* aSendBufferEnd ,
254 std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyStartIt ,
255 std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyEndIt );
256
265 uint32_t implementCalculateHeader ( const IPbusTransactionType& aType , const uint32_t& aWordCount , const uint32_t& aTransactionId , const uint8_t& aInfoCode );
266
276 bool implementExtractHeader ( const uint32_t& aHeader , IPbusTransactionType& aType , uint32_t& aWordCount , uint32_t& aTransactionId , uint8_t& aInfoCode );
277
280 {
281 return 0xF;
282 }
283
286 {
287 return 0xff;
288 }
289
290 virtual uint32_t getMaxNumberOfBuffers()
291 {
292 return 16;
293 }
294
295 virtual void dispatchExceptionHandler();
296
297 private:
298 std::function<void (std::ostream&, const uint8_t&)> getInfoCodeTranslator() { return translateInfoCode; }
299
300 static void translateInfoCode(std::ostream& aStream, const uint8_t& aErrorCode);
301
304
306 std::deque< uint32_t > mReceivePacketHeader;
307 };
308
309
310}
311
312
313#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Wraps a Python iterator so that it can also be used as a C++ input iterator
Definition: pytypes.h:1102
uint8_t requestTransactionInfoCode() const
Returns the InfoCode for request transactions in this IPbus version.
virtual uint32_t getMaxNumberOfBuffers()
Return the maximum number of packets in flight.
uint32_t getMaxTransactionWordCount() const
Returns the maximum value of the word count in the transaction header, for each IPbus version.
std::function< void(std::ostream &, const uint8_t &)> getInfoCodeTranslator()
uint32_t getMaxTransactionWordCount() const
Returns the maximum value of the word count in the transaction header, for each IPbus version.
uint8_t requestTransactionInfoCode() const
Returns the InfoCode for request transactions in this IPbus version.
virtual uint32_t getMaxNumberOfBuffers()
Return the maximum number of packets in flight.
std::function< void(std::ostream &, const uint8_t &)> getInfoCodeTranslator()
std::deque< uint32_t > mReceivePacketHeader
uint16_t mPacketCounter
The transaction counter which will be incremented in the sent IPbus headers.
A class providing the core IPbus packing functionality.
A class which provides the version-specific functionality for IPbus.
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
Definition: exception.hpp:71
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:49
IPbusTransactionType
Enumerated type to define the IPbus transaction type.
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50