update changelogs for Debian build
[fw/altos] / altosui / AltosEepromLog.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
30
31 import libaltosJNI.*;
32
33 /*
34  * Extract a bit of information from an eeprom-stored flight log.
35  */
36
37 public class AltosEepromLog {
38         int             serial;
39         boolean         has_flight;
40         int             flight;
41         int             start_block;
42         int             end_block;
43
44         boolean         has_gps;
45         int             year, month, day;
46         int             hour, minute, second;
47         double          lat, lon;
48
49         boolean         download;
50         boolean         delete;
51
52         public AltosEepromLog(AltosSerial serial_line, int in_serial,
53                               int in_start_block, int in_end_block)
54                 throws InterruptedException, TimeoutException {
55
56                 int             block;
57                 boolean         has_date = false, has_time = false, has_lat = false, has_lon = false;
58
59                 start_block = in_start_block;
60                 end_block = in_end_block;
61                 serial = in_serial;
62
63                 /*
64                  * By default, request that every log be downloaded but not deleted
65                  */
66                 download = true;
67                 delete = false;
68                 /*
69                  * Only look in the first two blocks so that this
70                  * process doesn't take a long time
71                  */
72                 if (in_end_block > in_start_block + 2)
73                         in_end_block = in_start_block + 2;
74
75                 for (block = in_start_block; block < in_end_block; block++) {
76                         AltosEepromBlock eeblock = new AltosEepromBlock(serial_line, block);
77                         if (eeblock.has_flight) {
78                                 flight = eeblock.flight;
79                                 has_flight = true;
80                         }
81                         if (eeblock.has_date) {
82                                 year = eeblock.year;
83                                 month = eeblock.month;
84                                 day = eeblock.day;
85                                 has_date = true;
86                         }
87                         if (eeblock.has_time) {
88                                 hour = eeblock.hour;
89                                 minute = eeblock.minute;
90                                 second = eeblock.second;
91                                 has_time = true;
92                         }
93                         if (eeblock.has_lat) {
94                                 lat = eeblock.lat;
95                                 has_lat = true;
96                         }
97                         if (eeblock.has_lon) {
98                                 lon = eeblock.lon;
99                                 has_lon = true;
100                         }
101                         if (has_date && has_time && has_lat && has_lon)
102                                 has_gps = true;
103                         if (has_gps && has_flight)
104                                 break;
105                 }
106                 System.out.printf("Serial %d start block %d end block %d\n",
107                                   serial, start_block, end_block);
108                 if (has_flight)
109                         System.out.printf("Flight %d\n", flight);
110                 if (has_gps)
111                         System.out.printf("%d-%d-%d %d:%02d:%02d Lat %f Lon %f\n",
112                                           year, month, day, hour, minute, second, lat, lon);
113         }
114 }