comparison 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
comparison
equal deleted inserted replaced
225:81ab8dec2259 226:30804198d5d0
1 /*
2 * This program extracts the a_pwr_thresholds[] table from one of Pirelli's
3 * fw images and converts the numbers to decimal.
4 */
5
6 #include <sys/types.h>
7 #include <sys/file.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 struct entry {
13 u_char mvolt[2];
14 u_char percent;
15 u_char pad;
16 };
17
18 struct entry array[21];
19
20 read_array_from_image(filename, offset_arg)
21 char *filename, *offset_arg;
22 {
23 int fd;
24
25 fd = open(filename, O_RDONLY);
26 if (fd < 0) {
27 perror(filename);
28 exit(1);
29 }
30 lseek(fd, strtoul(offset_arg, 0, 0), 0);
31 read(fd, array, sizeof array);
32 close(fd);
33 }
34
35 dump_array()
36 {
37 int i;
38 unsigned mvolt;
39
40 for (i = 0; i < 21; i++) {
41 mvolt = array[i].mvolt[0] | (array[i].mvolt[1] << 8);
42 printf("%4u\t%u\n", mvolt, array[i].percent);
43 }
44 }
45
46 main(argc, argv)
47 char **argv;
48 {
49 if (argc != 3) {
50 fprintf(stderr, "usage: %s fw-image offset\n", argv[0]);
51 exit(1);
52 }
53 read_array_from_image(argv[1], argv[2]);
54 dump_array();
55 exit(0);
56 }