changeset 94:1f035187e98f

fc-loadtool dump2{bin,srec}: smarter progress indication
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 01 Sep 2013 01:33:28 +0000
parents 45911ad957fd
children 336f5cc96810
files loadtools/ltdump.c
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/ltdump.c	Sat Aug 31 23:43:23 2013 +0000
+++ b/loadtools/ltdump.c	Sun Sep 01 01:33:28 2013 +0000
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <strings.h>
 #include <stdlib.h>
+#include <time.h>
 
 extern uint32_t crc32_table[];
 extern char target_response_line[];
@@ -69,7 +70,9 @@
 static FILE *dump_outfile;
 static int dump_save_srec;
 static uint32_t dump_nextaddr, dump_crcaccum;
+static uint32_t dump_total_len, dump_progress_len;
 static u_char dump_binrec[0x86];
+static time_t dump_last_time;
 
 static
 dump_receiver(line)
@@ -78,6 +81,7 @@
 	int i, b;
 	u_char sr_cksum;
 	uint32_t addr_from_srec;
+	time_t curtime;
 
 	if (strncmp(line, "S385", 4)) {
 		fprintf(stderr,
@@ -121,9 +125,16 @@
 						dump_binrec[i+5]] ^
 				(dump_crcaccum >> 8);
 	/* progress indication */
-	putchar('.');
-	fflush(stdout);
+	dump_progress_len += 0x80;
+	i = dump_progress_len * 100 / dump_total_len;
+	time(&curtime);
+	if (curtime != dump_last_time || i == 100) {
+		printf("\rRx %lu out of %lu bytes (%i%%)",
+			(u_long) dump_progress_len, (u_long) dump_total_len, i);
+		fflush(stdout);
+	}
 	dump_nextaddr += 0x80;
+	dump_last_time = curtime;
 	return(1);
 }
 
@@ -153,6 +164,8 @@
 	dump_save_srec = fmt_srec;
 	dump_nextaddr = start_addr;
 	dump_crcaccum = 0xFFFFFFFF;
+	dump_total_len = area_len;
+	dump_progress_len = 0;
 
 	printf("Requesting memory dump...\n");
 	sprintf(target_arg1, "%lx", start_addr);