changeset 71:0c1480317c18

dieid via fc-loadtool: added ability to save to a file
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 26 Jul 2013 18:11:41 +0000
parents e2698daf40d1
children 92c1ed6b4b67
files loadtools/ltdispatch.c loadtools/ltmisc.c
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/ltdispatch.c	Fri Jul 26 17:51:49 2013 +0000
+++ b/loadtools/ltdispatch.c	Fri Jul 26 18:11:41 2013 +0000
@@ -26,7 +26,7 @@
 } cmdtab[] = {
 	{"baud", 0, 1, cmd_baud},
 	{"crc32", 2, 2, cmd_crc32},
-	{"dieid", 0, 0, cmd_dieid},
+	{"dieid", 0, 1, cmd_dieid},
 	{"dump", 2, 2, loadtool_cmd_passthru},
 	{"dump2bin", 3, 3, cmd_dump2bin},
 	{"dump2srec", 3, 3, cmd_dump2srec},
--- a/loadtools/ltmisc.c	Fri Jul 26 17:51:49 2013 +0000
+++ b/loadtools/ltmisc.c	Fri Jul 26 18:11:41 2013 +0000
@@ -7,17 +7,31 @@
 #include <stdio.h>
 #include <stdint.h>
 
-cmd_dieid()
+cmd_dieid(argc, argv)
+	char **argv;
 {
-	uint32_t addr;
-	uint16_t data;
-	int stat;
+	static uint32_t addrs[4] = {0xFFFEF010, 0xFFFEF012, 0xFFFEF014,
+				    0xFFFEF016};
+	uint16_t data[4];
+	int i, stat;
+	FILE *of;
 
-	for (addr = 0xFFFEF010; addr <= 0xFFFEF016; addr += 2) {
-		stat = do_r16(addr, &data);
+	for (i = 0; i < 4; i++) {
+		stat = do_r16(addrs[i], data + i);
 		if (stat)
 			return(stat);
-		printf("%08lX: %04X\n", (u_long)addr, (int)data);
+		printf("%08lX: %04X\n", (u_long)addrs[i], (int)data[i]);
 	}
+	if (argc < 2)
+		return(0);
+	of = fopen(argv[1], "w");
+	if (!of) {
+		perror(argv[1]);
+		return(-1);
+	}
+	for (i = 0; i < 4; i++)
+		fprintf(of, "%08lX: %04X\n", (u_long)addrs[i], (int)data[i]);
+	fclose(of);
+	printf("Saved to %s\n", argv[1]);
 	return(0);
 }