From 20103f572fcf1451b6625209f02b7fde70dd3f04 Mon Sep 17 00:00:00 2001 From: Jean Cyr Date: Sun, 7 Jul 2013 20:19:27 -0400 Subject: Minor px4io optimization Since this module creates the PX4IO object and that the IOCTL function doesn't use the file descriptor parameter, there is no need to invoke IOCTL via the filesystem since we can call it directly. --- src/drivers/px4io/px4io.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp index ad0112b9b..1adefdea5 100644 --- a/src/drivers/px4io/px4io.cpp +++ b/src/drivers/px4io/px4io.cpp @@ -1388,7 +1388,8 @@ PX4IO::print_status() } int -PX4IO::ioctl(file *filep, int cmd, unsigned long arg) +PX4IO::ioctl(file * /*filep*/, int cmd, unsigned long arg) +/* Make it obvious that file * isn't used here */ { int ret = OK; @@ -1668,11 +1669,7 @@ start(int argc, char *argv[]) if (param_get(param_find("RC_RL1_DSM_VCC"), &dsm_vcc_ctl) == OK) { if (dsm_vcc_ctl) { g_dev->set_dsm_vcc_ctl(true); - int fd = open(GPIO_DEVICE_PATH, O_WRONLY); - if (fd < 0) - errx(1, "failed to open device"); - ioctl(fd, DSM_BIND_POWER_UP, 0); - close(fd); + g_dev->ioctl(nullptr, DSM_BIND_POWER_UP, 0); } } exit(0); @@ -1681,7 +1678,7 @@ start(int argc, char *argv[]) void bind(int argc, char *argv[]) { - int fd, pulses; + int pulses; if (g_dev == nullptr) errx(1, "px4io must be started first"); @@ -1699,12 +1696,7 @@ bind(int argc, char *argv[]) else errx(1, "unknown parameter %s, use dsm2 or dsmx", argv[2]); - fd = open(GPIO_DEVICE_PATH, O_WRONLY); - - if (fd < 0) - errx(1, "failed to open device"); - - ioctl(fd, DSM_BIND_START, pulses); + g_dev->ioctl(nullptr, DSM_BIND_START, pulses); /* Open console directly to grab CTRL-C signal */ int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY); @@ -1721,9 +1713,8 @@ bind(int argc, char *argv[]) if (read(console, &c, 1) == 1) { if (c == 0x03 || c == 0x63) { warnx("Done\n"); - ioctl(fd, DSM_BIND_STOP, 0); - ioctl(fd, DSM_BIND_POWER_UP, 0); - close(fd); + g_dev->ioctl(nullptr, DSM_BIND_STOP, 0); + g_dev->ioctl(nullptr, DSM_BIND_POWER_UP, 0); close(console); exit(0); } @@ -1914,7 +1905,7 @@ px4io_main(int argc, char *argv[]) * We can cheat and call the driver directly, as it * doesn't reference filp in ioctl() */ - g_dev->ioctl(NULL, PX4IO_INAIR_RESTART_ENABLE, 1); + g_dev->ioctl(nullptr, PX4IO_INAIR_RESTART_ENABLE, 1); } else { errx(1, "not loaded"); } @@ -1958,7 +1949,7 @@ px4io_main(int argc, char *argv[]) /* we can cheat and call the driver directly, as it * doesn't reference filp in ioctl() */ - int ret = g_dev->ioctl(NULL, PX4IO_SET_DEBUG, level); + int ret = g_dev->ioctl(nullptr, PX4IO_SET_DEBUG, level); if (ret != 0) { printf("SET_DEBUG failed - %d\n", ret); exit(1); -- cgit v1.2.3