From 0ddb3740ff8760cada6e15f03de911a270eb6711 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 18 Aug 2013 20:19:49 +0200 Subject: [PATCH] factor out leaving the bootloader into own function --- hmcfgusb.c | 16 ++++++++++++++++ hmcfgusb.h | 1 + hmland.c | 11 ++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hmcfgusb.c b/hmcfgusb.c index 8261f13..d77c9d8 100644 --- a/hmcfgusb.c +++ b/hmcfgusb.c @@ -497,6 +497,22 @@ void hmcfgusb_enter_bootloader(struct hmcfgusb_dev *dev) return; } +void hmcfgusb_leave_bootloader(struct hmcfgusb_dev *dev) +{ + uint8_t out[ASYNC_SIZE]; + + if (!dev->bootloader) { + fprintf(stderr, "request for leaving bootloader mode, but device already in normal mode!\n"); + return; + } + + memset(out, 0, sizeof(out)); + out[0] = 'K'; + hmcfgusb_send(dev, out, sizeof(out), 1); + + return; +} + void hmcfgusb_close(struct hmcfgusb_dev *dev) { int err; diff --git a/hmcfgusb.h b/hmcfgusb.h index e438077..8172622 100644 --- a/hmcfgusb.h +++ b/hmcfgusb.h @@ -39,5 +39,6 @@ struct hmcfgusb_dev *hmcfgusb_init(hmcfgusb_cb_fn cb, void *data); int hmcfgusb_add_pfd(struct hmcfgusb_dev *dev, int fd, short events); int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout); void hmcfgusb_enter_bootloader(struct hmcfgusb_dev *dev); +void hmcfgusb_leave_bootloader(struct hmcfgusb_dev *dev); void hmcfgusb_close(struct hmcfgusb_dev *dev); void hmcfgusb_set_debug(int d); diff --git a/hmland.c b/hmland.c index 29ec7a1..d09b10b 100644 --- a/hmland.c +++ b/hmland.c @@ -442,10 +442,11 @@ static int comm(int fd_in, int fd_out, int master_socket, int flags) } if (dev->bootloader) { - fprintf(stderr, "HM-CFG-USB in bootloader mode, restarting in normal mode...\n"); - memset(out, 0, sizeof(out)); - out[0] = 'K'; - hmcfgusb_send(dev, out, sizeof(out), 1); + if (verbose) + fprintf(stderr, "HM-CFG-USB in bootloader mode, restarting in normal mode...\n"); + + hmcfgusb_leave_bootloader(dev); + hmcfgusb_close(dev); sleep(1); return 0; @@ -709,7 +710,7 @@ void hmlan_syntax(char *prog) fprintf(stderr, "\t-i\tinteractive mode (connect HM-CFG-USB to terminal)\n"); fprintf(stderr, "\t-l ip\tlisten on given IP address only (for example 127.0.0.1)\n"); fprintf(stderr, "\t-P\tcreate PID file " PID_FILE " in daemon mode\n"); - fprintf(stderr, "\t-p n\tlisten on port n (default 1000)\n"); + fprintf(stderr, "\t-p n\tlisten on port n (default: 1000)\n"); fprintf(stderr, "\t-r n\treboot HM-CFG-USB after n seconds (0: no reboot, default: %u)\n", DEFAULT_REBOOT_SECONDS); fprintf(stderr, "\t-v\tverbose mode\n"); -- 2.39.5