X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=2a794f0fb0c4af8a79b662e12b810ffdb28b510d;hp=22e0428d94abf26a5421c540377dc9e55c6ddccf;hb=896936e568346956c32c548c78578e7a0d4094a3;hpb=e7216ae0a66fe1563514cbd3f67f2e240d010315 diff --git a/pv/session.cpp b/pv/session.cpp index 22e0428d..2a794f0f 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -18,6 +18,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _WIN32 +// Windows: Avoid boost/thread namespace pollution (which includes windows.h). +#define NOGDI +#define NORESOURCE +#endif +#include +#include + #ifdef ENABLE_DECODE #include #endif @@ -127,8 +135,11 @@ void Session::set_device(shared_ptr device) // Ensure we are not capturing before setting the device stop_capture(); + if (device_) + device_->close(); + device_ = std::move(device); - device_->create(); + device_->open(); device_->session()->add_datafeed_callback([=] (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); @@ -211,13 +222,28 @@ set< shared_ptr > Session::get_data() const return data; } -boost::shared_mutex& Session::signals_mutex() const +double Session::get_samplerate() const { - return signals_mutex_; + double samplerate = 0.0; + + for (const shared_ptr d : get_data()) { + assert(d); + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + samplerate = std::max(samplerate, s->samplerate()); + } + + // If there is no sample rate given we use samples as unit + if (samplerate == 0.0) + samplerate = 1.0; + + return samplerate; } -const unordered_set< shared_ptr >& Session::signals() const +const unordered_set< shared_ptr > Session::signals() const { + shared_lock lock(signals_mutex_); return signals_; } @@ -298,9 +324,14 @@ void Session::remove_decode_signal(view::DecodeTrace *signal) void Session::set_capture_state(capture_state state) { - lock_guard lock(sampling_mutex_); - const bool changed = capture_state_ != state; - capture_state_ = state; + bool changed; + + { + lock_guard lock(sampling_mutex_); + changed = capture_state_ != state; + capture_state_ = state; + } + if (changed) capture_state_changed(state); } @@ -466,6 +497,27 @@ void Session::feed_in_meta(shared_ptr meta) signals_changed(); } +void Session::feed_in_trigger() +{ + // The channel containing most samples should be most accurate + uint64_t sample_count = 0; + + for (const shared_ptr d : get_data()) { + assert(d); + uint64_t temp_count = 0; + + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + temp_count += s->get_sample_count(); + + if (temp_count > sample_count) + sample_count = temp_count; + } + + trigger_event(sample_count / get_samplerate()); +} + void Session::feed_in_frame_begin() { if (cur_logic_segment_ || !cur_analog_segments_.empty()) @@ -519,7 +571,7 @@ void Session::feed_in_analog(shared_ptr analog) const vector> channels = analog->channels(); const unsigned int channel_count = channels.size(); const size_t sample_count = analog->num_samples() / channel_count; - const float *data = analog->data_pointer(); + const float *data = static_cast(analog->data_pointer()); bool sweep_beginning = false; for (auto channel : channels) @@ -590,6 +642,10 @@ void Session::data_feed_in(shared_ptr device, feed_in_meta(dynamic_pointer_cast(packet->payload())); break; + case SR_DF_TRIGGER: + feed_in_trigger(); + break; + case SR_DF_FRAME_BEGIN: feed_in_frame_begin(); break;