2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
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.
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.
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.
18 package org.altusmetrum.altoslib_2;
20 import java.util.concurrent.*;
22 public class AltosMs5607 {
37 static final boolean ms5611 = false;
46 dT = raw_temp - ((int) tref << 8);
48 TEMP = (int) (2000 + (((long) dT * (long) tempsens) >> 23));
51 OFF = ((long) off << 16) + (((long) tco * (long) dT) >> 7);
53 SENS = ((long) sens << 15) + (((long) tcs * (long) dT) >> 8);
55 OFF = ((long) off << 17) + (((long) tco * (long) dT) >> 6);
57 SENS = ((long) sens << 16) + (((long) tcs * (long) dT) >> 7);
61 int T2 = (int) (((long) dT * (long) dT) >> 31);
62 int TEMPM = TEMP - 2000;
63 long OFF2 = ((long) 61 * (long) TEMPM * (long) TEMPM) >> 4;
64 long SENS2 = (long) 2 * (long) TEMPM * (long) TEMPM;
66 int TEMPP = TEMP + 1500;
67 long TEMPP2 = (long) TEMPP * (long) TEMPP;
68 OFF2 = OFF2 + 15 * TEMPP2;
69 SENS2 = SENS2 + 8 * TEMPP2;
76 pa = (int) (((((long) raw_pres * SENS) >> 21) - OFF) >> 15);
80 public int set(int in_pres, int in_temp) {
87 public boolean parse_line(String line) {
88 String[] items = line.split("\\s+");
89 if (line.startsWith("Pressure:")) {
90 if (items.length >= 2) {
91 raw_pres = Integer.parseInt(items[1]);
93 } else if (line.startsWith("Temperature:")) {
94 if (items.length >= 2)
95 raw_temp = Integer.parseInt(items[1]);
96 } else if (line.startsWith("ms5607 reserved:")) {
97 if (items.length >= 3)
98 reserved = Integer.parseInt(items[2]);
99 } else if (line.startsWith("ms5607 sens:")) {
100 if (items.length >= 3) {
101 sens = Integer.parseInt(items[2]);
103 } else if (line.startsWith("ms5607 off:")) {
104 if (items.length >= 3)
105 off = Integer.parseInt(items[2]);
106 } else if (line.startsWith("ms5607 tcs:")) {
107 if (items.length >= 3)
108 tcs = Integer.parseInt(items[2]);
109 } else if (line.startsWith("ms5607 tco:")) {
110 if (items.length >= 3)
111 tco = Integer.parseInt(items[2]);
112 } else if (line.startsWith("ms5607 tref:")) {
113 if (items.length >= 3)
114 tref = Integer.parseInt(items[2]);
115 } else if (line.startsWith("ms5607 tempsens:")) {
116 if (items.length >= 3)
117 tempsens = Integer.parseInt(items[2]);
118 } else if (line.startsWith("ms5607 crc:")) {
119 if (items.length >= 3)
120 crc = Integer.parseInt(items[2]);
121 } else if (line.startsWith("Altitude:")) {
127 static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
129 AltosMs5607 ms5607 = new AltosMs5607(link);
131 if (ms5607 != null) {
132 state.set_ms5607(ms5607);
135 } catch (TimeoutException te) {
139 public AltosMs5607() {
140 raw_pres = AltosLib.MISSING;
141 raw_temp = AltosLib.MISSING;
142 pa = AltosLib.MISSING;
143 cc = AltosLib.MISSING;
146 public AltosMs5607 (AltosLink link) throws InterruptedException, TimeoutException {
148 link.printf("c s\nB\n");
150 String line = link.get_reply_no_dialog(5000);
152 throw new TimeoutException();
154 if (!parse_line(line)) {