aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:02:14 (GMT)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:02:14 (GMT)
commit48d28562ffcd9f63276a636d64e90ca875e3a98e (patch)
tree673e7b6f7b69793e7a1f15a0b13238c39fbbfd21
parent4ee4b43b657f6ba951fb68d44ce5488f6f4d7fff (diff)
cec-ctl: add -D and -a support
With these options you can uniquely identify a CEC device without having to know the device node name. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/cec-ctl/cec-ctl.1.in10
-rw-r--r--utils/cec-ctl/cec-ctl.cpp37
2 files changed, 41 insertions, 6 deletions
diff --git a/utils/cec-ctl/cec-ctl.1.in b/utils/cec-ctl/cec-ctl.1.in
index bd43ce6..38b49a5 100644
--- a/utils/cec-ctl/cec-ctl.1.in
+++ b/utils/cec-ctl/cec-ctl.1.in
@@ -34,6 +34,16 @@ And instead of '--to 0' you can also write this as '-t0'.
\fB\-d\fR, \fB\-\-device\fR \fI<dev>\fR
Use device <dev> as the CEC device. If <dev> is a number, then /dev/cec<dev> is used.
.TP
+\fB\-D\fR, \fB\-\-driver\fR \fI<drv>\fR
+Use a cec device that has driver name \fI<drv>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-a\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
+\fB\-a\fR, \fB\-\-adapter\fR \fI<adap-name>\fR
+Use a cec device that has adapter name \fI<adap-name>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-D\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
Turn on verbose reporting.
.TP
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index bca1cc4..130c1fe 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -566,8 +566,10 @@ static void log_u8_array(const char *arg_name, unsigned num, const __u8 *vals)
In general the lower case is used to set something and the upper
case is used to retrieve a setting. */
enum Option {
+ OptSetAdapter = 'a',
OptClear = 'C',
OptSetDevice = 'd',
+ OptSetDriver = 'D',
OptFrom = 'f',
OptHelp = 'h',
OptLogicalAddress = 'l',
@@ -658,6 +660,8 @@ static void init_messages()
static struct option long_options[] = {
{ "device", required_argument, 0, OptSetDevice },
+ { "adapter", required_argument, 0, OptSetAdapter },
+ { "driver", required_argument, 0, OptSetDriver },
{ "help", no_argument, 0, OptHelp },
{ "trace", no_argument, 0, OptTrace },
{ "verbose", no_argument, 0, OptVerbose },
@@ -732,6 +736,8 @@ static void usage(void)
printf("Usage:\n"
" -d, --device <dev> Use device <dev> instead of /dev/cec0\n"
" If <dev> starts with a digit, then /dev/cec<dev> is used.\n"
+ " -D, --driver <driver> Use a cec device with this driver name\n"
+ " -a, --adapter <adapter> Use a cec device with this adapter name\n"
" -p, --phys-addr <addr> Use this physical address\n"
" -o, --osd-name <name> Use this OSD name\n"
" -V, --vendor-id <id> Use this vendor ID\n"
@@ -1688,7 +1694,9 @@ static void list_devices()
int main(int argc, char **argv)
{
- const char *device = "/dev/cec0"; /* -d device */
+ std::string device;
+ const char *driver = NULL;
+ const char *adapter = NULL;
const message *opt;
msg_vec msgs;
char short_options[26 * 2 * 2 + 1];
@@ -1740,13 +1748,19 @@ int main(int argc, char **argv)
return 0;
case OptSetDevice:
device = optarg;
- if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) {
+ if (device[0] >= '0' && device[0] <= '9' && device.length() <= 3) {
static char newdev[20];
- sprintf(newdev, "/dev/cec%s", device);
+ sprintf(newdev, "/dev/cec%s", optarg);
device = newdev;
}
break;
+ case OptSetDriver:
+ driver = optarg;
+ break;
+ case OptSetAdapter:
+ adapter = optarg;
+ break;
case OptVerbose:
verbose = true;
break;
@@ -2137,11 +2151,22 @@ int main(int argc, char **argv)
return 1;
}
+ if (device.empty() && (driver || adapter)) {
+ device = cec_device_find(driver, adapter);
+ if (device.empty()) {
+ fprintf(stderr,
+ "Could not find a CEC device for the given driver/adapter combination\n");
+ exit(1);
+ }
+ }
+ if (device.empty())
+ device = "/dev/cec0";
+
clock_gettime(CLOCK_MONOTONIC, &start_monotonic);
gettimeofday(&start_timeofday, NULL);
- if ((fd = open(device, O_RDWR)) < 0) {
- fprintf(stderr, "Failed to open %s: %s\n", device,
+ if ((fd = open(device.c_str(), O_RDWR)) < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n", device.c_str(),
strerror(errno));
exit(1);
}
@@ -2150,7 +2175,7 @@ int main(int argc, char **argv)
struct cec_caps caps = { };
node.fd = fd;
- node.device = device;
+ node.device = device.c_str();
doioctl(&node, CEC_ADAP_G_CAPS, &caps);
node.caps = caps.capabilities;
node.available_log_addrs = caps.available_log_addrs;

Privacy Policy