Skip to content

Commit

Permalink
Merge pull request #57 from 3drobotics/release-1.5.1
Browse files Browse the repository at this point in the history
Release 1.5.1
  • Loading branch information
m4gr3d committed Feb 11, 2016
2 parents a4e5f4e + 3584ed6 commit 5de9286
Show file tree
Hide file tree
Showing 147 changed files with 4,697 additions and 2,240 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ crashlytics.properties

# Vagrant
.vagrant/

# Fabric (crashlytics)
fabric.properties
22 changes: 15 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ android:
components:
- platform-tools
- tools

# The BuildTools version used by your project
- build-tools-23.0.2

# The SDK version used to compile your project
- android-23

# Additional components
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- extra-android-support

licenses:
- 'android-sdk-license-.+'

before_script:
- echo yes | android update sdk -u -a -t tools
- echo yes | android update sdk -u -a -t build-tools-22.0.1
- echo yes | android update sdk -u -a -t android-22
- echo yes | android update sdk -u -a -t extra-google-m2repository
- echo yes | android update sdk -u -a -t extra-android-m2repository
- echo yes | android update sdk -u -a -t extra-android-support,extra-google-google_play_services
- export GRADLE_OPTS="-XX:MaxPermSize=2048m -Xmx1536m"

script: ./gradlew clean build
script: ./gradlew cleanJar clean testDevDebug assembleDevDebug -PdisablePreDex

after_success:
- chmod a+x .utility/push-docs-to-gh-pages.sh
- .utility/push-docs-to-gh-pages.sh
Expand Down
22 changes: 11 additions & 11 deletions ClientLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
VERSION_MAJOR = 2
VERSION_MINOR = 7
VERSION_MINOR = 8
VERSION_PATCH = 0
VERSION_SUFFIX = "release"

Expand All @@ -15,12 +15,12 @@ ext {
}

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
compileSdkVersion android_build_sdk_version
buildToolsVersion android_build_tools_version

defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
minSdkVersion android_build_min_sdk_version
targetSdkVersion android_build_target_sdk_version
versionCode PUBLISH_VERSION_CODE
versionName PUBLISH_VERSION
}
Expand Down Expand Up @@ -55,13 +55,13 @@ android {
}

dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.android.gms:play-services-base:7.3.0'
compile "com.android.support:support-v4:${support_lib_version}"
compile "com.google.android.gms:play-services-base:${play_services_version}"

compile project(':dependencyLibs:Mavlink')
compile files('libs/Mavlink.jar')
debugCompile project(':Mavlink')
releaseCompile files('libs/Mavlink.jar')
}

assemble.dependsOn ':dependencyLibs:Mavlink:jar'
assemble.dependsOn ':Mavlink:jar'

apply from: "${rootDir}/release_android_library.gradle"
apply from: "../release_android_library.gradle"
129 changes: 85 additions & 44 deletions ClientLib/src/main/java/com/o3dr/android/client/Drone.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import com.o3dr.android.client.apis.MissionApi;
import com.o3dr.android.client.apis.VehicleApi;
import com.o3dr.android.client.interfaces.DroneListener;
import com.o3dr.android.client.utils.TxPowerComplianceCountries;
import com.o3dr.services.android.lib.coordinate.LatLong;
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
import com.o3dr.services.android.lib.drone.attribute.AttributeType;
import com.o3dr.services.android.lib.drone.calibration.magnetometer.MagnetometerCalibrationStatus;
import com.o3dr.services.android.lib.drone.companion.solo.SoloAttributes;
import com.o3dr.services.android.lib.drone.companion.solo.SoloEventExtras;
import com.o3dr.services.android.lib.drone.companion.solo.SoloEvents;
import com.o3dr.services.android.lib.drone.connection.ConnectionParameter;
import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
import com.o3dr.services.android.lib.drone.mission.Mission;
Expand Down Expand Up @@ -132,17 +135,19 @@ void init(ControlTower controlTower, Handler handler) {
this.droneObserver = new DroneObserver(this);
}

Context getContext(){
Context getContext() {
return this.context;
}

synchronized void start() {
if (!serviceMgr.isTowerConnected())
if (!serviceMgr.isTowerConnected()) {
throw new IllegalStateException("Service manager must be connected.");
}

IDroneApi droneApi = droneApiRef.get();
if (isStarted(droneApi))
if (isStarted(droneApi)) {
return;
}

try {
droneApi = serviceMgr.get3drServices().registerDroneApi(this.apiListener, serviceMgr.getApplicationId());
Expand All @@ -151,8 +156,9 @@ synchronized void start() {
throw new IllegalStateException("Unable to retrieve a valid drone handle.");
}

if (asyncScheduler == null || asyncScheduler.isShutdown())
if (asyncScheduler == null || asyncScheduler.isShutdown()) {
asyncScheduler = Executors.newFixedThreadPool(1);
}

addAttributesObserver(droneApi, this.droneObserver);
resetFlightTimer();
Expand Down Expand Up @@ -185,16 +191,17 @@ synchronized void destroy() {
private void checkForGroundCollision() {
Speed speed = getAttribute(AttributeType.SPEED);
Altitude altitude = getAttribute(AttributeType.ALTITUDE);
if (speed == null || altitude == null)
if (speed == null || altitude == null) {
return;
}

double verticalSpeed = speed.getVerticalSpeed();
double altitudeValue = altitude.getAltitude();

boolean isCollisionImminent = altitudeValue
+ (verticalSpeed * COLLISION_SECONDS_BEFORE_COLLISION) < 0
&& verticalSpeed < COLLISION_DANGEROUS_SPEED_METERS_PER_SECOND
&& altitudeValue > COLLISION_SAFE_ALTITUDE_METERS;
+ (verticalSpeed * COLLISION_SECONDS_BEFORE_COLLISION) < 0
&& verticalSpeed < COLLISION_DANGEROUS_SPEED_METERS_PER_SECOND
&& altitudeValue > COLLISION_SAFE_ALTITUDE_METERS;

Bundle extrasBundle = new Bundle(1);
extrasBundle.putBoolean(EXTRA_IS_GROUND_COLLISION_IMMINENT, isCollisionImminent);
Expand All @@ -214,8 +221,9 @@ public double getSpeedParameter() {
Parameters params = getAttribute(AttributeType.PARAMETERS);
if (params != null) {
Parameter speedParam = params.getParameter("WPNAV_SPEED");
if (speedParam != null)
if (speedParam != null) {
return speedParam.getValue();
}
}

return 0;
Expand All @@ -227,8 +235,9 @@ public double getSpeedParameter() {
* @param action Runnabl that will be executed.
*/
public void post(Runnable action) {
if (handler == null || action == null)
if (handler == null || action == null) {
return;
}

handler.post(action);
}
Expand Down Expand Up @@ -262,8 +271,9 @@ public long getFlightTime() {

public <T extends Parcelable> T getAttribute(String type) {
final IDroneApi droneApi = droneApiRef.get();
if (!isStarted(droneApi) || type == null)
if (!isStarted(droneApi) || type == null) {
return this.getAttributeDefaultValue(type);
}

T attribute = null;
Bundle carrier = null;
Expand All @@ -277,7 +287,7 @@ public <T extends Parcelable> T getAttribute(String type) {
try {
carrier.setClassLoader(contextClassLoader);
attribute = carrier.getParcelable(type);
}catch(Exception e){
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
Expand All @@ -287,8 +297,9 @@ public <T extends Parcelable> T getAttribute(String type) {

public <T extends Parcelable> void getAttributeAsync(final String attributeType,
final OnAttributeRetrievedCallback<T> callback) {
if (callback == null)
if (callback == null) {
throw new IllegalArgumentException("Callback must be non-null.");
}

final IDroneApi droneApi = droneApiRef.get();
if (!isStarted(droneApi)) {
Expand All @@ -309,19 +320,21 @@ public void run() {
handler.post(new Runnable() {
@Override
public void run() {
if (attribute == null)
if (attribute == null) {
callback.onRetrievalFailed();
else
} else {
callback.onRetrievalSucceed(attribute);
}
}
});
}
});
}

private <T extends Parcelable> T getAttributeDefaultValue(String attributeType) {
if (attributeType == null)
if (attributeType == null) {
return null;
}

switch (attributeType) {
case AttributeType.ALTITUDE:
Expand Down Expand Up @@ -475,7 +488,7 @@ private boolean isStarted(IDroneApi droneApi) {
return droneApi != null && droneApi.asBinder().pingBinder();
}

public boolean isStarted(){
public boolean isStarted() {
return isStarted(droneApiRef.get());
}

Expand All @@ -491,11 +504,13 @@ public ConnectionParameter getConnectionParameter() {

public <T extends MissionItem> void buildMissionItemsAsync(final MissionItem.ComplexItem<T>[] missionItems,
final OnMissionItemsBuiltCallback<T> callback) {
if (callback == null)
if (callback == null) {
throw new IllegalArgumentException("Callback must be non-null.");
}

if (missionItems == null || missionItems.length == 0)
if (missionItems == null || missionItems.length == 0) {
return;
}

asyncScheduler.execute(new Runnable() {
@Override
Expand All @@ -514,11 +529,13 @@ public void run() {
}

public void registerDroneListener(DroneListener listener) {
if (listener == null)
if (listener == null) {
return;
}

if (!droneListeners.contains(listener))
if (!droneListeners.contains(listener)) {
droneListeners.add(listener);
}
}

private void addAttributesObserver(IDroneApi droneApi, IObserver observer) {
Expand Down Expand Up @@ -554,8 +571,9 @@ public void removeMavlinkObserver(MavlinkObserver observer) {
}

public void unregisterDroneListener(DroneListener listener) {
if (listener == null)
if (listener == null) {
return;
}

droneListeners.remove(listener);
}
Expand Down Expand Up @@ -689,13 +707,14 @@ public void loadWaypoints() {
MissionApi.getApi(this).loadWaypoints();
}

public Handler getHandler(){
public Handler getHandler() {
return handler;
}

void notifyDroneConnectionFailed(final ConnectionResult result) {
if (droneListeners.isEmpty())
if (droneListeners.isEmpty()) {
return;
}

handler.post(new Runnable() {
@Override
Expand All @@ -708,38 +727,59 @@ public void run() {

void notifyAttributeUpdated(final String attributeEvent, final Bundle extras) {
//Update the bundle classloader
if (extras != null)
if (extras != null) {
extras.setClassLoader(contextClassLoader);
}

if (AttributeEvent.STATE_UPDATED.equals(attributeEvent)) {
getAttributeAsync(AttributeType.STATE, new OnAttributeRetrievedCallback<State>() {
@Override
public void onRetrievalSucceed(State state) {
if (state.isFlying())
resetFlightTimer();
else
stopTimer();
}
switch (attributeEvent) {
case AttributeEvent.STATE_UPDATED:
getAttributeAsync(AttributeType.STATE, new OnAttributeRetrievedCallback<State>() {
@Override
public void onRetrievalSucceed(State state) {
if (state.isFlying()) {
resetFlightTimer();
} else {
stopTimer();
}
}

@Override
public void onRetrievalFailed() {
stopTimer();
}
});
} else if (AttributeEvent.SPEED_UPDATED.equals(attributeEvent)) {
checkForGroundCollision();
@Override
public void onRetrievalFailed() {
stopTimer();
}
});
break;

case AttributeEvent.SPEED_UPDATED:
checkForGroundCollision();
break;

//TODO remove this when deprecated methods are deleted in 3.0
// This ensures that the api is backwards compatible
case SoloEvents.SOLO_TX_POWER_COMPLIANCE_COUNTRY_UPDATED:
String compliantCountry = extras.getString(SoloEventExtras.EXTRA_SOLO_TX_POWER_COMPLIANT_COUNTRY);
final Bundle eventInfo = new Bundle(1);
boolean isEUCompliant = !TxPowerComplianceCountries.getDefaultCountry().name().equals(compliantCountry);
eventInfo.putBoolean(SoloEventExtras.EXTRA_SOLO_EU_TX_POWER_COMPLIANT, isEUCompliant);
sendEventToListeners(SoloEvents.SOLO_EU_TX_POWER_COMPLIANCE_UPDATED, eventInfo);
break;
}

if (droneListeners.isEmpty())
sendEventToListeners(attributeEvent, extras);
}

private void sendEventToListeners(final String attributeEvent, final Bundle extras) {
if (droneListeners.isEmpty()) {
return;
}

handler.post(new Runnable() {
@Override
public void run() {
for (DroneListener listener : droneListeners) {
try {
listener.onDroneEvent(attributeEvent, extras);
}catch(Exception e){
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
Expand All @@ -748,8 +788,9 @@ public void run() {
}

void notifyDroneServiceInterrupted(final String errorMsg) {
if (droneListeners.isEmpty())
if (droneListeners.isEmpty()) {
return;
}

handler.post(new Runnable() {
@Override
Expand Down
Loading

0 comments on commit 5de9286

Please sign in to comment.