summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rwxr-xr-xhost/lib/transport/gen_vrt.py13
-rw-r--r--host/lib/types.cpp28
2 files changed, 34 insertions, 7 deletions
diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt.py
index 6cdd6645d..d1e553c41 100755
--- a/host/lib/transport/gen_vrt.py
+++ b/host/lib/transport/gen_vrt.py
@@ -169,7 +169,7 @@ void vrt::unpack_$(suffix)(
switch(pred){
#for $pred in range(2**5)
case $pred:
- #set $set_has_time_spec = False
+ #set $has_time_spec = False
#set $num_header_words = 1
########## Stream ID ##########
#if $pred & $sid_p
@@ -184,21 +184,20 @@ void vrt::unpack_$(suffix)(
#end if
########## Integer Time ##########
#if $pred & $tsi_p
- metadata.has_time_spec = true;
- #set $set_has_time_spec = True
+ #set $has_time_spec = True
metadata.time_spec.secs = $(XE_MACRO)(header_buff[$num_header_words]);
#set $num_header_words += 1
#end if
########## Fractional Time ##########
#if $pred & $tsf_p
- #if not $set_has_time_spec
- metadata.has_time_spec = true;
- #set $set_has_time_spec = True
- #end if
+ #set $has_time_spec = True
#set $num_header_words += 1
metadata.time_spec.set_ticks($(XE_MACRO)(header_buff[$num_header_words]), tick_rate);
#set $num_header_words += 1
#end if
+ #if $has_time_spec
+ metadata.has_time_spec = true;
+ #end if
########## Trailer ##########
#if $pred & $tlr_p
#set $num_trailer_words = 1;
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index daf3be7f7..78a3d22ce 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -120,6 +120,11 @@ tx_metadata_t::tx_metadata_t(void):
/***********************************************************************
* time spec
**********************************************************************/
+static inline void time_spec_normalize(time_spec_t &time_spec){
+ time_spec.secs += boost::uint32_t(std::ceil(time_spec.nsecs/1e9));
+ time_spec.nsecs = std::fmod(time_spec.nsecs, 1e9);
+}
+
time_spec_t::time_spec_t(boost::uint32_t secs, double nsecs):
secs(secs),
nsecs(nsecs)
@@ -127,6 +132,13 @@ time_spec_t::time_spec_t(boost::uint32_t secs, double nsecs):
/* NOP */
}
+time_spec_t::time_spec_t(boost::uint32_t secs, boost::uint32_t ticks, double tick_rate):
+ secs(secs),
+ nsecs(double(ticks)*1e9/tick_rate)
+{
+ /* NOP */
+}
+
boost::uint32_t time_spec_t::get_ticks(double tick_rate) const{
return boost::math::iround(nsecs*tick_rate*1e-9);
}
@@ -135,6 +147,22 @@ void time_spec_t::set_ticks(boost::uint32_t ticks, double tick_rate){
nsecs = double(ticks)*1e9/tick_rate;
}
+time_spec_t &time_spec_t::operator+=(const time_spec_t &rhs){
+ this->secs += rhs.secs;
+ this->nsecs += rhs.nsecs;
+ return *this;
+}
+
+time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
+ this->secs -= rhs.secs;
+ this->nsecs -= rhs.nsecs;
+ return *this;
+}
+
+bool uhd::operator==(const time_spec_t &lhs, const time_spec_t &rhs){
+ return lhs.secs == rhs.secs and lhs.nsecs == rhs.nsecs;
+}
+
/***********************************************************************
* device addr
**********************************************************************/