Skip to contentSkip to conversation

dbus: add -c option to gpiocli-get/set commands

PATCH In review David Lechner 2 participants 5 messages Feb 14 – Feb 16 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dbus: add -c option to gpiocli-get/set commands

Add the -c/--chip option to gpiocli-get/set to allow users to specify a chip and line number instead of a line name. This is useful when a line does not have a name.

---
 dbus/client/get.c | 24 +++++++++++++++++++++---
 dbus/client/set.c | 24 +++++++++++++++++++++---
 2 files changed, 42 insertions(+), 6 deletions(-)
dbus/client/get.c +21 -3
index 4ca6f3c..62825a7 100644
@@ -23,6 +23,7 @@ int gpiocli_get_main(int argc, char **argv)
 	g_autoptr(GpiodbusObject) req_obj = NULL;
 	g_autoptr(GArray) offsets = NULL;
 	g_autoptr(GArray) values = NULL;
+	const gchar *chip_name = NULL;
 	g_autoptr(GError) err = NULL;
 	g_auto(GStrv) lines = NULL;
 	GpiodbusRequest *request;
@@ -34,6 +35,16 @@ int gpiocli_get_main(int argc, char **argv)
 	gint value;
 
 	const GOptionEntry opts[] = {
+		{
+			.long_name		= "chip",
+			.short_name		= 'c',
+			.flags			= G_OPTION_FLAG_NONE,
+			.arg			= G_OPTION_ARG_STRING,
+			.arg_data		= &chip_name,
+			.description		=
+"Explicitly specify the chip_name on which to resolve the lines which allows to use raw offsets instead of line names.",
+			.arg_description	= "<chip name>",
+		},
 		{
 			.long_name		= "request",
 			.short_name		= 'r',
@@ -91,9 +102,16 @@ int gpiocli_get_main(int argc, char **argv)
 			g_autoptr(GVariant) arg_offsets = NULL;
 			g_autoptr(GVariant) arg_values = NULL;
 
-			ret = get_line_obj_by_name(lines[i], &line_obj, NULL);
-			if (!ret)
-				die("Line not found: %s\n", lines[i]);
+			if (chip_name) {
+				chip_obj = get_chip_obj(chip_name);
+				line_obj = get_line_obj_by_name_for_chip(chip_obj, lines[i]);
+				if (!line_obj)
+					die("Line '%s' not found on chip '%s'", lines[i], chip_name);
+			} else {
+				ret = get_line_obj_by_name(lines[i], &line_obj, NULL);
+				if (!ret)
+					die("Line not found: %s\n", lines[i]);
+			}
 
 			line = gpiodbus_object_peek_line(line_obj);
 			req_path = gpiodbus_line_get_request_path(line);
dbus/client/set.c +21 -3
index 6460dd5..44bed94 100644
@@ -26,6 +26,7 @@ int gpiocli_set_main(int argc, char **argv)
 	g_autoptr(GpiodbusObject) req_obj = NULL;
 	g_autoptr(GPtrArray) line_names = NULL;
 	g_autoptr(GArray) values = NULL;
+	const gchar *chip_name = NULL;
 	g_autoptr(GError) err = NULL;
 	g_auto(GStrv) lines = NULL;
 	GpiodbusRequest *request;
@@ -38,6 +39,16 @@ int gpiocli_set_main(int argc, char **argv)
 	gint val;
 
 	const GOptionEntry opts[] = {
+		{
+			.long_name		= "chip",
+			.short_name		= 'c',
+			.flags			= G_OPTION_FLAG_NONE,
+			.arg			= G_OPTION_ARG_STRING,
+			.arg_data		= &chip_name,
+			.description		=
+"Explicitly specify the chip_name on which to resolve the lines which allows to use raw offsets instead of line names.",
+			.arg_description	= "<chip name>",
+		},
 		{
 			.long_name		= "request",
 			.short_name		= 'r',
@@ -133,9 +144,16 @@ int gpiocli_set_main(int argc, char **argv)
 
 		line_name = g_ptr_array_index(line_names, i);
 
-		ret = get_line_obj_by_name(line_name->str, &line_obj, NULL);
-		if (!ret)
-			die("Line not found: %s\n", line_name->str);
+		if (chip_name) {
+			chip_obj = get_chip_obj(chip_name);
+			line_obj = get_line_obj_by_name_for_chip(chip_obj, line_name->str);
+			if (!line_obj)
+				die("Line '%s' not found on chip '%s'", line_name->str, chip_name);
+		} else {
+			ret = get_line_obj_by_name(line_name->str, &line_obj, NULL);
+			if (!ret)
+				die("Line not found: %s\n", line_name->str);
+		}
 
 		line = gpiodbus_object_peek_line(line_obj);
 		req_path = gpiodbus_line_get_request_path(line);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · David Lechner

Add the -c/--chip option to gpiocli-get/set to allow users to specify a chip and line number instead of a line name. This is useful when a line does not have a name.

---

Hi David!

I did not accidentally omit the --chip option in gpiocli get/set/monitor. GetValues/SetValues are methods of the Request interface, not Chip. User can request lines with a chip specified but getting/setting values happens on the object implementing the Request interface. You can check what requests are currently managed with gpiocli requests and use the -r/--request to restrict the scope to a particular one.

In other words, I don't think the client needs this.

Bartosz

#2 lore raw
Quoted 19 lines · Bartosz Golaszewski
Quoted 7 lines · David Lechner

Add the -c/--chip option to gpiocli-get/set to allow users to specify a chip and line number instead of a line name. This is useful when a line does not have a name.

---

Hi David!

I did not accidentally omit the --chip option in gpiocli get/set/monitor. GetValues/SetValues are methods of the Request interface, not Chip. User can request lines with a chip specified but getting/setting values happens on the object implementing the Request interface. You can check what requests are currently managed with gpiocli requests and use the -r/--request to restrict the scope to a particular one.

Quoted 3 lines

In other words, I don't think the client needs this.

Bartosz

OK. It just seems strange that the get/set commands have the offset and name options too if the intention is to only use the request name and not the line name or chip and offset specifiers.

#3 lore raw
Quoted 20 lines · David Lechner
Quoted 19 lines · Bartosz Golaszewski
Quoted 7 lines · David Lechner

Add the -c/--chip option to gpiocli-get/set to allow users to specify a chip and line number instead of a line name. This is useful when a line does not have a name.

---

Hi David!

I did not accidentally omit the --chip option in gpiocli get/set/monitor. GetValues/SetValues are methods of the Request interface, not Chip. User can request lines with a chip specified but getting/setting values happens on the object implementing the Request interface. You can check what requests are currently managed with gpiocli requests and use the -r/--request to restrict the scope to a particular one.

Quoted 7 lines
Quoted 3 lines

In other words, I don't think the client needs this.

Bartosz

OK. It just seems strange that the get/set commands have the offset and name options too if the intention is to only use the request name and not the line name or chip and offset specifiers.

I shouldn't reply to emails first thing in the morning. :-p

Now that my brain is working better, I get it that the offset/name are needed because the request itself can contain multiple lines and this is how the lines are identified in the request.

And if you need lines from two different chips in a single request, then you need to do the gpio-aggregator thing to make them look like they are all on a single chip.

#4 lore raw
Quoted 31 lines · David Lechner
Quoted 20 lines · David Lechner
Quoted 19 lines · Bartosz Golaszewski
Quoted 7 lines · David Lechner

Add the -c/--chip option to gpiocli-get/set to allow users to specify a chip and line number instead of a line name. This is useful when a line does not have a name.

---

Hi David!

I did not accidentally omit the --chip option in gpiocli get/set/monitor. GetValues/SetValues are methods of the Request interface, not Chip. User can request lines with a chip specified but getting/setting values happens on the object implementing the Request interface. You can check what requests are currently managed with gpiocli requests and use the -r/--request to restrict the scope to a particular one.

Quoted 7 lines
Quoted 3 lines

In other words, I don't think the client needs this.

Bartosz

OK. It just seems strange that the get/set commands have the offset and name options too if the intention is to only use the request name and not the line name or chip and offset specifiers.

I shouldn't reply to emails first thing in the morning. :-p

Quoted 8 lines

Now that my brain is working better, I get it that the offset/name are needed because the request itself can contain multiple lines and this is how the lines are identified in the request.

And if you need lines from two different chips in a single request, then you need to do the gpio-aggregator thing to make them look like they are all on a single chip.

Yes, just as if you were using the library's C API.

Bart