altosui: Add support for parsing list of flights from the 'l' command
[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 public class AltosEepromLog {
34         int             serial;
35         boolean         has_flight;
36         int             flight;
37         int             start_block;
38         int             end_block;
39
40         boolean         has_gps;
41         int             year, month, day;
42         int             hour, minute, second;
43         double          lat, lon;
44
45         public AltosEepromLog(AltosSerial serial_line, int in_serial,
46                               int in_start_block, int in_end_block)
47                 throws InterruptedException, TimeoutException {
48
49                 int             block;
50                 boolean         has_date = false, has_time = false, has_lat = false, has_lon = false;
51
52                 start_block = in_start_block;
53                 end_block = in_end_block;
54                 serial = in_serial;
55
56                 if (in_end_block > in_start_block + 2)
57                         in_end_block = in_start_block + 2;
58
59                 for (block = in_start_block; block < in_end_block; block++) {
60                         AltosEepromBlock eeblock = new AltosEepromBlock(serial_line, block);
61                         if (eeblock.has_flight) {
62                                 flight = eeblock.flight;
63                                 has_flight = true;
64                         }
65                         if (eeblock.has_date) {
66                                 year = eeblock.year;
67                                 month = eeblock.month;
68                                 day = eeblock.day;
69                                 has_date = true;
70                         }
71                         if (eeblock.has_time) {
72                                 hour = eeblock.hour;
73                                 minute = eeblock.minute;
74                                 second = eeblock.second;
75                                 has_time = true;
76                         }
77                         if (eeblock.has_lat) {
78                                 lat = eeblock.lat;
79                                 has_lat = true;
80                         }
81                         if (eeblock.has_lon) {
82                                 lon = eeblock.lon;
83                                 has_lon = true;
84                         }
85                         if (has_date && has_time && has_lat && has_lon)
86                                 has_gps = true;
87                         if (has_gps && has_flight)
88                                 break;
89                 }
90                 System.out.printf("Serial %d start block %d end block %d\n",
91                                   serial, start_block, end_block);
92                 if (has_flight)
93                         System.out.printf("Flight %d\n", flight);
94                 if (has_gps)
95                         System.out.printf("%d-%d-%d %d:%02d:%02d Lat %f Lon %f\n",
96                                           year, month, day, hour, minute, second, lat, lon);
97         }
98 }