#include "view/analogsignal.h"
#include "view/logicsignal.h"
-#include <QDebug>
-
#include <assert.h>
+#include <QDebug>
+
using namespace boost;
using namespace std;
_session = NULL;
}
-void SigSession::load_file(const string &name)
+void SigSession::load_file(const string &name,
+ function<void (const QString)> 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
}
void SigSession::start_capture(struct sr_dev_inst *sdi,
- uint64_t record_length, uint64_t sample_rate)
+ uint64_t record_length,
+ function<void (const QString)> 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, sample_rate));
+ record_length, error_handler));
}
void SigSession::stop_capture()
capture_state_changed(state);
}
-void SigSession::load_thread_proc(const string name)
+void SigSession::load_thread_proc(const string name,
+ function<void (const QString)> 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;
}
}
void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
- uint64_t record_length, uint64_t sample_rate)
+ uint64_t record_length,
+ function<void (const QString)> 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;
}
// 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.";
- sr_session_destroy();
- return;
- }
-
- // Set the samplerate
- if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
- &sample_rate) != SR_OK) {
- qDebug() << "Failed to configure samplerate.";
+ g_variant_new_uint64(record_length)) != SR_OK) {
+ 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;
}
void SigSession::feed_in_header(const sr_dev_inst *sdi)
{
shared_ptr<view::Signal> signal;
- uint64_t *sample_rate;
+ GVariant *gvar;
+ uint64_t sample_rate = 0;
unsigned int logic_probe_count = 0;
unsigned int analog_probe_count = 0;
// 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,
+ &gvar, sdi);
+ assert(ret == SR_OK);
+ sample_rate = g_variant_get_uint64(gvar);
+ g_variant_unref(gvar);
// Create data containers for the coming data snapshots
{
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);
}
}
case SR_PROBE_ANALOG:
signal = shared_ptr<view::Signal>(
new view::AnalogSignal(probe->name,
- _analog_data));
+ _analog_data, probe->index));
break;
}
void SigSession::feed_in_meta(const sr_dev_inst *sdi,
const sr_datafeed_meta &meta)
{
+ (void)sdi;
+
for (const GSList *l = meta.config; l; l = l->next) {
const sr_config *const src = (const sr_config*)l->data;
switch (src->key) {
void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
{
lock_guard<mutex> 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<data::LogicSnapshot>(
new data::LogicSnapshot(logic));
void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
{
lock_guard<mutex> 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<data::AnalogSnapshot>(
new data::AnalogSnapshot(analog));