Am 30.11.2015 um 12:32 schrieb Siarhei Siamashka:
Don't we have a redundant code duplication here (copied from the
"multiwrite" command implementation)?
If I understand it correctly, only the progress callback function is
different in all these implementations.
Yup. That's what the new file_upload() function accounted for, so the
various
"write" command cases are now much more streamlined.
Regards, B. Nortmann
--
You received this message because you are subscribed to the Google Groups
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>From a875406070f69c8bf77625fa91c46a166519c4e0 Mon Sep 17 00:00:00 2001
From: Bernhard Nortmann <bernhard.nortm...@web.de>
Date: Thu, 26 Nov 2015 16:46:01 +0100
Subject: [PATCH v6 8/9] fel: support FEL progress gauge via dialog utility
This patch adds some additional commands, and implements corresponding
progress callbacks that produce output for the 'dialog' utility:
http://invisible-island.net/dialog/dialog.html
The simple "*-with-gauge" just emits percentage numbers, line by line,
while "*-with-xgauge" outputs extended information to update the
dialog prompt. Both are meant for directly piping the output:
sunxi-fel write-with-gauge <...> | dialog --gauge "FEL upload" 6 70
Signed-off-by: Bernhard Nortmann <bernhard.nortm...@web.de>
---
fel.c | 21 +++++++++++++++++++++
progress.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
progress.h | 2 ++
3 files changed, 67 insertions(+)
diff --git a/fel.c b/fel.c
index 36fb544..cdb34c7 100644
--- a/fel.c
+++ b/fel.c
@@ -1299,8 +1299,13 @@ int main(int argc, char **argv)
" read address length file Write memory
contents into file\n"
" write address file Store file
contents into memory\n"
" write-with-progress addr file \"write\" with
progress bar\n"
+ " write-with-gauge addr file Output progress
for \"dialog --gauge\"\n"
+ " write-with-xgauge addr file Extended gauge
output (updates prompt)\n"
" multi[write] # addr file ...
\"write-with-progress\" multiple files,\n"
" sharing a
common progress status\n"
+ " multi[write]-with-gauge ... like their
\"write-with-*\" counterpart,\n"
+ " multi[write]-with-xgauge ... but following
the 'multi' syntax:\n"
+ " <#> addr file
[addr file [...]]\n"
" ver[sion] Show BROM
version\n"
" clear address length Clear memory\n"
" fill address length value Fill memory\n"
@@ -1367,11 +1372,27 @@ int main(int argc, char **argv)
} else if (strcmp(argv[1], "write-with-progress") == 0 && argc
> 3) {
skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
progress_bar);
+ } else if (strcmp(argv[1], "write-with-gauge") == 0 && argc >
3) {
+ skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
+ progress_gauge);
+ } else if (strcmp(argv[1], "write-with-xgauge") == 0 && argc >
3) {
+ skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
+ progress_gauge_xxx);
} else if ((strcmp(argv[1], "multiwrite") == 0 ||
strcmp(argv[1], "multi") == 0) && argc > 4) {
size_t count = strtoul(argv[2], NULL, 0); /* file count
*/
skip = 2 + 2 * file_upload(handle, count, argc - 3,
argv + 3, progress_bar);
+ } else if ((strcmp(argv[1], "multiwrite-with-gauge") == 0 ||
+ strcmp(argv[1], "multi-with-gauge") == 0) && argc >
4) {
+ size_t count = strtoul(argv[2], NULL, 0); /* file count
*/
+ skip = 2 + 2 * file_upload(handle, count, argc - 3,
+ argv + 3, progress_gauge);
+ } else if ((strcmp(argv[1], "multiwrite-with-xgauge") == 0 ||
+ strcmp(argv[1], "multi-with-xgauge") == 0) && argc
> 4) {
+ size_t count = strtoul(argv[2], NULL, 0); /* file count
*/
+ skip = 2 + 2 * file_upload(handle, count, argc - 3,
+ argv + 3,
progress_gauge_xxx);
} else if (strcmp(argv[1], "read") == 0 && argc > 4) {
size_t size = strtoul(argv[3], NULL, 0);
void *buf = malloc(size);
diff --git a/progress.c b/progress.c
index 05d8f8b..47ea893 100644
--- a/progress.c
+++ b/progress.c
@@ -119,3 +119,47 @@ void progress_bar(size_t total, size_t done)
fflush(stdout);
}
+
+/*
+ * Progress callback that emits percentage numbers, each on a separate line.
+ * The output is suitable for piping it into "dialog --gauge".
+ *
+ * sunxi-fel multiwrite-with-gauge <...> \
+ * | dialog --title "FEL upload progress" \
+ * --gauge "" 5 70
+ */
+void progress_gauge(size_t total, size_t done)
+{
+ if (total > 0) {
+ printf("%.0f\n", (float)done / total * 100);
+ fflush(stdout);
+ }
+}
+
+/*
+ * A more sophisticated version of progress_gauge() that also updates the
+ * prompt (caption) with additional information. This uses a feature of
+ * the dialog utility that parses "XXX" delimiters - see 'man dialog'.
+ *
+ * sunxi-fel multiwrite-with-xgauge <...> \
+ * | dialog --title "FEL upload progress" \
+ * --backtitle "Please wait..." \
+ * --gauge "" 6 70
+ */
+void progress_gauge_xxx(size_t total, size_t done)
+{
+ if (total > 0) {
+ double speed = rate(done, progress_elapsed());
+ double eta = estimate(total - done, speed);
+ printf("XXX\n");
+ printf("%.0f\n", (float)done / total * 100);
+ if (done < total)
+ printf("%zu of %zu, %.1f kB/s, ETA %s\n",
+ done, total, kilo(speed), format_ETA(eta));
+ else
+ printf("Done: %.1f kB, at %.1f kB/s\n",
+ kilo(done), kilo(speed));
+ printf("XXX\n");
+ fflush(stdout);
+ }
+}
diff --git a/progress.h b/progress.h
index b072cc0..b5c97aa 100644
--- a/progress.h
+++ b/progress.h
@@ -35,5 +35,7 @@ void progress_update(size_t bytes_done);
/* progress callback implementations for various display styles */
void progress_bar(size_t total, size_t done);
+void progress_gauge(size_t total, size_t done);
+void progress_gauge_xxx(size_t total, size_t done);
#endif /* _SUNXI_TOOLS_PROGRESS_H */
--
2.4.6