X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=5ab30ab1299e2e7bb81475053049eb46f189c3e1;hb=84b1b7d28acc52214940ac94a84943cf9e9685fa;hp=a611e7ac7c14159eed9d8e4c569e2a8b79bb9880;hpb=9c48fa57f507c1eb153b0fb4d3a273c5e32757c8;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index a611e7ac..5ab30ab1 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -20,6 +20,7 @@ #include "sigsession.h" +#include "devicemanager.h" #include "data/analog.h" #include "data/analogsnapshot.h" #include "data/logic.h" @@ -29,6 +30,8 @@ #include +#include + using namespace boost; using namespace std; @@ -37,7 +40,9 @@ namespace pv { // TODO: This should not be necessary SigSession* SigSession::_session = NULL; -SigSession::SigSession() : +SigSession::SigSession(DeviceManager &device_manager) : + _device_manager(device_manager), + _sdi(NULL), _capture_state(Stopped) { // TODO: This should not be necessary @@ -56,6 +61,28 @@ SigSession::~SigSession() _session = NULL; } +struct sr_dev_inst* SigSession::get_device() const +{ + return _sdi; +} + +void SigSession::set_device(struct sr_dev_inst *sdi) +{ + if (_sdi) + _device_manager.release_device(_sdi); + if (sdi) + _device_manager.use_device(sdi, this); + _sdi = sdi; +} + +void SigSession::release_device(struct sr_dev_inst *sdi) +{ + (void)sdi; + + assert(_capture_state == Stopped); + _sdi = NULL; +} + void SigSession::load_file(const string &name, function error_handler) { @@ -71,15 +98,20 @@ SigSession::capture_state SigSession::get_capture_state() const return _capture_state; } -void SigSession::start_capture(struct sr_dev_inst *sdi, - uint64_t record_length, +void SigSession::start_capture(uint64_t record_length, function error_handler) { stop_capture(); + // Check that a device instance has been selected. + if (!_sdi) { + qDebug() << "No device selected"; + return; + } + // Check that at least one probe is enabled const GSList *l; - for (l = sdi->probes; l; l = l->next) { + for (l = _sdi->probes; l; l = l->next) { sr_probe *const probe = (sr_probe*)l->data; assert(probe); if (probe->enabled) @@ -93,7 +125,7 @@ void SigSession::start_capture(struct sr_dev_inst *sdi, // Begin the session _sampling_thread.reset(new boost::thread( - &SigSession::sample_thread_proc, this, sdi, + &SigSession::sample_thread_proc, this, _sdi, record_length, error_handler)); } @@ -136,7 +168,7 @@ void SigSession::load_thread_proc(const string name, return; } - sr_session_datafeed_callback_add(data_feed_in_proc); + sr_session_datafeed_callback_add(data_feed_in_proc, NULL); if (sr_session_start() != SR_OK) { error_handler(tr("Failed to start session.")); @@ -146,9 +178,13 @@ void SigSession::load_thread_proc(const string name, set_capture_state(Running); sr_session_run(); - sr_session_stop(); + sr_session_destroy(); set_capture_state(Stopped); + + // Confirm that SR_DF_END was received + assert(!_cur_logic_snapshot); + assert(!_cur_analog_snapshot); } void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, @@ -159,7 +195,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, assert(error_handler); sr_session_new(); - sr_session_datafeed_callback_add(data_feed_in_proc); + sr_session_datafeed_callback_add(data_feed_in_proc, NULL); if (sr_session_dev_add(sdi) != SR_OK) { error_handler(tr("Failed to use device.")); @@ -169,7 +205,7 @@ 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) { + g_variant_new_uint64(record_length)) != SR_OK) { error_handler(tr("Failed to configure " "time-based sample limit.")); sr_session_destroy(); @@ -187,12 +223,17 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, sr_session_destroy(); set_capture_state(Stopped); + + // Confirm that SR_DF_END was received + assert(!_cur_logic_snapshot); + assert(!_cur_analog_snapshot); } void SigSession::feed_in_header(const sr_dev_inst *sdi) { shared_ptr signal; - uint64_t *sample_rate = NULL; + GVariant *gvar; + uint64_t sample_rate = 0; unsigned int logic_probe_count = 0; unsigned int analog_probe_count = 0; @@ -217,8 +258,14 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) assert(sdi->driver); const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, - (const void**)&sample_rate, sdi); - assert(ret == SR_OK); + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get samplerate\n"); + return; + } + + sample_rate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); // Create data containers for the coming data snapshots { @@ -226,12 +273,12 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) if (logic_probe_count != 0) { _logic_data.reset(new data::Logic( - logic_probe_count, *sample_rate)); + logic_probe_count, sample_rate)); assert(_logic_data); } if (analog_probe_count != 0) { - _analog_data.reset(new data::Analog(*sample_rate)); + _analog_data.reset(new data::Analog(sample_rate)); assert(_analog_data); } } @@ -259,7 +306,7 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) case SR_PROBE_ANALOG: signal = shared_ptr( new view::AnalogSignal(probe->name, - _analog_data)); + _analog_data, probe->index)); break; } @@ -292,10 +339,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)); @@ -313,10 +365,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)); @@ -372,8 +429,9 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, } void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi, - const struct sr_datafeed_packet *packet) + const struct sr_datafeed_packet *packet, void *cb_data) { + (void) cb_data; assert(_session); _session->data_feed_in(sdi, packet); }