Commit c32fb54b authored by DreamSourceLab's avatar DreamSourceLab

export csv only when data change, reduce the file size

fix the out of range error when measure @ LA mode
parent 1b1bb88e
......@@ -37,6 +37,7 @@ DSView/install_manifest.txt
moc_*.cxx
moc_*.cxx_parameters
qrc_*.cxx
libsigrok4DSL/version.h
......
......@@ -170,7 +170,7 @@ double DevInst::get_sample_time()
if (sample_rate == 0)
sample_time = 0;
else
sample_time = sample_limit * 1.0f / sample_rate;
sample_time = sample_limit * 1.0 / sample_rate;
return sample_time;
}
......
......@@ -25,6 +25,7 @@
#include "ruler.h"
#include "view.h"
#include "../device/device.h"
#include <QBrush>
#include <QPainter>
......@@ -57,15 +58,10 @@ Cursor::Cursor(View &view, QColor color, uint64_t index) :
{
}
Cursor::Cursor(View &view, QColor color) :
TimeMarker(view, color),
_other(*this)
{
}
QRectF Cursor::get_label_rect(const QRect &rect) const
{
const float x = (_time - _view.offset()) / _view.scale();
const double samples_per_pixel = _view.session().get_device()->get_sample_rate() * _view.scale();
const double x = _index/samples_per_pixel - (_view.offset() / _view.scale());
const QSizeF label_size(
_text_size.width() + View::LabelPadding.width() * 2,
......@@ -120,7 +116,7 @@ void Cursor::paint_label(QPainter &p, const QRect &rect,
p.drawLine(close.left() + 2, close.bottom() - 2, close.right() - 2, close.top() + 2);
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
Ruler::format_time(_time, prefix, 2));
Ruler::format_real_time(_index, _view.session().get_device()->get_sample_rate()));
const QRectF arrowRect = QRectF(r.bottomLeft().x(), r.bottomLeft().y(), r.width(), ArrowSize);
p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(index));
......@@ -147,7 +143,7 @@ void Cursor::paint_fix_label(QPainter &p, const QRect &rect,
p.setPen(Qt::white);
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
Ruler::format_time(_time, prefix, 2));
Ruler::format_real_time(_index, _view.session().get_device()->get_sample_rate()));
const QRectF arrowRect = QRectF(r.bottomLeft().x(), r.bottomLeft().y(), r.width(), ArrowSize);
p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, label);
......@@ -156,7 +152,7 @@ void Cursor::paint_fix_label(QPainter &p, const QRect &rect,
void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
{
_text_size = p.boundingRect(QRectF(), 0,
Ruler::format_time(_time, prefix, 2)).size();
Ruler::format_real_time(_index, _view.session().get_device()->get_sample_rate())).size();
}
} // namespace view
......
......@@ -55,7 +55,6 @@ public:
* @param time The time to set the flag to.
* @param other A reference to the other cursor.
*/
Cursor(View &view, QColor color);
Cursor(View &view, QColor color, uint64_t index);
......
......@@ -448,7 +448,7 @@ void DsoSignal::set_trig_vpos(int pos)
assert(_view);
int trig_value;
if (enabled()) {
double delta = min((double)max(pos - UpMargin, 0), get_view_rect().height()) * 1.0f / get_view_rect().height();
double delta = min((double)max(pos - UpMargin, 0), get_view_rect().height()) * 1.0 / get_view_rect().height();
bool isDSCope = (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0);
if (isDSCope) {
_trig_vpos = delta;
......@@ -475,7 +475,7 @@ void DsoSignal::set_zeroPos(int pos)
if (enabled()) {
double delta = _trig_vpos - _zeroPos;
set_trig_vpos(get_trig_vpos() + pos - get_zeroPos());
_zeroPos = min((double)max(pos - UpMargin, 0), get_view_rect().height()) * 1.0f / get_view_rect().height();
_zeroPos = min((double)max(pos - UpMargin, 0), get_view_rect().height()) * 1.0 / get_view_rect().height();
_trig_vpos = min(max(_zeroPos + delta, 0.0), 1.0);
update_zeroPos();
......@@ -486,7 +486,7 @@ void DsoSignal::update_zeroPos()
{
if (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0) {
//double vpos_off = (0.5 - _zeroPos) * _vDial->get_value() * DS_CONF_DSO_VDIVS;
double vpos_off = (0.5 - (get_zeroPos() - UpMargin) * 1.0f/get_view_rect().height()) * _vDial->get_value() * DS_CONF_DSO_VDIVS;
double vpos_off = (0.5 - (get_zeroPos() - UpMargin) * 1.0/get_view_rect().height()) * _vDial->get_value() * DS_CONF_DSO_VDIVS;
_dev_inst->set_config(_probe, NULL, SR_CONF_VPOS,
g_variant_new_double(vpos_off));
}
......@@ -517,7 +517,7 @@ void DsoSignal::paint_back(QPainter &p, int left, int right)
const uint64_t sample_len = _dev_inst->get_sample_limit();
const double samplerate = _dev_inst->get_sample_rate();
const double samples_per_pixel = samplerate * _view->scale();
const double shown_rate = min(samples_per_pixel * width * 1.0f / sample_len, 1.0);
const double shown_rate = min(samples_per_pixel * width * 1.0 / sample_len, 1.0);
const double start_time = _data->get_start_time();
const double start = samplerate * (_view->offset() - start_time);
const double shown_offset = min(start / sample_len, 1.0) * width;
......@@ -538,7 +538,7 @@ void DsoSignal::paint_back(QPainter &p, int left, int right)
QPen pen(Signal::dsFore);
pen.setStyle(Qt::DotLine);
p.setPen(pen);
const double spanY =height * 1.0f / DS_CONF_DSO_VDIVS;
const double spanY =height * 1.0 / DS_CONF_DSO_VDIVS;
for (i = 1; i <= DS_CONF_DSO_VDIVS; i++) {
const double posY = spanY * i + UpMargin;
p.drawLine(left, posY, right, posY);
......@@ -548,7 +548,7 @@ void DsoSignal::paint_back(QPainter &p, int left, int right)
width / 2.0f + 5, posY - miniSpanY * j);
}
}
const double spanX = width * 1.0f / DS_CONF_DSO_HDIVS;
const double spanX = width * 1.0 / DS_CONF_DSO_HDIVS;
for (i = 1; i <= DS_CONF_DSO_HDIVS; i++) {
const double posX = spanX * i;
p.drawLine(posX, UpMargin,
......@@ -815,7 +815,7 @@ void DsoSignal::paint_measure(QPainter &p)
_period = (count == 0) ? period * 10 : period * 10.0f / count;
const int channel_count = _view->session().get_ch_num(SR_CHANNEL_DSO);
uint64_t sample_rate = _dev_inst->get_sample_rate();
_period = _period * 200 / (channel_count * sample_rate * 1.0f/ SR_MHZ(1));
_period = _period * 200 / (channel_count * sample_rate * 1.0 / SR_MHZ(1));
QString max_string = abs(value_max) > 1000 ? QString::number(value_max/1000.0) + "V" : QString::number(value_max) + "mV";
QString min_string = abs(value_min) > 1000 ? QString::number(value_min/1000.0) + "V" : QString::number(value_min) + "mV";
QString period_string = abs(_period) > 1000000000 ? QString::number(_period/1000000000) + "S" :
......
......@@ -136,7 +136,7 @@ QString Ruler::format_time(double t)
QString Ruler::format_real_time(uint64_t delta_index, uint64_t sample_rate)
{
uint64_t delta_time = delta_index * std::pow(10, 12) / sample_rate;
uint64_t delta_time = std::pow(10, 12) / sample_rate * delta_index;
if (delta_time == 0)
return "0";
......@@ -148,12 +148,12 @@ QString Ruler::format_real_time(uint64_t delta_index, uint64_t sample_rate)
zero++;
}
return format_time(delta_time * 1.0f / std::pow(10, 12-zero), prefix/3+1, prefix/3*3 > zero ? prefix/3*3 - zero : 0);
return format_time(delta_time / std::pow(10.0, 12-zero), prefix/3+1, prefix/3*3 > zero ? prefix/3*3 - zero : 0);
}
QString Ruler::format_real_freq(uint64_t delta_index, uint64_t sample_rate)
{
const double delta_period = delta_index * 1.0f / sample_rate;
const double delta_period = delta_index * 1.0 / sample_rate;
return format_freq(delta_period);
}
......@@ -324,8 +324,8 @@ void Ruler::draw_tick_mark(QPainter &p)
{
using namespace Qt;
const double SpacingIncrement = 32.0f;
const double MinValueSpacing = 16.0f;
const double SpacingIncrement = 32.0;
const double MinValueSpacing = 16.0;
const int ValueMargin = 15;
double min_width = SpacingIncrement, typical_width;
......@@ -423,11 +423,11 @@ void Ruler::draw_logic_tick_mark(QPainter &p)
{
using namespace Qt;
const double SpacingIncrement = 32.0f;
const double MinValueSpacing = 16.0f;
const double SpacingIncrement = 32.0;
const double MinValueSpacing = 16.0;
const int ValueMargin = 5;
const double abs_min_period = 10.0f / _view.session().get_device()->get_sample_rate();
const double abs_min_period = 10.0 / _view.session().get_device()->get_sample_rate();
double min_width = SpacingIncrement;
double typical_width;
......@@ -505,13 +505,13 @@ void Ruler::draw_logic_tick_mark(QPainter &p)
else
{
// Draw a minor tick
if (minor_tick_period / _view.scale() > 2 * typical_width ||
tick_period / _view.scale() > _view.get_view_width())
if (minor_tick_period / _view.scale() > 2 * typical_width)
p.drawText(x, 2 * ValueMargin, 0, text_height,
AlignCenter | AlignTop | TextDontClip,
format_time(t, prefix));
//else if ((tick_period / _view.scale() > width() / 4) && (minor_tick_period / _view.scale() > inc_text_width))
else if (minor_tick_period / _view.scale() > 1.1 * inc_text_width)
else if (minor_tick_period / _view.scale() > 1.1 * inc_text_width ||
tick_period / _view.scale() > _view.get_view_width())
p.drawText(x, 2 * ValueMargin, 0, minor_tick_y1 + ValueMargin,
AlignCenter | AlignTop | TextDontClip,
format_time(t - major_t, minor_prefix));
......
......@@ -34,26 +34,15 @@ namespace view {
TimeMarker::TimeMarker(View &view, QColor &colour,
uint64_t index) :
_view(view),
_time(index * 1.0f / view.session().get_device()->get_sample_rate()),
_index(index),
_grabbed(false),
_colour(colour)
{
}
TimeMarker::TimeMarker(View &view, QColor &colour) :
_view(view),
_time(0),
_index(0),
_grabbed(false),
_colour(colour)
{
}
TimeMarker::TimeMarker(const TimeMarker &s) :
QObject(),
_view(s._view),
_time(s._time),
_index(s._index),
_colour(s._colour)
{
......@@ -68,11 +57,6 @@ void TimeMarker::set_grabbed(bool grabbed)
_grabbed = grabbed;
}
double TimeMarker::time() const
{
return _time;
}
uint64_t TimeMarker::index() const
{
return _index;
......@@ -81,13 +65,13 @@ uint64_t TimeMarker::index() const
void TimeMarker::set_index(uint64_t index)
{
_index = index;
_time = index * 1.0f / _view.session().get_device()->get_sample_rate();
time_changed();
}
void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight)
{
const float x = (_time - _view.offset()) / _view.scale();
const double samples_per_pixel = _view.session().get_device()->get_sample_rate() * _view.scale();
const double x = _index/samples_per_pixel - (_view.offset() / _view.scale());
p.setPen((_grabbed | highlight) ? QPen(_colour.lighter(), 2, Qt::DashLine) : QPen(_colour, 1, Qt::DashLine));
p.drawLine(QPointF(x, rect.top()), QPointF(x, rect.bottom()));
}
......
......@@ -50,7 +50,6 @@ protected:
* @param time The time to set the flag to.
*/
TimeMarker(View &view, QColor &colour, uint64_t index);
TimeMarker(View &view, QColor &colour);
/**
* Copy constructor
......@@ -107,7 +106,6 @@ signals:
protected:
View &_view;
double _time;
uint64_t _index;
QSizeF _text_size;
......
......@@ -125,10 +125,10 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget
_header->setObjectName(tr("ViewArea_header"));
_show_trig_cursor = false;
_trig_cursor = new Cursor(*this, Trace::dsLightRed);
_trig_cursor = new Cursor(*this, Trace::dsLightRed, 0);
_show_search_cursor = false;
_search_pos = 0;
_search_cursor = new Cursor(*this, Trace::dsLightBlue);
_search_cursor = new Cursor(*this, Trace::dsLightBlue, _search_pos);
}
SigSession& View::session()
......@@ -341,7 +341,7 @@ void View::show_search_cursor(bool show)
void View::set_trig_pos(quint64 trig_pos)
{
const double time = trig_pos * 1.0f / _session.get_device()->get_sample_rate();
const double time = trig_pos * 1.0 / _session.get_device()->get_sample_rate();
_trig_pos = trig_pos;
_trig_cursor->set_index(trig_pos);
_show_trig_cursor = true;
......@@ -354,7 +354,7 @@ void View::set_search_pos(uint64_t search_pos)
{
//assert(search_pos >= 0);
const double time = search_pos * 1.0f / _session.get_device()->get_sample_rate();
const double time = search_pos * 1.0 / _session.get_device()->get_sample_rate();
_search_pos = search_pos;
_search_cursor->set_index(search_pos);
set_scale_offset(_scale, time - _scale * get_view_width() / 2);
......@@ -452,14 +452,14 @@ void View::update_scale()
assert(sample_rate > 0);
if (_session.get_device()->dev_inst()->mode != DSO) {
_scale = (1.0f / sample_rate) / WellPixelsPerSample;
_scale = (1.0 / sample_rate) / WellPixelsPerSample;
_maxscale = _session.get_device()->get_sample_time() / (get_view_width() * MaxViewRate);
} else {
_scale = _session.get_device()->get_time_base() * 10.0f / get_view_width() * std::pow(10.0, -9.0);
_scale = _session.get_device()->get_time_base() * 10.0 / get_view_width() * std::pow(10.0, -9.0);
_maxscale = 1e9;
}
_minscale = (1.0f / sample_rate) / MaxPixelsPerSample;
_minscale = (1.0 / sample_rate) / MaxPixelsPerSample;
_offset = 0;
_preScale = _scale;
_preOffset = _offset;
......@@ -719,7 +719,7 @@ void View::set_cursor_middle(int index)
list<Cursor*>::iterator i = _cursorList.begin();
while (index-- != 0)
i++;
set_scale_offset(_scale, (*i)->time() - _scale * get_view_width() / 2);
set_scale_offset(_scale, (*i)->index() * 1.0 / _session.get_device()->get_sample_rate() - _scale * get_view_width() / 2);
}
void View::receive_data(quint64 length)
......@@ -748,20 +748,6 @@ QString View::get_cm_delta(int index1, int index2)
return _ruler->format_real_time(delta_sample, _session.get_device()->get_sample_rate());
}
double View::get_cursor_time(int index)
{
assert(index < (int)_cursorList.size());
int curIndex = 0;
for (list<Cursor*>::iterator i = _cursorList.begin();
i != _cursorList.end(); i++) {
if (index == curIndex) {
return (*i)->time();
}
curIndex++;
}
}
uint64_t View::get_cursor_samples(int index)
{
assert(index < (int)_cursorList.size());
......
......@@ -74,9 +74,9 @@ public:
static const QSizeF LabelPadding;
static const int WellPixelsPerSample = 10.0f;
static constexpr double MaxViewRate = 1.0f;
static const int MaxPixelsPerSample = 100.0f;
static const int WellPixelsPerSample = 10;
static constexpr double MaxViewRate = 1.0;
static const int MaxPixelsPerSample = 100;
public:
explicit View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent = 0);
......@@ -197,8 +197,6 @@ private:
void update_margins();
double get_cursor_time(int index);
static bool compare_trace_v_offsets(
const boost::shared_ptr<pv::view::Trace> &a,
const boost::shared_ptr<pv::view::Trace> &b);
......
......@@ -36,6 +36,8 @@
#include <QMouseEvent>
#include <QStyleOption>
#include <math.h>
#include <boost/foreach.hpp>
using namespace boost;
......@@ -177,8 +179,9 @@ void Viewport::paintSignals(QPainter &p)
if (_view.cursors_shown()) {
list<Cursor*>::iterator i = _view.get_cursorList().begin();
double cursorX;
const double samples_per_pixel = _view.session().get_device()->get_sample_rate() * _view.scale();
while (i != _view.get_cursorList().end()) {
cursorX = ((*i)->time() - _view.offset()) / _view.scale();
cursorX = (*i)->index()/samples_per_pixel - (_view.offset() / _view.scale());
if (rect().contains(_view.hover_point().x(), _view.hover_point().y()) &&
qAbs(cursorX - _view.hover_point().x()) <= HitCursorMargin)
(*i)->paint(p, rect(), 1);
......@@ -212,7 +215,7 @@ void Viewport::paintProgress(QPainter &p)
using pv::view::Signal;
const quint64 _total_sample_len = _view.session().get_device()->get_sample_limit();
double progress = -(_total_receive_len * 1.0f / _total_sample_len * 360 * 16);
double progress = -(_total_receive_len * 1.0 / _total_sample_len * 360 * 16);
int captured_progress = 0;
p.setPen(Qt::gray);
......@@ -345,8 +348,9 @@ void Viewport::mousePressEvent(QMouseEvent *event)
if (_view.cursors_shown()) {
list<Cursor*>::iterator i = _view.get_cursorList().begin();
double cursorX;
const double samples_per_pixel = _view.session().get_device()->get_sample_rate() * _view.scale();
while (i != _view.get_cursorList().end()) {
cursorX = ((*i)->time() - _view.offset()) / _view.scale();
cursorX = (*i)->index()/samples_per_pixel - (_view.offset() / _view.scale());
if ((*i)->grabbed())
_view.get_ruler()->rel_grabbed_cursor();
else if (qAbs(cursorX - event->pos().x()) <= HitCursorMargin) {
......@@ -405,11 +409,11 @@ void Viewport::mouseMoveEvent(QMouseEvent *event)
if (_view.cursors_shown() && grabbed_marker) {
const double cur_time = _view.offset() + _view.hover_point().x() * _view.scale();
const double pos = cur_time * sample_rate;
const double pos_delta = pos - (int)pos;
const double pos_delta = pos - (uint64_t)pos;
if ( pos_delta < 0.5)
grabbed_marker->set_index(floor(pos));
grabbed_marker->set_index((uint64_t)floor(pos));
else
grabbed_marker->set_index(ceil(pos));
grabbed_marker->set_index((uint64_t)ceil(pos));
}
measure();
}
......@@ -519,7 +523,7 @@ void Viewport::measure()
_cur_thdX = _thd_sample / samples_per_pixel - pixels_offset;
_cur_midY = logicSig->get_y();
_mm_duty = _thd_sample != 0 ? QString::number((_nxt_sample - _cur_sample) * 100.0f / (_thd_sample - _cur_sample), 'f', 2)+"%" :
_mm_duty = _thd_sample != 0 ? QString::number((_nxt_sample - _cur_sample) * 100.0 / (_thd_sample - _cur_sample), 'f', 2)+"%" :
"#####";
mouse_measure();
return;
......@@ -554,18 +558,28 @@ void Viewport::paintMeasure(QPainter &p)
}
if (_measure_en) {
double typical_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, _mm_width).width() + 150;
QRectF measure_rect = QRectF(_view.hover_point().x(), _view.hover_point().y(),
(double)typical_width, 80.0);
QRectF measure1_rect = QRectF(_view.hover_point().x(), _view.hover_point().y(),
(double)typical_width, 20.0);
QRectF measure2_rect = QRectF(_view.hover_point().x(), _view.hover_point().y() + 20,
(double)typical_width, 20.0);
QRectF measure3_rect = QRectF(_view.hover_point().x(), _view.hover_point().y() + 40,
(double)typical_width, 20.0);
QRectF measure4_rect = QRectF(_view.hover_point().x(), _view.hover_point().y() + 60,
(double)typical_width, 20.0);
int typical_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, _mm_width).width();
typical_width = max(typical_width, p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, _mm_period).width());
typical_width = max(typical_width, p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, _mm_freq).width());
typical_width = max(typical_width, p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, _mm_duty).width());
typical_width = typical_width + 100;
const double width = _view.get_view_width();
const double height = _view.viewport()->height();
const double left = _view.hover_point().x();
const double top = _view.hover_point().y();
const double right = left + typical_width;
const double bottom = top + 80;
QPointF org_pos = QPointF(right > width ? left - typical_width : left, bottom > height ? top - 80 : top);
QRectF measure_rect = QRectF(org_pos.x(), org_pos.y(), (double)typical_width, 80.0);
QRectF measure1_rect = QRectF(org_pos.x(), org_pos.y(), (double)typical_width, 20.0);
QRectF measure2_rect = QRectF(org_pos.x(), org_pos.y()+20, (double)typical_width, 20.0);
QRectF measure3_rect = QRectF(org_pos.x(), org_pos.y()+40, (double)typical_width, 20.0);
QRectF measure4_rect = QRectF(org_pos.x(), org_pos.y()+60, (double)typical_width, 20.0);
p.setPen(Qt::NoPen);
p.setBrush(QColor(17, 133, 209, 150));
......
......@@ -251,7 +251,7 @@ static int fpga_setting(const struct sr_dev_inst *sdi)
(devc->instant << 9) + (devc->zero << 10);
setting.divider = devc->zero ? 0x1 : (uint32_t)ceil(SR_MHZ(100) * 1.0 / devc->cur_samplerate);
setting.count = (uint32_t)(devc->limit_samples / (channel_cnt / channel_en_cnt));
setting.trig_pos = (uint32_t)(trigger->trigger_pos / 100.0f * devc->limit_samples);
setting.trig_pos = (uint32_t)(trigger->trigger_pos / 100.0 * devc->limit_samples);
setting.trig_glb = trigger->trigger_stages;
setting.trig_adp = setting.count - setting.trig_pos - 1;
setting.trig_sda = 0x0;
......@@ -1485,7 +1485,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
struct sr_channel *probe = (struct sr_channel *)l->data;
channel_cnt += probe->enabled;
}
devc->trigger_hpos = g_variant_get_uint16(data) * channel_cnt * devc->limit_samples / 200.0f;
devc->trigger_hpos = g_variant_get_uint16(data) * channel_cnt * devc->limit_samples / 200.0;
if (sdi->mode == DSO) {
ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, 1, SR_CONF_HORIZ_TRIGGERPOS));
}
......@@ -2001,7 +2001,7 @@ static unsigned int get_number_of_transfers(struct DSL_context *devc)
total_buffer_time * to_bytes_per_ms(devc));
/* Total buffer size should be able to hold about 500ms of data. */
//n = 500 * to_bytes_per_ms(devc) / get_buffer_size(devc);
n = ceil(total_size * 1.0f / get_buffer_size(devc));
n = ceil(total_size * 1.0 / get_buffer_size(devc));
if (n > NUM_SIMUL_TRANSFERS)
return NUM_SIMUL_TRANSFERS;
......
......@@ -289,7 +289,7 @@ static int fpga_setting(const struct sr_dev_inst *sdi)
(devc->instant << 9) + (devc->zero << 10);
setting.divider = devc->zero ? 0x1 : (uint32_t)ceil(SR_MHZ(100) * 1.0 / devc->cur_samplerate);
setting.count = (sdi->mode == DSO) ? (uint32_t)(devc->limit_samples / (channel_cnt / channel_en_cnt)) : (uint32_t)(devc->limit_samples);
setting.trig_pos = (uint32_t)(trigger->trigger_pos / 100.0f * devc->limit_samples);
setting.trig_pos = (uint32_t)(trigger->trigger_pos / 100.0 * devc->limit_samples);
setting.trig_glb = trigger->trigger_stages;
setting.trig_adp = setting.count - setting.trig_pos - 1;
setting.trig_sda = 0x0;
......@@ -1574,9 +1574,9 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
struct sr_channel *probe = (struct sr_channel *)l->data;
channel_cnt += probe->enabled;
}
devc->trigger_hpos = g_variant_get_uint16(data) * channel_cnt * devc->limit_samples / 200.0f;
devc->trigger_hpos = g_variant_get_uint16(data) * channel_cnt * devc->limit_samples / 200.0;
} else {
devc->trigger_hpos = g_variant_get_uint16(data) * devc->limit_samples / 100.0f;
devc->trigger_hpos = g_variant_get_uint16(data) * devc->limit_samples / 100.0;
}
if (sdi->mode == DSO) {
ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, 1, SR_CONF_HORIZ_TRIGGERPOS));
......
......@@ -601,8 +601,8 @@ static void samples_generator(uint16_t *buf, uint64_t size,
case PATTERN_TRIANGLE:
for (i = 0; i < size; i++) {
if (i%CONST_LEN == 0) {
demo_data = p > 0x7fff ? 0x40 * (1 + (0x8000 - p * 1.0f) / 0x8000) :
0x40 * (p * 1.0f / 0x8000);
demo_data = p > 0x7fff ? 0x40 * (1 + (0x8000 - p * 1.0) / 0x8000) :
0x40 * (p * 1.0 / 0x8000);
p += CONST_LEN * 10;
}
*(buf + i) = demo_data + (demo_data << 8);
......@@ -654,7 +654,7 @@ static void samples_generator(uint16_t *buf, uint64_t size,
case PATTERN_RANDOM: /* Random */
for (i = 0; i < size; i++) {
if (i%CONST_LEN == 0)
demo_data = (uint16_t)(rand() * (0x40 * 1.0f / RAND_MAX));
demo_data = (uint16_t)(rand() * (0x40 * 1.0 / RAND_MAX));
*(buf + i) = demo_data + (demo_data << 8);
GSList *l;
struct sr_channel *probe;
......
......@@ -33,6 +33,9 @@ struct context {
char separator;
gboolean header_done;
int *channel_index;
uint64_t mask;
uint64_t pre_data;
uint64_t index;
};
/*
......@@ -62,6 +65,8 @@ static int init(struct sr_output *o, GHashTable *options)
ctx = g_malloc0(sizeof(struct context));
o->priv = ctx;
ctx->separator = ',';
ctx->mask = 0;
ctx->index = 0;
/* Get the number of channels, and the unitsize. */
for (l = o->sdi->channels; l; l = l->next) {
......@@ -82,6 +87,7 @@ static int init(struct sr_output *o, GHashTable *options)
if (!ch->enabled)
continue;
ctx->channel_index[i++] = ch->index;
ctx->mask |= (1 << ch->index);
}
return SR_OK;
......@@ -108,20 +114,8 @@ static GString *gen_header(const struct sr_output *o)
/* Columns / channels */
num_channels = g_slist_length(o->sdi->channels);
g_string_append_printf(header, "; Channels (%d/%d):",
g_string_append_printf(header, "; Channels (%d/%d)\n",
ctx->num_enabled_channels, num_channels);
for (i = 0, l = o->sdi->channels; l; l = l->next, i++) {
ch = l->data;
if (ch->type != SR_CHANNEL_LOGIC)
continue;
if (!ch->enabled)
continue;
g_string_append_printf(header, " %s,", ch->name);
}
if (o->sdi->channels)
/* Drop last separator. */
g_string_truncate(header, header->len - 1);
g_string_append_printf(header, "\n");
if (ctx->samplerate == 0) {
if (sr_config_get(o->sdi->driver, o->sdi, NULL, NULL, SR_CONF_SAMPLERATE,
......@@ -136,6 +130,20 @@ static GString *gen_header(const struct sr_output *o)
g_free(samplerate_s);
}
g_string_append_printf(header, "Time(s),");
for (i = 0, l = o->sdi->channels; l; l = l->next, i++) {
ch = l->data;
if (ch->type != SR_CHANNEL_LOGIC)
continue;
if (!ch->enabled)
continue;
g_string_append_printf(header, " %s,", ch->name);
}
if (o->sdi->channels)
/* Drop last separator. */
g_string_truncate(header, header->len - 1);
g_string_append_printf(header, "\n");
return header;
}
......@@ -177,18 +185,19 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
}
for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
for (j = 0; j < ctx->num_enabled_channels; j++) {
ctx->index++;
if (ctx->index > 1 && (*(uint64_t *)(logic->data + i) & ctx->mask) == ctx->pre_data)
continue;
g_string_append_printf(*out, "%0.10g", (ctx->index-1)*1.0/ctx->samplerate);
for (j = 0; j < ctx->num_enabled_channels; j++) {
idx = ctx->channel_index[j];
p = logic->data + i + idx / 8;
c = *p & (1 << (idx % 8));
g_string_append_c(*out, c ? '1' : '0');
g_string_append_c(*out, ctx->separator);
}
if (j) {
/* Drop last separator. */
g_string_truncate(*out, (*out)->len - 1);
g_string_append_c(*out, ctx->separator);
g_string_append_c(*out, c ? '1' : '0');
}
g_string_append_printf(*out, "\n");
ctx->pre_data = (*(uint64_t *)(logic->data + i) & ctx->mask);
}
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment