diff miscprog/pirbattextr.c @ 226:30804198d5d0

Pirelli's a_pwr_thresholds[] table found
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 29 Nov 2017 22:51:50 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscprog/pirbattextr.c	Wed Nov 29 22:51:50 2017 +0000
@@ -0,0 +1,56 @@
+/*
+ * This program extracts the a_pwr_thresholds[] table from one of Pirelli's
+ * fw images and converts the numbers to decimal.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+struct entry {
+	u_char	mvolt[2];
+	u_char	percent;
+	u_char	pad;
+};
+
+struct entry array[21];
+
+read_array_from_image(filename, offset_arg)
+	char *filename, *offset_arg;
+{
+	int fd;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		perror(filename);
+		exit(1);
+	}
+	lseek(fd, strtoul(offset_arg, 0, 0), 0);
+	read(fd, array, sizeof array);
+	close(fd);
+}
+
+dump_array()
+{
+	int i;
+	unsigned mvolt;
+
+	for (i = 0; i < 21; i++) {
+		mvolt = array[i].mvolt[0] | (array[i].mvolt[1] << 8);
+		printf("%4u\t%u\n", mvolt, array[i].percent);
+	}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s fw-image offset\n", argv[0]);
+		exit(1);
+	}
+	read_array_from_image(argv[1], argv[2]);
+	dump_array();
+	exit(0);
+}