From 933539089899a2f5ba15840d0fd8aedb86bc68b7 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 21 Feb 2025 19:14:49 +0200 Subject: [PATCH 1/3] cdba-server: don't try opening the board if there is none If the cdba failed to find the board, don't call device_fastboot_open(). Signed-off-by: Dmitry Baryshkov --- cdba-server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } From bad935cbf2b0f7d7dd0e025dda98c2f7ed61538b Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 21 Feb 2025 19:17:01 +0200 Subject: [PATCH 2/3] device: support PPPS in parallel with the driver's USB control Don't make PPPS path exclusive to the driver USB control. Allow both to be used at the same time in case the setup uses both PPPS-hubs and driver-specific control. Signed-off-by: Dmitry Baryshkov --- device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From 3c1e7cc886179336f902e1e412a0eba7b877f1be Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 21 Feb 2025 19:19:45 +0200 Subject: [PATCH 3/3] laurent: add separate USB relays support Extend laurent driver, allowing using a relay to control USB circuits. For example, the relay might be connected to the DIP switch on RB1 / RB2 boards. Signed-off-by: Dmitry Baryshkov --- drivers/laurent.c | 30 ++++++++++++++++++++++++++++-- schema.yaml | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) 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