projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Open/close devices as needed
[pulseview.git]
/
pv
/
sigsession.cpp
diff --git
a/pv/sigsession.cpp
b/pv/sigsession.cpp
index 94867959f184fcb547b40463e84f97fccbfea5f6..c5a7d494ecf8ed55237b4c440bd3f4497e72c398 100644
(file)
--- a/
pv/sigsession.cpp
+++ b/
pv/sigsession.cpp
@@
-40,6
+40,7
@@
namespace pv {
SigSession* SigSession::_session = NULL;
SigSession::SigSession() :
SigSession* SigSession::_session = NULL;
SigSession::SigSession() :
+ _sdi(NULL),
_capture_state(Stopped)
{
// TODO: This should not be necessary
_capture_state(Stopped)
{
// TODO: This should not be necessary
@@
-58,6
+59,15
@@
SigSession::~SigSession()
_session = NULL;
}
_session = NULL;
}
+void SigSession::set_device(struct sr_dev_inst *sdi)
+{
+ if (_sdi)
+ sr_dev_close(_sdi);
+ if (sdi)
+ sr_dev_open(sdi);
+ _sdi = sdi;
+}
+
void SigSession::load_file(const string &name,
function<void (const QString)> error_handler)
{
void SigSession::load_file(const string &name,
function<void (const QString)> error_handler)
{
@@
-73,15
+83,20
@@
SigSession::capture_state SigSession::get_capture_state() const
return _capture_state;
}
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<void (const QString)> error_handler)
{
stop_capture();
function<void (const QString)> 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;
// 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)
sr_probe *const probe = (sr_probe*)l->data;
assert(probe);
if (probe->enabled)
@@
-95,7
+110,7
@@
void SigSession::start_capture(struct sr_dev_inst *sdi,
// Begin the session
_sampling_thread.reset(new boost::thread(
// 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));
}
record_length, error_handler));
}
@@
-138,7
+153,7
@@
void SigSession::load_thread_proc(const string name,
return;
}
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."));
if (sr_session_start() != SR_OK) {
error_handler(tr("Failed to start session."));
@@
-148,7
+163,7
@@
void SigSession::load_thread_proc(const string name,
set_capture_state(Running);
sr_session_run();
set_capture_state(Running);
sr_session_run();
- sr_session_
stop
();
+ sr_session_
destroy
();
set_capture_state(Stopped);
}
set_capture_state(Stopped);
}
@@
-161,7
+176,7
@@
void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
assert(error_handler);
sr_session_new();
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."));
if (sr_session_dev_add(sdi) != SR_OK) {
error_handler(tr("Failed to use device."));
@@
-221,7
+236,11
@@
void SigSession::feed_in_header(const sr_dev_inst *sdi)
const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
&gvar, sdi);
const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
&gvar, sdi);
- assert(ret == SR_OK);
+ if (ret != SR_OK) {
+ qDebug("Failed to get samplerate\n");
+ return;
+ }
+
sample_rate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
sample_rate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
@@
-387,8
+406,9
@@
void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
}
void SigSession::data_feed_in_proc(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);
}
assert(_session);
_session->data_feed_in(sdi, packet);
}