altosdroid: initial implementation of telemetry logging.
[fw/altos] / altoslib / AltosMs5607Query.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 AltosMs5607Query extends AltosMs5607 {
23         public AltosMs5607Query (AltosLink link) throws InterruptedException, TimeoutException {
24                 link.printf("v\nB\n");
25                 for (;;) {
26                         String line = link.get_reply_no_dialog(5000);
27                         if (line == null) {
28                                 throw new TimeoutException();
29                         }
30                         String[] items = line.split("\\s+");
31                         if (line.startsWith("Pressure:")) {
32                                 if (items.length >= 2)
33                                         raw_pres = Integer.parseInt(items[1]);
34                         } else if (line.startsWith("Temperature:")) {
35                                 if (items.length >= 2)
36                                         raw_temp = Integer.parseInt(items[1]);
37                         } else if (line.startsWith("ms5607 reserved:")) {
38                                 if (items.length >= 3)
39                                         reserved = Integer.parseInt(items[2]);
40                         } else if (line.startsWith("ms5607 sens:")) {
41                                 if (items.length >= 3)
42                                         sens = Integer.parseInt(items[2]);
43                         } else if (line.startsWith("ms5607 off:")) {
44                                 if (items.length >= 3)
45                                         off = Integer.parseInt(items[2]);
46                         } else if (line.startsWith("ms5607 tcs:")) {
47                                 if (items.length >= 3)
48                                         tcs = Integer.parseInt(items[2]);
49                         } else if (line.startsWith("ms5607 tco:")) {
50                                 if (items.length >= 3)
51                                         tco = Integer.parseInt(items[2]);
52                         } else if (line.startsWith("ms5607 tref:")) {
53                                 if (items.length >= 3)
54                                         tref = Integer.parseInt(items[2]);
55                         } else if (line.startsWith("ms5607 tempsens:")) {
56                                 if (items.length >= 3)
57                                         tempsens = Integer.parseInt(items[2]);
58                         } else if (line.startsWith("ms5607 crc:")) {
59                                 if (items.length >= 3)
60                                         crc = Integer.parseInt(items[2]);
61                         } else if (line.startsWith("Altitude"))
62                                 break;
63                 }
64                 convert();
65         }
66 }
67