diff options
author | Josh Blum <josh@joshknows.com> | 2010-07-05 19:12:01 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-07-05 19:12:01 -0700 |
commit | a95eaac42f6cc85fd2ad3f32dc29eeab38ef5194 (patch) | |
tree | bc1a60e25496a3a1c3ff26f0fc2d3782b6ab191d /host/include | |
parent | c2039a8c92561fa5532d87cb9d875a3ad7b875c1 (diff) | |
download | uhd-a95eaac42f6cc85fd2ad3f32dc29eeab38ef5194.tar.gz uhd-a95eaac42f6cc85fd2ad3f32dc29eeab38ef5194.tar.bz2 uhd-a95eaac42f6cc85fd2ad3f32dc29eeab38ef5194.zip |
usrp2: Added a peek64 to read pairs of 32 bit numbers such as time64
also added a templated host to/from network conversion in byteswap.hpp (didnt use it though)
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/utils/byteswap.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp index dd5dcbc09..26d60c2ab 100644 --- a/host/include/uhd/utils/byteswap.hpp +++ b/host/include/uhd/utils/byteswap.hpp @@ -37,6 +37,12 @@ namespace uhd{ //! perform a byteswap on a 64 bit integer boost::uint64_t byteswap(boost::uint64_t); + //! network to host: short, long, or long-long + template<typename T> T ntohx(T); + + //! host to network: short, long, or long-long + template<typename T> T htonx(T); + } //namespace uhd /*********************************************************************** @@ -117,4 +123,25 @@ namespace uhd{ #endif +/*********************************************************************** + * Define the templated network to/from host conversions + **********************************************************************/ +#include <boost/detail/endian.hpp> + +template<typename T> UHD_INLINE T uhd::ntohx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + +template<typename T> UHD_INLINE T uhd::htonx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + #endif /* INCLUDED_UHD_UTILS_BYTESWAP_HPP */ |