Skip to content

Commit

Permalink
Commiting all the modified files as a result of the updated message d…
Browse files Browse the repository at this point in the history
…efinitions.
  • Loading branch information
gmorph authored and billbonney committed Nov 12, 2017
1 parent a69de40 commit 836044c
Show file tree
Hide file tree
Showing 251 changed files with 4,832 additions and 4,732 deletions.
399 changes: 216 additions & 183 deletions dependencyLibs/Mavlink/src/com/MAVLink/MAVLinkPacket.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@

package com.MAVLink.Messages;

import com.MAVLink.MAVLinkPacket;

import java.io.Serializable;

import com.MAVLink.MAVLinkPacket;

public abstract class MAVLinkMessage implements Serializable {
private static final long serialVersionUID = -7754622750478538539L;
// The MAVLink message classes have been changed to implement Serializable,
// this way is possible to pass a mavlink message through the Service-Activity interface
// this way is possible to pass a mavlink message trought the Service-Acctivity interface

/**
* Simply a common interface for all MAVLink Messages
*/

public int sysid;
public int sysid;
public int compid;
public int msgid;
public abstract MAVLinkPacket pack();
public abstract void unpack(MAVLinkPayload payload);
}

49 changes: 27 additions & 22 deletions dependencyLibs/Mavlink/src/com/MAVLink/Messages/MAVLinkPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ public class MAVLinkPayload {

private static final long UNSIGNED_LONG_MIN_VALUE = 0;

public static final int MAX_PAYLOAD_SIZE = 255;

public final ByteBuffer payload;
public int index;

public MAVLinkPayload(int payloadSize) {
//Payload size should be less than 512.
payload = ByteBuffer.allocate(payloadSize);
if(payloadSize > MAX_PAYLOAD_SIZE) {
payload = ByteBuffer.allocate(MAX_PAYLOAD_SIZE);
} else {
payload = ByteBuffer.allocate(payloadSize);
}
}

public ByteBuffer getData() {
Expand Down Expand Up @@ -87,24 +92,24 @@ public int getInt() {

public long getUnsignedInt(){
long result = 0;
result |= (payload.get(index + 3) & 0xFFFFL) << 24;
result |= (payload.get(index + 2) & 0xFFFFL) << 16;
result |= (payload.get(index + 1) & 0xFFFFL) << 8;
result |= (payload.get(index + 0) & 0xFFFFL);
result |= (payload.get(index + 3) & 0xFFL) << 24;
result |= (payload.get(index + 2) & 0xFFL) << 16;
result |= (payload.get(index + 1) & 0xFFL) << 8;
result |= (payload.get(index + 0) & 0xFFL);
index += 4;
return result;
}

public long getLong() {
long result = 0;
result |= (payload.get(index + 7) & 0xFFFFL) << 56;
result |= (payload.get(index + 6) & 0xFFFFL) << 48;
result |= (payload.get(index + 5) & 0xFFFFL) << 40;
result |= (payload.get(index + 4) & 0xFFFFL) << 32;
result |= (payload.get(index + 3) & 0xFFFFL) << 24;
result |= (payload.get(index + 2) & 0xFFFFL) << 16;
result |= (payload.get(index + 1) & 0xFFFFL) << 8;
result |= (payload.get(index + 0) & 0xFFFFL);
result |= (payload.get(index + 7) & 0xFFL) << 56;
result |= (payload.get(index + 6) & 0xFFL) << 48;
result |= (payload.get(index + 5) & 0xFFL) << 40;
result |= (payload.get(index + 4) & 0xFFL) << 32;
result |= (payload.get(index + 3) & 0xFFL) << 24;
result |= (payload.get(index + 2) & 0xFFL) << 16;
result |= (payload.get(index + 1) & 0xFFL) << 8;
result |= (payload.get(index + 0) & 0xFFL);
index += 8;
return result;
}
Expand All @@ -115,14 +120,14 @@ public long getUnsignedLong(){

public long getLongReverse() {
long result = 0;
result |= (payload.get(index + 0) & 0xFFFFL) << 56;
result |= (payload.get(index + 1) & 0xFFFFL) << 48;
result |= (payload.get(index + 2) & 0xFFFFL) << 40;
result |= (payload.get(index + 3) & 0xFFFFL) << 32;
result |= (payload.get(index + 4) & 0xFFFFL) << 24;
result |= (payload.get(index + 5) & 0xFFFFL) << 16;
result |= (payload.get(index + 6) & 0xFFFFL) << 8;
result |= (payload.get(index + 7) & 0xFFFFL);
result |= (payload.get(index + 0) & 0xFFL) << 56;
result |= (payload.get(index + 1) & 0xFFL) << 48;
result |= (payload.get(index + 2) & 0xFFL) << 40;
result |= (payload.get(index + 3) & 0xFFL) << 32;
result |= (payload.get(index + 4) & 0xFFL) << 24;
result |= (payload.get(index + 5) & 0xFFL) << 16;
result |= (payload.get(index + 6) & 0xFFL) << 8;
result |= (payload.get(index + 7) & 0xFFL);
index += 8;
return result;
}
Expand Down
138 changes: 106 additions & 32 deletions dependencyLibs/Mavlink/src/com/MAVLink/Messages/MAVLinkStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@
package com.MAVLink.Messages;

import com.MAVLink.MAVLinkPacket;
import com.MAVLink.common.msg_radio_status;

/**
* Storage for MAVLink Packet and Error statistics
*
*/
public class MAVLinkStats /* implements Serializable */{

public int receivedPacketCount;
public int receivedPacketCount; // total recieved packet count for all sources

public int crcErrorCount;

public int lostPacketCount;
public int lostPacketCount; // total lost packet count for all sources

private int lastPacketSeq;
public boolean ignoreRadioPackets;

// stats are nil for a system id until a packet has been received from a system
public SystemStat[] systemStats; // stats for each system that is known

public MAVLinkStats() {
this(false);
}

public MAVLinkStats(boolean ignoreRadioPackets) {
this.ignoreRadioPackets = ignoreRadioPackets;
resetStats();
}

/**
* Check the new received packet to see if has lost someone between this and
Expand All @@ -30,31 +43,16 @@ public class MAVLinkStats /* implements Serializable */{
* Packet that should be checked
*/
public void newPacket(MAVLinkPacket packet) {
advanceLastPacketSequence();
if (hasLostPackets(packet)) {
updateLostPacketCount(packet);
if (ignoreRadioPackets && packet.msgid == msg_radio_status.MAVLINK_MSG_ID_RADIO_STATUS) {
return;
}
lastPacketSeq = packet.seq;
receivedPacketCount++;
}

private void updateLostPacketCount(MAVLinkPacket packet) {
int lostPackets;
if (packet.seq - lastPacketSeq < 0) {
lostPackets = (packet.seq - lastPacketSeq) + 255;
} else {
lostPackets = (packet.seq - lastPacketSeq);
if (systemStats[packet.sysid] == null) {
// only allocate stats for systems that exsist on the network
systemStats[packet.sysid] = new SystemStat();
}
lostPacketCount += lostPackets;
}

private boolean hasLostPackets(MAVLinkPacket packet) {
return lastPacketSeq > 0 && packet.seq != lastPacketSeq;
}

private void advanceLastPacketSequence() {
// wrap from 255 to 0 if necessary
lastPacketSeq = (lastPacketSeq + 1) & 0xFF;
lostPacketCount += systemStats[packet.sysid].newPacket(packet);
receivedPacketCount++;
}

/**
Expand All @@ -64,14 +62,90 @@ public void crcError() {
crcErrorCount++;
}

/**
* Resets statistics for this MAVLink.
*/
public void mavlinkResetStats() {
lastPacketSeq = -1;
lostPacketCount = 0;
public void resetStats() {
crcErrorCount = 0;
lostPacketCount = 0;
receivedPacketCount = 0;
systemStats = new SystemStat[256];
}

// stat structure for every system id
public static class SystemStat {
public int lostPacketCount; // the lost count for this source
public int receivedPacketCount;

// stats are nil for a component id until a packet has been received from a system
public ComponentStat[] componentStats; // stats for each component that is known

public SystemStat() {
resetStats();
}

public int newPacket(MAVLinkPacket packet) {
int newLostPackets = 0;
if (componentStats[packet.compid] == null) {
// only allocate stats for systems that exsist on the network
componentStats[packet.compid] = new ComponentStat();
}
newLostPackets = componentStats[packet.compid].newPacket(packet);
lostPacketCount += newLostPackets;
receivedPacketCount++;
return newLostPackets;
}

public void resetStats() {
lostPacketCount = 0;
receivedPacketCount = 0;
componentStats = new ComponentStat[256];
}
}

// stat structure for every system id
public static class ComponentStat {
public int lastPacketSeq;
public int lostPacketCount; // the lost count for this source
public int receivedPacketCount;

public ComponentStat() {
resetStats();
}

public int newPacket(MAVLinkPacket packet) {
int newLostPackets = 0;
if (hasLostPackets(packet)) {
newLostPackets = updateLostPacketCount(packet);
}
lastPacketSeq = packet.seq;
advanceLastPacketSequence(packet.seq);
receivedPacketCount++;
return newLostPackets;
}

public void resetStats() {
lastPacketSeq = -1;
lostPacketCount = 0;
receivedPacketCount = 0;
}

private int updateLostPacketCount(MAVLinkPacket packet) {
int lostPackets;
if (packet.seq - lastPacketSeq < 0) {
lostPackets = (packet.seq - lastPacketSeq) + 255;
} else {
lostPackets = (packet.seq - lastPacketSeq);
}
lostPacketCount += lostPackets;
return lostPackets;
}

private void advanceLastPacketSequence(int lastSeq) {
// wrap from 255 to 0 if necessary
lastPacketSeq = (lastSeq + 1) & 0xFF;
}

private boolean hasLostPackets(MAVLinkPacket packet) {
return lastPacketSeq >= 0 && packet.seq != lastPacketSeq;
}
}

}
}
33 changes: 13 additions & 20 deletions dependencyLibs/Mavlink/src/com/MAVLink/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ enum MAV_states {

MAV_states state = MAV_states.MAVLINK_PARSE_STATE_UNINIT;

private boolean msg_received;

public MAVLinkStats stats = new MAVLinkStats();
public MAVLinkStats stats;
private MAVLinkPacket m;

public Parser() {
this(false);
}

public Parser(boolean ignoreRadioPacketStats) {
stats = new MAVLinkStats(ignoreRadioPacketStats);
}

/**
* This is a convenience function which handles the complete MAVLink
* parsing. the function will parse one byte at a time and return the
Expand All @@ -35,7 +41,6 @@ enum MAV_states {
* The char to parse
*/
public MAVLinkPacket mavlink_parse_char(int c) {
msg_received = false;

switch (state) {
case MAVLINK_PARSE_STATE_UNINIT:
Expand All @@ -47,13 +52,8 @@ public MAVLinkPacket mavlink_parse_char(int c) {
break;

case MAVLINK_PARSE_STATE_GOT_STX:
if (msg_received) {
msg_received = false;
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
} else {
m = new MAVLinkPacket(c);
state = MAV_states.MAVLINK_PARSE_STATE_GOT_LENGTH;
}
m = new MAVLinkPacket(c);
state = MAV_states.MAVLINK_PARSE_STATE_GOT_LENGTH;
break;

case MAVLINK_PARSE_STATE_GOT_LENGTH:
Expand Down Expand Up @@ -91,7 +91,6 @@ public MAVLinkPacket mavlink_parse_char(int c) {
m.generateCRC();
// Check first checksum byte
if (c != m.crc.getLSB()) {
msg_received = false;
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
if (c == MAVLinkPacket.MAVLINK_STX) {
state = MAV_states.MAVLINK_PARSE_STATE_GOT_STX;
Expand All @@ -106,7 +105,6 @@ public MAVLinkPacket mavlink_parse_char(int c) {
case MAVLINK_PARSE_STATE_GOT_CRC1:
// Check second checksum byte
if (c != m.crc.getMSB()) {
msg_received = false;
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
if (c == MAVLinkPacket.MAVLINK_STX) {
state = MAV_states.MAVLINK_PARSE_STATE_GOT_STX;
Expand All @@ -115,18 +113,13 @@ public MAVLinkPacket mavlink_parse_char(int c) {
stats.crcError();
} else { // Successfully received the message
stats.newPacket(m);
msg_received = true;
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
return m;
}

break;

}
if (msg_received) {
return m;
} else {
return null;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/
public class CRC {
private static final int[] MAVLINK_MESSAGE_CRCS = {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 78, 0, 0, 0, 15, 3, 0, 0, 0, 0, 0, 153, 183, 51, 59, 118, 148, 21, 0, 243, 124, 0, 0, 38, 20, 158, 152, 143, 0, 0, 0, 106, 49, 22, 143, 140, 5, 150, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 93, 138, 108, 32, 185, 84, 34, 174, 124, 237, 4, 76, 128, 56, 116, 134, 237, 203, 250, 87, 203, 220, 25, 226, 46, 29, 223, 85, 6, 229, 203, 1, 195, 109, 168, 181, 148, 72, 131, 0, 0, 103, 154, 178, 200, 134, 219, 208, 188, 84, 22, 19, 21, 134, 0, 78, 68, 189, 127, 154, 21, 21, 144, 1, 234, 73, 181, 22, 83, 167, 138, 234, 240, 47, 189, 52, 174, 229, 85, 159, 186, 72, 0, 0, 0, 0, 92, 36, 71, 98, 0, 0, 0, 0, 0, 134, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 101, 50, 202, 17, 162, 0, 0, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 104, 85, 95, 130, 0, 0, 8, 204, 49, 170, 44, 83, 46, 0};
private static final int[] MAVLINK_MESSAGE_CRCS = {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 78, 196, 0, 0, 15, 3, 0, 0, 0, 0, 0, 167, 183, 119, 191, 118, 148, 21, 0, 243, 124, 0, 0, 38, 20, 158, 152, 143, 0, 0, 0, 106, 49, 22, 143, 140, 5, 150, 0, 231, 183, 63, 54, 47, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 93, 138, 108, 32, 185, 84, 34, 174, 124, 237, 4, 76, 128, 56, 116, 134, 237, 203, 250, 87, 203, 220, 25, 226, 46, 29, 223, 85, 6, 229, 203, 1, 195, 109, 168, 181, 47, 72, 131, 127, 0, 103, 154, 178, 200, 134, 219, 208, 188, 84, 22, 19, 21, 134, 0, 78, 68, 189, 127, 154, 21, 21, 144, 1, 234, 73, 181, 22, 83, 167, 138, 234, 240, 47, 189, 52, 174, 229, 85, 159, 186, 72, 0, 0, 0, 0, 92, 36, 71, 98, 120, 0, 0, 0, 0, 134, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 101, 50, 202, 17, 162, 0, 0, 0, 0, 0, 0, 207, 0, 0, 0, 163, 105, 151, 35, 150, 0, 0, 0, 0, 0, 0, 90, 104, 85, 95, 130, 184, 81, 8, 204, 49, 170, 44, 83, 46, 0};
private static final int CRC_INIT_VALUE = 0xffff;
private int crcValue;

Expand Down
Loading

0 comments on commit 836044c

Please sign in to comment.