MAVLinkPayload.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. package com.MAVLink.Messages;
  7. import java.nio.ByteBuffer;
  8. public class MAVLinkPayload {
  9. private static final byte UNSIGNED_BYTE_MIN_VALUE = 0;
  10. private static final short UNSIGNED_BYTE_MAX_VALUE = Byte.MAX_VALUE - Byte.MIN_VALUE;
  11. private static final short UNSIGNED_SHORT_MIN_VALUE = 0;
  12. private static final int UNSIGNED_SHORT_MAX_VALUE = Short.MAX_VALUE - Short.MIN_VALUE;
  13. private static final int UNSIGNED_INT_MIN_VALUE = 0;
  14. private static final long UNSIGNED_INT_MAX_VALUE = (long) Integer.MAX_VALUE - Integer.MIN_VALUE;
  15. private static final long UNSIGNED_LONG_MIN_VALUE = 0;
  16. public static final int MAX_PAYLOAD_SIZE = 255;
  17. public final ByteBuffer payload;
  18. public int index;
  19. public MAVLinkPayload(int payloadSize) {
  20. if(payloadSize > MAX_PAYLOAD_SIZE) {
  21. payload = ByteBuffer.allocate(MAX_PAYLOAD_SIZE);
  22. } else {
  23. payload = ByteBuffer.allocate(payloadSize);
  24. }
  25. }
  26. public ByteBuffer getData() {
  27. return payload;
  28. }
  29. public int size() {
  30. return payload.position();
  31. }
  32. public void add(byte c) {
  33. payload.put(c);
  34. }
  35. public void resetIndex() {
  36. index = 0;
  37. }
  38. public byte getByte() {
  39. byte result = 0;
  40. result |= (payload.get(index + 0) & 0xFF);
  41. index += 1;
  42. return result;
  43. }
  44. public short getUnsignedByte(){
  45. short result = 0;
  46. result |= payload.get(index + 0) & 0xFF;
  47. index+= 1;
  48. return result;
  49. }
  50. public short getShort() {
  51. short result = 0;
  52. result |= (payload.get(index + 1) & 0xFF) << 8;
  53. result |= (payload.get(index + 0) & 0xFF);
  54. index += 2;
  55. return result;
  56. }
  57. public int getUnsignedShort(){
  58. int result = 0;
  59. result |= (payload.get(index + 1) & 0xFF) << 8;
  60. result |= (payload.get(index + 0) & 0xFF);
  61. index += 2;
  62. return result;
  63. }
  64. public int getInt() {
  65. int result = 0;
  66. result |= (payload.get(index + 3) & 0xFF) << 24;
  67. result |= (payload.get(index + 2) & 0xFF) << 16;
  68. result |= (payload.get(index + 1) & 0xFF) << 8;
  69. result |= (payload.get(index + 0) & 0xFF);
  70. index += 4;
  71. return result;
  72. }
  73. public long getUnsignedInt(){
  74. long result = 0;
  75. result |= (payload.get(index + 3) & 0xFFL) << 24;
  76. result |= (payload.get(index + 2) & 0xFFL) << 16;
  77. result |= (payload.get(index + 1) & 0xFFL) << 8;
  78. result |= (payload.get(index + 0) & 0xFFL);
  79. index += 4;
  80. return result;
  81. }
  82. public long getLong() {
  83. long result = 0;
  84. result |= (payload.get(index + 7) & 0xFFL) << 56;
  85. result |= (payload.get(index + 6) & 0xFFL) << 48;
  86. result |= (payload.get(index + 5) & 0xFFL) << 40;
  87. result |= (payload.get(index + 4) & 0xFFL) << 32;
  88. result |= (payload.get(index + 3) & 0xFFL) << 24;
  89. result |= (payload.get(index + 2) & 0xFFL) << 16;
  90. result |= (payload.get(index + 1) & 0xFFL) << 8;
  91. result |= (payload.get(index + 0) & 0xFFL);
  92. index += 8;
  93. return result;
  94. }
  95. public long getUnsignedLong(){
  96. return getLong();
  97. }
  98. public long getLongReverse() {
  99. long result = 0;
  100. result |= (payload.get(index + 0) & 0xFFL) << 56;
  101. result |= (payload.get(index + 1) & 0xFFL) << 48;
  102. result |= (payload.get(index + 2) & 0xFFL) << 40;
  103. result |= (payload.get(index + 3) & 0xFFL) << 32;
  104. result |= (payload.get(index + 4) & 0xFFL) << 24;
  105. result |= (payload.get(index + 5) & 0xFFL) << 16;
  106. result |= (payload.get(index + 6) & 0xFFL) << 8;
  107. result |= (payload.get(index + 7) & 0xFFL);
  108. index += 8;
  109. return result;
  110. }
  111. public float getFloat() {
  112. return Float.intBitsToFloat(getInt());
  113. }
  114. public void putByte(byte data) {
  115. add(data);
  116. }
  117. public void putUnsignedByte(short data){
  118. if(data < UNSIGNED_BYTE_MIN_VALUE || data > UNSIGNED_BYTE_MAX_VALUE){
  119. throw new IllegalArgumentException("Value is outside of the range of an unsigned byte: " + data);
  120. }
  121. putByte((byte) data);
  122. }
  123. public void putShort(short data) {
  124. add((byte) (data >> 0));
  125. add((byte) (data >> 8));
  126. }
  127. public void putUnsignedShort(int data){
  128. if(data < UNSIGNED_SHORT_MIN_VALUE || data > UNSIGNED_SHORT_MAX_VALUE){
  129. throw new IllegalArgumentException("Value is outside of the range of an unsigned short: " + data);
  130. }
  131. putShort((short) data);
  132. }
  133. public void putInt(int data) {
  134. add((byte) (data >> 0));
  135. add((byte) (data >> 8));
  136. add((byte) (data >> 16));
  137. add((byte) (data >> 24));
  138. }
  139. public void putUnsignedInt(long data){
  140. if(data < UNSIGNED_INT_MIN_VALUE || data > UNSIGNED_INT_MAX_VALUE){
  141. throw new IllegalArgumentException("Value is outside of the range of an unsigned int: " + data);
  142. }
  143. putInt((int) data);
  144. }
  145. public void putLong(long data) {
  146. add((byte) (data >> 0));
  147. add((byte) (data >> 8));
  148. add((byte) (data >> 16));
  149. add((byte) (data >> 24));
  150. add((byte) (data >> 32));
  151. add((byte) (data >> 40));
  152. add((byte) (data >> 48));
  153. add((byte) (data >> 56));
  154. }
  155. public void putUnsignedLong(long data){
  156. if(data < UNSIGNED_LONG_MIN_VALUE){
  157. throw new IllegalArgumentException("Value is outside of the range of an unsigned long: " + data);
  158. }
  159. putLong(data);
  160. }
  161. public void putFloat(float data) {
  162. putInt(Float.floatToIntBits(data));
  163. }
  164. }