altoslib: Start restructuring AltosState harder
[fw/altos] / altoslib / AltosEepromMini.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 org.altusmetrum.altoslib_1;
19
20 import java.io.*;
21 import java.util.*;
22 import java.text.*;
23
24 public class AltosEepromMini extends AltosEeprom {
25         public static final int record_length = 16;
26
27         public int data8(int i) {
28                 return data8[i];
29         }
30
31         public int data16(int i) {
32                 return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16;
33         }
34
35         public int data24(int i) {
36                 return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16);
37         }
38
39         public int data32(int i) {
40                 return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
41         }
42
43         /* AO_LOG_FLIGHT elements */
44         public int flight() { return data16(0); }
45         public int ground_pres() { return data32(4); }
46
47         /* AO_LOG_STATE elements */
48         public int state() { return data16(0); }
49         public int reason() { return data16(2); }
50
51         /* AO_LOG_SENSOR elements */
52         public int pres() { return data24(0); }
53         public int temp() { return data24(3); }
54         public int sense_a() { return data16(6); }
55         public int sense_m() { return data16(8); }
56         public int v_batt() { return data16(10); }
57
58         public void update_state(AltosState state) {
59                 switch (cmd) {
60                 case AltosLib.AO_LOG_FLIGHT:
61                         break;
62                 case AltosLib.AO_LOG_STATE:
63                         break;
64                 case AltosLib.AO_LOG_SENSOR:
65                         break;
66                 }
67         }
68
69         public AltosEepromMini (AltosEepromChunk chunk, int start) throws ParseException {
70                 parse_chunk(chunk, start, record_length);
71         }
72
73         public AltosEepromMini (String line) {
74                 parse_string(line, record_length);
75         }
76
77         public AltosEepromMini(int in_cmd, int in_tick) {
78                 cmd = in_cmd;
79                 tick = in_tick;
80                 valid = true;
81         }
82
83         static public LinkedList<AltosEeprom> read(FileInputStream input) {
84                 LinkedList<AltosEeprom> minis = new LinkedList<AltosEeprom>();
85
86                 for (;;) {
87                         try {
88                                 String line = AltosLib.gets(input);
89                                 if (line == null)
90                                         break;
91                                 AltosEepromMini mini = new AltosEepromMini(line);
92                                 minis.add(mini);
93                         } catch (IOException ie) {
94                                 break;
95                         }
96                 }
97
98                 return minis;
99         }
100 }