563815618f41a33d6a516f6b46ee2781c26fe22b
[fw/altos] / altoslib / AltosTelemetryStandard.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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altoslib_12;
20
21 public abstract class AltosTelemetryStandard extends AltosTelemetry {
22         public int int8(int off) {
23                 return AltosLib.int8(bytes, off + 1);
24         }
25
26         public int uint8(int off) {
27                 return AltosLib.uint8(bytes, off + 1);
28         }
29
30         public int int16(int off) {
31                 return AltosLib.int16(bytes, off + 1);
32         }
33
34         public int uint16(int off) {
35                 return AltosLib.uint16(bytes, off + 1);
36         }
37
38         public int uint32(int off) {
39                 return AltosLib.uint32(bytes, off + 1);
40         }
41
42         public int int32(int off) {
43                 return AltosLib.int32(bytes, off + 1);
44         }
45
46         public String string(int off, int l) {
47                 return AltosLib.string(bytes, off + 1, l);
48         }
49
50         public int type() { return uint8(4); }
51
52         public int serial() { return uint16(0); }
53
54         public int tick() { return uint16(2); }
55
56         public static AltosTelemetry parse_hex(int[] bytes) throws AltosCRCException {
57                 AltosTelemetry  telem;
58
59                 int type = AltosLib.uint8(bytes, 4+1);
60                 switch (type) {
61                 case packet_type_TM_sensor:
62                 case packet_type_Tm_sensor:
63                 case packet_type_Tn_sensor:
64                         telem = new AltosTelemetrySensor(bytes);
65                         break;
66                 case packet_type_configuration:
67                         telem = new AltosTelemetryConfiguration(bytes);
68                         break;
69                 case packet_type_location:
70                         telem = new AltosTelemetryLocation(bytes);
71                         break;
72                 case packet_type_satellite:
73                         telem = new AltosTelemetrySatellite(bytes);
74                         break;
75                 case packet_type_companion:
76                         telem = new AltosTelemetryCompanion(bytes);
77                         break;
78                 case packet_type_mega_sensor:
79                         telem = new AltosTelemetryMegaSensor(bytes);
80                         break;
81                 case packet_type_mega_data:
82                         telem = new AltosTelemetryMegaData(bytes);
83                         break;
84                 case packet_type_metrum_sensor:
85                         telem = new AltosTelemetryMetrumSensor(bytes);
86                         break;
87                 case packet_type_metrum_data:
88                         telem = new AltosTelemetryMetrumData(bytes);
89                         break;
90                 case packet_type_mini2:
91                         telem = new AltosTelemetryMini2(bytes);
92                         break;
93                 case packet_type_mini3:
94                         telem = new AltosTelemetryMini3(bytes);
95                         break;
96                 default:
97                         telem = new AltosTelemetryRaw(bytes);
98                         break;
99                 }
100                 return telem;
101         }
102
103         public AltosTelemetryStandard(int[] bytes) throws AltosCRCException {
104                 super(bytes);
105         }
106
107         public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
108                 super.provide_data(listener, cal_data);
109         }
110 }