Commit a5ead175 authored by DreamSourceLab's avatar DreamSourceLab

Add region decode feature

parent f0aff5e7
......@@ -93,11 +93,32 @@ void Decoder::set_option(const char *id, GVariant *value)
_setted = true;
}
void Decoder::set_decode_region(uint64_t start, uint64_t end)
{
_decode_start_back = start;
_decode_end_back = end;
if (_decode_start != start ||
_decode_end != end)
_setted = true;
}
uint64_t Decoder::decode_start() const
{
return _decode_start;
}
uint64_t Decoder::decode_end() const
{
return _decode_end;
}
bool Decoder::commit()
{
if (_setted) {
_probes = _probes_back;
_options = _options_back;
_decode_start = _decode_start_back;
_decode_end = _decode_end_back;
_setted = false;
return true;
} else {
......
......@@ -73,6 +73,10 @@ public:
std::set< boost::shared_ptr<pv::data::Logic> > get_data();
void set_decode_region(uint64_t start, uint64_t end);
uint64_t decode_start() const;
uint64_t decode_end() const;
bool commit();
private:
......@@ -88,6 +92,9 @@ private:
_probes_back;
std::map<std::string, GVariant*> _options_back;
uint64_t _decode_start, _decode_end;
uint64_t _decode_start_back, _decode_end_back;
bool _setted;
};
......
......@@ -333,43 +333,83 @@ boost::optional<uint64_t> DecoderStack::wait_for_data() const
_sample_count);
}
//void DecoderStack::decode_data(
// const uint64_t sample_count, const unsigned int unit_size,
// srd_session *const session)
//{
// //uint8_t chunk[DecodeChunkLength];
// uint8_t *chunk = NULL;
// //chunk = (uint8_t *)realloc(chunk, DecodeChunkLength);
// const uint64_t chunk_sample_count =
// DecodeChunkLength / _snapshot->unit_size();
// for (uint64_t i = 0;
// !boost::this_thread::interruption_requested() &&
// i < sample_count;
// i += chunk_sample_count)
// {
// //lock_guard<mutex> decode_lock(_global_decode_mutex);
// const uint64_t chunk_end = min(
// i + chunk_sample_count, sample_count);
// chunk = _snapshot->get_samples(i, chunk_end);
// if (srd_session_send(session, i, i + sample_count, chunk,
// (chunk_end - i) * unit_size, unit_size) != SRD_OK) {
// _error_message = tr("Decoder reported an error");
// break;
// }
// {
// lock_guard<mutex> lock(_output_mutex);
// _samples_decoded = chunk_end;
// }
// if (i % DecodeNotifyPeriod == 0)
// new_decode_data();
// }
// _options_changed = false;
// decode_done();
// //new_decode_data();
//}
void DecoderStack::decode_data(
const uint64_t sample_count, const unsigned int unit_size,
srd_session *const session)
const uint64_t decode_start, const uint64_t decode_end,
const unsigned int unit_size, srd_session *const session)
{
//uint8_t chunk[DecodeChunkLength];
uint8_t *chunk = NULL;
//chunk = (uint8_t *)realloc(chunk, DecodeChunkLength);
const uint64_t chunk_sample_count =
DecodeChunkLength / _snapshot->unit_size();
DecodeChunkLength / _snapshot->unit_size();
for (uint64_t i = 0;
!boost::this_thread::interruption_requested() &&
i < sample_count;
i += chunk_sample_count)
{
for (uint64_t i = decode_start;
!boost::this_thread::interruption_requested() &&
i < decode_end;
i += chunk_sample_count)
{
//lock_guard<mutex> decode_lock(_global_decode_mutex);
const uint64_t chunk_end = min(
i + chunk_sample_count, sample_count);
i + chunk_sample_count, decode_end);
chunk = _snapshot->get_samples(i, chunk_end);
if (srd_session_send(session, i, i + sample_count, chunk,
if (srd_session_send(session, i, chunk_end, chunk,
(chunk_end - i) * unit_size, unit_size) != SRD_OK) {
_error_message = tr("Decoder reported an error");
break;
}
_error_message = tr("Decoder reported an error");
break;
}
{
lock_guard<mutex> lock(_output_mutex);
_samples_decoded = chunk_end;
}
{
lock_guard<mutex> lock(_output_mutex);
_samples_decoded = chunk_end - decode_start + 1;
}
if (i % DecodeNotifyPeriod == 0)
new_decode_data();
}
}
_options_changed = false;
decode_done();
//new_decode_data();
......@@ -382,6 +422,8 @@ void DecoderStack::decode_proc()
optional<uint64_t> sample_count;
srd_session *session;
srd_decoder_inst *prev_di = NULL;
uint64_t decode_start;
uint64_t decode_end;
assert(_snapshot);
......@@ -409,6 +451,8 @@ void DecoderStack::decode_proc()
srd_inst_stack (session, prev_di, di);
prev_di = di;
decode_start = dec->decode_start();
decode_end = min(dec->decode_end(), _snapshot->get_sample_count());
}
// Get the intial sample count
......@@ -429,7 +473,8 @@ void DecoderStack::decode_proc()
// do {
// decode_data(*sample_count, unit_size, session);
// } while(_error_message.isEmpty() && (sample_count = wait_for_data()));
decode_data(*sample_count, unit_size, session);
//decode_data(*sample_count, unit_size, session);
decode_data(decode_start, decode_end, unit_size, session);
// Destroy the session
srd_session_destroy(session);
......@@ -439,7 +484,10 @@ void DecoderStack::decode_proc()
uint64_t DecoderStack::sample_count() const
{
return _sample_count;
if (_snapshot)
return _snapshot->get_sample_count();
else
return 0;
}
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
......
......@@ -125,7 +125,10 @@ public:
private:
boost::optional<uint64_t> wait_for_data() const;
void decode_data(const uint64_t sample_count,
// void decode_data(const uint64_t sample_count,
// const unsigned int unit_size, srd_session *const session);
void decode_data(const uint64_t decode_start, const uint64_t decode_end,
const unsigned int unit_size, srd_session *const session);
void decode_proc();
......
......@@ -134,7 +134,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) :
connect(_t3_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(delta_update()));
connect(_fen_checkBox, SIGNAL(stateChanged(int)), &_view, SLOT(set_measure_en(int)));
connect(_view.get_viewport(), SIGNAL(mouse_measure()), this, SLOT(mouse_measure()));
connect(_view.get_viewport(), SIGNAL(measure_updated()), this, SLOT(measure_updated()));
this->setWidget(_widget);
_widget->setGeometry(0, 0, sizeHint().width(), 2000);
......@@ -220,7 +220,7 @@ void MeasureDock::cursor_update()
update();
}
void MeasureDock::mouse_measure()
void MeasureDock::measure_updated()
{
_width_label->setText(_view.get_viewport()->get_measure("width"));
_period_label->setText(_view.get_viewport()->get_measure("period"));
......
......@@ -74,7 +74,7 @@ private slots:
public slots:
void cursor_update();
void cursor_moved();
void mouse_measure();
void measure_updated();
private:
SigSession &_session;
......
......@@ -1104,6 +1104,9 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
_cur_logic_snapshot.reset();
_cur_dso_snapshot.reset();
_cur_analog_snapshot.reset();
BOOST_FOREACH(const boost::shared_ptr<view::DecodeTrace> d, _decode_traces)
d->frame_ended();
}
frame_ended();
......@@ -1287,6 +1290,13 @@ bool SigSession::add_decoder(srd_decoder *const dec)
boost::shared_ptr<view::DecodeTrace> d(
new view::DecodeTrace(*this, decoder_stack,
_decode_traces.size()));
// set view early for decode start/end region setting
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) {
if (s->get_view()) {
d->set_view(s->get_view());
break;
}
}
if (d->create_popup()) {
_decode_traces.push_back(d);
ret = true;
......
......@@ -58,7 +58,7 @@ AnalogSignal::AnalogSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
_data(data)
{
_colour = SignalColours[probe->index % countof(SignalColours)];
_scale = _signalHeight * 1.0f / 65536;
_scale = _totalHeight * 1.0f / 65536;
}
AnalogSignal::~AnalogSignal()
......@@ -81,7 +81,7 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right)
assert(_view);
assert(right >= left);
const int y = get_y() + _signalHeight * 0.5;
const int y = get_y() + _totalHeight * 0.5;
const double scale = _view->scale();
assert(scale > 0);
const double offset = _view->offset();
......@@ -91,7 +91,7 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right)
if (snapshots.empty())
return;
_scale = _signalHeight * 1.0f / 65536;
_scale = _totalHeight * 1.0f / 65536;
const boost::shared_ptr<pv::data::AnalogSnapshot> &snapshot =
snapshots.front();
......
This diff is collapsed.
......@@ -89,6 +89,10 @@ private:
static const QColor OutlineColours[16];
static const int DefaultFontSize = 8;
static const int ControlRectWidth = 5;
static const QString RegionStart;
static const QString RegionEnd;
public:
DecodeTrace(pv::SigSession &session,
......@@ -132,6 +136,11 @@ public:
QRectF get_rect(DecodeSetRegions type, int y, int right);
/**
* decode region
**/
void frame_ended();
protected:
void paint_type_options(QPainter &p, int right, const QPoint pt);
......@@ -191,11 +200,16 @@ private slots:
void on_decode_done();
void on_region_set(int index);
private:
pv::SigSession &_session;
boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
uint64_t _decode_start, _decode_end;
int _start_index, _end_index;
int _start_count, _end_count;
QComboBox *_start_comboBox, *_end_comboBox;
std::list< boost::shared_ptr<pv::prop::binding::DecoderOptions> >
_bindings;
......
......@@ -51,7 +51,7 @@ GroupSignal::GroupSignal(QString name, boost::shared_ptr<data::Group> data,
_data(data)
{
_colour = SignalColours[probe_index_list.front() % countof(SignalColours)];
_scale = _signalHeight * 1.0f / std::pow(2.0, static_cast<double>(probe_index_list.size()));
_scale = _totalHeight * 1.0f / std::pow(2.0, static_cast<double>(probe_index_list.size()));
}
GroupSignal::~GroupSignal()
......@@ -79,12 +79,12 @@ void GroupSignal::paint_mid(QPainter &p, int left, int right)
assert(_view);
assert(right >= left);
const int y = get_y() + _signalHeight * 0.5;
const int y = get_y() + _totalHeight * 0.5;
const double scale = _view->scale();
assert(scale > 0);
const double offset = _view->offset();
_scale = _signalHeight * 1.0f / std::pow(2.0, static_cast<int>(_index_list.size()));
_scale = _totalHeight * 1.0f / std::pow(2.0, static_cast<int>(_index_list.size()));
const deque< boost::shared_ptr<pv::data::GroupSnapshot> > &snapshots =
_data->get_snapshots();
......
......@@ -148,12 +148,12 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right)
assert(_view);
assert(right >= left);
const int y = get_y() + _signalHeight * 0.5;
const int y = get_y() + _totalHeight * 0.5;
const double scale = _view->scale();
assert(scale > 0);
const double offset = _view->offset();
const float high_offset = y - _signalHeight + 0.5f;
const float high_offset = y - _totalHeight + 0.5f;
const float low_offset = y + 0.5f;
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
......@@ -314,7 +314,7 @@ void LogicSignal::paint_type_options(QPainter &p, int right, const QPoint pt)
bool LogicSignal::measure(const QPointF &p, uint64_t &index0, uint64_t &index1, uint64_t &index2) const
{
const float gap = abs(p.y() - get_y());
if (gap < get_signalHeight() * 0.5) {
if (gap < get_totalHeight() * 0.5) {
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
_data->get_snapshots();
if (snapshots.empty())
......@@ -359,7 +359,7 @@ bool LogicSignal::edges(const QPointF &p, uint64_t start, uint64_t &rising, uint
{
uint64_t index, end;
const float gap = abs(p.y() - get_y());
if (gap < get_signalHeight() * 0.5) {
if (gap < get_totalHeight() * 0.5) {
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
_data->get_snapshots();
if (snapshots.empty())
......
......@@ -59,7 +59,7 @@ Trace::Trace(QString name, uint16_t index, int type) :
_v_offset(INT_MAX),
_type(type),
_sec_index(0),
_signalHeight(30)
_totalHeight(30)
{
_index_list.push_back(index);
}
......@@ -71,7 +71,7 @@ Trace::Trace(QString name, std::list<int> index_list, int type, int sec_index) :
_type(type),
_index_list(index_list),
_sec_index(sec_index),
_signalHeight(30)
_totalHeight(30)
{
}
......@@ -84,7 +84,7 @@ Trace::Trace(const Trace &t) :
_index_list(t._index_list),
_sec_index(t._sec_index),
_old_v_offset(t._old_v_offset),
_signalHeight(t._signalHeight),
_totalHeight(t._totalHeight),
_text_size(t._text_size)
{
}
......@@ -167,14 +167,14 @@ int Trace::get_zeroPos()
return _v_offset - _view->v_offset();
}
int Trace::get_signalHeight() const
int Trace::get_totalHeight() const
{
return _signalHeight;
return _totalHeight;
}
void Trace::set_signalHeight(int height)
void Trace::set_totalHeight(int height)
{
_signalHeight = height;
_totalHeight = height;
}
void Trace::set_view(pv::view::View *view)
......@@ -183,6 +183,11 @@ void Trace::set_view(pv::view::View *view)
_view = view;
}
pv::view::View* Trace::get_view() const
{
return _view;
}
void Trace::paint_back(QPainter &p, int left, int right)
{
QPen pen(Signal::dsGray);
......
......@@ -127,12 +127,12 @@ public:
/**
* Gets the height of this signal.
*/
int get_signalHeight() const;
int get_totalHeight() const;
/**
* Sets the height of this signal.
*/
void set_signalHeight(int height);
void set_totalHeight(int height);
/**
* Geom
......@@ -159,6 +159,7 @@ public:
virtual bool enabled() const = 0;
virtual void set_view(pv::view::View *view);
pv::view::View* get_view() const;
/**
* Paints the background layer of the trace with a QPainter
......@@ -291,7 +292,7 @@ protected:
std::list<int> _index_list;
int _sec_index;
int _old_v_offset;
int _signalHeight;
int _totalHeight;
QSizeF _text_size;
};
......
......@@ -501,7 +501,7 @@ void View::signals_changed()
BOOST_FOREACH(boost::shared_ptr<Trace> t, traces) {
t->set_view(this);
const double traceHeight = _signalHeight*t->rows_size();
t->set_signalHeight((int)traceHeight);
t->set_totalHeight((int)traceHeight);
t->set_v_offset(next_v_offset + 0.5 * traceHeight + SignalMargin);
next_v_offset += traceHeight + 2 * SignalMargin;
}
......
This diff is collapsed.
......@@ -54,13 +54,30 @@ public:
static const int DsoMeasureStages = 3;
static const double MinorDragRateUp;
static const double DragDamping;
enum ActionType {
NO_ACTION,
CURS_MOVE,
LOGIC_EDGE,
LOGIC_MOVE,
LOGIC_ZOOM,
DSO_XM_STEP0,
DSO_XM_STEP1,
DSO_XM_STEP2,
DSO_XM_STEP3,
DSO_YM,
DSO_TRIG_MOVE,
DECODE_REGION
};
enum MeasureType {
NO_MEASURE,
LOGIC_FREQ,
LOGIC_EDGE,
LOGIC_MOVE,
LOGIC_CURS,
DSO_FREQ
LOGIC_EDGE_CNT,
DSO_VALUE
};
public:
......@@ -103,7 +120,7 @@ private slots:
void set_receive_len(quint64 length);
signals:
void mouse_measure();
void measure_updated();
private:
View &_view;
......@@ -118,11 +135,8 @@ private:
QPixmap pixmap;
bool _zoom_rect_visible;
QRectF _zoom_rect;
bool _measure_en;
bool _measure_shown;
ActionType _action_type;
MeasureType _measure_type;
uint64_t _cur_sample;
uint64_t _nxt_sample;
......@@ -158,13 +172,11 @@ private:
QTimer _drag_timer;
int _drag_strength;
bool _dso_xm;
int _dso_xm_stage;
bool _dso_xm_valid;
int _dso_xm_y;
uint64_t _dso_xm_index[DsoMeasureStages];
bool _dso_ym;
bool _dso_ym_done;
bool _dso_ym_valid;
uint16_t _dso_ym_sig_index;
double _dso_ym_sig_value;
uint64_t _dso_ym_index;
......
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