namespace pv {
namespace data {
-DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack) :
+DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack,
+ const unordered_set< shared_ptr<data::SignalBase> > &all_signals) :
SignalBase(nullptr, SignalBase::DecodeChannel),
- decoder_stack_(decoder_stack)
+ decoder_stack_(decoder_stack),
+ all_signals_(all_signals)
{
set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name));
update_channel_list();
+ auto_assign_signals();
connect(decoder_stack_.get(), SIGNAL(new_annotations()),
this, SLOT(on_new_annotations()));
assert(decoder);
assert(decoder_stack);
decoder_stack_->push(make_shared<data::decode::Decoder>(decoder));
+
+ // Include the newly created decode channels in the channel list
update_channel_list();
+
+ auto_assign_signals();
decoder_stack_->begin_decode();
}
return channels_;
}
+void DecodeSignal::auto_assign_signals()
+{
+ // Try to auto-select channels that don't have signals assigned yet
+ for (data::DecodeChannel &ch : channels_) {
+ if (ch.assigned_signal)
+ continue;
+
+ for (shared_ptr<data::SignalBase> s : all_signals_)
+ if (s->logic_data() && (ch.name.toLower().contains(s->name().toLower())))
+ ch.assigned_signal = s.get();
+ }
+}
+
void DecodeSignal::assign_signal(const uint16_t channel_id, const SignalBase *signal)
{
for (data::DecodeChannel &ch : channels_)
#ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
#define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
+#include <unordered_set>
#include <vector>
#include <QString>
#include <pv/data/signalbase.hpp>
using std::list;
+using std::unordered_set;
using std::vector;
using std::shared_ptr;
Q_OBJECT
public:
- DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack);
+ DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack,
+ const unordered_set< shared_ptr<data::SignalBase> > &all_signals);
virtual ~DecodeSignal();
bool is_decode_signal() const;
QString error_message() const;
const list<data::DecodeChannel> get_channels() const;
+ void auto_assign_signals();
void assign_signal(const uint16_t channel_id, const SignalBase *signal);
void set_initial_pin_state(const uint16_t channel_id, const int init_state);
private:
shared_ptr<pv::data::DecoderStack> decoder_stack_;
+ const unordered_set< shared_ptr<data::SignalBase> > &all_signals_;
list<data::DecodeChannel> channels_;
};
// Create the decoder
decoder_stack = make_shared<data::DecoderStack>(*this, dec);
- // Make a list of all the channels
- vector<const srd_channel*> all_channels;
- for (const GSList *i = dec->channels; i; i = i->next)
- all_channels.push_back((const srd_channel*)i->data);
- for (const GSList *i = dec->opt_channels; i; i = i->next)
- all_channels.push_back((const srd_channel*)i->data);
-
- // Auto select the initial channels
- for (const srd_channel *pdch : all_channels)
- for (shared_ptr<data::SignalBase> b : signalbases_) {
- if (b->logic_data()) {
- if (QString::fromUtf8(pdch->name).toLower().
- contains(b->name().toLower()))
- channels[pdch] = b;
- }
- }
-
assert(decoder_stack);
assert(!decoder_stack->stack().empty());
assert(decoder_stack->stack().front());
// Create the decode signal
shared_ptr<data::DecodeSignal> signal =
- make_shared<data::DecodeSignal>(decoder_stack);
+ make_shared<data::DecodeSignal>(decoder_stack, signalbases_);
signalbases_.insert(signal);