X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=2de6fbeedd8dff0f266d17caad65125fa0e78817;hb=883041605ce8536ece950b1de191cfe71068dfba;hp=a3525922943a878b5d051fbdb724eb44a9f2100a;hpb=04b0467582d8dfa989bb38fe18bfb1be20cea456;p=pulseview.git diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index a3525922..2de6fbee 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -168,6 +168,10 @@ void DecodeSignal::reset_decode(bool shutting_down) current_segment_id_ = 0; segments_.clear(); + for (const shared_ptr& dec : stack_) + if (dec->has_logic_output()) + output_logic_[dec->get_srd_decoder()]->clear(); + logic_mux_data_.reset(); logic_mux_data_invalid_ = true; @@ -370,7 +374,7 @@ void DecodeSignal::update_output_signals() dec->logic_output_channels(); // All signals of a decoder share the same LogicSegment, so it's - // sufficient to check for the first channel only + // sufficient to check for only the first channel const decode::DecoderLogicOutputChannel& first_ch = logic_channels[0]; bool ch_exists = false; @@ -380,10 +384,11 @@ void DecodeSignal::update_output_signals() if (!ch_exists) { shared_ptr logic_data = make_shared(logic_channels.size()); + logic_data->set_samplerate(get_samplerate()); output_logic_[dec->get_srd_decoder()] = logic_data; shared_ptr logic_segment = make_shared( - *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; @@ -398,12 +403,17 @@ void DecodeSignal::update_output_signals() session_.add_generated_signal(signal); index++; } + } else { + shared_ptr logic_data = output_logic_[dec->get_srd_decoder()]; + logic_data->set_samplerate(get_samplerate()); + for (shared_ptr& segment : logic_data->logic_segments()) + segment->set_samplerate(get_samplerate()); } } } // 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 } @@ -1416,6 +1426,9 @@ void DecodeSignal::start_srd_session() return; } + // Update the samplerates for the output logic channels + update_output_signals(); + // Create the session srd_session_new(&srd_session_); assert(srd_session_); @@ -1723,15 +1736,29 @@ void DecodeSignal::logic_output_callback(srd_proto_data *pdata, void *decode_sig assert(pdl); shared_ptr output_logic = ds->output_logic_.at(decc); - shared_ptr last_segment = - dynamic_pointer_cast(output_logic->segments().back()); - assert(last_segment); - last_segment->append_subsignal_payload(pdl->logic_class, (void*)pdl->data, pdl->size); + vector< shared_ptr > segments = output_logic->segments(); + + shared_ptr last_segment; + + if (!segments.empty()) + last_segment = dynamic_pointer_cast(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( + *output_logic, 0, (output_logic->num_channels() + 7) / 8, output_logic->get_samplerate()); + output_logic->push_segment(last_segment); + } + + vector 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)