Hello everyone again! I figured out the problem with "invalid unit
size" when saving capture from OLS driver; and here is the fix. Hope
you'll like it.
Kind regards.
From 3b9f7f55e0113c35764aafda566e9eeafd664cbe Mon Sep 17 00:00:00 2001
From: Pavel Fedin <pavel_fe...@mail.ru>
Date: Sat, 28 Oct 2023 00:32:36 +0300
Subject: [PATCH] hardware/openbench-logic-sniffer: Un-hardcode unitsize
srzip output module, when initializing the zip stream, calculates unitsize
by itself from the number of available channels, taking one channel == one bit.
If a datastream with larger unitsize is fed, it aborts with "Unexpected unit
size". As a result, it's impossible to save a capture, done with this driver.
Fix the problem by setting unitsize to num_changroups, which is exactly number
of bytes in the stream, sent by the device. Do not expand to hardcoded 4.
Signed-off-by: Pavel Fedin <pavel_fe...@mail.ru>
---
.../openbench-logic-sniffer/protocol.c | 65 +++++++------------
src/output/srzip.c | 2 +-
2 files changed, 23 insertions(+), 44 deletions(-)
diff --git a/src/hardware/openbench-logic-sniffer/protocol.c
b/src/hardware/openbench-logic-sniffer/protocol.c
index 528b05c..689ae20 100644
--- a/src/hardware/openbench-logic-sniffer/protocol.c
+++ b/src/hardware/openbench-logic-sniffer/protocol.c
@@ -391,6 +391,8 @@ SR_PRIV int ols_receive_data(int fd, int revents, void
*cb_data)
}
}
+ sr_dbg("Receiving %d channel groups.", num_changroups);
+
if (revents == G_IO_IN && devc->num_samples < devc->limit_samples) {
if (serial_read_nonblocking(serial, &byte, 1) != 1)
return FALSE;
@@ -409,9 +411,16 @@ SR_PRIV int ols_receive_data(int fd, int revents, void
*cb_data)
* Got a full sample. Convert from the OLS's
little-endian
* sample to the local format.
*/
- sample = devc->sample[0] | (devc->sample[1] << 8) |
- (devc->sample[2] << 16) |
- (devc->sample[3] << 24);
+ sample = devc->sample[0];
+ if (num_changroups > 1) {
+ sample |= (devc->sample[1] << 8);
+ }
+ if (num_changroups > 2) {
+ sample |= (devc->sample[2] << 16);
+ }
+ if (num_changroups > 3) {
+ sample |= (devc->sample[3] << 24);
+ }
sr_dbg("Received sample 0x%.*x.", devc->num_bytes * 2,
sample);
if (devc->capture_flags & CAPTURE_FLAG_RLE) {
@@ -441,47 +450,17 @@ SR_PRIV int ols_receive_data(int fd, int revents, void
*cb_data)
devc->num_samples = devc->limit_samples;
}
- if (num_changroups < 4) {
- /*
- * Some channel groups may have been turned
- * off, to speed up transfer between the
- * hardware and the PC. Expand that here before
- * submitting it over the session bus --
- * whatever is listening on the bus will be
- * expecting a full 32-bit sample, based on
- * the number of channels.
- */
- j = 0;
- uint8_t tmp_sample[4] = { 0, 0, 0, 0 };
- for (i = 0; i < 4; i++) {
- if (((devc->capture_flags >> 2) &
- (1 << i)) == 0) {
- /*
- * This channel group was
- * enabled, copy from received
- * sample.
- */
- tmp_sample[i] =
- devc->sample[j++];
- }
- }
- memcpy(devc->sample, tmp_sample, 4);
- sr_spew("Expanded sample:
0x%.2hhx%.2hhx%.2hhx%.2hhx ",
- devc->sample[3], devc->sample[2],
- devc->sample[1], devc->sample[0]);
- }
-
/*
* the OLS sends its sample buffer backwards.
* store it in reverse order here, so we can dump
* this on the session bus later.
*/
- offset = (devc->limit_samples - devc->num_samples) * 4;
+ offset = (devc->limit_samples - devc->num_samples) *
num_changroups;
for (i = 0; i <= devc->rle_count; i++) {
- memcpy(devc->raw_sample_buf + offset + (i * 4),
- devc->sample, 4);
+ memcpy(devc->raw_sample_buf + offset + (i *
num_changroups),
+ devc->sample, num_changroups);
}
- memset(devc->sample, 0, 4);
+ memset(devc->sample, 0, num_changroups);
devc->num_bytes = 0;
devc->rle_count = 0;
}
@@ -503,12 +482,12 @@ SR_PRIV int ols_receive_data(int fd, int revents, void
*cb_data)
/* There are pre-trigger samples, send those
first. */
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
- logic.length = devc->trigger_at_smpl * 4;
- logic.unitsize = 4;
+ logic.length = devc->trigger_at_smpl *
num_changroups;
+ logic.unitsize = num_changroups;
logic.data = devc->raw_sample_buf +
(devc->limit_samples -
devc->num_samples) *
- 4;
+ num_changroups;
sr_session_send(sdi, &packet);
}
@@ -524,12 +503,12 @@ SR_PRIV int ols_receive_data(int fd, int revents, void
*cb_data)
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
logic.length =
- (devc->num_samples - num_pre_trigger_samples) * 4;
- logic.unitsize = 4;
+ (devc->num_samples - num_pre_trigger_samples) *
num_changroups;
+ logic.unitsize = num_changroups;
logic.data = devc->raw_sample_buf +
(num_pre_trigger_samples + devc->limit_samples -
devc->num_samples) *
- 4;
+ num_changroups;
sr_session_send(sdi, &packet);
g_free(devc->raw_sample_buf);
diff --git a/src/output/srzip.c b/src/output/srzip.c
index e3b57e3..02dc74e 100644
--- a/src/output/srzip.c
+++ b/src/output/srzip.c
@@ -408,7 +408,7 @@ static int zip_append_queue(const struct sr_output *o,
outc = o->priv;
buff = &outc->logic_buff;
if (length && unitsize != buff->unit_size) {
- sr_warn("Unexpected unit size, discarding logic data.");
+ sr_warn("Unexpected unit size %zu vs %zu, discarding logic
data.", unitsize, buff->unit_size);
return SR_ERR_ARG;
}
--
2.42.0.windows.2
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel