Skip to content

Commit 836044c

Browse files
gmorphbillbonney
authored andcommitted
Commiting all the modified files as a result of the updated message definitions.
1 parent a69de40 commit 836044c

251 files changed

Lines changed: 4832 additions & 4732 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dependencyLibs/Mavlink/src/com/MAVLink/MAVLinkPacket.java

Lines changed: 216 additions & 183 deletions
Large diffs are not rendered by default.

dependencyLibs/Mavlink/src/com/MAVLink/Messages/MAVLinkMessage.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66

77
package com.MAVLink.Messages;
88

9-
import com.MAVLink.MAVLinkPacket;
10-
119
import java.io.Serializable;
1210

11+
import com.MAVLink.MAVLinkPacket;
12+
1313
public abstract class MAVLinkMessage implements Serializable {
1414
private static final long serialVersionUID = -7754622750478538539L;
1515
// The MAVLink message classes have been changed to implement Serializable,
16-
// this way is possible to pass a mavlink message through the Service-Activity interface
16+
// this way is possible to pass a mavlink message trought the Service-Acctivity interface
1717

1818
/**
1919
* Simply a common interface for all MAVLink Messages
2020
*/
2121

22-
public int sysid;
22+
public int sysid;
2323
public int compid;
2424
public int msgid;
2525
public abstract MAVLinkPacket pack();
2626
public abstract void unpack(MAVLinkPayload payload);
2727
}
28-

dependencyLibs/Mavlink/src/com/MAVLink/Messages/MAVLinkPayload.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ public class MAVLinkPayload {
2121

2222
private static final long UNSIGNED_LONG_MIN_VALUE = 0;
2323

24+
public static final int MAX_PAYLOAD_SIZE = 255;
25+
2426
public final ByteBuffer payload;
2527
public int index;
2628

2729
public MAVLinkPayload(int payloadSize) {
28-
//Payload size should be less than 512.
29-
payload = ByteBuffer.allocate(payloadSize);
30+
if(payloadSize > MAX_PAYLOAD_SIZE) {
31+
payload = ByteBuffer.allocate(MAX_PAYLOAD_SIZE);
32+
} else {
33+
payload = ByteBuffer.allocate(payloadSize);
34+
}
3035
}
3136

3237
public ByteBuffer getData() {
@@ -87,24 +92,24 @@ public int getInt() {
8792

8893
public long getUnsignedInt(){
8994
long result = 0;
90-
result |= (payload.get(index + 3) & 0xFFFFL) << 24;
91-
result |= (payload.get(index + 2) & 0xFFFFL) << 16;
92-
result |= (payload.get(index + 1) & 0xFFFFL) << 8;
93-
result |= (payload.get(index + 0) & 0xFFFFL);
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);
9499
index += 4;
95100
return result;
96101
}
97102

98103
public long getLong() {
99104
long result = 0;
100-
result |= (payload.get(index + 7) & 0xFFFFL) << 56;
101-
result |= (payload.get(index + 6) & 0xFFFFL) << 48;
102-
result |= (payload.get(index + 5) & 0xFFFFL) << 40;
103-
result |= (payload.get(index + 4) & 0xFFFFL) << 32;
104-
result |= (payload.get(index + 3) & 0xFFFFL) << 24;
105-
result |= (payload.get(index + 2) & 0xFFFFL) << 16;
106-
result |= (payload.get(index + 1) & 0xFFFFL) << 8;
107-
result |= (payload.get(index + 0) & 0xFFFFL);
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);
108113
index += 8;
109114
return result;
110115
}
@@ -115,14 +120,14 @@ public long getUnsignedLong(){
115120

116121
public long getLongReverse() {
117122
long result = 0;
118-
result |= (payload.get(index + 0) & 0xFFFFL) << 56;
119-
result |= (payload.get(index + 1) & 0xFFFFL) << 48;
120-
result |= (payload.get(index + 2) & 0xFFFFL) << 40;
121-
result |= (payload.get(index + 3) & 0xFFFFL) << 32;
122-
result |= (payload.get(index + 4) & 0xFFFFL) << 24;
123-
result |= (payload.get(index + 5) & 0xFFFFL) << 16;
124-
result |= (payload.get(index + 6) & 0xFFFFL) << 8;
125-
result |= (payload.get(index + 7) & 0xFFFFL);
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);
126131
index += 8;
127132
return result;
128133
}

dependencyLibs/Mavlink/src/com/MAVLink/Messages/MAVLinkStats.java

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,33 @@
77
package com.MAVLink.Messages;
88

99
import com.MAVLink.MAVLinkPacket;
10+
import com.MAVLink.common.msg_radio_status;
1011

1112
/**
1213
* Storage for MAVLink Packet and Error statistics
1314
*
1415
*/
1516
public class MAVLinkStats /* implements Serializable */{
1617

17-
public int receivedPacketCount;
18+
public int receivedPacketCount; // total recieved packet count for all sources
1819

1920
public int crcErrorCount;
2021

21-
public int lostPacketCount;
22+
public int lostPacketCount; // total lost packet count for all sources
2223

23-
private int lastPacketSeq;
24+
public boolean ignoreRadioPackets;
25+
26+
// stats are nil for a system id until a packet has been received from a system
27+
public SystemStat[] systemStats; // stats for each system that is known
28+
29+
public MAVLinkStats() {
30+
this(false);
31+
}
32+
33+
public MAVLinkStats(boolean ignoreRadioPackets) {
34+
this.ignoreRadioPackets = ignoreRadioPackets;
35+
resetStats();
36+
}
2437

2538
/**
2639
* Check the new received packet to see if has lost someone between this and
@@ -30,31 +43,16 @@ public class MAVLinkStats /* implements Serializable */{
3043
* Packet that should be checked
3144
*/
3245
public void newPacket(MAVLinkPacket packet) {
33-
advanceLastPacketSequence();
34-
if (hasLostPackets(packet)) {
35-
updateLostPacketCount(packet);
46+
if (ignoreRadioPackets && packet.msgid == msg_radio_status.MAVLINK_MSG_ID_RADIO_STATUS) {
47+
return;
3648
}
37-
lastPacketSeq = packet.seq;
38-
receivedPacketCount++;
39-
}
4049

41-
private void updateLostPacketCount(MAVLinkPacket packet) {
42-
int lostPackets;
43-
if (packet.seq - lastPacketSeq < 0) {
44-
lostPackets = (packet.seq - lastPacketSeq) + 255;
45-
} else {
46-
lostPackets = (packet.seq - lastPacketSeq);
50+
if (systemStats[packet.sysid] == null) {
51+
// only allocate stats for systems that exsist on the network
52+
systemStats[packet.sysid] = new SystemStat();
4753
}
48-
lostPacketCount += lostPackets;
49-
}
50-
51-
private boolean hasLostPackets(MAVLinkPacket packet) {
52-
return lastPacketSeq > 0 && packet.seq != lastPacketSeq;
53-
}
54-
55-
private void advanceLastPacketSequence() {
56-
// wrap from 255 to 0 if necessary
57-
lastPacketSeq = (lastPacketSeq + 1) & 0xFF;
54+
lostPacketCount += systemStats[packet.sysid].newPacket(packet);
55+
receivedPacketCount++;
5856
}
5957

6058
/**
@@ -64,14 +62,90 @@ public void crcError() {
6462
crcErrorCount++;
6563
}
6664

67-
/**
68-
* Resets statistics for this MAVLink.
69-
*/
70-
public void mavlinkResetStats() {
71-
lastPacketSeq = -1;
72-
lostPacketCount = 0;
65+
public void resetStats() {
7366
crcErrorCount = 0;
67+
lostPacketCount = 0;
7468
receivedPacketCount = 0;
69+
systemStats = new SystemStat[256];
70+
}
71+
72+
// stat structure for every system id
73+
public static class SystemStat {
74+
public int lostPacketCount; // the lost count for this source
75+
public int receivedPacketCount;
76+
77+
// stats are nil for a component id until a packet has been received from a system
78+
public ComponentStat[] componentStats; // stats for each component that is known
79+
80+
public SystemStat() {
81+
resetStats();
82+
}
83+
84+
public int newPacket(MAVLinkPacket packet) {
85+
int newLostPackets = 0;
86+
if (componentStats[packet.compid] == null) {
87+
// only allocate stats for systems that exsist on the network
88+
componentStats[packet.compid] = new ComponentStat();
89+
}
90+
newLostPackets = componentStats[packet.compid].newPacket(packet);
91+
lostPacketCount += newLostPackets;
92+
receivedPacketCount++;
93+
return newLostPackets;
94+
}
95+
96+
public void resetStats() {
97+
lostPacketCount = 0;
98+
receivedPacketCount = 0;
99+
componentStats = new ComponentStat[256];
100+
}
101+
}
102+
103+
// stat structure for every system id
104+
public static class ComponentStat {
105+
public int lastPacketSeq;
106+
public int lostPacketCount; // the lost count for this source
107+
public int receivedPacketCount;
108+
109+
public ComponentStat() {
110+
resetStats();
111+
}
112+
113+
public int newPacket(MAVLinkPacket packet) {
114+
int newLostPackets = 0;
115+
if (hasLostPackets(packet)) {
116+
newLostPackets = updateLostPacketCount(packet);
117+
}
118+
lastPacketSeq = packet.seq;
119+
advanceLastPacketSequence(packet.seq);
120+
receivedPacketCount++;
121+
return newLostPackets;
122+
}
123+
124+
public void resetStats() {
125+
lastPacketSeq = -1;
126+
lostPacketCount = 0;
127+
receivedPacketCount = 0;
128+
}
129+
130+
private int updateLostPacketCount(MAVLinkPacket packet) {
131+
int lostPackets;
132+
if (packet.seq - lastPacketSeq < 0) {
133+
lostPackets = (packet.seq - lastPacketSeq) + 255;
134+
} else {
135+
lostPackets = (packet.seq - lastPacketSeq);
136+
}
137+
lostPacketCount += lostPackets;
138+
return lostPackets;
139+
}
140+
141+
private void advanceLastPacketSequence(int lastSeq) {
142+
// wrap from 255 to 0 if necessary
143+
lastPacketSeq = (lastSeq + 1) & 0xFF;
144+
}
145+
146+
private boolean hasLostPackets(MAVLinkPacket packet) {
147+
return lastPacketSeq >= 0 && packet.seq != lastPacketSeq;
148+
}
75149
}
76150

77-
}
151+
}

dependencyLibs/Mavlink/src/com/MAVLink/Parser.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ enum MAV_states {
2020

2121
MAV_states state = MAV_states.MAVLINK_PARSE_STATE_UNINIT;
2222

23-
private boolean msg_received;
24-
25-
public MAVLinkStats stats = new MAVLinkStats();
23+
public MAVLinkStats stats;
2624
private MAVLinkPacket m;
2725

26+
public Parser() {
27+
this(false);
28+
}
29+
30+
public Parser(boolean ignoreRadioPacketStats) {
31+
stats = new MAVLinkStats(ignoreRadioPacketStats);
32+
}
33+
2834
/**
2935
* This is a convenience function which handles the complete MAVLink
3036
* parsing. the function will parse one byte at a time and return the
@@ -35,7 +41,6 @@ enum MAV_states {
3541
* The char to parse
3642
*/
3743
public MAVLinkPacket mavlink_parse_char(int c) {
38-
msg_received = false;
3944

4045
switch (state) {
4146
case MAVLINK_PARSE_STATE_UNINIT:
@@ -47,13 +52,8 @@ public MAVLinkPacket mavlink_parse_char(int c) {
4752
break;
4853

4954
case MAVLINK_PARSE_STATE_GOT_STX:
50-
if (msg_received) {
51-
msg_received = false;
52-
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
53-
} else {
54-
m = new MAVLinkPacket(c);
55-
state = MAV_states.MAVLINK_PARSE_STATE_GOT_LENGTH;
56-
}
55+
m = new MAVLinkPacket(c);
56+
state = MAV_states.MAVLINK_PARSE_STATE_GOT_LENGTH;
5757
break;
5858

5959
case MAVLINK_PARSE_STATE_GOT_LENGTH:
@@ -91,7 +91,6 @@ public MAVLinkPacket mavlink_parse_char(int c) {
9191
m.generateCRC();
9292
// Check first checksum byte
9393
if (c != m.crc.getLSB()) {
94-
msg_received = false;
9594
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
9695
if (c == MAVLinkPacket.MAVLINK_STX) {
9796
state = MAV_states.MAVLINK_PARSE_STATE_GOT_STX;
@@ -106,7 +105,6 @@ public MAVLinkPacket mavlink_parse_char(int c) {
106105
case MAVLINK_PARSE_STATE_GOT_CRC1:
107106
// Check second checksum byte
108107
if (c != m.crc.getMSB()) {
109-
msg_received = false;
110108
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
111109
if (c == MAVLinkPacket.MAVLINK_STX) {
112110
state = MAV_states.MAVLINK_PARSE_STATE_GOT_STX;
@@ -115,18 +113,13 @@ public MAVLinkPacket mavlink_parse_char(int c) {
115113
stats.crcError();
116114
} else { // Successfully received the message
117115
stats.newPacket(m);
118-
msg_received = true;
119116
state = MAV_states.MAVLINK_PARSE_STATE_IDLE;
117+
return m;
120118
}
121119

122120
break;
123121

124122
}
125-
if (msg_received) {
126-
return m;
127-
} else {
128-
return null;
129-
}
123+
return null;
130124
}
131-
132125
}

dependencyLibs/Mavlink/src/com/MAVLink/ardupilotmega/CRC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515
public class CRC {
16-
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};
16+
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};
1717
private static final int CRC_INIT_VALUE = 0xffff;
1818
private int crcValue;
1919

0 commit comments

Comments
 (0)