diff --git a/cdba-server.c b/cdba-server.c index c463f19..992730e 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -59,10 +59,10 @@ static void msg_select_board(const void *param) if (!selected_device) { fprintf(stderr, "failed to open %s\n", (const char *)param); watch_quit(); + } else { + device_fastboot_open(selected_device, &fastboot_ops); } - device_fastboot_open(selected_device, &fastboot_ops); - cdba_send(MSG_SELECT_BOARD); } diff --git a/device.c b/device.c index 79856bb..6d15ad5 100644 --- a/device.c +++ b/device.c @@ -285,7 +285,7 @@ void device_usb(struct device *device, bool on) { if (device->ppps_path) ppps_power(device, on); - else if (device_has_control(device, usb)) + if (device_has_control(device, usb)) device_control(device, usb, on); } diff --git a/drivers/laurent.c b/drivers/laurent.c index d096a3a..56be4d5 100644 --- a/drivers/laurent.c +++ b/drivers/laurent.c @@ -23,6 +23,7 @@ struct laurent_options { const char *server; const char *password; unsigned int relay; + int usb_relay; }; struct laurent { @@ -42,6 +43,7 @@ void *laurent_parse_options(struct device_parser *dp) options = calloc(1, sizeof(*options)); options->password = DEFAULT_PASSWORD; + options->usb_relay = -1; device_parser_accept(dp, YAML_MAPPING_START_EVENT, NULL, 0); while (device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH)) { @@ -54,6 +56,8 @@ void *laurent_parse_options(struct device_parser *dp) options->password = strdup(value); else if (!strcmp(key, "relay")) options->relay = strtoul(value, NULL, 0); + else if (!strcmp(key, "usb_relay")) + options->usb_relay = strtoul(value, NULL, 0); else errx(1, "%s: unknown option \"%s\"", __func__, key); } @@ -124,7 +128,7 @@ static void *laurent_open(struct device *dev) return laurent; } -static int laurent_power(struct device *dev, bool on) +static int laurent_control(struct device *dev, unsigned int relay, bool on) { struct laurent *laurent = dev->cdb; char buf[BUFSIZ]; @@ -145,7 +149,7 @@ static int laurent_power(struct device *dev, bool on) len = snprintf(buf, sizeof(buf), "GET /cmd.cgi?psw=%s&cmd=REL,%u,%d HTTP/1.0\r\n\r\n", laurent->options->password, - laurent->options->relay, + relay, on); if (len < 0) { warn("asprintf failed\n"); @@ -190,8 +194,30 @@ static int laurent_power(struct device *dev, bool on) return -1; } +static int laurent_power(struct device *dev, bool on) +{ + struct laurent *laurent = dev->cdb; + + return laurent_control(dev, + laurent->options->relay, + on); +} + +static void laurent_usb(struct device *dev, bool on) +{ + struct laurent *laurent = dev->cdb; + + if (laurent->options->usb_relay < 0) + return; + + laurent_control(dev, + laurent->options->usb_relay, + on); +} + const struct control_ops laurent_ops = { .parse_options = laurent_parse_options, .open = laurent_open, .power = laurent_power, + .usb = laurent_usb, }; diff --git a/schema.yaml b/schema.yaml index 6ff209a..19a8bcc 100644 --- a/schema.yaml +++ b/schema.yaml @@ -152,6 +152,8 @@ properties: type: string relay: type: integer + usb_relay: + type: integer password: description: password to access the relays, defaults to 'Laurent' type: string