Commit Graph

263 Commits

Author SHA1 Message Date
Soeren Apel 7f894d958e Fix #1132 by passing segment IDs, not segment instances
Passing segment instances fails because this creates a race condition.
When a long conversion is taking place, the SignalBase::samples_added
signal is called often but since it's in a separate thread, the calls
are queued and aren't executed immediately. Now if the conversion is
restarted - for example as a result of a changed conversion threshold -
then the segments holding the converted data are destroyed, rendering
the pointers submitted as parameters to samples_added invalid.

Once the signal queue is processed, those invalid pointers will be
accessed and PV segfaults.

Since the signal queue can neither be emptied nor flushed, this
leaves only two sensible choices:
1) Signal samples_added less often, thereby reducing the chance of
signals being queued
2) Supply the segment ID instead of the segment instance as that's
essentially the only thing we currently care about - in fact, the
only user of samples_added (ViewBase::on_samples_added) uses the
instance to query only this

As #1 is only a band-aid and not a waterproof solution, I chose
to go with #2.
2018-03-05 23:45:46 +01:00
Soeren Apel b5d20c6d00 Fix #1089 by updating the signal labels and group labels
Group names currently don't change, so this doesn't do much
but they may change in the future, so it's useful to do anyway.
2018-02-08 16:32:19 +01:00
Gerhard Sittig 4349dc21e7 DecodeSignal: only pass non-zero sample rate to decoders
As reported in bug #1118 not all input sources provide a samplerate, and
decoder instances may not cope with a rate spec of 0. Only pass non-zero
sample rates to the decoder stack. This improves robustness in addition
to the specific fix for #1118 in the decoders' implementations.
2018-01-28 21:58:16 +01:00
Gerhard Sittig c5f9553c0b DecodeSignal: Void a session pointer after destroy() call
Fixup an error path when starting a created decoder session fails.
2018-01-11 21:42:45 +01:00
Soeren Apel 9009d9b5ca Session: Make get_segment_count() consider all segments
Also changes the type for the getters to uint32_t.
2018-01-10 00:34:39 +01:00
Soeren Apel 8c33974131 Supply the segment ID when adding samples to optimize trace painting
Use case is as follows:
- Capture 20+ segments with ~500kS each
- Afterwards, enable conversion for a channel

Without this change, the converted logic will be repainted
20++ times because we are only told that new samples were
added but not which segment.

With this change, the logic trace is only painted when we
see that samples were added to the segment we're showing.
2018-01-10 00:34:39 +01:00
Soeren Apel 85a702806a Add segment_id to all segment classes 2018-01-10 00:34:39 +01:00
Soeren Apel 4d08da71e2 LogicSegment: Don't use new/delete in get_unpacked_sample() 2018-01-10 00:34:39 +01:00
Soeren Apel 4cc0df94c1 LogicSegment: Limit end in get_subsampled_edges() if needed
This is necessary because there is a race condition between
adding samples and trace repainting.
2018-01-10 00:34:38 +01:00
Soeren Apel 2b3dda54bb SignalBase: Don't terminate conversion when there's no data
Instead of terminating, we wait instead.
We do this because SignalBase::on_samples_added() somehow doesn't
reliably see that there's no conversion thread active anymore.
conversion_thread_.joinable() returns true when the thread was
already terminated for whatever reason, resulting in on_samples_added()
trying to notify a non-existant thread.
2018-01-10 00:33:54 +01:00
Soeren Apel 558ad6ceb9 Implement Trace::ShowLastCompleteSegmentOnly display mode 2018-01-05 22:50:35 +01:00
Soeren Apel 65efd0258b DecodeSignal: Restructure metadata handling
Instead of handling the metadata separately from the mux/decode segments,
it's much neater to handle both together. Doing this also allows us to
remove the need for query_input_metadata() since we're taking the metadata
from the muxed logic segments.
2018-01-05 22:50:31 +01:00
Soeren Apel 63253d7271 SignalBase: Implement multi-segment conversion 2018-01-05 22:50:26 +01:00
Soeren Apel 8a603e135f Finalize segment decoding 2018-01-05 22:50:21 +01:00
Soeren Apel ed535cd705 DecodeSignal: Mux all segments 2018-01-05 22:48:45 +01:00
Soeren Apel 72435789a0 Prepare multi-segment protocol decoding ability 2017-12-27 18:40:19 +01:00
Soeren Apel ba5f21864c DecodeSignal: Allow muxed logic data to be cached 2017-12-27 18:40:19 +01:00
Soeren Apel f2f4845f15 DecodeSignal: Rename some items 2017-12-27 18:40:19 +01:00
Soeren Apel 5ecf957f9f Begin PD multisegment support 2017-12-27 18:40:19 +01:00
Soeren Apel aa71890d74 DecodeSignal: Make sure bit IDs are always up-to-date
https://www.youtube.com/watch?v=mw6Bd6Hv168 shows what
happens when this isn't done.
2017-12-13 14:03:59 +01:00
Philipp Marek a00f8221dc Session: Fix mismatched delete operator.
Mismatched free() / delete / delete []
   at 0x4C2D31B: operator delete(void*) (vg_replace_malloc.c:576)
   by 0x1C76D0: operator() (unique_ptr.h:78)
   by 0x1C76D0: ~unique_ptr (unique_ptr.h:268)
   by 0x1C76D0: pv::data::AnalogSegment::append_interleaved_samples(float const*, unsigned long, unsigned long) (analogsegment.cpp:78)
...
Address 0x1d123f70 is 0 bytes inside a block of size 312 alloc'd
   at 0x4C2C97F: operator new[](unsigned long) (vg_replace_malloc.c:423)
   by 0x1C765E: pv::data::AnalogSegment::append_interleaved_samples(float const*, unsigned long, unsigned long) (analogsegment.cpp:78)
   by 0x1AFDD5: pv::Session::feed_in_analog(std::shared_ptr<sigrok::Analog>) (session.cpp:1142)
2017-11-18 13:53:44 +01:00
Soeren Apel bc93f1ef2f Append new segments to the end, not the beginning of the list 2017-10-27 18:44:51 +02:00
Soeren Apel b8132c767b DecodeSignal: Remove outdated code and comment 2017-09-23 08:33:16 +02:00
Soeren Apel 8d3c0f7a0b SignalBase: Make sure PDs are restarted when conv options change 2017-09-22 21:13:48 +02:00
Soeren Apel eee3eab962 DecodeTrace: Reset cached trace properties when decoder stack resets 2017-09-22 21:13:48 +02:00
Soeren Apel 4913560f88 DecodeSignal: Break up annotation storage to allow multiple segments 2017-09-22 21:13:47 +02:00
Soeren Apel 7f9654641c Add segment selector UI + helpers 2017-09-22 20:58:16 +02:00
Uwe Hermann 1becee23bd rowdata: Use emplace_back() for Annotation objects.
This should eliminate one unnecessary allocation per annotation.
2017-09-22 12:03:14 +02:00
Soeren Apel 83b9c07b79 Rename DecodeSignal::segment_ to logic_mux_segment_ for clarity 2017-09-08 21:01:55 +02:00
Soeren Apel 6e7a4a0066 Fix #1024 by changing decode channel assigment to PDs
When assigning the decoder stack channels to the libsrd
instance's channels, channels that had no signal assigned
to them were still assigned anyway. This patch fixes this bug.

After doing this, another subtle bug became apparent:
The mapping between channels and bits in the data stream sent
to the PD was done via DecodeChannel->id. This is however
insufficient as the channels of the decoder stack have
IDs that may or may not match the ID needed for the data
stream. Example:

A PD has 4 channels: A, B, C and D. In PV, those channels
have the IDs 0, 1, 2 and 3. If the user only assigns A and D,
Decoder::create_decoder_inst() will use the IDs 0 and 3 as
the bit positions of those signals in the data stream sent
to libsrd. This is obviously wrong.

Hence, we now use a separate bit_id for this purpose.
2017-09-08 21:01:41 +02:00
Soeren Apel 753c8f08d8 SignalBase: Default to dynamic conversion preset, not custom values
The reason for this change is that when you initially select a
conversion from the channel config popup dialog, the threshold
will be set to "0.0V" or "0.0V/0.0V", respectively.
This is of course not what we want and the root cause is that
when no preset is selected, NoPreset is assumed instead of
DynamicPreset. This patch changes this.
2017-08-03 13:16:22 +02:00
Soeren Apel c6d9cf6582 Use min/max notification for autoranging of analog signals 2017-08-03 13:16:21 +02:00
Soeren Apel 932bc2461d Move delayed conversion starter to SignalBase
This way, we can use the same mechanism for changing
min/max as well, preventing multiple successive starts
of the conversion algorithm.
Preventing this is necessary because it makes the UI
stop updating for a significant amount of time, which
we obviously don't want.
2017-08-03 13:16:21 +02:00
Soeren Apel b4d448004a Remove SignalBase::A2LChannel 2017-08-03 13:06:27 +02:00
Soeren Apel f0f9c8566b Use identifiers for fixed conversion preset values 2017-08-03 13:06:27 +02:00
Soeren Apel 8e15445ccd Restart min-max-based conversion if min or max change 2017-08-03 13:06:27 +02:00
Uwe Hermann f529583485 Fix some random clang-tidy warnings. 2017-08-02 10:52:52 +02:00
Soeren Apel b9cdbe03be Typo fix: treshold -> threshold 2017-08-01 14:42:20 +02:00
Soeren Apel 52c900ac86 Implement A2L presets and custom threshold handling 2017-08-01 14:42:20 +02:00
Soeren Apel 06b6ce2669 Use getter for the conversion type instead of a local copy
Don't ask me why I used a local copy in the first place,
even I can't figure it out :)
2017-07-25 16:09:08 +02:00
Soeren Apel 64845ac28f SignalBase: Minor doxygen comments 2017-07-24 08:57:51 +02:00
Soeren Apel 289c1bdc7e DecodeSignal: Don't set name when creating the signal
The thought behind this was to have no unnamed signals because
this may make debugging harder. However, giving the signal a
long name and shortening it when decoders are added isn't working
well. The reason is that the width of the header area can be
expanded programmatically but we don't shrink it because we
don't want to hide things the user may want to see.
This behavior in turn leads to the header width expanding when
a signal labeled "Empty decoder signal" is added, only to see
this very signal be renamed to e.g. "SPI" immediately afterwards.
As we don't shrink the header width, the header is now too wide.
2017-07-10 19:14:35 +02:00
Soeren Apel 4ca06ec34a DecodeSignal: Fix flawed PD stack restoration
Before, the libsigrokdecode sessions would be started without
having any channels assigned to it, which of course should be
avoided.
2017-07-06 22:27:46 +02:00
Soeren Apel b21501d694 Fix assertions 2017-07-06 21:55:01 +02:00
Uwe Hermann 20f59e957e Apply some clang-tidy fixes.
This patch was generated using clang-tidy:

  clang-tidy -checks="-*,..." -fix

The following set of checks was enabled:

  modernize-use-nullptr,modernize-deprecated-headers,modernize-make-shared,
  modernize-redundant-void-arg,modernize-use-bool-literals,
  modernize-use-emplace,modernize-use-equals-default,
  google-readability-namespace-comments,misc-unused-using-decls

Add NOLINT to have clang-tidy (among other tools) ignore some lines
that are not meant to be changed.
2017-07-06 12:09:10 +02:00
Soeren Apel 762ab7a4b2 DecodeSignal: Auto-assign only the channels of newly added decoders
Before, the channels of all decoders in the stack were auto-assigned,
potentially messing up the configuration the user chose.
2017-07-06 00:37:09 +02:00
Soeren Apel 5e95d3d980 SignalBase: Adjust Schmitt-trigger thresholds
Currently, the thresholds are determined by the minimum
and maximum values of a signal. From those, we derive the
high and low thresholds by using a 10% margin to min/max.

However, this approach doesn't work very well when the
measurement includes reset conditions or similar, causing
spikes that raise the min/max significantly.

Example:
sigrok-dumps/i2c/eeprom_24xx/microchip_24lc64/sainsmart_dds120_powerup_scl_sda_analog.sr

This patch changes the thresholds margins to 35%. However,
they are expressed differently: (max-min)/2 is used as the
center line, from which 15% of the amplitude (max-min) is
used as the margin. This way seems a little more intuitive
for me since the percentage given (15) is directly proportional
to the hysteresis.
2017-07-06 00:37:09 +02:00
Soeren Apel 8ebf8079b4 DecodeSignal: Improve robustness 2017-07-06 00:37:08 +02:00
Soeren Apel 419ec4e11e Make sigrok::Context semi-global and use libsigrok A2L methods 2017-07-06 00:37:08 +02:00
Soeren Apel b82243f74a Make get_raw_samples() use provided mem instead of allocating
Until now, Segment::get_raw_samples() was allocating the required
amount of memory and returned it to the caller to use. This way,
there was always enough memory allocated for the data that was
written to that memory location.

However, in SignalBase::conversion_thread_proc() we want to use
one memory location multiple times because we will create several
layers of libsigrok wrapper objects around it. This only works
if Segment::get_raw_samples() uses a given memory location instead
of allocating it by itself.
2017-07-06 00:37:08 +02:00