Created
April 17, 2015 13:29
-
-
Save pcercuei/65100986e77fc16845b2 to your computer and use it in GitHub Desktop.
untested fix for https://github.com/analogdevicesinc/iio-oscilloscope/issues/15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 53a73c65fca89f8fc830c1e210b2c9bb032fa816 Mon Sep 17 00:00:00 2001 | |
From: Paul Cercueil <paul.cercueil@analog.com> | |
Date: Fri, 17 Apr 2015 15:27:45 +0200 | |
Subject: [PATCH] OSC: Handle lines in INI that start with a "debug" token | |
Signed-off-by: Paul Cercueil <paul.cercueil@analog.com> | |
--- | |
osc.c | 26 ++++++++++++++++++++++---- | |
osc.h | 2 +- | |
2 files changed, 23 insertions(+), 5 deletions(-) | |
diff --git a/osc.c b/osc.c | |
index 1562733..1b1ad27 100644 | |
--- a/osc.c | |
+++ b/osc.c | |
@@ -2117,12 +2117,19 @@ cleanup: | |
int osc_identify_attrib(struct iio_context *ctx, const char *attrib, | |
struct iio_device **dev, struct iio_channel **chn, | |
- const char **attr) | |
+ const char **attr, bool *debug) | |
{ | |
struct iio_device *device; | |
char *dev_name = NULL, *filename = NULL; | |
int ret; | |
+ if (!strncmp(attrib, "debug.", sizeof("debug.") - 1)) { | |
+ *debug = true; | |
+ attrib += sizeof("debug.") - 1; | |
+ } else { | |
+ *debug = false; | |
+ } | |
+ | |
ret = sscanf(attrib, "%m[^.].%m[^.]", &dev_name, &filename); | |
if (ret != 2) { | |
ret = -EINVAL; | |
@@ -2153,12 +2160,15 @@ static int osc_read_nonenclosed_value(struct iio_context *ctx, | |
struct iio_device *dev; | |
struct iio_channel *chn; | |
const char *attr; | |
- int ret = osc_identify_attrib(ctx, value, &dev, &chn, &attr); | |
+ bool debug; | |
+ int ret = osc_identify_attrib(ctx, value, &dev, &chn, &attr, &debug); | |
if (ret < 0) | |
return ret; | |
if (chn) | |
ret = iio_channel_attr_read_longlong(chn, attr, out); | |
+ else if (debug) | |
+ ret = iio_device_debug_attr_read_longlong(dev, attr, out); | |
else | |
ret = iio_device_attr_read_longlong(dev, attr, out); | |
return ret < 0 ? ret : 0; | |
@@ -2242,6 +2252,7 @@ int osc_log_value(struct iio_context *ctx, | |
struct iio_channel *chn; | |
const char *attr; | |
char buf[1024]; | |
+ bool debug; | |
FILE *f; | |
if (strncmp(attribute, "log.", sizeof("log.") - 1)) { | |
@@ -2251,12 +2262,14 @@ int osc_log_value(struct iio_context *ctx, | |
ret = osc_identify_attrib(ctx, | |
attribute + sizeof("log.") - 1, | |
- &dev, &chn, &attr); | |
+ &dev, &chn, &attr, &debug); | |
if (ret < 0) | |
goto err_ret; | |
if (chn) | |
ret = iio_channel_attr_read(chn, attr, buf, sizeof(buf)); | |
+ else if (debug) | |
+ ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf)); | |
else | |
ret = iio_device_attr_read(dev, attr, buf, sizeof(buf)); | |
if (ret < 0) | |
@@ -2285,6 +2298,7 @@ int osc_plugin_default_handle(struct iio_context *ctx, | |
struct iio_device *dev; | |
struct iio_channel *chn; | |
const char *attr; | |
+ bool debug; | |
int ret; | |
if (!strncmp(attrib, "test.", sizeof("test.") - 1)) { | |
@@ -2295,7 +2309,7 @@ int osc_plugin_default_handle(struct iio_context *ctx, | |
if (!strncmp(attrib, "log.", sizeof("log.") - 1)) | |
return osc_log_value(ctx, attrib, value); | |
- ret = osc_identify_attrib(ctx, attrib, &dev, &chn, &attr); | |
+ ret = osc_identify_attrib(ctx, attrib, &dev, &chn, &attr, &debug); | |
if (ret < 0) { | |
if (driver_handle) | |
return driver_handle(attrib, value); | |
@@ -2313,10 +2327,14 @@ int osc_plugin_default_handle(struct iio_context *ctx, | |
if (chn) | |
ret = iio_channel_attr_write_longlong(chn, attr, lval); | |
+ else if (debug) | |
+ ret = iio_device_debug_attr_write_longlong(dev, attr, lval); | |
else | |
ret = iio_device_attr_write_longlong(dev, attr, lval); | |
} else if (chn) | |
ret = iio_channel_attr_write(chn, attr, value); | |
+ else if (debug) | |
+ ret = iio_device_debug_attr_write(dev, attr, value); | |
else | |
ret = iio_device_attr_write(dev, attr, value); | |
if (ret < 0) | |
diff --git a/osc.h b/osc.h | |
index 34e9372..36e22e8 100644 | |
--- a/osc.h | |
+++ b/osc.h | |
@@ -112,7 +112,7 @@ int osc_test_value(struct iio_context *ctx, | |
const char *attribute, const char *value); | |
int osc_identify_attrib(struct iio_context *ctx, const char *attrib, | |
struct iio_device **dev, struct iio_channel **chn, | |
- const char **attr); | |
+ const char **attr, bool *debug); | |
int osc_read_value(struct iio_context *ctx, | |
const char *value, long long *out); | |
int osc_log_value(struct iio_context *ctx, | |
-- | |
2.1.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment