Commit Graph

2529 Commits

Author SHA1 Message Date
Gerhard Sittig ebc5110989 uni-t-ut181a: implement device driver for the UNI-T UT181A multimeter
Extend the previously introduced skeleton driver for UNI-T UT181A. Introduce
support for the full multimeter's protocol as it was documented by the ut181a
project. Which covers the retrieval of live readings, saved measurements, and
recordings, in all of the meter's modes and including relative, min/max, and
peak submodes. This implementation also parses compare mode (limits check)
responses, although it cannot express the result in terms of the session feed.

Announce the device as a multimeter as well as a thermometer, it supports
up to two probes including difference mode. When in doubt, prefer usability
over feature coverage (the driver side reflects all properties of the meter,
but not all features can get controlled by the driver). The probe routine
requires that users specify the serial port, and enable serial communication
on the meter.

Several TODO items remain. Comments in the driver code discuss limitations
of the current implementation, as well as cases where the meter's features
don't map well to sigrok's internal presentation. This implementation also
contains (optional, off by default) diagnostics for research on the serial
protocol.
2020-06-01 18:35:05 +02:00
Gerhard Sittig 3094e9d8ca uni-t-ut181a: Initial driver skeleton. 2020-06-01 18:35:05 +02:00
Gerhard Sittig 5cc292b34a asix-sigma: discuss usability of data pattern trigger specs
When data patterns for trigger specs span multiple bits, users may not
want to specify long lists of "<ch>=<lvl>" conditions for sigrok-cli's
--trigger option, and count channels by hand. Or click a dozen dialogs
to specify one data pattern, or modify a previous specification. Setups
with few traces may accept that, "data heavy" setups like parallel data
or address bus inspection may not.

Add comments which discuss the potential use of SR_CONF_TRIGGER_PATTERN.
Outline a syntax which may be flexible enough _and_ acceptable to users,
support data patterns and edge triggers alike, in several presentations
that serve different use cases.  This commit exclusively adds comments,
does not change behaviour.

Update a comment in the user spec to internal format trigger spec parser
to expand on hardware constraints and implementation limitations. Rename
an identifier which checks the number of edge conditions, not the number
of accepted trigger spec details.
2020-05-31 23:56:40 +02:00
Gerhard Sittig e092671365 asix-sigma: unconditionally re-enable trigger support code
Trigger support became operational again. Drop the compile time switch
which disabled the previously incomplete implementation.

This resolves bug #359.
2020-05-31 23:56:16 +02:00
Gerhard Sittig f14e6f7e1a asix-sigma: complete and extend capture mode supervision
Parse trigger specs early when acquisition starts, timeout calculation
needs to reflect on it. Either immediately start an acquisition timeout
for trigger-less configurations. Or prepare a timeout which spans the
post-trigger period, but only start its active period when the trigger
match was detected by the device's hardware.

Extend mode tracking during acquisition to handle other special cases.
Terminate acquisition when the user specified sample count limit exceeds
the hardware capacity, or when no limits were specified and the device's
memory is exhausted.

There is a slight inaccuracy in this approach, but the implementation
fails on the safe side. When both user specified limits and triggers are
involved, then at least the user specified time or sample count span is
provided. Usually more data is sent to the session feed, and all of the
requested period is covered. This is because of the software poll period
and the potential to start the timeout slightly late. As well as having
added some slack for hardware pipelines in the timeout calculation.
2020-05-31 23:53:42 +02:00
Gerhard Sittig debe1ff66d asix-sigma: download sample memory in multiple receive calls
The previous implementation ran the complete sample memory retrieval
in a single call to the receive callback. Which in combination with
slow USB communication and deep memory could block application logic
for rather long periods of time.

Rephrase the download_capture() routine such that it can spread its
workload across multiple invocations. Run the acquisition stop and
resource allocation for the download, the interpretation of a set of
DRAM lines, and the resource cleanup, as needed. And keep calling the
download routine until completion of the interpretation of the sample
memory region of interest. The workload size per invocation may need
more adjustment.

The previous implementation could stall UI progress for some 20-30s.
This change lets users perceive UI progress while sample memory gets
retrieved and interpreted.

This resolves bug #1005.
2020-05-31 23:52:24 +02:00
Gerhard Sittig 914f8160e7 asix-sigma: drop obsolete "trigger countdown" in sample interpretation
Recent commits added "position tracking" for interesting spots in the
sample stream and the current iteration pointer. Which obsoletes the
counters for remaining items until trigger, the "triggered here" flags,
as well as the unfortunate "rewind a little" workaround which lacked a
comment on its motivation or implementation details.
2020-05-31 23:51:23 +02:00
Gerhard Sittig 8a72362505 asix-sigma: re-enable software check for exact trigger position
The hardware provided trigger match location is inaccurate. Do check
sample values against the initial trigger condition spec for a short
range of the retrieved sample data, to refine the trigger marker's
position which is sent to the session feed.

Temporarily ignore the optional sample count limit for trigger-using
acquisitions, to reduce the diff size and simplify review. Since the
hardware transparently compresses sample data, we cannot reliably
determine where to start the download and interpretation of sample data,
and the submission to the session feed. Starting early in the sample
memory content, and sticking with the strict sample count limit, could
clip submission before the actual trigger position.

This implementation provides _at least_ the requested amount of data,
and does cover the spot of interest (the trigger position). This, and
the trigger support's having become operational again, is considered an
important improvement. The inaccuracy is considered acceptable for now.
Trigger-less acquisition does enforce the exact sample count limit.
2020-05-31 23:49:35 +02:00
Gerhard Sittig 66d1790cc0 asix-sigma: rephrase sample memory iteration position and trigger check
Rephrase how the sample memory iteration position gets tracked, increment
after every event slot already. Update the "last seen sample" status more
often (an event slot can hold several sample items). Arrange for a period
of time where software will check sample data for trigger matches. This
improves the precision of the hardware provided trigger match location.

Do send hardware provided trigger locations to the session feed even if
the software check found no match on the data content. This covers user
initiated button presses (which can unblock the acquisition when the
application provided trigger condition never matches).

Note that this implementation does manage the window of supervision, but
does not yet check the sample values against the trigger condition. This
gets added later.
2020-05-31 23:46:21 +02:00
Gerhard Sittig 16a5d5ac7d asix-sigma: rework outer sample download loop (DRAM lines iteration)
Factor USB data transfer out of the code path which interprets sample
memory content. Keep internal state of sample memory download in the
device context. This eliminates local variables, and ideally allows a
future implementation to spread chunked downloads across several read
callbacks, which would improve UI responsiveness.

Update comments while we are here. Address minor portability nits (ull
suffix vs UINT64_C macro). The inner loops (iterating clusters and their
events which contain individual samples) are not affected by this commit.
2020-05-31 23:45:29 +02:00
Gerhard Sittig 1385f791b0 asix-sigma: more trigger LUT download rephrase, think 16bit entities
Further rephrase the sigma_write_trigger_lut() routine. It's helpful to
"think" in BE16 quantities to improve readability of LUT address and
parameter downloads. Better matches the vendor's documentation. Also use
a better name for the "trigger select 2" register content.
2020-05-31 23:44:56 +02:00
Gerhard Sittig ee5cef7103 asix-sigma: concentrate more sample memory interpretation params
Start moving parameters into the device context which are related to the
interpretation of sample memory content. This can simplify error paths,
allow to release resources late. And ideally sample memory download and
interpretation could spread across several receive callbacks, improving
UI responsiveness. Also makes total and current dimensions available to
deeper nesting levels in the interpretation, which currently don't have
access to these details.
2020-05-31 23:44:29 +02:00
Gerhard Sittig de4c29fa91 asix-sigma: concentrate parameters for sample memory interpretation
Create a sub struct in the device context which keeps those parameters
which are related to sample memory interpretation. Which also obsoletes
the 'state' struct and only leaves the 'state' enum as a remainder.

Use the "samples per event" condition instead of the samplerate when
extracting a number of samples from an event's storage. Rename the
de-interleaving routines to better reflect their purpose.
2020-05-31 23:44:09 +02:00
Gerhard Sittig ea57157d0d asix-sigma: force strict boolen arith in LUT item manipulation
Mechanically adjust the add_trigger_function() routine to address nits,
attempt to improve maintainability.

Raise awareness of the fact that strict binary arithmetics is done (bit
operators are used), the strict 0..1 set of values needs to be enforced,
and mere "logical truthness" is not good enough in this spot. Explicitly
check for bit positions instead of "shifting out" the bit of interest
and have the 0/1 value result nearly by coincidence.

Extend comments. Group related instructions and separate them from other
groups. Reduce the scope of the rather generic i, j, tmp named variables
which are just too easy to get wrong.
2020-05-31 23:43:17 +02:00
Gerhard Sittig 3f5f548410 asix-sigma: use more helpers for bit mask creation
Rename macros to better reflect which of them check a bit position, and
which span a bit field of given width. Adjust more call sites to use the
macros. This takes tedium out of maintenance as well as review. Has the
minor benefit of somewhat shortening text lines, and eliminating nested
parentheses (or getting perceived as if it would).
2020-05-31 23:42:53 +02:00
Gerhard Sittig 156b6879e9 asix-sigma: rephrase limits management, use sub structure
Move the acquisition limits related variables into a sub struct within
the device context. Over time they became numerous, and might grow more
in the future.
2020-05-31 23:42:32 +02:00
Gerhard Sittig fb65ca09b7 asix-sigma: track whether triggers were specified when acquisition started
There are several separate conditions which the driver needs to tell
apart. There is a compile time switch whether trigger support shall be
built in. There is the condition whether acquisition start involved a
user provided trigger spec. And there is the hardware flag whether a
previously configured trigger condition matched and where its position
is.

Only accept user provided trigger specs when trigger support is builtin.
(The get/set/list availability and spec passing is done in applications
outside of the library, we better check just to make sure.) Only setup
the trigger related hardware parameters when a spec was provided. Only
check for trigger positions when the hardware detected a match.
2020-05-31 23:41:40 +02:00
Gerhard Sittig 8a57728d0e asix-sigma: enable trigger support code (development HACK)
Enable the compile time option which builds trigger support code into
the asix-sigma driver. This is a development hack. Trigger support in
the driver is incomplete and currently not operational.
2020-05-31 23:41:23 +02:00
Gerhard Sittig 3d9373af2e asix-sigma: data type nits, minor variable renames
Address remaining data type nits. Use more appropriate types for sizes
and counters and indices, as well as for booleans.

Prefer more verbose variable names in a few spots to avoid the rather
generic 'i' symbol, especially in complex code paths with deeply nested
flow control or with long distances between declaration and use. Re-use
an existing buffer in the acquisition start for command sequences which
setup trigger in/out as well as clock parameters.

Introduce some variables which may seem unnecessary. But these are
useful for research during maintenance.

This is a mechanical adjustment, behaviour does not change.
2020-05-31 23:41:06 +02:00
Gerhard Sittig 53c8a99c41 asix-sigma: prepare configuration re-use across sigrok sessions
Introduce the required infrastructure to store successfully applied
configuration data in hardware registers. This lets the probe phase of
the next sigrok session pick up where the previous session left. Which
improves usability, and increases performance by eliminating delays in
the acquisition start, by not repeating unnecessary firmware uploads.

The vendor documentation suggests there would be FPGA registers that are
available for application use ("plugin configuration"). Unfortunately
experiments show that registers beyond address 0x0f don't hold the data
which was written to them. As do unused registers in the first page. So
the desirable feature is not operational in this implementation. There
could be different netlist versions which I'm not aware of, or there
could be flaws in this driver implementation. This needs more attention.
2020-05-31 23:40:19 +02:00
Gerhard Sittig 8bd4dc8799 asix-sigma: nits in the hardware configuration declaration
Stop assuming that C language variables whould have a specific memory
layout that applications could rely on. Use normal data types in higher
abstraction layers, drop non-portable bit fields. Use existing macros
for the creation of bit masks of a given width.
2020-05-31 23:39:55 +02:00
Gerhard Sittig 17ed72cc44 sw_limits: start msec timeout period only after start() call
When application code used the common SW limits API, the call sequence
of init() then set() then check() already kept expiring, which is rather
unexpected. The timeout period should only start when start() is called,
check() should not signal expiration before the start() call.

The specific use case is the combination of an msecs timeout and capture
ratio when triggers are used. The post-trigger period only starts when
the trigger match was seen, even though its length is already known when
the acquisition starts. It's desirable to run the start() call for the
post-trigger timeout late, and not terminate the acquisition before the
trigger match.
2020-05-31 23:39:28 +02:00
Gerhard Sittig dbb3e2ad3d serial: accept bitrate only serialcomm= spec, default to 8n1 frames
The previous implementation considered both the UART bitrate and the
frame format mandatory, users had to specify "/8n1" as well just to
change the bitrate.

This commit makes the frame format optional, and defaults to 8n1 which
is so popular these days. When specified, the frame format still needs
to preceed the other optional flow and handshake flags, for maximum
backwards compatibility, and equal robustness in the process of parsing
serialcomm= specs.

Unfortunately device drivers cannot specify their preferred or default
UART frame format. Which means that users still need to provide these
when a device does not use 8n1. This is not a regression, the previous
implementation always needed the frame format spec.
2020-05-31 23:39:19 +02:00
Gerhard Sittig 7718f3ca8f asix-sigma: update comment on channel names (vendor doc says "1-16")
Eliminate doubt from a comment on ASIX SIGMA's channel names which was
introduced in commit d261dbbfcc. Publicly available documentation does
agree their names start at "1" and go up to "16".
2020-05-29 08:06:18 +02:00
Gerhard Sittig 2d8a508976 asix-sigma: add support for external clock
The 50MHz netlist supports the use of an external clock. Any of the 16
channels can use any of its edges to have another sample taken from all
the other pins. It's nice that the hardware does track timestamps, which
results in an exact reproduction of the input signals' timing with 20ns
resolution, although the clock is externally provided and need not have
a fixed rate.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 16791da9c9 asix-sigma: more trigger spec to register values conversion sync with doc
Rephrase more parts of sigma_build_basic_trigger() to closer match the
vendor documentation. Use the M3Q name. Be explicit about "parameters"
setup (even if that means to assign zero values, comments help there).
Using three BE16 items for the parameters improves readability.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 7dd766e0aa asix-sigma: rephrase trigger LUT creation (mechanical change)
Rephrase the sigma_build_basic_trigger() and build_lut_entry() routines
to hopefully improve readability. Avoid the use of short and generic
identifiers which are just too easy to confuse with each other and the
1 literal and negation operator in deeply nested loops and complex
expressions that span several text lines. Reduce indentation where
appropriate. Concentrate initialization and use of variables such that
reviewers need less context for verification.

This is a purely mechanical change, the function of triggers remains
untested for now. Setting "selres" in that spot is suspicious, too.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 72ea3b84bd asix-sigma: rephrase trigger LUT upload to hardware for readability
Rephrase the sigma_write_trigger_lut() routine to work on "a higher
level" of abstraction. Avoid short and most of all generic variable
names. Use identifiers that are closer to the vendor documentation.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 0f017b7da9 asix-sigma: rephrase and extend register access for readability
Reduce the probability of errors during maintenance, and also increase
readability. Replace open coded nibble extraction and bit positions by
accessor helpers and symbolic identifiers. Adjust existing math where it
did not match the vendor documentation. Always communicate 8bit register
addresses, don't assume that application use remains within a specific
"page". Provide more FPGA register access primitives so that call sites
need not re-invent FPGA command sequence construction. Remove remaining
open coded endianess conversion in DRAM access.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 419f109505 asix-sigma: rephrase firmware dependent param upload at acquisition start
The 100/200MHz supporting FPGA netlists differ in their register set
from 50MHz netlists. Adjust the parameter download at acquisition start.

Raise awareness of the "TriggerSelect" and "TriggerSelect2" difference
(the former only exists in 50MHz netlists, the latter's meaning differs
between firmware variants). "ClockSelect" semantics also differs between
netlists. Stop sending four bytes to a register that is just one byte
deep, channel selection happened to work by mere coincidence.

Eliminate a few more magic numbers, unobfuscate respective code paths.
Though some questions remain (trigger related, not a blocker for now,
needs to get addressed later).
2020-05-29 08:06:18 +02:00
Gerhard Sittig abcd477196 asix-sigma: keep remaining samplerate handling in protocol.c
Make the list of supported samplerates an internal detail of the
protocol.c source file. Have the api.c source file retrieve the list
as well as the currently configured value by means of query routines.

Ideally the current rate could get retrieved from hardware at runtime.
A future driver implementation could do that. This version sticks with
the lowest supported rate, as in the previous version.
2020-05-29 08:06:18 +02:00
Gerhard Sittig a426f74aca asix-sigma: cosmetics, sort protocol.h function groups
Sort "semi public" routines and "global data" of the asix-sigma driver
in the protocol.h header file by their use. Add comments. This improves
maintenance of the driver source.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 7fe1f91f75 asix-sigma: prepare FTDI open/close for "optional open"
Move all of the FTDI connection handling from api.c to protocol.c, and
prepare "forced" and "optional" open/close. This allows future driver
code to gracefully handle situations where FPGA registers need to get
accessed, while the caller may be inside or outside the "opened" period
of the session. This is motivated by automatic netlist type and sample
rate detection, to avoid the cost of repeated firmware uploads.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 88a5f9eabe asix-sigma: improve error propagation, increase robustness
Detect more error conditions, and unbreak those code paths where wrong
data was forwarded. It's essential to tell the USB communication layer,
sigrok API error codes, and glib mainloop receive callbacks apart. Since
the compiler won't notice, maintainers have to be extra careful.

Rephrase diagnostics messages. The debug and spew levels are intended
for developers, but the error/warn/info levels will get presented to
users, should read more fluently and speak from the application's POV.
Allow long text lines in source code, to not break string literals which
users will report and developers need to search for (this matches Linux
kernel coding style).

This commit also combines the retrieval of sample memory fill level,
trigger position, and status flags. Since these values span an adjacent
set of FPGA registers. Which reduces USB communication overhead, and
simplifies error handling. The helper routine considers the retrieval
of each of these values as optional from the caller's perspective, to
simplify other use cases (mode check during acquisition, before sample
download after acquisition has stopped).

INIT pin sensing after PROG pin pulsing was reworked, to handle the
technicalities of the FTDI chip and its USB communication and the FTDI
library which is an external dependency of this device driver. Captures
of USB traffic suggest that pin state is communicated at arbitrary times.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 5c231fc466 asix-sigma: style nits, expression complexity, information locality
Address minor style nits to improve readability and simplify review. The
sizeof() expressions need not duplicate data type details. Concentrate
the assignment to, update of, and evaluation of variables in closer
proximity to reduce potential for errors during maintenance. Separate
the gathering of input data and the check for their availability from
each other, to simplify expressions and better reflect the logic's flow.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 9334ed6ccd asix-sigma: update copyright notice for recent non-trivial changes 2020-05-29 07:50:33 +02:00
Gerhard Sittig 2a62a9c44e asix-sigma: more u16 sample memory access nits (timestamps, values)
Further "flatten" the DRAM layout's declaration for sample data. Declare
timestamps and sample data as uint16_t, keep accessing them via endianess
aware conversion routines. Accessing a larger integer in smaller quantities
is perfectly fine, the inverse direction would be problematic.
2020-05-29 07:50:33 +02:00
Gerhard Sittig a53b8e4d74 asix-sigma: improve robustness of parameter upload to hardware
Keep application data in its logical presentation in C language struct
fields. Explicitly convert to raw byte streams by means of endianess
aware conversion helpers. Don't assume a specific memory layout for
C language variables any longer. This improves portability, and
reliability of hardware access across compiler versions and build
configurations.

This change also unobfuscates the "disabled channels" arithmetics in
the sample rate dependent logic. Passes read-only pointers to write
routines. Improves buffer size checks. Reduces local buffer size for
DRAM reads. Rewords comments on "decrement then subtract 64" during
trigger/stop position gathering. Unobfuscates access to sample data
after download (timestamps, and values). Covers a few more occurances
of magic numbers for memory organization.

Prefer masks over shift counts for hardware register bit fields, to
improve consistency of the declaration block and code instructions.
Improve maintenability of the LA mode initiation after FPGA netlist
configuration (better match written data and read-back expectation,
eliminate magic literals that are hidden in nibbles).
2020-05-29 07:50:33 +02:00
Gerhard Sittig 9b4d261fab asix-sigma: style nits, devc in routine signatures, long text lines
Move the 'devc' parameter to the front in routine signatures for the
remaining locations which were not adjusted yet. Reduce indentation of
continuation lines, especially in long routine signatures. Try to not
break string literals in diagnostics messages, rephrase some of the
messages. Massage complex formulae for the same reason.

Whitespace changes a lot, word positions move on text lines. See a
corresponding whitespace ignoring and/or word diff for the essence of
the change.
2020-05-29 07:50:23 +02:00
Gerhard Sittig b65649f6b9 asix-sigma: reword list of sample rates, (try to) use 1/2/5 steps
The driver got extended in a previous commit to accept any hardware
supported samplerate in the setter API, although the list call does
suggest a discrete set of rates (a subset of the hardware capabilities).
Update a comment to catch up with the implementation.

Drop the 250kHz item, it's too close to 200kHz. Add a 2MHz item to
achieve a more consistent 1/2/5 sequence in each decade. Unfortunately
50MHz and an integer divider will never result in 20MHz, that's why
25MHz is an exception to this rule (has been before, just "stands out
more perceivably" in this adjusted sequence).
2020-05-29 07:50:18 +02:00
Gerhard Sittig c749d1ca57 asix-sigma: improve robustness of firmware download, delay and retry
Running several firmware uploads in quick repetition sometimes failed.
It's essential to stop the active netlist from preventing the FPGA's
getting reconfigured (FTDI to FPGA pins are so few, and shared). Delays
in a single iteration of the initiation sequence improves reliability.
Retries of the sequence are belt and suspenders on top of that.

Before the change, failure to configure was roughly one in ten. After
the change, several thousand reconfigurations passed without failure.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 80e717b3cf asix-sigma: eliminate magic numbers in firmware file references
Use symbolic identifiers to select firmware images, which eliminates
magic 0/1/2 position numbers in the list of files, improves readability
and also improves robustness. Move 'devc' to 'ctx' and before other
arguments in routine signatures while we are here.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 1bb9dc8217 asix-sigma: mark FPGA config phase in "state" of dev context
FPGA configuration (netlist upload) of ASIX SIGMA devices is rather
special a phase, and deserves its own state in the device context's
"state" tracking. Not only is the logic analyzer not available during
this period, the FTDI cable is also put into bitbanging mode instead
of regular data communication in FIFO mode, and netlist configuration
takes a considerable amount of time (tenths of a second).
2020-05-29 07:50:18 +02:00
Gerhard Sittig 5e78a56481 asix-sigma: rework time/count limits support, accept more samplerates
Use common support for SW limits, and untangle the formerly convoluted
logic for sample count or time limits. Accept user provided samplerate
values when the hardware supports them, also those which are not listed.

The previous implementation mapped sample count limits to timeout specs
which depend on the samplerate. The order of applications' calls into
the config set routines is unspecified, the use of one common storage
space led to an arbitrary resulting value for the msecs limit, and loss
of user specified values for read-back.

Separate the input which was specified by applications, from limits
which were derived from this input and determine the acquisition phase's
duration, from sample count limits which apply to sample data download
and session feed submission after the acquisition finished. This allows
to configure the values in any order, to read back previously configured
values, and to run arbitrary numbers of acquisition and download cycles
without losing input specs.

This commit also concentrates all the limits related computation in a
single location at the start of the acquisition. Moves the submission
buffer's count limit container to the device context where the other
limits are kept as well. Renames the samplerate variable, and drops an
aggressive check for supported rates (now uses hardware constraints as
the only condition). Removes an unused variable in the device context.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 98b43eb3cd asix-sigma: rephrase submission of logic data to session feed
Introduce a 4MiB session feed submission buffer in the device context.
This reduces the number of API calls and improves performance of srzip
archive creation.

This change also eliminates complex logic which manipulates a previously
created buffer's length and data position, to split the queued data when
a trigger position was involed. The changed implementation results in a
data flow from sample memory to the session feed which feels more natural
during review, and better lends itself to future trigger support code.

Use common SW limits support for the optional sample count limit. Move
'sdi' and 'devc' parameters to the front to match conventions. Reduce
indentation in routine signatures while we are here.

This implementation is prepared to handle trigger positions, but for now
disables the specific logic which checks for trigger condition matches
to improve the trigger marker's resolution. This will get re-enabled in
a later commit.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 2c33b09255 asix-sigma: eliminate magic numbers in sample memory access
Add more symbolic identifiers, and rename some of the existing names for
access to SIGMA sample memory. This eliminates magic numbers and reduces
redundancy and potential for errors during maintenance.

This commit also concentrates DRAM layout related declarations in the
header file in a single location, which previously were scattered, and
separated registers from their respective bit fields.

Extend comments on the difference of events versus sample data.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 7c41c420aa asix-sigma: move FPGA commands before register layout declaration
Move the FPGA commands (which can access registers, and sample memory)
declarations before the register layout declaration. Which then no
longer separates the registers declarations from their bit fields.
Update comments on the register set while we are here.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 07411a605e asix-sigma: rephrase some of the FPGA command exchange
Eliminate a few magic numbers in FPGA commands, use symbolic identifiers
for automatic register address increments, and DRAM access bank selects.
Improve grouping of related declarations in the header file.
2020-05-29 07:49:58 +02:00
Gerhard Sittig 9fb4c6324d asix-sigma: sync FPGA register names with documentation
Rename source code identifiers for FPGA registers to closer match the
vendor's documentation.
2020-05-29 07:49:58 +02:00
Gerhard Sittig dc0906e21c asix-sigma: eliminate magic numbers in FPGA configuration
Slightly rephrase and comment on the FPGA configuration of the ASIX
SIGMA logic analyzer. Use symbolic pin names to eliminate magic numbers.
Concentrate FPGA related comments in a single spot, tell the Xilinx FPGA
from FTDI cable (uses bitbang mode for slave serial configuration).

This fixes typos in the PROG pulse and INIT check (tests D5 and comments
on D6). Also removes the most probably undesired 100s timeout in the
worst case (100M us, 10K iterations times 10ms delay). Obsoletes labels
for error paths. Drops a few empty lines to keep related instruction
blocks together. Includes other style nits.
2020-05-29 07:49:58 +02:00
Gerhard Sittig 53a939aba5 asix-sigma: rework scan for USB devices, add support for conn= specs
Stick with the FTDI library for data acquisition, and most of all for
firmware upload (bitbang is needed during FPGA configuration). Removing
this dependency is more complex, and needs to get addressed later.

Re-use common USB support during scan before open, which also allows to
select devices if several of them are connected. Either of "conn=vid.pid"
or "conn=bus.addr" formats are supported and were tested.

This implementation detects and displays SIGMA and SIGMA2 devices. Though
their function is identical, users may want to see the respective device
name. Optionally detect OMEGA devices, too (compile time option, off by
default), though they currently are not supported beyond detection. They
just show up during scans for ASIX logic analyzers, and users may want to
have them listed, too, for awareness.

This implementation also improves robustness when devices get disconnected
between scan and use. The open and close routines now always create the
FTDI contexts after the code has moved out of the scan phase, where common
USB support code is used.

This resolves bug #841.
2020-05-29 07:49:50 +02:00
Gerhard Sittig 742368a2bc asix-sigma: nits in the list of firmware files
Eliminate an unnecessary magic number for the maximum filename length of
SIGMA netlists. Use a more compact source code phrase to "unclutter" the
list of filenames and their features/purpose. Move the filesize limit to
the list of files to simplify future maintenance.
2020-05-29 06:13:41 +02:00
Gerhard Sittig 97aa41e9b5 strutil: introduce sr_atol_base() conversion helper (non-decimal)
Introduce a text to number conversion routine which is more general than
sr_atol() is. It accepts non-decimal numbers, with optional caller given
or automatic base, including 0b for binary. It is not as strict and can
return the position after the number, so that callers can optionally
support suffix notations (units, or scale factors, or multiple separated
numbers in the same text string).
2020-05-29 06:12:50 +02:00
Gerhard Sittig 080b6bcf09 libsigrok-internal.h: add 24bit little endian reader helper
Add another endianess conversion helper which reads 24bit values in
little endian format.
2020-05-29 06:11:38 +02:00
Gerhard Sittig f1833600a0 libsigrok-internal.h: rephrase endianess conversion helpers
Address style, robustness, and usability nits in the common endianess
conversion helpers in the libsigrok-internal.h header file. Rephrase
preprocessor macros as static inline C language functions to eliminate
side effects, and improve data type safety. Provide macros under the
previous names for backwards compatibility, so that call sites can
migrate to the routines at their discretion (or not at all).

Performance is not affected. Inline routines are identically accessible
to compiler optimizers as preprocessor macros with their text expansion
are. Resulting machine code should be the same.

Introduce variants which also increment the read or write position in
the byte stream after data transfer. This reduces more redundancy at
call sites.
2020-05-29 06:10:18 +02:00
Frank Stettner 883db4dad1 hp-3478a: Fix glib variant ref count in SET MQ request. 2020-05-26 21:17:32 +02:00
Frank Stettner 1c8110dbc7 scpi-dmm: Fix coding style. 2020-05-26 21:17:25 +02:00
Tobias Faeth 6d2e307016 serial-dmm: Added support for Metex ME-21 multimeters 2020-05-26 21:11:48 +02:00
Sergey Rzhevsky 9785891436 ftdi-la: Add FT4232H PID:VID. 2020-05-02 17:01:39 +02:00
Richard 77f3c5e51f rigol-ds: Added support for the DS1202Z-E 2020-05-02 17:01:39 +02:00
Gerhard Sittig 8c381a353c hameg-hmo: use common helper to setup description of an analog value
Replace an open coded sequence of assignments to an aggregate of several
related structures. Prefer the common sr_analog_init() routine instead.
2020-05-02 17:01:39 +02:00
Gerhard Sittig 00f3c94386 uni-t-ut32x: drop redundant close and free at end of scan
The UT32x driver requires a user spec for the connection. The device
cannot get identified, that's why successful open/close for the port
will suffice. Lack of an input spec as well as failure in the early
scan phase will terminate the scan routine early.

When we reach the end of the scan which creates the device instance
and registers it with the list of found devices, the port already
is closed and the list of devices will never be empty. Remove the
redundant close call and the dead branch which frees the serial port.
2020-05-02 17:01:39 +02:00
Gerhard Sittig ff5fb18526 scpi-dmm: fix glib variant ref count in SET MQ request 2020-05-02 17:01:39 +02:00
Uwe Hermann 6cfc6c5c7a Fix compiler warnings related to -Wcast-function-type.
This fixes bug #1297.
2020-05-02 17:01:39 +02:00
Uwe Hermann 4c5ac0cf5b siglent-sds: Fix various compiler warnings.
src/hardware/siglent-sds/protocol.c: In function 'siglent_sds_get_digital':
  src/hardware/siglent-sds/protocol.c:382:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if (data_low_channels->len <= samples_index) {
                                     ^
  src/hardware/siglent-sds/protocol.c:391:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if (data_high_channels->len <= samples_index) {
                                      ^
  src/hardware/siglent-sds/protocol.c:417:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (long index = 0; index < tmp_samplebuf->len; index++) {
                                  ^
  In file included from src/hardware/siglent-sds/protocol.c:37:0:
  src/hardware/siglent-sds/protocol.c: In function 'siglent_sds_receive':
  src/hardware/siglent-sds/protocol.h:28:20: warning: format '%li' expects argument of type 'long int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=]
   #define LOG_PREFIX "siglent-sds"
                      ^
  ./src/libsigrok-internal.h:815:41: note: in expansion of macro 'LOG_PREFIX'
   #define sr_dbg(...) sr_log(SR_LOG_DBG,  LOG_PREFIX ": " __VA_ARGS__)
                                           ^
  src/hardware/siglent-sds/protocol.c:564:6: note: in expansion of macro 'sr_dbg'
        sr_dbg("Requesting: %li bytes.", devc->num_samples - devc->num_block_bytes);
        ^
  src/hardware/siglent-sds/protocol.c: In function 'siglent_sds_get_dev_cfg_horizontal':
  src/hardware/siglent-sds/protocol.h:28:20: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=]
   #define LOG_PREFIX "siglent-sds"
                      ^
  ./src/libsigrok-internal.h:815:41: note: in expansion of macro 'LOG_PREFIX'
   #define sr_dbg(...) sr_log(SR_LOG_DBG,  LOG_PREFIX ": " __VA_ARGS__)
                                           ^
  src/hardware/siglent-sds/protocol.c:933:2: note: in expansion of macro 'sr_dbg'
    sr_dbg("Current memory depth: %lu.", devc->memory_depth_analog);
    ^
2020-05-02 15:48:26 +02:00
Andreas Sandberg 4704f64551 bt/bt_bluez: Implement retry if rfcomm sockets are busy
There are cases where the connect() call returns EBUSY when trying to
connect to a device. This has been observed when sampling an RDTech
UM24C. In this case, scanning the device works fine. However, when
sampling the device, Sigrok first scans the device, then closes the
connection and re-opens it to sample the device. If the close/open
calls happen in close successions, the Bluetooth stack sometimes
returns EBUSY.

Work around this issue by retrying if the connect() returns EBUSY.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-04-11 16:00:52 +02:00
v1ne 1d657f47be modbus: Close device after scan
Since the device should be closed after the scan, close it in sr_modbus_scan.
Alternatively, every single driver could close the device after calling
sr_modbus_scan. This causes duplicated code, is prone to forgetting it and it
wasn't the calling driver who opened the device in the first place.

This change unbreaks maynuo-m97 and rdtech-dps.
2020-04-11 15:55:35 +02:00
Florian Schmidt 8f3c77db26 scpi-pps: fixed out-of-bounds array access...
when accessing devc->device->channels in config_list().
this array has to be accessed via the "hw_output_idx"

This fixes bug #1533.
2020-04-11 15:52:13 +02:00
Uwe Hermann f0aec55605 center-3xx: Fix incorrect values due to endianness issue.
Replace RL16S with RB16S, the values are big-endian.

This is related to the recently-fixed bug #1463.
2020-04-09 23:51:16 +02:00
Uwe Hermann 4c5f70063a Use std_session_send_df_frame_begin()/_end() where possible. 2020-04-08 23:54:25 +02:00
Uwe Hermann 7f7702b81b std: Rename std_session_send_frame_begin/_end(). 2020-04-08 23:35:44 +02:00
Uwe Hermann 0fa71943e3 Use std_session_send_df_trigger() where possible. 2020-04-08 23:21:39 +02:00
Uwe Hermann 447c4216fc std: Factor out send_df_without_payload() helper. 2020-04-08 23:11:15 +02:00
Uwe Hermann 10cf811385 std: Add std_session_send_df_trigger(). 2020-04-08 23:02:04 +02:00
Uwe Hermann 148cf8bea1 zeroplus-logic-cube: Fix an issue when changing triggers.
Changing triggers (e.g. from low to high) would sometimes cause the
acquisition to seemingly "hang" due to missing variable initializations
(in reality the device would wait for incorrect triggers and/or on
incorrect channels).

This fixes bug #1535.
2020-04-08 22:58:02 +02:00
Jan Metzger 88daa0536c zeroplus-logic-cube: Enable edge-triggering capabilities.
This fixes bug #1334.
2020-04-08 22:57:02 +02:00
Christian Fruth c8dcd3ab72 korad-kaxxxxp: Add support for RND KA3005P V5.5 power supply 2020-04-07 00:54:18 +02:00
Peter van der Perk 082ca8d8bc korad-kaxxxxp: Add support for TENMA 72-2540 V5.2 power supply 2020-04-07 00:54:18 +02:00
Tom Matthews 3ff6cfeebe ftdi-la: add TUMPA VID:PID and JTAG pin names 2020-04-07 00:54:18 +02:00
v1ne 69c5d959e7 rdtech-dps: Make it work in SmuView
Without the mutex, concurrent reception from the ModBus port leads to CRC
errors.
2020-04-04 23:25:25 +02:00
Gerhard Sittig 56a1bf7b4b center-3xx: use common signed LE16 conversion for temperature value
Prefer the common conversion helper for little endian 16bit signed data.
The previous local implementation only worked for positive values, and
yielded incorrect results for negative temperatures.

This fixes bug #1463.
2020-04-04 23:25:25 +02:00
Elen Eisendle ca7d442692 serial-dmm/uni-t-dmm: Add UNI-T UT804 DMM definitions 2020-04-04 23:25:09 +02:00
Andreas Sandberg 35037b1d8b input/trace32_ad: Fix pod_data uninitialised warning
Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-04-04 22:25:03 +02:00
Andreas Sandberg 5ff772410b gwinstek-gpd: Fix use of uninitialized variable
Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-04-04 22:24:26 +02:00
Uwe Hermann 6762401d2b Doxygen: Fix various warnings.
src/resource.c:414: warning: unbalanced grouping commands

  conversion.c:81: warning: argument 'lo_thr' from the argument list of sr_a2l_schmitt_trigger has multiple @param documentation sections

  src/analog.c:611: warning: return value 'SR_ERR_ARG' of sr_rational_div has multiple documentation sections

  src/device.c:205: warning: explicit link request to 'TRUE' could not be resolved
  src/device.c:205: warning: explicit link request to 'FALSE' could not be resolved
  src/device.c:231: warning: explicit link request to 'TRUE' could not be resolved
  src/device.c:231: warning: explicit link request to 'FALSE' could not be resolved

  src/serial.c:246: warning: explicit link request to 'NULL' could not be resolved

  src/strutil.c:602: warning: explicit link request to 'NULL' could not be resolved

  src/device.c:94: warning: unable to resolve reference to 'sr_channel_free()' for \ref command

  src/strutil.c:597: warning: unable to resolve reference to 'sr_hexdump_free()' for \ref command
  src/strutil.c:622: warning: unable to resolve reference to 'sr_hexdump_new()' for \ref command

  src/device.c:430: warning: The following parameters of sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, const char *name) are not documented: parameter 'sdi'

  src/session.c:163: warning: The following parameters of fd_source_new(struct sr_session *session, void *key, gintptr fd, int events, int timeout_ms) are not documented: parameter 'events'
2020-03-25 20:27:57 +01:00
Uwe Hermann 82b9f3d116 Doxygen: Properly mark a few symbols as private.
(otherwise these end up in the API docs)

Remove all @internal markings, only use @private where needed.
2020-03-25 20:10:24 +01:00
Uwe Hermann 20680f58ff manson-hcs-3xxx: Support device IDs with and without "HCS-" prefix.
Since we've now seen lots of devices in the wild that come with the
"HCS-" prefix in the ID, it's probably safe to assume all of them
could have it.

This fixes bug #1530.
2020-03-24 21:10:27 +01:00
Uwe Hermann bfa79fbdb6 asix-sigma: Drop duplicate error message prefixes.
The sr_err() call automatically adds a prefix to all messages, in
this specific case "asix-sigma: " will be added.
2020-03-24 19:22:11 +01:00
Daniel Trnka 440810958c asix-sigma: move DRAM line buffer allocation closer to its use
Move the allocation of the DRAM line buffer in the sample download code
path closer to the location where that buffer is used and gets released.
2020-03-24 19:20:40 +01:00
Daniel Trnka f73b00b647 asix-sigma: check for successful register access in sample download
The previous implementation got stuck in an infinite loop when data
acquisition started, but the device got disconnected before the data
acquisition terminates. An implementation detail ignored communication
errors, and never saw the expected condition that was required to
continue in the sample download sequence. Unbreak that code path.
2020-03-24 19:20:40 +01:00
Uwe Hermann f5c863e572 korad-kaxxxxp: Fix max. possible current for all devices.
Even though the devices/websites/manuals usually say 0..30V, the
hardware actually accepts up to 31V, both via serial as well as by
simply rotating the knob on the device (and our driver already
reflects that).

The same is true for current, it's usually 0..5A as per docs, but many
(probably all) devices accept 5.1A via serial and knob.

Thus, set the max current of all devices to 5.1A (or 3.1A for 3A
devices). We're assuming they all have this property, and we've seen
this in practice on at least three different versions of the device.
2020-03-22 16:58:54 +01:00
David Sastre Medina 7415217ede korad-kaxxxxp: Add a new ID for KORAD KA3005P V4.2 power supply
On a recently acquired Korad KA3005P power supply, the ID supplied by the
device is not known by libsigrok.

$ sigrok-cli --driver=korad-kaxxxxp:conn=/dev/ttyACM0 --scan
sr: korad-kaxxxxp: Unknown model ID 'KORAD KA3005P V4.2' detected, aborting.

This fixes bug #1522.

Thanks to bitaround@gmail.com for the amperage fix.
2020-03-22 15:52:16 +01:00
jirjirjir c4a46475a6 rigol-ds: Rigol DS1152E-EDU support fix 2020-03-16 23:44:25 +01:00
Soeren Apel 781ae4484d Fix #1509 by providing alternate sample format scales 2020-02-28 23:26:20 +01:00
Uwe Hermann f0362f595a agilent-dmm: Add Agilent U1237AX (completely untested). 2019-12-27 22:08:41 +01:00
Uwe Hermann e47e23355f agilent-dmm: U127x: Fix mode switch event handling.
The DMMs report as an event to which mode the user switched (by turning the
rotary switch): "*0", "*1", etc.

Most other DMMs have few modes, but the U127x DMMs have up to 11 different
modes (i.e., "*10" is a valid event).
2019-12-27 20:59:04 +01:00
Uwe Hermann f0901a5050 src/serial_hid.h: Include guard consistency fix. 2019-12-24 16:38:56 +01:00
Uwe Hermann 31b4a9a236 input/csv: Set default "header" option value to true.
This makes re-opening files that were saved via the libsigrok CSV
output module slightly more convenient.
2019-12-22 23:50:22 +01:00
Uwe Hermann 5a27356705 output/csv: Set default "time" option value to false. 2019-12-22 23:50:11 +01:00
Uwe Hermann d649ff2290 manson-hcs-3xxx: support new HCS-3200 / PPS-13610 model string.
This fixes bug #1441.
2019-12-22 23:19:47 +01:00
Uwe Hermann c810ad60b4 mastech-ms6514: Add missing string.h #include. 2019-12-22 21:06:46 +01:00
Dave Buechi 23669c3df3 Initial support for MASTECH MS6514 thermometer 2019-12-22 15:32:51 +01:00
Uwe Hermann 212769c3b8 input/csv: Consistently use a newline before the last return statement. 2019-12-22 14:42:34 +01:00
Gerhard Sittig 51e60cde09 input/csv: style nits, drop @brief and DIAG in debug output
The @brief keyword is not needed since JAVADOC_AUTOBRIEF is enabled in the
Doxygen configuration. Remove a remaining "DIAG" prefix in a debug
message, the output already is filtered according to the log level, and
prefixed by the module name.
2019-12-22 14:35:41 +01:00
Gerhard Sittig 811dcf7ea9 input/csv: re-calculate samplerate after file re-import
Don't clobber the user provided samplerate (specified by input module
options). This allows to re-determine the samplerate from a potentially
changed file on disk upon reload.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 307b239390 input/csv: expand cleanup (resource release) and unbreak file reload
The list of previously created channels is kept across file reloads. We
also need to keep (or re-create) the list of channels that are used for
datafeed submission of analog data.

Release more allocated resources in the .cleanup() routine, and do reset
internal state such that a .reset() thus .cleanup() then .receive() call
sequence will work. This code path is taken for re-import of files (see
bug #1241, CSV was affected).
2019-12-21 18:20:04 +01:00
Gerhard Sittig fbefa03f58 input/csv: improve reliabilty of text line isolation
Slightly unobfuscate the "end of current input chunk" marker in the data
processing loop. Make the variable's identifier reflect that it's not a
temporary, but instead something worth keeping around until needed again.

Unbreak the calculation of line numbers in those situations where input
chunks (including previously accumulated unprocessed data) happens to
start with a line termination. This covers input files which start with
empty lines, as well as environments with mutli-byte line termination
sequences (CR/LF) and arbitrary distribution of bytes across chunks.

This fixes bug #968.

Accept when there is no line termination in the current input chunk. We
cannot assume that calling applications always provide file content in
large enough chunks to span complete lines. And any arbitrary chunk size
which applications happen to use can get exceeded by input files (e.g.
for generated files with wide data or long comments).
2019-12-21 18:20:04 +01:00
Gerhard Sittig cb3b80512e input/csv: update developer comments and TODO list
Mention the required synchronization of default option values and format
match logic in a prominent location where options are discussed.

Update the TODO list for the CSV input module. Mixed signal handling got
fixed by rearranging channel creation. Samplerate can get determined
from timestamp columns already. The double data type for analog data
remains.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 05719d75aa input/csv: move channel creation to after format parsing
The previous implementation incompletely handled arbitrary data type
oders in mixed signal input files. Rearrange the logic such that all
format specs get parsed first, then all channel creation details get
determined, then all channels get created. It appears to be essential
that all logic channels get created first, resulting in index numbers
starting at 0 and addressing the correct position in bitfields. The
analog channels get created after all logic channels exist. Adjacent
number ranges for channel types also results in more readable logic in
other locations.

This was tested with -I csv:column_formats=t,2a,l,a,x4,a,-,b3 example
data, and works as expected.
2019-12-21 18:20:04 +01:00
Gerhard Sittig cd7c5f9655 input/csv: add automatic format match support
Implement .format_match() support in the CSV input module. Simple
multi-column files will automatically load without an "-I csv" spec.
Non-default option values still do require the module selection before
options can get passed to the module.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 43e1e23a11 input/csv: another stab at option help texts
Try to balance a compact format and completeness/accuracy of content for
builtin help texts for the CSV input module's options. Assume a technical
audience (this is signal analysis software after all).

Rename a few internal identifiers which help organize the list of options
and their help texts. Too short names became obscure.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 7e4e65bf65 input/csv: add support for timestamp columns, auto detect samplerate
Accept 't' format specs for timestamp columns. Automatically derive the
samplerate from input data when timestamps are available and the user
did not provide a rate. Stick with a simple approach for robustness
since automatic detection is easy to override when it fails. This
feature is mostly about convenience.
2019-12-21 18:20:04 +01:00
Gerhard Sittig fc3b42e93a input/csv: robustness nits in column format dispatching
The previous implementation open coded type checks by comparing an enum
value against specific constants. Which was especially ugly since there
are multiple types which all are logic, and future column types neither
get ignored nor have channels associated with them.

Improve readability and robustness by adding helpers which check classes
(ignore, logic, analog) instead of the multitude of -/x/o/b|l/a variants
within the classes.

Also comment on the order of channel creation, and how to improve it.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 08eb955a69 input/csv: update comments/helptext for analog input data
Expand the developer comment that's inline in the source file. There is
enough room to explain things. Try to come up with a "one-line" help text
that is precise yet compact, and does inform the user of available format
choices including modifiers. Chances are that longer descriptions start
reducing the usefulness of the help or the visibility of options when
users are in a hurry. Those who care can access the manual.

Mark more options as obsolete, and mention more default values in the
builtin help text. Also tweak a comment on getting channel names from
header lines.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 3f1f63f007 input/csv: work around undesired logic/analog group "bleeding"
Support for mixed signal CSV input data is desirable and should be
possible. The current implementation just happens to not fully cope with
arbitrary mixes of data types in columns yet. Add a quick workaround,
but also a TODO item to properly address the topic later.
2019-12-21 18:20:04 +01:00
Gerhard Sittig a267bf450c input/csv: accept user provided analog resolution in column formats
Stick with the (arbitrary) default of 3 digits for analog data. Accept
user specified digit counts in the column_formats= option, like "a4".
2019-12-21 18:20:04 +01:00
Gerhard Sittig 43bdef2634 input/csv: add support for analog input data
Extend the CSV input module which was strictly limited to logic data so
far. Add support for analog data types. Implement the 'a' column format,
and feed analog data to the session bus.

This implementation feeds data of individual analog channels to the
session bus in separate packets each. This approach was found to work
most reliably, not all recipients support the submission of multiple
samples for multiple channels in a single packet.

A fixed 'digits' value is used. This needs to get addressed later.

Local experiments suggest that the 'double' data type for analog data
can result in erroneous visual presentation (observed with sigrok-cli).
Use 'float' for now, until the issue is understood and got fixed.
Support for double is prepared internally and is easily enabled.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 5ada72fc0a input/csv: address unassorted nits
Address several minor nits. Eliminate unneeded variables. Update text to
number conversion comments including wildcard handling. Remove empty
lines in init() which used to spill out a set of lines which all do the
same thing (evaluate a set of options) and shall belong together.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 9e7af34eaf input/csv: move channel creation to column processing details creation
Move the creation of logic channels to the location where formats fields
get iterated, and column processing details get derived. This reduces a
lot of redundancy, and simplifies the addition of more data formats.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 5a9711764d input/csv: update TODO comments
Update the list of TODO items at the top of the CSV input module's
source. Text line handling (counting line numbers) got fixed. Adding
support for analog channels was prepared, as are timestamp columns.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 72903e9d55 input/csv: rework user accessible options for consistency
Rename the CSV input module's option keywords. To better reflect their
purpose, and for consistency across the rather complex set of options
and how they interact. Rearrange the list of options (not that the order
matters from the outside, but it's good to have during maintenance).

Update builtin help texts which will show up in applications, as well as
the source code comments which discuss these options in greater detail.
Would be nice to have a "general" help text for input modules which is
not tied to one single option, to provide an overview or use examples.
Arrange the option keys, short and long help texts such that the source
better reflects the applications' screen layout. To better support
future maintenance, again.

Consistently separate multi-work keywords for improved readability.
Prefer underscores over dashes for consistency with common keys in
shared infrastructure in other project sources (device options, MQ
items, etc).
2019-12-21 18:20:04 +01:00
Gerhard Sittig 1a920e33fe input/csv: extend column-formats support for backwards compatibility
Extend the "column-formats" option support in the CSV input module to
also support wildcards and automatic channel count detection. Move the
format string interpretation to the location where the first data line
or the optional header line are seen. Map the simple options (single
column number and channel count, or first column number and optional
channel count) to a format string, to unify internal code paths. Remove
code paths for the previous specific yet limited scenarios.

Rephrase the condition which keeps executing the "initial receive"
phase. The text line termination sequence gets derived from the first
complete text line, but other essential information is only gathered
later, potentially after skipping a large (user specified) amount of
input data. Keep checking for this essential setup data until data or
the header actually were seen, before regular processing of input data
starts.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 2142a79b53 input/csv: introduce column-formats option (flexible logic import)
Extend the CSV input module, introduce support for the "column-formats="
option. This syntax can express the previous single- and multi-column
semantics, as well as any arbitrary order of to-get-ignored, and single-
and multi-bit columns in several formats.

The previous "simple" keywords for single and multi column modes still
are in place, it's yet to get determined whether to axe them. Depends on
whether users can handle the format strings for these simple cases.
2019-12-21 18:20:04 +01:00
Gerhard Sittig ef0b9935cf input/csv: fixup input file line number handling
The previous implementation allowed CSV input files to use any line
termination in either CR only, LF only, or CR/LF format. The first EOL
was searched for and was recorded, but then was not used. Instead any of
CR or LF were considered a line termination. "Raw data processing" still
was correct, but line numbers in diagnostics were way off, and optional
features like skipping first N lines were not effective. Fix that.

Source code inspection suggests the "startline" feature did not work at
all. The user provided number was used in the initial optional search
for the header line (to get signal names) or auto-determination of the
number of columns. But then was not used when the file actually got
processed.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 836fac9cf6 input/csv: unassorted adjustment, mostly "column processing" related
Reduce "state" in the CSV input module's context. Stick with variables
that are local to routines when knowledge of details need not be global.
Really base the processing of a column's input text on the column's
processing information which was gathered in the setup phase.

Rename few identifiers, to explicitly refer to logic channels (the only
currently supported data type of the CSV input module). Cease feeding
logic data to the session bus when there are no logic channels at all
(currently not really an option). Prepare for simpler dispatching of
parse routines should more data types get added in a future version.

Reduce some "clutter" (overly fragmented stuff that should go together
since it forms logical groups and is not really standalone). Address a
few more minor style nits (sizeof() redundancy, "seemingly inverse"
string comparison phrases).
2019-12-21 18:20:04 +01:00
Gerhard Sittig f6dcb3200d input/csv: improve "channel name from header line" logic
Improve the code paths which determine logic channels' names from an
optional CSV file header line. Strip optional quotes from the column's
input text (re-use a SCPI helper routine for that). Also use the channel
name for multi-bit fields, append [0] etc suffixes in that case. Comment
on the manipulation of input data, which is acceptable since that very
data won't get processed another time in another code path.
2019-12-21 18:20:04 +01:00
Gerhard Sittig e53f32d2b8 input/csv: introduce generic "column processing" support
Rephrase the CSV input module's implementation such that generic support
to "process a column" becomes available. All columns of an input file's
text line get inspected, a column can either get ignored, or converted
to logic data. A future version can then remove the current limitations
of single- and multi-column modes (either one single multi-bit cell, or
multiple single-bit cells which must be adjacent).

Combine the bin/oct/hex parse routines into one routine which handles up
to four bits per input number digit with common logic. Availability of
more data than channels (according to user specs) is not fatal.

Drop the counter intuitive "first-channel" option, use "first-column"
instead. Warn when comment leader and column separator are identical
(was silent before, may be unexpected). Extend diagnostics and address
minor readability nits, update comments. Rephrase logic channel name
assignment.

Use simple scalar options to derive generic processing details: Either
'single-column' and 'numchannels' are required, with an optional
'format' spec (resulting in single-column mode). Or 'first-column' with
an optional 'numchannels' (multi-column mode with fixed format, using
all available columns by default). The default is multi-column mode with
one logic channel per column and spanning all columns on a text line.
2019-12-21 18:20:04 +01:00
Gerhard Sittig de8fe3b515 input/csv: improve robustness of "use header for channel names"
Don't clobber the value of the user provided 'header' option. Use a
separate flag to track whether the header line was seen before, or
needs to get skipped when it passes by.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 246aca5f54 input/csv: move samplerate meta packet to logic data feed submission
Move the communication of the samplerate meta packet to the very spot
where logic sample data gets sent. This allows to optionally determine
late the samplerate, potentially from input data instead of user specs.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 626c388abf input/csv: rearrange text to logic data conversion and datafeed
Move the helper routines which arrange for the data feed to an earlier
spot, so that references resolve without forward declarations. Rename
routines to reflect that they deal with logic data.

Slightly unobfuscate column text to logic data conversion, and reduce
redundancy. Move sample data preset to a central location.

Rephrase error messages, provide stronger hints as to why the input text
for a conversion was considered invalid.
2019-12-21 18:20:04 +01:00
Gerhard Sittig dbc38383b2 input/csv: stricter input data test for multi column mode
The previous implementation assumed that in multi-column mode each cell
communicates exactly one bit of input (a logic channel). But only the
first character got tested. Tighten the check, to cover the whole input
text. This rejects fully invalid input, as well as increases robustness
since multi-bit input like "100" was mistaken as a value of 1 before.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 19267272d3 input/csv: slightly shuffle text routines, add bin/hex/oct doc
Add documentation to the bin/hex/oct text parse routines, and move the
bin/hex/oct dispatcher to the location where its invoked routines are.
Stick with a TODO comment for parse_line() to reduce the diff size.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 9eab4435f0 input/csv: unobfuscate text line to column splitting
The parse_line() routine is rather complex, optionally accepts an upper
limit for the number of columns, but unconditionally assumes a first one
and drops preceeding fields. The rather generic n and k identifiers are
not helpful.

Use the 'seen' and 'taken' names instead which better reflect what's
actually happening. Remove empty lines which used to tear apart groups
of instructions which are strictly related. This organization neither
was helpful during maintenance.
2019-12-21 18:20:04 +01:00
Gerhard Sittig b2c4dde226 input/csv: trim whitespace after eliminating comments
Accept when comments are indented, trim the whitespace from text lines
after stripping off the comment. This avoids the processing of lines
which actually are empty, and improves robustness (avoids errors for a
non-fatal situation). Also results in more appropriate diagnostics at
higher log levels.
2019-12-21 18:20:04 +01:00
Gerhard Sittig c6aa9870b4 input/csv: eliminate magic numbers in options declaration
The CSV input module has grown so many options, that counting them by
hand became tedious and error prone. Eliminate the magic numbers in the
associated code paths.

This also has the side effect that the set is easy to re-order just by
adjusting the enum, no other code is affected. Help text and default
values is much easier to verify and adjust with the symbolic references.

[ see 'git diff --word-diff' for the essence of the change ]
2019-12-21 18:20:04 +01:00
Gerhard Sittig ad6a2beec3 input/csv: data type nits (sizes, enums)
Use size_t for things that get counted: column indices, channel numbers
(line numbers already used size_t). De-anonymize an enum to avoid 'int'
where it gets referenced. Adjust printf(3) format strings. Get unsigned
values from option lookups (stick with 32bits, should be acceptable for
spreadsheet columns and channel counts).

Address other minor nits while we are here: Also terminate the last item
in an enum declaration. Add a doxygen comment for parse_line(). Rename a
parameter to achieve tabular doc text layout.
2019-12-21 18:20:04 +01:00
Gerhard Sittig e05f18273d input/csv: include section nits
Rephrase the #include statements in the CSV input module. "config" is
not a system header but is provided by the application source code.
Separate the config and system and application groups (their order is
essential). Alpha-sort the files within their group for simplified
maintenance.
2019-12-21 18:20:04 +01:00
Gerhard Sittig affaf54012 input/csv: add channel list checks for file re-read
Do for the CSV input module what commit 08f8421a9e did for VCD. Check
the channel list for consistency across re-imports of the same file.
This addresses the CSV part of bug #1241.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 539188e524 input/csv: improve cleanup code path, unbreak re-import
The cleanup() routine gets invoked upon shutdown, as well as before
re-importing another file. The cleanup() routine must not release
resources which get allocated in the init() routine, as the init()
routine won't run again in the module's lifetime. The cleanup() routine
must void those context fields which get evaluated in the next receive()
calls.
2019-12-21 18:20:04 +01:00
Gerhard Sittig 17c30d0593 output/vcd: support smaller timescales with higher resolution
The previous implementation inspected the input stream's samplerate, and
simply used the next 1kHz/1MHz/1GHz timescale for VCD export. Re-import
of the exported file might suffer from rather high an overhead, where
users might have to downsample the input stream. Also exported data
might use an "odd" timescale which doesn't represent the input stream's
timing well.

Rephrase the samplerate to VCD timescale conversion such that the lowest
frequency is used which satisfies the file format's constraints as well
as provides high enough a resolution to communicate the input stream's
timing with minimal loss. Do limit this scaling support to at most three
orders above the input samplerate, to most appropriately cope with odd
rates.

As a byproduct the rephrased implementation transparently supports rates
above 1GHz. Input streams with no samplerate now result in 1s timescale
instead of the 1ms timescale of the previous implementation.
2019-12-21 17:19:50 +01:00
Gerhard Sittig 4ddea31451 output/vcd: use larger data type to internally store frequency
The 'period' member of the VCD output module's context is supposed to
hold frequencies that correspond to the timescale used during export.
An 'int' (in combination with VCD's 1/10/100 constraint) thus would
result in a 1GHz limit, use uint64_t instead to support higher rates.
2019-12-21 17:19:50 +01:00
Gerhard Sittig 3895064542 output/wavedrom: rephrase accumulation of output data
Iterate over the received sample set first, before iterating over the
respective sample's number of channels. This avoids redundant extraction
of sampled bits (which saves only little), but also increases locality
of processed data (though string accumulation still may be expensive).

It also adds the future option of RLE compression during accumulation of
output data, which perfectly matches the WaveDrom syntax for repeated
bit patterns.
2019-12-21 13:58:43 +01:00
Gerhard Sittig 7a0d1bdc20 output/wavedrom: separate data processing logic from init/cleanup
Rearrange the order of routines in the wavedrom output module. Keep the
flow of .receive() -> .process_logic() -> .wavedrom_render() in one common
group of routines, which is not disrupted by the .init() and .cleanup()
routines which are kind of boilerplate in the source file. This increases
readability and maintainability.
2019-12-21 13:58:43 +01:00
Gerhard Sittig dd5735c998 output/wavedrom: address style nits
Adjust brace style, use C language comments, drop camel case. Use size_t
for indices and offsets. Unobfuscate the open/close logic of rendered
output. Allocate zero-filled memory, reduce sizeof() redundancy. Don't
SHOUT in the module's .name property.

[ Changes indentation, see 'git diff -w -b' for review. ]
2019-12-21 13:58:43 +01:00
Marc Jacobi 40f812f5dc output/wavedrom: introduce a wavedrom output module
WaveDrom provides a textual description of digital timing diagrams,
using the JSON syntax. See https://wavedrom.com/ for more details.
2019-12-21 13:58:43 +01:00
Frank Stettner 675cb86f15 hp-3478a: Check for overflow. 2019-12-20 23:08:51 +01:00
Frank Stettner 7812a5c802 hp-3478a: Add get/set/list of digits. 2019-12-20 23:08:51 +01:00
Frank Stettner e5137b9343 hp-3478a: Add get/set/list of measurement ranges. 2019-12-20 23:07:25 +01:00
Frank Stettner ccf68765aa Add config key SR_CONF_DIGITS. 2019-12-20 13:02:06 +01:00
Frank Stettner 84b4f9a1ff Add config key SR_CONF_RANGE. 2019-12-20 13:02:06 +01:00
Michał Janiszewski e3f86ef5fc beaglelogic: Fix mismatched printf specifiers. 2019-12-19 22:20:47 +01:00
Gerhard Sittig dc40081706 asix-sigma: comment on trigger/stop position, silence warning
Add a comment on the logic which skips the upper 64 bytes of a 512 bytes
chunk in the Asix Sigma's sample memory. Move the initial assignment and
the subsequent update from a value which was retrieved from a hardware
register closer together for awareness during maintenance. Pre-setting a
high position value that will never match when the feature is not in use
is very appropriate.

Adjust the sigma_read_pos() routine to handle triggerpos identically to
stoppos. The test condition's intention is to check whether a decrement
of the position ends up in the meta data section of a chunk. The previous
implementation tested whether a pointer to the position variable ended in
0x1ff when decremented -- which is unrelated to the driver's operation.
It's assumed that no harm was done because the trigger feature is
unsupported (see bug #359).

This silences the compiler warning reported in bug #1411.
2019-12-19 21:18:35 +01:00
Adrian Godwin a16198316f scpi-dmm: Added minimal support for HP34401A (PR #36) 2019-12-17 00:08:09 +01:00
Peter Åstrand cf6beeb20d korad-kaxxxxp: Add support for RND 320-KD3005P (PR #35)
Since this model replies with a serial number, truncate before that
2019-12-17 00:08:03 +01:00
Sylvain Pelissier 24931412ee lecroy-xstream: Remove header read (PR #33) 2019-12-16 23:52:50 +01:00
Andreas Sandberg 19ab8e363e fluke-dmm: Fix use-after-free bugs
The handler for fluke 18x and 28x DMMs allocates several data
structures on the stack that are used after they have been freed when
creating a data feed packet.

Restructure the code so that all handlers send their own packets. As a
bonus, this avoid a couple of small heap allocations.
2019-12-16 15:51:07 +01:00
Frank Stettner 253d653d4d korad-kaxxxxp: Reword debug output for the status byte. 2019-12-16 15:42:53 +01:00
Frank Stettner 2e129b8b25 korad-kaxxxxp: Send META packet when states have changed. 2019-12-16 15:42:49 +01:00
Frank Stettner 8da30037cf korad-kaxxxxp: Fix bug when setting values while acquisition is running.
By separating the variables that holds the get and set values, the output
state, OVP and OCP can now be set while the acquisition is running.
Also some variables are named more clearly.
2019-12-16 15:42:36 +01:00
Frank Stettner dfdf4c83ff rdtech-dps: Send META package when states have changed. 2019-12-16 15:38:58 +01:00
Frank Stettner cce6a8a1b7 rdtech-dps: Handle different current/voltage digits for the various models. 2019-12-16 15:38:54 +01:00
Frank Stettner aff2094193 rdtech-dps: Retry sr_modbus_read_holding_registers() up to 3 times.
The communication with the rdtech power supplies is not very reliable,
especially during the start. Because of that, the driver tries to read the
modbus registers up to three times.
Nevertheless there is the chance, that the communication fails.
2019-11-13 10:09:07 +01:00
Frank Stettner c9b187a607 rdtech-dps: Use SR_MQFLAG_DC only for voltage and current channels. 2019-11-12 23:14:33 +01:00
Frank Stettner 7c0891b0b8 rdtech-dps: Synchronize read and write operations. 2019-11-12 23:14:33 +01:00
Gerhard Sittig ad4174c1d8 ols: introduce metadata quirks support, unbreak Logic Shrimp
Introduce quirks support for devices which provide incomplete metadata.
Add conservative logic to unbreak the Logic Shrimp. Amend previously
received information when it was incomplete, but don't interfere if a
future firmware version fixes the issue.

Without this change, the device gets detected but "has zero channels"
and would be unusable. Because when a device provides metadata, these
details are used exclusively, no fallbacks apply.
2019-11-07 23:16:06 +01:00
Sylvain Munaut cfdc80151b std: Remove call to sr_dev_close from std_serial_dev_acquisition_stop
There is no reason to close the entire device in acquisition_stop and
this actually breaks pulseview on serial devices using this callback
when running multiple acquisition cycles

This fixes bug #1271.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2019-11-02 16:38:13 +01:00
Marc Schink f216309fd0 demo: Fix memory leak
How to reproduce:

 $ G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --leak-check=full sigrok-cli --scan --driver demo

Signed-off-by: Marc Schink <dev@zapb.de>
2019-11-02 15:32:22 +01:00
Gerhard Sittig 76dea519e4 mooshimeter-dmm: silence compiler warning (memset() prototypes)
The Mooshimeter driver uses mem*() and str*() library calls. Include the
<string.h> header file to silence compiler warnings.

  ...
  ./src/hardware/mooshimeter-dmm/protocol.c: In function 'lookup_tree_path':
  ./src/hardware/mooshimeter-dmm/protocol.c:275:3: warning: implicit declaration of function 'strchr' [-Wimplicit-function-declaration]
     end = strchr(path, ':');
     ^
  ./src/hardware/mooshimeter-dmm/protocol.c:275:9: warning: incompatible implicit declaration of built-in function 'strchr' [enabled by default]
     end = strchr(path, ':');
           ^
  ...
2019-10-29 17:50:07 +01:00
Gerhard Sittig 113de3a572 bt: apply 20s timeout to BLE connect(2) attempts
Even working BLE devices won't immediately succeed in the first call to
connect(2), which is why the "in progress" phase was added. But absent
peers made the previous implementation try forever, getting stuck in the
sr_bt_connect_ble() call.

Try to balance these two constraints. Do terminate BLE connect attempts
after a generous timeout. When this 20s period passed, there probably is
a configuration error or unresponsive peer. Yet the timeout needs to be
in this ballpark to not erroneously fail for working setups.
2019-10-29 17:42:34 +01:00
Uwe Hermann 0f92d5db03 bt/bt_bluez: Adjust some log levels. 2019-10-26 21:31:51 +02:00
Uwe Hermann f314d87111 bt/bt_bluez: Remove some no longer needed verbose log messages. 2019-10-26 21:31:51 +02:00
Uwe Hermann 59d916fe67 mooshimeter-dmm: Only report successful scan upon working connection. 2019-10-26 21:10:48 +02:00
Derek Hageman ebcd1aba01 Add support for the Mooshimeter DMM
This adds support for the Mooshim Engineering BLE based Mooshimeter.
Because the meter requires raw BLE packets, the driver uses the BLE
layer directly. Since the meter has no physical way of configuring it,
the actual configuration is set entirely with sigrok device options.
2019-10-22 12:21:47 +02:00
Stefan Brüns 02a8c07d89 Fix link errors when compiling with LTO enabled
When libsigrok is compiled with link-time-optimization, the linker
stumbles over the section named the same as the function. Whether this
is a compiler/linker bug or a coding error is unknown.

Renaming the special section (to the same as already used on OS X) avoids
the problem.

This fixes bug #1416.
2019-10-07 00:13:13 +02:00
Kate J. Temkin 1656cd4a4a fx2lafw: allow for sampling at 48MHz, matching a fw change 2019-10-01 23:52:00 +02:00
Jan Luebbe 6d8205ad9a manson-hcs-3xxx: support new firmware for HCS-3202
A recently bought device seems to use a different model string, but
still speaks the same protocol.
2019-09-27 15:35:38 +02:00
Sebastian Reichel f6129c8f0c rigol-ds: Add initial Rigol MSO5000 support.
This adds basic support for the Rigol MSO5000 series. It has
the same problems as the DS4000 series: Live capture provides
one digital channel per byte. Buffered memory returns the data
compressed (one byte has 8 digital channels), but the banks are
read separately. It's not possible to read uint16.
2019-08-21 14:54:12 +02:00
Miklos Marton 4d8338bb96 demo: Add random analog signal generation 2019-07-31 23:15:18 +02:00
Elen Eisendle b1b8a7d079 korad-kaxxxxp: Add Korad KD6005P 2019-07-31 23:15:11 +02:00
Gerhard Sittig b50970a541 lcr/vc4080: introduce LCR packet parser for Voltcraft 4080 (and PeakTech 2165)
Introduce the lcr/vc4080.c source file which implements the parser for
the serial data stream of the Voltcraft 4080 LCR meter. Add the meter to
the list of supported devices in the serial-lcr driver, as well as the
PeakTech 2165 LCR meter which is another compatible device.

This implementation contains a workaround for USB based serial cables
which seem to suffer from incomplete parity handling (observed with the
FT232R based PeakTech cable). Similar approaches were seen in existing
DMM drivers.

This implementation supports the main and secondary displays. The D and Q
"displays" which are communicated in the serial packets appear unreliable
and redundant, users can have the D and Q values shown in the supported
displays.
2019-07-31 22:40:44 +02:00
Gerhard Sittig 66c300c4a6 serial-lcr: also request packets before initial state retrieval
Commit cb5cd1538f introduced packet request support in the serial-lcr
device driver. Calls were added to the detection of the device's
presence, and the periodic acquisition of measurement data. Add another
call to the device configuration retrieval that follows the presence
detection, without it communication timed out with no data received.

Also slightly raise the timeout for this device configuration gathering
phase. With one second sharp, the VC4080 was detected, but getting its
current configuration kept failing. This device's serial communication
is extra slow (1200 bps) and the packets are rather large (39 bytes).
Which made the stream detect's receive routine stop checking for the
availability of more data while a packet was being received.
2019-07-31 15:23:03 +02:00
Gerhard Sittig c4d2e6fa5e serial-lcr: move probe, dev inst creation, data read out of scan
Move the initial device probe (LCR packet validity check), the creation
of the device instance after successful probe, and the subsequent packet
inspection after resource allocation out of the scan routine. This shall
improve readability of the serial-lcr driver's probe logic, and reduces
diffs when handling of multiple connections gets added later.

Add a developer comment, the serial-lcr driver needs to handle multiple
connections when the conn= spec is ambiguous (multiple cables of the
same type, with the same VID:PID).
2019-07-31 15:23:03 +02:00
Gerhard Sittig 0fb4512125 dmm/bm86x.c: reduce verbosity level (packet request)
Remove a debug message from the Brymen BM86x meter's packet request method.
2019-07-31 15:23:03 +02:00
Gerhard Sittig 60117e6e9a serial_hid: reduce verbosity, drop excessive debug messages
The HID transport for serial communication was rather noisy at log
levels of 4 and above. Now that test coverage was increased and
operation is stable, drop a lot of the excessive and redundant debug
messages in regular code paths.
2019-07-31 15:23:03 +02:00
Uwe Hermann ea9e7a3e82 config keys: Revert re-orderings to avoid ABI changes. 2019-07-30 23:53:42 +02:00
Uwe Hermann 1838d9f13f hameg-hmo: Fix two compiler warnings (-Wstringop-truncation).
src/hardware/hameg-hmo/protocol.c: In function ‘hmo_scope_state_get’:
  src/hardware/hameg-hmo/protocol.c:1130:2: warning: ‘strncpy’ specified bound 20 equals destination size [-Wstringop-truncation]
    strncpy(state->trigger_pattern,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     sr_scpi_unquote_string(tmp_str),
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CC       src/hardware/hp-3478a/api.lo
    CC       src/hardware/hung-chang-dso-2100/protocol.lo
  src/hardware/hameg-hmo/api.c: In function ‘config_set’:
  src/hardware/hameg-hmo/api.c:388:3: warning: ‘strncpy’ specified bound 20 equals destination size [-Wstringop-truncation]
     strncpy(state->trigger_pattern,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      tmp_str,
      ~~~~~~~~
      MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-07-30 23:53:42 +02:00
Uwe Hermann c38d69adf4 hameg-hmo: Fix two compiler warnings (-Warray-bounds).
src/hardware/hameg-hmo/protocol.c: In function ‘hmo_scope_state_get’:
  src/hardware/hameg-hmo/protocol.c:1035:31: warning: array subscript 0 is above array bounds of ‘char *[0]’ [-Warray-bounds]
     g_free(logic_threshold_short[i]);
            ~~~~~~~~~~~~~~~~~~~~~^~~
  src/hardware/hameg-hmo/protocol.c:1035:31: warning: array subscript 0 is above array bounds of ‘char *[0]’ [-Warray-bounds]
  src/hardware/hameg-hmo/protocol.c:974:24: warning: array subscript 0 is above array bounds of ‘char *[0]’ [-Warray-bounds]
     logic_threshold_short[i] = g_strdup((*config->logic_threshold)[i]);
     ~~~~~~~~~~~~~~~~~~~~~^~~
  src/hardware/hameg-hmo/protocol.c:974:24: warning: array subscript 0 is above array bounds of ‘char *[0]’ [-Warray-bounds]
2019-07-30 23:53:42 +02:00
Guido Trentalancia 97a000748a hameg-hmo: Add SR_CONF_HIGH_RESOLUTION and SR_CONF_PEAK_DETECTION.
Implement High Resolution mode and Peak Detection settings.

Beautify the code by reordering the Trigger Source settings
definitions.
2019-07-26 01:43:19 +02:00
Guido Trentalancia 29a9b1a0bd hameg-hmo: Get SCPI_CMD_GET_HORIZONTAL_DIV at runtime.
Get the number of horizontal divisions from the device (at runtime)
instead of hardcoding its value in the driver.
2019-07-26 01:43:19 +02:00
Guido Trentalancia a12456f1bb hameg-hmo: Don't hardcode POD/channel numbers.
Don't hardcode the number of PODs or the number of logic (digital)
channels per POD.
2019-07-26 00:55:40 +02:00
Guido Trentalancia 0c96de7223 hameg-hmo: Remove duplicate function call.
This call was inadvertently left around in commit
8cccbac8da.
2019-07-26 00:55:40 +02:00
Guido Trentalancia 66ddc22a1d hameg-hmo: Rename SCPI_CMD_GET_VERTICAL_DIV to *_SCALE.
Fix the name of the SCPI command used to get the vertical scale.
2019-07-26 00:55:40 +02:00
Guido Trentalancia 396af5ad7d hameg-hmo: Beautify trigger pattern.
Beautify the trigger pattern by removing the quotes from the SCPI response
using sr_scpi_unquote_string() and improve the string pattern handling.
2019-07-26 00:55:40 +02:00
Guido Trentalancia a058de0410 hameg-hmo: Add missing 1ns timebase for some models.
Extend the timebase setting down to 1ns from the current limit
of 2ns for all supported series except the HMO Compact.
2019-07-26 00:55:40 +02:00
Guido Trentalancia 0184aca19d hameg-hmo: Add missing quotes for SCPI_CMD_SET_TRIGGER_PATTERN. 2019-07-26 00:11:07 +02:00
Guido Trentalancia b720f16eb5 hameg-hmo: Add RTA4000 MSO support (untested).
According to the latest available version of the manual, as
for the RTB2000 and RTM3000 series, the RTA4000 series also
uses a slightly different dialect than other previously
supported models, in particular when it comes to the POD
(logic channel groups) handling.

I do not have such model available for testing therefore, as
for the RTB2000 and RTM3000 support recently introduced, I do
not know whether or not the RTA4000 also understands the
existing dialect. In doubt, the new official dialect is
implemented by this patch.
2019-07-26 00:11:07 +02:00
Guido Trentalancia aac3063300 hameg-hmo: Add RTB2000 and RTM3000 MSO support (untested).
According to the latest available version of the manual, they
both use a slightly different dialect than currently supported
models, in particular when it comes to the POD (logic channel
groups) handling.

I do not have any of the above models available for testing
therefore I do not know whether or not they also understand
the existing dialect. In doubt, the new official dialect is
implemented by this patch.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 3a247d0359 hameg-hmo: Add SR_CONF_LOGIC_ANALYZER drvopt. 2019-07-26 00:11:07 +02:00
Guido Trentalancia 4f3cb1eaf7 hameg-hmo: Fix the upper limit for the vertical scale. 2019-07-26 00:11:07 +02:00
Guido Trentalancia 1203acc78f hameg-hmo: Only update states after successful SCPI SET.
Update the oscilloscope state with new settings only after
they have been successfully stored in the device to avoid
an inconsistent state in case of SCPI SET command failure.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 39e1972347 hameg-hmo: Fix for an incorrect samplerate being returned.
The hameg-hmo driver returns an incorrect sample rate: to reproduce this
bug, set the maximum sample rate from the ACQUIRE menu.

This patch fixes the driver so that the correct sample rate is returned.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 3883934404 hameg-hmo: Avoid bogus SCPI timeouts.
During the initial configuration phase of the hameg-hmo driver
only send an OPC command if a SCPI command has been previously
sent to the device so that bogus SCPI timeouts are avoided.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 262061ff3d hameg-hmo: Use 1-based (not 0-based) POD numbers.
The current starting index for the POD name is currently wrong as it is zero.

The official POD numbering starts instead at 1 (see device panel, buttons
and manual), so the current index used for message printing and groups
naming in the driver needs to be incremented by one.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 830e24b68f hameg-hmo: SR_CONF_LIMIT_SAMPLES/_FRAMES don't support _GET.
The samples and frame acquisition limits are not stored in the device or
elsewhere. Therefore they should not be read.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 673989692c hameg-hmo: Avoid a double-free.
Avoid double memory freeing leading to segmentation fault in when a SCPI
command fails to get a string due conditions such as a timeout or an invalid
command.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 4fa4db2c79 hameg-hmo: Add SR_CONF_TRIGGER_PATTERN support.
Introduce support for the Pattern Trigger functionality, sometimes also
called Logic Trigger.
2019-07-26 00:11:07 +02:00
Guido Trentalancia c8ecfa6ea4 hameg-hmo: When setting slope, also set trigger type to edge.
When setting the type of slope for the edge trigger function, also set the
trigger type to edge because it is not necessarily configured that way and
therefore such functionality might fail to work properly!

This fixes parts of bug #1328.
2019-07-26 00:11:07 +02:00
Guido Trentalancia a9f3fa0548 hameg-hmo: Remove unused SCPI command enums, sort entries. 2019-07-26 00:11:07 +02:00
Guido Trentalancia 4cf90b8667 hameg-hmo: Add support for the HMO1202 MSO. 2019-07-26 00:11:07 +02:00
Guido Trentalancia e35ebc6aa3 hameg-hmo: Initial R&S RTC1000 MSO support attempt.
(might need testing)
2019-07-26 00:11:07 +02:00
Guido Trentalancia e131be0ac3 hameg-hmo: Add support for SR_CONF_LOGIC_THRESHOLD/_CUSTOM.
Update the Hameg/Rohde&Schwarz HMO driver (hameg-hmo) so that it
is possible to configure the logic threshold for digital signals.

The user can get or set the logic threshold configuration using
the channel group POD0 (and/or POD1 where available), for example:

sigrok-cli --driver hameg-hmo --get logic_threshold -g POD0
sigrok-cli --driver hameg-hmo --config logic_threshold=TTL --set -g POD0

sigrok-cli --driver hameg-hmo --get logic_threshold_custom -g POD0
sigrok-cli --driver hameg-hmo --config logic_threshold_custom=0.7 --set -g POD0
2019-07-26 00:11:07 +02:00
Guido Trentalancia 3308450089 hameg-hmo: Update the default serial port options.
Update the default serial port options for Rohde&Schwarz and
Hameg mixed-signal oscilloscope devices connected through USB.

Also, remove misplaced and unused serial port configuration option.

This patch complements fa3d104f17
in terms of updating the USB PIDs for new devices (HMO series).

This fixes parts of bug #1321.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 232eb33c67 hameg-hmo: Try to find a valid serialcomm if none is supplied.
If no serial port option is specified on the command-line using the
"serialcomm" driver option, but the device is connected through USB
and it requires a known default serial port option, then use it in
order to avoid data corruption or even worse problems.

Note: the easiest way to reproduce data corruption on HMO3000 series
is to start an analog data acquisition (e.g. on channel CH1) after
switching from Ethernet mode to USB VCP mode (HO732 USB/Ethernet interface).

This fixes parts of bug #1321.
2019-07-26 00:11:07 +02:00
Guido Trentalancia bb0665868e hameg-hmo: Avoid getting stuck upon SCPI timeouts.
Correctly set the length of the buffer used to hold the SCPI response
from the device containing the binary acquisition data.

If a timeout occurs, truncate the buffer and send the partial response
from the device instead of getting stuck on timeouts!

Thanks to Stefan Brüns for reviewing the first version of this patch
and spotting out a serious problem with it.

This fixes bug #1323.
2019-07-26 00:11:07 +02:00
Guido Trentalancia d779dcacb7 hameg-hmo: Add SR_CONF_LIMIT_SAMPLES support.
At the moment only the maximum number of frames to be acquired can be
configured for the Hameg/Rohde&Schwarz HMO mixed-signal oscilloscope
series driver (hameg-hmo).

This patch adds support to configure the number of samples to acquire
in both analog and digital (logic) mode.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 6d0f3508f7 hameg-hmo: Add support for 16 digital (logic) channels.
This patch introduces the support for 16 digital (logic) channels for the
following oscilloscope models: HMO3032, HMO3042, HMO3052 and HMO3522
(previously only 8 digital channels were supported, i.e. only 1 POD).
2019-07-26 00:11:07 +02:00
Guido Trentalancia 91525636a6 hameg-hmo: Remove invalid HMO2522, add missing HMO3522.
This patch takes care of removing an invalid product model (HMO2522)
and adds a missing product model (HMO3522) in the hameg-hmo driver,
thus extending the number of supported oscilloscope models.

This fixes bug #1322.
2019-07-26 00:11:07 +02:00
Guido Trentalancia 14cb6aa40a hameg-hmo: Use g_byte_array_free() instead of g_free().
Use the appropriate glib function to free memory (byte array).

This fixes bug #1324.
2019-07-26 00:10:35 +02:00
Guido Trentalancia 1bb348cdbf std: std_gvar_tuple_array/_rational: Fix GVariantBuilder type.
Fix the type of container used to initialize the GVariantBuilder
structure which builds an array of tuples.
2019-07-26 00:10:35 +02:00
Uwe Hermann 80d3497569 hantek-4032l: Fix broken triggering on low signal.
The trigger range/mask "compression" procedure is apparently not
required and breaks triggering on a low line state.

This has been verified to fix the issue on a Hantek 4032L with FPGA
version 0x4303. It is possible that the procedure mentioned above
might be required for other FPGA versions, though that is unknown.

If you experience trigger issues with other FPGA versions, please
contact us for further debugging and testing.

This fixes bug #1402.
2019-07-06 23:22:47 +02:00
Uwe Hermann e6bb2984e9 hantek-4032l: Cosmetics. 2019-07-06 23:21:22 +02:00
Nadav Mavor 744d683ca7 rigol-ds: Add Agilent DSO1000B series IDs 2019-07-06 16:54:26 +02:00
Mike Walters 0b0f40d864 scpi-pps: Support HP 66312a 2019-07-03 12:43:18 +01:00
Uwe Hermann be7c63dcf8 serial_hid: Don't print empty strings, [aaaa.bbbb] VID/PID format. 2019-06-20 18:16:31 +02:00
Uwe Hermann c0aa074eb2 std: Factor out std_dummy_set_params(). 2019-06-20 17:56:29 +02:00
Gerhard Sittig e378e3a2d4 dmm/bm86x: unbreak temperature modes (two probes and no probes)
The Brymen BM86x supports up to two temperature probes. The dual display
can show individual temperatures of the two probes or differences. The
previous implementation "detected" a value of zero degrees when no probe
was attached and the display showed dash lines. When cycling assignments
of probes to displays, some valid combinations did not result in values
shown by the libsigrok driver.

An implementation detail of the formerly separate brymen-bm86x driver
was lost during recent migration of the dmm/bm86x parser into the
serial-dmm driver. When the meter's temperature function is selected,
it's essential to inspect the primary display's flags and digits, to
determine the secondary display's quantity and unit. Previous versions
never bothered to explicitly check for the "----" digits text, but the
combination of the primary's last digit showing C/F as well as the
binary C/F flags before the value provided hints which the secondary
displays group of digits and flags did not.

This fixes bug #1394.
2019-06-20 17:23:48 +02:00
Gerhard Sittig 3775ef8c7a dmm/bm86x: drop local packet dump, already done in serial-dmm 2019-06-20 17:21:47 +02:00
Gerhard Sittig a1771c26ba serial_hid: make --list-serial output compatible with conn=, print "VID.PID"
When the list of all connections gets created which are supported by the
HID serial transport, items contain a "hid/ch9325/raw=/dev/hidraw3" path
and a "1a86:e008" pair of vendor and product IDs.

Separate the VID/PID pair by a period not a colon, so that --list-serial
output immediately becomes usable with "--driver <name>:conn=<spec>"
invocations. Eliminate the necessity to adjust clipboard context by the
user. This improves usability in cases where not a single connection
gets addressed, but a group of connections gets specified by ambiguous
conn= specs.

$ sigrok-cli -d uni-t-ut32x:conn=1a86.e008 --scan
2019-06-20 17:21:47 +02:00
Gerhard Sittig 87307940f1 serial_hid: address constness nits 2019-06-20 17:21:47 +02:00
Gerhard Sittig cb5cd1538f serial-lcr: add support for packet request
Some meters require the reception of a request before they provide
acquisition data. Add support for the chip driver's .packet_request()
routine, and timeout handling in the serial-lcr driver. This follows
the serial-dmm model.
2019-06-20 16:45:36 +02:00
Gerhard Sittig 3f5473dde2 serial-lcr: add support for chip specific channel names
Allow LCR chip drivers to specify custom printf() formats for their
channel names. Default to "P1" etc in the absence of format specs.
This implementation is similar to serial-dmm.
2019-06-20 16:45:36 +02:00
Gerhard Sittig 238b874e44 lcr/es51919: minor style nits in the ES51919 packet parser
Use macros for frequency constants. They hopfully are more readable than
large number literals with their magnitude being not as apparent.
2019-06-20 16:45:36 +02:00
Gerhard Sittig 8556703a6c dmm/eev121gw: visibility nits (single display parse routine)
The EEVBlog 121GW meter support always registers the three-displays
parse routine with the serial-dmm device driver. The single-display
routine need not be public. Adjust the visibility.

Reduce indentation for a continued line in a nearby declaration
while we are here.
2019-06-20 16:45:36 +02:00
Daniel Anselmi 08ecb98e84 ipdbg-la: Fix an issue when capture rate is 100%.
If the capture ratio was set to 100%, the delay counter-value has an
overflow and a delay of 0 samples is used.

This fixes bug #1393.
2019-06-20 14:30:05 +02:00
Uwe Hermann bf6b9e7b16 serial: Shorten a few code snippets. 2019-06-15 17:35:42 +02:00
Uwe Hermann c87e9d26f4 serial_hid.h: Update SER_HID_CHUNK_SIZE comment. 2019-06-15 17:17:52 +02:00
Uwe Hermann 92499a9c78 serial-lcr: Replace duplicated std_session_send_frame_end(). 2019-06-15 15:54:48 +02:00
Uwe Hermann 9451e01e77 Eliminate VID_PID_TERM in favor of ALL_ZERO. 2019-06-15 15:45:12 +02:00
Uwe Hermann 66e19f47f4 ftdi-la: Fix VID/PID format in a log message.
Before: 0x 403:0x6001
After:  0x0403:0x6001
2019-06-14 00:15:24 +02:00
Gerhard Sittig 01ae826ba3 ftdi-la: do enter the error path upon VID:PID mismatch
Bug #1390 reports that "!desc" is always true (should be: false?). But
the actual problem would be that 'desc' is _not_ NULL when none of the
supported chips' VID:PID matched (FT232H happens to "get found" then,
erroneously).

Add a sentinel to the table of supported chips, such that 'desc' becomes
NULL upon mismatch, and the error path is entered.
2019-06-13 19:38:06 +02:00
Gerhard Sittig 03f169b36b serial-dmm: rename victor-dmm-ser entry, default to USB HID cable
The serial-dmm entry for Victor DMMs is able to communicate to either
geniune COM ports (RS232 or USB CDC) or the obfuscating USB HID cables.
The victor-dmm driver became obsolete and was removed. Rename the
serial-dmm entry, remove the no longer needed "-ser" suffix. Suggest a
default connection via the obfuscating USB HID cable, accept user
provided overrides for regular serial cables (same behaviour as before,
connection spec for serial ports keeps being mandatory).
2019-06-13 19:35:57 +02:00
Gerhard Sittig e45a8de41c victor-dmm: remove obsolete device driver, has moved to serial-dmm
Remove the victor-dmm device driver. Its functionality is contained in
the Victor specific serial-over-HID transport, the FS9922 DMM parser,
and the serial-dmm device driver. The additional implementation became
obsolete.
2019-06-13 19:34:43 +02:00
Gerhard Sittig 0cdb72c8f2 serial-hid: add support for (scrambling) Victor DMM cables
Introduce a serial transport which undoes the Victor DMM cable's
obfuscation to the DMM chip's original data packet. Which allows to
re-use the existing FS9922 support code, obsoleting the victor-dmm
device driver.
2019-06-13 19:34:09 +02:00
Gerhard Sittig a89884c16c uni-t-ut32x: don't provide a default conn= spec in the driver source
This undoes the essence of commit bf700f679a, which introduced the
default conn= spec. Which improved usability: Users just select the
device and need not specify the connection. But also resulted in the
UT32x thermometer driver's probe to "succeed" as soon as the WCH CH9325
chip was found, no data check was involved in the scan. Unfortunately
this chip is also used in the popular UT-D04 cable, and thus there were
many false positives.
2019-06-13 19:33:01 +02:00
Gerhard Sittig 97c8fa70da brymen-bm86x: retire libusb using driver, has moved to serial-dmm
Remove the src/hardware/brymen-bm86x/ hierarchy of source files. Its
functionality has moved to the bm86x packet parser and the serial-dmm
device driver.
2019-06-13 19:32:51 +02:00
Gerhard Sittig b800667daf serial-dmm: bm86x: increase packet request frequency
Request packets from the Brymen BM86x meter much faster. The previous
implementation in the separate driver used to immediately send another
request when a measurement arrived, with a 10ms granularity in the poll
routine, and a 500ms timeout between requests.

Considering the meter's update rate, stick with the 500ms timeout, but
increase the maximum request rate to 10 per second, with a minimum of 2
per second. This receives measurement data at the meter's capability
(compare DC and AC modes, seems to automatically adjust to the internal
operation, and match the display update rate).
2019-06-13 19:31:31 +02:00
Gerhard Sittig 0759e2f55b dmm/bm86x: add Brymen BM86x packet parser, register with serial-dmm
Move Brymen BM86x specific packet parse logic to a new src/dmm/bm86x.c
source file, and register the routines with the serial-dmm driver's list
of supported devices. Which obsoletes the src/hardware/brymen-bm86x/
hierarchy.

This implementation differs from the previous version: The parse routine
gets called multiple times after one DMM packet was received. Values for
the displays get extracted in separate invocations, the received packet
is considered read-only. Unsupported LCD segment combinations for digits
get logged. Low battery gets logged with higher severity -- the validity
of measurement values is uncertain after all. The parse routine uses
longer identifiers. Packet reception uses whichever serial transport is
available (need no longer be strictly USB HID nor libusb based). All
features of the previous implementation are believed to still be present
in this version.

This configuration queries measurement values each 0.5 seconds and
re-sends a not responded to request after 1.5 seconds. Which follows the
combination of the vendor's suggested flow (frequency) and the previous
implementation's timeout (3x 500ms). This implementation does not try to
re-connect to the HID device for each measurement, and neither checks
for the 4.0 seconds timeout (vendor's suggested flow). Local experiments
work without these.
2019-06-13 19:23:24 +02:00
Gerhard Sittig 7c7a112046 brymen-bm86x: rename specific Brymen BM86x driver (libusb implementation)
The src/hardware/brymen-bm86x/ source code contains specific support for
the Brymen BM86x devices, and directly depends on the libusb library.
Rename the registered device (append the "-usb" suffix) before adding
BM86x support to the serial-dmm driver.
2019-06-13 19:22:02 +02:00
Gerhard Sittig a10284cd18 serial-hid: introduce support for Brymen BU-86X IR adapters
The Brymen BU-86X infrared adapters are sold with BM869s meters. Raw
streams of data bytes get communicated by means of HID reports with
report number 0 and up to 8 data bytes each. Communication parameters
are fixed and need no configuration.
2019-06-13 18:33:23 +02:00
Gerhard Sittig 0527cc3ad7 serial-dmm: add support for default connections (USB cables)
Some meters which are supported by the serial-dmm driver don't strictly
require the user's COM port specification. When a known (usually bundled,
or even builtin) cable type is used, we can provide a default conn= spec
and thus improve usability. Prepare the DMM_CONN() macro, accept user
overrides.
2019-06-13 18:33:23 +02:00