39 #include <boost/date_time/posix_time/posix_time_types.hpp> 40 #include <boost/shared_ptr.hpp> 41 #include <boost/thread/lock_guard.hpp> 48 #include "uhal/log/log.hpp" 56 template< u
int8_t IPbus_minor >
65 template< u
int8_t IPbus_minor >
70 template< u
int8_t IPbus_minor >
76 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() );
106 template< u
int8_t IPbus_minor >
109 uint8_t lType ( 0x00 );
139 exception::ValidationError lExc;
140 log ( lExc ,
"Configuration space read undefined in IPbus version 1" );
145 return ( 0x10000000 | ( ( aTransactionId&0x7ff ) <<17 ) | ( ( aWordCount&0x1ff ) <<8 ) | lType | ( aInfoCode&0x7 ) );
149 template< u
int8_t IPbus_minor >
155 template< u
int8_t IPbus_minor >
158 uint32_t lProtocolVersion ( ( aHeader >> 28 ) & 0xF );
160 if ( lProtocolVersion != 1 )
162 log (
Error() ,
"Wrong Protocol Version! " ,
Integer ( lProtocolVersion ) ,
" != 1" );
166 switch ( aHeader & 0xF8 )
197 aWordCount = ( aHeader >> 8 ) & 0x1ff;
198 aTransactionId = ( aHeader >> 17 ) & 0x7ff;
199 aInfoCode = aHeader & 0x3;
203 template< u
int8_t IPbus_minor >
209 template< u
int8_t IPbus_minor >
215 template< u
int8_t IPbus_minor >
222 template< u
int8_t IPbus_minor >
226 aStream <<
"success";
229 aStream <<
"partial";
232 aStream <<
"failure";
235 aStream <<
"UNKNOWN";
243 template< u
int8_t IPbus_minor >
247 #ifndef DISABLE_PACKET_COUNTER_HACK
257 template< u
int8_t IPbus_minor >
262 template< u
int8_t IPbus_minor >
265 aBuffers->send ( 0x200000F0 | ( ( mPacketCounter&0xffff ) <<8 ) );
266 #ifndef DISABLE_PACKET_COUNTER_HACK 270 boost::lock_guard<boost::mutex> lLock ( mReceivePacketMutex );
271 mReceivePacketHeader.push_back ( 0x00000000 );
272 aBuffers->receive ( mReceivePacketHeader.back() );
277 template< u
int8_t IPbus_minor >
284 template< u
int8_t IPbus_minor >
291 template< u
int8_t IPbus_minor >
293 uint8_t* aSendBufferEnd ,
294 std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyStartIt ,
295 std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyEndIt )
299 if ( * ( uint32_t* ) ( aSendBufferStart ) != * ( uint32_t* ) ( aReplyStartIt ->first ) )
301 uhal::exception::IPbus2PacketHeaderMismatch* lExc =
new uhal::exception::IPbus2PacketHeaderMismatch();
302 log ( *lExc ,
"Returned Packet Header from URI " ,
Quote ( this->
uri() ) ,
", " ,
Integer ( * ( uint32_t* ) ( aReplyStartIt ->first ) ,
IntFmt<hex,fixed>() ) ,
308 boost::lock_guard<boost::mutex> lLock ( mReceivePacketMutex );
309 mReceivePacketHeader.pop_front();
313 return IPbusCore::validate ( ( aSendBufferStart+=4 ) , aSendBufferEnd , ( ++aReplyStartIt ) , aReplyEndIt );
319 template< u
int8_t IPbus_minor >
322 uint8_t lType ( 0x00 );
328 exception::ValidationError lExc;
329 log ( lExc ,
"Byte-Order-Transaction undefined in IPbus version 2" );
355 exception::ValidationError lExc;
356 log ( lExc ,
"Reserved address information transaction is undefined in IPbus version 2" );
361 return ( 0x20000000 | ( ( aTransactionId&0xfff ) <<16 ) | ( ( aWordCount&0xff ) <<8 ) | lType | ( aInfoCode&0xF ) );
365 template< u
int8_t IPbus_minor >
372 template< u
int8_t IPbus_minor >
375 uint32_t lProtocolVersion ( ( aHeader >> 28 ) & 0xF );
377 if ( lProtocolVersion != 2 )
379 log (
Error() ,
"Wrong Protocol Version! " ,
Integer ( lProtocolVersion ) ,
" != 2" );
383 switch ( aHeader & 0xF0 )
411 aWordCount = ( aHeader >> 8 ) & 0xff;
412 aTransactionId = ( aHeader >> 16 ) & 0xfff;
413 aInfoCode = aHeader & 0xf;
417 template< u
int8_t IPbus_minor >
423 template< u
int8_t IPbus_minor >
429 template< u
int8_t IPbus_minor >
433 #ifndef DISABLE_PACKET_COUNTER_HACK 438 mReceivePacketHeader.clear();
442 template< u
int8_t IPbus_minor >
447 aStream <<
"success";
450 aStream <<
"bad header";
453 aStream <<
"bus error on read";
456 aStream <<
"bus error on write";
459 aStream <<
"bus timeout on read";
462 aStream <<
"bus timeout on write";
465 aStream <<
"outbound request";
468 aStream <<
"UNKNOWN";
A class which provides the version-specific functionality for IPbus.
eIPbusTransactionType
Enumerated type to define the IPbus transaction type.
virtual void dispatchExceptionHandler()
Function which is called when an exception is thrown.
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
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...
Empty struct which acts as a dummy variable for passing the formatting information around...
_Quote< T > Quote(const T &aT)
A class providing the core IPbus packing functionality.
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
Struct to store a URI when parsed by boost spirit.