Commit 9eb36b33 authored by DreamSourceLab's avatar DreamSourceLab
Browse files

v0.4 release

parent 5d7e3237
/*
* 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 DSLOGIC_PV_DATA_DECODE_ROWDATA_H
#define DSLOGIC_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;
uint64_t get_max_annotation() 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:
uint64_t _max_annotation;
std::vector<Annotation> _annotations;
};
}
} // data
} // pv
#endif // DSLOGIC_PV_DATA_DECODE_ROWDATA_H
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2012 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 <libsigrokdecode/libsigrokdecode.h>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <stdexcept>
#include <QDebug>
#include "decoderstack.h"
#include <pv/data/logic.h>
#include <pv/data/logicsnapshot.h>
#include <pv/data/decode/decoder.h>
#include <pv/data/decode/annotation.h>
#include <pv/sigsession.h>
#include <pv/view/logicsignal.h>
using boost::lock_guard;
using boost::mutex;
using boost::optional;
using boost::shared_ptr;
using boost::unique_lock;
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 {
const double DecoderStack::DecodeMargin = 1.0;
const double DecoderStack::DecodeThreshold = 0.2;
const int64_t DecoderStack::DecodeChunkLength = 1024 * 1024;
const unsigned int DecoderStack::DecodeNotifyPeriod = 1;
mutex DecoderStack::_global_decode_mutex;
DecoderStack::DecoderStack(pv::SigSession &session,
const srd_decoder *const dec) :
_session(session),
_sample_count(0),
_frame_complete(false),
_samples_decoded(0),
_decode_state(Stopped),
_options_changed(false)
{
connect(&_session, SIGNAL(frame_began()),
this, SLOT(on_new_frame()));
connect(&_session, SIGNAL(data_received()),
this, SLOT(on_data_received()));
connect(&_session, SIGNAL(frame_ended()),
this, SLOT(on_frame_ended()));
_stack.push_back(shared_ptr<decode::Decoder>(
new decode::Decoder(dec)));
}
DecoderStack::~DecoderStack()
{
// if (_decode_thread.joinable()) {
// _decode_thread.interrupt();
// _decode_thread.join();
// }
stop_decode();
}
const std::list< boost::shared_ptr<decode::Decoder> >&
DecoderStack::stack() const
{
return _stack;
}
void DecoderStack::push(boost::shared_ptr<decode::Decoder> decoder)
{
assert(decoder);
_stack.push_back(decoder);
}
void DecoderStack::remove(int index)
{
assert(index >= 0);
assert(index < (int)_stack.size());
// Find the decoder in the stack
list< shared_ptr<Decoder> >::iterator iter = _stack.begin();
for(int i = 0; i < index; i++, iter++)
assert(iter != _stack.end());
// Delete the element
_stack.erase(iter);
}
int64_t DecoderStack::samples_decoded() const
{
lock_guard<mutex> decode_lock(_output_mutex);
return _samples_decoded;
}
std::vector< std::pair<decode::Row, bool> > DecoderStack::get_visible_rows() const
{
lock_guard<mutex> lock(_output_mutex);
std::vector< std::pair<decode::Row, bool> > 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(make_pair(Row(decc), dec->shown()));
// 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(make_pair(Row(decc, ann_row), dec->shown()));
}
}
return rows;
}
void DecoderStack::get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
const Row &row, uint64_t start_sample,
uint64_t end_sample) const
{
lock_guard<mutex> lock(_output_mutex);
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);
}
uint64_t DecoderStack::get_max_annotation(const Row &row)
{
lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
if (iter != _rows.end())
return (*iter).second.get_max_annotation();
return 0;
}
bool DecoderStack::has_annotations(const Row &row) const
{
lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
if (iter != _rows.end())
if(0 == (*iter).second.get_max_sample())
return false;
else
return true;
else
return false;
}
QString DecoderStack::error_message()
{
lock_guard<mutex> lock(_output_mutex);
return _error_message;
}
void DecoderStack::clear()
{
_sample_count = 0;
_frame_complete = false;
_samples_decoded = 0;
_error_message = QString();
_rows.clear();
_class_rows.clear();
}
void DecoderStack::stop_decode()
{
if(_decode_state == Stopped)
return;
if (_decode_thread.get()) {
_decode_thread->interrupt();
_decode_thread->join();
_decode_state = Stopped;
}
_decode_thread.reset();
}
void DecoderStack::begin_decode()
{
shared_ptr<pv::view::LogicSignal> logic_signal;
shared_ptr<pv::data::Logic> data;
if (!_options_changed)
return;
// if (_decode_thread.joinable()) {
// _decode_thread.interrupt();
// _decode_thread.join();
// }
stop_decode();
clear();
// Check that all decoders have the required channels
BOOST_FOREACH(const shared_ptr<decode::Decoder> &dec, _stack)
if (!dec->have_required_probes()) {
_error_message = tr("One or more required channels "
"have not been specified");
return;
}
// 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 channel in the list.
// This works because we are currently assuming all
// LogicSignals have the same data/snapshot
BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
if (dec && !dec->channels().empty() &&
((logic_signal = (*dec->channels().begin()).second)) &&
((data = logic_signal->logic_data())))
break;
if (!data)
return;
// Check we have a snapshot of data
const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots =
data->get_snapshots();
if (snapshots.empty())
return;
_snapshot = snapshots.front();
// Get the samplerate and start time
_start_time = data->get_start_time();
_samplerate = data->samplerate();
if (_samplerate == 0.0)
_samplerate = 1.0;
//_decode_thread = boost::thread(&DecoderStack::decode_proc, this);
_decode_thread.reset(new boost::thread(&DecoderStack::decode_proc, this));
}
uint64_t DecoderStack::get_max_sample_count() const
{
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;
}
boost::optional<uint64_t> DecoderStack::wait_for_data() const
{
unique_lock<mutex> input_lock(_input_mutex);
while(!boost::this_thread::interruption_requested() &&
!_frame_complete && (uint64_t)_samples_decoded >= _sample_count)
_input_cond.wait(input_lock);
return boost::make_optional(
!boost::this_thread::interruption_requested() &&
((uint64_t)_samples_decoded < _sample_count || !_frame_complete),
_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);
_snapshot->get_samples(chunk, i, chunk_end);
if (srd_session_send(session, i, i + sample_count, chunk,
(chunk_end - i) * 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_proc()
{
lock_guard<mutex> decode_lock(_global_decode_mutex);
optional<uint64_t> sample_count;
srd_session *session;
srd_decoder_inst *prev_di = NULL;
assert(_snapshot);
// Create the session
srd_session_new(&session);
assert(session);
_decode_state = Running;
// Create the decoders
const unsigned int unit_size = _snapshot->unit_size();
BOOST_FOREACH(const shared_ptr<decode::Decoder> &dec, _stack)
{
srd_decoder_inst *const di = dec->create_decoder_inst(session, unit_size);
if (!di)
{
_error_message = tr("Failed to create decoder instance");
srd_session_destroy(session);
return;
}
if (prev_di)
srd_inst_stack (session, prev_di, di);
prev_di = di;
}
// Get the intial sample count
{
unique_lock<mutex> input_lock(_input_mutex);
sample_count = _sample_count = _snapshot->get_sample_count();
}
// Start the session
srd_session_metadata_set(session, SRD_CONF_SAMPLERATE,
g_variant_new_uint64((uint64_t)_samplerate));
srd_pd_output_callback_add(session, SRD_OUTPUT_ANN,
DecoderStack::annotation_callback, this);
srd_session_start(session);
// do {
// decode_data(*sample_count, unit_size, session);
// } while(_error_message.isEmpty() && (sample_count = wait_for_data()));
decode_data(*sample_count, unit_size, session);
// Destroy the session
srd_session_destroy(session);
_decode_state = Stopped;
}
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
{
assert(pdata);
assert(decoder);
DecoderStack *const d = (DecoderStack*)decoder;
assert(d);
lock_guard<mutex> lock(d->_output_mutex);
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
{
// Failing that, use the decoder as a key
row_iter = d->_rows.find(Row(decc));
}
assert(row_iter != d->_rows.end());
if (row_iter == d->_rows.end()) {
qDebug() << "Unexpected annotation: decoder = " << decc <<
", format = " << a.format();
assert(0);
return;
}
// Add the annotation
(*row_iter).second.push_annotation(a);
}
void DecoderStack::on_new_frame()
{
//begin_decode();
}
void DecoderStack::on_data_received()
{
// {
// unique_lock<mutex> lock(_input_mutex);
// if (_snapshot)
// _sample_count = _snapshot->get_sample_count();
// }
// _input_cond.notify_one();
}
void DecoderStack::on_frame_ended()
{
// {
// unique_lock<mutex> lock(_input_mutex);
// if (_snapshot)
// _frame_complete = true;
// }
// _input_cond.notify_one();
_options_changed = true;
begin_decode();
}
int DecoderStack::cur_rows_size()
{
int rows_size = 0;
for (map<const Row, RowData>::const_iterator i = _rows.begin();
i != _rows.end(); i++)
if ((*i).second.get_max_sample() != 0)
rows_size++;
if (rows_size == 0)
return 1;
else
return rows_size;
}
void DecoderStack::options_changed(bool changed)
{
_options_changed = changed;
}
} // namespace data
} // namespace pv
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2012 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 DSLOGIC_PV_DATA_DECODERSTACK_H
#define DSLOGIC_PV_DATA_DECODERSTACK_H
#include "signaldata.h"
#include <list>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#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_channel;
struct srd_proto_data;
struct srd_session;
namespace DecoderStackTest {
class TwoDecoderStack;
}
namespace pv {
class SigSession;
namespace view {
class LogicSignal;
}
namespace data {
class LogicSnapshot;
namespace decode {
class Annotation;
class Decoder;
}
class Logic;
class DecoderStack : public QObject, public SignalData
{
Q_OBJECT
private:
static const double DecodeMargin;
static const double DecodeThreshold;
static const int64_t DecodeChunkLength;
static const unsigned int DecodeNotifyPeriod;
public:
enum decode_state {
Stopped,
Running
};
public:
DecoderStack(pv::SigSession &_session,
const srd_decoder *const decoder);
virtual ~DecoderStack();
const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
void push(boost::shared_ptr<decode::Decoder> decoder);
void remove(int index);
int64_t samples_decoded() const;
std::vector< std::pair<decode::Row, bool> > get_visible_rows() const;
/**
* Extracts sorted annotations between two period into a vector.
*/
void get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
const decode::Row &row, uint64_t start_sample,
uint64_t end_sample) const;
uint64_t get_max_annotation(const decode::Row &row);
bool has_annotations(const decode::Row &row) const;
QString error_message();
void clear();
uint64_t get_max_sample_count() const;
void begin_decode();
void stop_decode();
int cur_rows_size();
void options_changed(bool changed);
private:
boost::optional<uint64_t> wait_for_data() const;
void decode_data(const uint64_t sample_count,
const unsigned int unit_size, srd_session *const session);
void decode_proc();
static void annotation_callback(srd_proto_data *pdata,
void *decoder);
private slots:
void on_new_frame();
void on_data_received();
void on_frame_ended();
signals:
void new_decode_data();
void decode_done();
private:
pv::SigSession &_session;
/**
* This mutex prevents more than one decode operation occuring
* concurrently.
* @todo A proper solution should be implemented to allow multiple
* decode operations.
*/
static boost::mutex _global_decode_mutex;
std::list< boost::shared_ptr<decode::Decoder> > _stack;
boost::shared_ptr<pv::data::LogicSnapshot> _snapshot;
mutable boost::mutex _input_mutex;
mutable boost::condition_variable _input_cond;
uint64_t _sample_count;
bool _frame_complete;
mutable boost::mutex _output_mutex;
int64_t _samples_decoded;
std::map<const decode::Row, decode::RowData> _rows;
std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
QString _error_message;
std::auto_ptr<boost::thread> _decode_thread;
decode_state _decode_state;
bool _options_changed;
friend class DecoderStackTest::TwoDecoderStack;
};
} // namespace data
} // namespace pv
#endif // DSLOGIC_PV_DATA_DECODERSTACK_H
......@@ -29,8 +29,8 @@ using namespace std;
namespace pv {
namespace data {
Dso::Dso(unsigned int num_probes, uint64_t samplerate) :
SignalData(num_probes, samplerate)
Dso::Dso(int num_probes) :
SignalData(num_probes)
{
}
......@@ -44,5 +44,10 @@ deque< boost::shared_ptr<DsoSnapshot> >& Dso::get_snapshots()
return _snapshots;
}
void Dso::clear()
{
_snapshots.clear();
}
} // namespace data
} // namespace pv
......@@ -36,7 +36,7 @@ class DsoSnapshot;
class Dso : public SignalData
{
public:
Dso(unsigned int num_probes, uint64_t samplerate);
Dso(int num_probes);
void push_snapshot(
boost::shared_ptr<DsoSnapshot> &snapshot);
......@@ -44,6 +44,8 @@ public:
std::deque< boost::shared_ptr<DsoSnapshot> >&
get_snapshots();
void clear();
private:
std::deque< boost::shared_ptr<DsoSnapshot> > _snapshots;
};
......
......@@ -73,6 +73,8 @@ void DsoSnapshot::append_payload(const sr_datafeed_dso &dso)
const uint8_t *DsoSnapshot::get_samples(
int64_t start_sample, int64_t end_sample, uint16_t index) const
{
(void)end_sample;
assert(start_sample >= 0);
assert(start_sample < (int64_t)get_sample_count());
assert(end_sample >= 0);
......
......@@ -30,8 +30,8 @@ using namespace std;
namespace pv {
namespace data {
Group::Group(unsigned int num_probes, uint64_t samplerate) :
SignalData(num_probes, samplerate)
Group::Group() :
SignalData()
{
}
......@@ -45,5 +45,10 @@ deque< boost::shared_ptr<GroupSnapshot> >& Group::get_snapshots()
return _snapshots;
}
void Group::clear()
{
_snapshots.clear();
}
} // namespace data
} // namespace pv
......@@ -37,7 +37,7 @@ class GroupSnapshot;
class Group : public SignalData
{
public:
Group(unsigned int num_probes, uint64_t samplerate);
Group();
void push_snapshot(
boost::shared_ptr<GroupSnapshot> &snapshot);
......@@ -45,6 +45,8 @@ public:
std::deque< boost::shared_ptr<GroupSnapshot> >&
get_snapshots();
void clear();
private:
std::deque< boost::shared_ptr<GroupSnapshot> > _snapshots;
};
......
......@@ -59,7 +59,7 @@ GroupSnapshot::GroupSnapshot(const boost::shared_ptr<LogicSnapshot> &_logic_snap
memset(_envelope_levels, 0, sizeof(_envelope_levels));
_data = _logic_snapshot->get_data();
_sample_count = _logic_snapshot->get_sample_count();
_unit_size = _logic_snapshot->get_unit_size();
_unit_size = _logic_snapshot->unit_size();
_index_list = index_list;
append_payload();
}
......
......@@ -30,10 +30,9 @@ using namespace std;
namespace pv {
namespace data {
Logic::Logic(unsigned int num_probes, uint64_t samplerate) :
SignalData(num_probes, samplerate)
Logic::Logic(int num_probes) :
SignalData(num_probes)
{
assert(_num_probes > 0);
}
void Logic::push_snapshot(
......@@ -47,5 +46,10 @@ deque< boost::shared_ptr<LogicSnapshot> >& Logic::get_snapshots()
return _snapshots;
}
void Logic::clear()
{
_snapshots.clear();
}
} // namespace data
} // namespace pv
......@@ -37,7 +37,9 @@ class LogicSnapshot;
class Logic : public SignalData
{
public:
Logic(unsigned int num_probes, uint64_t samplerate);
Logic(int num_probes);
int get_num_probes() const;
void push_snapshot(
boost::shared_ptr<LogicSnapshot> &snapshot);
......@@ -45,6 +47,8 @@ public:
std::deque< boost::shared_ptr<LogicSnapshot> >&
get_snapshots();
void clear();
private:
std::deque< boost::shared_ptr<LogicSnapshot> > _snapshots;
};
......
......@@ -74,6 +74,22 @@ void LogicSnapshot::append_payload(
append_payload_to_mipmap();
}
void LogicSnapshot::get_samples(uint8_t *const data,
int64_t start_sample, int64_t end_sample) const
{
assert(data);
assert(start_sample >= 0);
assert(start_sample <= (int64_t)_sample_count);
assert(end_sample >= 0);
assert(end_sample <= (int64_t)_sample_count);
assert(start_sample <= end_sample);
//lock_guard<recursive_mutex> lock(_mutex);
const size_t size = (end_sample - start_sample) * _unit_size;
memcpy(data, (const uint8_t*)_data + start_sample * _unit_size, size);
}
void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m)
{
const uint64_t new_data_length = ((m.length + MipMapDataUnit - 1) /
......@@ -170,14 +186,6 @@ void LogicSnapshot::append_payload_to_mipmap()
}
}
uint64_t LogicSnapshot::get_sample(uint64_t index) const
{
assert(_data);
assert(index < _sample_count);
return *(uint64_t*)((uint8_t*)_data + index * _unit_size);
}
void LogicSnapshot::get_subsampled_edges(
std::vector<EdgePair> &edges,
uint64_t start, uint64_t end,
......@@ -194,6 +202,9 @@ void LogicSnapshot::get_subsampled_edges(
assert(sig_index >= 0);
assert(sig_index < 64);
if (!_data)
return;
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
const uint64_t block_length = (uint64_t)max(min_length, 1.0f);
......
......@@ -67,7 +67,8 @@ public:
void append_payload(const sr_datafeed_logic &logic);
uint64_t get_sample(uint64_t index) const;
void get_samples(uint8_t *const data,
int64_t start_sample, int64_t end_sample) const;
private:
void reallocate_mipmap_level(MipMapLevel &m);
......
......@@ -20,27 +20,31 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <assert.h>
#include "signaldata.h"
namespace pv {
namespace data {
SignalData::SignalData(unsigned int num_probes, double samplerate) :
_num_probes(num_probes),
_samplerate(samplerate),
_start_time(0)
SignalData::SignalData(int num_probes) :
_samplerate(0),
_start_time(0),
_num_probes(num_probes)
{
assert(num_probes >= 0);
}
int SignalData::get_num_probes() const
double SignalData::samplerate() const
{
return _num_probes;
return _samplerate;
}
double SignalData::get_samplerate() const
void SignalData::set_samplerate(double samplerate)
{
return _samplerate;
assert(samplerate > 0);
_samplerate = samplerate;
clear();
}
double SignalData::get_start_time() const
......@@ -48,5 +52,16 @@ double SignalData::get_start_time() const
return _start_time;
}
int SignalData::get_num_probes() const
{
return _num_probes;
}
void SignalData::set_num_probes(int num)
{
assert(num >= 0);
_num_probes = num;
}
} // namespace data
} // namespace pv
......@@ -32,17 +32,24 @@ namespace data {
class SignalData
{
public:
SignalData(unsigned int num_probes, double samplerate);
SignalData(int num_probes = 1);
public:
double get_samplerate() const;
double samplerate() const;
void set_samplerate(double samplerate);
virtual void clear() = 0;
double get_start_time() const;
int get_num_probes() const;
void set_num_probes(int num);
protected:
const unsigned int _num_probes;
const double _samplerate;
const double _start_time;
double _samplerate;
double _start_time;
int _num_probes;
};
} // namespace data
......
......@@ -54,6 +54,7 @@ Snapshot::~Snapshot()
int Snapshot::init(uint64_t _total_sample_len)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
_data = malloc(_total_sample_len * _unit_size +
sizeof(uint64_t));
......@@ -83,7 +84,7 @@ void* Snapshot::get_data() const
return _data;
}
int Snapshot::get_unit_size() const
int Snapshot::unit_size() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
return _unit_size;
......@@ -95,6 +96,16 @@ unsigned int Snapshot::get_channel_num() const
return _channel_num;
}
uint64_t Snapshot::get_sample(uint64_t index) const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
assert(_data);
assert(index < _sample_count);
return *(uint64_t*)((uint8_t*)_data + index * _unit_size);
}
void Snapshot::append_data(void *data, uint64_t samples)
{
// boost::lock_guard<boost::recursive_mutex> lock(_mutex);
......
......@@ -44,12 +44,14 @@ public:
void * get_data() const;
int get_unit_size() const;
int unit_size() const;
bool buf_null() const;
unsigned int get_channel_num() const;
uint64_t get_sample(uint64_t index) const;
protected:
void append_data(void *data, uint64_t samples);
......
/*
* This file is part of the DSLogic-gui project.
* DSLogic-gui is based on PulseView.
*
* 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 <sstream>
#include <libsigrok4DSLogic/libsigrok.h>
#include "device.h"
using std::ostringstream;
using std::string;
namespace pv {
namespace device {
Device::Device(sr_dev_inst *sdi) :
_sdi(sdi)
{
assert(_sdi);
}
sr_dev_inst* Device::dev_inst() const
{
return _sdi;
}
void Device::use(SigSession *owner) throw(QString)
{
DevInst::use(owner);
sr_session_new();
assert(_sdi);
sr_dev_open(_sdi);
if (sr_session_dev_add(_sdi) != SR_OK)
throw QString(tr("Failed to use device."));
}
void Device::release()
{
if (_owner) {
DevInst::release();
sr_session_destroy();
}
sr_dev_close(_sdi);
}
std::string Device::format_device_title() const
{
ostringstream s;
assert(_sdi);
if (_sdi->vendor && _sdi->vendor[0]) {
s << _sdi->vendor;
if ((_sdi->model && _sdi->model[0]) ||
(_sdi->version && _sdi->version[0]))
s << ' ';
}
if (_sdi->model && _sdi->model[0]) {
s << _sdi->model;
if (_sdi->version && _sdi->version[0])
s << ' ';
}
if (_sdi->version && _sdi->version[0])
s << _sdi->version;
return s.str();
}
bool Device::is_trigger_enabled() const
{
assert(_sdi);
for (const GSList *l = _sdi->channels; l; l = l->next) {
const sr_channel *const p = (const sr_channel *)l->data;
assert(p);
if (p->trigger && p->trigger[0] != '\0')
return true;
}
return false;
}
} // device
} // pv
/*
* This file is part of the DSLogic-gui project.
* DSLogic-gui is based on PulseView.
*
* 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 DSLOGIC_PV_DEVICE_DEVICE_H
#define DSLOGIC_PV_DEVICE_DEVICE_H
#include "devinst.h"
namespace pv {
namespace device {
class Device : public DevInst
{
public:
Device(sr_dev_inst *dev_inst);
sr_dev_inst* dev_inst() const;
void use(SigSession *owner) throw(QString);
void release();
std::string format_device_title() const;
bool is_trigger_enabled() const;
private:
sr_dev_inst *const _sdi;
};
} // device
} // pv
#endif // DSLOGIC_PV_DEVICE_DEVICE_H
/*
* This file is part of the DSLogic-gui project.
* DSLogic-gui is based on PulseView.
*
* 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 <cassert>
#include <QDebug>
#include <libsigrok4DSLogic/libsigrok.h>
#include "devinst.h"
#include <pv/sigsession.h>
namespace pv {
namespace device {
DevInst::DevInst() :
_owner(NULL)
{
_id = malloc(1);
}
DevInst::~DevInst()
{
assert(_id);
free(_id);
}
void* DevInst::get_id() const
{
assert(_id);
return _id;
}
void DevInst::use(SigSession *owner) throw(QString)
{
assert(owner);
assert(!_owner);
_owner = owner;
}
void DevInst::release()
{
if (_owner) {
_owner->release_device(this);
_owner = NULL;
}
}
SigSession* DevInst::owner() const
{
return _owner;
}
GVariant* DevInst::get_config(const sr_channel *ch, const sr_channel_group *group, int key)
{
GVariant *data = NULL;
assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if (sr_config_get(sdi->driver, sdi, ch, group, key, &data) != SR_OK)
return NULL;
return data;
}
bool DevInst::set_config(const sr_channel *ch, const sr_channel_group *group, int key, GVariant *data)
{
assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if(sr_config_set(sdi, ch, group, key, data) == SR_OK) {
config_changed();
return true;
}
return false;
}
GVariant* DevInst::list_config(const sr_channel_group *group, int key)
{
GVariant *data = NULL;
assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if (sr_config_list(sdi->driver, sdi, group, key, &data) != SR_OK)
return NULL;
return data;
}
void DevInst::enable_probe(const sr_channel *probe, bool enable)
{
assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
for (const GSList *p = sdi->channels; p; p = p->next)
if (probe == p->data) {
const_cast<sr_channel*>(probe)->enabled = enable;
config_changed();
return;
}
// Probe was not found in the device
assert(0);
}
uint64_t DevInst::get_sample_limit()
{
uint64_t sample_limit;
GVariant* gvar = get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES);
if (gvar != NULL) {
sample_limit = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else {
sample_limit = 0U;
}
return sample_limit;
}
uint64_t DevInst::get_sample_rate()
{
uint64_t sample_rate;
GVariant* gvar = get_config(NULL, NULL, SR_CONF_SAMPLERATE);
if (gvar != NULL) {
sample_rate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else {
sample_rate = 0U;
}
return sample_rate;
}
uint64_t DevInst::get_time_base()
{
uint64_t time_base;
GVariant* gvar = get_config(NULL, NULL, SR_CONF_TIMEBASE);
if (gvar != NULL) {
time_base = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else {
time_base = 0U;
}
return time_base;
}
double DevInst::get_sample_time()
{
uint64_t sample_rate = get_sample_rate();
uint64_t sample_limit = get_sample_limit();
double sample_time;
if (sample_rate == 0)
sample_time = 0;
else
sample_time = sample_limit * 1.0f / sample_rate;
return sample_time;
}
GSList* DevInst::get_dev_mode_list()
{
assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
return sr_dev_mode_list(sdi->driver);
}
bool DevInst::is_trigger_enabled() const
{
return false;
}
void DevInst::start()
{
if (sr_session_start() != SR_OK)
throw tr("Failed to start session.");
}
void DevInst::run()
{
sr_session_run();
}
} // device
} // pv
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