Commit Graph

5608 Commits

Author SHA1 Message Date
Ralf 2dddd5bd5e scpi: accept numbers like 4.0000E3 as integer value
MSO5000 returns memory depth value in that format, e.g.
sr: [04:21.491949] scpi_vxi: Successfully sent SCPI command: 'ACQ:MDEP?'.
sr: [04:21.501463] scpi: Got response: '4.0000E+03', length 10.

[ gsi: drop redundant assignment and parens, amend diag message ]
2020-09-27 12:51:39 +02:00
Gerhard Sittig 0c52026459 serial: lower severity of failed stream detect message
Reduce the message's log level from ERR to INFO when the serial stream
detect routine cannot find a valid packet. Although an error code gets
returned, the condition need not be fatal (can be the result of trying
several peers before success or finally giving up). Let callers decide
on the severity of failure to detect a specific device's presence, and
provide more context in their message which is more helpful to users.
Interested readers still get the message at slightly raised log levels.

This avoids confusing user perceivable situations like these:

  $ sigrok-cli --scan
  sr: serial: Didn't find a valid packet (read 0 bytes).
  sr: serial: Didn't find a valid packet (read 0 bytes).
  The following devices were found:
  demo - Demo device with 13 channels: D0 D1 D2 D3 D4 D5 D6 D7 A0 A1 A2 A3 A4
2020-09-27 12:33:19 +02:00
Gerhard Sittig 7dd1dd9f7d ols: more robust device reset in acquisition stop
Use the existing ols_send_reset() routine because acquisition
termination can get initiated in several code paths. Make sure the
device will cease activity whatever state it happens to be in. This
amends commit 6d8182b643.
2020-09-27 07:53:09 +02:00
Ben Gardiner 6d8182b643 ols: send CMD_RESET on acquisition stop
Sending CMD_RESET will interrupt armed/untriggered acquisitions which is
very useful in Pulseview sessions since, without this, a next 'run' will
hang.

Signed-off-by: Ben Gardiner <ben.l.gardiner@gmail.com>
2020-09-24 12:54:32 +00:00
Gerhard Sittig 8e79890770 brymen-dmm: unbreak dBm reference impedance interpretation
The reference impedance for dBm measurements comes in an unexpected
format. Isolate the 4..1200 Ohms value, ignore the (inappropriate?)
"0." and exponent parts of the response. Clearly reflect that Ohms
values are seen in different contexts (dBm reference, continuity,
resistance).

Reword comments in the BM850 response parser's code path for dBm
measurements. The reference value is shown when the function is entered
(verified here) or when the reference value changes (haven't seen this
here but a comment in the previous implementation said so).
2020-09-21 21:37:06 +02:00
Gerhard Sittig 3f8453b274 brymen-dmm: unbreak temperature response parsing
The BM850s temperature function response includes the C/F unit in an
unexpected position ("0.0272CE+3") which breaks number conversion. Drop
the C/F unit to unbreak the conversion.

This was observed with BM859s. Absence of the C/F unit in the response
is fatal in this implementation. If other meter firmware versions or
models don't suffer from that issue, the removal must be silent and
non-fatal.
2020-09-21 21:29:43 +02:00
Gerhard Sittig 66b349841a brymen-dmm: rephrase bfunc and value text parsing
When the BM850s response packet's payload gets interpreted, the DLE/STX
transport envelope is not of interest. Rephrase the bitfield inspection
to better reflect that 'bfunc' indicators get accessed (match the vendor's
documentation). Rephrase the calling parse routine to unobfuscate the text
field access. Unclutter assignments for the analog feed. Use a shorter
layout in debug messages, reflect raw input data and conversion results.
2020-09-21 21:29:27 +02:00
Gerhard Sittig 56213aa027 brymen-dmm: improve text to number conversion robustness, signed OL
The BM850(a/s) response packets are a mix of binary and text content.
The text part of it is _not_ a regular ASCIIZ string. Enforce the NUL
termination before running standard C library string routines on it.
Rephrase the conversion routine to become more C idiomatic.

Also check the optional sign for overflow conditions, return either
positive or negative infinity as a result.
2020-09-21 19:57:32 +02:00
Gerhard Sittig 11addc897a brymen-dmm: style nits, apply comm param defaults, low battery warning
Rephrase how the default serial communication parameters get applied.
Preset the variable to the default value and let optional user provided
specs override these. This avoids an extra check which is difficult to
read and highly redundant. Add a comment for raised awareness that a
default port spec is undesirable because it's unreliable.

Raise the severity of low battery messages. It's worth warning the user
because measurements could be inaccurate.

Reduce indentation in continuation lines of a long routine signature,
and drop an empty line in a short struct while we are here.
2020-09-20 10:44:20 +02:00
Gerhard Sittig 648f32d119 brymen-dmm: unbreak BM85x communication by pulsing RTS after COM port open
Either the Brymen meters in the BM850s series or their cables require an
RTS pulse to wakeup, without it there won't be a response during scan or
when requesting measurements. Follow the vendor's documented sequence for
a low RTS pulse after opening the serial port and before communication to
the device.

This fixes bug #1595.

Reported-By: Karl Palsson <karlp@tweak.net.au>
2020-09-20 10:44:20 +02:00
Gerhard Sittig 3ad30b4e19 serial: add routine to manipulate handshake state (RTS, DTR)
Introduce a routine in libsigrok's internal serial layer which lets
applications manipulate the state of handshake signals (RTS and DTR)
after the serial port got opened and configured. This allows for timed
pulses which cannot get expressed with static "rts=1" etc phrases in
parameter strings, and allows handshake signal control while leaving
bitrate and frame format untouched. Applications specify which signals
to modify while other signals remain as they are (ternary input).

Do implement the signal manipulation in the libserialport transport,
do nothing and silently pass in the HID and BT transports. These can
get extended later as the need arises, depending on the HID chips' and
RFCOMM peers' capability to control these signals. This extension is
transparent to application code (acquisition device drivers).
2020-09-20 10:44:20 +02:00
Gerhard Sittig b1184024fe serial: rephrase check for speed (bitrate) in parameter string routine
Use positive logic, put the error path for an unavailable value where
the check for its availability is. Do the regular activity on available
values in the straight code path with lesser indentation. Also group the
bitrate, frame format, and handshake params when breaking text lines.
2020-09-20 10:42:54 +02:00
Gerhard Sittig 400bc4ffab dmm/bm52x: introduce support for Brymen BM525s
Introduce a bm52x DMM packet parser which is modelled after the bm86x
implementation, and hook it up to the serial-dmm driver. This supports
the live readings (real-time download) of the Brymen BM525s logging DMM.
The timing follows the vendor documentation (0.5s between requests, and
4.0s absolute timeout after request transmission). Reading previously
recorded data (memory data sets) unfortunately does not fit well into
the serial-dmm approach, and needs to get addressed differently later.
2020-09-19 12:52:41 +02:00
Gerhard Sittig abcb13855f serial-dmm: only do bytes to text conversion at higher log levels
Check the current log level before starting the potentially expensive
bytes to text conversion for a debug message (dump DMM packets).
2020-09-19 12:32:35 +02:00
Gerhard Sittig ce3fe37969 input/csv: provide double precision values to session feed
Common conversion support code accepts double precision input data for
analog packets. Use the 'double' data type in the CSV input module to
feed sample data to the session bus.
2020-09-18 16:42:37 +02:00
Gerhard Sittig e62b284c1c analog.c: rephrase analog feed to float conversion routine
Rephrase the sr_analog_to_float() routine to further reduce redundancy.

Check early for a match of the input data and result format, to grab the
raw data without conversion in that case. Handle optional scale/offset
calculation in that fast code path, too.

Unify the instructions which convert input data from either integer or
floating point presentations to the result format. Use common stream
readers to retrieve input data in several formats, which eliminates
local conversion buffers. Move common sub-expressions (scale/offset) out
of loops. Run more calculations on double precision data before results
get trimmed to single precision.

Add and extend comments to improve future maintenance. Include (terse)
details of unsupported input data presentations in error messages.

This implementation was neither tuned nor measured for performance.
There still is a lot of redundancy among the branches which handle a
specific input data type. Rephrasing that approach interacts with the
yet to be done performance tuning, thus needs to get addressed later.
The current phrases' verbosity is believed to improve readability.
2020-09-18 16:42:37 +02:00
Gerhard Sittig e4bcc63de6 libsigrok-internal.h: add more endianess aware stream reader routines
Add endianess aware readers including address incrementing variants for
those intrinsic data types which were missing in the previous version
yet are needed for sr_analog_to_float() adjustment.

Also move the 24bit reader to its position in the sort order.
2020-09-18 16:42:37 +02:00
Gerhard Sittig 6205515cc8 tests/analog: add more tests for analog feed to float array conversion
Extend test coverage for the sr_analog_to_float() conversion routine.
Pass data which is encoded in native, little and big endian format to
the routine. Pass single and double precision floating point data, and
integer data in different unit sizes and signedness. Cover scale/offset
calculations as well.

Also cover expected failed conversion for unsupported combinations of
input data format details (half/quad precision float, u64 integer).

Adjust the grouping of test cases in the sequence while we are here.
Move SI prefix, unit, and rational number related tests out of the
analog-to-float conversion group.
2020-09-18 16:42:37 +02:00
Timo Kokkonen f37f11ec6b analog.c: sr_analog_to_float(): Support for receiving double values.
Unbreak the conversion of input data in the floating point format when
the input data's format does not match the host's internal presentation,
thus grabbing raw data cannot be done.

Also accept the input data in double precision format which was not
supported before. Check for unsupported unit size values and emit an
error message similar to the integer code path.

This is motivated by bug #779 but does not resolve it. Adjusts common
conversion support, but sticks with single precision return data type
for API compatibility.
2020-09-18 16:42:37 +02:00
Jiri Slaby 505a55f789 tests: strutil, use ck_assert
We pass no message, so use ck_assert instead of ck_assert_msg. This
results in an error with check 0.15:
tests/strutil.c:157:2: error: too few arguments to function '_ck_assert_failed'
  157 |  ck_assert_msg(saved_locale != NULL);
2020-09-15 08:56:21 +02:00
Gerhard Sittig 5208214739 input/saleae: improve L2D undersampling, do provide sample data
The Saleae Logic exported files (Logic2 digital format) don't contain a
samplerate, so users need to specify the value. For values smaller than
the samplerate that was used during the capture undersampling will take
place. An implementation detail of the input module could result in
incorrect timing of sample values in the session feed. In extreme cases
none of the periods between signal edges qualified for submission. In
that case no sample data was sent to the sigrok session at all.

  $ sigrok-cli -i digital_1.bin -I saleae:samplerate=1000

Keep the very timestamp at hand when the last sample data was submitted.
Only advance that timestamp when more sample data was sent. This avoids
the accumulation of timing errors for undersampling scenarios, and does
forward undersampled input data when the user provided sample period has
passed.

This fixes bug #1600.
2020-09-02 19:52:44 +02:00
Gerhard Sittig 565c8c3545 korad-kaxxxxp: remove obsolete code (clear before read, timeout literal)
The korad response read routine clears the receive buffers, so callers
don't have to. This amends commit d2cc60bd45.

The acquisition timeout is handled by common sw_limits support. Remove
the no longer referenced literal. This amends commit 3f9b48ae5f.
2020-09-01 17:15:54 +02:00
Gerhard Sittig d2cc60bd45 korad-kaxxxxp: speed up scan process, rephrase response read routine
The Korad protocol relies on unterminated request and response strings,
which works well enough for fixed length acquisition and status queries.
But the variable length replies to identification requests suffered from
an implementation detail in the receive routine. A large timeout must be
used because supported devices reportedly are slow to respond. There is
no simple yet robust condition to detect the response's completion. The
scan code must prepare for the maximum response length across the set of
supported devices. Unfortunately the maximum amount of time was spent
waiting for the response to occupy the provided response buffer, before
a long total timeout expired.

Rework the korad driver's helper routine which gets a variable length
non-terminated text string. Keep the long initial timeout, and keep
iterating in that initial phase to quickly detect when response data
became available. But terminate the read sequence after a shorter period
without receive data after some initial receive data was seen. Assume
that identification responses get transferred at wire speed and without
additional delays beyond bitrate expectations. Acquisition and status
responses shall not be affected by this change.

This speeds up the scan for devices from roughly 5s to some 0.1s on
newer devices (KA3005P v5.5) and 0.5s on older devices (KA3005P V2.0).

This commit also addresses an issue in the response text termination,
where partial responses contained undefined data. The previous version's
return value was unspecific: Negative for fatal errors, but either zero
or non-zero for successful reads, with no way for callers to learn about
the received amount of data. The rephrased version always returns the
amount of received data, and adds internal documentation which discusses
the implementation's constraints and the motivation for the approach.

This is a modified version of the initial implementation which was
Submitted-By: Karl Palsson <karlp@tweak.net.au>
2020-09-01 17:11:36 +02:00
Gerhard Sittig fcacf532f5 korad-kaxxxxp: style cleanup in device scan, keep serno at hand
Cleanup style in the korad driver's scan() routine. Keep declarations
out of code blocks. Reduce redundancy and improve robustness in the
response buffer length calculation. Reduce clutter and group related
instructions together. Unobfuscate result checks, and keep the result
at hand (for diagnostics, or error propagation). Unobfuscate string
comparisons in the model ID lookups, terminate the search upon match.
Use a not so terse name for data that gets referenced at rather distant
locations.

Keep the optionally available serial number at hand, to present it to
users when desired. This aspect was
Reported-By: Karl Palsson <karlp@tweak.net.au>
2020-08-28 16:28:47 +02:00
Gerhard Sittig 003ad0ab8c input/saleae: keep previous channels across cleanup() call
The previous implementation of the cleanup() routine in the saleae input
module kept user specified options, but lost the previously created list
of sigrok channels. Keep it.

Also make sure that reset() voids the previous copy after grabbing its
value. To not unexpectedly release resources which still get referenced.

This shall unbreak file-reload.
2020-08-26 17:06:15 +02:00
Gerhard Sittig f403cb9de9 scpi-pps: use remote and local modes for HMP4000
Stop using the unusal "mixed" mode (local interface available during
remote operation) for HMP4000, applications may not be prepared for this
use case. Use traditional "remote" and "local" modes instead. This change
also ends remote mode after the application is done using the device.
2020-08-25 21:06:01 +02:00
Gerhard Sittig 22f76e188b scpi-pps: Add more HMP4000 series devices
List both vendor names "HAMEG" and "ROHDE&SCHWARZ" in the scpi-pps
driver, either responses were seen for HMP4000 devices. Unfortunately
vendor names don't support regex matches, so they require individual
profile items. The items also "violate" the alpha sort order in the list
of profiles, but keeping the series' models together is more important.

Add a declaration for the HMP4030 device which re-uses the HMP4040 data
but open codes the smaller channel count. Ideally the .probe_channels()
routine would receive the scpi_pps item as a parameter, and could yield
model specific result data from common information for the series. The
implementation in this commit is the least intrusive approach until
something better becomes available.

This shall cover the whole HMP4000 series:
  https://www.rohde-schwarz.com/product/hmp4000
2020-08-25 20:59:31 +02:00
Florian Schmidt bd5f0a143e scpi-pps: add support for Hameg / Rohde & Schwarz HMP4040
This commit introduces initial support for the HMP4040 power supply by
Rohde & Schwarz. It allows to configure the device and "statically" read
back current state. Automatic status updates with per-channel details
are not available yet (common support is missing).

[ gsi: drop status update remainder, address minor style nits ]
2020-08-25 20:58:54 +02:00
Gerhard Sittig 24a953382c doc: update README.devices for GWInstek VCP (CP210x in disguise)
Reference the vendor's Windows specific "driver" download for the
CP210x chip with a non-default VID:PID. Provide an example how to
assign the Linux driver to that device (interactive, no udev rule).
2020-08-25 19:38:23 +02:00
Gerhard Sittig f91c6940ab scpi_serial: add "GWInstek VCP" (PID 0x0030) as seen in GDM-834x 2020-08-25 19:38:23 +02:00
Gerhard Sittig 395c1850b7 scpi-dmm: factor out some OL detection limits
Prepare the "plus/minus infinity" checks for OL conditions to use
model dependent limits. This commit does not change behaviour.
2020-08-25 19:38:23 +02:00
Gerhard Sittig 7d95afb9be scpi-dmm: add SR_CONF_CONN getter
Add config_get() support for conn= specs. This is a best-effort approach.
Failure to get the SCPI connection text is non-fatal during probe.
2020-08-25 19:38:23 +02:00
v1ne 6f9234e6f3 ols: Detect Demon Core, use its canonic command names
Document Demon Core commands and associated metadata magic numbers.
See http://web.archive.org/web/20190317154112/
http://mygizmos.org/ols/Logic-Sniffer-FPGA-Spec.pdf for documentation.

Detect the Demon Core presence, use more symbolic names in related
code paths to eliminate magic numbers, switch to their canonic names.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:57:13 +02:00
v1ne 2755ab36f3 ols: Refactor, deduplicate logic packet code
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:57:06 +02:00
v1ne dcdc2848b7 ols: Use symbolic name for "success" error code.
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:43:03 +02:00
v1ne 58a75642e9 ols: Make constant names more precise, clarify comment
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:33:13 +02:00
v1ne a80bed7656 ols: Rename "flags" to "capture flags".
In the current implementation the "flags" are exclusively used for
captures. Prepare the introduction of device flags by renaming the
capture related flags which are specific to an operation.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:29:03 +02:00
v1ne a2b1a53bb4 ols: Symbolic name for magic value, reflect units in variable names
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:26:43 +02:00
v1ne f1a37f3924 ols: Remove stray command
It's nowhere documented and nowhere used.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:26:01 +02:00
v1ne 0ccc6f7cdf ols: Make use of zero-initialization.
No need to assign zero after gmalloc0(). Move comments to declaration.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:24:27 +02:00
Frank Stettner b54d9b4974 libsigrok.h: Fix comment for unit Joule. 2020-08-23 13:10:00 +02:00
Frank Stettner fe8c5aef1f libsigrok.h: Add Joule, Coulomb, and Ah units.
Also extend a comment on energy in comparison to power.
2020-08-22 21:53:56 +02:00
Frank Stettner 82ff704449 libsigrok.h: Add MQ for electric charge. 2020-08-22 21:53:56 +02:00
Frank Stettner f5247d953f teleinfo: Fix measured quantity (energy, not power). 2020-08-22 21:53:39 +02:00
Gerhard Sittig 98b7b08956 output/csv: always generate text for analog/logic data packets
Unconditionally generate output text when a session packet is received
which carries analog or logic sample data. Even if the data gets queued
and is not shown immediately, in that case the output text remains empty
but needs to be present. Otherwise applications may assume that the CSV
output module had not handled the data at all, which would result in
unexpected "screen output" with fallback data being interleaved with the
CSV output.

This resolves bug #1026 in its strictest sense (the unexpected presence
of fallback data). But leaves all other issues mentioned in comment 1.
2020-08-22 19:04:31 +02:00
Gerhard Sittig ce384e074f output/csv: check unsupported/untested input signal conditions
The current implementation of the CSV output module makes assumptions
which don't hold. Which results in incorrect or incomplete output for
some combinations of logic and analog signals.

Check for some of the known problematic conditions, and warn the user
about potentially unexpected results. This is a workaround until the
issues properly get addressed in the implementation.

This is motivated by but does not resolve bug #1026.
2020-08-22 19:00:05 +02:00
Timo Kokkonen 66665b0932 README.devices: Document enabling GW Instek GDM-397 serial output mode. 2020-08-22 09:10:42 +02:00
Timo Kokkonen a3ec8a9aa1 serial-dmm: Add GW Instek GDM-397 meter support.
This meter appears to be rebranded UNI-T UT61B, but with
improved input protection.
2020-08-22 09:10:42 +02:00
Gerhard Sittig e37e301e26 korad-kaxxxxp: add support for forced "detection" of a given model
Korad PSU models are rather popular. But the successful operation of
currently unsupported model names or firmware versions is hard to verify
by users, because building the library from locally modified sources is
involved.

Introduce support for the "force_detect=" scan option. Warning messages
contain how the device identifies itself. Optional user specs can force
the assignment of the driver to the unsupported model. Which results in
reports that include the identification details as well as the successful
use of the device.

  $ sigrok-cli -d korad-kaxxxxp:conn=...:force_detect=KORADKA3005PV2.0 --show
2020-08-22 09:10:29 +02:00
Gerhard Sittig d643e6bc39 hwdriver: introduce SR_CONF_FORCE_DETECT config key (scan option)
Often previously unsupported models might be covered by existing code,
but would not match against a builtin list of known devices.

Introduce a config key which provides a scan option for users to force
the use of a driver with an unsupported device. This increases the
probability of requests for support of an additional model which are
associated with a successful use of that very device, and eliminates
the necessity to build from source for the trivial cases.

It's up to individual drivers whether they support forced detection,
and how they interpret the value of the scan option.
2020-08-22 09:10:29 +02:00