41#include <boost/date_time/posix_time/posix_time_types.hpp>
55 template< u
int8_t IPbus_minor >
62 template< u
int8_t IPbus_minor >
68 template< u
int8_t IPbus_minor >
75 template< u
int8_t IPbus_minor >
82 template< u
int8_t IPbus_minor >
85 uint32_t lWords ( aBuffers->sendCounter() >> 2 );
87 int32_t lPaddingWords ( ( 7 + this->getPreambleSize() ) - lWords );
89 if ( lPaddingWords > 0 )
93 for ( int32_t lWords = 0 ; lWords != lPaddingWords ; ++lWords )
95 log (
Debug() ,
"Adding padding word." );
97 aBuffers->send ( CalculateHeader (
B_O_T , 0 , 0 ) );
98 std::pair < ValHeader , _ValHeader_* > lReply ( CreateValHeader() );
99 lReply.second->IPbusHeaders.push_back ( 0 );
100 aBuffers->add ( lReply.first );
101 aBuffers->receive ( lReply.second->IPbusHeaders.back() );
107 template< u
int8_t IPbus_minor >
110 uint8_t lType ( 0x00 );
140 exception::ValidationError lExc;
141 log ( lExc ,
"Configuration space read undefined in IPbus version 1" );
146 return ( 0x10000000 | ( ( aTransactionId&0x7ff ) <<17 ) | ( ( aWordCount&0x1ff ) <<8 ) | lType | ( aInfoCode&0x7 ) );
150 template< u
int8_t IPbus_minor >
157 template< u
int8_t IPbus_minor >
160 uint32_t lProtocolVersion ( ( aHeader >> 28 ) & 0xF );
162 if ( lProtocolVersion != 1 )
164 log (
Error() ,
"Wrong Protocol Version! " ,
Integer ( lProtocolVersion ) ,
" != 1" );
168 switch ( aHeader & 0xF8 )
199 aWordCount = ( aHeader >> 8 ) & 0x1ff;
200 aTransactionId = ( aHeader >> 17 ) & 0x7ff;
201 aInfoCode = aHeader & 0x3;
206 template< u
int8_t IPbus_minor >
213 template< u
int8_t IPbus_minor >
220 template< u
int8_t IPbus_minor >
227 template< u
int8_t IPbus_minor >
231 aStream <<
"success";
234 aStream <<
"partial";
237 aStream <<
"failure";
240 aStream <<
"UNKNOWN";
248 template< u
int8_t IPbus_minor >
256 template< u
int8_t IPbus_minor >
261 template< u
int8_t IPbus_minor >
264 aBuffers->send ( 0x200000F0 | ( ( mPacketCounter&0xffff ) <<8 ) );
266 std::lock_guard<std::mutex> lLock ( mReceivePacketMutex );
267 mReceivePacketHeader.push_back ( 0x00000000 );
268 aBuffers->receive ( mReceivePacketHeader.back() );
273 template< u
int8_t IPbus_minor >
280 template< u
int8_t IPbus_minor >
287 template< u
int8_t IPbus_minor >
289 uint8_t* aSendBufferEnd ,
290 std::deque< std::pair< uint8_t* , uint32_t > >
::iterator aReplyStartIt ,
291 std::deque< std::pair< uint8_t* , uint32_t > >
::iterator aReplyEndIt )
293 if ( * ( uint32_t* ) ( aSendBufferStart ) != * ( uint32_t* ) ( aReplyStartIt ->
first ) )
295 uhal::exception::IPbus2PacketHeaderMismatch* lExc =
new uhal::exception::IPbus2PacketHeaderMismatch();
302 std::lock_guard<std::mutex> lLock ( mReceivePacketMutex );
303 mReceivePacketHeader.pop_front();
306 return IPbusCore::validate ( ( aSendBufferStart+=4 ) , aSendBufferEnd , ( ++aReplyStartIt ) , aReplyEndIt );
312 template< u
int8_t IPbus_minor >
315 uint8_t lType ( 0x00 );
321 exception::ValidationError lExc;
322 log ( lExc ,
"Byte-Order-Transaction undefined in IPbus version 2" );
348 exception::ValidationError lExc;
349 log ( lExc ,
"Reserved address information transaction is undefined in IPbus version 2" );
354 return ( 0x20000000 | ( ( aTransactionId&0xfff ) <<16 ) | ( ( aWordCount&0xff ) <<8 ) | lType | ( aInfoCode&0xF ) );
358 template< u
int8_t IPbus_minor >
365 template< u
int8_t IPbus_minor >
368 uint32_t lProtocolVersion ( ( aHeader >> 28 ) & 0xF );
370 if ( lProtocolVersion != 2 )
372 log (
Error() ,
"Wrong Protocol Version! " ,
Integer ( lProtocolVersion ) ,
" != 2" );
376 switch ( aHeader & 0xF0 )
404 aWordCount = ( aHeader >> 8 ) & 0xff;
405 aTransactionId = ( aHeader >> 16 ) & 0xfff;
406 aInfoCode = aHeader & 0xf;
411 template< u
int8_t IPbus_minor >
418 template< u
int8_t IPbus_minor >
425 template< u
int8_t IPbus_minor >
429 mReceivePacketHeader.clear();
434 template< u
int8_t IPbus_minor >
439 aStream <<
"success";
442 aStream <<
"bad header";
445 aStream <<
"bus error on read";
448 aStream <<
"bus error on write";
451 aStream <<
"bus timeout on read";
454 aStream <<
"bus timeout on write";
457 aStream <<
"outbound request";
460 aStream <<
"UNKNOWN";
\rst Wraps a Python iterator so that it can also be used as a C++ input iterator
A class providing the core IPbus packing functionality.
virtual exception::exception * validate(uint8_t *aSendBufferStart, uint8_t *aSendBufferEnd, std::deque< std::pair< uint8_t *, uint32_t > >::iterator aReplyStartIt, std::deque< std::pair< uint8_t *, uint32_t > >::iterator aReplyEndIt)
Function which the transport protocol calls when the IPbus reply is received to check that the header...
virtual void dispatchExceptionHandler()
Function which is called when an exception is thrown.
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...
_Quote< T > Quote(const T &aT)
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
IPbusTransactionType
Enumerated type to define the IPbus transaction type.
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
constexpr int first(int i)
Implementation details for constexpr functions.
Empty struct which acts as a dummy variable for passing the formatting information around.
Struct to store a URI when parsed by boost spirit.