]> sigrok.org Git - pulseview.git/blobdiff - pv/session.cpp
Session: Add error messages
[pulseview.git] / pv / session.cpp
index 605cc05c65fd8ab234f5509d5885f30f276f805d..a9bb554efd08a34e14b3375955b0ee6679ae31ea 100644 (file)
@@ -352,8 +352,7 @@ void Session::select_device(shared_ptr<devices::Device> device)
                else
                        set_default_device();
        } catch (const QString &e) {
-               main_bar_->session_error(tr("Failed to Select Device"),
-                       tr("Failed to Select Device"));
+               main_bar_->session_error(tr("Failed to select device"), e);
        }
 }
 
@@ -401,6 +400,7 @@ void Session::set_device(shared_ptr<devices::Device> device)
                device_->open();
        } catch (const QString &e) {
                device_.reset();
+               main_bar_->session_error(tr("Failed to open device"), e);
        }
 
        if (device_) {
@@ -426,7 +426,7 @@ void Session::set_default_device()
        // Try and find the demo device and select that by default
        const auto iter = find_if(devices.begin(), devices.end(),
                [] (const shared_ptr<devices::HardwareDevice> &d) {
-                       return d->hardware_device()->driver()->name() == "demo";        });
+                       return d->hardware_device()->driver()->name() == "demo"; });
        set_device((iter == devices.end()) ? devices.front() : *iter);
 }
 
@@ -567,6 +567,8 @@ void Session::start_capture(function<void (const QString)> error_handler)
        for (const shared_ptr<data::SignalData> d : all_signal_data_)
                d->clear();
 
+       trigger_list_.clear();
+
        // Revert name back to default name (e.g. "Session 1") for real devices
        // as the (possibly saved) data is gone. File devices keep their name.
        shared_ptr<devices::HardwareDevice> hw_device =
@@ -677,16 +679,27 @@ double Session::get_samplerate() const
        return samplerate;
 }
 
-int Session::get_segment_count() const
+uint32_t Session::get_segment_count() const
 {
-       int min_val = INT_MAX;
+       uint32_t value = 0;
 
-       // Find the lowest common number of segments
+       // Find the highest number of segments
        for (shared_ptr<data::SignalData> data : all_signal_data_)
-               if (data->get_segment_count() < min_val)
-                       min_val = data->get_segment_count();
+               if (data->get_segment_count() > value)
+                       value = data->get_segment_count();
+
+       return value;
+}
 
-       return (min_val != INT_MAX) ? min_val : 0;
+vector<util::Timestamp> Session::get_triggers(uint32_t segment_id) const
+{
+       vector<util::Timestamp> result;
+
+       for (pair<uint32_t, util::Timestamp> entry : trigger_list_)
+               if (entry.first == segment_id)
+                       result.push_back(entry.second);
+
+       return result;
 }
 
 const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
@@ -694,6 +707,17 @@ const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
        return signalbases_;
 }
 
+bool Session::all_segments_complete(uint32_t segment_id) const
+{
+       bool all_complete = true;
+
+       for (shared_ptr<data::SignalBase> base : signalbases_)
+               if (!base->segment_is_complete(segment_id))
+                       all_complete = false;
+
+       return all_complete;
+}
+
 #ifdef ENABLE_DECODE
 shared_ptr<data::DecodeSignal> Session::add_decode_signal()
 {
@@ -906,6 +930,7 @@ void Session::sample_thread_proc(function<void (const QString)> error_handler)
                cur_analog_segments_.clear();
        }
        highest_segment_id_ = -1;
+       frame_began_ = false;
 
        try {
                device_->start();
@@ -1055,7 +1080,13 @@ void Session::feed_in_trigger()
                }
        }
 
-       trigger_event(sample_count / get_samplerate());
+       // If no frame began then this is a trigger for a new segment
+       const uint32_t segment_id =
+               (frame_began_) ? highest_segment_id_ : (highest_segment_id_ + 1);
+
+       util::Timestamp timestamp = sample_count / get_samplerate();
+       trigger_list_.emplace_back(segment_id, timestamp);
+       trigger_event(segment_id, timestamp);
 }
 
 void Session::feed_in_frame_begin()
@@ -1083,8 +1114,7 @@ void Session::feed_in_frame_end()
                cur_analog_segments_.clear();
        }
 
-       if (frame_began_)
-               frame_began_ = false;
+       frame_began_ = false;
 
        signal_segment_completed();
 }
@@ -1109,7 +1139,8 @@ void Session::feed_in_logic(shared_ptr<Logic> logic)
 
                // Create a new data segment
                cur_logic_segment_ = make_shared<data::LogicSegment>(
-                       *logic_data_, logic->unit_size(), cur_samplerate_);
+                       *logic_data_, logic_data_->get_segment_count(),
+                       logic->unit_size(), cur_samplerate_);
                logic_data_->push_segment(cur_logic_segment_);
 
                signal_new_segment();
@@ -1162,7 +1193,7 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
 
                        // Create a segment, keep it in the maps of channels
                        segment = make_shared<data::AnalogSegment>(
-                               *data, cur_samplerate_);
+                               *data, data->get_segment_count(), cur_samplerate_);
                        cur_analog_segments_[channel] = segment;
 
                        // Push the segment into the analog data.