Skip to content

Commit c8994eb

Browse files
committed
Merge pull request #178 from DroidPlanner/fix_mavlink_lib_overflow_underflow_bug
Fix mavlink lib overflow/underflow bug
2 parents 522290c + 46fb5fe commit c8994eb

File tree

242 files changed

+7971
-5485
lines changed

Some content is hidden

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

242 files changed

+7971
-5485
lines changed

ClientLib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
ext {
44
PUBLISH_ARTIFACT_ID = 'dronekit-android'
5-
PUBLISH_VERSION = '2.3.32'
5+
PUBLISH_VERSION = '2.3.33'
66
PROJECT_DESCRIPTION = "Android DroneKit client library."
77
PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android', 'DroneKit']
88
PROJECT_LICENSES = ['Apache-2.0']
@@ -17,7 +17,7 @@ android {
1717
defaultConfig {
1818
minSdkVersion 14
1919
targetSdkVersion 21
20-
versionCode 20332
20+
versionCode 20333
2121
versionName PUBLISH_VERSION
2222
}
2323

ClientLib/libs/Mavlink.jar

-514 Bytes
Binary file not shown.

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/calibration/magnetometer/MagnetometerCalibrationProgress.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99
public class MagnetometerCalibrationProgress implements Parcelable {
1010

11-
private byte compassId;
11+
private int compassId;
1212

13-
private byte completionPercentage;
13+
private int completionPercentage;
1414

1515
/**
1616
* Body frame direction vector for display
@@ -21,7 +21,7 @@ public class MagnetometerCalibrationProgress implements Parcelable {
2121

2222
public MagnetometerCalibrationProgress(){}
2323

24-
public MagnetometerCalibrationProgress(byte compassId, byte percentage, float directionX, float directionY, float
24+
public MagnetometerCalibrationProgress(int compassId, int percentage, float directionX, float directionY, float
2525
directionZ){
2626
this.compassId = compassId;
2727
this.completionPercentage = percentage;
@@ -30,15 +30,15 @@ public MagnetometerCalibrationProgress(byte compassId, byte percentage, float di
3030
this.directionZ = directionZ;
3131
}
3232

33-
public byte getCompassId() {
33+
public int getCompassId() {
3434
return compassId;
3535
}
3636

3737
public void setCompassId(byte compassId) {
3838
this.compassId = compassId;
3939
}
4040

41-
public byte getCompletionPercentage() {
41+
public int getCompletionPercentage() {
4242
return completionPercentage;
4343
}
4444

@@ -77,16 +77,16 @@ public int describeContents() {
7777

7878
@Override
7979
public void writeToParcel(Parcel dest, int flags) {
80-
dest.writeByte(this.compassId);
81-
dest.writeByte(this.completionPercentage);
80+
dest.writeInt(this.compassId);
81+
dest.writeInt(this.completionPercentage);
8282
dest.writeFloat(this.directionX);
8383
dest.writeFloat(this.directionY);
8484
dest.writeFloat(this.directionZ);
8585
}
8686

8787
private MagnetometerCalibrationProgress(Parcel in) {
88-
this.compassId = in.readByte();
89-
this.completionPercentage = in.readByte();
88+
this.compassId = in.readInt();
89+
this.completionPercentage = in.readInt();
9090
this.directionX = in.readFloat();
9191
this.directionY = in.readFloat();
9292
this.directionZ = in.readFloat();

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/calibration/magnetometer/MagnetometerCalibrationResult.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public class MagnetometerCalibrationResult implements Parcelable {
1010

11-
private byte compassId;
11+
private int compassId;
1212

1313
/**
1414
* RMS milligauss residuals
@@ -42,7 +42,7 @@ public class MagnetometerCalibrationResult implements Parcelable {
4242

4343
public MagnetometerCalibrationResult(){}
4444

45-
public MagnetometerCalibrationResult(byte compassId,
45+
public MagnetometerCalibrationResult(int compassId,
4646
boolean calibrationSuccessful, boolean autoSaved, float fitness,
4747
float xOffset, float yOffset, float zOffset,
4848
float xDiag, float yDiag, float zDiag,
@@ -62,7 +62,7 @@ public MagnetometerCalibrationResult(byte compassId,
6262
this.zOffset = zOffset;
6363
}
6464

65-
public byte getCompassId() {
65+
public int getCompassId() {
6666
return compassId;
6767
}
6868

@@ -173,7 +173,7 @@ public int describeContents() {
173173

174174
@Override
175175
public void writeToParcel(Parcel dest, int flags) {
176-
dest.writeByte(this.compassId);
176+
dest.writeInt(this.compassId);
177177
dest.writeFloat(this.fitness);
178178
dest.writeFloat(this.xOffset);
179179
dest.writeFloat(this.yOffset);
@@ -189,7 +189,7 @@ public void writeToParcel(Parcel dest, int flags) {
189189
}
190190

191191
private MagnetometerCalibrationResult(Parcel in) {
192-
this.compassId = in.readByte();
192+
this.compassId = in.readInt();
193193
this.fitness = in.readFloat();
194194
this.xOffset = in.readFloat();
195195
this.yOffset = in.readFloat();

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/calibration/magnetometer/MagnetometerCalibrationStatus.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*/
1414
public class MagnetometerCalibrationStatus implements Parcelable {
1515

16-
private final Map<Byte, MagnetometerCalibrationProgress> calibrationProgressTracker = new HashMap<>();
17-
private final Map<Byte, MagnetometerCalibrationResult> calibrationResultTracker = new HashMap<>();
16+
private final Map<Integer, MagnetometerCalibrationProgress> calibrationProgressTracker = new HashMap<>();
17+
private final Map<Integer, MagnetometerCalibrationResult> calibrationResultTracker = new HashMap<>();
1818

19-
private final List<Byte> compassList = new ArrayList<>();
19+
private final List<Integer> compassList = new ArrayList<>();
2020

2121
private boolean calibrationCancelled;
2222

@@ -25,29 +25,29 @@ public MagnetometerCalibrationStatus() {
2525

2626
public void addCalibrationProgress(MagnetometerCalibrationProgress progress) {
2727
if (progress != null) {
28-
final byte compassId = progress.getCompassId();
28+
final int compassId = progress.getCompassId();
2929
calibrationProgressTracker.put(compassId, progress);
3030
compassList.add(compassId);
3131
}
3232
}
3333

3434
public void addCalibrationResult(MagnetometerCalibrationResult result) {
3535
if (result != null) {
36-
final byte compassId = result.getCompassId();
36+
final int compassId = result.getCompassId();
3737
calibrationResultTracker.put(result.getCompassId(), result);
3838
compassList.add(compassId);
3939
}
4040
}
4141

42-
public List<Byte> getCompassIds() {
42+
public List<Integer> getCompassIds() {
4343
return compassList;
4444
}
4545

46-
public MagnetometerCalibrationProgress getCalibrationProgress(byte compassId) {
46+
public MagnetometerCalibrationProgress getCalibrationProgress(int compassId) {
4747
return calibrationProgressTracker.get(compassId);
4848
}
4949

50-
public MagnetometerCalibrationResult getCalibrationResult(byte compassId) {
50+
public MagnetometerCalibrationResult getCalibrationResult(int compassId) {
5151
return calibrationResultTracker.get(compassId);
5252
}
5353

@@ -60,7 +60,7 @@ public void setCalibrationCancelled(boolean calibrationCancelled) {
6060
}
6161

6262
public boolean isCalibrationComplete(){
63-
for(Byte compassId: compassList){
63+
for(Integer compassId: compassList){
6464
if(!calibrationResultTracker.containsKey(compassId))
6565
return false;
6666
}

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/MissionItemType.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,6 @@ protected Creator<ReturnToLaunch> getMissionItemCreator() {
115115
}
116116
},
117117

118-
DO_LAND_START("Do Land start") {
119-
@Override
120-
public boolean isTypeSupported(Type vehicleType){
121-
return super.isTypeSupported(vehicleType) && vehicleType.getDroneType() == Type.TYPE_PLANE;
122-
}
123-
124-
@Override
125-
public MissionItem getNewItem() {
126-
return new DoLandStart();
127-
}
128-
129-
@Override
130-
protected Creator<DoLandStart> getMissionItemCreator() {
131-
return DoLandStart.CREATOR;
132-
}
133-
},
134-
135118
LAND("Land") {
136119
@Override
137120
public MissionItem getNewItem() {
@@ -226,6 +209,23 @@ public MissionItem getNewItem() {
226209
protected Creator<SetRelay> getMissionItemCreator() {
227210
return SetRelay.CREATOR;
228211
}
212+
},
213+
214+
DO_LAND_START("Do Land start") {
215+
@Override
216+
public boolean isTypeSupported(Type vehicleType){
217+
return super.isTypeSupported(vehicleType) && vehicleType.getDroneType() == Type.TYPE_PLANE;
218+
}
219+
220+
@Override
221+
public MissionItem getNewItem() {
222+
return new DoLandStart();
223+
}
224+
225+
@Override
226+
protected Creator<DoLandStart> getMissionItemCreator() {
227+
return DoLandStart.CREATOR;
228+
}
229229
};
230230

231231
private final static String EXTRA_MISSION_ITEM_TYPE = "extra_mission_item_type";

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/EkfStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public EkfStatus() {
4848
this.flags = new BitSet(FLAGS_BIT_COUNT);
4949
}
5050

51-
public EkfStatus(short flags, float compassVariance, float horizontalPositionVariance, float
51+
public EkfStatus(int flags, float compassVariance, float horizontalPositionVariance, float
5252
terrainAltitudeVariance, float velocityVariance, float verticalPositionVariance) {
5353
this();
5454
this.compassVariance = compassVariance;
@@ -60,7 +60,7 @@ public EkfStatus(short flags, float compassVariance, float horizontalPositionVar
6060
fromShortToBitSet(flags);
6161
}
6262

63-
private void fromShortToBitSet(short flags) {
63+
private void fromShortToBitSet(int flags) {
6464
final EkfFlags[] ekfFlags = EkfFlags.values();
6565
final int ekfFlagsCount = ekfFlags.length;
6666

ClientLib/src/main/java/com/o3dr/services/android/lib/util/version/VersionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public class VersionUtils {
1010

11-
public static final int LIB_VERSION = 20215;
11+
public static final int LIB_VERSION = 20216;
1212

1313
public static int getVersion(Context context){
1414
try {

dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MavLinkCalibration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class MavLinkCalibration {
1313

1414
public static void sendCalibrationAckMessage(int count, Drone drone) {
1515
msg_command_ack msg = new msg_command_ack();
16-
msg.command = (short) count;
16+
msg.command = count;
1717
msg.result = MAV_CMD_ACK.MAV_CMD_ACK_OK;
1818
drone.getMavClient().sendMavPacket(msg.pack());
1919
}
@@ -56,7 +56,7 @@ public static void startMagnetometerCalibration(Drone drone, boolean retryOnFail
5656
msg.target_system = drone.getSysid();
5757
msg.target_component = drone.getCompid();
5858

59-
msg.command = (short) MAV_CMD.MAV_CMD_DO_START_MAG_CAL;
59+
msg.command = MAV_CMD.MAV_CMD_DO_START_MAG_CAL;
6060
msg.param1 = 0;
6161
msg.param2 = retryOnFailure ? 1 : 0;
6262
msg.param3 = saveAutomatically ? 1 : 0;
@@ -77,7 +77,7 @@ public static void cancelMagnetometerCalibration(Drone drone){
7777
msg.target_system = drone.getSysid();
7878
msg.target_component = drone.getCompid();
7979

80-
msg.command = (short) MAV_CMD.MAV_CMD_DO_CANCEL_MAG_CAL;
80+
msg.command = MAV_CMD.MAV_CMD_DO_CANCEL_MAG_CAL;
8181
msg.param1 = 0;
8282
msg.param2 = 0;
8383
msg.param3 = 0;
@@ -98,7 +98,7 @@ public static void acceptMagnetometerCalibration(Drone drone){
9898
msg.target_system = drone.getSysid();
9999
msg.target_component = drone.getCompid();
100100

101-
msg.command = (short) MAV_CMD.MAV_CMD_DO_ACCEPT_MAG_CAL;
101+
msg.command = MAV_CMD.MAV_CMD_DO_ACCEPT_MAG_CAL;
102102
msg.param1 = 0;
103103
msg.param2 = 0;
104104
msg.param3 = 0;

dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MavLinkMsgHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private void processNamedValueInt(msg_named_value_int message){
218218
}
219219

220220
private void checkIfFlying(msg_heartbeat msg_heart) {
221-
final byte systemStatus = msg_heart.system_status;
221+
final short systemStatus = msg_heart.system_status;
222222
final boolean wasFlying = drone.getState().isFlying();
223223

224224
final boolean isFlying = systemStatus == MAV_STATE.MAV_STATE_ACTIVE
@@ -234,7 +234,7 @@ private void processState(msg_heartbeat msg_heart) {
234234
}
235235

236236
private void checkFailsafe(msg_heartbeat msg_heart) {
237-
boolean failsafe2 = msg_heart.system_status == (byte) MAV_STATE.MAV_STATE_CRITICAL
237+
boolean failsafe2 = msg_heart.system_status == MAV_STATE.MAV_STATE_CRITICAL
238238
|| msg_heart.system_status == MAV_STATE.MAV_STATE_EMERGENCY;
239239

240240
if (failsafe2) {
@@ -252,7 +252,7 @@ private void checkControlSensorsHealth(msg_sys_status sysStatus){
252252

253253
private void checkArmState(msg_heartbeat msg_heart) {
254254
drone.getState().setArmed(
255-
(msg_heart.base_mode & (byte) MAV_MODE_FLAG.MAV_MODE_FLAG_SAFETY_ARMED) == (byte) MAV_MODE_FLAG.MAV_MODE_FLAG_SAFETY_ARMED);
255+
(msg_heart.base_mode & MAV_MODE_FLAG.MAV_MODE_FLAG_SAFETY_ARMED) == MAV_MODE_FLAG.MAV_MODE_FLAG_SAFETY_ARMED);
256256
}
257257

258258
private void processStatusText(msg_statustext statusText) {

dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MavLinkStreamRates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ private static void requestMavlinkDataStream(MAVLinkOutputStream mAVClient, byte
2828
msg.target_system = sysid;
2929
msg.target_component = compid;
3030

31-
msg.req_message_rate = (short) rate;
32-
msg.req_stream_id = (byte) stream_id;
31+
msg.req_message_rate = rate;
32+
msg.req_stream_id = (short) stream_id;
3333

3434
if (rate > 0) {
3535
msg.start_stop = 1;

dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MavLinkWaypoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void requestWayPoint(Drone drone, int index) {
2424
msg_mission_request msg = new msg_mission_request();
2525
msg.target_system = drone.getSysid();
2626
msg.target_component = drone.getCompid();
27-
msg.seq = (short) index;
27+
msg.seq = index;
2828
drone.getMavClient().sendMavPacket(msg.pack());
2929
}
3030

@@ -39,7 +39,7 @@ public static void sendWaypointCount(Drone drone, int count) {
3939
msg_mission_count msg = new msg_mission_count();
4040
msg.target_system = drone.getSysid();
4141
msg.target_component = drone.getCompid();
42-
msg.count = (short) count;
42+
msg.count = count;
4343
drone.getMavClient().sendMavPacket(msg.pack());
4444
}
4545

dependencyLibs/Core/src/org/droidplanner/core/MAVLink/WaypointManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ public void onWaypointReached(int wpNumber) {
153153
*
154154
* @param seq number of the updated waypoint
155155
*/
156-
private void onCurrentWaypointUpdate(short seq) {
156+
private void onCurrentWaypointUpdate(int seq) {
157157
}
158158

159159
/**
160160
* number of waypoints to be received, used when reading waypoints
161161
*/
162-
private short waypointCount;
162+
private int waypointCount;
163163
/**
164164
* list of waypoints used when writing or receiving
165165
*/

dependencyLibs/Core/src/org/droidplanner/core/drone/camera/GoProImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void startRecording() {
140140
//Start recording
141141
sendSetRequest(GOPRO_COMMAND.GOPRO_COMMAND_SHUTTER, 1, new SetResponseHandler() {
142142
@Override
143-
public void onResponse(byte commandId, boolean success) {
143+
public void onResponse(short commandId, boolean success) {
144144
if(success != isRecording) {
145145
isRecording = success;
146146
drone.notifyDroneEvent(DroneEventsType.GOPRO_STATUS_UPDATE);
@@ -156,7 +156,7 @@ public void stopRecording() {
156156
//Stop recording
157157
sendSetRequest(GOPRO_COMMAND.GOPRO_COMMAND_SHUTTER, 0, new SetResponseHandler() {
158158
@Override
159-
public void onResponse(byte commandId, boolean success) {
159+
public void onResponse(short commandId, boolean success) {
160160
if(success == isRecording) {
161161
isRecording = !success;
162162
drone.notifyDroneEvent(DroneEventsType.GOPRO_STATUS_UPDATE);
@@ -212,10 +212,10 @@ private void updateRequestTarget() {
212212
*/
213213
private static abstract class GetResponseHandler {
214214

215-
public abstract void onResponse(byte commandId, byte value);
215+
public abstract void onResponse(short commandId, short value);
216216
}
217217

218218
private static abstract class SetResponseHandler {
219-
public abstract void onResponse(byte commandId, boolean success);
219+
public abstract void onResponse(short commandId, boolean success);
220220
}
221221
}

0 commit comments

Comments
 (0)