Switch from GPLv2 to GPLv2+
[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_11;
20
21 public abstract class AltosTelemetryStandard extends AltosTelemetry {
22         int[]   bytes;
23         int     type;
24
25         public int int8(int off) {
26                 return AltosLib.int8(bytes, off + 1);
27         }
28
29         public int uint8(int off) {
30                 return AltosLib.uint8(bytes, off + 1);
31         }
32
33         public int int16(int off) {
34                 return AltosLib.int16(bytes, off + 1);
35         }
36
37         public int uint16(int off) {
38                 return AltosLib.uint16(bytes, off + 1);
39         }
40
41         public int uint32(int off) {
42                 return AltosLib.uint32(bytes, off + 1);
43         }
44
45         public int int32(int off) {
46                 return AltosLib.int32(bytes, off + 1);
47         }
48
49         public String string(int off, int l) {
50                 return AltosLib.string(bytes, off + 1, l);
51         }
52
53         public static AltosTelemetry parse_hex(int[] bytes) {
54                 int     type = AltosLib.uint8(bytes, 4 + 1);
55
56                 AltosTelemetry  telem;
57                 switch (type) {
58                 case packet_type_TM_sensor:
59                 case packet_type_Tm_sensor:
60                 case packet_type_Tn_sensor:
61                         telem = new AltosTelemetrySensor(bytes);
62                         break;
63                 case packet_type_configuration:
64                         telem = new AltosTelemetryConfiguration(bytes);
65                         break;
66                 case packet_type_location:
67                         telem = new AltosTelemetryLocation(bytes);
68                         break;
69                 case packet_type_satellite:
70                         telem = new AltosTelemetrySatellite(bytes);
71                         break;
72                 case packet_type_companion:
73                         telem = new AltosTelemetryCompanion(bytes);
74                         break;
75                 case packet_type_mega_sensor:
76                         telem = new AltosTelemetryMegaSensor(bytes);
77                         break;
78                 case packet_type_mega_data:
79                         telem = new AltosTelemetryMegaData(bytes);
80                         break;
81                 case packet_type_metrum_sensor:
82                         telem = new AltosTelemetryMetrumSensor(bytes);
83                         break;
84                 case packet_type_metrum_data:
85                         telem = new AltosTelemetryMetrumData(bytes);
86                         break;
87                 case packet_type_mini:
88                         telem = new AltosTelemetryMini(bytes);
89                         break;
90                 default:
91                         telem = new AltosTelemetryRaw(bytes);
92                         break;
93                 }
94                 return telem;
95         }
96
97         public AltosTelemetryStandard(int[] bytes) {
98                 this.bytes = bytes;
99
100                 serial = uint16(0);
101                 tick   = uint16(2);
102                 type   = uint8(4);
103         }
104
105         public void update_state(AltosState state) {
106                 super.update_state(state);
107         }
108 }