Change AltosLib to altoslib
[fw/altos] / altoslib / AltosSensorMM.java
1 /*
2  * Copyright © 2012 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;
19
20 import java.util.concurrent.TimeoutException;
21
22 class AltosSensorMM {
23         int             tick;
24         int             sense[];
25         int             v_batt;
26         int             v_pyro;
27         int             accel;
28         int             accel_ref;
29
30         public AltosSensorMM(AltosLink link) throws InterruptedException, TimeoutException {
31                 link.printf("a\n");
32                 for (;;) {
33                         String line = link.get_reply_no_dialog(5000);
34                         if (line == null) {
35                                 throw new TimeoutException();
36                         }
37                         if (!line.startsWith("tick:"))
38                                 continue;
39                         String[] items = line.split("\\s+");
40                         sense = new int[6];
41                         for (int i = 0; i < items.length;) {
42                                 if (items[i].equals("tick:")) {
43                                         tick = Integer.parseInt(items[i+1]);
44                                         i += 2;
45                                         continue;
46                                 }
47                                 if (items[i].equals("0:")) {
48                                         sense[0] = Integer.parseInt(items[i+1]);
49                                         i += 2;
50                                         continue;
51                                 }
52                                 if (items[i].equals("1:")) {
53                                         sense[1] = Integer.parseInt(items[i+1]);
54                                         i += 2;
55                                         continue;
56                                 }
57                                 if (items[i].equals("2:")) {
58                                         sense[2] = Integer.parseInt(items[i+1]);
59                                         i += 2;
60                                         continue;
61                                 }
62                                 if (items[i].equals("3:")) {
63                                         sense[3] = Integer.parseInt(items[i+1]);
64                                         i += 2;
65                                         continue;
66                                 }
67                                 if (items[i].equals("4:")) {
68                                         sense[4] = Integer.parseInt(items[i+1]);
69                                         i += 2;
70                                         continue;
71                                 }
72                                 if (items[i].equals("5:")) {
73                                         sense[5] = Integer.parseInt(items[i+1]);
74                                         i += 2;
75                                         continue;
76                                 }
77                                 if (items[i].equals("6:")) {
78                                         v_batt = Integer.parseInt(items[i+1]);
79                                         i += 2;
80                                         continue;
81                                 }
82                                 if (items[i].equals("7:")) {
83                                         v_pyro = Integer.parseInt(items[i+1]);
84                                         i += 2;
85                                         continue;
86                                 }
87                                 if (items[i].equals("8:")) {
88                                         accel = Integer.parseInt(items[i+1]);
89                                         i += 2;
90                                         continue;
91                                 }
92                                 if (items[i].equals("9:")) {
93                                         accel_ref = Integer.parseInt(items[i+1]);
94                                         i += 2;
95                                         continue;
96                                 }
97                                 i++;
98                         }
99                         break;
100                 }
101         }
102 }
103