Commit fd7c9cd1 authored by DreamSourceLab's avatar DreamSourceLab

Add DAQ mode for DSCope series of products

parent dcdd51b2
This diff is collapsed.
......@@ -43,8 +43,8 @@ class AnalogSnapshot : public Snapshot
public:
struct EnvelopeSample
{
uint16_t min;
uint16_t max;
uint8_t min;
uint8_t max;
};
struct EnvelopeSection
......@@ -52,15 +52,22 @@ public:
uint64_t start;
unsigned int scale;
uint64_t length;
uint64_t samples_num;
EnvelopeSample *samples;
uint8_t *max;
uint8_t *min;
};
private:
struct Envelope
{
uint64_t length;
uint64_t ring_length;
uint64_t count;
uint64_t data_length;
EnvelopeSample *samples;
uint8_t *max;
uint8_t *min;
};
private:
......@@ -70,8 +77,6 @@ private:
static const float LogEnvelopeScaleFactor;
static const uint64_t EnvelopeDataUnit;
static const int BytesPerSample = 2;
public:
AnalogSnapshot();
......@@ -85,16 +90,19 @@ public:
void append_payload(const sr_datafeed_analog &analog);
const uint16_t* get_samples(int64_t start_sample,
int64_t end_sample) const;
const uint8_t *get_samples(int64_t start_sample) const;
void get_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length, int probe_index) const;
void get_envelope_section(EnvelopeSection &s,
uint64_t start, int64_t count, float min_length, int probe_index) const;
int get_ch_order(int sig_index);
uint8_t get_unit_bytes() const;
int get_scale_factor() const;
private:
void append_data(void *data, uint64_t samples);
void append_data(void *data, uint64_t samples, uint16_t pitch);
void free_envelop();
void reallocate_envelope(Envelope &l);
void append_payload_to_envelope_levels();
......@@ -102,8 +110,9 @@ private:
private:
struct Envelope _envelope_levels[2*DS_MAX_ANALOG_PROBES_NUM][ScaleStepCount];
struct Envelope _envelope_levels[DS_MAX_ANALOG_PROBES_NUM][ScaleStepCount];
uint8_t _unit_bytes;
uint16_t _unit_pitch;
friend class AnalogSnapshotTest::Basic;
};
......
......@@ -93,6 +93,26 @@ uint64_t Snapshot::get_sample_count() const
return _sample_count;
}
uint64_t Snapshot::get_ring_start() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (_sample_count < _total_sample_count)
return 0;
else
return _ring_sample_count;
}
uint64_t Snapshot::get_ring_end() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
if (_sample_count == 0)
return 0;
else if (_ring_sample_count == 0)
return _total_sample_count - 1;
else
return _ring_sample_count - 1;
}
const void* Snapshot::get_data() const
{
return _data;
......
......@@ -39,6 +39,8 @@ public:
virtual void init() = 0;
uint64_t get_sample_count() const;
uint64_t get_ring_start() const;
uint64_t get_ring_end() const;
const void * get_data() const;
......
......@@ -107,17 +107,17 @@ void Calibration::set_device(boost::shared_ptr<device::DevInst> dev_inst)
uint64_t vgain = 0, vgain_default = 0;
uint16_t vgain_range = 0;
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN);
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN);
if (gvar != NULL) {
vgain = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT);
if (gvar != NULL) {
vgain_default = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_RANGE);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE);
if (gvar != NULL) {
vgain_range = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
......@@ -135,12 +135,12 @@ void Calibration::set_device(boost::shared_ptr<device::DevInst> dev_inst)
uint64_t voff = 0;
uint16_t voff_range = 0;
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VOFF);
if (gvar != NULL) {
voff = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF_RANGE);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VOFF_RANGE);
if (gvar != NULL) {
voff_range = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
......@@ -185,16 +185,16 @@ void Calibration::set_value(int value)
assert(probe);
if (sc->objectName() == VGAIN+probe->index) {
uint64_t vgain_default;
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT);
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT);
if (gvar != NULL) {
vgain_default = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
_dev_inst->set_config(probe, NULL, SR_CONF_VGAIN,
_dev_inst->set_config(probe, NULL, SR_CONF_PROBE_VGAIN,
g_variant_new_uint64(value+vgain_default));
}
break;
} else if (sc->objectName() == VOFF+probe->index) {
_dev_inst->set_config(probe, NULL, SR_CONF_VOFF,
_dev_inst->set_config(probe, NULL, SR_CONF_PROBE_VOFF,
g_variant_new_uint16(value));
break;
}
......@@ -262,17 +262,17 @@ void Calibration::reload_value()
uint64_t vgain = 0, vgain_default = 0;
uint16_t vgain_range = 0;
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN);
GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN);
if (gvar != NULL) {
vgain = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT);
if (gvar != NULL) {
vgain_default = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_RANGE);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE);
if (gvar != NULL) {
vgain_range = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
......@@ -280,12 +280,12 @@ void Calibration::reload_value()
uint64_t voff = 0;
uint16_t voff_range = 0;
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VOFF);
if (gvar != NULL) {
voff = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
}
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF_RANGE);
gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VOFF_RANGE);
if (gvar != NULL) {
voff_range = g_variant_get_uint16(gvar);
g_variant_unref(gvar);
......
File mode changed from 100755 to 100644
This diff is collapsed.
......@@ -43,6 +43,7 @@
#include <libsigrok4DSL/libsigrok.h>
#include "../device/devinst.h"
#include "../prop/binding/deviceoptions.h"
#include "../prop/binding/probeoptions.h"
#include "../toolbars/titlebar.h"
#include "../dialogs/dsdialog.h"
......@@ -64,7 +65,9 @@ private:
QGridLayout *get_property_form(QWidget *parent);
void setup_probes();
void logic_probes(QGridLayout& layout);
void analog_probes(QGridLayout& layout);
QString dynamic_widget(QGridLayout &_dynamic_layout);
void set_all_probes(bool set);
void enable_max_probes();
......@@ -83,10 +86,10 @@ private:
QVBoxLayout _layout;
toolbars::TitleBar *_titlebar;
QGroupBox *_probes_box;
QGridLayout _probes_box_layout;
QGridLayout _dynamic_layout;
QVector <QLabel *> _probes_label_list;
QVector <QCheckBox *> _probes_checkBox_list;
QVector <QWidget *> _probe_widget_list;
QGroupBox *_props_box;
......@@ -98,6 +101,7 @@ private:
QString _mode;
pv::prop::binding::DeviceOptions _device_options_binding;
QVector <pv::prop::binding::ProbeOptions *> _probe_options_binding_list;
};
} // namespace dialogs
......
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
......@@ -75,6 +75,7 @@
#include "view/signal.h"
#include "view/dsosignal.h"
#include "view/logicsignal.h"
#include "view/analogsignal.h"
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
#define __STDC_FORMAT_MACROS
......@@ -450,11 +451,11 @@ void MainWindow::run_stop()
switch(_session.get_capture_state()) {
case SigSession::Init:
case SigSession::Stopped:
_view->capture_init(false);
commit_trigger(false);
_session.start_capture(false,
boost::bind(&MainWindow::session_error, this,
QString(tr("Capture failed")), _1));
_view->capture_init(false);
break;
case SigSession::Running:
......@@ -468,11 +469,11 @@ void MainWindow::instant_stop()
switch(_session.get_capture_state()) {
case SigSession::Init:
case SigSession::Stopped:
_view->capture_init(true);
commit_trigger(true);
_session.start_capture(true,
boost::bind(&MainWindow::session_error, this,
QString(tr("Capture failed")), _1));
_view->capture_init(true);
break;
case SigSession::Running:
......@@ -767,13 +768,14 @@ bool MainWindow::load_session(QString name)
(probe->type == obj["type"].toDouble())) {
isEnabled = true;
probe->enabled = obj["enabled"].toBool();
//probe->colour = obj["colour"].toString();
probe->name = g_strdup(obj["name"].toString().toStdString().c_str());
probe->vdiv = obj["vdiv"].toDouble();
probe->coupling = obj["coupling"].toDouble();
probe->vfactor = obj["vfactor"].toDouble();
probe->trig_value = obj["trigValue"].toDouble();
//probe->zeroPos = obj["zeroPos"].toDouble();
probe->map_unit = g_strdup(obj["mapUnit"].toString().toStdString().c_str());
probe->map_min = obj["mapMin"].toDouble();
probe->map_max = obj["mapMax"].toDouble();
break;
}
}
......@@ -807,6 +809,13 @@ bool MainWindow::load_session(QString name)
dsoSig->set_trig_vrate(obj["trigValue"].toDouble());
dsoSig->commit_settings();
}
boost::shared_ptr<view::AnalogSignal> analogSig;
if (analogSig = dynamic_pointer_cast<view::AnalogSignal>(s)) {
analogSig->set_zero_vrate(obj["zeroPos"].toDouble(), true);
analogSig->commit_settings();
}
break;
}
}
......@@ -900,6 +909,16 @@ bool MainWindow::store_session(QString name)
s_obj["trigValue"] = dsoSig->get_trig_vrate();
s_obj["zeroPos"] = dsoSig->get_zero_vrate();
}
boost::shared_ptr<view::AnalogSignal> analogSig;
if (analogSig = dynamic_pointer_cast<view::AnalogSignal>(s)) {
s_obj["vdiv"] = QJsonValue::fromVariant(static_cast<qulonglong>(analogSig->get_vdiv()));
s_obj["coupling"] = analogSig->get_acCoupling();
s_obj["zeroPos"] = analogSig->get_zero_vrate();
s_obj["mapUnit"] = analogSig->get_mapUnit();
s_obj["mapMin"] = analogSig->get_mapMin();
s_obj["mapMax"] = analogSig->get_mapMax();
}
channelVar.append(s_obj);
}
sessionVar["channel"] = channelVar;
......
......@@ -84,8 +84,8 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
case SR_CONF_FILTER:
case SR_CONF_MAX_HEIGHT:
case SR_CONF_MAX_HEIGHT_VALUE:
case SR_CONF_COUPLING:
case SR_CONF_EN_CH:
case SR_CONF_PROBE_COUPLING:
case SR_CONF_PROBE_EN:
case SR_CONF_OPERATION_MODE:
case SR_CONF_BUFFER_OPTIONS:
case SR_CONF_THRESHOLD:
......@@ -93,7 +93,7 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
case SR_CONF_STREAM:
case SR_CONF_TEST:
case SR_CONF_STATUS:
case SR_CONF_FACTOR:
case SR_CONF_PROBE_FACTOR:
bind_enum(name, key, gvar_list);
break;
......@@ -116,7 +116,7 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
bind_enum(name, key, gvar_list, print_timebase);
break;
case SR_CONF_VDIV:
case SR_CONF_PROBE_VDIV:
bind_enum(name, key, gvar_list, print_vdiv);
break;
default:
......
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2018 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <boost/bind.hpp>
#include <QDebug>
#include <QObject>
#include <stdint.h>
#include "probeoptions.h"
#include <pv/prop/bool.h>
#include <pv/prop/double.h>
#include <pv/prop/enum.h>
#include <pv/prop/int.h>
using namespace boost;
using namespace std;
namespace pv {
namespace prop {
namespace binding {
ProbeOptions::ProbeOptions(struct sr_dev_inst *sdi,
struct sr_channel *probe) :
_sdi(sdi),
_probe(probe)
{
GVariant *gvar_opts, *gvar_list;
gsize num_opts;
if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_PROBE_CONFIGS,
&gvar_opts) != SR_OK))
/* Driver supports no device instance options. */
return;
const int *const options = (const int32_t *)g_variant_get_fixed_array(
gvar_opts, &num_opts, sizeof(int32_t));
for (unsigned int i = 0; i < num_opts; i++) {
const struct sr_config_info *const info =
sr_config_info_get(options[i]);
if (!info)
continue;
const int key = info->key;
if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK)
gvar_list = NULL;
const QString name(info->label);
switch(key)
{
case SR_CONF_PROBE_VDIV:
bind_vdiv(name, gvar_list);
break;
case SR_CONF_PROBE_MAP_MIN:
case SR_CONF_PROBE_MAP_MAX:
bind_double(name, key, "",
pair<double, double>(-999999.99, 999999.99), 2, 0.01);
break;
case SR_CONF_PROBE_COUPLING:
bind_coupling(name, gvar_list);
break;
case SR_CONF_PROBE_MAP_UNIT:
bind_enum(name, key, gvar_list);
break;
default:
gvar_list = NULL;
}
if (gvar_list)
g_variant_unref(gvar_list);
}
g_variant_unref(gvar_opts);
}
GVariant* ProbeOptions::config_getter(
const struct sr_dev_inst *sdi,
const struct sr_channel *probe, int key)
{
GVariant *data = NULL;
if (sr_config_get(sdi->driver, sdi, probe, NULL, key, &data) != SR_OK) {
qDebug() <<
"WARNING: Failed to get value of config id" << key;
return NULL;
}
return data;
}
void ProbeOptions::config_setter(
struct sr_dev_inst *sdi,
struct sr_channel *probe, int key, GVariant* value)
{
if (sr_config_set(sdi, probe, NULL, key, value) != SR_OK)
qDebug() << "WARNING: Failed to set value of sample rate";
}
void ProbeOptions::bind_bool(const QString &name, int key)
{
_properties.push_back(boost::shared_ptr<Property>(
new Bool(name, bind(config_getter, _sdi, _probe, key),
bind(config_setter, _sdi, _probe, key, _1))));
}
void ProbeOptions::bind_enum(const QString &name, int key,
GVariant *const gvar_list, boost::function<QString (GVariant*)> printer)
{
GVariant *gvar;
GVariantIter iter;
vector< pair<GVariant*, QString> > values;
assert(gvar_list);
g_variant_iter_init (&iter, gvar_list);
while ((gvar = g_variant_iter_next_value (&iter)))
values.push_back(make_pair(gvar, printer(gvar)));
_properties.push_back(boost::shared_ptr<Property>(
new Enum(name, values,
bind(config_getter, _sdi, _probe, key),
bind(config_setter, _sdi, _probe, key, _1))));
}
void ProbeOptions::bind_int(const QString &name, int key, QString suffix,
optional< std::pair<int64_t, int64_t> > range)
{
_properties.push_back(boost::shared_ptr<Property>(
new Int(name, suffix, range,
bind(config_getter, _sdi, _probe, key),
bind(config_setter, _sdi, _probe, key, _1))));
}
void ProbeOptions::bind_double(const QString &name, int key, QString suffix,
optional< std::pair<double, double> > range,
int decimals, boost::optional<double> step)
{
_properties.push_back(boost::shared_ptr<Property>(
new Double(name, decimals, suffix, range, step,
bind(config_getter, _sdi, _probe, key),
bind(config_setter, _sdi, _probe, key, _1))));
}
void ProbeOptions::bind_vdiv(const QString &name,
GVariant *const gvar_list)
{
GVariant *gvar_list_vdivs;
assert(gvar_list);
if ((gvar_list_vdivs = g_variant_lookup_value(gvar_list,
"vdivs", G_VARIANT_TYPE("at"))))
{
bind_enum(name, SR_CONF_PROBE_VDIV,
gvar_list_vdivs, print_vdiv);
g_variant_unref(gvar_list_vdivs);
}
}
void ProbeOptions::bind_coupling(const QString &name,
GVariant *const gvar_list)
{
GVariant *gvar_list_coupling;
assert(gvar_list);
if ((gvar_list_coupling = g_variant_lookup_value(gvar_list,
"coupling", G_VARIANT_TYPE("ay"))))
{
bind_enum(name, SR_CONF_PROBE_COUPLING,
gvar_list_coupling, print_coupling);
g_variant_unref(gvar_list_coupling);
}
}
QString ProbeOptions::print_gvariant(GVariant *const gvar)
{
QString s;
if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s")))
s = QString::fromUtf8(g_variant_get_string(gvar, NULL));
else
{
gchar *const text = g_variant_print(gvar, FALSE);
s = QString::fromUtf8(text);
g_free(text);
}
return s;
}
QString ProbeOptions::print_vdiv(GVariant *const gvar)
{
uint64_t p, q;
g_variant_get(gvar, "t", &p);
if (p < 1000ULL) {
q = 1000;
} else if (p < 1000000ULL) {
q = 1;
p /= 1000;
}
return QString(sr_voltage_string(p, q));
}
QString ProbeOptions::print_coupling(GVariant *const gvar)
{
uint8_t coupling;
g_variant_get(gvar, "y", &coupling);
if (coupling == SR_DC_COUPLING) {
return QString("DC");
} else if (coupling == SR_AC_COUPLING) {
return QString("AC");
} else if (coupling == SR_GND_COUPLING) {
return QString("GND");
} else {
return QString("Undefined");
}
}
} // binding
} // prop
} // pv
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2018 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DSVIEW_PV_PROP_BINDING_PROBEOPTIONS_H
#define DSVIEW_PV_PROP_BINDING_PROBEOPTIONS_H
#include <boost/function.hpp>
#include <boost/optional.hpp>
#include <QString>
#include <libsigrok4DSL/libsigrok.h>
#include "binding.h"
namespace pv {
namespace prop {
namespace binding {
class ProbeOptions : public Binding
{
public:
ProbeOptions(struct sr_dev_inst *sdi,
struct sr_channel *probe);
private:
static GVariant* config_getter(
const struct sr_dev_inst *sdi,
const struct sr_channel *probe, int key);
static void config_setter(
struct sr_dev_inst *sdi,
struct sr_channel *probe, int key, GVariant* value);
void bind_bool(const QString &name, int key);
void bind_enum(const QString &name, int key,
GVariant *const gvar_list,
boost::function<QString (GVariant*)> printer = print_gvariant);
void bind_int(const QString &name, int key, QString suffix,
boost::optional< std::pair<int64_t, int64_t> > range);
void bind_double(const QString &name, int key, QString suffix,
boost::optional<std::pair<double, double> > range,
int decimals, boost::optional<double> step);
static QString print_gvariant(GVariant *const gvar);
void bind_vdiv(const QString &name,
GVariant *const gvar_list);
void bind_coupling(const QString &name,
GVariant *const gvar_list);
static QString print_vdiv(GVariant *const gvar);
static QString print_coupling(GVariant *const gvar);
protected:
struct sr_dev_inst *const _sdi;
struct sr_channel *const _probe;
};
} // binding