]> sigrok.org Git - pulseview.git/commitdiff
Continue work on SRD_OUTPUT_LOGIC
authorSoeren Apel <redacted>
Tue, 3 Mar 2020 21:23:05 +0000 (22:23 +0100)
committerSoeren Apel <redacted>
Sat, 13 Feb 2021 21:37:41 +0000 (22:37 +0100)
pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/data/decodesignal.cpp
pv/data/logicsegment.cpp

index b1cf42d5d0edfa7810670500d444df3eead3848e..ebcbc1c9bfa45a2c25e297becd0e243910f90596 100644 (file)
@@ -341,7 +341,7 @@ const vector<DecoderLogicOutputChannel> Decoder::logic_output_channels() const
                        (srd_decoder_logic_output_channel*)l->data;
 
                result.emplace_back(QString::fromUtf8(ch_data->id),
                        (srd_decoder_logic_output_channel*)l->data;
 
                result.emplace_back(QString::fromUtf8(ch_data->id),
-                       QString::fromUtf8(ch_data->desc), ch_data->samplerate);
+                       QString::fromUtf8(ch_data->desc));
        }
 
        return result;
        }
 
        return result;
index e86deccdcfc1a38c1097f1c2f7b886259687e160..ac1052e62c9dfcb1cc270455686bfc0b619e003f 100644 (file)
@@ -90,10 +90,9 @@ struct DecodeChannel
 };
 
 struct DecoderLogicOutputChannel {
 };
 
 struct DecoderLogicOutputChannel {
-       DecoderLogicOutputChannel (QString id, QString desc, uint64_t sr) :
-               id(id), desc(desc), samplerate(sr) {};
+       DecoderLogicOutputChannel (QString id, QString desc) :
+               id(id), desc(desc) {};
        QString id, desc;
        QString id, desc;
-       uint64_t samplerate;
 };
 
 struct DecodeBinaryClassInfo
 };
 
 struct DecodeBinaryClassInfo
index 9decbe302fe5892864b9c083ad36e28d37d0f3ff..2de6fbeedd8dff0f266d17caad65125fa0e78817 100644 (file)
@@ -168,6 +168,10 @@ void DecodeSignal::reset_decode(bool shutting_down)
        current_segment_id_ = 0;
        segments_.clear();
 
        current_segment_id_ = 0;
        segments_.clear();
 
+       for (const shared_ptr<decode::Decoder>& dec : stack_)
+               if (dec->has_logic_output())
+                       output_logic_[dec->get_srd_decoder()]->clear();
+
        logic_mux_data_.reset();
        logic_mux_data_invalid_ = true;
 
        logic_mux_data_.reset();
        logic_mux_data_invalid_ = true;
 
@@ -380,11 +384,11 @@ void DecodeSignal::update_output_signals()
 
                        if (!ch_exists) {
                                shared_ptr<Logic> logic_data = make_shared<Logic>(logic_channels.size());
 
                        if (!ch_exists) {
                                shared_ptr<Logic> logic_data = make_shared<Logic>(logic_channels.size());
-                               logic_data->set_samplerate(first_ch.samplerate);
+                               logic_data->set_samplerate(get_samplerate());
                                output_logic_[dec->get_srd_decoder()] = logic_data;
 
                                shared_ptr<LogicSegment> logic_segment = make_shared<data::LogicSegment>(
                                output_logic_[dec->get_srd_decoder()] = logic_data;
 
                                shared_ptr<LogicSegment> logic_segment = make_shared<data::LogicSegment>(
-                                       *logic_data, 0, (logic_data->num_channels() + 7) / 8, first_ch.samplerate);
+                                       *logic_data, 0, (logic_data->num_channels() + 7) / 8, get_samplerate());
                                logic_data->push_segment(logic_segment);
 
                                uint index = 0;
                                logic_data->push_segment(logic_segment);
 
                                uint index = 0;
@@ -399,12 +403,17 @@ void DecodeSignal::update_output_signals()
                                        session_.add_generated_signal(signal);
                                        index++;
                                }
                                        session_.add_generated_signal(signal);
                                        index++;
                                }
+                       } else {
+                               shared_ptr<Logic> logic_data = output_logic_[dec->get_srd_decoder()];
+                               logic_data->set_samplerate(get_samplerate());
+                               for (shared_ptr<LogicSegment>& segment : logic_data->logic_segments())
+                                       segment->set_samplerate(get_samplerate());
                        }
                }
        }
 
        // TODO Delete signals that no longer have a corresponding decoder (also from session)
                        }
                }
        }
 
        // TODO Delete signals that no longer have a corresponding decoder (also from session)
-       // TODO Check whether all sample rates are the same as the session's
+       // TODO Assert that all sample rates are the same as the session's
        // TODO Set colors to the same as the decoder's background color
 }
 
        // TODO Set colors to the same as the decoder's background color
 }
 
@@ -1417,6 +1426,9 @@ void DecodeSignal::start_srd_session()
                return;
        }
 
                return;
        }
 
+       // Update the samplerates for the output logic channels
+       update_output_signals();
+
        // Create the session
        srd_session_new(&srd_session_);
        assert(srd_session_);
        // Create the session
        srd_session_new(&srd_session_);
        assert(srd_session_);
@@ -1733,16 +1745,20 @@ void DecodeSignal::logic_output_callback(srd_proto_data *pdata, void *decode_sig
                last_segment = dynamic_pointer_cast<LogicSegment>(segments.back());
        else {
                // Happens when the data was cleared - all segments are gone then
                last_segment = dynamic_pointer_cast<LogicSegment>(segments.back());
        else {
                // Happens when the data was cleared - all segments are gone then
+               // segment_id is always 0 as it's the first segment
                last_segment = make_shared<data::LogicSegment>(
                        *output_logic, 0, (output_logic->num_channels() + 7) / 8, output_logic->get_samplerate());
                output_logic->push_segment(last_segment);
        }
 
                last_segment = make_shared<data::LogicSegment>(
                        *output_logic, 0, (output_logic->num_channels() + 7) / 8, output_logic->get_samplerate());
                output_logic->push_segment(last_segment);
        }
 
-       last_segment->append_subsignal_payload(pdl->logic_class, (void*)pdl->data, pdl->size);
+       vector<uint8_t> data;
+       for (unsigned int i = pdata->start_sample; i < pdata->end_sample; i++)
+               data.emplace_back(*((uint8_t*)pdl->data));
+
+       last_segment->append_subsignal_payload(pdl->logic_class, data.data(), data.size());
 
 
-       qInfo() << "Received" << pdl->size << "bytes /" << pdl->size \
-               << "samples of logic output for class" << pdl->logic_class << "from decoder" \
-               << QString::fromUtf8(decc->name);
+       qInfo() << "Received logic output state change for class" << pdl->logic_class << "from decoder" \
+               << QString::fromUtf8(decc->name) << "from" << pdata->start_sample << "to" << pdata->end_sample;
 }
 
 void DecodeSignal::on_capture_state_changed(int state)
 }
 
 void DecodeSignal::on_capture_state_changed(int state)
index 354c14f85d8bef035fd3a184757aabfb5d304c0b..d02a23a28ad7856262b3f889e599a896404dcfbf 100644 (file)
@@ -365,18 +365,22 @@ void LogicSegment::append_payload(void *data, uint64_t data_size)
 
 void LogicSegment::append_subsignal_payload(unsigned int index, void *data, uint64_t data_size)
 {
 
 void LogicSegment::append_subsignal_payload(unsigned int index, void *data, uint64_t data_size)
 {
-       static vector<uint8_t> merged_data;  // Using static also places it on the heap
+       static vector<uint8_t> merged_data;  // To preserve intermediate data across calls
 
 
-       for (uint64_t i = 0; i < data_size * unit_size_; i++)
-               merged_data.emplace_back(0);
+       if (index == 0)
+               for (uint64_t i = 0; i < data_size * unit_size_; i++)
+                       merged_data.emplace_back(0);
 
        // Set the bits for this sub-signal where needed
        // Note: the bytes in *data must either be 0 or 1, nothing else
 
        // Set the bits for this sub-signal where needed
        // Note: the bytes in *data must either be 0 or 1, nothing else
-       unsigned int index_byte = index / 8;
+       unsigned int index_byte_offs = index / 8;
+       uint8_t* output_data = merged_data.data() + index_byte_offs;
+       uint8_t* input_data = (uint8_t*)data;
+
        for (uint64_t i = 0; i < data_size; i++) {
        for (uint64_t i = 0; i < data_size; i++) {
-               unsigned int offs = i * unit_size_ + index_byte;
-               uint8_t* data_byte = merged_data.data() + offs;
-               *data_byte |= *((uint8_t*)data + i) << index;
+               assert((i * unit_size_ + index_byte_offs) < merged_data.size());
+               *output_data |= (input_data[i] << index);
+               output_data += unit_size_;
        }
 
        if (index == owner_.num_channels() - 1) {
        }
 
        if (index == owner_.num_channels() - 1) {