MAVLinkPayload.java
Go to the documentation of this file.
1 /* AUTO-GENERATED FILE. DO NOT MODIFY.
2  *
3  * This class was automatically generated by the
4  * java mavlink generator tool. It should not be modified by hand.
5  */
6 
7 package com.MAVLink.Messages;
8 
9 import java.nio.ByteBuffer;
10 
11 public class MAVLinkPayload {
12 
13  private static final byte UNSIGNED_BYTE_MIN_VALUE = 0;
14  private static final short UNSIGNED_BYTE_MAX_VALUE = Byte.MAX_VALUE - Byte.MIN_VALUE;
15 
16  private static final short UNSIGNED_SHORT_MIN_VALUE = 0;
17  private static final int UNSIGNED_SHORT_MAX_VALUE = Short.MAX_VALUE - Short.MIN_VALUE;
18 
19  private static final int UNSIGNED_INT_MIN_VALUE = 0;
20  private static final long UNSIGNED_INT_MAX_VALUE = (long) Integer.MAX_VALUE - Integer.MIN_VALUE;
21 
22  private static final long UNSIGNED_LONG_MIN_VALUE = 0;
23 
24  public static final int MAX_PAYLOAD_SIZE = 255;
25 
26  public final ByteBuffer payload;
27  public int index;
28 
29  public MAVLinkPayload(int payloadSize) {
30  if(payloadSize > MAX_PAYLOAD_SIZE) {
31  payload = ByteBuffer.allocate(MAX_PAYLOAD_SIZE);
32  } else {
33  payload = ByteBuffer.allocate(payloadSize);
34  }
35  }
36 
37  public ByteBuffer getData() {
38  return payload;
39  }
40 
41  public int size() {
42  return payload.position();
43  }
44 
45  public void add(byte c) {
46  payload.put(c);
47  }
48 
49  public void resetIndex() {
50  index = 0;
51  }
52 
53  public byte getByte() {
54  byte result = 0;
55  result |= (payload.get(index + 0) & 0xFF);
56  index += 1;
57  return result;
58  }
59 
60  public short getUnsignedByte(){
61  short result = 0;
62  result |= payload.get(index + 0) & 0xFF;
63  index+= 1;
64  return result;
65  }
66 
67  public short getShort() {
68  short result = 0;
69  result |= (payload.get(index + 1) & 0xFF) << 8;
70  result |= (payload.get(index + 0) & 0xFF);
71  index += 2;
72  return result;
73  }
74 
75  public int getUnsignedShort(){
76  int result = 0;
77  result |= (payload.get(index + 1) & 0xFF) << 8;
78  result |= (payload.get(index + 0) & 0xFF);
79  index += 2;
80  return result;
81  }
82 
83  public int getInt() {
84  int result = 0;
85  result |= (payload.get(index + 3) & 0xFF) << 24;
86  result |= (payload.get(index + 2) & 0xFF) << 16;
87  result |= (payload.get(index + 1) & 0xFF) << 8;
88  result |= (payload.get(index + 0) & 0xFF);
89  index += 4;
90  return result;
91  }
92 
93  public long getUnsignedInt(){
94  long result = 0;
95  result |= (payload.get(index + 3) & 0xFFL) << 24;
96  result |= (payload.get(index + 2) & 0xFFL) << 16;
97  result |= (payload.get(index + 1) & 0xFFL) << 8;
98  result |= (payload.get(index + 0) & 0xFFL);
99  index += 4;
100  return result;
101  }
102 
103  public long getLong() {
104  long result = 0;
105  result |= (payload.get(index + 7) & 0xFFL) << 56;
106  result |= (payload.get(index + 6) & 0xFFL) << 48;
107  result |= (payload.get(index + 5) & 0xFFL) << 40;
108  result |= (payload.get(index + 4) & 0xFFL) << 32;
109  result |= (payload.get(index + 3) & 0xFFL) << 24;
110  result |= (payload.get(index + 2) & 0xFFL) << 16;
111  result |= (payload.get(index + 1) & 0xFFL) << 8;
112  result |= (payload.get(index + 0) & 0xFFL);
113  index += 8;
114  return result;
115  }
116 
117  public long getUnsignedLong(){
118  return getLong();
119  }
120 
121  public long getLongReverse() {
122  long result = 0;
123  result |= (payload.get(index + 0) & 0xFFL) << 56;
124  result |= (payload.get(index + 1) & 0xFFL) << 48;
125  result |= (payload.get(index + 2) & 0xFFL) << 40;
126  result |= (payload.get(index + 3) & 0xFFL) << 32;
127  result |= (payload.get(index + 4) & 0xFFL) << 24;
128  result |= (payload.get(index + 5) & 0xFFL) << 16;
129  result |= (payload.get(index + 6) & 0xFFL) << 8;
130  result |= (payload.get(index + 7) & 0xFFL);
131  index += 8;
132  return result;
133  }
134 
135  public float getFloat() {
136  return Float.intBitsToFloat(getInt());
137  }
138 
139  public void putByte(byte data) {
140  add(data);
141  }
142 
143  public void putUnsignedByte(short data){
144  if(data < UNSIGNED_BYTE_MIN_VALUE || data > UNSIGNED_BYTE_MAX_VALUE){
145  throw new IllegalArgumentException("Value is outside of the range of an unsigned byte: " + data);
146  }
147 
148  putByte((byte) data);
149  }
150 
151  public void putShort(short data) {
152  add((byte) (data >> 0));
153  add((byte) (data >> 8));
154  }
155 
156  public void putUnsignedShort(int data){
157  if(data < UNSIGNED_SHORT_MIN_VALUE || data > UNSIGNED_SHORT_MAX_VALUE){
158  throw new IllegalArgumentException("Value is outside of the range of an unsigned short: " + data);
159  }
160 
161  putShort((short) data);
162  }
163 
164  public void putInt(int data) {
165  add((byte) (data >> 0));
166  add((byte) (data >> 8));
167  add((byte) (data >> 16));
168  add((byte) (data >> 24));
169  }
170 
171  public void putUnsignedInt(long data){
172  if(data < UNSIGNED_INT_MIN_VALUE || data > UNSIGNED_INT_MAX_VALUE){
173  throw new IllegalArgumentException("Value is outside of the range of an unsigned int: " + data);
174  }
175 
176  putInt((int) data);
177  }
178 
179  public void putLong(long data) {
180  add((byte) (data >> 0));
181  add((byte) (data >> 8));
182  add((byte) (data >> 16));
183  add((byte) (data >> 24));
184  add((byte) (data >> 32));
185  add((byte) (data >> 40));
186  add((byte) (data >> 48));
187  add((byte) (data >> 56));
188  }
189 
190  public void putUnsignedLong(long data){
191  if(data < UNSIGNED_LONG_MIN_VALUE){
192  throw new IllegalArgumentException("Value is outside of the range of an unsigned long: " + data);
193  }
194 
195  putLong(data);
196  }
197 
198  public void putFloat(float data) {
199  putInt(Float.floatToIntBits(data));
200  }
201 
202 }


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Apr 7 2019 02:06:02