X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=5af04b839be314cbc878e664fd6e0ddfb4e5ac41;hb=f4c92e1c49680738bde7d5fa08153fa914ac2920;hp=6a69fdca2b99970aa0a86234a92fc0336dcb33c0;hpb=b85f25545939d923f71609e5cc670e48f4f83f19;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 6a69fdca..5af04b83 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -27,10 +27,10 @@ #include "view/analogsignal.h" #include "view/logicsignal.h" -#include - #include +#include + using namespace boost; using namespace std; @@ -58,11 +58,13 @@ SigSession::~SigSession() _session = NULL; } -void SigSession::load_file(const string &name) +void SigSession::load_file(const string &name, + function error_handler) { stop_capture(); _sampling_thread.reset(new boost::thread( - &SigSession::load_thread_proc, this, name)); + &SigSession::load_thread_proc, this, name, + error_handler)); } SigSession::capture_state SigSession::get_capture_state() const @@ -72,13 +74,29 @@ SigSession::capture_state SigSession::get_capture_state() const } void SigSession::start_capture(struct sr_dev_inst *sdi, - uint64_t record_length) + uint64_t record_length, + function error_handler) { stop_capture(); + // Check that at least one probe is enabled + const GSList *l; + for (l = sdi->probes; l; l = l->next) { + sr_probe *const probe = (sr_probe*)l->data; + assert(probe); + if (probe->enabled) + break; + } + + if (!l) { + error_handler(tr("No probes enabled.")); + return; + } + + // Begin the session _sampling_thread.reset(new boost::thread( &SigSession::sample_thread_proc, this, sdi, - record_length)); + record_length, error_handler)); } void SigSession::stop_capture() @@ -112,17 +130,18 @@ void SigSession::set_capture_state(capture_state state) capture_state_changed(state); } -void SigSession::load_thread_proc(const string name) +void SigSession::load_thread_proc(const string name, + function error_handler) { if (sr_session_load(name.c_str()) != SR_OK) { - qDebug() << "Failed to load file."; + error_handler(tr("Failed to load file.")); return; } sr_session_datafeed_callback_add(data_feed_in_proc); if (sr_session_start() != SR_OK) { - qDebug() << "Failed to start session."; + error_handler(tr("Failed to start session.")); return; } @@ -135,15 +154,17 @@ void SigSession::load_thread_proc(const string name) } void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, - uint64_t record_length) + uint64_t record_length, + function error_handler) { assert(sdi); + assert(error_handler); sr_session_new(); sr_session_datafeed_callback_add(data_feed_in_proc); if (sr_session_dev_add(sdi) != SR_OK) { - qDebug() << "Failed to use device."; + error_handler(tr("Failed to use device.")); sr_session_destroy(); return; } @@ -151,13 +172,14 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, // Set the sample limit if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, &record_length) != SR_OK) { - qDebug() << "Failed to configure time-based sample limit."; + error_handler(tr("Failed to configure " + "time-based sample limit.")); sr_session_destroy(); return; } if (sr_session_start() != SR_OK) { - qDebug() << "Failed to start session."; + error_handler(tr("Failed to start session.")); return; } @@ -195,8 +217,10 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) // Read out the sample rate assert(sdi->driver); - assert(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, - (const void**)&sample_rate, sdi) == SR_OK); + + const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, + (const void**)&sample_rate, sdi); + assert(ret == SR_OK); // Create data containers for the coming data snapshots { @@ -270,10 +294,15 @@ void SigSession::feed_in_meta(const sr_dev_inst *sdi, void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { lock_guard lock(_data_mutex); - if (!_cur_logic_snapshot) + + if (!_logic_data) { - assert(_logic_data); + qDebug() << "Unexpected logic packet"; + return; + } + if (!_cur_logic_snapshot) + { // Create a new data snapshot _cur_logic_snapshot = shared_ptr( new data::LogicSnapshot(logic)); @@ -291,10 +320,15 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) void SigSession::feed_in_analog(const sr_datafeed_analog &analog) { lock_guard lock(_data_mutex); - if (!_cur_analog_snapshot) + + if(!_analog_data) { - assert(_analog_data); + qDebug() << "Unexpected analog packet"; + return; // This analog packet was not expected. + } + if (!_cur_analog_snapshot) + { // Create a new data snapshot _cur_analog_snapshot = shared_ptr( new data::AnalogSnapshot(analog));