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;
20 public class AltosMs5607 {
35 static final boolean ms5611 = false;
44 dT = raw_temp - ((int) tref << 8);
46 TEMP = (int) (2000 + (((long) dT * (long) tempsens) >> 23));
49 OFF = ((long) off << 16) + (((long) tco * (long) dT) >> 7);
51 SENS = ((long) sens << 15) + (((long) tcs * (long) dT) >> 8);
53 OFF = ((long) off << 17) + (((long) tco * (long) dT) >> 6);
55 SENS = ((long) sens << 16) + (((long) tcs * (long) dT) >> 7);
59 int T2 = (int) (((long) dT * (long) dT) >> 31);
60 int TEMPM = TEMP - 2000;
61 long OFF2 = ((long) 61 * (long) TEMPM * (long) TEMPM) >> 4;
62 long SENS2 = (long) 2 * (long) TEMPM * (long) TEMPM;
64 int TEMPP = TEMP + 1500;
65 long TEMPP2 = (long) TEMPP * (long) TEMPP;
66 OFF2 = OFF2 + 15 * TEMPP2;
67 SENS2 = SENS2 + 8 * TEMPP2;
74 pa = (int) (((((long) raw_pres * SENS) >> 21) - OFF) >> 15);
78 public int set(int in_pres, int in_temp) {
85 public boolean parse_line(String line) {
86 String[] items = line.split("\\s+");
87 if (line.startsWith("Pressure:")) {
88 if (items.length >= 2)
89 raw_pres = Integer.parseInt(items[1]);
90 } else if (line.startsWith("Temperature:")) {
91 if (items.length >= 2)
92 raw_temp = Integer.parseInt(items[1]);
93 } else if (line.startsWith("ms5607 reserved:")) {
94 if (items.length >= 3)
95 reserved = Integer.parseInt(items[2]);
96 } else if (line.startsWith("ms5607 sens:")) {
97 if (items.length >= 3)
98 sens = Integer.parseInt(items[2]);
99 } else if (line.startsWith("ms5607 off:")) {
100 if (items.length >= 3)
101 off = Integer.parseInt(items[2]);
102 } else if (line.startsWith("ms5607 tcs:")) {
103 if (items.length >= 3)
104 tcs = Integer.parseInt(items[2]);
105 } else if (line.startsWith("ms5607 tco:")) {
106 if (items.length >= 3)
107 tco = Integer.parseInt(items[2]);
108 } else if (line.startsWith("ms5607 tref:")) {
109 if (items.length >= 3)
110 tref = Integer.parseInt(items[2]);
111 } else if (line.startsWith("ms5607 tempsens:")) {
112 if (items.length >= 3)
113 tempsens = Integer.parseInt(items[2]);
114 } else if (line.startsWith("ms5607 crc:")) {
115 if (items.length >= 3)
116 crc = Integer.parseInt(items[2]);
117 } else if (line.startsWith("Altitude"))
122 public AltosMs5607() {
123 raw_pres = AltosRecord.MISSING;
124 raw_temp = AltosRecord.MISSING;
125 pa = AltosRecord.MISSING;
126 cc = AltosRecord.MISSING;