pv/data/decoderstack.cpp
pv/data/decode/annotation.cpp
pv/data/decode/decoder.cpp
+ pv/data/decode/row.cpp
+ pv/data/decode/rowdata.cpp
pv/prop/binding/decoderoptions.cpp
pv/view/decodetrace.cpp
pv/widgets/decodergroupbox.cpp
assert(pda);
_format = pda->ann_format;
- _row = 0;
const char *const *annotations = (char**)pda->ann_text;
while(*annotations) {
return _format;
}
-int Annotation::row() const
-{
- return _row;
-}
-
-int Annotation::pd_index() const
-{
- return _pd_index;
-}
-
const std::vector<QString>& Annotation::annotations() const
{
return _annotations;
}
-void Annotation::set_row(int row)
-{
- _row = row;
-}
-
-void Annotation::set_pd_index(int pd_index)
-{
- _pd_index = pd_index;
-}
-
} // namespace decode
} // namespace data
} // namespace pv
uint64_t start_sample() const;
uint64_t end_sample() const;
int format() const;
- int row() const;
- int pd_index() const;
const std::vector<QString>& annotations() const;
void set_row(int row);
uint64_t _start_sample;
uint64_t _end_sample;
int _format;
- int _row;
- int _pd_index;
std::vector<QString> _annotations;
};
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 "row.h"
+
+namespace pv {
+namespace data {
+namespace decode {
+
+Row::Row() :
+ _decoder(NULL),
+ _row(NULL)
+{
+}
+
+Row::Row(const srd_decoder *decoder, const srd_decoder_annotation_row *row) :
+ _decoder(decoder),
+ _row(row)
+{
+}
+
+const srd_decoder* Row::decoder() const
+{
+ return _decoder;
+}
+
+const srd_decoder_annotation_row* Row::row() const
+{
+ return _row;
+}
+
+bool Row::operator<(const Row &other) const
+{
+ return (_decoder < other._decoder) ||
+ (_decoder == other._decoder && _row < other._row);
+}
+
+} // decode
+} // data
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 PULSEVIEW_PV_DATA_DECODE_ROW_H
+#define PULSEVIEW_PV_DATA_DECODE_ROW_H
+
+#include <vector>
+
+#include "annotation.h"
+
+struct srd_decoder;
+struct srd_decoder_annotation_row;
+
+namespace pv {
+namespace data {
+namespace decode {
+
+class Row
+{
+public:
+ Row();
+
+ Row(const srd_decoder *decoder,
+ const srd_decoder_annotation_row *row = NULL);
+
+ const srd_decoder* decoder() const;
+ const srd_decoder_annotation_row* row() const;
+
+ bool operator<(const Row &other) const;
+
+private:
+ const srd_decoder *_decoder;
+ const srd_decoder_annotation_row *_row;
+};
+
+} // decode
+} // data
+} // pv
+
+#endif // PULSEVIEW_PV_DATA_DECODE_ROW_H
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <assert.h>
+
+#include "rowdata.h"
+
+using std::vector;
+
+namespace pv {
+namespace data {
+namespace decode {
+
+RowData::RowData()
+{
+}
+
+uint64_t RowData::get_max_sample() const
+{
+ if (_annotations.empty())
+ return 0;
+ return _annotations.back().end_sample();
+}
+
+void RowData::get_annotation_subset(
+ std::vector<pv::data::decode::Annotation> &dest,
+ uint64_t start_sample, uint64_t end_sample) const
+{
+ const vector<size_t>::const_iterator start_iter =
+ lower_bound(_ann_end_index.begin(),
+ _ann_end_index.end(), start_sample,
+ bind(&RowData::index_entry_end_sample_lt,
+ this, _1, _2));
+
+ const vector<size_t>::const_iterator end_iter =
+ upper_bound(_ann_start_index.begin(),
+ _ann_start_index.end(), end_sample,
+ bind(&RowData::index_entry_start_sample_gt,
+ this, _1, _2));
+
+ for (vector<size_t>::const_iterator i = start_iter;
+ i != _ann_end_index.end() && *i != *end_iter; i++)
+ dest.push_back(_annotations[*i]);
+}
+
+void RowData::push_annotation(const Annotation &a)
+{
+ const size_t offset = _annotations.size();
+ _annotations.push_back(a);
+
+ // Insert the annotation into the start index
+ vector<size_t>::iterator i = _ann_start_index.end();
+ if (!_ann_start_index.empty() &&
+ _annotations[_ann_start_index.back()].start_sample() >
+ a.start_sample())
+ i = upper_bound(_ann_start_index.begin(),
+ _ann_start_index.end(), a.start_sample(),
+ bind(&RowData::index_entry_start_sample_gt,
+ this, _1, _2));
+
+ _ann_start_index.insert(i, offset);
+
+ // Insert the annotation into the end index
+ vector<size_t>::iterator j = _ann_end_index.end();
+ if (!_ann_end_index.empty() &&
+ _annotations[_ann_end_index.back()].end_sample() <
+ a.end_sample())
+ j = upper_bound(_ann_end_index.begin(),
+ _ann_end_index.end(), a.end_sample(),
+ bind(&RowData::index_entry_end_sample_gt,
+ this, _1, _2));
+
+ _ann_end_index.insert(j, offset);
+}
+
+bool RowData::index_entry_start_sample_gt(
+ const uint64_t sample, const size_t index) const
+{
+ assert(index < _annotations.size());
+ return _annotations[index].start_sample() > sample;
+}
+
+bool RowData::index_entry_end_sample_lt(
+ const size_t index, const uint64_t sample) const
+{
+ assert(index < _annotations.size());
+ return _annotations[index].end_sample() < sample;
+}
+
+bool RowData::index_entry_end_sample_gt(
+ const uint64_t sample, const size_t index) const
+{
+ assert(index < _annotations.size());
+ return _annotations[index].end_sample() > sample;
+}
+
+} // decode
+} // data
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 PULSEVIEW_PV_DATA_DECODE_ROWDATA_H
+#define PULSEVIEW_PV_DATA_DECODE_ROWDATA_H
+
+#include <vector>
+
+#include "annotation.h"
+
+namespace pv {
+namespace data {
+namespace decode {
+
+class RowData
+{
+public:
+ RowData();
+
+public:
+ uint64_t get_max_sample() const;
+
+ /**
+ * Extracts sorted annotations between two period into a vector.
+ */
+ void get_annotation_subset(
+ std::vector<pv::data::decode::Annotation> &dest,
+ uint64_t start_sample, uint64_t end_sample) const;
+
+ void push_annotation(const Annotation& a);
+
+private:
+ bool index_entry_start_sample_gt(
+ const uint64_t sample, const size_t index) const;
+ bool index_entry_end_sample_lt(
+ const size_t index, const uint64_t sample) const;
+ bool index_entry_end_sample_gt(
+ const uint64_t sample, const size_t index) const;
+
+private:
+ std::vector<Annotation> _annotations;
+
+ /**
+ * _ann_start_index and _ann_end_index contain lists of annotions
+ * (represented by offsets in the _annotations vector), sorted in
+ * ascending ordered by the start_sample and end_sample respectively.
+ */
+ std::vector<size_t> _ann_start_index, _ann_end_index;
+};
+
+}
+} // data
+} // pv
+
+#endif // PULSEVIEW_PV_DATA_DECODE_ROWDATA_H
#include <libsigrokdecode/libsigrokdecode.h>
-#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
using boost::mutex;
using boost::shared_ptr;
using std::deque;
+using std::make_pair;
+using std::max;
using std::min;
using std::list;
+using std::map;
+using std::pair;
using std::vector;
+using namespace pv::data::decode;
+
namespace pv {
namespace data {
void DecoderStack::remove(int index)
{
- using pv::data::decode::Decoder;
-
assert(index >= 0);
assert(index < (int)_stack.size());
return _samples_decoded;
}
+std::vector<Row> DecoderStack::get_rows() const
+{
+ lock_guard<mutex> lock(_mutex);
+
+ vector<Row> rows;
+
+ BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
+ {
+ assert(dec);
+ const srd_decoder *const decc = dec->decoder();
+ assert(dec->decoder());
+
+ // Add a row for the decoder if it doesn't have a row list
+ if (!decc->annotation_rows)
+ rows.push_back(Row(decc));
+
+ // Add the decoder rows
+ for (const GSList *l = decc->annotation_rows; l; l = l->next)
+ {
+ const srd_decoder_annotation_row *const ann_row =
+ (srd_decoder_annotation_row *)l->data;
+ assert(ann_row);
+ rows.push_back(Row(decc, ann_row));
+ }
+ }
+
+ return rows;
+}
+
void DecoderStack::get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
- uint64_t start_sample, uint64_t end_sample) const
+ const Row &row, uint64_t start_sample,
+ uint64_t end_sample) const
{
lock_guard<mutex> lock(_mutex);
- const vector<size_t>::const_iterator start_iter =
- lower_bound(_ann_end_index.begin(),
- _ann_end_index.end(), start_sample,
- bind(&DecoderStack::index_entry_end_sample_lt,
- this, _1, _2));
-
- const vector<size_t>::const_iterator end_iter =
- upper_bound(_ann_start_index.begin(),
- _ann_start_index.end(), end_sample,
- bind(&DecoderStack::index_entry_start_sample_gt,
- this, _1, _2));
-
- for (vector<size_t>::const_iterator i = start_iter;
- i != _ann_end_index.end() && *i != *end_iter; i++)
- dest.push_back(_annotations[*i]);
+ std::map<const Row, decode::RowData>::const_iterator iter =
+ _rows.find(row);
+ if (iter != _rows.end())
+ (*iter).second.get_annotation_subset(dest,
+ start_sample, end_sample);
}
QString DecoderStack::error_message()
return _error_message;
}
+void DecoderStack::clear()
+{
+ _samples_decoded = 0;
+ _error_message = QString();
+ _rows.clear();
+ _class_rows.clear();
+}
+
void DecoderStack::begin_decode()
{
shared_ptr<pv::view::LogicSignal> logic_signal;
_decode_thread.interrupt();
_decode_thread.join();
- _samples_decoded = 0;
-
clear();
+ // Add classes
+ BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
+ {
+ assert(dec);
+ const srd_decoder *const decc = dec->decoder();
+ assert(dec->decoder());
+
+ // Add a row for the decoder if it doesn't have a row list
+ if (!decc->annotation_rows)
+ _rows[Row(decc)] = decode::RowData();
+
+ // Add the decoder rows
+ for (const GSList *l = decc->annotation_rows; l; l = l->next)
+ {
+ const srd_decoder_annotation_row *const ann_row =
+ (srd_decoder_annotation_row *)l->data;
+ assert(ann_row);
+
+ const Row row(decc, ann_row);
+
+ // Add a new empty row data object
+ _rows[row] = decode::RowData();
+
+ // Map out all the classes
+ for (const GSList *ll = ann_row->ann_classes;
+ ll; ll = ll->next)
+ _class_rows[make_pair(decc,
+ GPOINTER_TO_INT(ll->data))] = row;
+ }
+ }
+
// We get the logic data of the first probe in the list.
// This works because we are currently assuming all
// LogicSignals have the same data/snapshot
data);
}
-void DecoderStack::clear()
-{
- _annotations.clear();
- _ann_start_index.clear();
- _ann_end_index.clear();
-}
-
uint64_t DecoderStack::get_max_sample_count() const
{
- if (_annotations.empty())
- return 0;
- return _annotations.back().end_sample();
+ uint64_t max_sample_count = 0;
+
+ for (map<const Row, RowData>::const_iterator i = _rows.begin();
+ i != _rows.end(); i++)
+ max_sample_count = max(max_sample_count,
+ (*i).second.get_max_sample());
+
+ return max_sample_count;
}
void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
const unsigned int chunk_sample_count =
DecodeChunkLength / snapshot->unit_size();
- // Clear error message upon every new session run
- _error_message = QString();
-
// Create the session
srd_session_new(&session);
assert(session);
srd_session_destroy(session);
}
-bool DecoderStack::index_entry_start_sample_gt(
- const uint64_t sample, const size_t index) const
-{
- assert(index < _annotations.size());
- return _annotations[index].start_sample() > sample;
-}
-
-bool DecoderStack::index_entry_end_sample_lt(
- const size_t index, const uint64_t sample) const
-{
- assert(index < _annotations.size());
- return _annotations[index].end_sample() < sample;
-}
-
-bool DecoderStack::index_entry_end_sample_gt(
- const uint64_t sample, const size_t index) const
-{
- assert(index < _annotations.size());
- return _annotations[index].end_sample() > sample;
-}
-
-void DecoderStack::insert_annotation_into_start_index(
- const pv::data::decode::Annotation &a, const size_t storage_offset)
-{
- vector<size_t>::iterator i = _ann_start_index.end();
- if (!_ann_start_index.empty() &&
- _annotations[_ann_start_index.back()].start_sample() >
- a.start_sample())
- i = upper_bound(_ann_start_index.begin(),
- _ann_start_index.end(), a.start_sample(),
- bind(&DecoderStack::index_entry_start_sample_gt,
- this, _1, _2));
-
- _ann_start_index.insert(i, storage_offset);
-}
-
-void DecoderStack::insert_annotation_into_end_index(
- const pv::data::decode::Annotation &a, const size_t storage_offset)
-{
- vector<size_t>::iterator i = _ann_end_index.end();
- if (!_ann_end_index.empty() &&
- _annotations[_ann_end_index.back()].end_sample() <
- a.end_sample())
- i = upper_bound(_ann_end_index.begin(),
- _ann_end_index.end(), a.end_sample(),
- bind(&DecoderStack::index_entry_end_sample_gt,
- this, _1, _2));
-
- _ann_end_index.insert(i, storage_offset);
-}
-
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
{
- using pv::data::decode::Annotation;
-
- GSList *l, *ll;
- int row, ann_class, idx = 0;
- struct srd_decoder_annotation_row *ann_row;
- struct srd_decoder *decc;
-
assert(pdata);
assert(decoder);
DecoderStack *const d = (DecoderStack*)decoder;
+ assert(d);
lock_guard<mutex> lock(d->_mutex);
- Annotation a = Annotation(pdata);
-
- decc = pdata->pdo->di->decoder;
- BOOST_FOREACH(const shared_ptr<decode::Decoder> &dec, d->stack()) {
- if (dec->decoder() == decc)
- break;
- idx++;
- }
- a.set_pd_index(idx);
-
- for (l = decc->annotation_rows, row = 0; l; l = l->next, row++)
+ const Annotation a(pdata);
+
+ // Find the row
+ assert(pdata->pdo);
+ assert(pdata->pdo->di);
+ const srd_decoder *const decc = pdata->pdo->di->decoder;
+ assert(decc);
+
+ map<const Row, decode::RowData>::iterator row_iter = d->_rows.end();
+
+ // Try looking up the sub-row of this class
+ const map<pair<const srd_decoder*, int>, Row>::const_iterator r =
+ d->_class_rows.find(make_pair(decc, a.format()));
+ if (r != d->_class_rows.end())
+ row_iter = d->_rows.find((*r).second);
+ else
{
- ann_row = (struct srd_decoder_annotation_row *)l->data;
-
- for (ll = ann_row->ann_classes, ann_class = 0; ll;
- ll = ll->next, ann_class++)
- {
- if (GPOINTER_TO_INT(ll->data) == a.format())
- a.set_row(row);
- }
+ // Failing that, use the decoder as a key
+ row_iter = d->_rows.find(Row(decc));
}
- const size_t offset = d->_annotations.size();
- d->_annotations.push_back(a);
+ assert(row_iter != d->_rows.end());
+ if (row_iter == d->_rows.end()) {
+ qDebug() << "Unexpected annotation: decoder = " << decc <<
+ ", format = " << a.format();
+ assert(0);
+ return;
+ }
- d->insert_annotation_into_start_index(a, offset);
- d->insert_annotation_into_end_index(a, offset);
+ // Add the annotation
+ (*row_iter).second.push_annotation(a);
d->new_decode_data();
}
#include <QObject>
#include <QString>
+#include <pv/data/decode/row.h>
+#include <pv/data/decode/rowdata.h>
+
struct srd_decoder;
+struct srd_decoder_annotation_row;
struct srd_probe;
struct srd_proto_data;
int64_t samples_decoded() const;
+ std::vector<decode::Row> get_rows() const;
+
/**
* Extracts sorted annotations between two period into a vector.
*/
void get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
- uint64_t start_sample, uint64_t end_sample) const;
+ const decode::Row &row, uint64_t start_sample,
+ uint64_t end_sample) const;
QString error_message();
private:
void decode_proc(boost::shared_ptr<data::Logic> data);
- bool index_entry_start_sample_gt(
- const uint64_t sample, const size_t index) const;
- bool index_entry_end_sample_lt(
- const size_t index, const uint64_t sample) const;
- bool index_entry_end_sample_gt(
- const uint64_t sample, const size_t index) const;
-
- void insert_annotation_into_start_index(
- const pv::data::decode::Annotation &a,
- const size_t storage_offset);
- void insert_annotation_into_end_index(
- const pv::data::decode::Annotation &a,
- const size_t storage_offset);
-
static void annotation_callback(srd_proto_data *pdata,
void *decoder);
mutable boost::mutex _mutex;
int64_t _samples_decoded;
- std::vector<pv::data::decode::Annotation> _annotations;
- /**
- * _ann_start_index and _ann_end_index contain lists of annotions
- * (represented by offsets in the _annotations vector), sorted in
- * ascending ordered by the start_sample and end_sample respectively.
- */
- std::vector<size_t> _ann_start_index, _ann_end_index;
+ std::map<const decode::Row, decode::RowData> _rows;
+
+ std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
QString _error_message;
void DecodeTrace::paint_mid(QPainter &p, int left, int right)
{
- using pv::data::decode::Annotation;
+ using namespace pv::data::decode;
const double scale = _view->scale();
assert(scale > 0);
samples_per_pixel, 0.0);
QFontMetrics m(QApplication::font());
- const int h = (m.boundingRect(QRect(), 0, "Tg").height() * 5) / 4;
+ const int text_height = m.boundingRect(QRect(), 0, "Tg").height();
+ const int annotation_height = (text_height * 5) / 4;
+ const int row_height = (text_height * 6) / 4;
assert(_decoder_stack);
const QString err = _decoder_stack->error_message();
if (!err.isEmpty())
{
draw_error(p, err, left, right);
- draw_unresolved_period(p, h, left, right, samples_per_pixel,
- pixels_offset);
+ draw_unresolved_period(p, annotation_height, left, right,
+ samples_per_pixel, pixels_offset);
return;
}
+ // Iterate through the rows
assert(_view);
- const int y = get_y();
+ int y = get_y();
assert(_decoder_stack);
- vector<Annotation> annotations;
- _decoder_stack->get_annotation_subset(annotations,
- start_sample, end_sample);
- BOOST_FOREACH(const Annotation &a, annotations)
+ const vector<Row> rows(_decoder_stack->get_rows());
+ BOOST_FOREACH (const Row &row, rows)
{
- // Every stacked PD is 60 pixels further down.
- int y_stack_offset = a.pd_index() * 60;
-
- // Every annotation row is 20 pixels further down.
- int y_ann_row_offset = a.row() * 20;
-
- draw_annotation(a, p, get_text_colour(), h, left, right,
- samples_per_pixel, pixels_offset,
- y + y_stack_offset + y_ann_row_offset);
+ vector<Annotation> annotations;
+ _decoder_stack->get_annotation_subset(annotations, row,
+ start_sample, end_sample);
+ if (!annotations.empty()) {
+ BOOST_FOREACH(const Annotation &a, annotations)
+ draw_annotation(a, p, get_text_colour(),
+ annotation_height, left, right,
+ samples_per_pixel, pixels_offset, y);
+ y += row_height;
+ }
}
- draw_unresolved_period(p, h, left, right,
+ // Draw the hatching
+ draw_unresolved_period(p, annotation_height, left, right,
samples_per_pixel, pixels_offset);
}