diff --git a/.travis.yml b/.travis.yml index 2f79011d3a..d47e98f799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ android: before_script: - export GRADLE_OPTS="-XX:MaxPermSize=2048m -Xmx1536m" -script: ./gradlew cleanJar clean testDevDebug assembleDevDebug -PdisablePreDex +script: ./gradlew cleanJar clean testDebug assembleDebug -PdisablePreDex after_success: - chmod a+x .utility/push-docs-to-gh-pages.sh diff --git a/ServiceApp/art/ic_launcher.svg b/ClientLib/art/ic_launcher.svg similarity index 100% rename from ServiceApp/art/ic_launcher.svg rename to ClientLib/art/ic_launcher.svg diff --git a/ServiceApp/art/ic_stat_notify.svg b/ClientLib/art/ic_stat_notify.svg similarity index 100% rename from ServiceApp/art/ic_stat_notify.svg rename to ClientLib/art/ic_stat_notify.svg diff --git a/ClientLib/build.gradle b/ClientLib/build.gradle index cf8f19aeeb..6144eea16c 100644 --- a/ClientLib/build.gradle +++ b/ClientLib/build.gradle @@ -1,8 +1,9 @@ apply plugin: 'com.android.library' +apply plugin: 'com.getkeepsafe.dexcount' ext { - VERSION_MAJOR = 2 - VERSION_MINOR = 9 + VERSION_MAJOR = 3 + VERSION_MINOR = 0 VERSION_PATCH = 1 VERSION_SUFFIX = "release" @@ -10,19 +11,40 @@ ext { PUBLISH_VERSION = generateVersionName("", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_SUFFIX) PUBLISH_VERSION_CODE = computeVersionCode(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) PROJECT_DESCRIPTION = "Android DroneKit client library." - PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android', 'DroneKit'] - PROJECT_LICENSES = ['Apache-2.0'] + PROJECT_LABELS = ['DroneCode', '3DR', 'Tower', 'DroneAPI', 'Android', 'DroneKit', '3DR Services'] + PROJECT_LICENSE = 'The Apache Software License, Version 2.0' + PROJECT_LICENSE_URL = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + PROJECT_LICENSE_DISTRIBUTION = 'repo' } +//Log levels values +def logLevelVerbose = 2; +def logLevelDebug = 3; +def logLevelInfo = 4; +def logLevelWarn = 5; +def logLevelError = 6; +def logLevelAssert = 7; + android { compileSdkVersion android_build_sdk_version buildToolsVersion android_build_tools_version + dexOptions { + javaMaxHeapSize "4g" + } + defaultConfig { minSdkVersion android_build_min_sdk_version targetSdkVersion android_build_target_sdk_version + versionCode PUBLISH_VERSION_CODE versionName PUBLISH_VERSION + + //Build config fields + buildConfigField "boolean", "SITL_DEBUG", "false" + buildConfigField "String", "SOLO_LINK_IP", getSoloLinkIp() + buildConfigField "boolean", "WRITE_LOG_FILE", "false" + buildConfigField "int", "LOG_FILE_LEVEL", "$logLevelDebug" } sourceSets { @@ -52,16 +74,67 @@ android { } } } + + buildTypes { + debug { + debuggable true + buildConfigField "boolean", "WRITE_LOG_FILE", "true" + } + + sitl { + debuggable true + buildConfigField "String", "SOLO_LINK_IP", getLocalIp() + buildConfigField "boolean", "SITL_DEBUG", "true" + } + + release { + } + } + + testOptions { + unitTests.returnDefaultValues = true + } } dependencies { - compile "com.android.support:support-v4:${support_lib_version}" + compile 'com.jakewharton.timber:timber:3.1.0' + compile "com.google.android.gms:play-services-base:${play_services_version}" + compile "com.google.android.gms:play-services-location:${play_services_version}" + + //Java semver library + compile 'com.github.zafarkhaja:java-semver:0.9.0' + + compile 'com.jcraft:jsch:0.1.51' + + //MP4 generation library + compile 'com.googlecode.mp4parser:isoparser:1.1.7' + + compile 'org.droidplanner.android:usb-serial-android:0.1.0' debugCompile project(':Mavlink') - releaseCompile files('libs/Mavlink.jar') +// sitlCompile project(':Mavlink') + + compile files('libs/Mavlink.jar') + compile files('libs/d2xx.jar') + + androidTestCompile 'junit:junit:4.12' + androidTestCompile "org.robolectric:robolectric:3.0" +} + +def getSoloLinkIp() { + return '\"10.1.1.10\"' +} + +def getLocalIp() { + try { + return '\"' + InetAddress.getLocalHost().getCanonicalHostName() + '\"' + }catch(Exception e){ + return '\"\"' + } } +evaluationDependsOn ':Mavlink' assemble.dependsOn ':Mavlink:jar' -apply from: "../release_android_library.gradle" \ No newline at end of file +apply from: "$projectDir/maven-push.gradle" \ No newline at end of file diff --git a/ServiceApp/libs/d2xx.jar b/ClientLib/libs/d2xx.jar similarity index 100% rename from ServiceApp/libs/d2xx.jar rename to ClientLib/libs/d2xx.jar diff --git a/ClientLib/maven-push.gradle b/ClientLib/maven-push.gradle new file mode 100644 index 0000000000..cdacd69277 --- /dev/null +++ b/ClientLib/maven-push.gradle @@ -0,0 +1,128 @@ +apply plugin: 'maven' +apply plugin: 'signing' + +def projectGroupId = 'com.o3dr.android' +def projectArtifactId = project.PUBLISH_ARTIFACT_ID +def projectVersion = project.PUBLISH_VERSION +def projectDescription = project.PROJECT_DESCRIPTION +def projectLabels = project.PROJECT_LABELS +def projectLicense = project.PROJECT_LICENSE +def projectLicenseUrl = project.PROJECT_LICENSE_URL +def projectLicenseDistribution = project.PROJECT_LICENSE_DISTRIBUTION + +def getMavenOrg(){ + return hasProperty('COM_O3DR_MAVEN_ORG') ? COM_O3DR_MAVEN_ORG : '' +} + +def getMavenPublishUrl(String artifactId){ + def prefix = hasProperty('COM_O3DR_MAVEN_PUBLISH_URL_PREFIX') ? COM_O3DR_MAVEN_PUBLISH_URL_PREFIX : null + if(prefix == null) + return null + + return "$prefix/$artifactId/;publish=0;override=1" +} + +def getMavenPomPackaging(){ + return hasProperty('COM_O3DR_MAVEN_POM_PACKAGING') ? COM_O3DR_MAVEN_POM_PACKAGING : 'aar' +} + +def getDeveloperId(){ + return hasProperty('DEVELOPER_ID') ? DEVELOPER_ID : '' +} + +def getDeveloperName(){ + return hasProperty('DEVELOPER_NAME') ? DEVELOPER_NAME : '' +} + +afterEvaluate { project -> + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + pom.groupId = projectGroupId + pom.artifactId = projectArtifactId + pom.version = projectVersion + + repository(url: getMavenPublishUrl(projectArtifactId)) { + authentication(userName: getMavenUsername(), password: getMavenApiKey()) + } + + pom.project { + name projectArtifactId + packaging getMavenPomPackaging() + description projectDescription + + url 'https://github.com/dronekit/dronekit-android' + scm { + url 'https://github.com/dronekit/dronekit-android' + connection 'scm:git:git@github.com:dronekit/dronekit-android.git' + developerConnection 'scm:git:git@github.com:dronekit/dronekit-android.git' + } + + licenses { + license { + name projectLicense + url projectLicenseUrl + distribution projectLicenseDistribution + } + } + + developers { + developer { + id getDeveloperId() + name getDeveloperName() + } + } + } + } + } + } + + signing { + required { gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives + } + + task androidJavadocs(type: Javadoc) { + failOnError false + + //Add the project java source directory. + def files = [android.sourceSets.main.java.srcDirs] + + //Add the java source directories for the project's dependencies + configurations.compile.dependencies.each { + if (it instanceof ProjectDependency) { + def dependency = it as ProjectDependency + def depProj = dependency.getDependencyProject() + def projName = depProj.getName() + if(projName != "Mavlink") { + files += depProj.android.sourceSets.main.java.srcDirs + } + } + } + + source = files + title = projectDescription + exclude '**/*.aidl', 'org/droidplanner/services/android/impl/**' + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.links("http://docs.oracle.com/javase/7/docs/api/") + options.links("https://developer.android.com/reference/packages.html") + } + + task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs){ + classifier = 'javadoc' + from androidJavadocs.destinationDir + } + + task androidSourcesJar(type: Jar){ + classifier = 'sources' + from android.sourceSets.main.java.srcDirs + exclude 'org/droidplanner/services/android/impl/**' + } + + artifacts { + archives androidSourcesJar + archives androidJavadocsJar + } +} \ No newline at end of file diff --git a/ServiceApp/test/java/com/o3dr/android/client/apis/ControlApiTest.java b/ClientLib/src/androidTest/java/com/o3dr/android/client/apis/ControlApiTest.java similarity index 96% rename from ServiceApp/test/java/com/o3dr/android/client/apis/ControlApiTest.java rename to ClientLib/src/androidTest/java/com/o3dr/android/client/apis/ControlApiTest.java index c2cb9ada0f..5b0203af76 100644 --- a/ServiceApp/test/java/com/o3dr/android/client/apis/ControlApiTest.java +++ b/ClientLib/src/androidTest/java/com/o3dr/android/client/apis/ControlApiTest.java @@ -7,8 +7,9 @@ import com.o3dr.services.android.lib.model.AbstractCommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.mock.MockDrone; -import org.junit.Assert; +import junit.framework.Assert; + +import org.droidplanner.services.android.impl.mock.MockDrone; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricGradleTestRunner; @@ -24,7 +25,7 @@ * Created by Fredia Huya-Kouadio on 10/23/15. */ @RunWith(RobolectricGradleTestRunner.class) -@Config(constants = org.droidplanner.services.android.BuildConfig.class, sdk = 18) +@Config(constants = com.o3dr.android.client.BuildConfig.class, sdk = 18) public class ControlApiTest { private static final SparseArray expectedVelocitiesPerAttitude = new SparseArray<>(); diff --git a/ServiceApp/test/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/TLVMessageParserTest.java b/ClientLib/src/androidTest/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/TLVMessageParserTest.java similarity index 100% rename from ServiceApp/test/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/TLVMessageParserTest.java rename to ClientLib/src/androidTest/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/TLVMessageParserTest.java diff --git a/ServiceApp/test/java/com/o3dr/services/android/lib/util/MathUtilsTest.java b/ClientLib/src/androidTest/java/com/o3dr/services/android/lib/util/MathUtilsTest.java similarity index 100% rename from ServiceApp/test/java/com/o3dr/services/android/lib/util/MathUtilsTest.java rename to ClientLib/src/androidTest/java/com/o3dr/services/android/lib/util/MathUtilsTest.java diff --git a/ServiceApp/test/java/org/droidplanner/services/android/BasicTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/BasicTest.java similarity index 80% rename from ServiceApp/test/java/org/droidplanner/services/android/BasicTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/BasicTest.java index cc6a50e20a..313f94a605 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/BasicTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/BasicTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android; +package org.droidplanner.services.android.impl; import android.content.Context; import android.os.Bundle; @@ -8,25 +8,28 @@ import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.common.msg_command_long; import com.MAVLink.enums.MAV_CMD; +import com.o3dr.android.client.BuildConfig; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduCopter; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.mock.MockMAVLinkClient; -import org.droidplanner.services.android.utils.AndroidApWarningParser; import org.junit.Assert; import org.junit.Before; + +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduCopter; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.mock.MockMAVLinkClient; +import org.droidplanner.services.android.impl.utils.AndroidApWarningParser; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; + /** * Created by djmedina on 3/5/15. * This is a simple test case. diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilotTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilotTest.java similarity index 96% rename from ServiceApp/test/java/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilotTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilotTest.java index aa26a0f7d4..2a7daa2fa0 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilotTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilotTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm; import com.github.zafarkhaja.semver.Version; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord2DTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord2DTest.java similarity index 81% rename from ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord2DTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord2DTest.java index 392967e3ab..74bde32af0 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord2DTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord2DTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.coordinates; +package org.droidplanner.services.android.impl.core.helpers.coordinates; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord3DTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord3DTest.java similarity index 94% rename from ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord3DTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord3DTest.java index d8c25059ac..c535556833 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/Coord3DTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/Coord3DTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.coordinates; +package org.droidplanner.services.android.impl.core.helpers.coordinates; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/CoordBoundsTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBoundsTest.java similarity index 94% rename from ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/CoordBoundsTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBoundsTest.java index 5cde695c93..ec87117274 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/coordinates/CoordBoundsTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBoundsTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.coordinates; +package org.droidplanner.services.android.impl.core.helpers.coordinates; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/geoTools/GeoToolsTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoToolsTest.java similarity index 93% rename from ServiceApp/test/java/org/droidplanner/services/android/core/helpers/geoTools/GeoToolsTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoToolsTest.java index 41cd080e82..9e45ebcf2b 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/geoTools/GeoToolsTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoToolsTest.java @@ -1,11 +1,12 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import junit.framework.TestCase; -import org.droidplanner.services.android.core.polygon.Polygon; +import org.droidplanner.services.android.impl.core.polygon.Polygon; + public class GeoToolsTest extends TestCase { diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/units/AreaTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/units/AreaTest.java similarity index 92% rename from ServiceApp/test/java/org/droidplanner/services/android/core/helpers/units/AreaTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/units/AreaTest.java index 5476372415..685d4f711f 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/helpers/units/AreaTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/helpers/units/AreaTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.units; +package org.droidplanner.services.android.impl.core.helpers.units; import junit.framework.TestCase; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeCameraTriggerImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeCameraTriggerImplTest.java similarity index 59% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeCameraTriggerImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeCameraTriggerImplTest.java index d354c433b3..6900de0e27 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeCameraTriggerImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeCameraTriggerImplTest.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.commands.CameraTriggerImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.commands.CameraTriggerImpl; import java.util.List; public class ChangeCameraTriggerImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - CameraTriggerImpl item = new CameraTriggerImpl(mission, (12.0)); + MissionImpl missionImpl = new MissionImpl(null); + CameraTriggerImpl item = new CameraTriggerImpl(missionImpl, (12.0)); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeSpeedImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeSpeedImplTest.java similarity index 67% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeSpeedImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeSpeedImplTest.java index b5b6fbe13c..48958226f4 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ChangeSpeedImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ChangeSpeedImplTest.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.commands.ChangeSpeedImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ChangeSpeedImpl; import java.util.List; public class ChangeSpeedImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - ChangeSpeedImpl item = new ChangeSpeedImpl(mission, 12.0); + MissionImpl missionImpl = new MissionImpl(null); + ChangeSpeedImpl item = new ChangeSpeedImpl(missionImpl, 12.0); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ConditionYawImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ConditionYawImplTest.java similarity index 63% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ConditionYawImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ConditionYawImplTest.java index aa28ddc4ad..5dfba2860b 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/ConditionYawImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/ConditionYawImplTest.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.commands.ConditionYawImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ConditionYawImpl; import java.util.List; public class ConditionYawImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - ConditionYawImpl item = new ConditionYawImpl(mission, 12, false); + MissionImpl missionImpl = new MissionImpl(null); + ConditionYawImpl item = new ConditionYawImpl(missionImpl, 12, false); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/LandImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImplTest.java similarity index 71% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/LandImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImplTest.java index 8b062c8b4e..e93df02557 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/LandImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImplTest.java @@ -1,19 +1,19 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; import java.util.List; public class LandImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - LandImpl item = new LandImpl(mission); + MissionImpl missionImpl = new MissionImpl(null); + LandImpl item = new LandImpl(missionImpl); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItemTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItemTest.java similarity index 66% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItemTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItemTest.java index dc2c54593e..7ebed0749d 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItemTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItemTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_FRAME; @@ -6,13 +6,13 @@ import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; public class SpatialCoordItemTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - WaypointImpl item = new WaypointImpl(mission, new LatLongAlt(0.1, 1, (2))); + MissionImpl missionImpl = new MissionImpl(null); + WaypointImpl item = new WaypointImpl(missionImpl, new LatLongAlt(0.1, 1, (2))); msg_mission_item mavMsg = item.packMissionItem().get(0); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/TakeoffImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/TakeoffImplTest.java similarity index 65% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/TakeoffImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/TakeoffImplTest.java index 31c8e126c2..bc1a773c5f 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/TakeoffImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/TakeoffImplTest.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.commands.TakeoffImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.commands.TakeoffImpl; import java.util.List; public class TakeoffImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - TakeoffImpl item = new TakeoffImpl(mission, (50.0)); + MissionImpl missionImpl = new MissionImpl(null); + TakeoffImpl item = new TakeoffImpl(missionImpl, (50.0)); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/WaypointImplTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImplTest.java similarity index 70% rename from ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/WaypointImplTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImplTest.java index 12c3e955be..23665b1e05 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/mission/waypoints/WaypointImplTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImplTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; @@ -6,15 +6,15 @@ import junit.framework.TestCase; -import org.droidplanner.services.android.core.mission.Mission; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; import java.util.List; public class WaypointImplTest extends TestCase { public void testPackMissionItem() { - Mission mission = new Mission(null); - WaypointImpl item = new WaypointImpl(mission, new LatLongAlt(0, 1, (2))); + MissionImpl missionImpl = new MissionImpl(null); + WaypointImpl item = new WaypointImpl(missionImpl, new LatLongAlt(0, 1, (2))); List listOfMsg = item.packMissionItem(); assertEquals(1, listOfMsg.size()); diff --git a/ServiceApp/test/java/org/droidplanner/services/android/core/survey/FootprintTest.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/survey/FootprintTest.java similarity index 97% rename from ServiceApp/test/java/org/droidplanner/services/android/core/survey/FootprintTest.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/survey/FootprintTest.java index a5621dbb3a..2e0327bb55 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/core/survey/FootprintTest.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/core/survey/FootprintTest.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.survey; +package org.droidplanner.services.android.impl.core.survey; import com.MAVLink.ardupilotmega.msg_camera_feedback; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/mock/MockDrone.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockDrone.java similarity index 86% rename from ServiceApp/test/java/org/droidplanner/services/android/mock/MockDrone.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockDrone.java index 7e03e2dd93..55fe2d5c33 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/mock/MockDrone.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockDrone.java @@ -1,11 +1,9 @@ -package org.droidplanner.services.android.mock; +package org.droidplanner.services.android.impl.mock; import android.content.Context; import android.os.Parcelable; import com.o3dr.android.client.Drone; -import com.o3dr.services.android.lib.drone.attribute.AttributeType; -import com.o3dr.services.android.lib.drone.property.Attitude; import com.o3dr.services.android.lib.drone.property.DroneAttribute; import com.o3dr.services.android.lib.model.action.Action; diff --git a/ServiceApp/test/java/org/droidplanner/services/android/mock/MockMAVLinkClient.java b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockMAVLinkClient.java similarity index 78% rename from ServiceApp/test/java/org/droidplanner/services/android/mock/MockMAVLinkClient.java rename to ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockMAVLinkClient.java index 8373e3182b..21a36c1c94 100644 --- a/ServiceApp/test/java/org/droidplanner/services/android/mock/MockMAVLinkClient.java +++ b/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/mock/MockMAVLinkClient.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.mock; +package org.droidplanner.services.android.impl.mock; import android.content.Context; @@ -7,8 +7,9 @@ import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.communication.service.MAVLinkClient; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.communication.service.MAVLinkClient; + /** * Created by Fredia Huya-Kouadio on 12/17/15. diff --git a/ClientLib/src/main/AndroidManifest.xml b/ClientLib/src/main/AndroidManifest.xml index df1ff90a7e..bc14e62699 100644 --- a/ClientLib/src/main/AndroidManifest.xml +++ b/ClientLib/src/main/AndroidManifest.xml @@ -3,13 +3,67 @@ + + + + + + + + + + + + + + + + + + + + + + + android:excludeFromRecents="true"> + + + + + + + + + + + + + + + + + diff --git a/ServiceApp/assets/CameraInfo/Canon A2300 A2400.xml b/ClientLib/src/main/assets/CameraInfo/Canon A2300 A2400.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon A2300 A2400.xml rename to ClientLib/src/main/assets/CameraInfo/Canon A2300 A2400.xml diff --git a/ServiceApp/assets/CameraInfo/Canon ELPH 110 320 HS.xml b/ClientLib/src/main/assets/CameraInfo/Canon ELPH 110 320 HS.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon ELPH 110 320 HS.xml rename to ClientLib/src/main/assets/CameraInfo/Canon ELPH 110 320 HS.xml diff --git a/ServiceApp/assets/CameraInfo/Canon ELPH 115 130 IS.xml b/ClientLib/src/main/assets/CameraInfo/Canon ELPH 115 130 IS.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon ELPH 115 130 IS.xml rename to ClientLib/src/main/assets/CameraInfo/Canon ELPH 115 130 IS.xml diff --git a/ServiceApp/assets/CameraInfo/Canon ELPH 330 HS.xml b/ClientLib/src/main/assets/CameraInfo/Canon ELPH 330 HS.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon ELPH 330 HS.xml rename to ClientLib/src/main/assets/CameraInfo/Canon ELPH 330 HS.xml diff --git a/ServiceApp/assets/CameraInfo/Canon ELPH 520 HS.xml b/ClientLib/src/main/assets/CameraInfo/Canon ELPH 520 HS.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon ELPH 520 HS.xml rename to ClientLib/src/main/assets/CameraInfo/Canon ELPH 520 HS.xml diff --git a/ServiceApp/assets/CameraInfo/Canon S100.xml b/ClientLib/src/main/assets/CameraInfo/Canon S100.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon S100.xml rename to ClientLib/src/main/assets/CameraInfo/Canon S100.xml diff --git a/ServiceApp/assets/CameraInfo/Canon S110 S120.xml b/ClientLib/src/main/assets/CameraInfo/Canon S110 S120.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon S110 S120.xml rename to ClientLib/src/main/assets/CameraInfo/Canon S110 S120.xml diff --git a/ServiceApp/assets/CameraInfo/Canon SX260.xml b/ClientLib/src/main/assets/CameraInfo/Canon SX260.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Canon SX260.xml rename to ClientLib/src/main/assets/CameraInfo/Canon SX260.xml diff --git a/ServiceApp/assets/CameraInfo/GoPro Hero 3+ Black.xml b/ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Black.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro Hero 3+ Black.xml rename to ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Black.xml diff --git a/ServiceApp/assets/CameraInfo/GoPro Hero 3+ Silver (Medium).xml b/ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Silver (Medium).xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro Hero 3+ Silver (Medium).xml rename to ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Silver (Medium).xml diff --git a/ServiceApp/assets/CameraInfo/GoPro Hero 3+ Silver (Wide).xml b/ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Silver (Wide).xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro Hero 3+ Silver (Wide).xml rename to ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ Silver (Wide).xml diff --git a/ServiceApp/assets/CameraInfo/GoPro Hero 3+ White.xml b/ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ White.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro Hero 3+ White.xml rename to ClientLib/src/main/assets/CameraInfo/GoPro Hero 3+ White.xml diff --git a/ServiceApp/assets/CameraInfo/GoPro Hero 4 Black.xml b/ClientLib/src/main/assets/CameraInfo/GoPro Hero 4 Black.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro Hero 4 Black.xml rename to ClientLib/src/main/assets/CameraInfo/GoPro Hero 4 Black.xml diff --git a/ServiceApp/assets/CameraInfo/GoPro_Hero_3_Silver.xml b/ClientLib/src/main/assets/CameraInfo/GoPro_Hero_3_Silver.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/GoPro_Hero_3_Silver.xml rename to ClientLib/src/main/assets/CameraInfo/GoPro_Hero_3_Silver.xml diff --git a/ServiceApp/assets/CameraInfo/Mobius_A_Lens.xml b/ClientLib/src/main/assets/CameraInfo/Mobius_A_Lens.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Mobius_A_Lens.xml rename to ClientLib/src/main/assets/CameraInfo/Mobius_A_Lens.xml diff --git a/ServiceApp/assets/CameraInfo/Mobius_B_Lens.xml b/ClientLib/src/main/assets/CameraInfo/Mobius_B_Lens.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Mobius_B_Lens.xml rename to ClientLib/src/main/assets/CameraInfo/Mobius_B_Lens.xml diff --git a/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_Monochrome.xml b/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_Monochrome.xml new file mode 100644 index 0000000000..000da1d98c --- /dev/null +++ b/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_Monochrome.xml @@ -0,0 +1,8 @@ + + + Parrot Sequoia Monochrome + 4.8 + 3.6 + 3.98 + 1.23 + diff --git a/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_RGB.xml b/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_RGB.xml new file mode 100644 index 0000000000..70d6f00f34 --- /dev/null +++ b/ClientLib/src/main/assets/CameraInfo/Parrot_Sequoia_RGB.xml @@ -0,0 +1,8 @@ + + + Parrot Sequoia RGB + 6.17 + 4.63 + 4.88 + 15.9 + \ No newline at end of file diff --git a/ServiceApp/assets/CameraInfo/Sentek GEMS V0.xml b/ClientLib/src/main/assets/CameraInfo/Sentek GEMS V0.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sentek GEMS V0.xml rename to ClientLib/src/main/assets/CameraInfo/Sentek GEMS V0.xml diff --git a/ServiceApp/assets/CameraInfo/Sentek GEMS V1.xml b/ClientLib/src/main/assets/CameraInfo/Sentek GEMS V1.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sentek GEMS V1.xml rename to ClientLib/src/main/assets/CameraInfo/Sentek GEMS V1.xml diff --git a/ServiceApp/assets/CameraInfo/Sentek GEMS V2.xml b/ClientLib/src/main/assets/CameraInfo/Sentek GEMS V2.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sentek GEMS V2.xml rename to ClientLib/src/main/assets/CameraInfo/Sentek GEMS V2.xml diff --git a/ServiceApp/assets/CameraInfo/Sony NEX5 16mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony NEX5 16mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony NEX5 16mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony NEX5 16mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony NEX5 20mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony NEX5 20mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony NEX5 20mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony NEX5 20mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony NEX5 25mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony NEX5 25mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony NEX5 25mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony NEX5 25mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony QX1 16mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony QX1 16mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony QX1 16mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony QX1 16mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony QX1 20mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony QX1 20mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony QX1 20mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony QX1 20mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony RX100 M3 24mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony RX100 M3 24mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony RX100 M3 24mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony RX100 M3 24mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony RX100 M3 70mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony RX100 M3 70mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony RX100 M3 70mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony RX100 M3 70mm.xml diff --git a/ServiceApp/assets/CameraInfo/Sony RX100_M3 50mm.xml b/ClientLib/src/main/assets/CameraInfo/Sony RX100_M3 50mm.xml similarity index 100% rename from ServiceApp/assets/CameraInfo/Sony RX100_M3 50mm.xml rename to ClientLib/src/main/assets/CameraInfo/Sony RX100_M3 50mm.xml diff --git a/ServiceApp/assets/Parameters/ParameterMetaData.xml b/ClientLib/src/main/assets/Parameters/ParameterMetaData.xml similarity index 100% rename from ServiceApp/assets/Parameters/ParameterMetaData.xml rename to ClientLib/src/main/assets/Parameters/ParameterMetaData.xml diff --git a/ServiceApp/assets/VehicleProfiles/ArduCopter.xml b/ClientLib/src/main/assets/VehicleProfiles/ArduCopter.xml similarity index 100% rename from ServiceApp/assets/VehicleProfiles/ArduCopter.xml rename to ClientLib/src/main/assets/VehicleProfiles/ArduCopter.xml diff --git a/ServiceApp/assets/VehicleProfiles/ArduPlane.xml b/ClientLib/src/main/assets/VehicleProfiles/ArduPlane.xml similarity index 100% rename from ServiceApp/assets/VehicleProfiles/ArduPlane.xml rename to ClientLib/src/main/assets/VehicleProfiles/ArduPlane.xml diff --git a/ServiceApp/assets/VehicleProfiles/ArduRover.xml b/ClientLib/src/main/assets/VehicleProfiles/ArduRover.xml similarity index 100% rename from ServiceApp/assets/VehicleProfiles/ArduRover.xml rename to ClientLib/src/main/assets/VehicleProfiles/ArduRover.xml diff --git a/ServiceApp/assets/VehicleProfiles/ArduSolo.xml b/ClientLib/src/main/assets/VehicleProfiles/ArduSolo.xml similarity index 100% rename from ServiceApp/assets/VehicleProfiles/ArduSolo.xml rename to ClientLib/src/main/assets/VehicleProfiles/ArduSolo.xml diff --git a/ClientLib/src/main/java/com/o3dr/android/client/ApiAvailability.java b/ClientLib/src/main/java/com/o3dr/android/client/ApiAvailability.java new file mode 100644 index 0000000000..ef3421c0c6 --- /dev/null +++ b/ClientLib/src/main/java/com/o3dr/android/client/ApiAvailability.java @@ -0,0 +1,72 @@ +package com.o3dr.android.client; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.support.annotation.NonNull; + +import com.o3dr.services.android.lib.model.IDroidPlannerServices; +import com.o3dr.services.android.lib.util.version.VersionUtils; + +import org.droidplanner.services.android.impl.api.DroidPlannerService; + +import java.util.List; + +/** + * Helper class to verify that the DroneKit-Android services APK is available and up-to-date + * Created by Fredia Huya-Kouadio on 7/7/15. + */ +class ApiAvailability { + + private static class LazyHolder { + private static final ApiAvailability INSTANCE = new ApiAvailability(); + } + + private static final String SERVICES_CLAZZ_NAME = IDroidPlannerServices.class.getName(); + private static final String METADATA_KEY = "com.o3dr.dronekit.android.core.version"; + + private static final int INVALID_LIB_VERSION = -1; + + //Private to prevent instantiation + private ApiAvailability() { + } + + static ApiAvailability getInstance() { + return LazyHolder.INSTANCE; + } + + /** + * Find and returns the most adequate instance of the services lib. + * + * @param context Application context. Must not be null. + * @return intent Intent used to bind to an instance of the services lib. + */ + Intent getAvailableServicesInstance(@NonNull final Context context) { + final PackageManager pm = context.getPackageManager(); + + //Check if an instance of the services library is up and running. + final Intent serviceIntent = new Intent(SERVICES_CLAZZ_NAME); + final List serviceInfos = pm.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA); + if(serviceInfos != null && !serviceInfos.isEmpty()){ + for(ResolveInfo serviceInfo : serviceInfos) { + final Bundle metaData = serviceInfo.serviceInfo.metaData; + if (metaData == null) + continue; + + final int coreLibVersion = metaData.getInt(METADATA_KEY, INVALID_LIB_VERSION); + if (coreLibVersion != INVALID_LIB_VERSION && coreLibVersion >= VersionUtils.getCoreLibVersion(context)) { + serviceIntent.setClassName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name); + return serviceIntent; + } + } + } + + //Didn't find any that's up and running. Enable the local one + DroidPlannerService.enableDroidPlannerService(context, true); + serviceIntent.setClass(context, DroidPlannerService.class); + return serviceIntent; + } + +} diff --git a/ClientLib/src/main/java/com/o3dr/android/client/ControlTower.java b/ClientLib/src/main/java/com/o3dr/android/client/ControlTower.java index 573f073732..7c7f5695e6 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/ControlTower.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/ControlTower.java @@ -4,17 +4,16 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; -import com.o3dr.android.client.apis.ApiAvailability; import com.o3dr.android.client.interfaces.TowerListener; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.model.IDroidPlannerServices; +import com.o3dr.services.android.lib.model.IDroneApi; import java.util.concurrent.atomic.AtomicBoolean; @@ -25,8 +24,6 @@ public class ControlTower { private static final String TAG = ControlTower.class.getSimpleName(); - private final Intent serviceIntent = new Intent(IDroidPlannerServices.class.getName()); - private final IBinder.DeathRecipient binderDeathRecipient = new IBinder.DeathRecipient() { @Override public void binderDied() { @@ -59,15 +56,13 @@ public void onServiceDisconnected(ComponentName name) { private final AtomicBoolean isServiceConnecting = new AtomicBoolean(false); private final Context context; + private final DroneApiListener apiListener; private TowerListener towerListener; private IDroidPlannerServices o3drServices; public ControlTower(Context context) { this.context = context; - } - - IDroidPlannerServices get3drServices() { - return o3drServices; + this.apiListener = new DroneApiListener(this.context); } public boolean isTowerConnected() { @@ -134,22 +129,9 @@ public void connect(TowerListener listener) { towerListener = listener; if (!isTowerConnected() && !isServiceConnecting.get()) { - final int apiAvailableResult = ApiAvailability.getInstance().checkApiAvailability(context); - - switch(apiAvailableResult){ - case ApiAvailability.API_AVAILABLE: - final ResolveInfo info = context.getPackageManager().resolveService(serviceIntent, 0); - if (info != null) { - serviceIntent.setClassName(info.serviceInfo.packageName, info.serviceInfo.name); - isServiceConnecting.set(context.bindService(serviceIntent, o3drServicesConnection, - Context.BIND_AUTO_CREATE)); - } - break; - - default: - ApiAvailability.getInstance().showErrorDialog(context, apiAvailableResult); - break; - } + final Intent serviceIntent = ApiAvailability.getInstance().getAvailableServicesInstance(context); + isServiceConnecting.set(context.bindService(serviceIntent, o3drServicesConnection, + Context.BIND_AUTO_CREATE)); } } @@ -166,11 +148,19 @@ public void disconnect() { try { context.unbindService(o3drServicesConnection); } catch (Exception e) { - Log.e(TAG, "Error occurred while unbinding from 3DR Services."); + Log.e(TAG, "Error occurred while unbinding from DroneKit-Android."); } } - String getApplicationId() { + IDroneApi registerDroneApi() throws RemoteException { + return o3drServices.registerDroneApi(this.apiListener, getApplicationId()); + } + + void releaseDroneApi(IDroneApi droneApi) throws RemoteException { + o3drServices.releaseDroneApi(droneApi); + } + + private String getApplicationId() { return context.getPackageName(); } } diff --git a/ClientLib/src/main/java/com/o3dr/android/client/Drone.java b/ClientLib/src/main/java/com/o3dr/android/client/Drone.java index d3f42c6866..65a526c0f8 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/Drone.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/Drone.java @@ -9,26 +9,15 @@ import android.os.SystemClock; import android.util.Log; -import com.o3dr.android.client.apis.CalibrationApi; -import com.o3dr.android.client.apis.ControlApi; -import com.o3dr.android.client.apis.ExperimentalApi; -import com.o3dr.android.client.apis.FollowApi; 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.interfaces.LinkListener; -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.gcs.follow.FollowLocationSource; -import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.drone.mission.Mission; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.property.Altitude; @@ -43,13 +32,11 @@ import com.o3dr.services.android.lib.drone.property.Speed; import com.o3dr.services.android.lib.drone.property.State; import com.o3dr.services.android.lib.drone.property.Type; -import com.o3dr.services.android.lib.drone.property.VehicleMode; import com.o3dr.services.android.lib.gcs.follow.FollowState; -import com.o3dr.services.android.lib.gcs.follow.FollowType; -import com.o3dr.services.android.lib.gcs.returnToMe.ReturnToMeState; +import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.gcs.link.LinkEvent; import com.o3dr.services.android.lib.gcs.link.LinkEventExtra; -import com.o3dr.services.android.lib.mavlink.MavlinkMessageWrapper; +import com.o3dr.services.android.lib.gcs.returnToMe.ReturnToMeState; import com.o3dr.services.android.lib.model.AbstractCommandListener; import com.o3dr.services.android.lib.model.IDroneApi; import com.o3dr.services.android.lib.model.IObserver; @@ -108,7 +95,6 @@ public void binderDied() { private Handler handler; private ControlTower serviceMgr; private DroneObserver droneObserver; - private DroneApiListener apiListener; private final AtomicReference droneApiRef = new AtomicReference<>(null); private ConnectionParameter connectionParameter; @@ -136,7 +122,6 @@ public Drone(Context context) { void init(ControlTower controlTower, Handler handler) { this.handler = handler; this.serviceMgr = controlTower; - this.apiListener = new DroneApiListener(this); this.droneObserver = new DroneObserver(this); } @@ -155,7 +140,7 @@ synchronized void start() { } try { - droneApi = serviceMgr.get3drServices().registerDroneApi(this.apiListener, serviceMgr.getApplicationId()); + droneApi = serviceMgr.registerDroneApi(); droneApi.asBinder().linkToDeath(binderDeathRecipient, 0); } catch (RemoteException e) { throw new IllegalStateException("Unable to retrieve a valid drone handle."); @@ -179,7 +164,7 @@ synchronized void destroy() { try { if (isStarted(droneApi)) { droneApi.asBinder().unlinkToDeath(binderDeathRecipient, 0); - serviceMgr.get3drServices().releaseDroneApi(droneApi); + serviceMgr.releaseDroneApi(droneApi); } } catch (RemoteException | NoSuchElementException e) { Log.e(TAG, e.getMessage(), e); @@ -614,141 +599,12 @@ private void removeAttributesObserver(IDroneApi droneApi, IObserver observer) { } } - /** - * @deprecated Use {@link VehicleApi#setVehicleMode(VehicleMode)} instead. - */ - public void changeVehicleMode(VehicleMode newMode) { - VehicleApi.getApi(this).setVehicleMode(newMode); - } - - /** - * @deprecated Use {@link VehicleApi#refreshParameters()} instead. - */ - public void refreshParameters() { - VehicleApi.getApi(this).refreshParameters(); - } - - /** - * @deprecated Use {@link VehicleApi#writeParameters(Parameters)} instead. - */ - public void writeParameters(Parameters parameters) { - VehicleApi.getApi(this).writeParameters(parameters); - } - - /** - * @deprecated Use {@link MissionApi#setMission(Mission, boolean)} instead. - */ - public void setMission(Mission mission, boolean pushToDrone) { - MissionApi.getApi(this).setMission(mission, pushToDrone); - } - - /** - * @deprecated Use {@link MissionApi#generateDronie()} instead. - */ - public void generateDronie() { - MissionApi.getApi(this).generateDronie(); - } - - /** - * @deprecated Use {@link VehicleApi#arm(boolean)} instead. - */ - public void arm(boolean arm) { - VehicleApi.getApi(this).arm(arm); - } - - /** - * @deprecated Use {@link CalibrationApi#startIMUCalibration()} instead. - */ - public void startIMUCalibration() { - CalibrationApi.getApi(this).startIMUCalibration(); - } - - /** - * @deprecated Use {@link CalibrationApi#sendIMUAck(int)} instead. - */ - public void sendIMUCalibrationAck(int step) { - CalibrationApi.getApi(this).sendIMUAck(step); - } - - /** - * @deprecated Use {@link ControlApi#takeoff(double, AbstractCommandListener)} instead. - */ - public void doGuidedTakeoff(double altitude) { - ControlApi.getApi(this).takeoff(altitude, null); - } - - /** - * @deprecated Use {@link ControlApi#pauseAtCurrentLocation(AbstractCommandListener)} instead. - */ - public void pauseAtCurrentLocation() { - ControlApi.getApi(this).pauseAtCurrentLocation(null); - } - - /** - * @deprecated Use {@link ControlApi#goTo(LatLong, boolean, AbstractCommandListener)} instead. - */ - public void sendGuidedPoint(LatLong point, boolean force) { - ControlApi.getApi(this).goTo(point, force, null); - } - - /** - * @deprecated Use {@link ExperimentalApi#sendMavlinkMessage(MavlinkMessageWrapper)} instead. - */ - public void sendMavlinkMessage(MavlinkMessageWrapper messageWrapper) { - ExperimentalApi.getApi(this).sendMavlinkMessage(messageWrapper); - } - - /** - * @deprecated Use {@link ControlApi#climbTo(double)} instead. - */ - public void setGuidedAltitude(double altitude) { - ControlApi.getApi(this).climbTo(altitude); - } - - /** - * @deprecated Use {@link FollowApi#enableFollowMe(FollowType, com.o3dr.services.android.lib.gcs.follow.FollowLocationSource)} instead. - */ - public void enableFollowMe(FollowType followType) { - FollowApi.getApi(this).enableFollowMe(followType, FollowLocationSource.INTERNAL); - } - - /** - * @deprecated Use {@link FollowApi#disableFollowMe()} instead. - */ - public void disableFollowMe() { - FollowApi.getApi(this).disableFollowMe(); - } - - /** - * @deprecated Use {@link ExperimentalApi#triggerCamera()} instead. - */ - public void triggerCamera() { - ExperimentalApi.getApi(this).triggerCamera(); - } - - /** - * @deprecated Use {@link MissionApi#loadWaypoints()} instead. - */ - public void loadWaypoints() { - MissionApi.getApi(this).loadWaypoints(); - } - public Handler getHandler() { return handler; } - void notifyDroneConnectionFailed(final ConnectionResult result) { - if (droneListeners.isEmpty()) { - return; - } - - handler.post(new Runnable() { - @Override - public void run() { - for (DroneListener listener : droneListeners) - listener.onDroneConnectionFailed(result); - } - }); + public ExecutorService getAsyncScheduler(){ + return asyncScheduler; } void notifyAttributeUpdated(final String attributeEvent, final Bundle extras) { @@ -780,16 +636,6 @@ public void onRetrievalFailed() { 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); - sendDroneEventToListeners(SoloEvents.SOLO_EU_TX_POWER_COMPLIANCE_UPDATED, eventInfo); - break; - case LinkEvent.LINK_STATE_UPDATED: sendLinkEventToListener(extras); return; diff --git a/ClientLib/src/main/java/com/o3dr/android/client/DroneApiListener.java b/ClientLib/src/main/java/com/o3dr/android/client/DroneApiListener.java index 43b3e35a71..a6881cd3b5 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/DroneApiListener.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/DroneApiListener.java @@ -1,5 +1,6 @@ package com.o3dr.android.client; +import android.content.Context; import android.os.RemoteException; import com.o3dr.services.android.lib.drone.connection.ConnectionResult; @@ -11,16 +12,14 @@ */ public class DroneApiListener extends IApiListener.Stub { - private final Drone drone; + private final Context context; - public DroneApiListener(Drone drone){ - this.drone = drone; + public DroneApiListener(Context context){ + this.context = context; } @Override - public void onConnectionFailed(ConnectionResult connectionResult) throws RemoteException { - drone.notifyDroneConnectionFailed(connectionResult); - } + public void onConnectionFailed(ConnectionResult connectionResult) throws RemoteException {} @Override public int getClientVersionCode() throws RemoteException { @@ -29,6 +28,6 @@ public int getClientVersionCode() throws RemoteException { @Override public int getApiVersionCode(){ - return VersionUtils.getCoreLibVersion(drone.getContext()); + return VersionUtils.getCoreLibVersion(this.context); } } diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/ApiAvailability.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/ApiAvailability.java deleted file mode 100644 index f1e69971ce..0000000000 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/ApiAvailability.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.o3dr.android.client.apis; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.os.Bundle; -import android.support.annotation.NonNull; - -import com.o3dr.android.client.utils.InstallServiceDialog; -import com.o3dr.services.android.lib.model.IDroidPlannerServices; -import com.o3dr.services.android.lib.util.version.VersionUtils; - -/** - * Helper class to verify that the DroneKit-Android services APK is available and up-to-date - * Created by Fredia Huya-Kouadio on 7/7/15. - */ -public class ApiAvailability { - - private static class LazyHolder { - private static final ApiAvailability INSTANCE = new ApiAvailability(); - } - - private static final String TAG = ApiAvailability.class.getSimpleName(); - - private static final String SERVICES_CLAZZ_NAME = IDroidPlannerServices.class.getName(); - private static final String METADATA_KEY = "com.o3dr.dronekit.android.core.version"; - - public static final int API_AVAILABLE = 0; - public static final int API_MISSING = 1; - public static final int API_UPDATE_REQUIRED = 2; - - //Private to prevent instantiation - private ApiAvailability() { - } - - public static ApiAvailability getInstance() { - return LazyHolder.INSTANCE; - } - - /** - * Verifies that DroneKit-Android services is installed and enabled on this device, and that the version - * installed is up-to-date. - * - * @param context Application context. Must not be null. - * @return status code indicating the availability of the api. - */ - public int checkApiAvailability(@NonNull final Context context) { - final PackageManager pm = context.getPackageManager(); - - //Check if DroneKit-Android services is installed. - final Intent serviceIntent = new Intent(SERVICES_CLAZZ_NAME); - final ResolveInfo serviceInfo = pm.resolveService(serviceIntent, PackageManager.GET_META_DATA); - if (serviceInfo == null) { - return API_MISSING; - } - - final Bundle metaData = serviceInfo.serviceInfo.metaData; - if (metaData == null) - return API_UPDATE_REQUIRED; - - final int coreLibVersion = metaData.getInt(METADATA_KEY); - if (coreLibVersion < VersionUtils.getCoreLibVersion(context)) - return API_UPDATE_REQUIRED; - else - return API_AVAILABLE; - } - - /** - * Display a dialog for an error code returned from callback to {@link ApiAvailability#checkApiAvailability(Context)} - * - * @param context Application context - * @param errorCode Error code returned from callback to - * {@link ApiAvailability#checkApiAvailability(Context)}. If errorCode is API_AVAILABLE, then this does nothing. - */ - public void showErrorDialog(Context context, int errorCode) { - switch (errorCode) { - case API_MISSING: - context.startActivity(new Intent(context, InstallServiceDialog.class) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(InstallServiceDialog.EXTRA_REQUIREMENT, InstallServiceDialog.REQUIRE_INSTALL)); - break; - - case API_UPDATE_REQUIRED: - context.startActivity(new Intent(context, InstallServiceDialog.class) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(InstallServiceDialog.EXTRA_REQUIREMENT, InstallServiceDialog.REQUIRE_UPDATE)); - break; - } - } - -} diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/ExperimentalApi.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/ExperimentalApi.java index 8dbbe15f3b..fa1a85ae3d 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/ExperimentalApi.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/apis/ExperimentalApi.java @@ -360,7 +360,7 @@ private IVideoStreamCallback getCallback() { public void run() { handler.removeCallbacks(reconnectTask); if (linkConn != null) - linkConn.connect(); + linkConn.connect(null); } }; @@ -374,7 +374,7 @@ public void start() { handler.removeCallbacks(reconnectTask); Log.d(TAG, "Connecting to video stream..."); - this.linkConn.connect(); + this.linkConn.connect(null); } public void stop() { diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/GimbalApi.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/GimbalApi.java index f8e445f36f..158a4fd8ac 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/GimbalApi.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/apis/GimbalApi.java @@ -10,7 +10,6 @@ import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra; import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; -import com.o3dr.services.android.lib.drone.connection.ConnectionResult; import com.o3dr.services.android.lib.drone.property.Type; import com.o3dr.services.android.lib.model.SimpleCommandListener; import com.o3dr.services.android.lib.model.action.Action; @@ -18,7 +17,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import static com.o3dr.services.android.lib.drone.action.GimbalActions.*; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.ACTION_SET_GIMBAL_MOUNT_MODE; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.ACTION_SET_GIMBAL_ORIENTATION; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.GIMBAL_MOUNT_MODE; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.GIMBAL_PITCH; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.GIMBAL_ROLL; +import static com.o3dr.services.android.lib.drone.action.GimbalActions.GIMBAL_YAW; public final class GimbalApi extends Api implements DroneListener { @@ -266,11 +270,6 @@ private void notifyGimbalOrientationUpdated(GimbalOrientation orientation){ } } - @Override - public void onDroneConnectionFailed(ConnectionResult result) { - - } - @Override public void onDroneEvent(String event, Bundle extras) { switch(event){ diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/MissionApi.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/MissionApi.java index efcbcf02d7..c0deb83c29 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/MissionApi.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/apis/MissionApi.java @@ -1,6 +1,8 @@ package com.o3dr.android.client.apis; +import android.net.Uri; import android.os.Bundle; +import android.support.annotation.Nullable; import com.o3dr.android.client.Drone; import com.o3dr.services.android.lib.drone.mission.Mission; @@ -11,7 +13,24 @@ import java.util.concurrent.ConcurrentHashMap; -import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.*; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_BUILD_COMPLEX_MISSION_ITEM; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_CHANGE_MISSION_SPEED; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_GENERATE_DRONIE; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_GOTO_WAYPOINT; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_LOAD_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_LOAD_WAYPOINTS; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_SAVE_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_SET_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_START_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_FORCE_ARM; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_FORCE_MODE_CHANGE; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_LOAD_MISSION_URI; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_MISSION_ITEM_INDEX; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_MISSION_SPEED; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_PUSH_TO_DRONE; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_SAVE_MISSION_URI; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_SET_LOADED_MISSION; /** * Provides access to missions specific functionality. @@ -95,6 +114,118 @@ public void loadWaypoints() { drone.performAsyncAction(new Action(ACTION_LOAD_WAYPOINTS)); } + /** + * Loads the mission from the given source uri + * @param sourceUri + * @param loadingCallback Invoked when the loading operation completes. + * @since 3.0.0 + */ + @Nullable + public void loadMission(Uri sourceUri, LoadingCallback loadingCallback) { + loadAndSetMission(sourceUri, false, loadingCallback); + } + + /** + * Loads and sets the mission retrieved from the source uri. + * @param sourceUri + * @param loadingCallback Invoked when the loading operation completes. + * @since 3.0.0 + */ + public void loadAndSetMission(Uri sourceUri, LoadingCallback loadingCallback){ + loadAndSetMission(sourceUri, true, loadingCallback); + } + + private void loadAndSetMission(final Uri sourceUri, final boolean setMission, final LoadingCallback loadingCallback){ + if(sourceUri == null){ + throw new NullPointerException("Mission source uri must be non null."); + } + if(!setMission && loadingCallback == null){ + // No point to load the mission if no one is listening for it. + return; + } + + drone.getAsyncScheduler().execute(new Runnable() { + @Override + public void run() { + postLoadingStart(loadingCallback); + + Bundle params = new Bundle(); + params.putParcelable(EXTRA_LOAD_MISSION_URI, sourceUri); + params.putBoolean(EXTRA_SET_LOADED_MISSION, setMission); + + Action loadAction = new Action(ACTION_LOAD_MISSION, params); + boolean result = drone.performAction(loadAction); + if (loadingCallback != null) { + if (result) { + final Mission loadedMission = loadAction.getData().getParcelable(EXTRA_MISSION); + if (loadedMission == null) { + postLoadingFailed(loadingCallback); + } + else { + postLoadingComplete(loadedMission, loadingCallback); + } + } else { + postLoadingFailed(loadingCallback); + } + } + } + }); + } + + private void postLoadingStart(final LoadingCallback callback) { + if(callback != null){ + drone.getHandler().post(new Runnable() { + @Override + public void run() { + callback.onLoadingStart(); + } + }); + } + } + + private void postLoadingFailed(final LoadingCallback callback){ + if(callback != null){ + drone.getHandler().post(new Runnable() { + @Override + public void run() { + callback.onLoadingFailed(); + } + }); + } + } + + private void postLoadingComplete(final T loaded, final LoadingCallback callback) { + if(callback != null){ + drone.getHandler().post(new Runnable() { + @Override + public void run() { + callback.onLoadingComplete(loaded); + } + }); + } + } + + /** + * Saves a mission to the given save uri. + * @param mission Mission to save + * @param saveUri Destination uri for the mission + * @param listener + * + * @since 3.0.0 + */ + public void saveMission(Mission mission, Uri saveUri, AbstractCommandListener listener){ + if(mission == null){ + throw new NullPointerException("Mission must be non null."); + } + if(saveUri == null){ + throw new NullPointerException("Mission destination uri must be non null."); + } + Bundle params = new Bundle(); + params.putParcelable(EXTRA_MISSION, mission); + params.putParcelable(EXTRA_SAVE_MISSION_URI, saveUri); + drone.performAsyncActionOnDroneThread(new Action(ACTION_SAVE_MISSION, params), listener); + } + /** * Build and return complex mission item. * @param itemBundle bundle containing the complex mission item to update. @@ -153,4 +284,10 @@ public void setMissionSpeed(float speed, AbstractCommandListener listener) { params.putFloat(EXTRA_MISSION_SPEED, speed); drone.performAsyncActionOnDroneThread(new Action(ACTION_CHANGE_MISSION_SPEED, params), listener); } + + public interface LoadingCallback { + void onLoadingStart(); + void onLoadingComplete(T loaded); + void onLoadingFailed(); + } } diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/VehicleApi.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/VehicleApi.java index 1b7ef38b43..aa3f026e77 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/VehicleApi.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/apis/VehicleApi.java @@ -3,7 +3,6 @@ import android.os.Bundle; import com.o3dr.android.client.Drone; -import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.drone.property.Parameters; @@ -55,11 +54,9 @@ public static VehicleApi getApi(final Drone drone) { } private final Drone drone; - private final ControlApi controlApi; private VehicleApi(Drone drone) { this.drone = drone; - this.controlApi = ControlApi.getApi(drone); } /** @@ -155,76 +152,6 @@ public void writeParameters(Parameters parameters) { drone.performAsyncAction(new Action(ACTION_WRITE_PARAMETERS, params)); } - /* - Deprecated apis - */ - - /** - * @param altitude altitude in meters - * @deprecated Use {@link ControlApi#takeoff(double, AbstractCommandListener)} instead. - * Perform a guided take off. - */ - public void takeoff(double altitude) { - controlApi.takeoff(altitude, null); - } - - /** - * @param altitude altitude in meters - * @param listener Register a callback to receive update of the command execution state. - * @deprecated Use {@link ControlApi#takeoff(double, AbstractCommandListener)} instead. - * Perform a guided take off. - */ - public void takeoff(double altitude, AbstractCommandListener listener) { - controlApi.takeoff(altitude, listener); - } - - /** - * @param point guided point location - * @param force true to enable guided mode is required. - * @deprecated Use {@link ControlApi#goTo(LatLong, boolean, AbstractCommandListener)} instead. - * Send a guided point to the connected drone. - */ - public void sendGuidedPoint(LatLong point, boolean force) { - controlApi.goTo(point, force, null); - } - - /** - * @param point guided point location - * @param force true to enable guided mode is required. - * @param listener Register a callback to receive update of the command execution state. - * @deprecated Use {@link ControlApi#goTo(LatLong, boolean, AbstractCommandListener)} instead. - * Send a guided point to the connected drone. - */ - public void sendGuidedPoint(LatLong point, boolean force, AbstractCommandListener listener) { - controlApi.goTo(point, force, listener); - } - - /** - * @param altitude altitude in meters - * @deprecated Use {@link ControlApi#climbTo(double)} instead. - * Set the altitude for the guided point. - */ - public void setGuidedAltitude(double altitude) { - controlApi.climbTo(altitude); - } - - /** - * @deprecated Use {@link ControlApi#pauseAtCurrentLocation(AbstractCommandListener)} instead. - * Pause the vehicle at its current location. - */ - public void pauseAtCurrentLocation() { - controlApi.pauseAtCurrentLocation(null); - } - - /** - * @param listener Register a callback to receive update of the command execution state. - * @deprecated Use {@link ControlApi#pauseAtCurrentLocation(AbstractCommandListener)} instead. - * Pause the vehicle at its current location. - */ - public void pauseAtCurrentLocation(final AbstractCommandListener listener) { - controlApi.pauseAtCurrentLocation(listener); - } - /** * Changes the vehicle home location. * diff --git a/ClientLib/src/main/java/com/o3dr/android/client/apis/solo/SoloConfigApi.java b/ClientLib/src/main/java/com/o3dr/android/client/apis/solo/SoloConfigApi.java index cae78919ef..2b58b0268e 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/apis/solo/SoloConfigApi.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/apis/solo/SoloConfigApi.java @@ -91,20 +91,6 @@ public void updateControllerMode(@SoloControllerMode.ControllerMode int controll drone.performAsyncActionOnDroneThread(new Action(ACTION_UPDATE_CONTROLLER_MODE, params), listener); } - /** - * @deprecated Use {@link #updateTxPowerComplianceCountry(TxPowerComplianceCountries compliantCountry, AbstractCommandListener listener)} instead. - */ - public void updateEUTxPowerCompliance(boolean isEUCompliant, AbstractCommandListener listener) { - TxPowerComplianceCountries compliantCountry; - if (isEUCompliant) { - compliantCountry = TxPowerComplianceCountries.getDefaultEUCountry(); - } else { - compliantCountry = TxPowerComplianceCountries.getDefaultCountry(); - } - - updateTxPowerComplianceCountry(compliantCountry, listener); - } - /** * Updates the tx power compliance to the specified country. * diff --git a/ClientLib/src/main/java/com/o3dr/android/client/interfaces/DroneListener.java b/ClientLib/src/main/java/com/o3dr/android/client/interfaces/DroneListener.java index 1fa92a64fb..36239c3725 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/interfaces/DroneListener.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/interfaces/DroneListener.java @@ -2,21 +2,11 @@ import android.os.Bundle; -import com.o3dr.services.android.lib.drone.connection.ConnectionResult; -import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; - /** * Created by fhuya on 11/18/14. */ public interface DroneListener { - /** - * @deprecated Use {@link LinkListener#onLinkStateUpdated(LinkConnectionStatus)} instead. - * - * @param result - */ - void onDroneConnectionFailed(ConnectionResult result); - void onDroneEvent(String event, Bundle extras); void onDroneServiceInterrupted(String errorMsg); diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/FileUtils.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/FileUtils.java similarity index 55% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/FileUtils.java rename to ClientLib/src/main/java/com/o3dr/android/client/utils/FileUtils.java index 3f4d73a90e..14d2d97efa 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/FileUtils.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/FileUtils.java @@ -1,7 +1,9 @@ -package org.droidplanner.services.android.utils.file; +package com.o3dr.android.client.utils; import android.content.Context; +import org.droidplanner.services.android.impl.utils.file.DirectoryPath; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -13,8 +15,7 @@ public class FileUtils { public static final String CAMERA_FILENAME_EXT = ".xml"; - - public static final String TLOG_FILENAME_EXT = ".tlog"; + public static final SimpleDateFormat timestampFormatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS", Locale.US); public static File[] getCameraInfoFileList(Context context) { FilenameFilter filter = new FilenameFilter() { @@ -26,28 +27,7 @@ public boolean accept(File dir, String filename) { return getFileList(DirectoryPath.getCameraInfoPath(context), filter); } - public static File[] getTLogFileList(Context context, String appId) { - final FilenameFilter tlogFilter = new FilenameFilter() { - public boolean accept(File dir, String filename) { - return filename.endsWith(TLOG_FILENAME_EXT); - } - }; - - File[] unsentFiles = getFileList(DirectoryPath.getTLogPath(context, appId).getPath(), tlogFilter); - File[] sentFiles = getFileList(DirectoryPath.getTLogSentPath(context, appId).getPath(), tlogFilter); - File[] tlogFiles = new File[unsentFiles.length + sentFiles.length]; - - int i = 0; - for(File file : unsentFiles) - tlogFiles[i++] = file; - - for(File file : sentFiles) - tlogFiles[i++] = file; - - return tlogFiles; - } - - static public File[] getFileList(String path, FilenameFilter filter) { + private static File[] getFileList(String path, FilenameFilter filter) { File mPath = new File(path); if(!mPath.exists()) return new File[0]; @@ -70,11 +50,35 @@ public static FileOutputStream getExceptionFileStream(Context context) throws Fi * Timestamp for logs in the Mission Planner Format */ static public String getTimeStamp(long timestamp) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US); - return sdf.format(new Date(timestamp)); + return timestampFormatter.format(new Date(timestamp)); } - static public String getTimeStamp() { + private static String getTimeStamp() { return getTimeStamp(System.currentTimeMillis()); } + + public static String getFilenameWithoutExtension(File file){ + return getFilenameWithoutExtension(file.getName()); + } + + public static String getFilenameWithoutExtension(String filename){ + int pos = filename.lastIndexOf("."); + if (pos >= 0) { + filename = filename.substring(0, pos); + } + return filename; + } + + public static String getFileExtension(File file){ + return getFileExtension(file.getName()); + } + + public static String getFileExtension(String filename){ + String extension = ""; + int pos = filename.lastIndexOf("."); + if(pos >= 0){ + extension = filename.substring(pos); + } + return extension; + } } diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/InstallServiceDialog.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/InstallServiceDialog.java deleted file mode 100644 index 652bda078c..0000000000 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/InstallServiceDialog.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.o3dr.android.client.utils; - -import android.content.Intent; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import android.widget.Toast; - -import com.o3dr.android.client.R; - -/** - * Created by fhuya on 11/14/14. - */ -public class InstallServiceDialog extends FragmentActivity { - - public static final String EXTRA_REQUIREMENT = "extra_requirement"; - - public static final int REQUIRE_INSTALL = 0; - public static final int REQUIRE_UPDATE = 1; - - private Button installButton; - private TextView dialogTitle; - private TextView dialogMsg; - - @Override - public void onCreate(Bundle savedInstanceState){ - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_install_service_dialog); - - final Button cancelButton = (Button) findViewById(R.id.dialog_cancel_button); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - - dialogTitle = (TextView) findViewById(R.id.dialog_title); - dialogMsg = (TextView) findViewById(R.id.dialog_message); - - installButton = (Button) findViewById(R.id.dialog_install_button); - installButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - final PackageManager pm = getPackageManager(); - - Intent marketIntent = new Intent(Intent.ACTION_VIEW, - Uri.parse("market://details?id=org.droidplanner.services.android")); - if(pm.resolveActivity(marketIntent, 0) == null){ - marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=org.droidplanner.services.android")); - if(pm.resolveActivity(marketIntent, 0) == null){ - marketIntent = null; - } - } - - if(marketIntent != null) - startActivity(marketIntent); - else{ - Toast.makeText(getApplicationContext(), "No app found to complete the process.", Toast - .LENGTH_LONG).show(); - } - - finish(); - } - }); - - handleIntent(getIntent()); - } - - @Override - public void onNewIntent(Intent intent){ - super.onNewIntent(intent); - handleIntent(intent); - } - - private void handleIntent(Intent intent){ - if(intent == null){ - finish(); - return; - } - - final int requirement = intent.getIntExtra(EXTRA_REQUIREMENT, REQUIRE_INSTALL); - switch(requirement){ - case REQUIRE_INSTALL: - installButton.setText(R.string.install_service_dialog_install_button); - dialogTitle.setText(R.string.install_service_dialog_title); - dialogMsg.setText(R.string.install_service_dialog_message); - break; - - case REQUIRE_UPDATE: - installButton.setText(R.string.update_service_dialog_update_button); - dialogTitle.setText(R.string.update_service_dialog_title); - dialogMsg.setText(R.string.update_service_dialog_message); - break; - } - } -} diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/LogToFileTree.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/LogToFileTree.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/utils/LogToFileTree.java rename to ClientLib/src/main/java/com/o3dr/android/client/utils/LogToFileTree.java index 9e30bae12c..70a0090e0c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/LogToFileTree.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/LogToFileTree.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.utils; +package com.o3dr.android.client.utils; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log; -import org.droidplanner.services.android.BuildConfig; +import com.o3dr.android.client.BuildConfig; import java.io.File; import java.io.FileOutputStream; diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/AbstractIpConnection.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/AbstractIpConnection.java index fbc3c98631..786a1f684f 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/AbstractIpConnection.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/AbstractIpConnection.java @@ -1,5 +1,6 @@ package com.o3dr.android.client.utils.connection; +import android.os.Bundle; import android.os.Handler; import android.os.Process; import android.os.RemoteException; @@ -12,6 +13,7 @@ import java.nio.ByteBuffer; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; /** * Base class for ip connection (tcp, udp). @@ -43,6 +45,7 @@ public abstract class AbstractIpConnection { private final LinkedBlockingQueue packetsToSend = new LinkedBlockingQueue<>(); private final AtomicInteger connectionStatus = new AtomicInteger(STATE_DISCONNECTED); + private final AtomicReference extrasHolder = new AtomicReference<>(); private final boolean isSendingDisabled; private final boolean isReadingDisabled; @@ -58,7 +61,7 @@ public void run() { try { try { - open(); + open(extrasHolder.get()); connectionStatus.set(STATE_CONNECTED); if(ipConnectionListener != null) ipConnectionListener.onIpConnected(); @@ -200,7 +203,7 @@ public AbstractIpConnection(Handler handler, int readBufferSize, boolean disable this.isPolling = isPolling; } - protected abstract void open() throws IOException; + protected abstract void open(Bundle extras) throws IOException; protected abstract int read(ByteBuffer buffer) throws IOException; @@ -210,16 +213,22 @@ public AbstractIpConnection(Handler handler, int readBufferSize, boolean disable /** * Establish an ip connection. If successful, ConnectionListener#onIpConnected() is called. + * @param extras */ - public void connect(){ + public void connect(Bundle extras){ if(connectionStatus.compareAndSet(STATE_DISCONNECTED, STATE_CONNECTING)){ Log.i(TAG, "Starting manager thread."); + extrasHolder.set(extras); managerThread = new Thread(managerTask, "IP Connection-Manager Thread"); managerThread.setPriority(Thread.MAX_PRIORITY); managerThread.start(); } } + public Bundle getConnectionExtras(){ + return extrasHolder.get(); + } + /** * Disconnect an existing ip connection. If successful, ConnectionListener#onIpDisconnected() is called. */ diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/TcpConnection.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/TcpConnection.java index 2a133ec257..9120a76a8e 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/TcpConnection.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/TcpConnection.java @@ -1,7 +1,10 @@ package com.o3dr.android.client.utils.connection; +import android.os.Bundle; import android.os.Handler; +import org.droidplanner.services.android.impl.utils.NetworkUtils; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; @@ -29,10 +32,11 @@ public TcpConnection(Handler handler, String serverIp, int serverPort){ } @Override - protected void open() throws IOException { + protected void open(Bundle extras) throws IOException { final InetAddress serverAddr = InetAddress.getByName(serverIp); socket = new Socket(); socket.setReuseAddress(true); + NetworkUtils.bindSocketToNetwork(extras, socket); socket.connect(new InetSocketAddress(serverAddr, serverPort), CONNECTION_TIMEOUT); connOut = new BufferedOutputStream(socket.getOutputStream()); connIn = new BufferedInputStream(socket.getInputStream()); diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/UdpConnection.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/UdpConnection.java index 2315745e21..6188883035 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/UdpConnection.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/connection/UdpConnection.java @@ -1,8 +1,11 @@ package com.o3dr.android.client.utils.connection; +import android.os.Bundle; import android.os.Handler; import android.util.Log; +import org.droidplanner.services.android.impl.utils.NetworkUtils; + import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; @@ -51,13 +54,14 @@ public UdpConnection(Handler handler, String address, int hostPort, int serverPo } @Override - protected void open() throws IOException { + protected void open(Bundle extras) throws IOException { Log.d(TAG, "Opening udp connection."); socket = (serverPort == -1) ?new DatagramSocket() : new DatagramSocket(serverPort); socket.setBroadcast(true); socket.setReuseAddress(true); socket.setSoTimeout(readTimeout); + NetworkUtils.bindSocketToNetwork(extras, socket); } @Override diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogParser.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogParser.java index 748e3a8ed8..8be0cb4efa 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogParser.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogParser.java @@ -1,5 +1,6 @@ package com.o3dr.android.client.utils.data.tlog; +import android.content.Context; import android.net.Uri; import android.os.Handler; import android.util.Log; @@ -7,14 +8,15 @@ import com.MAVLink.MAVLinkPacket; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.Parser; +import com.o3dr.services.android.lib.util.UriUtils; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; @@ -36,7 +38,8 @@ private TLogParser(){} * Iterator class to iterate and parse the Tlog file. */ public static class TLogIterator { - private File file; + private final Context context; + private final Uri uri; private DataInputStream in = null; private final Handler handler; @@ -52,8 +55,8 @@ public boolean acceptEvent(Event event) { * * @param uri Location of the TLog files */ - public TLogIterator(Uri uri) { - this(uri, new Handler()); + public TLogIterator(Context context, Uri uri) { + this(context, uri, new Handler()); } /** @@ -62,9 +65,10 @@ public TLogIterator(Uri uri) { * @param uri Location of the TLog files * @param handler Handler to post results to */ - public TLogIterator(Uri uri, Handler handler) { + public TLogIterator(Context context, Uri uri, Handler handler) { + this.context = context; this.handler = handler; - file = new File(uri.toString()); + this.uri = uri; } /** @@ -72,8 +76,8 @@ public TLogIterator(Uri uri, Handler handler) { * * @throws FileNotFoundException */ - public void start() throws FileNotFoundException { - in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); + public void start() throws IOException { + in = new DataInputStream(new BufferedInputStream(UriUtils.getInputStream(context, this.uri))); } /** @@ -107,16 +111,12 @@ public void nextAsync(final TLogIteratorFilter filter, final TLogIteratorCallbac @Override public void run() { try { - Event event = next(in); - while (event != null) { - if (filter.acceptEvent(event)) { - sendResult(callback, event); - return; - } - event = next(in); + Event event = blockingNext(filter); + if (event != null) { + sendResult(callback, event); + } else { + sendFailed(callback, new NoSuchElementException()); } - - sendFailed(callback, new NoSuchElementException()); } catch (IOException e) { sendFailed(callback, e); } @@ -124,6 +124,35 @@ public void run() { }); } + /** + * Retrieves next tlog data event. + * Note: This method blocks and should not be used on the main thread. + * @return + * @throws IOException + */ + public Event blockingNext() throws IOException { + return blockingNext(DEFAULT_FILTER); + } + + /** + * Retrieves next tlog data event matching the given filter parameter. + * Note: This method blocks and should not be used on the main thread. + * @param filter + * @return + * @throws IOException + */ + public Event blockingNext(final TLogIteratorFilter filter) throws IOException { + Event event = next(in); + while (event != null) { + if (filter.acceptEvent(event)) { + return event; + } + event = next(in); + } + + return null; + } + private void sendResult(final TLogIteratorCallback callback, final Event event) { if (callback != null) { handler.post(new Runnable() { @@ -165,8 +194,8 @@ public boolean shouldIterate() { * @return * @throws Exception */ - public static List getAllEvents(final Uri uri) throws Exception { - return getAllEvents(uri, DEFAULT_FILTER); + public static List getAllEvents(Context context, final Uri uri) throws Exception { + return getAllEvents(context, uri, DEFAULT_FILTER); } /** @@ -176,11 +205,11 @@ public static List getAllEvents(final Uri uri) throws Exceptio * @return * @throws Exception */ - public static List getAllEvents(final Uri uri, final TLogParserFilter filter) throws Exception { - File file = new File(uri.getPath()); + public static List getAllEvents(Context context, final Uri uri, final TLogParserFilter filter) throws Exception { + InputStream inputStream = UriUtils.getInputStream(context, uri); DataInputStream in = null; try { - in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); + in = new DataInputStream(new BufferedInputStream(inputStream)); ArrayList eventList = new ArrayList<>(); Event event = next(in); while (event != null && filter.shouldIterate()) { @@ -210,8 +239,8 @@ public static List getAllEvents(final Uri uri, final TLogParse * @param uri {@link Uri} * @param callback {@link TLogParserCallback} */ - public static void getAllEventsAsync(final Handler handler, final Uri uri, final TLogParserCallback callback) { - getAllEventsAsync(handler, uri, DEFAULT_FILTER, callback); + public static void getAllEventsAsync(Context context, final Handler handler, final Uri uri, final TLogParserCallback callback) { + getAllEventsAsync(context, handler, uri, DEFAULT_FILTER, callback); } /** @@ -222,12 +251,12 @@ public static void getAllEventsAsync(final Handler handler, final Uri uri, final * @param filter {@link TLogParserFilter} * @param callback {@link TLogParserCallback} */ - public static void getAllEventsAsync(final Handler handler, final Uri uri, final TLogParserFilter filter, final TLogParserCallback callback) { + public static void getAllEventsAsync(final Context context, final Handler handler, final Uri uri, final TLogParserFilter filter, final TLogParserCallback callback) { getInstance().execute(new Runnable() { @Override public void run() { try { - List eventList = getAllEvents(uri, filter); + List eventList = getAllEvents(context, uri, filter); if (eventList.isEmpty()) { sendFailed(handler, callback, new NoSuchElementException()); @@ -290,7 +319,9 @@ private static class InitializeExecutorService { /** * Mavlink message event. */ - public static class Event { + public static class Event implements Serializable { + private static final long serialVersionUID = -3035618718582382608L; + private long timestamp; private MAVLinkMessage mavLinkMessage; @@ -316,5 +347,30 @@ public long getTimestamp() { public MAVLinkMessage getMavLinkMessage() { return mavLinkMessage; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Event)) { + return false; + } + + Event event = (Event) o; + + if (timestamp != event.timestamp) { + return false; + } + return mavLinkMessage != null ? mavLinkMessage.equals(event.mavLinkMessage) : event.mavLinkMessage == null; + + } + + @Override + public int hashCode() { + int result = (int) (timestamp ^ (timestamp >>> 32)); + result = 31 * result + (mavLinkMessage != null ? mavLinkMessage.hashCode() : 0); + return result; + } } } diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogPicker.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogPicker.java deleted file mode 100644 index 98cdd32c74..0000000000 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/data/tlog/TLogPicker.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.o3dr.android.client.utils.data.tlog; - -import android.app.Activity; -import android.content.Intent; - -import com.o3dr.services.android.lib.data.ServiceDataContract; - -/** - * Provides utility to select a tlog files. - */ -public class TLogPicker { - - public static void startTLogPicker(Activity activity, int resultCode){ - if(activity == null) - return; - - final Intent requestIntent = new Intent(ServiceDataContract.ACTION_REQUEST_TLOG) - .putExtra(ServiceDataContract.EXTRA_REQUEST_TLOG_APP_ID, activity.getPackageName()) - .setType(ServiceDataContract.TLOG_MIME_TYPE); - activity.startActivityForResult(requestIntent, resultCode); - } - - //Private constructor to prevent instantiation - private TLogPicker(){} -} diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/FilterByTimestampGeoTagAlgorithm.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/FilterByTimestampGeoTagAlgorithm.java index 3327c70fbe..39df59a9dd 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/FilterByTimestampGeoTagAlgorithm.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/FilterByTimestampGeoTagAlgorithm.java @@ -11,11 +11,8 @@ import java.io.File; import java.util.ArrayList; import java.util.Calendar; -import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.SortedMap; import java.util.TreeMap; diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagAsyncTask.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagAsyncTask.java index 933b5dfb47..6bc0dea834 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagAsyncTask.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagAsyncTask.java @@ -32,7 +32,7 @@ public void onProgress(int numProcessed, int numTotal) { * Warning: this copies data to external storage * * @param rootDir {@link File} - * @param events {@link List} list of events to geotag photos. + * @param events {@link List< com.o3dr.android.client.utils.data.tlog.TLogParser.Event>} list of events to geotag photos. * @param photos {@link List} list of files of photos to geotag. */ public GeoTagAsyncTask(File rootDir, List events, ArrayList photos) { diff --git a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagUtils.java b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagUtils.java index e7bda97237..527f5c135c 100644 --- a/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagUtils.java +++ b/ClientLib/src/main/java/com/o3dr/android/client/utils/geotag/GeoTagUtils.java @@ -11,13 +11,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; /** diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/data/ServiceDataContract.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/data/ServiceDataContract.java deleted file mode 100644 index e68f937aaa..0000000000 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/data/ServiceDataContract.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.o3dr.services.android.lib.data; - -import com.o3dr.services.android.lib.util.Utils; - -/** - * The contract between the 3DR Services data provider, and applications. Contains definitions for the supported URIs - * and columns. - */ -public class ServiceDataContract { - - private static final String PACKAGE_NAME = Utils.PACKAGE_NAME + ".provider"; - - /** - * Authority for the service data provider. - */ - public static final String DATA_PROVIDER_AUTHORITY = PACKAGE_NAME + ".dataprovider"; - - /** - * Authority for the file provider. - */ - public static final String FILE_PROVIDER_AUTHORITY = PACKAGE_NAME + ".fileprovider"; - - /** - * Action used to request a tlog file. - */ - public static final String ACTION_REQUEST_TLOG = PACKAGE_NAME + ".action.REQUEST_TLOG_FILE"; - - /** - * Key used to access the id of the app requesting the tlog data. - */ - public static final String EXTRA_REQUEST_TLOG_APP_ID = PACKAGE_NAME + ".extra.REQUEST_TLOG_APP_ID"; - - /** - * Key used to access the file path for the request tlog data. - */ - public static final String EXTRA_TLOG_ABSOLUTE_PATH = "extra_tlog_absolute_path"; - - /** - * Action used to notify of the availability of a tlog file. - */ - public static final String ACTION_RETURN_TLOG = PACKAGE_NAME + ".action.RETURN_TLOG_FILE"; - - /** - * Mime type for a tlog file. - */ - public static final String TLOG_MIME_TYPE = "application/octet-stream"; -} diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/action/GuidedActions.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/action/GuidedActions.java index 3bf4b42530..9273f4febb 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/action/GuidedActions.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/action/GuidedActions.java @@ -1,7 +1,5 @@ package com.o3dr.services.android.lib.drone.action; -import com.o3dr.services.android.lib.util.Utils; - /** * Created by Fredia Huya-Kouadio on 1/19/15. */ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEventExtras.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEventExtras.java index f5480e339d..bc758baa1b 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEventExtras.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEventExtras.java @@ -20,11 +20,6 @@ private SoloEventExtras(){} */ public static final String EXTRA_SOLO_MESSAGE_DATA = PACKAGE_NAME + ".EXTRA_SOLO_MESSAGE_DATA"; - /** - * @deprecated Use {@link #EXTRA_SOLO_TX_POWER_COMPLIANT_COUNTRY} instead. - */ - public static final String EXTRA_SOLO_EU_TX_POWER_COMPLIANT = PACKAGE_NAME + ".EXTRA_SOLO_EU_TX_POWER_COMPLIANT"; - /** * Used to retrieve the String value specifying which country the controller is compliant with tx power levels. * @see {@link SoloEvents#SOLO_TX_POWER_COMPLIANCE_COUNTRY_UPDATED} diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEvents.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEvents.java index c7429e459e..32f5d92b6c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEvents.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloEvents.java @@ -50,11 +50,6 @@ private SoloEvents() { */ public static final String SOLO_MESSAGE_RECEIVED = PACKAGE_NAME + ".SOLO_MESSAGE_RECEIVED"; - /** - * @deprecated Use {@link #SOLO_TX_POWER_COMPLIANCE_COUNTRY_UPDATED} instead. - */ - public static final String SOLO_EU_TX_POWER_COMPLIANCE_UPDATED = PACKAGE_NAME + ".SOLO_EU_TX_POWER_COMPLIANCE_UPDATED"; - /** * Triggers upon updates to the tx power compliance. */ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloState.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloState.java index 1925e137e3..94ff23e49c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloState.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/SoloState.java @@ -88,10 +88,7 @@ public String getWifiSsid() { return wifiSsid; } - /** - * @deprecated Use {@link #getTxPowerCompliantCountry()} instead. - */ - public boolean isEUTxPowerCompliant() { + private boolean isEUTxPowerCompliant() { return !TxPowerComplianceCountries.getDefaultCountry().name().equals(txPowerCompliantCountry); } diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloActions.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloActions.java index c6b436665e..539495fc2c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloActions.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloActions.java @@ -1,7 +1,5 @@ package com.o3dr.services.android.lib.drone.companion.solo.action; -import com.o3dr.services.android.lib.util.Utils; - /** * Created by Fredia Huya-Kouadio on 7/10/15. */ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloConfigActions.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloConfigActions.java index 098202d159..56b9bcc098 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloConfigActions.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/action/SoloConfigActions.java @@ -33,15 +33,6 @@ private SoloConfigActions() { */ public static final String EXTRA_CONTROLLER_MODE = "extra_controller_mode"; - /** - * @deprecated Use {@link #ACTION_UPDATE_TX_POWER_COMPLIANCE_COUNTRY} instead. - */ - public static final String ACTION_UPDATE_EU_TX_POWER_COMPLIANCE = PACKAGE_NAME + ".UPDATE_EU_TX_POWER_COMPLIANCE"; - /** - * @deprecated Use {@link #EXTRA_TX_POWER_COMPLIANT_COUNTRY_CODE} instead. - */ - public static final String EXTRA_EU_TX_POWER_COMPLIANT = "extra_eu_tx_power_compliant"; - public static final String ACTION_UPDATE_TX_POWER_COMPLIANCE_COUNTRY = PACKAGE_NAME + ".UPDATE_TX_POWER_COMPLIANCE_COUNTRY"; /** * String value. The country the controller should be made compliant with. diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproConstants.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproConstants.java index 28f28c8271..a4e440356c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproConstants.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproConstants.java @@ -2,8 +2,6 @@ import android.support.annotation.IntDef; -import com.MAVLink.enums.GOPRO_CAPTURE_MODE; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproState.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproState.java index 2a01affcbb..aaa277ed4c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproState.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/SoloGoproState.java @@ -1,12 +1,9 @@ package com.o3dr.services.android.lib.drone.companion.solo.tlv; import android.os.Parcel; -import android.support.annotation.IntDef; import com.o3dr.services.android.lib.drone.property.DroneAttribute; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.nio.ByteBuffer; /** diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/mpcc/SoloSplineAttach.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/mpcc/SoloSplineAttach.java index 47e764c2ef..50ab52ec45 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/mpcc/SoloSplineAttach.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/companion/solo/tlv/mpcc/SoloSplineAttach.java @@ -21,7 +21,7 @@ * indicate that it has reached the Path and is prepared to receive SOLO_SPLINE_SEEK messages. * * - * This message is only valid once after a Path is loaded. There is no corresponding “detach” + * This message is only valid once after a Path is loaded. There is no corresponding "detach" * message -- the vehicle stays attached until playback mode is exited. * * @since 2.8.0 diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionParameter.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionParameter.java index 68b62f0e06..2685f519d6 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionParameter.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionParameter.java @@ -1,5 +1,6 @@ package com.o3dr.services.android.lib.drone.connection; +import android.net.Uri; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; @@ -11,64 +12,103 @@ */ public class ConnectionParameter implements Parcelable { - private final int connectionType; + private static final long DEFAULT_EVENTS_DISPATCHING_PERIOD = 0L; //milliseconds - disabled by default. + + private final @ConnectionType.Type int connectionType; private final Bundle paramsBundle; - private final DroneSharePrefs droneSharePrefs; + private final Uri tlogLoggingUri; + private final long eventsDispatchingPeriod; /** + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged * @return Returns a new {@link ConnectionParameter} with type {@link ConnectionType#TYPE_USB} * and baud rate {@link ConnectionType#DEFAULT_USB_BAUD_RATE}. */ - public static ConnectionParameter newUsbConnection() { - return newUsbConnection(ConnectionType.DEFAULT_USB_BAUD_RATE); + public static ConnectionParameter newUsbConnection(@Nullable Uri tlogLoggingUri) { + return newUsbConnection(ConnectionType.DEFAULT_USB_BAUD_RATE, tlogLoggingUri); } /** * * @param usbBaudRate Baud rate for USB connection. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @return Returns a new {@link ConnectionParameter} with type {@link ConnectionType#TYPE_USB}. + */ + public static ConnectionParameter newUsbConnection(int usbBaudRate, @Nullable Uri tlogLoggingUri) { + return newUsbConnection(usbBaudRate, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param usbBaudRate Baud rate for USB connection. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns a new {@link ConnectionParameter} with type {@link ConnectionType#TYPE_USB}. */ - public static ConnectionParameter newUsbConnection(int usbBaudRate) { + public static ConnectionParameter newUsbConnection(int usbBaudRate, @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod){ Bundle paramsBundle = new Bundle(1); paramsBundle.putInt(ConnectionType.EXTRA_USB_BAUD_RATE, usbBaudRate); - return new ConnectionParameter(ConnectionType.TYPE_USB, paramsBundle); + return new ConnectionParameter(ConnectionType.TYPE_USB, paramsBundle, tlogLoggingUri, eventsDispatchingPeriod); } /** - * + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}, using * {@link ConnectionType#DEFAULT_UDP_SERVER_PORT} port. */ - public static ConnectionParameter newUdpConnection() { - return newUdpConnection(ConnectionType.DEFAULT_UDP_SERVER_PORT); + public static ConnectionParameter newUdpConnection(@Nullable Uri tlogLoggingUri) { + return newUdpConnection(ConnectionType.DEFAULT_UDP_SERVER_PORT, tlogLoggingUri); } /** * * @param udpPort Port for the UDP connection. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}. + */ + public static ConnectionParameter newUdpConnection(int udpPort, @Nullable Uri tlogLoggingUri) { + return newUdpConnection(udpPort, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param udpPort Port for the UDP connection. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}. */ - public static ConnectionParameter newUdpConnection(int udpPort) { - return newUdpConnection(udpPort, null, 0, null); + public static ConnectionParameter newUdpConnection(int udpPort, @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod) { + Bundle paramsBundle = new Bundle(); + paramsBundle.putInt(ConnectionType.EXTRA_UDP_SERVER_PORT, udpPort); + + return new ConnectionParameter(ConnectionType.TYPE_UDP, paramsBundle, tlogLoggingUri, + eventsDispatchingPeriod); } /** * * @param udpPort Port for the UDP connection. - * @param udpPingReceiverIp IP address of the UDP server to ping. If this value is null, it is ignored - * along with udpPingReceiverPort and udpPingPayload. + * @param udpPingReceiverIp IP address of the UDP server to ping. * @param udpPingReceiverPort Port of the UDP server to ping. * @param udpPingPayload Ping payload. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged * * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}. The ping * period is set to {@link ConnectionType#DEFAULT_UDP_PING_PERIOD} */ - public static ConnectionParameter newUdpConnection(int udpPort, @Nullable String udpPingReceiverIp, int udpPingReceiverPort, - byte[] udpPingPayload) { - return newUdpConnection(udpPort, udpPingReceiverIp, udpPingReceiverPort, udpPingPayload, ConnectionType.DEFAULT_UDP_PING_PERIOD); + public static ConnectionParameter newUdpWithPingConnection(int udpPort, String udpPingReceiverIp, + int udpPingReceiverPort, + byte[] udpPingPayload, + @Nullable Uri tlogLoggingUri) { + return newUdpWithPingConnection(udpPort, udpPingReceiverIp, udpPingReceiverPort, + udpPingPayload, ConnectionType.DEFAULT_UDP_PING_PERIOD, tlogLoggingUri); } /** @@ -79,11 +119,41 @@ public static ConnectionParameter newUdpConnection(int udpPort, @Nullable String * @param udpPingReceiverPort Port of the UDP server to ping. * @param udpPingPayload Ping payload. * @param pingPeriod How often should the udp ping be performed. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * + * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}. + */ + public static ConnectionParameter newUdpWithPingConnection(int udpPort, + String udpPingReceiverIp, + int udpPingReceiverPort, + byte[] udpPingPayload, + long pingPeriod, + @Nullable Uri tlogLoggingUri) { + return newUdpWithPingConnection(udpPort, udpPingReceiverIp, udpPingReceiverPort, + udpPingPayload, pingPeriod, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param udpPort Port for the UDP connection. + * @param udpPingReceiverIp IP address of the UDP server to ping. If this value is null, it is ignored + * along with udpPingReceiverPort, udpPingPayload, and pingPeriod. + * @param udpPingReceiverPort Port of the UDP server to ping. + * @param udpPingPayload Ping payload. + * @param pingPeriod How often should the udp ping be performed. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_UDP}. */ - public static ConnectionParameter newUdpConnection(int udpPort, @Nullable String udpPingReceiverIp, int udpPingReceiverPort, - byte[] udpPingPayload, long pingPeriod) { + public static ConnectionParameter newUdpWithPingConnection(int udpPort, + String udpPingReceiverIp, + int udpPingReceiverPort, + byte[] udpPingPayload, + long pingPeriod, + @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod) { Bundle paramsBundle = new Bundle(); paramsBundle.putInt(ConnectionType.EXTRA_UDP_SERVER_PORT, udpPort); @@ -94,46 +164,81 @@ public static ConnectionParameter newUdpConnection(int udpPort, @Nullable String paramsBundle.putLong(ConnectionType.EXTRA_UDP_PING_PERIOD, pingPeriod); } - return new ConnectionParameter(ConnectionType.TYPE_UDP, paramsBundle); + return new ConnectionParameter(ConnectionType.TYPE_UDP, paramsBundle, tlogLoggingUri, eventsDispatchingPeriod); } /** * * @param tcpServerIp TCP server IP address. - * + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_TCP}, using * {@link ConnectionType#DEFAULT_TCP_SERVER_PORT}. */ - public static ConnectionParameter newTcpConnection(String tcpServerIp) { - return newTcpConnection(tcpServerIp, ConnectionType.DEFAULT_TCP_SERVER_PORT); + public static ConnectionParameter newTcpConnection(String tcpServerIp, @Nullable Uri tlogLoggingUri) { + return newTcpConnection(tcpServerIp, ConnectionType.DEFAULT_TCP_SERVER_PORT, tlogLoggingUri); } /** * * @param tcpServerIp TCP server IP address. * @param tcpServerPort TCP server port. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_TCP}. + */ + public static ConnectionParameter newTcpConnection(String tcpServerIp, int tcpServerPort, + @Nullable Uri tlogLoggingUri) { + return newTcpConnection(tcpServerIp, tcpServerPort, tlogLoggingUri, + DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param tcpServerIp TCP server IP address. + * @param tcpServerPort TCP server port. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_TCP}. */ - public static ConnectionParameter newTcpConnection(String tcpServerIp, int tcpServerPort) { + public static ConnectionParameter newTcpConnection(String tcpServerIp, int tcpServerPort, + @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod) { Bundle paramsBundle = new Bundle(2); paramsBundle.putString(ConnectionType.EXTRA_TCP_SERVER_IP, tcpServerIp); paramsBundle.putInt(ConnectionType.EXTRA_TCP_SERVER_PORT, tcpServerPort); - return new ConnectionParameter(ConnectionType.TYPE_TCP, paramsBundle); + return new ConnectionParameter(ConnectionType.TYPE_TCP, paramsBundle, tlogLoggingUri, + eventsDispatchingPeriod); } /** * * @param bluetoothAddress Bluetooth address. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_BLUETOOTH}. + */ + public static ConnectionParameter newBluetoothConnection(String bluetoothAddress, @Nullable Uri tlogLoggingUri){ + return newBluetoothConnection(bluetoothAddress, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param bluetoothAddress Bluetooth address. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_BLUETOOTH}. */ - public static ConnectionParameter newBluetoothConnection(String bluetoothAddress) { + public static ConnectionParameter newBluetoothConnection(String bluetoothAddress, + @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod){ Bundle paramsBundle = new Bundle(1); paramsBundle.putString(ConnectionType.EXTRA_BLUETOOTH_ADDRESS, bluetoothAddress); - return new ConnectionParameter(ConnectionType.TYPE_BLUETOOTH, paramsBundle); + return new ConnectionParameter(ConnectionType.TYPE_BLUETOOTH, paramsBundle, tlogLoggingUri, + eventsDispatchingPeriod); } /** @@ -141,40 +246,64 @@ public static ConnectionParameter newBluetoothConnection(String bluetoothAddress * @param ssid Wifi SSID of the solo vehicle link. This will remove a leading and/or trailing quotation. * @param password Password to access the solo wifi network. This value can be null as long as the wifi * configuration has been set up and stored in the mobile device's system. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged. + * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_SOLO}. + */ + public static ConnectionParameter newSoloConnection(String ssid, @Nullable String password, @Nullable Uri tlogLoggingUri){ + return newSoloConnection(ssid, password, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + /** * + * @param ssid Wifi SSID of the solo vehicle link. This will remove a leading and/or trailing quotation. + * @param password Password to access the solo wifi network. This value can be null as long as the wifi + * configuration has been set up and stored in the mobile device's system. + * @param tlogLoggingUri Uri where the tlog data should be logged. Pass null if the tlog data shouldn't be logged. + * @param eventsDispatchingPeriod Dictates how long (in milliseconds) to wait before dispatching + * buffered drone events. A value of OL means events should be + * dispatched as soon as they are received. * @return Returns {@link ConnectionParameter} with type {@link ConnectionType#TYPE_SOLO}. */ - public static ConnectionParameter newSoloConnection(String ssid, @Nullable String password) { + public static ConnectionParameter newSoloConnection(String ssid, @Nullable String password, + @Nullable Uri tlogLoggingUri, + long eventsDispatchingPeriod){ String ssidWithoutQuotes = ssid.replaceAll("^\"|\"$", ""); Bundle paramsBundle = new Bundle(2); paramsBundle.putString(ConnectionType.EXTRA_SOLO_LINK_ID, ssidWithoutQuotes); paramsBundle.putString(ConnectionType.EXTRA_SOLO_LINK_PASSWORD, password); - return new ConnectionParameter(ConnectionType.TYPE_SOLO, paramsBundle); + return new ConnectionParameter(ConnectionType.TYPE_SOLO, paramsBundle, tlogLoggingUri, + eventsDispatchingPeriod); + } + + private ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle){ + this(connectionType, paramsBundle, null); } /** - * @deprecated Use one of specified static methods */ - //TODO: make this private version 3.0 - public ConnectionParameter(int connectionType, Bundle paramsBundle){ + private ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle, Uri tlogLoggingUri){ + this(connectionType, paramsBundle, tlogLoggingUri, DEFAULT_EVENTS_DISPATCHING_PERIOD); + } + + private ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle, + Uri tlogLoggingUri, long eventsDispatchingPeriod){ this.connectionType = connectionType; this.paramsBundle = paramsBundle; - this.droneSharePrefs = null; + this.tlogLoggingUri = tlogLoggingUri; + this.eventsDispatchingPeriod = eventsDispatchingPeriod; } /** - * @deprecated Use {@link ConnectionParameter#ConnectionParameter(int, Bundle)} instead. - * @since 2.8.0 + * Dictates how long (in milliseconds) to wait before dispatching buffered drone events. + * A value of OL means events should be dispatched as soon as they are received. */ - public ConnectionParameter(int connectionType, Bundle paramsBundle, DroneSharePrefs droneSharePrefs){ - this.connectionType = connectionType; - this.paramsBundle = paramsBundle; - this.droneSharePrefs = droneSharePrefs; + public long getEventsDispatchingPeriod() { + return eventsDispatchingPeriod; } - public int getConnectionType() { + public @ConnectionType.Type int getConnectionType() { return connectionType; } @@ -182,8 +311,12 @@ public Bundle getParamsBundle() { return paramsBundle; } - public DroneSharePrefs getDroneSharePrefs() { - return droneSharePrefs; + /** + * Return the uri where the tlog data should be logged. + * @return Uri where to log the tlog data, or null if it shouldn't be logged. + */ + public Uri getTLogLoggingUri(){ + return tlogLoggingUri; } public String getUniqueId(){ @@ -274,6 +407,11 @@ public String toString() { return toString; } + @Override + public ConnectionParameter clone(){ + return new ConnectionParameter(this.connectionType, this.paramsBundle); + } + @Override public int describeContents() { return 0; @@ -283,13 +421,16 @@ public int describeContents() { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.connectionType); dest.writeBundle(paramsBundle); - dest.writeParcelable(this.droneSharePrefs, 0); + dest.writeParcelable(tlogLoggingUri, flags); + dest.writeLong(eventsDispatchingPeriod); } private ConnectionParameter(Parcel in) { - this.connectionType = in.readInt(); - paramsBundle = in.readBundle(); - this.droneSharePrefs = in.readParcelable(DroneSharePrefs.class.getClassLoader()); + @ConnectionType.Type int type = in.readInt(); + this.connectionType = type; + paramsBundle = in.readBundle(getClass().getClassLoader()); + tlogLoggingUri = in.readParcelable(Uri.class.getClassLoader()); + eventsDispatchingPeriod = in.readLong(); } public static final Creator CREATOR = new Creator() { diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionType.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionType.java index ac2468ac48..95d3162288 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionType.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/ConnectionType.java @@ -1,10 +1,25 @@ package com.o3dr.services.android.lib.drone.connection; +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Contains constants used for the connection parameters. */ public class ConnectionType { + @IntDef({ + TYPE_USB, + TYPE_UDP, + TYPE_TCP, + TYPE_BLUETOOTH, + TYPE_SOLO + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Type {} + /** * USB connection type */ @@ -94,4 +109,25 @@ public class ConnectionType { */ public static final String EXTRA_SOLO_LINK_PASSWORD = "extra_solo_link_password"; + public static String getConnectionTypeLabel(@Type int connectionType){ + switch (connectionType) { + case TYPE_BLUETOOTH: + return "bluetooth"; + + case TYPE_TCP: + return "tcp"; + + case TYPE_UDP: + return "udp"; + + case TYPE_USB: + return "usb"; + + case TYPE_SOLO: + return "solo"; + + default: + return null; + } + } } diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/DroneSharePrefs.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/DroneSharePrefs.java deleted file mode 100644 index 34d2b600af..0000000000 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/connection/DroneSharePrefs.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.o3dr.services.android.lib.drone.connection; - -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; - -/** - * Created by fhuya on 11/14/14. - * @deprecated DroneShare uploads are no longer supported. - * @since 2.8.0 - */ -public class DroneSharePrefs implements Parcelable { - - private final String username; - private final String password; - private final boolean isEnabled; - private final boolean enableLiveUpload; - - public DroneSharePrefs(String username, String password, boolean isEnabled, boolean enableLiveUpload) { - this.username = username; - this.password = password; - this.isEnabled = isEnabled; - this.enableLiveUpload = enableLiveUpload; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public boolean isEnabled() { - return isEnabled; - } - - public boolean isLiveUploadEnabled() { - return isEnabled && enableLiveUpload; - } - - public boolean areLoginCredentialsSet(){ - return !TextUtils.isEmpty(username) && !TextUtils.isEmpty(password); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DroneSharePrefs)) return false; - - DroneSharePrefs that = (DroneSharePrefs) o; - - if (enableLiveUpload != that.enableLiveUpload) return false; - if (isEnabled != that.isEnabled) return false; - if (password != null ? !password.equals(that.password) : that.password != null) - return false; - if (username != null ? !username.equals(that.username) : that.username != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = username != null ? username.hashCode() : 0; - result = 31 * result + (password != null ? password.hashCode() : 0); - result = 31 * result + (isEnabled ? 1 : 0); - result = 31 * result + (enableLiveUpload ? 1 : 0); - return result; - } - - @Override - public String toString() { - return "DroneSharePrefs{" + - "username='" + username + '\'' + - ", isEnabled=" + isEnabled + - ", enableLiveUpload=" + enableLiveUpload + - '}'; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.username); - dest.writeString(this.password); - dest.writeByte(isEnabled ? (byte) 1 : (byte) 0); - dest.writeByte(enableLiveUpload ? (byte) 1 : (byte) 0); - } - - private DroneSharePrefs(Parcel in) { - this.username = in.readString(); - this.password = in.readString(); - this.isEnabled = in.readByte() != 0; - this.enableLiveUpload = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - public DroneSharePrefs createFromParcel(Parcel source) { - return new DroneSharePrefs(source); - } - - public DroneSharePrefs[] newArray(int size) { - return new DroneSharePrefs[size]; - } - }; -} diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/Mission.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/Mission.java index d7df4be27b..9706fcf0b5 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/Mission.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/Mission.java @@ -2,12 +2,10 @@ import android.os.Bundle; import android.os.Parcel; -import android.os.Parcelable; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; import com.o3dr.services.android.lib.drone.property.DroneAttribute; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -57,6 +55,31 @@ public void setCurrentMissionItem(int currentMissionItem) { this.currentMissionItem = currentMissionItem; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Mission)) { + return false; + } + + Mission mission = (Mission) o; + + if (currentMissionItem != mission.currentMissionItem) { + return false; + } + return missionItemsList.equals(mission.missionItemsList); + + } + + @Override + public int hashCode() { + int result = currentMissionItem; + result = 31 * result + missionItemsList.hashCode(); + return result; + } + @Override public int describeContents() { return 0; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/action/MissionActions.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/action/MissionActions.java index e30a873550..c6261340c4 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/action/MissionActions.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/action/MissionActions.java @@ -24,6 +24,13 @@ private MissionActions(){} public static final String EXTRA_FORCE_ARM = "extra_force_arm"; public static final String EXTRA_MISSION_SPEED = "extra_mission_speed"; + public static final String ACTION_SAVE_MISSION = Utils.PACKAGE_NAME + ".action.SAVE_MISSION"; + public static final String EXTRA_SAVE_MISSION_URI = "extra_save_mission_uri"; + + public static final String ACTION_LOAD_MISSION = Utils.PACKAGE_NAME + ".action.LOAD_MISSION"; + public static final String EXTRA_LOAD_MISSION_URI = "extra_load_mission_uri"; + public static final String EXTRA_SET_LOADED_MISSION = "extra_set_loaded_mission"; + public static final String ACTION_LOAD_WAYPOINTS = Utils.PACKAGE_NAME + ".action.LOAD_WAYPOINTS"; public static final String ACTION_BUILD_COMPLEX_MISSION_ITEM = Utils.PACKAGE_NAME + ".action" + diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/MissionItem.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/MissionItem.java index f4c2fb8b5d..f41e312013 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/MissionItem.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/MissionItem.java @@ -6,8 +6,6 @@ import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.mission.MissionItemType; -import java.io.Serializable; - /** * Created by fhuya on 11/5/14. */ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/StructureScanner.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/StructureScanner.java index 1c8eba77db..c7364cbe94 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/StructureScanner.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/StructureScanner.java @@ -32,6 +32,7 @@ public StructureScanner(StructureScanner copy){ copy(copy); } + @Override public void copy(StructureScanner source){ this.radius = source.radius; this.heightStep = source.heightStep; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/SurveyDetail.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/SurveyDetail.java index 6a6e94e34a..0454c3c36e 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/SurveyDetail.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/complex/SurveyDetail.java @@ -3,8 +3,6 @@ import android.os.Parcel; import android.os.Parcelable; -import java.io.Serializable; - /** * Created by fhuya on 11/7/14. */ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/BaseSpatialItem.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/BaseSpatialItem.java index a26045f4fe..b04b0de689 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/BaseSpatialItem.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/BaseSpatialItem.java @@ -14,12 +14,16 @@ public abstract class BaseSpatialItem extends MissionItem implements MissionItem private LatLongAlt coordinate; protected BaseSpatialItem(MissionItemType type) { + this(type, null); + } + + protected BaseSpatialItem(MissionItemType type, LatLongAlt coordinate){ super(type); + this.coordinate = coordinate; } protected BaseSpatialItem(BaseSpatialItem copy){ - this(copy.getType()); - coordinate = copy.coordinate == null ? null : new LatLongAlt(copy.coordinate); + this(copy.getType(), copy.coordinate == null ? null : new LatLongAlt(copy.coordinate)); } @Override diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Circle.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Circle.java index 79c339153d..ed54252db3 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Circle.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Circle.java @@ -2,7 +2,6 @@ import android.os.Parcel; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Land.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Land.java index fbd83ff574..5f6fb79081 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Land.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Land.java @@ -12,8 +12,7 @@ public class Land extends BaseSpatialItem implements android.os.Parcelable { public Land(){ - super(MissionItemType.LAND); - super.setCoordinate(new LatLongAlt(0.0, 0.0, 0.0)); + super(MissionItemType.LAND, new LatLongAlt(0.0, 0.0, 0.0)); } public Land(Land copy){ diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/RegionOfInterest.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/RegionOfInterest.java index a6c0ee486f..07e52afbb8 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/RegionOfInterest.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/RegionOfInterest.java @@ -2,12 +2,11 @@ import android.os.Parcel; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; /** - * Points the nose of the vehicle and camera gimbal at the “region of interest”. + * Points the nose of the vehicle and camera gimbal at the "region of interest". * Created by fhuya on 11/6/14. */ public class RegionOfInterest extends BaseSpatialItem implements android.os.Parcelable { diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/SplineWaypoint.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/SplineWaypoint.java index 408e36208b..3a67f512a7 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/SplineWaypoint.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/SplineWaypoint.java @@ -2,7 +2,6 @@ import android.os.Parcel; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Waypoint.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Waypoint.java index f1df71ae71..93dbc4990c 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Waypoint.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/mission/item/spatial/Waypoint.java @@ -2,7 +2,6 @@ import android.os.Parcel; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.mission.MissionItemType; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Battery.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Battery.java index b41870f507..93c751b316 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Battery.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Battery.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; /** * Created by fhuya on 10/28/14. diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/CameraProxy.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/CameraProxy.java index 4fef2a1f14..282bf0be86 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/CameraProxy.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/CameraProxy.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/FootPrint.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/FootPrint.java index 97320f1541..f47f9d19e2 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/FootPrint.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/FootPrint.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.util.MathUtils; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Parameter.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Parameter.java index d93e78a7a9..08ec729802 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Parameter.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Parameter.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; import java.text.DecimalFormat; import java.text.ParseException; @@ -114,14 +113,14 @@ public boolean hasInfo() { public double[] parseRange() throws ParseException { final DecimalFormat format = formatter; - final String[] parts = this.range.split(" "); - if (parts.length != 2) { + final String[] parts = this.range.split("( to |\\s+|-)"); + if (parts.length < 2) { throw new IllegalArgumentException(); } final double[] outRange = new double[2]; - outRange[RANGE_LOW] = format.parse(parts[RANGE_LOW]).doubleValue(); - outRange[RANGE_HIGH] = format.parse(parts[RANGE_HIGH]).doubleValue(); + outRange[RANGE_LOW] = format.parse(parts[0]).doubleValue(); + outRange[RANGE_HIGH] = format.parse(parts[outRange.length -1]).doubleValue(); return outRange; } diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/State.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/State.java index 53e3f0134b..237d5dd0e0 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/State.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/State.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Type.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Type.java index 814f244d36..1e1675f71b 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Type.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/Type.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; /** * Stores information about the drone's type. @@ -20,7 +19,7 @@ public static enum Firmware { private final String label; - private Firmware(String label){ + Firmware(String label){ this.label = label; } @@ -38,24 +37,23 @@ public Type(){} public Type(int droneType, String firmwareVersion){ this.droneType = droneType; this.firmwareVersion = firmwareVersion; + this.firmware = getTypeFirmware(droneType); + } + private static Firmware getTypeFirmware(int droneType) { switch(droneType){ case TYPE_COPTER: - firmware = Firmware.ARDU_COPTER; - break; + return Firmware.ARDU_COPTER; case TYPE_PLANE: - firmware = Firmware.ARDU_PLANE; - break; + return Firmware.ARDU_PLANE; case TYPE_ROVER: - firmware = Firmware.APM_ROVER; - break; + return Firmware.APM_ROVER; case TYPE_UNKNOWN: default: - firmware = null; - break; + return null; } } @@ -92,14 +90,16 @@ public int describeContents() { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.droneType); dest.writeString(this.firmwareVersion); - dest.writeInt(this.firmware == null ? -1 : this.firmware.ordinal()); + + // We're no longer passing the firmware ordinal since it'll be inferred from the drone type. + dest.writeInt(-1); } private Type(Parcel in) { - this.droneType = in.readInt(); - this.firmwareVersion = in.readString(); - int tmpFirmware = in.readInt(); - this.firmware = tmpFirmware == -1 ? null : Firmware.values()[tmpFirmware]; + this(in.readInt(), in.readString()); + + // Last value is the drone firmware ordinal, which is no longer of use. + in.readInt(); } public static final Creator CREATOR = new Creator() { diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/VehicleMode.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/VehicleMode.java index dd2b93232d..dda33e2ab0 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/VehicleMode.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/drone/property/VehicleMode.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.drone.property; import android.os.Parcel; -import android.os.Parcelable; import java.util.ArrayList; import java.util.List; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/gcs/link/LinkConnectionStatus.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/gcs/link/LinkConnectionStatus.java index e9f1c95980..a3f3bc6ea9 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/gcs/link/LinkConnectionStatus.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/gcs/link/LinkConnectionStatus.java @@ -7,6 +7,9 @@ import android.support.annotation.Nullable; import android.support.annotation.StringDef; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Conveys information about the link connection state. *

@@ -33,22 +36,30 @@ public final class LinkConnectionStatus implements Parcelable { */ public static final String EXTRA_CONNECTION_TIME = "extra_connection_time"; + /** + * The possible status codes that notifies what state the link connection is in. + */ @StringDef({ CONNECTED, CONNECTING, DISCONNECTED, FAILED }) - /** - * The possible status codes that notifies what state the link connection is in. - */ + @Retention(RetentionPolicy.SOURCE) public @interface StatusCode { } + public static final String CONNECTED = "CONNECTED"; public static final String CONNECTING = "CONNECTING"; public static final String DISCONNECTED = "DISCONNECTED"; public static final String FAILED = "FAILED"; + /** + * The possible failure codes that can be retrieved from the {@link #getExtras()} using key + * {@link #EXTRA_ERROR_CODE}. A {@link LinkConnectionStatus.FailureCode} + * is guaranteed when {@link #FAILED} occurs. + * + */ @IntDef({ SYSTEM_UNAVAILABLE, LINK_UNAVAILABLE, @@ -58,12 +69,7 @@ public final class LinkConnectionStatus implements Parcelable { ADDRESS_IN_USE, UNKNOWN }) - /** - * The possible failure codes that can be retrieved from the {@link #getExtras()} using key - * {@link #EXTRA_ERROR_CODE}. A {@link LinkConnectionStatus.FailureCode} - * is guaranteed when {@link #FAILED} occurs. - * - */ + @Retention(RetentionPolicy.SOURCE) public @interface FailureCode { } diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/util/MathUtils.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/MathUtils.java index bb9dcbb192..0bf46402c7 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/util/MathUtils.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/MathUtils.java @@ -204,7 +204,7 @@ public static double[][] dcmFromEuler(double roll, double pitch, double yaw) { * @param epsilon Tolerance for determining list of points for approximation of curve. * @return List of lat/long points in the approximated curve. */ - public static List simplify(List list, double epsilon) { + public static List simplify(List list, double epsilon) { int index = 0; double dmax = 0; int lastIndex = list.size() - 1; diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/util/UriUtils.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/UriUtils.java new file mode 100644 index 0000000000..a5b646e83a --- /dev/null +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/UriUtils.java @@ -0,0 +1,39 @@ +package com.o3dr.services.android.lib.util; + +import android.content.Context; +import android.net.Uri; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Created by fhuya on 8/13/2016. + */ +public class UriUtils { + + private UriUtils() { + } + + /** + * Retrieves an output stream from the given uri. + * + * @param uri + * @return + * @since 3.0.0 + */ + public static OutputStream getOutputStream(Context context, Uri uri) throws IOException { + return context.getContentResolver().openOutputStream(uri); + } + + /** + * Retrieves an input stream from the given uri. + * + * @param uri + * @return + * @since 3.0.0 + */ + public static InputStream getInputStream(Context context, Uri uri) throws IOException { + return context.getContentResolver().openInputStream(uri); + } +} diff --git a/ClientLib/src/main/java/com/o3dr/services/android/lib/util/version/VersionUtils.java b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/version/VersionUtils.java index 74939b8a56..2f7f75016a 100644 --- a/ClientLib/src/main/java/com/o3dr/services/android/lib/util/version/VersionUtils.java +++ b/ClientLib/src/main/java/com/o3dr/services/android/lib/util/version/VersionUtils.java @@ -1,7 +1,6 @@ package com.o3dr.services.android.lib.util.version; import android.content.Context; -import android.content.pm.PackageManager; import com.o3dr.android.client.R; @@ -10,6 +9,10 @@ */ public class VersionUtils { + /** + * @param context + * @return + */ public static int getCoreLibVersion(Context context){ return context.getResources().getInteger(R.integer.core_lib_version); } diff --git a/ServiceApp/src/org/droidplanner/services/android/api/DPServices.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DPServices.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/api/DPServices.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DPServices.java index 506008f8d9..a6f16f3ca7 100644 --- a/ServiceApp/src/org/droidplanner/services/android/api/DPServices.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DPServices.java @@ -1,9 +1,10 @@ -package org.droidplanner.services.android.api; +package org.droidplanner.services.android.impl.api; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; +import com.o3dr.android.client.BuildConfig; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.gcs.event.GCSEvent; import com.o3dr.services.android.lib.model.IApiListener; @@ -11,8 +12,7 @@ import com.o3dr.services.android.lib.model.IDroneApi; import com.o3dr.services.android.lib.util.version.VersionUtils; -import org.droidplanner.services.android.BuildConfig; -import org.droidplanner.services.android.core.drone.DroneManager; +import org.droidplanner.services.android.impl.core.drone.DroneManager; import java.util.ArrayList; import java.util.List; @@ -59,8 +59,7 @@ public Bundle[] getConnectedApps(String requesterId) throws RemoteException { DroneManager droneManager = droneApi.getDroneManager(); if(droneManager != null) { final ConnectionParameter droneParams = droneApi.getDroneManager().getConnectionParameter(); - final ConnectionParameter sanitizedParams = new ConnectionParameter(droneParams.getConnectionType(), - droneParams.getParamsBundle(), null); + final ConnectionParameter sanitizedParams = droneParams.clone(); Bundle info = new Bundle(); info.putString(GCSEvent.EXTRA_APP_ID, droneApi.getOwnerId()); diff --git a/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroidPlannerService.java similarity index 83% rename from ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroidPlannerService.java index 0af1887125..5d803b7e37 100644 --- a/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroidPlannerService.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.api; +package org.droidplanner.services.android.impl.api; import android.annotation.SuppressLint; import android.app.Notification; -import android.app.PendingIntent; import android.app.Service; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.os.Build; +import android.content.pm.PackageManager; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -14,18 +14,16 @@ import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; +import com.o3dr.android.client.R; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; import com.o3dr.services.android.lib.model.IApiListener; import com.o3dr.services.android.lib.model.IDroidPlannerServices; -import org.droidplanner.services.android.DroidPlannerServicesApp; -import org.droidplanner.services.android.R; -import org.droidplanner.services.android.core.drone.DroneManager; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.ui.activity.MainActivity; -import org.droidplanner.services.android.utils.Utils; -import org.droidplanner.services.android.utils.file.IO.CameraInfoLoader; +import org.droidplanner.services.android.impl.core.drone.DroneManager; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.utils.Utils; +import org.droidplanner.services.android.impl.utils.file.IO.CameraInfoLoader; import java.util.ArrayList; import java.util.List; @@ -34,13 +32,11 @@ import timber.log.Timber; /** - * 3DR Services background service implementation. + * DroneKit-Android background service implementation. */ public class DroidPlannerService extends Service { - private static final String TAG = DroidPlannerService.class.getName(); - - /** + /** * Status bar notification id */ private static final int FOREGROUND_ID = 101; @@ -69,7 +65,6 @@ public class DroidPlannerService extends Service { final ConcurrentHashMap droneManagers = new ConcurrentHashMap<>(); private DPServices dpServices; - private DroneAccess droneAccess; private CameraInfoLoader cameraInfoLoader; private List cachedCameraDetails; @@ -137,7 +132,7 @@ DroneManager connectDroneManager(ConnectionParameter connParams, String appId, D } Timber.d("Drone manager connection for " + appId); - droneMgr.connect(appId, listener); + droneMgr.connect(appId, listener, connParams); return droneMgr; } @@ -200,8 +195,7 @@ public IBinder onBind(Intent intent) { // Return binder to ipc client-server interaction. return dpServices; } else { - // Return binder to the service. - return droneAccess; + return null; } } @@ -210,14 +204,10 @@ public IBinder onBind(Intent intent) { public void onCreate() { super.onCreate(); - final DroidPlannerServicesApp dpApp = (DroidPlannerServicesApp) getApplication(); - dpApp.createFileStartLogging(); - - Timber.d("Creating 3DR Services."); + Timber.d("Creating DroneKit-Android."); final Context context = getApplicationContext(); - droneAccess = new DroneAccess(this); dpServices = new DPServices(this); lbm = LocalBroadcastManager.getInstance(context); this.cameraInfoLoader = new CameraInfoLoader(context); @@ -231,19 +221,13 @@ private void updateForegroundNotification() { //Put the service in the foreground final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) - .setContentTitle("3DR Services") + .setContentTitle("DroneKit-Android") .setPriority(NotificationCompat.PRIORITY_MIN) - .setSmallIcon(R.drawable.ic_stat_notify) - .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, - MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0)); + .setSmallIcon(R.drawable.ic_stat_notify); final int connectedCount = droneApiStore.size(); - if (connectedCount > 0) { - if (connectedCount == 1) { - notifBuilder.setContentText("1 connected app"); - } else { - notifBuilder.setContentText(connectedCount + " connected apps"); - } + if (connectedCount > 1) { + notifBuilder.setContentText(connectedCount + " connected apps"); } final Notification notification = notifBuilder.build(); @@ -253,7 +237,7 @@ private void updateForegroundNotification() { @Override public void onDestroy() { super.onDestroy(); - Timber.d("Destroying 3DR Services."); + Timber.d("Destroying DroneKit-Android."); for (DroneApi droneApi : droneApiStore.values()) { droneApi.destroy(); @@ -269,8 +253,8 @@ public void onDestroy() { stopForeground(true); - final DroidPlannerServicesApp dpApp = (DroidPlannerServicesApp) getApplication(); - dpApp.closeLogFile(); + //Disable this service. It'll be reenabled the next time its local client needs it. + enableDroidPlannerService(getApplicationContext(), false); } @Override @@ -290,4 +274,17 @@ public int onStartCommand(Intent intent, int flags, int startId) { return START_NOT_STICKY; } + /** + * Toggles the DroidPlannerService component + * @param context + * @param enable + */ + public static void enableDroidPlannerService(Context context, boolean enable){ + final ComponentName serviceComp = new ComponentName(context, DroidPlannerService.class); + final int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED + : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; + + context.getPackageManager().setComponentEnabledSetting(serviceComp, newState, PackageManager.DONT_KILL_APP); + } + } diff --git a/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroneApi.java similarity index 81% rename from ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroneApi.java index c3b30e17bd..0200ad0599 100644 --- a/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/api/DroneApi.java @@ -1,9 +1,12 @@ -package org.droidplanner.services.android.api; +package org.droidplanner.services.android.impl.api; import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; +import android.os.Looper; import android.os.RemoteException; import android.text.TextUtils; import android.util.Pair; @@ -12,8 +15,8 @@ import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.ardupilotmega.msg_mag_cal_progress; import com.MAVLink.ardupilotmega.msg_mag_cal_report; -import com.o3dr.services.android.lib.drone.action.CameraActions; import com.o3dr.services.android.lib.coordinate.LatLongAlt; +import com.o3dr.services.android.lib.drone.action.CameraActions; import com.o3dr.services.android.lib.drone.action.ConnectionActions; import com.o3dr.services.android.lib.drone.action.ExperimentalActions; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; @@ -21,7 +24,6 @@ import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; 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; import com.o3dr.services.android.lib.drone.mission.action.MissionActions; import com.o3dr.services.android.lib.drone.mission.item.MissionItem; @@ -42,24 +44,31 @@ import com.o3dr.services.android.lib.model.IObserver; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.communication.connection.SoloConnection; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneManager; -import org.droidplanner.services.android.core.drone.autopilot.Drone; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.variables.calibration.AccelCalibration; -import org.droidplanner.services.android.core.drone.variables.calibration.MagnetometerCalibrationImpl; -import org.droidplanner.services.android.exception.ConnectionException; -import org.droidplanner.services.android.utils.CommonApiUtils; -import org.droidplanner.services.android.utils.video.VideoManager; +import org.droidplanner.services.android.impl.communication.connection.SoloConnection; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.AccelCalibration; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.exception.ConnectionException; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.utils.MissionUtils; +import org.droidplanner.services.android.impl.utils.video.VideoManager; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentLinkedQueue; import timber.log.Timber; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.ACTION_SET_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_MISSION; +import static com.o3dr.services.android.lib.drone.mission.action.MissionActions.EXTRA_PUSH_TO_DRONE; + /** * Implementation for the IDroneApi interface. */ @@ -69,7 +78,36 @@ public final class DroneApi extends IDroneApi.Stub implements DroneInterfaces.On //The Reset ROI mission item was introduced in version 2.6.8. Any client library older than this do not support it. private final static int RESET_ROI_LIB_VERSION = 206080; + private final Runnable eventsDispatcher = new Runnable() { + private final LinkedHashMap eventsFilter = new LinkedHashMap<>(); + + @Override + public void run() { + eventsFilter.clear(); + //Go through the events buffer and empty it + EventInfo eventInfo = eventsBuffer.poll(); + while(eventInfo != null) { + eventsFilter.put(eventInfo.event, eventInfo.extras); + EventInfo.recycle(eventInfo); + + eventInfo = eventsBuffer.poll(); + } + + for(Map.Entry entry : eventsFilter.entrySet()){ + dispatchAttributeEvent(entry.getKey(), entry.getValue()); + } + + eventsFilter.clear(); + + handler.removeCallbacks(this); + if(isEventsBufferingEnabled()) { + handler.postDelayed(this, connectionParams.getEventsDispatchingPeriod()); + } + } + }; + private final Context context; + private final Handler handler; private final ConcurrentLinkedQueue observersList; private final ConcurrentLinkedQueue mavlinkObserversList; @@ -81,12 +119,15 @@ public final class DroneApi extends IDroneApi.Stub implements DroneInterfaces.On private final DroidPlannerService service; + private final ConcurrentLinkedQueue eventsBuffer = new ConcurrentLinkedQueue<>(); + private ConnectionParameter connectionParams; DroneApi(DroidPlannerService dpService, IApiListener listener, String ownerId) { this.service = dpService; this.context = dpService.getApplicationContext(); + handler = new Handler(Looper.getMainLooper()); this.ownerId = ownerId; @@ -140,6 +181,10 @@ private Drone getDrone() { return this.droneMgr.getDrone(); } + private boolean isEventsBufferingEnabled(){ + return connectionParams != null && connectionParams.getEventsDispatchingPeriod() > 0L; + } + @Override public Bundle getAttribute(String type) throws RemoteException { Bundle carrier = new Bundle(); @@ -190,7 +235,7 @@ private ConnectionParameter checkConnectionParameter(ConnectionParameter connPar } if (SoloConnection.isUdpSoloConnection(context, connParams)) { - ConnectionParameter update = SoloConnection.getSoloConnectionParameterFromUdp(context); + ConnectionParameter update = SoloConnection.getSoloConnectionParameterFromUdp(context, connParams); if (update != null) { return update; } @@ -219,6 +264,11 @@ public void connect(ConnectionParameter connParams) { this.connectionParams = connParams; this.droneMgr = service.connectDroneManager(this.connectionParams, ownerId, this); + + if(isEventsBufferingEnabled()) { + eventsBuffer.clear(); + handler.postDelayed(eventsDispatcher, this.connectionParams.getEventsDispatchingPeriod()); + } } } catch (ConnectionException e) { LinkConnectionStatus connectionStatus = LinkConnectionStatus @@ -233,6 +283,8 @@ public void disconnect() { this.connectionParams = null; this.droneMgr = null; + handler.removeCallbacks(eventsDispatcher); + } private void checkForSelfRelease() { @@ -350,6 +402,37 @@ public void executeAction(Action action, ICommandListener listener) throws Remot } break; + case MissionActions.ACTION_SAVE_MISSION: { + Mission mission = data.getParcelable(MissionActions.EXTRA_MISSION); + Uri saveUri = data.getParcelable(MissionActions.EXTRA_SAVE_MISSION_URI); + if (saveUri == null) { + CommonApiUtils.postErrorEvent(CommandExecutionError.COMMAND_FAILED, listener); + } else { + MissionUtils.saveMission(context, mission, saveUri, listener); + } + break; + } + + case MissionActions.ACTION_LOAD_MISSION: { + Uri loadUri = data.getParcelable(MissionActions.EXTRA_LOAD_MISSION_URI); + boolean setMission = data.getBoolean(MissionActions.EXTRA_SET_LOADED_MISSION, false); + if (loadUri != null) { + Mission mission = MissionUtils.loadMission(context, loadUri); + if(mission != null){ + // Going back to the caller. + data.putParcelable(MissionActions.EXTRA_MISSION, mission); + + if(setMission){ + Bundle params = new Bundle(); + params.putParcelable(EXTRA_MISSION, mission); + params.putBoolean(EXTRA_PUSH_TO_DRONE, false); + executeAction(new Action(ACTION_SET_MISSION, params), listener); + } + } + } + break; + } + default: if (droneMgr != null) { droneMgr.executeAsyncAction(clientInfo, action, listener); @@ -386,21 +469,31 @@ private void notifyAttributeUpdate(List> attributesInfo) { } private void notifyAttributeUpdate(String attributeEvent, Bundle extrasBundle) { - if (observersList.isEmpty()) { + if (observersList.isEmpty() || attributeEvent == null) { return; } - if (attributeEvent != null) { - for (IObserver observer : observersList) { + if(AttributeEvent.STATE_CONNECTED.equals(attributeEvent) || + AttributeEvent.STATE_DISCONNECTED.equals(attributeEvent) || + !isEventsBufferingEnabled()){ + //Dispatch the event immediately + dispatchAttributeEvent(attributeEvent, extrasBundle); + } + else{ + eventsBuffer.add(EventInfo.obtain(attributeEvent, extrasBundle)); + } + } + + private void dispatchAttributeEvent(String attributeEvent, Bundle extrasBundle){ + for (IObserver observer : observersList) { + try { + observer.onAttributeUpdated(attributeEvent, extrasBundle); + } catch (RemoteException e) { + Timber.e(e, e.getMessage()); try { - observer.onAttributeUpdated(attributeEvent, extrasBundle); - } catch (RemoteException e) { - Timber.e(e, e.getMessage()); - try { - removeAttributesObserver(observer); - } catch (RemoteException e1) { - Timber.e(e, e1.getMessage()); - } + removeAttributesObserver(observer); + } catch (RemoteException e1) { + Timber.e(e, e1.getMessage()); } } } @@ -440,7 +533,7 @@ public ClientInfo getClientInfo() { } @Override - public void onAttributeEvent(String attributeEvent, Bundle eventInfo, boolean checkForSololinkApi) { + public void onAttributeEvent(String attributeEvent, Bundle eventInfo) { if (TextUtils.isEmpty(attributeEvent)) { return; } @@ -468,6 +561,9 @@ public void onDroneEvent(DroneInterfaces.DroneEventsType event, Drone drone) { .putExtra(GCSEvent.EXTRA_APP_ID, ownerId)); droneEvent = AttributeEvent.STATE_DISCONNECTED; + + //Empty the event buffer queue + eventsBuffer.clear(); break; case GUIDEDPOINT: @@ -581,8 +677,7 @@ public void onDroneEvent(DroneInterfaces.DroneEventsType event, Drone drone) { case CONNECTED: //Broadcast the vehicle connection. - ConnectionParameter sanitizedParameter = new ConnectionParameter(connectionParams - .getConnectionType(), connectionParams.getParamsBundle()); + ConnectionParameter sanitizedParameter = connectionParams.clone(); context.sendBroadcast(new Intent(GCSEvent.ACTION_VEHICLE_CONNECTION) .putExtra(GCSEvent.EXTRA_APP_ID, ownerId) @@ -683,11 +778,8 @@ public void onConnectionStatus(LinkConnectionStatus connectionStatus) { case LinkConnectionStatus.FAILED: disconnect(); checkForSelfRelease(); - - //This is to ensure backwards compatibility - // TODO: remove this in version 3.0 - notifyConnectionFailed(connectionStatus); break; + case LinkConnectionStatus.DISCONNECTED: disconnect(); checkForSelfRelease(); @@ -700,22 +792,6 @@ public void onConnectionStatus(LinkConnectionStatus connectionStatus) { } - private void notifyConnectionFailed(LinkConnectionStatus connectionStatus) { - Bundle extras = connectionStatus.getExtras(); - String msg = null; - if (extras != null) { - msg = extras.getString(LinkConnectionStatus.EXTRA_ERROR_MSG); - } - - ConnectionResult connectionResult = new ConnectionResult(0, msg); - try { - apiListener.onConnectionFailed(connectionResult); - } catch (RemoteException e) { - Timber.w(e, "Unable to forward connection fail to client."); - } - - } - @Override public void binderDied() { checkForSelfRelease(); @@ -756,4 +832,31 @@ public ClientInfo(String appId, int apiVersionCode, int clientVersionCode) { this.clientVersionCode = clientVersionCode; } } + + private static class EventInfo { + + private static final ConcurrentLinkedQueue sPool = new ConcurrentLinkedQueue<>(); + + String event; + Bundle extras; + + static EventInfo obtain(String event, Bundle extras){ + EventInfo eventInfo = sPool.poll(); + if(eventInfo == null){ + eventInfo = new EventInfo(); + } + + eventInfo.event = event; + eventInfo.extras = extras; + return eventInfo; + } + + static void recycle(EventInfo eventInfo){ + if(eventInfo != null) { + eventInfo.event = null; + eventInfo.extras = null; + sPool.offer(eventInfo); + } + } + } } diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidIpConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidIpConnection.java similarity index 65% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidIpConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidIpConnection.java index ea1af2a85b..93c692495e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidIpConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidIpConnection.java @@ -1,8 +1,9 @@ -package org.droidplanner.services.android.communication.connection; +package org.droidplanner.services.android.impl.communication.connection; import android.content.Context; +import android.os.Bundle; -import org.droidplanner.services.android.utils.connection.WifiConnectionHandler; +import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler; import java.io.IOException; @@ -13,24 +14,20 @@ public abstract class AndroidIpConnection extends AndroidMavLinkConnection { private final WifiConnectionHandler wifiHandler; - public AndroidIpConnection(Context applicationContext) { - this(applicationContext, null); - } - protected AndroidIpConnection(Context context, WifiConnectionHandler wifiHandler){ super(context); this.wifiHandler = wifiHandler; } @Override - protected final void openConnection() throws IOException { + protected final void openConnection(Bundle connectionExtras) throws IOException { if(this.wifiHandler != null) { this.wifiHandler.start(); } - onOpenConnection(); + onOpenConnection(connectionExtras); } - protected abstract void onOpenConnection() throws IOException; + protected abstract void onOpenConnection(Bundle extras) throws IOException; @Override protected final void closeConnection() throws IOException { diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidMavLinkConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidMavLinkConnection.java new file mode 100644 index 0000000000..43c4a8878a --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidMavLinkConnection.java @@ -0,0 +1,20 @@ +package org.droidplanner.services.android.impl.communication.connection; + +import android.content.Context; + +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnection; +import org.droidplanner.services.android.impl.core.model.Logger; +import org.droidplanner.services.android.impl.utils.AndroidLogger; + +public abstract class AndroidMavLinkConnection extends MavLinkConnection { + + + public AndroidMavLinkConnection(Context applicationContext) { + super(applicationContext); + } + + @Override + protected final Logger initLogger() { + return AndroidLogger.getLogger(); + } +} diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidTcpConnection.java similarity index 75% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidTcpConnection.java index 54b37879e4..b7954ccebb 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidTcpConnection.java @@ -1,12 +1,13 @@ -package org.droidplanner.services.android.communication.connection; +package org.droidplanner.services.android.impl.communication.connection; import android.content.Context; +import android.os.Bundle; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.core.MAVLink.connection.TcpConnection; -import org.droidplanner.services.android.core.model.Logger; -import org.droidplanner.services.android.utils.connection.WifiConnectionHandler; +import org.droidplanner.services.android.impl.core.MAVLink.connection.TcpConnection; +import org.droidplanner.services.android.impl.core.model.Logger; +import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler; import java.io.IOException; @@ -23,7 +24,7 @@ public AndroidTcpConnection(Context context, String tcpServerIp, int tcpServerPo this.serverIp = tcpServerIp; this.serverPort = tcpServerPort; - mConnectionImpl = new TcpConnection() { + mConnectionImpl = new TcpConnection(context) { @Override protected int loadServerPort() { return serverPort; @@ -40,8 +41,8 @@ protected Logger initLogger() { } @Override - protected void onConnectionOpened() { - AndroidTcpConnection.this.onConnectionOpened(); + protected void onConnectionOpened(Bundle extras) { + AndroidTcpConnection.this.onConnectionOpened(extras); } @Override @@ -66,8 +67,8 @@ protected void loadPreferences() { } @Override - protected void onOpenConnection() throws IOException { - mConnectionImpl.openConnection(); + protected void onOpenConnection(Bundle extras) throws IOException { + mConnectionImpl.openConnection(extras); } @Override diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidUdpConnection.java similarity index 87% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidUdpConnection.java index 98103e94b3..c23d886ab8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/AndroidUdpConnection.java @@ -1,13 +1,14 @@ -package org.droidplanner.services.android.communication.connection; +package org.droidplanner.services.android.impl.communication.connection; import android.content.Context; +import android.os.Bundle; import android.util.Log; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.core.MAVLink.connection.UdpConnection; -import org.droidplanner.services.android.core.model.Logger; -import org.droidplanner.services.android.utils.connection.WifiConnectionHandler; +import org.droidplanner.services.android.impl.core.MAVLink.connection.UdpConnection; +import org.droidplanner.services.android.impl.core.model.Logger; +import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler; import java.io.IOException; import java.net.InetAddress; @@ -31,7 +32,7 @@ public AndroidUdpConnection(Context context, int udpServerPort, WifiConnectionHa super(context, wifiHandler); this.serverPort = udpServerPort; - mConnectionImpl = new UdpConnection() { + mConnectionImpl = new UdpConnection(context) { @Override protected int loadServerPort() { return serverPort; @@ -43,8 +44,8 @@ protected Logger initLogger() { } @Override - protected void onConnectionOpened() { - AndroidUdpConnection.this.onConnectionOpened(); + protected void onConnectionOpened(Bundle extras) { + AndroidUdpConnection.this.onConnectionOpened(extras); } @Override @@ -88,9 +89,9 @@ protected void loadPreferences() { } @Override - protected void onOpenConnection() throws IOException { + protected void onOpenConnection(Bundle extras) throws IOException { Log.d(TAG, "Opening udp connection"); - mConnectionImpl.openConnection(); + mConnectionImpl.openConnection(extras); if (pingRunner == null || pingRunner.isShutdown()) pingRunner = Executors.newSingleThreadScheduledExecutor(); diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/BluetoothConnection.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/BluetoothConnection.java index 99ddfd4ba1..807cb75f0c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/BluetoothConnection.java @@ -1,14 +1,15 @@ -package org.droidplanner.services.android.communication.connection; +package org.droidplanner.services.android.impl.communication.connection; import android.annotation.SuppressLint; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Context; +import android.os.Bundle; import android.os.ParcelUuid; import android.util.Log; -import org.droidplanner.services.android.core.MAVLink.connection.MavLinkConnectionTypes; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnectionTypes; import java.io.IOException; import java.io.InputStream; @@ -38,7 +39,7 @@ public BluetoothConnection(Context parentContext, String btAddress) { } @Override - protected void openConnection() throws IOException { + protected void openConnection(Bundle connectionExtras) throws IOException { Log.d(BLUE, "Connect"); // Reset the bluetooth connection @@ -74,7 +75,7 @@ protected void openConnection() throws IOException { out = bluetoothSocket.getOutputStream(); in = bluetoothSocket.getInputStream(); - onConnectionOpened(); + onConnectionOpened(connectionExtras); } @SuppressLint("NewApi") @@ -90,7 +91,6 @@ private BluetoothDevice findSerialBluetoothBoard() throws UnknownHostException { final ParcelUuid[] deviceUuids = device.getUuids(); if (deviceUuids != null && deviceUuids.length > 0) { for (ParcelUuid id : device.getUuids()) { - // TODO maybe this will not work on newer devices Log.d(BLUE, "id:" + id.toString()); if (id.toString().equalsIgnoreCase(UUID_SPP_DEVICE)) { Log.d(BLUE, @@ -149,6 +149,5 @@ private void resetConnection() throws IOException { @Override protected void loadPreferences() { - // TODO Auto-generated method stub } } diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/SoloConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/SoloConnection.java similarity index 85% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/SoloConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/SoloConnection.java index cee0bbdee6..8ca911cea7 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/SoloConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/SoloConnection.java @@ -1,6 +1,7 @@ -package org.droidplanner.services.android.communication.connection; +package org.droidplanner.services.android.impl.communication.connection; import android.content.Context; +import android.net.Uri; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -10,9 +11,10 @@ import com.o3dr.services.android.lib.drone.connection.ConnectionType; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.utils.connection.WifiConnectionHandler; +import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler; import java.io.IOException; +import java.sql.Connection; import java.util.List; import timber.log.Timber; @@ -39,8 +41,8 @@ public SoloConnection(Context applicationContext, String soloLinkId, String pass this.soloLinkPassword = password; this.dataLink = new AndroidUdpConnection(applicationContext, SOLO_UDP_PORT) { @Override - protected void onConnectionOpened() { - SoloConnection.this.onConnectionOpened(); + protected void onConnectionOpened(Bundle extras) { + SoloConnection.this.onConnectionOpened(extras); } @Override @@ -51,7 +53,7 @@ protected void onConnectionStatus(LinkConnectionStatus connectionStatus) { } @Override - protected void openConnection() throws IOException { + protected void openConnection(Bundle connectionExtras) throws IOException { if (TextUtils.isEmpty(soloLinkId)) { LinkConnectionStatus connectionStatus = LinkConnectionStatus .newFailedConnectionStatus(LinkConnectionStatus.INVALID_CREDENTIALS, "Invalid connection credentials!"); @@ -97,13 +99,13 @@ public int getConnectionType() { } @Override - public void onWifiConnected(String wifiSsid) { + public void onWifiConnected(String wifiSsid, Bundle extras) { if (isConnecting()) { //Let's see if we're connected to our target wifi if (wifiSsid.equalsIgnoreCase(soloLinkId)) { //We're good to go try { - dataLink.openConnection(); + dataLink.openConnection(extras); } catch (IOException e) { reportIOException(e); Timber.e(e, e.getMessage()); @@ -151,7 +153,14 @@ private void checkScanResults(List results) { if (targetResult != null) { //We're good to go try { - int connectionResult = wifiHandler.connectToWifi(targetResult, soloLinkPassword); + Bundle connectInfo = new Bundle(); + Bundle extras = getConnectionExtras(); + if (extras != null && !extras.isEmpty()) { + connectInfo.putAll(extras); + } + connectInfo.putParcelable(WifiConnectionHandler.EXTRA_SCAN_RESULT, targetResult); + connectInfo.putString(WifiConnectionHandler.EXTRA_SSID_PASSWORD, soloLinkPassword); + int connectionResult = wifiHandler.connectToWifi(connectInfo); if (connectionResult != 0) { @LinkConnectionStatus.FailureCode int failureCode = connectionResult; LinkConnectionStatus connectionStatus = LinkConnectionStatus @@ -193,13 +202,13 @@ public static boolean isUdpSoloConnection(Context context, ConnectionParameter c } } - public static ConnectionParameter getSoloConnectionParameterFromUdp(Context context){ + public static ConnectionParameter getSoloConnectionParameterFromUdp(Context context, ConnectionParameter udpConnectionParameters){ if(context == null) return null; final String wifiSsid = WifiConnectionHandler.getCurrentWifiLink((WifiManager) context.getSystemService(Context.WIFI_SERVICE)); if(WifiConnectionHandler.isSoloWifi(wifiSsid)){ - return ConnectionParameter.newSoloConnection(wifiSsid, null); + return ConnectionParameter.newSoloConnection(wifiSsid, null, udpConnectionParameters.getTLogLoggingUri(), udpConnectionParameters.getEventsDispatchingPeriod()); } return null; diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbCDCConnection.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbCDCConnection.java index ca48297c77..b75eae65fd 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbCDCConnection.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.communication.connection.usb; +package org.droidplanner.services.android.impl.communication.connection.usb; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -7,10 +7,12 @@ import android.content.IntentFilter; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; +import android.os.Bundle; import android.util.Log; import com.hoho.android.usbserial.driver.UsbSerialDriver; import com.hoho.android.usbserial.driver.UsbSerialProber; + import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import java.io.IOException; @@ -44,7 +46,7 @@ public void onReceive(Context context, Intent intent) { if (device != null) { //call method to set up device communication try { - openUsbDevice(device); + openUsbDevice(device, extrasHolder.get()); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } @@ -75,6 +77,7 @@ public void run() { } }; + private final AtomicReference extrasHolder = new AtomicReference<>(); private ScheduledExecutorService scheduler; protected UsbCDCConnection(Context context, UsbConnection parentConn, int baudRate) { @@ -102,7 +105,8 @@ private void removeWatchdog() { } @Override - protected void openUsbConnection() throws IOException { + protected void openUsbConnection(Bundle extras) throws IOException { + extrasHolder.set(extras); registerUsbPermissionBroadcastReceiver(); // Get UsbManager from Android. @@ -118,7 +122,7 @@ protected void openUsbConnection() throws IOException { //Pick the first device UsbDevice device = availableDevices.get(0); if (manager.hasPermission(device)) { - openUsbDevice(device); + openUsbDevice(device, extras); } else { removeWatchdog(); @@ -129,7 +133,7 @@ protected void openUsbConnection() throws IOException { } } - private void openUsbDevice(UsbDevice device) throws IOException { + private void openUsbDevice(UsbDevice device, Bundle extras) throws IOException { // Get UsbManager from Android. UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); @@ -147,7 +151,7 @@ private void openUsbDevice(UsbDevice device) throws IOException { serialDriverRef.set(serialDriver); - onUsbConnectionOpened(); + onUsbConnectionOpened(extras); } catch (IOException e) { Log.e(TAG, "Error setting up device: " + e.getMessage(), e); try { diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbConnection.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbConnection.java index 00e389ce69..4cc26490b1 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbConnection.java @@ -1,16 +1,17 @@ -package org.droidplanner.services.android.communication.connection.usb; +package org.droidplanner.services.android.impl.communication.connection.usb; import android.content.Context; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; +import android.os.Bundle; import android.util.Log; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.communication.connection.AndroidMavLinkConnection; -import org.droidplanner.services.android.core.MAVLink.connection.MavLinkConnectionTypes; -import org.droidplanner.services.android.core.model.Logger; -import org.droidplanner.services.android.utils.AndroidLogger; +import org.droidplanner.services.android.impl.communication.connection.AndroidMavLinkConnection; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnectionTypes; +import org.droidplanner.services.android.impl.core.model.Logger; +import org.droidplanner.services.android.impl.utils.AndroidLogger; import java.io.IOException; import java.util.HashMap; @@ -43,10 +44,10 @@ protected void loadPreferences() { } @Override - protected void openConnection() throws IOException { + protected void openConnection(Bundle connectionExtras) throws IOException { if (mUsbConnection != null) { try { - mUsbConnection.openUsbConnection(); + mUsbConnection.openUsbConnection(connectionExtras); Log.d(TAG, "Reusing previous usb connection."); return; } catch (IOException e) { @@ -55,10 +56,10 @@ protected void openConnection() throws IOException { } } - if (isFTDIdevice(mContext)) { - final UsbConnectionImpl tmp = new UsbFTDIConnection(mContext, this, mBaudRate); + if (isFTDIdevice(context)) { + final UsbConnectionImpl tmp = new UsbFTDIConnection(context, this, mBaudRate); try { - tmp.openUsbConnection(); + tmp.openUsbConnection(connectionExtras); // If the call above is successful, 'mUsbConnection' will be set. mUsbConnection = tmp; @@ -71,10 +72,10 @@ protected void openConnection() throws IOException { // Fallback if (mUsbConnection == null) { - final UsbConnectionImpl tmp = new UsbCDCConnection(mContext, this, mBaudRate); + final UsbConnectionImpl tmp = new UsbCDCConnection(context, this, mBaudRate); // If an error happens here, let it propagate up the call chain since this is the fallback. - tmp.openUsbConnection(); + tmp.openUsbConnection(connectionExtras); mUsbConnection = tmp; Log.d(TAG, "Using open-source usb connection."); } @@ -139,8 +140,8 @@ protected UsbConnectionImpl(Context context, UsbConnection parentConn, int baudR mBaudRate = baudRate; } - protected void onUsbConnectionOpened() { - parentConnection.onConnectionOpened(); + protected void onUsbConnectionOpened(Bundle extras) { + parentConnection.onConnectionOpened(extras); } protected void onUsbConnectionStatus(LinkConnectionStatus connectionStatus) { @@ -149,7 +150,7 @@ protected void onUsbConnectionStatus(LinkConnectionStatus connectionStatus) { protected abstract void closeUsbConnection() throws IOException; - protected abstract void openUsbConnection() throws IOException; + protected abstract void openUsbConnection(Bundle extras) throws IOException; protected abstract int readDataBlock(byte[] readData) throws IOException; diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbFTDIConnection.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbFTDIConnection.java index ae628d6e7b..841627dcd4 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/connection/usb/UsbFTDIConnection.java @@ -1,14 +1,15 @@ -package org.droidplanner.services.android.communication.connection.usb; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicReference; +package org.droidplanner.services.android.impl.communication.connection.usb; import android.content.Context; +import android.os.Bundle; import android.util.Log; import com.ftdi.j2xx.D2xxManager; import com.ftdi.j2xx.FT_Device; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicReference; + class UsbFTDIConnection extends UsbConnection.UsbConnectionImpl { private static final String TAG = UsbFTDIConnection.class.getSimpleName(); @@ -22,7 +23,7 @@ protected UsbFTDIConnection(Context context, UsbConnection parentConn, int baudR } @Override - protected void openUsbConnection() throws IOException { + protected void openUsbConnection(Bundle extras) throws IOException { D2xxManager ftD2xx = null; try { ftD2xx = D2xxManager.getInstance(mContext); @@ -70,7 +71,7 @@ protected void openUsbConnection() throws IOException { ftDevRef.set(ftDev); - onUsbConnectionOpened(); + onUsbConnectionOpened(extras); } @Override diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/model/DataLink.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/model/DataLink.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/communication/model/DataLink.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/model/DataLink.java index 62ac365510..2a9d409b76 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/model/DataLink.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/model/DataLink.java @@ -1,4 +1,6 @@ -package org.droidplanner.services.android.communication.model; +package org.droidplanner.services.android.impl.communication.model; + +import android.os.Bundle; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.model.ICommandListener; @@ -15,6 +17,8 @@ public interface DataLinkProvider { void closeConnection(); + Bundle getConnectionExtras(); + } public interface DataLinkListener { diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/service/MAVLinkClient.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/service/MAVLinkClient.java index a646e9b893..e6a904c2e2 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/communication/service/MAVLinkClient.java @@ -1,38 +1,31 @@ -package org.droidplanner.services.android.communication.service; +package org.droidplanner.services.android.impl.communication.service; import android.content.Context; +import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import com.MAVLink.MAVLinkPacket; import com.MAVLink.Messages.MAVLinkMessage; -import com.google.android.gms.analytics.HitBuilders; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.drone.connection.ConnectionType; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.communication.connection.AndroidMavLinkConnection; -import org.droidplanner.services.android.communication.connection.AndroidTcpConnection; -import org.droidplanner.services.android.communication.connection.AndroidUdpConnection; -import org.droidplanner.services.android.communication.connection.BluetoothConnection; -import org.droidplanner.services.android.communication.connection.SoloConnection; -import org.droidplanner.services.android.communication.connection.usb.UsbConnection; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.MAVLink.connection.MavLinkConnection; -import org.droidplanner.services.android.core.MAVLink.connection.MavLinkConnectionListener; -import org.droidplanner.services.android.core.MAVLink.connection.MavLinkConnectionTypes; -import org.droidplanner.services.android.core.drone.manager.DroneCommandTracker; -import org.droidplanner.services.android.data.SessionDB; -import org.droidplanner.services.android.utils.analytics.GAUtils; -import org.droidplanner.services.android.utils.connection.WifiConnectionHandler; -import org.droidplanner.services.android.utils.file.DirectoryPath; -import org.droidplanner.services.android.utils.file.FileUtils; - -import java.io.File; +import org.droidplanner.services.android.impl.communication.connection.AndroidMavLinkConnection; +import org.droidplanner.services.android.impl.communication.connection.AndroidTcpConnection; +import org.droidplanner.services.android.impl.communication.connection.AndroidUdpConnection; +import org.droidplanner.services.android.impl.communication.connection.BluetoothConnection; +import org.droidplanner.services.android.impl.communication.connection.SoloConnection; +import org.droidplanner.services.android.impl.communication.connection.usb.UsbConnection; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnection; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnectionListener; +import org.droidplanner.services.android.impl.core.drone.manager.DroneCommandTracker; +import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler; + import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.Date; import timber.log.Timber; @@ -44,8 +37,6 @@ public class MAVLinkClient implements DataLink.DataLinkProvider private static final int DEFAULT_SYS_ID = 255; private static final int DEFAULT_COMP_ID = 190; - private static final String TLOG_PREFIX = "log"; - /** * Maximum possible sequence number for a packet. */ @@ -66,16 +57,6 @@ public void onConnectionStatus(final LinkConnectionStatus connectionStatus) { case LinkConnectionStatus.DISCONNECTED: closeConnection(); break; - - case LinkConnectionStatus.CONNECTED: - Bundle extras = connectionStatus.getExtras(); - if (extras != null) { - long connectionTime = extras.getLong(LinkConnectionStatus.EXTRA_CONNECTION_TIME); - if (connectionTime != 0) { - startLoggingThread(connectionTime); - } - } - break; } } }; @@ -83,7 +64,6 @@ public void onConnectionStatus(final LinkConnectionStatus connectionStatus) { private AndroidMavLinkConnection mavlinkConn; private final DataLink.DataLinkListener listener; - private final SessionDB sessionDB; private final Context context; private int packetSeqNumber = 0; @@ -101,8 +81,6 @@ public MAVLinkClient(Context context, DataLink.DataLinkListener l } this.connParams = connParams; - this.sessionDB = new SessionDB(context); - this.commandTracker = commandTracker; } @@ -195,13 +173,7 @@ public synchronized void openConnection() { } if (mavlinkConn.getConnectionStatus() == MavLinkConnection.MAVLINK_DISCONNECTED) { - mavlinkConn.connect(); - - // Record which connection type is used. - GAUtils.sendEvent(new HitBuilders.EventBuilder() - .setCategory(GAUtils.Category.MAVLINK_CONNECTION) - .setAction("MavLink connect") - .setLabel(connParams.toString())); + mavlinkConn.connect(null); } } @@ -217,17 +189,20 @@ public synchronized void closeConnection() { if(mavlinkConn.getMavLinkConnectionListenersCount() == 0){ Timber.i("Disconnecting..."); mavlinkConn.disconnect(); - GAUtils.sendEvent(new HitBuilders.EventBuilder() - .setCategory(GAUtils.Category.MAVLINK_CONNECTION) - .setAction("MavLink disconnect") - .setLabel(connParams.toString())); } - stopLoggingThread(System.currentTimeMillis()); - listener.onConnectionStatus(new LinkConnectionStatus(LinkConnectionStatus.DISCONNECTED, null)); } + @Override + public Bundle getConnectionExtras() { + if (mavlinkConn == null) { + return null; + } + + return mavlinkConn.getConnectionExtras(); + } + @Override public synchronized void sendMessage(MAVLinkMessage message, ICommandListener listener) { sendMavMessage(message, DEFAULT_SYS_ID, DEFAULT_COMP_ID, listener); @@ -265,28 +240,17 @@ private boolean isConnecting(){ return getConnectionStatus() == MavLinkConnection.MAVLINK_CONNECTING; } - private File getTLogDir(String appId) { - return DirectoryPath.getTLogPath(this.context, appId); - } - - private File getTempTLogFile(String appId, long connectionTimestamp) { - return new File(getTLogDir(appId), getTLogFilename(connectionTimestamp)); - } - - private String getTLogFilename(long connectionTimestamp) { - return TLOG_PREFIX + "_" + MavLinkConnectionTypes.getConnectionTypeLabel(this.connParams.getConnectionType()) + - "_" + FileUtils.getTimeStamp(connectionTimestamp) + FileUtils.TLOG_FILENAME_EXT; - } - /** * Register a log listener. * * @param appId Tag for the listener. */ - public synchronized void addLoggingFile(String appId){ - if(isConnecting() || isConnected()) { - final File logFile = getTempTLogFile(appId, System.currentTimeMillis()); - mavlinkConn.addLoggingPath(appId, logFile.getAbsolutePath()); + public synchronized void registerForTLogLogging(String appId, Uri tlogLoggingUri){ + if(tlogLoggingUri == null) + return; + + if (isConnecting() || isConnected()) { + mavlinkConn.addLoggingPath(appId, tlogLoggingUri); } } @@ -295,21 +259,10 @@ public synchronized void addLoggingFile(String appId){ * * @param appId Tag for the listener. */ - public synchronized void removeLoggingFile(String appId){ + public synchronized void unregisterForTLogLogging(String appId){ if(isConnecting() || isConnected()){ mavlinkConn.removeLoggingPath(appId); } } - private void startLoggingThread(long startTime) { - //log into the database the connection time. - final String connectionType = MavLinkConnectionTypes.getConnectionTypeLabel(connParams.getConnectionType()); - this.sessionDB.startSession(new Date(startTime), connectionType); - } - - private void stopLoggingThread(long stopTime) { - //log into the database the disconnection time. - final String connectionType = MavLinkConnectionTypes.getConnectionTypeLabel(connParams.getConnectionType()); - this.sessionDB.endSession(new Date(stopTime), connectionType, new Date()); - } } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCalibration.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCalibration.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCalibration.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCalibration.java index 7d863bcad2..a75893ddb8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCalibration.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCalibration.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.MAVLink; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_command_ack; import com.MAVLink.common.msg_command_long; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_CMD_ACK; -import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import com.o3dr.services.android.lib.model.ICommandListener; public class MavLinkCalibration { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCommands.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCommands.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCommands.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCommands.java index 4c17097660..d05ca227ef 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkCommands.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkCommands.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.MAVLink; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_command_long; import com.MAVLink.common.msg_manual_control; @@ -11,8 +11,8 @@ import com.MAVLink.enums.MAV_GOTO; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; public class MavLinkCommands { @@ -38,7 +38,7 @@ public static void setGuidedMode(MavLinkDrone drone, double latitude, double lon msg_mission_item msg = new msg_mission_item(); msg.seq = 0; msg.current = 2; // TODO use guided mode enum - msg.frame = MAV_FRAME.MAV_FRAME_GLOBAL; + msg.frame = MAV_FRAME.MAV_FRAME_GLOBAL_RELATIVE_ALT; msg.command = MAV_CMD.MAV_CMD_NAV_WAYPOINT; // msg.param1 = 0; // TODO use correct parameter msg.param2 = 0; // TODO use correct parameter diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkMsgHandler.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkMsgHandler.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkMsgHandler.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkMsgHandler.java index 899fcd0ac8..ee18e77ff8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkMsgHandler.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkMsgHandler.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.MAVLink; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.common.msg_heartbeat; import com.MAVLink.enums.MAV_AUTOPILOT; import com.MAVLink.enums.MAV_TYPE; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; /** * Parse the received mavlink messages, and update the drone state appropriately. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkParameters.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkParameters.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkParameters.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkParameters.java index 49be088377..48bc7aa7c9 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkParameters.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkParameters.java @@ -1,10 +1,10 @@ -package org.droidplanner.services.android.core.MAVLink; - -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_param_request_list; import com.MAVLink.common.msg_param_request_read; import com.MAVLink.common.msg_param_set; + +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.drone.property.Parameter; public class MavLinkParameters { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkRC.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkRC.java similarity index 82% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkRC.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkRC.java index 95353ba0d1..32b67b21b8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkRC.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkRC.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.core.MAVLink; - -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_rc_channels_override; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + public class MavLinkRC { public static void sendRcOverrideMsg(MavLinkDrone drone, int[] rcOutputs) { msg_rc_channels_override msg = new msg_rc_channels_override(); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkStreamRates.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkStreamRates.java similarity index 91% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkStreamRates.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkStreamRates.java index 664e0ef525..be88535b79 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkStreamRates.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkStreamRates.java @@ -1,10 +1,10 @@ -package org.droidplanner.services.android.core.MAVLink; - -import org.droidplanner.services.android.communication.model.DataLink.DataLinkProvider; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_request_data_stream; import com.MAVLink.enums.MAV_DATA_STREAM; +import org.droidplanner.services.android.impl.communication.model.DataLink.DataLinkProvider; + public class MavLinkStreamRates { public static void setupStreamRates(DataLinkProvider MAVClient, byte sysid, byte compid, diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkWaypoint.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkWaypoint.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkWaypoint.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkWaypoint.java index bba32dc2f0..a7d8fb49d3 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/MavLinkWaypoint.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/MavLinkWaypoint.java @@ -1,6 +1,4 @@ -package org.droidplanner.services.android.core.MAVLink; - -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.MAVLink; import com.MAVLink.common.msg_mission_ack; import com.MAVLink.common.msg_mission_count; @@ -9,6 +7,8 @@ import com.MAVLink.common.msg_mission_set_current; import com.MAVLink.enums.MAV_MISSION_RESULT; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + public class MavLinkWaypoint { public static void sendAck(MavLinkDrone drone) { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/WaypointManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/WaypointManager.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/WaypointManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/WaypointManager.java index a007ce2caa..92b2520f70 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/WaypointManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/WaypointManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.MAVLink; +package org.droidplanner.services.android.impl.core.MAVLink; import android.os.Handler; @@ -10,9 +10,9 @@ import com.MAVLink.common.msg_mission_item_reached; import com.MAVLink.common.msg_mission_request; -import org.droidplanner.services.android.core.drone.DroneInterfaces.OnWaypointManagerListener; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnWaypointManagerListener; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import java.util.ArrayList; import java.util.List; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/command/doCmd/MavLinkDoCmds.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/command/doCmd/MavLinkDoCmds.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/command/doCmd/MavLinkDoCmds.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/command/doCmd/MavLinkDoCmds.java index ed00aba64b..b1d41d87f8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/command/doCmd/MavLinkDoCmds.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/command/doCmd/MavLinkDoCmds.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.MAVLink.command.doCmd; +package org.droidplanner.services.android.impl.core.MAVLink.command.doCmd; import com.MAVLink.ardupilotmega.msg_digicam_control; import com.MAVLink.ardupilotmega.msg_mount_control; @@ -6,11 +6,11 @@ import com.MAVLink.common.msg_mission_set_current; import com.MAVLink.enums.GRIPPER_ACTIONS; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - public class MavLinkDoCmds { public static void setVehicleHome(MavLinkDrone drone, LatLongAlt location, ICommandListener listener){ diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnection.java similarity index 88% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnection.java index 857242c1e3..c51f2143d8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnection.java @@ -1,16 +1,18 @@ -package org.droidplanner.services.android.core.MAVLink.connection; +package org.droidplanner.services.android.impl.core.MAVLink.connection; +import android.content.Context; +import android.net.Uri; import android.os.Bundle; import android.support.v4.util.Pair; import com.MAVLink.MAVLinkPacket; import com.MAVLink.Parser; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; +import com.o3dr.services.android.lib.util.UriUtils; -import org.droidplanner.services.android.core.model.Logger; +import org.droidplanner.services.android.impl.core.model.Logger; import java.io.BufferedOutputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.net.BindException; import java.nio.ByteBuffer; @@ -20,6 +22,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; /** * Base for mavlink connection implementations. @@ -40,6 +43,11 @@ public abstract class MavLinkConnection { */ private static final int READ_BUFFER_SIZE = 4096; + /** + * @see {@link android.net.Network} + */ + public static final String EXTRA_NETWORK = "extra_network"; + /** * Set of listeners subscribed to this mavlink connection. We're using a * ConcurrentSkipListSet because the object will be accessed from multiple @@ -50,7 +58,7 @@ public abstract class MavLinkConnection { /** * Stores the list of log files to be written to. */ - private final ConcurrentHashMap> loggingOutStreams = new + private final ConcurrentHashMap> loggingOutStreams = new ConcurrentHashMap<>(); /** @@ -67,6 +75,7 @@ public abstract class MavLinkConnection { private final AtomicInteger mConnectionStatus = new AtomicInteger(MAVLINK_DISCONNECTED); private final AtomicLong mConnectionTime = new AtomicLong(-1); + private final AtomicReference extrasHolder = new AtomicReference<>(); /** * Start the connection process. @@ -78,7 +87,7 @@ public void run() { loadPreferences(); // Open the connection try { - openConnection(); + openConnection(extrasHolder.get()); } catch (IOException e) { // Ignore errors while shutting down if (mConnectionStatus.get() != MAVLINK_DISCONNECTED) { @@ -216,21 +225,21 @@ public void run() { logBuffer.clear(); logBuffer.putLong(System.currentTimeMillis() * 1000); - for (Map.Entry> entry : loggingOutStreams + for (Map.Entry> entry : loggingOutStreams .entrySet()) { - final Pair logInfo = entry.getValue(); - final String loggingFilePath = logInfo.first; + final Pair logInfo = entry.getValue(); + final Uri loggingFileUri = logInfo.first; try { BufferedOutputStream logWriter = logInfo.second; if (logWriter == null) { - logWriter = new BufferedOutputStream(new FileOutputStream(loggingFilePath)); - loggingOutStreams.put(entry.getKey(), Pair.create(loggingFilePath, logWriter)); + logWriter = new BufferedOutputStream(UriUtils.getOutputStream(context, loggingFileUri)); + loggingOutStreams.put(entry.getKey(), Pair.create(loggingFileUri, logWriter)); } logWriter.write(logBuffer.array()); logWriter.write(packetData); } catch (IOException e) { - mLogger.logErr(TAG, "IO Exception while writing to " + loggingFilePath, e); + mLogger.logErr(TAG, "IO Exception while writing to " + loggingFileUri, e); } } } @@ -240,14 +249,14 @@ public void run() { mLogger.logVerbose(TAG, errorMessage); } } finally { - for (Pair entry : loggingOutStreams.values()) { - final String loggingFilePath = entry.first; + for (Pair entry : loggingOutStreams.values()) { + final Uri loggingFileUri = entry.first; try { if (entry.second != null) { entry.second.close(); } } catch (IOException e) { - mLogger.logErr(TAG, "IO Exception while closing " + loggingFilePath, e); + mLogger.logErr(TAG, "IO Exception while closing " + loggingFileUri, e); } } @@ -257,16 +266,18 @@ public void run() { }; protected final Logger mLogger = initLogger(); + protected final Context context; private Thread mConnectThread; private Thread mTaskThread; - /** - * Establish a mavlink connection. If the connection is successful, it will - * be reported through the MavLinkConnectionListener interface. - */ - public void connect() { + protected MavLinkConnection(Context context){ + this.context = context; + } + + public void connect(Bundle extras) { if (mConnectionStatus.compareAndSet(MAVLINK_DISCONNECTED, MAVLINK_CONNECTING)) { + extrasHolder.set(extras); mLogger.logInfo(TAG, "Starting connection thread."); mConnectThread = new Thread(mConnectingTask, "MavLinkConnection-Connecting Thread"); mConnectThread.start(); @@ -274,8 +285,9 @@ public void connect() { } } - protected void onConnectionOpened() { + protected void onConnectionOpened(Bundle extras) { if (mConnectionStatus.compareAndSet(MAVLINK_CONNECTING, MAVLINK_CONNECTED)) { + extrasHolder.set(extras); mLogger.logInfo(TAG, "Starting manager thread."); mTaskThread = new Thread(mManagerTask, "MavLinkConnection-Manager Thread"); mTaskThread.start(); @@ -303,10 +315,9 @@ public void disconnect() { } try { - final long disconnectTime = System.currentTimeMillis(); - mConnectionStatus.set(MAVLINK_DISCONNECTED); mConnectionTime.set(-1); + extrasHolder.set(null); if (mConnectThread != null && mConnectThread.isAlive() && !mConnectThread.isInterrupted()) { mConnectThread.interrupt(); @@ -349,13 +360,13 @@ private void queueToLog(byte[] packetData) { } } - public void addLoggingPath(String tag, String loggingPath) { - if (tag == null || tag.length() == 0 || loggingPath == null || loggingPath.length() == 0) { + public void addLoggingPath(String tag, Uri loggingUri) { + if (tag == null || tag.length() == 0 || loggingUri == null) { return; } if (!loggingOutStreams.contains(tag)) { - loggingOutStreams.put(tag, Pair.create(loggingPath, null)); + loggingOutStreams.put(tag, Pair.create(loggingUri, null)); } } @@ -364,7 +375,7 @@ public void removeLoggingPath(String tag) { return; } - Pair logInfo = loggingOutStreams.remove(tag); + Pair logInfo = loggingOutStreams.remove(tag); if (logInfo != null) { BufferedOutputStream outStream = logInfo.second; if (outStream != null) { @@ -400,6 +411,10 @@ public int getMavLinkConnectionListenersCount() { return mListeners.size(); } + public Bundle getConnectionExtras() { + return extrasHolder.get(); + } + /** * Used to query the presence of a connection listener. * @@ -428,7 +443,7 @@ public void removeAllMavLinkConnectionListeners() { protected abstract Logger initLogger(); - protected abstract void openConnection() throws IOException; + protected abstract void openConnection(Bundle connectionExtras) throws IOException; protected abstract int readDataBlock(byte[] buffer) throws IOException; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnectionListener.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionListener.java similarity index 88% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnectionListener.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionListener.java index 75cb55e9d9..81a3c3ed03 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/MavLinkConnectionListener.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionListener.java @@ -1,6 +1,7 @@ -package org.droidplanner.services.android.core.MAVLink.connection; +package org.droidplanner.services.android.impl.core.MAVLink.connection; import com.MAVLink.MAVLinkPacket; + import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; /** diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionTypes.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionTypes.java new file mode 100644 index 0000000000..aa192c751d --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/MavLinkConnectionTypes.java @@ -0,0 +1,31 @@ +package org.droidplanner.services.android.impl.core.MAVLink.connection; + +/** + * List the supported mavlink connection types. + */ +public class MavLinkConnectionTypes { + + /** + * Bluetooth mavlink connection. + */ + public static final int MAVLINK_CONNECTION_BLUETOOTH = 3; + + /** + * USP mavlink connection. + */ + public static final int MAVLINK_CONNECTION_USB = 0; + + /** + * UDP mavlink connection. + */ + public static final int MAVLINK_CONNECTION_UDP = 1; + + /** + * TCP mavlink connection. + */ + public static final int MAVLINK_CONNECTION_TCP = 2; + + // Not instantiable + private MavLinkConnectionTypes() { + } +} diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/TcpConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/TcpConnection.java similarity index 75% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/TcpConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/TcpConnection.java index c450d155a0..17a1ae758f 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/TcpConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/TcpConnection.java @@ -1,4 +1,9 @@ -package org.droidplanner.services.android.core.MAVLink.connection; +package org.droidplanner.services.android.impl.core.MAVLink.connection; + +import android.content.Context; +import android.os.Bundle; + +import org.droidplanner.services.android.impl.utils.NetworkUtils; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -21,10 +26,14 @@ public abstract class TcpConnection extends MavLinkConnection { private String serverIP; private int serverPort; + protected TcpConnection(Context context) { + super(context); + } + @Override - public final void openConnection() throws IOException { - getTCPStream(); - onConnectionOpened(); + public final void openConnection(Bundle connectionExtras) throws IOException { + getTCPStream(connectionExtras); + onConnectionOpened(connectionExtras); } @Override @@ -57,9 +66,10 @@ public final void closeConnection() throws IOException { } } - private void getTCPStream() throws IOException { + private void getTCPStream(Bundle extras) throws IOException { InetAddress serverAddr = InetAddress.getByName(serverIP); socket = new Socket(); + NetworkUtils.bindSocketToNetwork(extras, socket); socket.connect(new InetSocketAddress(serverAddr, serverPort), CONNECTION_TIMEOUT); mavOut = new BufferedOutputStream((socket.getOutputStream())); mavIn = new BufferedInputStream(socket.getInputStream()); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/UdpConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/UdpConnection.java similarity index 84% rename from ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/UdpConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/UdpConnection.java index 54cc67a39e..f220c1ceda 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/MAVLink/connection/UdpConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/MAVLink/connection/UdpConnection.java @@ -1,4 +1,9 @@ -package org.droidplanner.services.android.core.MAVLink.connection; +package org.droidplanner.services.android.impl.core.MAVLink.connection; + +import android.content.Context; +import android.os.Bundle; + +import org.droidplanner.services.android.impl.utils.NetworkUtils; import java.io.IOException; import java.net.DatagramPacket; @@ -19,10 +24,15 @@ public abstract class UdpConnection extends MavLinkConnection { private DatagramPacket sendPacket; private DatagramPacket receivePacket; - private void getUdpStream() throws IOException { + protected UdpConnection(Context context) { + super(context); + } + + private void getUdpStream(Bundle extras) throws IOException { final DatagramSocket socket = new DatagramSocket(serverPort); socket.setBroadcast(true); socket.setReuseAddress(true); + NetworkUtils.bindSocketToNetwork(extras, socket); socketRef.set(socket); } @@ -35,9 +45,9 @@ public final void closeConnection() throws IOException { } @Override - public final void openConnection() throws IOException { - getUdpStream(); - onConnectionOpened(); + public final void openConnection(Bundle connectionExtras) throws IOException { + getUdpStream(connectionExtras); + onConnectionOpened(connectionExtras); } @Override diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneEvents.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneEvents.java new file mode 100644 index 0000000000..edf9605e6e --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneEvents.java @@ -0,0 +1,39 @@ +package org.droidplanner.services.android.impl.core.drone; + +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + +import java.util.concurrent.ConcurrentLinkedQueue; + +public class DroneEvents extends DroneVariable { + + private final ConcurrentLinkedQueue droneListeners = new ConcurrentLinkedQueue(); + + public DroneEvents(MavLinkDrone myDrone) { + super(myDrone); + } + + public void addDroneListener(OnDroneListener listener) { + if (listener != null & !droneListeners.contains(listener)) + droneListeners.add(listener); + } + + public void removeDroneListener(OnDroneListener listener) { + if (listener != null && droneListeners.contains(listener)) + droneListeners.remove(listener); + } + + public void removeAllDroneListeners(){ + droneListeners.clear(); + } + + public void notifyDroneEvent(DroneEventsType event) { + if (event == null || droneListeners.isEmpty()) + return; + + for (OnDroneListener listener : droneListeners) { + listener.onDroneEvent(event, myDrone); + } + } +} diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneInterfaces.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneInterfaces.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/DroneInterfaces.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneInterfaces.java index 32be8546e6..ff3a609fea 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneInterfaces.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneInterfaces.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.drone; +package org.droidplanner.services.android.impl.core.drone; import android.os.Bundle; import com.o3dr.services.android.lib.drone.property.Parameter; -import org.droidplanner.services.android.core.MAVLink.WaypointManager; -import org.droidplanner.services.android.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.MAVLink.WaypointManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; public class DroneInterfaces { @@ -203,7 +203,7 @@ public interface OnDroneListener { } public interface AttributeEventListener { - void onAttributeEvent(String attributeEvent, Bundle eventInfo, boolean checkForSololinkApi); + void onAttributeEvent(String attributeEvent, Bundle eventInfo); } public interface OnParameterManagerListener { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneManager.java similarity index 76% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/DroneManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneManager.java index 7eb4b88c75..9742273308 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone; +package org.droidplanner.services.android.impl.core.drone; import android.content.Context; import android.os.Bundle; @@ -11,20 +11,19 @@ import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; import com.o3dr.services.android.lib.drone.connection.ConnectionType; -import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.drone.property.DroneAttribute; import com.o3dr.services.android.lib.drone.property.Parameter; +import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.api.DroneApi; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.drone.autopilot.Drone; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.ArduSolo; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.SoloComp; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.utils.CommonApiUtils; -import org.droidplanner.services.android.utils.analytics.GAUtils; +import org.droidplanner.services.android.impl.api.DroneApi; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.ArduSolo; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.SoloComp; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; import java.util.concurrent.ConcurrentHashMap; @@ -38,8 +37,6 @@ public class DroneManager implements DataLink.DataLinkListen public static final String EXTRA_CLIENT_APP_ID = "extra_client_app_id"; - private static final int SOLOLINK_API_MIN_VERSION = 20412; - protected final ConcurrentHashMap connectedApps = new ConcurrentHashMap<>(); protected final Context context; @@ -80,16 +77,16 @@ public void destroy() { } - public synchronized void connect(String appId, DroneApi listener) { + public synchronized void connect(String appId, DroneApi listener, ConnectionParameter connParams) { if (listener == null || TextUtils.isEmpty(appId)) { return; } connectedApps.put(appId, listener); - doConnect(appId, listener); + doConnect(appId, listener, connParams); } - protected void doConnect(String appId, DroneApi listener) { + protected void doConnect(String appId, DroneApi listener, ConnectionParameter connParams) { } @@ -108,10 +105,8 @@ protected boolean isCompanionComputerEnabled() { final int connectionType = connectionParameter.getConnectionType(); return drone instanceof ArduSolo - || - (connectionType == ConnectionType.TYPE_UDP && SoloComp.isAvailable(context) && doAnyListenersSupportSoloLinkApi()) - || - connectionType == ConnectionType.TYPE_SOLO; + || (connectionType == ConnectionType.TYPE_UDP && SoloComp.isAvailable(context)) + || connectionType == ConnectionType.TYPE_SOLO; } @@ -159,11 +154,7 @@ public void onConnectionStatus(LinkConnectionStatus connectionStatus) { case LinkConnectionStatus.DISCONNECTED: notifyDroneEvent(DroneInterfaces.DroneEventsType.DISCONNECTED); break; - case LinkConnectionStatus.CONNECTED: - // Start a new ga analytics session. The new session will be tagged - // with the mavlink connection mechanism, as well as whether the user has an active droneshare account. - GAUtils.startNewSession(null); - break; + case LinkConnectionStatus.CONNECTING: notifyDroneEvent(DroneInterfaces.DroneEventsType.CONNECTING); break; @@ -230,51 +221,13 @@ public boolean executeAsyncAction(DroneApi.ClientInfo clientInfo, Action action, } protected void notifyDroneAttributeEvent(String attributeEvent, Bundle eventInfo) { - notifyDroneAttributeEvent(attributeEvent, eventInfo, false); - } - - /** - * Temporary delegate to prevent sending of newly defined payload to older version of the api - * #FIXME: remove when old version of the api is phased out. - * - * @param attributeEvent - * @param eventInfo - * @param checkForSoloLinkApi - */ - private void notifyDroneAttributeEvent(String attributeEvent, Bundle eventInfo, boolean checkForSoloLinkApi) { if (TextUtils.isEmpty(attributeEvent) || connectedApps.isEmpty()) { return; } for (DroneApi listener : connectedApps.values()) { - if (checkForSoloLinkApi && !supportSoloLinkApi(listener)) { - continue; - } - listener.onAttributeEvent(attributeEvent, eventInfo, checkForSoloLinkApi); - } - } - - private boolean supportSoloLinkApi(DroneApi listener) { - return listener != null && listener.getClientInfo().apiVersionCode >= SOLOLINK_API_MIN_VERSION; - } - - /** - * FIXME: remove when android solo v2 is released. - * - * @return - */ - private boolean doAnyListenersSupportSoloLinkApi() { - if (connectedApps.isEmpty()) { - return false; - } - - for (DroneApi listener : connectedApps.values()) { - if (supportSoloLinkApi(listener)) { - return true; - } + listener.onAttributeEvent(attributeEvent, eventInfo); } - - return false; } @Override @@ -344,7 +297,7 @@ public void onMessageLogged(int logLevel, String message) { } @Override - public void onAttributeEvent(String attributeEvent, Bundle eventInfo, boolean checkForSololinkApi) { - notifyDroneAttributeEvent(attributeEvent, eventInfo, checkForSololinkApi); + public void onAttributeEvent(String attributeEvent, Bundle eventInfo) { + notifyDroneAttributeEvent(attributeEvent, eventInfo); } } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneVariable.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneVariable.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/DroneVariable.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneVariable.java index 4f107d983b..faf75dcf09 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/DroneVariable.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/DroneVariable.java @@ -1,12 +1,11 @@ -package org.droidplanner.services.android.core.drone; +package org.droidplanner.services.android.impl.core.drone; import android.os.Handler; import android.os.RemoteException; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - import timber.log.Timber; public class DroneVariable { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/LogMessageListener.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/LogMessageListener.java similarity index 72% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/LogMessageListener.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/LogMessageListener.java index f3ce87eb05..09e2fa69c1 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/LogMessageListener.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/LogMessageListener.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone; +package org.droidplanner.services.android.impl.core.drone; /** * Created by Fredia Huya-Kouadio on 3/23/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/Drone.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/Drone.java similarity index 86% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/Drone.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/Drone.java index 75db51176e..305903f9fe 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/Drone.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/Drone.java @@ -1,11 +1,10 @@ -package org.droidplanner.services.android.core.drone.autopilot; +package org.droidplanner.services.android.impl.core.drone.autopilot; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; import com.o3dr.services.android.lib.drone.property.DroneAttribute; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.core.drone.DroneInterfaces; - /** * Created by Fredia Huya-Kouadio on 7/27/15. */ diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/MavLinkDrone.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/MavLinkDrone.java new file mode 100644 index 0000000000..4e7e820c67 --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/MavLinkDrone.java @@ -0,0 +1,62 @@ +package org.droidplanner.services.android.impl.core.drone.autopilot; + +import com.MAVLink.Messages.MAVLinkMessage; + +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.WaypointManager; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterManager; +import org.droidplanner.services.android.impl.core.drone.variables.Camera; +import org.droidplanner.services.android.impl.core.drone.variables.GuidedPoint; +import org.droidplanner.services.android.impl.core.drone.variables.MissionStats; +import org.droidplanner.services.android.impl.core.drone.variables.State; +import org.droidplanner.services.android.impl.core.drone.variables.StreamRates; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.AccelCalibration; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; + +public interface MavLinkDrone extends Drone { + + String PACKAGE_NAME = "org.droidplanner.services.android.core.drone.autopilot"; + + String ACTION_REQUEST_HOME_UPDATE = PACKAGE_NAME + ".action.REQUEST_HOME_UPDATE"; + + boolean isConnectionAlive(); + + int getMavlinkVersion(); + + void onMavLinkMessageReceived(MAVLinkMessage message); + + public byte getSysid(); + + public byte getCompid(); + + public State getState(); + + public ParameterManager getParameterManager(); + + public int getType(); + + public FirmwareType getFirmwareType(); + + public DataLink.DataLinkProvider getMavClient(); + + public WaypointManager getWaypointManager(); + + public MissionImpl getMission(); + + public StreamRates getStreamRates(); + + public MissionStats getMissionStats(); + + public GuidedPoint getGuidedPoint(); + + public AccelCalibration getCalibrationSetup(); + + public MagnetometerCalibrationImpl getMagnetometerCalibration(); + + public String getFirmwareVersion(); + + public Camera getCamera(); + +} diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/APMConstants.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/APMConstants.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/APMConstants.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/APMConstants.java index f97fae07cd..7c1bdeda2d 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/APMConstants.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/APMConstants.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm; /** * Set of APM autopilots related constants. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduCopter.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduCopter.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduCopter.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduCopter.java index 08d05174d6..a6f2fd5483 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduCopter.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduCopter.java @@ -1,38 +1,40 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm; import android.content.Context; import android.os.Bundle; import android.os.Handler; -import com.github.zafarkhaja.semver.Version; import com.MAVLink.Messages.MAVLinkMessage; +import com.github.zafarkhaja.semver.Version; import com.o3dr.android.client.apis.CapabilityApi; import com.o3dr.services.android.lib.drone.action.ControlActions; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.drone.property.Parameter; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneManager; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.profiles.ParameterManager; -import org.droidplanner.services.android.core.drone.variables.ApmModes; -import org.droidplanner.services.android.core.drone.variables.State; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneManager; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterManager; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.variables.State; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Created by Fredia Huya-Kouadio on 7/27/15. */ public class ArduCopter extends ArduPilot { - private static final Version BRAKE_FEATURE_FIRMWARE_VERSION = Version.forIntegers(3, 3, 0); + private static final Version ARDU_COPTER_V3_3 = Version.forIntegers(3,3,0); + private static final Version ARDU_COPTER_V3_4 = Version.forIntegers(3,4,0); + + private static final Version BRAKE_FEATURE_FIRMWARE_VERSION = ARDU_COPTER_V3_3; + private static final Version COMPASS_CALIBRATION_MIN_VERSION = ARDU_COPTER_V3_4; private final ConcurrentHashMap manualControlStateListeners = new ConcurrentHashMap<>(); @@ -146,6 +148,9 @@ protected boolean isFeatureSupported(String featureId){ case CapabilityApi.FeatureIds.KILL_SWITCH: return CommonApiUtils.isKillSwitchSupported(this); + case CapabilityApi.FeatureIds.COMPASS_CALIBRATION: + return getFirmwareVersionNumber().greaterThanOrEqualTo(COMPASS_CALIBRATION_MIN_VERSION); + default: return super.isFeatureSupported(featureId); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilot.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilot.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilot.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilot.java index 88b36c1a54..9e9d5617c8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduPilot.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilot.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm; import android.content.Context; import android.os.Bundle; @@ -23,6 +23,25 @@ import com.MAVLink.enums.MAV_MOUNT_MODE; import com.MAVLink.enums.MAV_SYS_STATUS_SENSOR; import com.github.zafarkhaja.semver.Version; + +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkParameters; +import org.droidplanner.services.android.impl.core.MAVLink.WaypointManager; +import org.droidplanner.services.android.impl.core.MAVLink.command.doCmd.MavLinkDoCmds; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.variables.APMHeartBeat; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.variables.Camera; +import org.droidplanner.services.android.impl.core.drone.variables.GuidedPoint; +import org.droidplanner.services.android.impl.core.drone.variables.HeartBeat; +import org.droidplanner.services.android.impl.core.drone.variables.Magnetometer; +import org.droidplanner.services.android.impl.core.drone.variables.RC; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.AccelCalibration; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.action.ControlActions; @@ -42,26 +61,7 @@ import com.o3dr.services.android.lib.model.AbstractCommandListener; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; - -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.MAVLink.MavLinkParameters; -import org.droidplanner.services.android.core.MAVLink.WaypointManager; -import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.autopilot.apm.variables.APMHeartBeat; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.drone.variables.ApmModes; -import org.droidplanner.services.android.core.drone.variables.Camera; -import org.droidplanner.services.android.core.drone.variables.GuidedPoint; -import org.droidplanner.services.android.core.drone.variables.HeartBeat; -import org.droidplanner.services.android.core.drone.variables.Magnetometer; -import org.droidplanner.services.android.core.drone.variables.RC; -import org.droidplanner.services.android.core.drone.variables.calibration.AccelCalibration; -import org.droidplanner.services.android.core.drone.variables.calibration.MagnetometerCalibrationImpl; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -78,8 +78,8 @@ public abstract class ArduPilot extends GenericMavLinkDrone { public static final String FIRMWARE_VERSION_NUMBER_REGEX = "\\d+(\\.\\d{1,2})?"; - private final org.droidplanner.services.android.core.drone.variables.RC rc; - private final Mission mission; + private final org.droidplanner.services.android.impl.core.drone.variables.RC rc; + private final MissionImpl missionImpl; private final GuidedPoint guidedPoint; private final AccelCalibration accelCalibrationSetup; private final WaypointManager waypointManager; @@ -99,7 +99,7 @@ public ArduPilot(String droneId, Context context, DataLink.DataLinkProvider mavClient, Handler handler, AutopilotWarningParser warningParser, LogMessageListener logListener) { super(droneId, context, mavClient, handler, warningParser, logListener); } @@ -61,5 +67,16 @@ protected void processGlobalPositionInt(msg_global_position_int gpi){ setAltitudeGroundAndAirSpeeds(relativeAlt, groundSpeed, groundSpeed, climbRate); } + @Override + protected boolean isFeatureSupported(String featureId){ + switch(featureId){ + case CapabilityApi.FeatureIds.COMPASS_CALIBRATION: + return getFirmwareVersionNumber().greaterThanOrEqualTo(COMPASS_CALIBRATION_MIN_VERSION); + + default: + return super.isFeatureSupported(featureId); + } + } + } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduRover.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduRover.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduRover.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduRover.java index e4c2dab31b..c5dffa322a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/ArduRover.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduRover.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm; import android.content.Context; import android.os.Handler; @@ -6,10 +6,10 @@ import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.enums.MAV_TYPE; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; /** * Created by Fredia Huya-Kouadio on 7/27/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/AbstractLinkManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/AbstractLinkManager.java similarity index 88% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/AbstractLinkManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/AbstractLinkManager.java index 824e53bc25..bd72f973d5 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/AbstractLinkManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/AbstractLinkManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.solo; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo; import android.content.Context; import android.os.Handler; @@ -9,7 +9,8 @@ import com.o3dr.android.client.utils.connection.IpConnectionListener; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.utils.connection.SshConnection; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.utils.connection.SshConnection; import java.io.IOException; import java.util.concurrent.ExecutorService; @@ -43,7 +44,7 @@ public interface LinkListener { @Override public void run() { handler.removeCallbacks(reconnectTask); - linkConn.connect(); + linkConn.connect(linkProvider.getConnectionExtras()); } }; @@ -70,16 +71,22 @@ public void run() { protected final Context context; protected final AbstractIpConnection linkConn; + protected final DataLink.DataLinkProvider linkProvider; private T linkListener; - public AbstractLinkManager(Context context, AbstractIpConnection ipConn, Handler handler, ExecutorService asyncExecutor) { + public AbstractLinkManager(Context context, + AbstractIpConnection ipConn, + Handler handler, + ExecutorService asyncExecutor, + DataLink.DataLinkProvider linkProvider) { this.context = context; this.linkConn = ipConn; this.linkConn.setIpConnectionListener(this); this.handler = handler; this.asyncExecutor = asyncExecutor; + this.linkProvider = linkProvider; } protected void postAsyncTask(Runnable task){ @@ -143,7 +150,7 @@ public void start(T listener) { handler.removeCallbacks(reconnectTask); isStarted.set(true); - this.linkConn.connect(); + this.linkConn.connect(linkProvider.getConnectionExtras()); this.linkListener = listener; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/ArduSolo.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/ArduSolo.java similarity index 88% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/ArduSolo.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/ArduSolo.java index 80a8c42200..443d427479 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/ArduSolo.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/ArduSolo.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.solo; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo; import android.content.Context; import android.os.Bundle; @@ -11,7 +11,6 @@ import com.MAVLink.common.msg_statustext; import com.MAVLink.enums.MAV_TYPE; import com.o3dr.android.client.apis.CapabilityApi; -import com.o3dr.android.client.utils.TxPowerComplianceCountries; 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.attribute.error.CommandExecutionError; @@ -29,20 +28,19 @@ import com.o3dr.services.android.lib.drone.companion.solo.tlv.TLVPacket; import com.o3dr.services.android.lib.drone.property.DroneAttribute; import com.o3dr.services.android.lib.drone.property.State; -import com.o3dr.services.android.lib.model.AbstractCommandListener; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduCopter; -import org.droidplanner.services.android.core.drone.variables.ApmModes; -import org.droidplanner.services.android.core.drone.variables.HeartBeat; -import org.droidplanner.services.android.core.drone.variables.StreamRates; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.utils.SoloApiUtils; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduCopter; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.variables.HeartBeat; +import org.droidplanner.services.android.impl.core.drone.variables.StreamRates; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; +import org.droidplanner.services.android.impl.utils.SoloApiUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,7 +60,7 @@ public class ArduSolo extends ArduCopter { private final Runnable disconnectSoloCompTask = new Runnable() { @Override public void run() { - if (soloComp != null && soloComp.isConnected()) { + if (soloComp.isConnected()) { soloComp.stop(); } @@ -77,7 +75,7 @@ public void run() { public ArduSolo(String droneId, Context context, DataLink.DataLinkProvider mavClient, Handler handler, AutopilotWarningParser warningParser, LogMessageListener logListener) { super(droneId, context, mavClient, handler, warningParser, logListener); - this.soloComp = new SoloComp(context, handler); + this.soloComp = new SoloComp(context, handler, mavClient); this.soloComp.setListener(new SoloComp.SoloCompListener() { @Override public void onConnected() { @@ -93,7 +91,6 @@ public void onDisconnected() { @Override public void onTlvPacketReceived(TLVPacket packet) { - //TODO: filter the message that are broadcast. switch (packet.getMessageType()) { case TLVMessageTypes.TYPE_ARTOO_INPUT_REPORT_MESSAGE: //Drop this message as only the battery info is enabled, and that info is already @@ -117,33 +114,33 @@ public void onTlvPacketReceived(TLVPacket packet) { final Bundle messageInfo = new Bundle(); messageInfo.putParcelable(SoloEventExtras.EXTRA_SOLO_MESSAGE_DATA, packet); - notifyAttributeListener(SoloEvents.SOLO_MESSAGE_RECEIVED, messageInfo, true); + notifyAttributeListener(SoloEvents.SOLO_MESSAGE_RECEIVED, messageInfo); break; } } @Override public void onPresetButtonLoaded(int buttonType, SoloButtonSetting buttonSettings) { - notifyAttributeListener(SoloEvents.SOLO_BUTTON_SETTINGS_UPDATED, null, true); + notifyAttributeListener(SoloEvents.SOLO_BUTTON_SETTINGS_UPDATED, null); } @Override public void onWifiInfoUpdated(String wifiName, String wifiPassword) { - notifyAttributeListener(SoloEvents.SOLO_WIFI_SETTINGS_UPDATED, null, true); + notifyAttributeListener(SoloEvents.SOLO_WIFI_SETTINGS_UPDATED, null); } @Override public void onButtonPacketReceived(ButtonPacket packet) { final Bundle eventInfo = new Bundle(); eventInfo.putParcelable(SoloEventExtras.EXTRA_SOLO_BUTTON_EVENT, packet); - notifyAttributeListener(SoloEvents.SOLO_BUTTON_EVENT_RECEIVED, eventInfo, true); + notifyAttributeListener(SoloEvents.SOLO_BUTTON_EVENT_RECEIVED, eventInfo); } @Override public void onTxPowerComplianceCountryUpdated(String compliantCountry) { final Bundle eventInfo = new Bundle(1); eventInfo.putString(SoloEventExtras.EXTRA_SOLO_TX_POWER_COMPLIANT_COUNTRY, compliantCountry); - notifyAttributeListener(SoloEvents.SOLO_TX_POWER_COMPLIANCE_COUNTRY_UPDATED, eventInfo, true); + notifyAttributeListener(SoloEvents.SOLO_TX_POWER_COMPLIANCE_COUNTRY_UPDATED, eventInfo); } @Override @@ -155,12 +152,12 @@ public void onVersionsUpdated() { eventInfo.putString(SoloEventExtras.EXTRA_SOLO_CONTROLLER_VERSION, soloComp.getControllerVersion()); eventInfo.putString(SoloEventExtras.EXTRA_SOLO_CONTROLLER_FIRMWARE_VERSION, soloComp.getControllerFirmwareVersion()); - notifyAttributeListener(SoloEvents.SOLO_VERSIONS_UPDATED, eventInfo, true); + notifyAttributeListener(SoloEvents.SOLO_VERSIONS_UPDATED, eventInfo); } @Override public void onControllerEvent(String event, Bundle eventInfo) { - notifyAttributeListener(event, eventInfo, true); + notifyAttributeListener(event, eventInfo); } }); } @@ -335,14 +332,6 @@ public boolean executeAsyncAction(Action action, final ICommandListener listener SoloApiUtils.updateSoloLinkControllerMode(this, mode, listener); return true; - //TODO remove this when deprecated methods are deleted in 3.0 - case SoloConfigActions.ACTION_UPDATE_EU_TX_POWER_COMPLIANCE: - final boolean isCompliant = data.getBoolean(SoloConfigActions.EXTRA_EU_TX_POWER_COMPLIANT); - String compliantCountryCode = isCompliant ? TxPowerComplianceCountries.getDefaultEUCountry().name() : - TxPowerComplianceCountries.getDefaultCountry().name(); - SoloApiUtils.updateSoloLinkTxPowerComplianceCountry(this, compliantCountryCode, listener); - return true; - case SoloConfigActions.ACTION_UPDATE_TX_POWER_COMPLIANCE_COUNTRY: final String compliantCountry = data.getString(SoloConfigActions.EXTRA_TX_POWER_COMPLIANT_COUNTRY_CODE); SoloApiUtils.updateSoloLinkTxPowerComplianceCountry(this, compliantCountry, listener); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/SoloComp.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/SoloComp.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/SoloComp.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/SoloComp.java index 4017d32a62..124fb0d9ba 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/SoloComp.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/SoloComp.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.solo; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo; import android.content.Context; import android.os.Bundle; @@ -8,6 +8,7 @@ import android.util.Pair; import android.util.SparseArray; +import com.o3dr.android.client.BuildConfig; import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.drone.companion.solo.SoloEventExtras; @@ -25,12 +26,12 @@ import com.o3dr.services.android.lib.drone.companion.solo.tlv.TLVPacket; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.BuildConfig; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.controller.ControllerLinkListener; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.controller.ControllerLinkManager; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.sololink.SoloLinkListener; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.sololink.SoloLinkManager; -import org.droidplanner.services.android.utils.NetworkUtils; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.controller.ControllerLinkListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.controller.ControllerLinkManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.sololink.SoloLinkListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.sololink.SoloLinkManager; +import org.droidplanner.services.android.impl.utils.NetworkUtils; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -85,14 +86,14 @@ public interface SoloCompListener { * * @param context Application context */ - public SoloComp(Context context, Handler handler) { + public SoloComp(Context context, Handler handler, DataLink.DataLinkProvider mavClient) { this.context = context; this.handler = handler; asyncExecutor = Executors.newCachedThreadPool(); - this.controllerLinkManager = new ControllerLinkManager(context, handler, asyncExecutor); - this.soloLinkMgr = new SoloLinkManager(context, handler, asyncExecutor); + this.controllerLinkManager = new ControllerLinkManager(context, handler, asyncExecutor, mavClient); + this.soloLinkMgr = new SoloLinkManager(context, handler, asyncExecutor, mavClient); } public SoloGoproState getGoproState() { @@ -115,7 +116,6 @@ public void setListener(SoloCompListener listener) { } public static boolean isAvailable(Context context) { - //TODO: complement the logic. return NetworkUtils.isOnSololinkNetwork(context); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java index 5a22767982..d723262088 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkListener.java @@ -1,11 +1,10 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.solo.controller; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.controller; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.AbstractLinkManager; import com.o3dr.services.android.lib.drone.companion.solo.button.ButtonPacket; import com.o3dr.services.android.lib.drone.companion.solo.controller.SoloControllerUnits; import com.o3dr.services.android.lib.drone.companion.solo.tlv.TLVPacket; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.AbstractLinkManager; - /** * Created by Fredia Huya-Kouadio on 7/10/15. */ diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java index d4c9a7c0c1..019be3d427 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/solo/controller/ControllerLinkManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.solo.controller; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.controller; import android.content.Context; import android.os.Handler; @@ -17,10 +17,11 @@ import com.o3dr.services.android.lib.drone.companion.solo.tlv.TLVPacket; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.AbstractLinkManager; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.SoloComp; -import org.droidplanner.services.android.utils.NetworkUtils; -import org.droidplanner.services.android.utils.connection.SshConnection; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.AbstractLinkManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.SoloComp; +import org.droidplanner.services.android.impl.utils.NetworkUtils; +import org.droidplanner.services.android.impl.utils.connection.SshConnection; import java.io.IOException; import java.nio.ByteBuffer; @@ -74,7 +75,7 @@ public class ControllerLinkManager extends AbstractLinkManager { private final UdpConnection followDataConn; - private static final SshConnection sshLink = new SshConnection(getSoloLinkIp(), SoloComp.SSH_USERNAME, SoloComp.SSH_PASSWORD); + private final SshConnection sshLink; private final SoloButtonSettingGetter presetButtonAGetter = new SoloButtonSettingGetter(ButtonTypes.BUTTON_A, ButtonTypes.BUTTON_EVENT_PRESS); @@ -108,9 +108,13 @@ public void run() { private SoloLinkListener linkListener; - public SoloLinkManager(Context context, Handler handler, ExecutorService asyncExecutor) { - super(context, new TcpConnection(handler, getSoloLinkIp(), SOLO_LINK_TCP_PORT), handler, asyncExecutor); + public SoloLinkManager(Context context, Handler handler, ExecutorService asyncExecutor, + DataLink.DataLinkProvider mavClient) { + super(context, new TcpConnection(handler, getSoloLinkIp(), SOLO_LINK_TCP_PORT), handler, + asyncExecutor, + mavClient); + sshLink = new SshConnection(getSoloLinkIp(), SoloComp.SSH_USERNAME, SoloComp.SSH_PASSWORD, mavClient); UdpConnection dataConn = null; try { dataConn = new UdpConnection(handler, getSoloLinkIp(), SHOT_FOLLOW_UDP_PORT, 14557); @@ -322,7 +326,7 @@ public void disableFollowDataConnection() { public void enableFollowDataConnection() { if (followDataConn != null) { - followDataConn.connect(); + followDataConn.connect(linkProvider.getConnectionExtras()); } } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/variables/APMHeartBeat.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/variables/APMHeartBeat.java similarity index 75% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/variables/APMHeartBeat.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/variables/APMHeartBeat.java index f927212980..94c591ec15 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/apm/variables/APMHeartBeat.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/variables/APMHeartBeat.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.drone.autopilot.apm.variables; +package org.droidplanner.services.android.impl.core.drone.autopilot.apm.variables; import android.os.Handler; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduPilot; -import org.droidplanner.services.android.core.drone.variables.HeartBeat; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduPilot; +import org.droidplanner.services.android.impl.core.drone.variables.HeartBeat; /** * Created by Fredia Huya-Kouadio on 10/24/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/generic/GenericMavLinkDrone.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/generic/GenericMavLinkDrone.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/generic/GenericMavLinkDrone.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/generic/GenericMavLinkDrone.java index 4295cd0395..1804cb2960 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/generic/GenericMavLinkDrone.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/generic/GenericMavLinkDrone.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.autopilot.generic; +package org.droidplanner.services.android.impl.core.drone.autopilot.generic; import android.content.Context; import android.os.Bundle; @@ -49,32 +49,31 @@ import com.o3dr.services.android.lib.model.action.Action; import com.o3dr.services.android.lib.util.MathUtils; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.MAVLink.MavLinkWaypoint; -import org.droidplanner.services.android.core.MAVLink.WaypointManager; -import org.droidplanner.services.android.core.drone.DroneEvents; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.APMConstants; -import org.droidplanner.services.android.core.drone.profiles.ParameterManager; -import org.droidplanner.services.android.core.drone.variables.ApmModes; -import org.droidplanner.services.android.core.drone.variables.Camera; -import org.droidplanner.services.android.core.drone.variables.GuidedPoint; -import org.droidplanner.services.android.core.drone.variables.HeartBeat; -import org.droidplanner.services.android.core.drone.variables.MissionStats; -import org.droidplanner.services.android.core.drone.variables.State; -import org.droidplanner.services.android.core.drone.variables.StreamRates; -import org.droidplanner.services.android.core.drone.variables.Type; -import org.droidplanner.services.android.core.drone.variables.calibration.AccelCalibration; -import org.droidplanner.services.android.core.drone.variables.calibration.MagnetometerCalibrationImpl; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.utils.CommonApiUtils; -import org.droidplanner.services.android.utils.prefs.DroidPlannerPrefs; -import org.droidplanner.services.android.utils.video.VideoManager; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkWaypoint; +import org.droidplanner.services.android.impl.core.MAVLink.WaypointManager; +import org.droidplanner.services.android.impl.core.drone.DroneEvents; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.APMConstants; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterManager; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.variables.Camera; +import org.droidplanner.services.android.impl.core.drone.variables.GuidedPoint; +import org.droidplanner.services.android.impl.core.drone.variables.HeartBeat; +import org.droidplanner.services.android.impl.core.drone.variables.MissionStats; +import org.droidplanner.services.android.impl.core.drone.variables.State; +import org.droidplanner.services.android.impl.core.drone.variables.StreamRates; +import org.droidplanner.services.android.impl.core.drone.variables.Type; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.AccelCalibration; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.utils.video.VideoManager; /** * Base drone implementation. @@ -121,7 +120,7 @@ public GenericMavLinkDrone(String droneId, Context context, Handler handler, Dat this.logListener = logListener; - events = new DroneEvents(this, handler); + events = new DroneEvents(this); heartbeat = initHeartBeat(handler); this.type = new Type(this); this.missionStats = new MissionStats(this); @@ -129,7 +128,7 @@ public GenericMavLinkDrone(String droneId, Context context, Handler handler, Dat this.state = new State(this, handler, warningParser); parameterManager = new ParameterManager(this, context, handler); - this.videoMgr = new VideoManager(context, handler); + this.videoMgr = new VideoManager(context, handler, mavClient); } @Override @@ -148,7 +147,7 @@ public MissionStats getMissionStats() { } @Override - public Mission getMission() { + public MissionImpl getMission() { //TODO: complete implementation return null; } @@ -298,17 +297,13 @@ protected void notifyAttributeListener(String attributeEvent) { } protected void notifyAttributeListener(String attributeEvent, Bundle eventInfo) { - notifyAttributeListener(attributeEvent, eventInfo, false); - } - - protected void notifyAttributeListener(String attributeEvent, Bundle eventInfo, boolean checkForSololinkApi) { if (attributeListener != null) { if(eventInfo == null){ eventInfo = new Bundle(); } eventInfo.putString(AttributeEventExtra.EXTRA_VEHICLE_ID, getId()); - attributeListener.onAttributeEvent(attributeEvent, eventInfo, checkForSololinkApi); + attributeListener.onAttributeEvent(attributeEvent, eventInfo); } } @@ -422,11 +417,11 @@ public boolean executeAsyncAction(Action action, ICommandListener listener) { private boolean updateVehicleDataStreamRate(Bundle data, ICommandListener listener) { StreamRates streamRates = getStreamRates(); if(streamRates != null){ - int rate = data.getInt(StateActions.EXTRA_VEHICLE_DATA_STREAM_RATE, DroidPlannerPrefs.DEFAULT_STREAM_RATE); - StreamRates.Rates rates = new StreamRates.Rates(rate); - streamRates.setRates(rates); - - streamRates.setupStreamRatesFromPref(); + int rate = data.getInt(StateActions.EXTRA_VEHICLE_DATA_STREAM_RATE, -1); + if(rate != -1) { + StreamRates.Rates rates = new StreamRates.Rates(rate); + streamRates.setRates(rates); + } CommonApiUtils.postSuccessEvent(listener); return true; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/px4/Px4Native.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/px4/Px4Native.java similarity index 55% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/px4/Px4Native.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/px4/Px4Native.java index ef9ef5974d..05eb393f6b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/px4/Px4Native.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/px4/Px4Native.java @@ -1,15 +1,15 @@ -package org.droidplanner.services.android.core.drone.autopilot.px4; +package org.droidplanner.services.android.impl.core.drone.autopilot.px4; import android.content.Context; import android.os.Handler; import com.MAVLink.Messages.MAVLinkMessage; -import org.droidplanner.services.android.communication.model.DataLink; -import org.droidplanner.services.android.core.drone.LogMessageListener; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.drone.LogMessageListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; /** * Created by Fredia Huya-Kouadio on 9/10/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/manager/DroneCommandTracker.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/DroneCommandTracker.java similarity index 98% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/manager/DroneCommandTracker.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/DroneCommandTracker.java index 1aa348b63c..600b0f5d6e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/manager/DroneCommandTracker.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/DroneCommandTracker.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.manager; +package org.droidplanner.services.android.impl.core.drone.manager; import android.os.Handler; import android.os.RemoteException; @@ -7,6 +7,7 @@ import com.MAVLink.common.msg_command_ack; import com.MAVLink.common.msg_command_long; import com.MAVLink.common.msg_set_mode; + import com.o3dr.services.android.lib.model.ICommandListener; import java.util.concurrent.ConcurrentHashMap; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/manager/MavLinkDroneManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/MavLinkDroneManager.java similarity index 78% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/manager/MavLinkDroneManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/MavLinkDroneManager.java index b0e22ad20f..8f598ffd9b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/manager/MavLinkDroneManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/manager/MavLinkDroneManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.manager; +package org.droidplanner.services.android.impl.core.drone.manager; import android.content.Context; import android.os.Bundle; @@ -16,44 +16,44 @@ import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.drone.connection.ConnectionParameter; -import com.o3dr.services.android.lib.gcs.follow.FollowLocationSource; -import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.drone.property.DroneAttribute; import com.o3dr.services.android.lib.gcs.action.FollowMeActions; +import com.o3dr.services.android.lib.gcs.follow.FollowLocationSource; import com.o3dr.services.android.lib.gcs.follow.FollowType; +import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.gcs.returnToMe.ReturnToMeState; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.api.DroneApi; -import org.droidplanner.services.android.communication.service.MAVLinkClient; -import org.droidplanner.services.android.core.MAVLink.MavLinkMsgHandler; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneManager; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduCopter; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduPlane; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduRover; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.ArduSolo; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.px4.Px4Native; -import org.droidplanner.services.android.core.drone.profiles.ParameterManager; -import org.droidplanner.services.android.core.drone.variables.StreamRates; -import org.droidplanner.services.android.core.drone.variables.calibration.MagnetometerCalibrationImpl; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.gcs.GCSHeartbeat; -import org.droidplanner.services.android.core.gcs.ReturnToMe; -import org.droidplanner.services.android.core.gcs.follow.Follow; -import org.droidplanner.services.android.core.gcs.follow.FollowAlgorithm; -import org.droidplanner.services.android.core.gcs.location.FusedLocation; -import org.droidplanner.services.android.utils.AndroidApWarningParser; -import org.droidplanner.services.android.utils.CommonApiUtils; -import org.droidplanner.services.android.utils.SoloApiUtils; -import org.droidplanner.services.android.utils.prefs.DroidPlannerPrefs; +import org.droidplanner.services.android.impl.api.DroneApi; +import org.droidplanner.services.android.impl.communication.service.MAVLinkClient; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkMsgHandler; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduCopter; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduPlane; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduRover; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.ArduSolo; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.px4.Px4Native; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterManager; +import org.droidplanner.services.android.impl.core.drone.variables.StreamRates; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.gcs.GCSHeartbeat; +import org.droidplanner.services.android.impl.core.gcs.ReturnToMe; +import org.droidplanner.services.android.impl.core.gcs.follow.Follow; +import org.droidplanner.services.android.impl.core.gcs.follow.FollowAlgorithm; +import org.droidplanner.services.android.impl.core.gcs.location.FusedLocation; +import org.droidplanner.services.android.impl.utils.AndroidApWarningParser; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.utils.SoloApiUtils; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import timber.log.Timber; @@ -62,6 +62,8 @@ */ public class MavLinkDroneManager extends DroneManager implements MagnetometerCalibrationImpl.OnMagnetometerCalibrationListener { + private static final int DEFAULT_STREAM_RATE = 2; //Hz + private Follow followMe; private ReturnToMe returnToMe; @@ -71,6 +73,8 @@ public class MavLinkDroneManager extends DroneManager currentRate) { + updateComplete = droneStreamRate.compareAndSet(currentRate, eventsDispatchingRate); + if (updateComplete && drone != null) { + StreamRates rates = drone.getStreamRates(); + if (rates != null) { + rates.setRates(new StreamRates.Rates(droneStreamRate.get())); + } + } + } + }while(!updateComplete); } @Override @@ -184,7 +216,7 @@ protected void doDisconnect(String appId, DroneApi listener) { } if (listener != null) { - mavClient.removeLoggingFile(appId); + mavClient.unregisterForTLogLogging(appId); if (isConnected()) { listener.onDroneEvent(DroneInterfaces.DroneEventsType.DISCONNECTED, drone); } @@ -347,9 +379,7 @@ private void enableFollowMe(FollowType followType, FollowLocationSource source, Timber.d("CURRENT: followMe.enabled=%s followMe.state=%s source=%s", followMe.isEnabled(), followMe.getState(), source); - if (!followMe.isEnabled()) { - followMe.enableFollowMe(source); - } + followMe.enableFollowMe(source); FollowAlgorithm currentAlg = followMe.getFollowAlgorithm(); if (currentAlg.getType() != selectedMode) { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterManager.java similarity index 86% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterManager.java index 414fb7aeff..75f046367a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.profiles; +package org.droidplanner.services.android.impl.core.drone.profiles; import android.content.Context; import android.os.Handler; @@ -9,17 +9,18 @@ import com.MAVLink.common.msg_param_value; import com.o3dr.services.android.lib.drone.property.Parameter; -import org.droidplanner.services.android.core.MAVLink.MavLinkParameters; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneInterfaces.OnDroneListener; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.utils.file.IO.ParameterMetadataLoader; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkParameters; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.utils.file.IO.ParameterMetadataLoader; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import timber.log.Timber; @@ -58,6 +59,7 @@ public void run() { }; private final AtomicBoolean isRefreshing = new AtomicBoolean(false); + private final ConcurrentLinkedQueue paramsToReadFromVehicle = new ConcurrentLinkedQueue<>(); private int expectedParams; @@ -80,6 +82,7 @@ public ParameterManager(MavLinkDrone myDrone, Context context, Handler handler) public void refreshParameters() { if (isRefreshing.compareAndSet(false, true)) { + paramsToReadFromVehicle.clear(); expectedParams = 0; parameters.clear(); paramsRollCall.clear(); @@ -115,12 +118,15 @@ public boolean processMessage(MAVLinkMessage msg) { } protected void processReceivedParam(msg_param_value m_value) { + String paramName = m_value.getParam_Id(); + if(!paramsToReadFromVehicle.remove(paramName) && !isRefreshing.get()) + return; // collect params in parameter list - Parameter param = new Parameter(m_value.getParam_Id(), m_value.param_value, m_value.param_type); + Parameter param = new Parameter(paramName, m_value.param_value, m_value.param_type); loadParameterMetadata(param); - parameters.put(param.getName().toLowerCase(Locale.US), param); int paramIndex = m_value.param_index; + parameters.put(param.getName().toLowerCase(Locale.US), param); if (paramIndex == -1) { // update listener notifyParameterReceipt(param, 0, 1); @@ -137,9 +143,9 @@ protected void processReceivedParam(msg_param_value m_value) { // Are all parameters here? Notify the listener with the parameters if (parameters.size() >= m_value.param_count) { - killWatchdog(); - isRefreshing.set(false); - + if(isRefreshing.compareAndSet(true, false)) { + killWatchdog(); + } notifyParametersReceiptEnd(); } else { resetWatchdog(); @@ -155,10 +161,12 @@ private void reRequestMissingParams(int howManyParams) { } public void sendParameter(Parameter parameter) { + paramsToReadFromVehicle.add(parameter.getName()); MavLinkParameters.sendParameter(myDrone, parameter); } public void readParameter(String name) { + paramsToReadFromVehicle.add(name); MavLinkParameters.readParameter(myDrone, name); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterMetadata.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterMetadata.java similarity index 84% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterMetadata.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterMetadata.java index c91ad5d50d..fcadb911fe 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/ParameterMetadata.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/ParameterMetadata.java @@ -1,10 +1,6 @@ -package org.droidplanner.services.android.core.drone.profiles; +package org.droidplanner.services.android.impl.core.drone.profiles; import java.io.Serializable; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.util.LinkedHashMap; -import java.util.Map; public class ParameterMetadata implements Serializable { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/VehicleProfile.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/VehicleProfile.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/VehicleProfile.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/VehicleProfile.java index c5185dba3d..99169bc869 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/profiles/VehicleProfile.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/profiles/VehicleProfile.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.profiles; +package org.droidplanner.services.android.impl.core.drone.profiles; public class VehicleProfile { private String parameterMetadataType; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/ApmModes.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/ApmModes.java similarity index 98% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/ApmModes.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/ApmModes.java index 89cb85de50..5246e570ea 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/ApmModes.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/ApmModes.java @@ -1,10 +1,10 @@ -package org.droidplanner.services.android.core.drone.variables; +package org.droidplanner.services.android.impl.core.drone.variables; + +import com.MAVLink.enums.MAV_TYPE; import java.util.ArrayList; import java.util.List; -import com.MAVLink.enums.MAV_TYPE; - public enum ApmModes { FIXED_WING_MANUAL (0,"Manual",MAV_TYPE.MAV_TYPE_FIXED_WING), FIXED_WING_CIRCLE (1,"Circle",MAV_TYPE.MAV_TYPE_FIXED_WING), diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Camera.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Camera.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Camera.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Camera.java index 8e6c2dabe5..ad29c679c3 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Camera.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Camera.java @@ -1,22 +1,22 @@ -package org.droidplanner.services.android.core.drone.variables; - -import java.util.ArrayList; -import java.util.List; - -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.core.survey.Footprint; +package org.droidplanner.services.android.impl.core.drone.variables; import com.MAVLink.ardupilotmega.msg_camera_feedback; import com.MAVLink.ardupilotmega.msg_mount_status; + +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.core.survey.Footprint; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Altitude; import com.o3dr.services.android.lib.drone.property.Attitude; import com.o3dr.services.android.lib.drone.property.Gps; +import java.util.ArrayList; +import java.util.List; + public class Camera extends DroneVariable { private CameraInfo camera = new CameraInfo(); private List footprints = new ArrayList(); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/GuidedPoint.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/GuidedPoint.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/GuidedPoint.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/GuidedPoint.java index 6dc640e836..7f88143cda 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/GuidedPoint.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/GuidedPoint.java @@ -1,8 +1,14 @@ -package org.droidplanner.services.android.core.drone.variables; +package org.droidplanner.services.android.impl.core.drone.variables; import android.os.Handler; import android.os.RemoteException; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; @@ -11,13 +17,6 @@ import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.SimpleCommandListener; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneInterfaces.OnDroneListener; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.Drone; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - import timber.log.Timber; public class GuidedPoint extends DroneVariable implements OnDroneListener { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/HeartBeat.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/HeartBeat.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/HeartBeat.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/HeartBeat.java index cc8814d1d7..76cf147ec5 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/HeartBeat.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/HeartBeat.java @@ -1,14 +1,14 @@ -package org.droidplanner.services.android.core.drone.variables; +package org.droidplanner.services.android.impl.core.drone.variables; import android.os.Handler; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.common.msg_heartbeat; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneInterfaces.OnDroneListener; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import timber.log.Timber; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Magnetometer.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Magnetometer.java similarity index 77% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Magnetometer.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Magnetometer.java index 22f42e9e61..3c6f67179c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Magnetometer.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Magnetometer.java @@ -1,10 +1,10 @@ -package org.droidplanner.services.android.core.drone.variables; - -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.drone.variables; import com.MAVLink.common.msg_raw_imu; + +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.drone.property.Parameter; public class Magnetometer extends DroneVariable { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/MissionStats.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/MissionStats.java similarity index 75% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/MissionStats.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/MissionStats.java index e108e314f2..10867f128b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/MissionStats.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/MissionStats.java @@ -1,8 +1,8 @@ -package org.droidplanner.services.android.core.drone.variables; +package org.droidplanner.services.android.impl.core.drone.variables; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; public class MissionStats extends DroneVariable { private double distanceToWp = 0; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/RC.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/RC.java similarity index 74% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/RC.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/RC.java index db21dfaa8a..6910f41638 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/RC.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/RC.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.drone.variables; - -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.drone.variables; import com.MAVLink.common.msg_rc_channels_raw; import com.MAVLink.common.msg_servo_output_raw; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + public class RC extends DroneVariable { public int in[] = new int[8]; public int out[] = new int[8]; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/State.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/State.java similarity index 91% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/State.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/State.java index 1d9120757b..49860dca09 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/State.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/State.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.drone.variables; +package org.droidplanner.services.android.impl.core.drone.variables; import android.os.Handler; import android.os.RemoteException; @@ -6,18 +6,18 @@ import com.MAVLink.ardupilotmega.msg_ekf_status_report; import com.MAVLink.enums.EKF_STATUS_FLAGS; + +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.MAVLink.WaypointManager; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.MAVLink.WaypointManager; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - import timber.log.Timber; public class State extends DroneVariable { diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/StreamRates.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/StreamRates.java new file mode 100644 index 0000000000..3975a9b66d --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/StreamRates.java @@ -0,0 +1,121 @@ +package org.droidplanner.services.android.impl.core.drone.variables; + +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkStreamRates; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + +public class StreamRates extends DroneVariable implements OnDroneListener { + + private Rates rates; + + public StreamRates(MavLinkDrone myDrone) { + super(myDrone); + myDrone.addDroneListener(this); + } + + public void setRates(Rates rates) { + if(this.rates == null || !this.rates.equals(rates)) { + this.rates = rates; + if (myDrone.isConnected() && myDrone.isConnectionAlive()) { + setupStreamRatesFromPref(); + } + } + } + + @Override + public void onDroneEvent(DroneEventsType event, MavLinkDrone drone) { + switch (event) { + case CONNECTED: + case HEARTBEAT_FIRST: + case HEARTBEAT_RESTORED: + setupStreamRatesFromPref(); + break; + default: + break; + } + } + + private void setupStreamRatesFromPref() { + if(rates == null) + return; + + MavLinkStreamRates.setupStreamRates(myDrone.getMavClient(), myDrone.getSysid(), + myDrone.getCompid(), rates.extendedStatus, rates.extra1, rates.extra2, + rates.extra3, rates.position, rates.rcChannels, rates.rawSensors, + rates.rawController); + } + + public static class Rates { + public int extendedStatus; + public int extra1; + public int extra2; + public int extra3; + public int position; + public int rcChannels; + public int rawSensors; + public int rawController; + + public Rates(int rate){ + this.extendedStatus = rate; + this.extra1 = rate; + this.extra2 = rate; + this.extra3 = rate; + this.position = rate; + this.rcChannels = rate; + this.rawSensors = rate; + this.rawController = rate; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Rates)) { + return false; + } + + Rates rates = (Rates) o; + + if (extendedStatus != rates.extendedStatus) { + return false; + } + if (extra1 != rates.extra1) { + return false; + } + if (extra2 != rates.extra2) { + return false; + } + if (extra3 != rates.extra3) { + return false; + } + if (position != rates.position) { + return false; + } + if (rcChannels != rates.rcChannels) { + return false; + } + if (rawSensors != rates.rawSensors) { + return false; + } + return rawController == rates.rawController; + + } + + @Override + public int hashCode() { + int result = extendedStatus; + result = 31 * result + extra1; + result = 31 * result + extra2; + result = 31 * result + extra3; + result = 31 * result + position; + result = 31 * result + rcChannels; + result = 31 * result + rawSensors; + result = 31 * result + rawController; + return result; + } + } + +} diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Type.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Type.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Type.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Type.java index c9a6ea698a..836c7b6185 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/Type.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/Type.java @@ -1,13 +1,12 @@ -package org.droidplanner.services.android.core.drone.variables; - -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +package org.droidplanner.services.android.impl.core.drone.variables; import com.MAVLink.enums.MAV_TYPE; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; + public class Type extends DroneVariable implements DroneInterfaces.OnDroneListener{ private static final int DEFAULT_TYPE = MAV_TYPE.MAV_TYPE_GENERIC; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/AccelCalibration.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/AccelCalibration.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/AccelCalibration.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/AccelCalibration.java index 11b40a376a..a26344259b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/AccelCalibration.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/AccelCalibration.java @@ -1,19 +1,19 @@ -package org.droidplanner.services.android.core.drone.variables.calibration; +package org.droidplanner.services.android.impl.core.drone.variables.calibration; import android.os.Handler; import android.os.RemoteException; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.common.msg_statustext; + +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCalibration; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.SimpleCommandListener; -import org.droidplanner.services.android.core.MAVLink.MavLinkCalibration; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - import java.util.concurrent.atomic.AtomicReference; import timber.log.Timber; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/MagnetometerCalibrationImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/MagnetometerCalibrationImpl.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/MagnetometerCalibrationImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/MagnetometerCalibrationImpl.java index 7ab1fe3006..781daacc41 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/drone/variables/calibration/MagnetometerCalibrationImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/variables/calibration/MagnetometerCalibrationImpl.java @@ -1,13 +1,13 @@ -package org.droidplanner.services.android.core.drone.variables.calibration; +package org.droidplanner.services.android.impl.core.drone.variables.calibration; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.ardupilotmega.msg_mag_cal_progress; import com.MAVLink.ardupilotmega.msg_mag_cal_report; -import org.droidplanner.services.android.core.MAVLink.MavLinkCalibration; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCalibration; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; import java.util.HashMap; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/firmware/FirmwareType.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/firmware/FirmwareType.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/firmware/FirmwareType.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/firmware/FirmwareType.java index 4069d10183..9863d0aa5e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/firmware/FirmwareType.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/firmware/FirmwareType.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.firmware; +package org.droidplanner.services.android.impl.core.firmware; import com.MAVLink.enums.MAV_AUTOPILOT; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/GCSHeartbeat.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/GCSHeartbeat.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/GCSHeartbeat.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/GCSHeartbeat.java index 102aa5bf6f..0f76fcbd60 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/GCSHeartbeat.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/GCSHeartbeat.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.gcs; +package org.droidplanner.services.android.impl.core.gcs; import com.MAVLink.Messages.MAVLinkMessage; import com.MAVLink.common.msg_heartbeat; import com.MAVLink.enums.MAV_AUTOPILOT; import com.MAVLink.enums.MAV_TYPE; -import org.droidplanner.services.android.communication.model.DataLink; +import org.droidplanner.services.android.impl.communication.model.DataLink; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/ReturnToMe.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/ReturnToMe.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/ReturnToMe.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/ReturnToMe.java index b41e18f6f3..00e251f5bb 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/ReturnToMe.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/ReturnToMe.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.gcs; +package org.droidplanner.services.android.impl.core.gcs; import android.os.Bundle; @@ -13,13 +13,13 @@ import com.o3dr.services.android.lib.model.ICommandListener; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds; -import org.droidplanner.services.android.core.drone.DroneInterfaces; -import org.droidplanner.services.android.core.drone.DroneInterfaces.AttributeEventListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.utils.CommonApiUtils; +import org.droidplanner.services.android.impl.core.MAVLink.command.doCmd.MavLinkDoCmds; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.AttributeEventListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.utils.CommonApiUtils; import java.util.concurrent.atomic.AtomicBoolean; @@ -50,7 +50,6 @@ public class ReturnToMe implements DroneInterfaces.OnDroneListener public ReturnToMe(MavLinkDroneManager droneMgr, Location.LocationFinder locationFinder, AttributeEventListener listener) { this.droneMgr = droneMgr; this.locationFinder = locationFinder; - locationFinder.addLocationListener(TAG, this); this.attributeListener = listener; this.currentState = new ReturnToMeState(); @@ -201,7 +200,7 @@ private void updateCurrentState(@ReturnToMeState.ReturnToMeStates int state) { if (attributeListener != null) { final Bundle eventInfo = new Bundle(); eventInfo.putInt(AttributeEventExtra.EXTRA_RETURN_TO_ME_STATE, state); - attributeListener.onAttributeEvent(AttributeEvent.RETURN_TO_ME_STATE_UPDATE, eventInfo, false); + attributeListener.onAttributeEvent(AttributeEvent.RETURN_TO_ME_STATE_UPDATE, eventInfo); } } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/Follow.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/Follow.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/Follow.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/Follow.java index be4f923ce4..3bafa2b95b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/Follow.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/Follow.java @@ -1,6 +1,5 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; -import android.content.Context; import android.os.Handler; import com.o3dr.services.android.lib.drone.action.ControlActions; @@ -8,16 +7,16 @@ import com.o3dr.services.android.lib.gcs.follow.FollowLocationSource; import com.o3dr.services.android.lib.model.action.Action; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneInterfaces.OnDroneListener; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.ArduSolo; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.drone.variables.GuidedPoint; -import org.droidplanner.services.android.core.drone.variables.State; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.gcs.location.Location.LocationFinder; -import org.droidplanner.services.android.core.gcs.location.Location.LocationReceiver; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.OnDroneListener; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.ArduSolo; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.drone.variables.GuidedPoint; +import org.droidplanner.services.android.impl.core.drone.variables.State; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.gcs.location.Location.LocationFinder; +import org.droidplanner.services.android.impl.core.gcs.location.Location.LocationReceiver; import timber.log.Timber; @@ -25,7 +24,7 @@ public class Follow implements OnDroneListener, LocationReceiver { private static final String TAG = Follow.class.getSimpleName(); private Location lastLocation; - private FollowLocationSource mLocationSource = null; + private FollowLocationSource mLocationSource; /** * Set of return value for the 'toggleFollowMeState' method. @@ -41,7 +40,7 @@ public enum FollowStates { private FollowAlgorithm followAlgorithm; private final LocationRelay mLocationRelay; - public Follow(Context context, MavLinkDroneManager droneMgr, Handler handler, LocationFinder locationFinder) { + public Follow(MavLinkDroneManager droneMgr, Handler handler, LocationFinder locationFinder) { this.droneMgr = droneMgr; final MavLinkDrone drone = droneMgr.getDrone(); if(drone != null) @@ -52,36 +51,36 @@ public Follow(Context context, MavLinkDroneManager droneMgr, Handler handler, Lo FollowAlgorithm.FollowModes.LEASH.getAlgorithmType(droneMgr, handler); this.locationFinder = locationFinder; - locationFinder.addLocationListener(TAG, this); - mLocationRelay = new LocationRelay(); } public void enableFollowMe(FollowLocationSource source) { - final MavLinkDrone drone = droneMgr.getDrone(); - final State droneState = (drone != null)? drone.getState(): null; - - if(droneState == null) { - Timber.w("No drone for enableFollowMe(%s)", source); - state = FollowStates.FOLLOW_INVALID_STATE; - return; - } + if (!isEnabled()) { + final MavLinkDrone drone = droneMgr.getDrone(); + final State droneState = (drone != null) ? drone.getState() : null; + + if (droneState == null) { + Timber.w("No drone for enableFollowMe(%s)", source); + state = FollowStates.FOLLOW_INVALID_STATE; + return; + } - if(droneMgr.isConnected()) { - if(droneState.isArmed()) { - GuidedPoint.changeToGuidedMode(drone, null); - setLocationSource(source); - state = FollowStates.FOLLOW_START; - mLocationRelay.onFollowStart(); - followAlgorithm.enableFollow(); + if (droneMgr.isConnected()) { + if (droneState.isArmed()) { + GuidedPoint.changeToGuidedMode(drone, null); + state = FollowStates.FOLLOW_START; + followAlgorithm.enableFollow(); - droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_START, null, false); + droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_START, null); + } else { + state = FollowStates.FOLLOW_DRONE_NOT_ARMED; + } } else { - state = FollowStates.FOLLOW_DRONE_NOT_ARMED; + state = FollowStates.FOLLOW_DRONE_DISCONNECTED; } - } else { - state = FollowStates.FOLLOW_DRONE_DISCONNECTED; } + + setLocationSource(source); } public void disableFollowMe() { @@ -89,15 +88,13 @@ public void disableFollowMe() { followAlgorithm.disableFollow(); - if(mLocationSource == FollowLocationSource.INTERNAL) { - locationFinder.disableLocationUpdates(TAG); - } + setLocationSource(FollowLocationSource.NONE); lastLocation = null; if (isEnabled()) { state = FollowStates.FOLLOW_END; - droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_STOP, null, false); + droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_STOP, null); } final MavLinkDrone drone = droneMgr.getDrone(); @@ -158,7 +155,7 @@ public void onLocationUpdate(Location location) { state = FollowStates.FOLLOW_START; } - droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_UPDATE, null, false); + droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_UPDATE, null); } @Override @@ -183,7 +180,7 @@ public void setAlgorithm(FollowAlgorithm algorithm) { followAlgorithm.onLocationReceived(lastLocation); } - droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_UPDATE, null, false); + droneMgr.onAttributeEvent(AttributeEvent.FOLLOW_UPDATE, null); } public FollowAlgorithm getFollowAlgorithm() { @@ -195,11 +192,15 @@ public FollowStates getState() { } private void setLocationSource(FollowLocationSource source) { + if(!isEnabled()) + return; + if(mLocationSource != source) { switch(source) { case CLIENT_SPECIFIED: { Timber.d("Switch to client-specified locations"); locationFinder.disableLocationUpdates(TAG); + mLocationRelay.onFollowStart(); break; } @@ -208,6 +209,12 @@ private void setLocationSource(FollowLocationSource source) { locationFinder.enableLocationUpdates(TAG, this); break; } + + case NONE: + default:{ + locationFinder.disableLocationUpdates(TAG); + break; + } } mLocationSource = source; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAbove.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAbove.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAbove.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAbove.java index abba4c9076..f5642ef3c6 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAbove.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAbove.java @@ -1,13 +1,12 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - public class FollowAbove extends FollowAlgorithm { protected final MavLinkDrone drone; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAlgorithm.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAlgorithm.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAlgorithm.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAlgorithm.java index 60c8fffa99..7f2ea387b0 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowAlgorithm.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowAlgorithm.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.gcs.roi.ROIEstimator; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.gcs.roi.ROIEstimator; import java.util.Collections; import java.util.Map; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowCircle.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowCircle.java similarity index 75% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowCircle.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowCircle.java index dff589bb38..8a95b929ce 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowCircle.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowCircle.java @@ -1,14 +1,13 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.util.MathUtils; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; - public class FollowCircle extends FollowWithRadiusAlgorithm { /** * °/s diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowGuidedScan.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowGuidedScan.java similarity index 87% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowGuidedScan.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowGuidedScan.java index c83292cdec..91e6b688d1 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowGuidedScan.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowGuidedScan.java @@ -1,15 +1,14 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.MAVLink.command.doCmd.MavLinkDoCmds; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.roi.ROIEstimator; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.roi.ROIEstimator; - import java.util.HashMap; import java.util.Map; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowHeadingAngle.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowHeadingAngle.java similarity index 68% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowHeadingAngle.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowHeadingAngle.java index 5c71d0f93f..7fa5a5f5d5 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowHeadingAngle.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowHeadingAngle.java @@ -1,14 +1,13 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; - public abstract class FollowHeadingAngle extends FollowWithRadiusAlgorithm { protected double angleOffset; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLead.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLead.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLead.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLead.java index f9e1517aeb..7527c06dcd 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLead.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLead.java @@ -1,8 +1,8 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; public class FollowLead extends FollowHeadingAngle { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeash.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeash.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeash.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeash.java index 86320669c6..afcb2dbafe 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeash.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeash.java @@ -1,15 +1,14 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Gps; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; - public class FollowLeash extends FollowWithRadiusAlgorithm { public FollowLeash(MavLinkDroneManager droneMgr, Handler handler, double radius) { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeft.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeft.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeft.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeft.java index cf0c8d65ec..d776973128 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLeft.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLeft.java @@ -1,8 +1,8 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; public class FollowLeft extends FollowHeadingAngle { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLookAtMe.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLookAtMe.java similarity index 65% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLookAtMe.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLookAtMe.java index ed1d197b4e..1c903f667b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowLookAtMe.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowLookAtMe.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; /** * Created by Fredia Huya-Kouadio on 3/23/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowRight.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowRight.java similarity index 68% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowRight.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowRight.java index aee1a07c4f..f12254ca1f 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowRight.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowRight.java @@ -1,8 +1,8 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; public class FollowRight extends FollowHeadingAngle { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSoloShot.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSoloShot.java similarity index 83% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSoloShot.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSoloShot.java index d79a676e92..50601733ee 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSoloShot.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSoloShot.java @@ -1,18 +1,17 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.ArduSolo; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.SoloComp; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.gcs.roi.ROIEstimator; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.drone.companion.solo.tlv.SoloMessageLocation; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.ArduSolo; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.SoloComp; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.gcs.roi.ROIEstimator; - /** * Created by Fredia Huya-Kouadio on 8/3/15. */ diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineAbove.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineAbove.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineAbove.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineAbove.java index 7a504557be..ddd6ae6b02 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineAbove.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineAbove.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; /** * Created by fhuya on 1/5/15. @@ -19,7 +19,6 @@ public class FollowSplineAbove extends FollowAlgorithm { public void processNewLocation(Location location) { LatLong gcsLoc = new LatLong(location.getCoord()); - //TODO: some device (nexus 6) do not report the speed (always 0).. figure out workaround. double speed = location.getSpeed(); double bearing = location.getBearing(); double bearingInRad = Math.toRadians(bearing); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineLeash.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineLeash.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineLeash.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineLeash.java index 7f23b8bab5..27b8d65f6c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowSplineLeash.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowSplineLeash.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; @@ -7,9 +7,9 @@ import com.o3dr.services.android.lib.drone.attribute.AttributeType; import com.o3dr.services.android.lib.drone.property.Gps; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; /** * Created by fhuya on 1/5/15. @@ -29,7 +29,6 @@ public void processNewLocation(Location location) { double headingGCSToDrone = GeoTools.getHeadingFromCoordinates(userLoc, droneLoc); LatLong goCoord = GeoTools.newCoordFromBearingAndDistance(userLoc, headingGCSToDrone, radius); - //TODO: some device (nexus 6) do not report the speed (always 0).. figure out workaround. double speed = location.getSpeed(); double bearing = location.getBearing(); double bearingInRad = Math.toRadians(bearing); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowWithRadiusAlgorithm.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowWithRadiusAlgorithm.java similarity index 81% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowWithRadiusAlgorithm.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowWithRadiusAlgorithm.java index 6156c5e119..c996ccaf98 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/FollowWithRadiusAlgorithm.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/FollowWithRadiusAlgorithm.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import android.os.Handler; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.manager.MavLinkDroneManager; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.manager.MavLinkDroneManager; import java.util.HashMap; import java.util.Map; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/LocationRelay.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/LocationRelay.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/LocationRelay.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/LocationRelay.java index ccb3a13800..dc31bd61bf 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/follow/LocationRelay.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/follow/LocationRelay.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.core.gcs.follow; +package org.droidplanner.services.android.impl.core.gcs.follow; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.gcs.location.Location; import timber.log.Timber; @@ -26,10 +26,6 @@ public static String getLatLongFromLocation(final android.location.Location loca private float mTotalSpeed = 0; private int mSpeedReadings = 0; - public LocationRelay() { - super(); - } - public void onFollowStart() { mTotalSpeed = 0; mSpeedReadings = 0; @@ -40,6 +36,9 @@ public void onFollowStart() { * Convert the specified Android location to a local Location, and track speed/accuracy */ public Location toGcsLocation(android.location.Location androidLocation) { + if(androidLocation == null) + return null; + Location gcsLocation = null; if(VERBOSE) Timber.d("toGcsLocation(): followLoc=" + androidLocation); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/location/FusedLocation.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/FusedLocation.java similarity index 89% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/location/FusedLocation.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/FusedLocation.java index 70c94626f6..b07fbaff1f 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/location/FusedLocation.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/FusedLocation.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.gcs.location; +package org.droidplanner.services.android.impl.core.gcs.location; import android.content.Context; import android.location.Location; @@ -15,9 +15,9 @@ import com.o3dr.services.android.lib.util.googleApi.GoogleApiClientManager; import com.o3dr.services.android.lib.util.googleApi.GoogleApiClientManager.GoogleApiClientTask; -import org.droidplanner.services.android.core.gcs.follow.LocationRelay; -import org.droidplanner.services.android.core.gcs.location.Location.LocationFinder; -import org.droidplanner.services.android.core.gcs.location.Location.LocationReceiver; +import org.droidplanner.services.android.impl.core.gcs.follow.LocationRelay; +import org.droidplanner.services.android.impl.core.gcs.location.Location.LocationFinder; +import org.droidplanner.services.android.impl.core.gcs.location.Location.LocationReceiver; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -81,8 +81,8 @@ protected void doRun() { @Override public void enableLocationUpdates(String tag, LocationReceiver receiver) { + receivers.put(tag, receiver); if(!mLocationUpdatesEnabled) { - receivers.put(tag, receiver); gApiMgr.start(); locationRelay.onFollowStart(); mLocationUpdatesEnabled = true; @@ -92,11 +92,11 @@ public void enableLocationUpdates(String tag, LocationReceiver receiver) { @Override public void disableLocationUpdates(String tag) { if(mLocationUpdatesEnabled) { - receivers.remove(tag); gApiMgr.addTask(removeLocationUpdate); gApiMgr.stopSafely(); mLocationUpdatesEnabled = false; } + receivers.remove(tag); } @Override @@ -112,15 +112,18 @@ public void onLocationResult(LocationResult result) { if (androidLocation == null) return; - org.droidplanner.services.android.core.gcs.location.Location gcsLocation = + org.droidplanner.services.android.impl.core.gcs.location.Location gcsLocation = locationRelay.toGcsLocation(androidLocation); + if(gcsLocation == null) + return; + Timber.d("Location Lat/Long: " + LocationRelay.getLatLongFromLocation(androidLocation)); notifyLocationUpdate(gcsLocation); } - private void notifyLocationUpdate(org.droidplanner.services.android.core.gcs.location.Location location) { + private void notifyLocationUpdate(org.droidplanner.services.android.impl.core.gcs.location.Location location) { if (receivers.isEmpty()) { Timber.d(TAG, "notifyLocationUpdate(): No receivers"); return; @@ -131,16 +134,6 @@ private void notifyLocationUpdate(org.droidplanner.services.android.core.gcs.loc } } - @Override - public void addLocationListener(String tag, LocationReceiver receiver) { - receivers.put(tag, receiver); - } - - @Override - public void removeLocationListener(String tag) { - receivers.remove(tag); - } - @Override public void onGoogleApiConnectionError(ConnectionResult result) { notifyLocationUnavailable(); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/location/Location.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/Location.java similarity index 87% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/location/Location.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/Location.java index ad3ec4e232..5636bb4759 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/location/Location.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/location/Location.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.gcs.location; +package org.droidplanner.services.android.impl.core.gcs.location; import com.o3dr.services.android.lib.coordinate.LatLongAlt; @@ -13,9 +13,6 @@ public interface LocationReceiver { public interface LocationFinder { void enableLocationUpdates(String tag, LocationReceiver receiver); void disableLocationUpdates(String tag); - - void addLocationListener(String tag, LocationReceiver receiver); - void removeLocationListener(String tag); } private LatLongAlt coordinate; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/package-info.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/package-info.java similarity index 64% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/package-info.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/package-info.java index 3e9e6cbe7f..34d13ef5b1 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/package-info.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/package-info.java @@ -1,4 +1,4 @@ /** * This package contains code and logic related to the ground control station functionality. */ -package org.droidplanner.services.android.core.gcs; \ No newline at end of file +package org.droidplanner.services.android.impl.core.gcs; \ No newline at end of file diff --git a/ServiceApp/src/org/droidplanner/services/android/core/gcs/roi/ROIEstimator.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/roi/ROIEstimator.java similarity index 85% rename from ServiceApp/src/org/droidplanner/services/android/core/gcs/roi/ROIEstimator.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/roi/ROIEstimator.java index 7b8a8b8fb3..c35254a868 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/gcs/roi/ROIEstimator.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/gcs/roi/ROIEstimator.java @@ -1,16 +1,15 @@ -package org.droidplanner.services.android.core.gcs.roi; +package org.droidplanner.services.android.impl.core.gcs.roi; import android.os.Handler; +import org.droidplanner.services.android.impl.core.MAVLink.command.doCmd.MavLinkDoCmds; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.gcs.location.Location; +import org.droidplanner.services.android.impl.core.gcs.location.Location.LocationReceiver; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.gcs.location.Location; -import org.droidplanner.services.android.core.gcs.location.Location.LocationReceiver; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; - import java.util.concurrent.atomic.AtomicBoolean; /** diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/coordinates/CoordBounds.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBounds.java similarity index 90% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/coordinates/CoordBounds.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBounds.java index c6d19f86e1..00dd39e474 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/coordinates/CoordBounds.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/coordinates/CoordBounds.java @@ -1,11 +1,10 @@ -package org.droidplanner.services.android.core.helpers.coordinates; +package org.droidplanner.services.android.impl.core.helpers.coordinates; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.List; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; - /** * Calculate a rectangle that bounds all inserted points */ diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/GeoTools.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoTools.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/GeoTools.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoTools.java index 487b54e967..142607b3d1 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/GeoTools.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/GeoTools.java @@ -1,12 +1,11 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; +import org.droidplanner.services.android.impl.core.helpers.units.Area; +import org.droidplanner.services.android.impl.core.polygon.Polygon; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; import com.o3dr.services.android.lib.util.MathUtils; -import org.droidplanner.services.android.core.helpers.units.Area; -import org.droidplanner.services.android.core.polygon.Polygon; - import java.util.List; import static java.lang.Math.PI; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineLatLong.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineLatLong.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineLatLong.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineLatLong.java index 9158204156..509ea9c5d0 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineLatLong.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineLatLong.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineSampler.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineSampler.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineSampler.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineSampler.java index 27fe9d0cf9..213160186a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineSampler.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineSampler.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineTools.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineTools.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineTools.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineTools.java index 1c7e94bb6f..bf155f5c03 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/LineTools.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/LineTools.java @@ -1,12 +1,11 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; +import org.droidplanner.services.android.impl.core.helpers.coordinates.CoordBounds; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.ArrayList; import java.util.List; -import org.droidplanner.services.android.core.helpers.coordinates.CoordBounds; - public class LineTools { public static LineLatLong findExternalPoints(ArrayList crosses) { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PointTools.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PointTools.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PointTools.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PointTools.java index 249e04983a..0fc5e4e75c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PointTools.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PointTools.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PolylineTools.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PolylineTools.java similarity index 89% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PolylineTools.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PolylineTools.java index 4d90a6ea52..1649eadbff 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/PolylineTools.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/PolylineTools.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/Simplify.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/Simplify.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/Simplify.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/Simplify.java index 8fb8440764..8ee6cfb75e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/Simplify.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/Simplify.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools; +package org.droidplanner.services.android.impl.core.helpers.geoTools; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/Spline.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/Spline.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/Spline.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/Spline.java index 202ebf756f..cbc9f1c7fb 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/Spline.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/Spline.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools.spline; +package org.droidplanner.services.android.impl.core.helpers.geoTools.spline; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/SplinePath.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/SplinePath.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/SplinePath.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/SplinePath.java index 6dc89c5c2d..5926309855 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/geoTools/spline/SplinePath.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/geoTools/spline/SplinePath.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.geoTools.spline; +package org.droidplanner.services.android.impl.core.helpers.geoTools.spline; import com.o3dr.services.android.lib.coordinate.LatLong; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/helpers/units/Area.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/units/Area.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/helpers/units/Area.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/units/Area.java index 34c3d951a5..da86121aa0 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/helpers/units/Area.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/helpers/units/Area.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.helpers.units; +package org.droidplanner.services.android.impl.core.helpers.units; import java.util.Locale; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/Mission.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionImpl.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/Mission.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionImpl.java index 73eb58aa3c..ee1e900079 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/Mission.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionImpl.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.mission; +package org.droidplanner.services.android.impl.core.mission; import android.util.Pair; @@ -14,27 +14,19 @@ import com.o3dr.services.android.lib.drone.property.Home; import com.o3dr.services.android.lib.drone.property.Parameter; -import org.droidplanner.services.android.core.drone.DroneInterfaces.DroneEventsType; -import org.droidplanner.services.android.core.drone.DroneVariable; -import org.droidplanner.services.android.core.drone.autopilot.apm.APMConstants; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.mission.commands.CameraTriggerImpl; -import org.droidplanner.services.android.core.mission.commands.ChangeSpeedImpl; -import org.droidplanner.services.android.core.mission.commands.ConditionYawImpl; -import org.droidplanner.services.android.core.mission.commands.DoJumpImpl; -import org.droidplanner.services.android.core.mission.commands.EpmGripperImpl; -import org.droidplanner.services.android.core.mission.commands.ReturnToHomeImpl; -import org.droidplanner.services.android.core.mission.commands.SetRelayImpl; -import org.droidplanner.services.android.core.mission.commands.SetServoImpl; -import org.droidplanner.services.android.core.mission.commands.TakeoffImpl; -import org.droidplanner.services.android.core.mission.waypoints.CircleImpl; -import org.droidplanner.services.android.core.mission.waypoints.DoLandStartImpl; -import org.droidplanner.services.android.core.mission.waypoints.LandImpl; -import org.droidplanner.services.android.core.mission.waypoints.RegionOfInterestImpl; -import org.droidplanner.services.android.core.mission.waypoints.SpatialCoordItem; -import org.droidplanner.services.android.core.mission.waypoints.SplineWaypointImpl; -import org.droidplanner.services.android.core.mission.waypoints.WaypointImpl; +import org.droidplanner.services.android.impl.core.drone.DroneInterfaces.DroneEventsType; +import org.droidplanner.services.android.impl.core.drone.DroneVariable; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.APMConstants; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.mission.commands.ChangeSpeedImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ReturnToHomeImpl; +import org.droidplanner.services.android.impl.core.mission.commands.TakeoffImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.LandImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.RegionOfInterestImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.SpatialCoordItem; +import org.droidplanner.services.android.impl.core.mission.waypoints.WaypointImpl; +import org.droidplanner.services.android.impl.utils.MissionUtils; import java.util.ArrayList; import java.util.Collections; @@ -44,7 +36,7 @@ * This implements a mavlink mission. A mavlink mission is a set of * commands/mission items to be carried out by the drone. */ -public class Mission extends DroneVariable { +public class MissionImpl extends DroneVariable { /** * Stores the set of mission items belonging to this mission. @@ -52,7 +44,7 @@ public class Mission extends DroneVariable { private List items = new ArrayList(); private final List componentItems = new ArrayList<>(); - public Mission(GenericMavLinkDrone myDrone) { + public MissionImpl(GenericMavLinkDrone myDrone) { super(myDrone); } @@ -107,8 +99,7 @@ public void addMissionItem(int index, MissionItemImpl missionItemImpl) { } /** - * Signals that this mission object was updated. //TODO: maybe move outside - * of this class + * Signals that this mission object was updated. */ public void notifyMissionUpdate() { updateComponentItems(); @@ -215,7 +206,7 @@ public void onMissionReceived(List msgs) { myDrone.processHomeUpdate(msgs.get(0)); msgs.remove(0); // Remove Home waypoint items.clear(); - items.addAll(processMavLinkMessages(msgs)); + items.addAll(MissionUtils.processMavLinkMessages(this, msgs)); myDrone.notifyDroneEvent(DroneEventsType.MISSION_RECEIVED); notifyMissionUpdate(); } @@ -226,69 +217,12 @@ public void onMissionLoaded(List msgs) { myDrone.processHomeUpdate(msgs.get(0)); msgs.remove(0); // Remove Home waypoint items.clear(); - items.addAll(processMavLinkMessages(msgs)); + items.addAll(MissionUtils.processMavLinkMessages(this, msgs)); myDrone.notifyDroneEvent(DroneEventsType.MISSION_RECEIVED); notifyMissionUpdate(); } } - private List processMavLinkMessages(List msgs) { - List received = new ArrayList(); - for (msg_mission_item msg : msgs) { - switch (msg.command) { - case MAV_CMD.MAV_CMD_DO_SET_SERVO: - received.add(new SetServoImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_WAYPOINT: - received.add(new WaypointImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_SPLINE_WAYPOINT: - received.add(new SplineWaypointImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_LAND: - received.add(new LandImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_LAND_START: - received.add(new DoLandStartImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_TAKEOFF: - received.add(new TakeoffImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_CHANGE_SPEED: - received.add(new ChangeSpeedImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_SET_CAM_TRIGG_DIST: - received.add(new CameraTriggerImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_GRIPPER: - received.add(new EpmGripperImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_SET_ROI: - received.add(new RegionOfInterestImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_LOITER_TURNS: - received.add(new CircleImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_NAV_RETURN_TO_LAUNCH: - received.add(new ReturnToHomeImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_CONDITION_YAW: - received.add(new ConditionYawImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_SET_RELAY: - received.add(new SetRelayImpl(msg, this)); - break; - case MAV_CMD.MAV_CMD_DO_JUMP: - received.add(new DoJumpImpl(msg, this)); - break; - - default: - break; - } - } - return received; - } - /** * Sends the mission to the drone using the mavlink protocol. */ @@ -312,7 +246,7 @@ private void updateComponentItems(List msgMissionItems) { if(firstItem.seq == APMConstants.HOME_WAYPOINT_INDEX) { msgMissionItems.remove(0); // Remove Home waypoint } - componentItems.addAll(processMavLinkMessages(msgMissionItems)); + componentItems.addAll(MissionUtils.processMavLinkMessages(this, msgMissionItems)); } public msg_mission_item packHomeMavlink() { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemImpl.java similarity index 74% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemImpl.java index e191a82fc6..303a5f74d5 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemImpl.java @@ -1,21 +1,21 @@ -package org.droidplanner.services.android.core.mission; - -import java.util.ArrayList; -import java.util.List; +package org.droidplanner.services.android.impl.core.mission; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_FRAME; +import java.util.ArrayList; +import java.util.List; + public abstract class MissionItemImpl implements Comparable { - protected Mission mission; + protected MissionImpl missionImpl; - public MissionItemImpl(Mission mission) { - this.mission = mission; + public MissionItemImpl(MissionImpl missionImpl) { + this.missionImpl = missionImpl; } public MissionItemImpl(MissionItemImpl item) { - this(item.mission); + this(item.missionImpl); } /** @@ -42,13 +42,13 @@ public List packMissionItem() { public abstract MissionItemType getType(); - public Mission getMission() { - return mission; + public MissionImpl getMission() { + return missionImpl; } @Override public int compareTo(MissionItemImpl another) { - return mission.getOrder(this) - mission.getOrder(another); + return missionImpl.getOrder(this) - missionImpl.getOrder(another); } } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemType.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemType.java similarity index 63% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemType.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemType.java index 74bee68cad..294ad4ad6d 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/MissionItemType.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/MissionItemType.java @@ -1,26 +1,25 @@ -package org.droidplanner.services.android.core.mission; +package org.droidplanner.services.android.impl.core.mission; +import org.droidplanner.services.android.impl.core.mission.commands.CameraTriggerImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ChangeSpeedImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ConditionYawImpl; +import org.droidplanner.services.android.impl.core.mission.commands.DoJumpImpl; +import org.droidplanner.services.android.impl.core.mission.commands.EpmGripperImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ReturnToHomeImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetRelayImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetServoImpl; +import org.droidplanner.services.android.impl.core.mission.commands.TakeoffImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SplineSurveyImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SurveyImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.CircleImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.DoLandStartImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.LandImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.RegionOfInterestImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.SplineWaypointImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.StructureScannerImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.WaypointImpl; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.mission.commands.CameraTriggerImpl; -import org.droidplanner.services.android.core.mission.commands.ChangeSpeedImpl; -import org.droidplanner.services.android.core.mission.commands.ConditionYawImpl; -import org.droidplanner.services.android.core.mission.commands.DoJumpImpl; -import org.droidplanner.services.android.core.mission.commands.EpmGripperImpl; -import org.droidplanner.services.android.core.mission.commands.ReturnToHomeImpl; -import org.droidplanner.services.android.core.mission.commands.SetRelayImpl; -import org.droidplanner.services.android.core.mission.commands.SetServoImpl; -import org.droidplanner.services.android.core.mission.commands.TakeoffImpl; -import org.droidplanner.services.android.core.mission.survey.SplineSurveyImpl; -import org.droidplanner.services.android.core.mission.survey.SurveyImpl; -import org.droidplanner.services.android.core.mission.waypoints.CircleImpl; -import org.droidplanner.services.android.core.mission.waypoints.DoLandStartImpl; -import org.droidplanner.services.android.core.mission.waypoints.LandImpl; -import org.droidplanner.services.android.core.mission.waypoints.RegionOfInterestImpl; -import org.droidplanner.services.android.core.mission.waypoints.SplineWaypointImpl; -import org.droidplanner.services.android.core.mission.waypoints.StructureScannerImpl; -import org.droidplanner.services.android.core.mission.waypoints.WaypointImpl; - import java.util.Collections; public enum MissionItemType { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/CameraTriggerImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/CameraTriggerImpl.java similarity index 67% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/CameraTriggerImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/CameraTriggerImpl.java index faeec3a667..82e1502e3f 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/CameraTriggerImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/CameraTriggerImpl.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import java.util.List; @@ -16,13 +16,13 @@ public CameraTriggerImpl(MissionItemImpl item) { super(item); } - public CameraTriggerImpl(msg_mission_item msg, Mission mission) { - super(mission); + public CameraTriggerImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public CameraTriggerImpl(Mission mission, double triggerDistance) { - super(mission); + public CameraTriggerImpl(MissionImpl missionImpl, double triggerDistance) { + super(missionImpl); this.distance = triggerDistance; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ChangeSpeedImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ChangeSpeedImpl.java similarity index 70% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ChangeSpeedImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ChangeSpeedImpl.java index 14bc22bdb6..b034aea83a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ChangeSpeedImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ChangeSpeedImpl.java @@ -1,15 +1,15 @@ -package org.droidplanner.services.android.core.mission.commands; - -import java.util.List; - -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; + +import java.util.List; + public class ChangeSpeedImpl extends MissionCMD { private double speed = 5; //meters per second @@ -17,13 +17,13 @@ public ChangeSpeedImpl(MissionItemImpl item) { super(item); } - public ChangeSpeedImpl(msg_mission_item msg, Mission mission) { - super(mission); + public ChangeSpeedImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public ChangeSpeedImpl(Mission mission, double speed) { - super(mission); + public ChangeSpeedImpl(MissionImpl missionImpl, double speed) { + super(missionImpl); this.speed = speed; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ConditionYawImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ConditionYawImpl.java similarity index 72% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ConditionYawImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ConditionYawImpl.java index cef4ca8ec3..6715c71e2b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ConditionYawImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ConditionYawImpl.java @@ -1,15 +1,15 @@ -package org.droidplanner.services.android.core.mission.commands; - -import java.util.List; - -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; + +import java.util.List; + public class ConditionYawImpl extends MissionCMD { private boolean isRelative = false; private double angle = 0; @@ -19,13 +19,13 @@ public ConditionYawImpl(MissionItemImpl item) { super(item); } - public ConditionYawImpl(msg_mission_item msg, Mission mission) { - super(mission); + public ConditionYawImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public ConditionYawImpl(Mission mission, double angle, boolean isRelative) { - super(mission); + public ConditionYawImpl(MissionImpl missionImpl, double angle, boolean isRelative) { + super(missionImpl); setAngle(angle); setRelative(isRelative); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/DoJumpImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/DoJumpImpl.java similarity index 70% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/DoJumpImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/DoJumpImpl.java index eeac162bf0..3e49bfe411 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/DoJumpImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/DoJumpImpl.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import java.util.List; @@ -20,17 +20,17 @@ public DoJumpImpl(MissionItemImpl item){ super(item); } - public DoJumpImpl(Mission mission) { - super(mission); + public DoJumpImpl(MissionImpl missionImpl) { + super(missionImpl); } - public DoJumpImpl(msg_mission_item mavMsg, Mission mission){ - super(mission); + public DoJumpImpl(msg_mission_item mavMsg, MissionImpl missionImpl){ + super(missionImpl); unpackMAVMessage(mavMsg); } - public DoJumpImpl(Mission mission, int waypoint, int repeatCount){ - super(mission); + public DoJumpImpl(MissionImpl missionImpl, int waypoint, int repeatCount){ + super(missionImpl); this.waypoint = waypoint; this.repeatCount = repeatCount; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/EpmGripperImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/EpmGripperImpl.java similarity index 70% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/EpmGripperImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/EpmGripperImpl.java index 2022770490..6f2b556757 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/EpmGripperImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/EpmGripperImpl.java @@ -1,15 +1,15 @@ -package org.droidplanner.services.android.core.mission.commands; - -import java.util.List; - -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.GRIPPER_ACTIONS; import com.MAVLink.enums.MAV_CMD; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; + +import java.util.List; + public class EpmGripperImpl extends MissionCMD { private boolean release = true; @@ -18,13 +18,13 @@ public EpmGripperImpl(MissionItemImpl item) { super(item); } - public EpmGripperImpl(msg_mission_item msg, Mission mission) { - super(mission); + public EpmGripperImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public EpmGripperImpl(Mission mission, boolean release) { - super(mission); + public EpmGripperImpl(MissionImpl missionImpl, boolean release) { + super(missionImpl); this.release = release; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/MissionCMD.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/MissionCMD.java similarity index 51% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/MissionCMD.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/MissionCMD.java index f346e4d76e..7d1ddb71aa 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/MissionCMD.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/MissionCMD.java @@ -1,16 +1,16 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; -import java.util.List; +import com.MAVLink.common.msg_mission_item; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; -import com.MAVLink.common.msg_mission_item; +import java.util.List; public abstract class MissionCMD extends MissionItemImpl { - public MissionCMD(Mission mission) { - super(mission); + public MissionCMD(MissionImpl missionImpl) { + super(missionImpl); } public MissionCMD(MissionItemImpl item) { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ReturnToHomeImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ReturnToHomeImpl.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ReturnToHomeImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ReturnToHomeImpl.java index 2a8730e818..6121fd5cec 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/ReturnToHomeImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/ReturnToHomeImpl.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import java.util.List; @@ -19,13 +19,13 @@ public ReturnToHomeImpl(MissionItemImpl item) { returnAltitude = (0); } - public ReturnToHomeImpl(msg_mission_item msg, Mission mission) { - super(mission); + public ReturnToHomeImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public ReturnToHomeImpl(Mission mission) { - super(mission); + public ReturnToHomeImpl(MissionImpl missionImpl) { + super(missionImpl); returnAltitude = (0.0); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetRelayImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetRelayImpl.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetRelayImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetRelayImpl.java index c0afc4020a..bef674b659 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetRelayImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetRelayImpl.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import java.util.List; @@ -22,13 +22,13 @@ public SetRelayImpl(MissionItemImpl item){ super(item); } - public SetRelayImpl(msg_mission_item msg, Mission mission){ - super(mission); + public SetRelayImpl(msg_mission_item msg, MissionImpl missionImpl){ + super(missionImpl); unpackMAVMessage(msg); } - public SetRelayImpl(Mission mission, int relayNumber, boolean enabled){ - super(mission); + public SetRelayImpl(MissionImpl missionImpl, int relayNumber, boolean enabled){ + super(missionImpl); this.relayNumber = relayNumber; this.enabled = enabled; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetServoImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetServoImpl.java similarity index 68% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetServoImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetServoImpl.java index db1fce4349..eefbe7f5cf 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/SetServoImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/SetServoImpl.java @@ -1,14 +1,14 @@ -package org.droidplanner.services.android.core.mission.commands; - -import java.util.List; - -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; + +import java.util.List; + public class SetServoImpl extends MissionCMD { private int pwm; @@ -18,13 +18,13 @@ public SetServoImpl(MissionItemImpl item) { super(item); } - public SetServoImpl(msg_mission_item msg, Mission mission) { - super(mission); + public SetServoImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public SetServoImpl(Mission mission, int channel, int pwm) { - super(mission); + public SetServoImpl(MissionImpl missionImpl, int channel, int pwm) { + super(missionImpl); this.channel = channel; this.pwm = pwm; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/TakeoffImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/TakeoffImpl.java similarity index 72% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/commands/TakeoffImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/TakeoffImpl.java index e0d84f5870..a0cd0fd0c3 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/commands/TakeoffImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/commands/TakeoffImpl.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.mission.commands; +package org.droidplanner.services.android.impl.core.mission.commands; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import java.util.List; @@ -21,19 +21,19 @@ public TakeoffImpl(MissionItemImpl item) { super(item); } - public TakeoffImpl(msg_mission_item msg, Mission mission) { - super(mission); + public TakeoffImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl); unpackMAVMessage(msg); } - public TakeoffImpl(Mission mission, double altitude) { - super(mission); + public TakeoffImpl(MissionImpl missionImpl, double altitude) { + super(missionImpl); this.finishedAlt = altitude; this.pitch = 0; } - public TakeoffImpl(Mission mission, double altitude, double pitch) { - super(mission); + public TakeoffImpl(MissionImpl missionImpl, double altitude, double pitch) { + super(missionImpl); this.finishedAlt = altitude; this.pitch = pitch; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SplineSurveyImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SplineSurveyImpl.java similarity index 74% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SplineSurveyImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SplineSurveyImpl.java index 9a22fdd852..c9a7e4f663 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SplineSurveyImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SplineSurveyImpl.java @@ -1,19 +1,19 @@ -package org.droidplanner.services.android.core.mission.survey; +package org.droidplanner.services.android.impl.core.mission.survey; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; -import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; +import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.List; public class SplineSurveyImpl extends SurveyImpl { - public SplineSurveyImpl(Mission mission, List points) { - super(mission, points); + public SplineSurveyImpl(MissionImpl missionImpl, List points) { + super(missionImpl, points); } @Override diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SurveyImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SurveyImpl.java similarity index 81% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SurveyImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SurveyImpl.java index 9202df55d7..3853529acc 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/survey/SurveyImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/survey/SurveyImpl.java @@ -1,19 +1,19 @@ -package org.droidplanner.services.android.core.mission.survey; +package org.droidplanner.services.android.impl.core.mission.survey; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; -import org.droidplanner.services.android.core.mission.commands.CameraTriggerImpl; -import org.droidplanner.services.android.core.polygon.Polygon; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.core.survey.SurveyData; -import org.droidplanner.services.android.core.survey.grid.Grid; -import org.droidplanner.services.android.core.survey.grid.GridBuilder; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.commands.CameraTriggerImpl; +import org.droidplanner.services.android.impl.core.polygon.Polygon; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.core.survey.SurveyData; +import org.droidplanner.services.android.impl.core.survey.grid.Grid; +import org.droidplanner.services.android.impl.core.survey.grid.GridBuilder; import java.util.ArrayList; import java.util.List; @@ -26,8 +26,8 @@ public class SurveyImpl extends MissionItemImpl { private boolean startCameraBeforeFirstWaypoint; - public SurveyImpl(Mission mission, List points) { - super(mission); + public SurveyImpl(MissionImpl missionImpl, List points) { + super(missionImpl); polygon.addPoints(points); } @@ -71,7 +71,7 @@ public List packMissionItem() { private void packSurveyPoints(List list) { //Generate the camera trigger - CameraTriggerImpl camTrigger = new CameraTriggerImpl(mission, surveyData.getLongitudinalPictureDistance()); + CameraTriggerImpl camTrigger = new CameraTriggerImpl(missionImpl, surveyData.getLongitudinalPictureDistance()); //Add it if the user wants it to start before the first waypoint. if(startCameraBeforeFirstWaypoint){ @@ -97,7 +97,7 @@ private void packSurveyPoints(List list) { } } - list.addAll((new CameraTriggerImpl(mission, (0.0)).packMissionItem())); + list.addAll((new CameraTriggerImpl(missionImpl, (0.0)).packMissionItem())); } protected msg_mission_item getSurveyPoint(LatLong point, double altitude){ @@ -137,8 +137,6 @@ private msg_mission_item getYawCondition(double angle){ @Override public void unpackMAVMessage(msg_mission_item mavMsg) { - // TODO Auto-generated method stub - } @Override diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/CircleImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/CircleImpl.java similarity index 78% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/CircleImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/CircleImpl.java index 3588ddafd0..2b6ed3fac5 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/CircleImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/CircleImpl.java @@ -1,13 +1,13 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; import com.MAVLink.enums.MAV_FRAME; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; +import com.o3dr.services.android.lib.coordinate.LatLongAlt; import java.util.ArrayList; import java.util.List; @@ -21,12 +21,12 @@ public CircleImpl(MissionItemImpl item) { super(item); } - public CircleImpl(Mission mission, LatLongAlt coord) { - super(mission, coord); + public CircleImpl(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl, coord); } - public CircleImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public CircleImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/DoLandStartImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/DoLandStartImpl.java similarity index 59% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/DoLandStartImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/DoLandStartImpl.java index 3742576772..332566273b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/DoLandStartImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/DoLandStartImpl.java @@ -1,14 +1,14 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; - import java.util.List; public class DoLandStartImpl extends SpatialCoordItem { @@ -18,16 +18,16 @@ public DoLandStartImpl(MissionItemImpl item) { setAltitude((0.0)); } - public DoLandStartImpl(Mission mission) { - this(mission, new LatLong(0, 0)); + public DoLandStartImpl(MissionImpl missionImpl) { + this(missionImpl, new LatLong(0, 0)); } - public DoLandStartImpl(Mission mMission, LatLong coord) { - super(mMission, new LatLongAlt(coord, (0))); + public DoLandStartImpl(MissionImpl mMissionImpl, LatLong coord) { + super(mMissionImpl, new LatLongAlt(coord, (0))); } - public DoLandStartImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public DoLandStartImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/LandImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImpl.java similarity index 59% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/LandImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImpl.java index bdf7e55f24..c7b39acfec 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/LandImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/LandImpl.java @@ -1,14 +1,14 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; - import java.util.List; public class LandImpl extends SpatialCoordItem { @@ -18,16 +18,16 @@ public LandImpl(MissionItemImpl item) { setAltitude((0.0)); } - public LandImpl(Mission mission) { - this(mission, new LatLong(0, 0)); + public LandImpl(MissionImpl missionImpl) { + this(missionImpl, new LatLong(0, 0)); } - public LandImpl(Mission mMission, LatLong coord) { - super(mMission, new LatLongAlt(coord, 0)); + public LandImpl(MissionImpl mMissionImpl, LatLong coord) { + super(mMissionImpl, new LatLongAlt(coord, 0)); } - public LandImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public LandImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/RegionOfInterestImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/RegionOfInterestImpl.java similarity index 65% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/RegionOfInterestImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/RegionOfInterestImpl.java index 0ec6a2275c..9c862c5e57 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/RegionOfInterestImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/RegionOfInterestImpl.java @@ -1,27 +1,27 @@ -package org.droidplanner.services.android.core.mission.waypoints; - -import java.util.List; - -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import com.o3dr.services.android.lib.coordinate.LatLongAlt; +import java.util.List; + public class RegionOfInterestImpl extends SpatialCoordItem { public RegionOfInterestImpl(MissionItemImpl item) { super(item); } - public RegionOfInterestImpl(Mission mission, LatLongAlt coord) { - super(mission,coord); + public RegionOfInterestImpl(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl,coord); } - public RegionOfInterestImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public RegionOfInterestImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItem.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItem.java similarity index 82% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItem.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItem.java index 1f3e5bbb51..84f1b18dad 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SpatialCoordItem.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SpatialCoordItem.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; - import java.util.List; public abstract class SpatialCoordItem extends MissionItemImpl { protected LatLongAlt coordinate; - public SpatialCoordItem(Mission mission, LatLongAlt coord) { - super(mission); + public SpatialCoordItem(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl); this.coordinate = coord; } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SplineWaypointImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SplineWaypointImpl.java similarity index 71% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SplineWaypointImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SplineWaypointImpl.java index 289ab46cb0..65bdc7aad8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/SplineWaypointImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/SplineWaypointImpl.java @@ -1,12 +1,12 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; -import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; +import com.o3dr.services.android.lib.coordinate.LatLongAlt; import java.util.List; @@ -25,12 +25,12 @@ public SplineWaypointImpl(MissionItemImpl item) { super(item); } - public SplineWaypointImpl(Mission mission, LatLongAlt coord) { - super(mission, coord); + public SplineWaypointImpl(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl, coord); } - public SplineWaypointImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public SplineWaypointImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/StructureScannerImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/StructureScannerImpl.java similarity index 81% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/StructureScannerImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/StructureScannerImpl.java index 967228f85c..317316c318 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/StructureScannerImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/StructureScannerImpl.java @@ -1,20 +1,20 @@ -package org.droidplanner.services.android.core.mission.waypoints; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; +import org.droidplanner.services.android.impl.core.mission.survey.SurveyImpl; +import org.droidplanner.services.android.impl.core.polygon.Polygon; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.core.survey.SurveyData; +import org.droidplanner.services.android.impl.core.survey.grid.GridBuilder; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.coordinate.LatLongAlt; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; -import org.droidplanner.services.android.core.mission.survey.SurveyImpl; -import org.droidplanner.services.android.core.polygon.Polygon; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.core.survey.SurveyData; -import org.droidplanner.services.android.core.survey.grid.GridBuilder; - import java.util.ArrayList; import java.util.List; @@ -25,8 +25,8 @@ public class StructureScannerImpl extends SpatialCoordItem { private boolean crossHatch = false; SurveyData survey = new SurveyData(); - public StructureScannerImpl(Mission mission, LatLongAlt coord) { - super(mission, coord); + public StructureScannerImpl(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl, coord); } public StructureScannerImpl(MissionItemImpl item) { @@ -45,13 +45,13 @@ public List packMissionItem() { } private void packROI(List list) { - RegionOfInterestImpl roi = new RegionOfInterestImpl(mission, new LatLongAlt(coordinate, (0.0))); + RegionOfInterestImpl roi = new RegionOfInterestImpl(missionImpl, new LatLongAlt(coordinate, (0.0))); list.addAll(roi.packMissionItem()); } private void packCircles(List list) { for (double altitude = coordinate.getAltitude(); altitude <= getTopHeight(); altitude += heightStep) { - CircleImpl circleImpl = new CircleImpl(mission, new LatLongAlt(coordinate, (altitude))); + CircleImpl circleImpl = new CircleImpl(missionImpl, new LatLongAlt(coordinate, (altitude))); circleImpl.setRadius(radius); list.addAll(circleImpl.packMissionItem()); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/WaypointImpl.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImpl.java similarity index 80% rename from ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/WaypointImpl.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImpl.java index 17bcc4c9e5..e87fff465c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/mission/waypoints/WaypointImpl.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/mission/waypoints/WaypointImpl.java @@ -1,15 +1,15 @@ -package org.droidplanner.services.android.core.mission.waypoints; - -import java.util.List; - -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.MissionItemType; +package org.droidplanner.services.android.impl.core.mission.waypoints; import com.MAVLink.common.msg_mission_item; import com.MAVLink.enums.MAV_CMD; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemType; import com.o3dr.services.android.lib.coordinate.LatLongAlt; +import java.util.List; + public class WaypointImpl extends SpatialCoordItem { private double delay; @@ -22,12 +22,12 @@ public WaypointImpl(MissionItemImpl item) { super(item); } - public WaypointImpl(Mission mission, LatLongAlt coord) { - super(mission, coord); + public WaypointImpl(MissionImpl missionImpl, LatLongAlt coord) { + super(missionImpl, coord); } - public WaypointImpl(msg_mission_item msg, Mission mission) { - super(mission, null); + public WaypointImpl(msg_mission_item msg, MissionImpl missionImpl) { + super(missionImpl, null); unpackMAVMessage(msg); } diff --git a/ServiceApp/src/org/droidplanner/services/android/core/model/AutopilotWarningParser.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/AutopilotWarningParser.java similarity index 58% rename from ServiceApp/src/org/droidplanner/services/android/core/model/AutopilotWarningParser.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/AutopilotWarningParser.java index cdb6a69275..1a6a5208be 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/model/AutopilotWarningParser.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/AutopilotWarningParser.java @@ -1,6 +1,6 @@ -package org.droidplanner.services.android.core.model; +package org.droidplanner.services.android.impl.core.model; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; /** * Parse received autopilot warning messages. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/model/Logger.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/Logger.java similarity index 91% rename from ServiceApp/src/org/droidplanner/services/android/core/model/Logger.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/Logger.java index d141af3af5..4d582ef4f7 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/model/Logger.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/model/Logger.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.model; +package org.droidplanner.services.android.impl.core.model; /** * Defines a set of essential logging utilities. diff --git a/ServiceApp/src/org/droidplanner/services/android/core/polygon/Polygon.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/polygon/Polygon.java similarity index 83% rename from ServiceApp/src/org/droidplanner/services/android/core/polygon/Polygon.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/polygon/Polygon.java index fd5ff4f6a5..aaf7cb6b6a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/polygon/Polygon.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/polygon/Polygon.java @@ -1,15 +1,14 @@ -package org.droidplanner.services.android.core.polygon; +package org.droidplanner.services.android.impl.core.polygon; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineLatLong; +import org.droidplanner.services.android.impl.core.helpers.units.Area; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.helpers.geoTools.LineLatLong; -import org.droidplanner.services.android.core.helpers.units.Area; - public class Polygon { private List points = new ArrayList(); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/srtm/Srtm.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/Srtm.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/srtm/Srtm.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/Srtm.java index 03913c7b85..f5e177e8bb 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/srtm/Srtm.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/Srtm.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.srtm; +package org.droidplanner.services.android.impl.core.srtm; public class Srtm { private static final int SRTM_NaN = -32768; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmData.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmData.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmData.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmData.java index d5b7f2fac2..15da9f6559 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmData.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmData.java @@ -1,4 +1,6 @@ -package org.droidplanner.services.android.core.srtm; +package org.droidplanner.services.android.impl.core.srtm; + +import org.droidplanner.services.android.impl.core.srtm.Srtm.OnProgressListner; import java.io.BufferedInputStream; import java.io.File; @@ -6,8 +8,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.droidplanner.services.android.core.srtm.Srtm.OnProgressListner; - public class SrtmData { private String path; private File srtmFile; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmDownloader.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmDownloader.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmDownloader.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmDownloader.java index aa534bcaad..8049c50c81 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmDownloader.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmDownloader.java @@ -1,4 +1,6 @@ -package org.droidplanner.services.android.core.srtm; +package org.droidplanner.services.android.impl.core.srtm; + +import org.droidplanner.services.android.impl.core.srtm.Srtm.OnProgressListner; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -9,8 +11,6 @@ import java.net.URL; import java.net.URLConnection; -import org.droidplanner.services.android.core.srtm.Srtm.OnProgressListner; - public class SrtmDownloader { static final String url = "http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/"; private OnProgressListner listner; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmRegions.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmRegions.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmRegions.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmRegions.java index a0e466857a..ff3bada3ec 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/srtm/SrtmRegions.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/SrtmRegions.java @@ -1,4 +1,6 @@ -package org.droidplanner.services.android.core.srtm; +package org.droidplanner.services.android.impl.core.srtm; + +import org.droidplanner.services.android.impl.core.srtm.Srtm.OnProgressListner; import java.io.File; import java.io.IOException; @@ -6,8 +8,6 @@ import java.util.Map; import java.util.Scanner; -import org.droidplanner.services.android.core.srtm.Srtm.OnProgressListner; - public class SrtmRegions { static final String[] REGIONS = { "Eurasia", "Africa", "Australia", "Islands", "North_America", "South_America" }; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/srtm/UnZip.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/UnZip.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/core/srtm/UnZip.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/UnZip.java index aba889bccf..bf96582e72 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/srtm/UnZip.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/srtm/UnZip.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.srtm; +package org.droidplanner.services.android.impl.core.srtm; import java.io.File; import java.io.FileOutputStream; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/CameraInfo.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/CameraInfo.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/CameraInfo.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/CameraInfo.java index da679f11a4..897d875062 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/CameraInfo.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/CameraInfo.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.core.survey; +package org.droidplanner.services.android.impl.core.survey; public class CameraInfo { public String name = "Canon SX260"; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/Footprint.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/Footprint.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/Footprint.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/Footprint.java index 43f356453c..16cabb4af8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/Footprint.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/Footprint.java @@ -1,11 +1,11 @@ -package org.droidplanner.services.android.core.survey; +package org.droidplanner.services.android.impl.core.survey; import com.MAVLink.ardupilotmega.msg_camera_feedback; + +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; import com.o3dr.services.android.lib.coordinate.LatLong; import com.o3dr.services.android.lib.util.MathUtils; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; - import java.util.ArrayList; import java.util.List; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/SurveyData.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/SurveyData.java similarity index 95% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/SurveyData.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/SurveyData.java index 9d3643bff3..90603bd550 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/SurveyData.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/SurveyData.java @@ -1,6 +1,6 @@ -package org.droidplanner.services.android.core.survey; +package org.droidplanner.services.android.impl.core.survey; -import org.droidplanner.services.android.core.helpers.units.Area; +import org.droidplanner.services.android.impl.core.helpers.units.Area; import java.util.Locale; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/CircumscribedGrid.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/CircumscribedGrid.java similarity index 83% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/grid/CircumscribedGrid.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/CircumscribedGrid.java index 238e0aedcc..f25b3a3595 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/CircumscribedGrid.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/CircumscribedGrid.java @@ -1,14 +1,13 @@ -package org.droidplanner.services.android.core.survey.grid; +package org.droidplanner.services.android.impl.core.survey.grid; +import org.droidplanner.services.android.impl.core.helpers.coordinates.CoordBounds; +import org.droidplanner.services.android.impl.core.helpers.geoTools.GeoTools; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineLatLong; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.ArrayList; import java.util.List; -import org.droidplanner.services.android.core.helpers.coordinates.CoordBounds; -import org.droidplanner.services.android.core.helpers.geoTools.GeoTools; -import org.droidplanner.services.android.core.helpers.geoTools.LineLatLong; - public class CircumscribedGrid { private static final int MAX_NUMBER_OF_LINES = 300; List grid = new ArrayList(); diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/EndpointSorter.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/EndpointSorter.java similarity index 86% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/grid/EndpointSorter.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/EndpointSorter.java index 453893acd0..91bd0fee8b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/EndpointSorter.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/EndpointSorter.java @@ -1,14 +1,13 @@ -package org.droidplanner.services.android.core.survey.grid; +package org.droidplanner.services.android.impl.core.survey.grid; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineLatLong; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineSampler; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineTools; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.ArrayList; import java.util.List; -import org.droidplanner.services.android.core.helpers.geoTools.LineLatLong; -import org.droidplanner.services.android.core.helpers.geoTools.LineSampler; -import org.droidplanner.services.android.core.helpers.geoTools.LineTools; - public class EndpointSorter { private static final int MAX_NUMBER_OF_CAMERAS = 2000; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Grid.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Grid.java similarity index 82% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Grid.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Grid.java index 22ee63c62e..42f80bfb6e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Grid.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Grid.java @@ -1,9 +1,8 @@ -package org.droidplanner.services.android.core.survey.grid; +package org.droidplanner.services.android.impl.core.survey.grid; +import org.droidplanner.services.android.impl.core.helpers.geoTools.PolylineTools; import com.o3dr.services.android.lib.coordinate.LatLong; -import org.droidplanner.services.android.core.helpers.geoTools.PolylineTools; - import java.util.List; public class Grid { diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/GridBuilder.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/GridBuilder.java similarity index 83% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/grid/GridBuilder.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/GridBuilder.java index 7a3f8e7d37..25a2560318 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/GridBuilder.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/GridBuilder.java @@ -1,13 +1,12 @@ -package org.droidplanner.services.android.core.survey.grid; +package org.droidplanner.services.android.impl.core.survey.grid; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineLatLong; +import org.droidplanner.services.android.impl.core.polygon.Polygon; +import org.droidplanner.services.android.impl.core.survey.SurveyData; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.List; -import org.droidplanner.services.android.core.helpers.geoTools.LineLatLong; -import org.droidplanner.services.android.core.polygon.Polygon; -import org.droidplanner.services.android.core.survey.SurveyData; - public class GridBuilder { private Polygon poly; diff --git a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Trimmer.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Trimmer.java similarity index 84% rename from ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Trimmer.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Trimmer.java index 816a15d94e..7544681b1f 100644 --- a/ServiceApp/src/org/droidplanner/services/android/core/survey/grid/Trimmer.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/core/survey/grid/Trimmer.java @@ -1,13 +1,12 @@ -package org.droidplanner.services.android.core.survey.grid; +package org.droidplanner.services.android.impl.core.survey.grid; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineLatLong; +import org.droidplanner.services.android.impl.core.helpers.geoTools.LineTools; import com.o3dr.services.android.lib.coordinate.LatLong; import java.util.ArrayList; import java.util.List; -import org.droidplanner.services.android.core.helpers.geoTools.LineLatLong; -import org.droidplanner.services.android.core.helpers.geoTools.LineTools; - public class Trimmer { List trimedGrid = new ArrayList(); diff --git a/ServiceApp/src/org/droidplanner/services/android/exception/ConnectionException.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/exception/ConnectionException.java similarity index 73% rename from ServiceApp/src/org/droidplanner/services/android/exception/ConnectionException.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/exception/ConnectionException.java index 879e997aab..7da22d062d 100644 --- a/ServiceApp/src/org/droidplanner/services/android/exception/ConnectionException.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/exception/ConnectionException.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.exception; +package org.droidplanner.services.android.impl.exception; /** * Created by fhuya on 11/2/14. diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/ui/activity/UsbIntentReceiver.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/ui/activity/UsbIntentReceiver.java new file mode 100644 index 0000000000..d2ad541aa6 --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/ui/activity/UsbIntentReceiver.java @@ -0,0 +1,36 @@ +package org.droidplanner.services.android.impl.ui.activity; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.Gravity; +import android.view.ViewGroup; +import android.widget.TextView; + + +/** + * Created by fhuya on 11/12/14. + */ +public class UsbIntentReceiver extends Activity { + + @Override + public void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + TextView contentView = new TextView(getApplicationContext()); + contentView.setText("Accessing USB Device..."); + contentView.setGravity(Gravity.CENTER); + setContentView(contentView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + handleIntent(getIntent()); + } + + @Override + public void onNewIntent(Intent intent){ + super.onNewIntent(intent); + handleIntent(intent); + } + + private void handleIntent(Intent intent) { + finish(); + } +} diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/AndroidApWarningParser.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidApWarningParser.java similarity index 96% rename from ServiceApp/src/org/droidplanner/services/android/utils/AndroidApWarningParser.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidApWarningParser.java index 49bc607c39..7503d8dd5e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/AndroidApWarningParser.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidApWarningParser.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; import com.o3dr.services.android.lib.drone.attribute.error.ErrorType; -import org.droidplanner.services.android.core.model.AutopilotWarningParser; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.model.AutopilotWarningParser; import java.util.Locale; @@ -60,10 +60,10 @@ public String getDefaultWarning() { } /** - * Maps the ArduPilot warnings set to the 3DR Services warnings set. + * Maps the ArduPilot warnings set to the DroneKit-Android warnings set. * * @param warning warning originating from the ArduPilot autopilot - * @return equivalent 3DR Services warning type + * @return equivalent DroneKit-Android warning type */ @Override public String parseWarning(MavLinkDrone drone, String warning) { diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/AndroidLogger.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidLogger.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/utils/AndroidLogger.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidLogger.java index 00d228fba2..a511c69e60 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/AndroidLogger.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/AndroidLogger.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.utils; - -import org.droidplanner.services.android.core.model.Logger; +package org.droidplanner.services.android.impl.utils; import android.util.Log; +import org.droidplanner.services.android.impl.core.model.Logger; + /** * Android specific implementation for the {org.droidplanner.services.android.core.model.Logger} * interface. diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/CommonApiUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/CommonApiUtils.java similarity index 92% rename from ServiceApp/src/org/droidplanner/services/android/utils/CommonApiUtils.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/CommonApiUtils.java index 2b6ffd3442..b5e76b05c8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/CommonApiUtils.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/CommonApiUtils.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; import android.os.Bundle; import android.os.RemoteException; @@ -41,26 +41,27 @@ import com.o3dr.services.android.lib.model.AbstractCommandListener; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.MAVLink.MavLinkCommands; -import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds; -import org.droidplanner.services.android.core.drone.autopilot.Drone; -import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone; -import org.droidplanner.services.android.core.drone.autopilot.apm.ArduPilot; -import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone; -import org.droidplanner.services.android.core.drone.profiles.ParameterManager; -import org.droidplanner.services.android.core.drone.variables.ApmModes; -import org.droidplanner.services.android.core.drone.variables.Camera; -import org.droidplanner.services.android.core.drone.variables.GuidedPoint; -import org.droidplanner.services.android.core.drone.variables.calibration.AccelCalibration; -import org.droidplanner.services.android.core.drone.variables.calibration.MagnetometerCalibrationImpl; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.droidplanner.services.android.core.gcs.follow.Follow; -import org.droidplanner.services.android.core.gcs.follow.FollowAlgorithm; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.survey.SplineSurveyImpl; -import org.droidplanner.services.android.core.mission.survey.SurveyImpl; -import org.droidplanner.services.android.core.mission.waypoints.StructureScannerImpl; -import org.droidplanner.services.android.core.survey.Footprint; +import org.droidplanner.services.android.impl.core.MAVLink.MavLinkCommands; +import org.droidplanner.services.android.impl.core.MAVLink.command.doCmd.MavLinkDoCmds; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.drone.autopilot.MavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.ArduPilot; +import org.droidplanner.services.android.impl.core.drone.autopilot.generic.GenericMavLinkDrone; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterManager; +import org.droidplanner.services.android.impl.core.drone.variables.ApmModes; +import org.droidplanner.services.android.impl.core.drone.variables.Camera; +import org.droidplanner.services.android.impl.core.drone.variables.GuidedPoint; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.AccelCalibration; +import org.droidplanner.services.android.impl.core.drone.variables.calibration.MagnetometerCalibrationImpl; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.core.gcs.follow.Follow; +import org.droidplanner.services.android.impl.core.gcs.follow.FollowAlgorithm; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SplineSurveyImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SurveyImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.StructureScannerImpl; +import org.droidplanner.services.android.impl.core.survey.Footprint; import java.lang.reflect.Field; import java.util.ArrayList; @@ -377,7 +378,7 @@ public static State getState(MavLinkDrone drone, boolean isConnected, Vibration if (drone == null) return new State(); - org.droidplanner.services.android.core.drone.variables.State droneState = drone.getState(); + org.droidplanner.services.android.impl.core.drone.variables.State droneState = drone.getState(); ApmModes droneMode = droneState.getMode(); AccelCalibration accelCalibration = drone.getCalibrationSetup(); String calibrationMessage = accelCalibration != null && accelCalibration.isCalibrating() @@ -407,8 +408,8 @@ public static Mission getMission(MavLinkDrone drone) { if (drone == null) return proxyMission; - org.droidplanner.services.android.core.mission.Mission droneMission = drone.getMission(); - List droneMissionItemImpls = droneMission.getComponentItems(); + MissionImpl droneMissionImpl = drone.getMission(); + List droneMissionItemImpls = droneMissionImpl.getComponentItems(); proxyMission.setCurrentMissionItem((short) drone.getMissionStats().getCurrentWP()); @@ -584,16 +585,16 @@ public static void setMission(MavLinkDrone drone, Mission mission, boolean pushT if (drone == null) return; - org.droidplanner.services.android.core.mission.Mission droneMission = drone.getMission(); - droneMission.clearMissionItems(); + MissionImpl droneMissionImpl = drone.getMission(); + droneMissionImpl.clearMissionItems(); List itemsList = mission.getMissionItems(); for (MissionItem item : itemsList) { - droneMission.addMissionItem(ProxyUtils.getMissionItemImpl(droneMission, item)); + droneMissionImpl.addMissionItem(ProxyUtils.getMissionItemImpl(droneMissionImpl, item)); } if (pushToDrone) - droneMission.sendMissionToAPM(); + droneMissionImpl.sendMissionToAPM(); } public static void startMission(final ArduPilot drone, final boolean forceModeChange, boolean forceArm, final ICommandListener listener) { @@ -682,7 +683,7 @@ public static void arm(final ArduPilot drone, final boolean arm, final boolean e return; if (!arm && emergencyDisarm) { - if (org.droidplanner.services.android.core.drone.variables.Type.isCopter(drone.getType()) && !isKillSwitchSupported(drone)) { + if (org.droidplanner.services.android.impl.core.drone.variables.Type.isCopter(drone.getType()) && !isKillSwitchSupported(drone)) { changeVehicleMode(drone, VehicleMode.COPTER_STABILIZE, new AbstractCommandListener() { @Override @@ -730,7 +731,7 @@ public static boolean isKillSwitchSupported(MavLinkDrone drone) { if (drone == null) return false; - if (!org.droidplanner.services.android.core.drone.variables.Type.isCopter(drone.getType())) + if (!org.droidplanner.services.android.impl.core.drone.variables.Type.isCopter(drone.getType())) return false; String firmwareVersion = drone.getFirmwareVersion(); @@ -904,25 +905,25 @@ public static void buildComplexMissionItem(MavLinkDrone drone, Bundle itemBundle } public static Survey buildSurvey(MavLinkDrone drone, Survey survey) { - org.droidplanner.services.android.core.mission.Mission droneMission = drone == null ? null : drone.getMission(); + MissionImpl droneMissionImpl = drone == null ? null : drone.getMission(); SurveyImpl updatedSurveyImpl = (SurveyImpl) ProxyUtils.getMissionItemImpl - (droneMission, survey); + (droneMissionImpl, survey); return (Survey) ProxyUtils.getProxyMissionItem(updatedSurveyImpl); } public static Survey buildSplineSurvey(MavLinkDrone drone, Survey survey) { - org.droidplanner.services.android.core.mission.Mission droneMission = drone == null ? null : drone.getMission(); + MissionImpl droneMissionImpl = drone == null ? null : drone.getMission(); SplineSurveyImpl updatedSplineSurvey = (SplineSurveyImpl) - ProxyUtils.getMissionItemImpl(droneMission, survey); + ProxyUtils.getMissionItemImpl(droneMissionImpl, survey); return (Survey) ProxyUtils.getProxyMissionItem(updatedSplineSurvey); } public static StructureScanner buildStructureScanner(MavLinkDrone drone, StructureScanner item) { - org.droidplanner.services.android.core.mission.Mission droneMission = drone == null ? null : drone.getMission(); + MissionImpl droneMissionImpl = drone == null ? null : drone.getMission(); StructureScannerImpl updatedScan = (StructureScannerImpl) ProxyUtils - .getMissionItemImpl(droneMission, item); + .getMissionItemImpl(droneMissionImpl, item); StructureScanner proxyScanner = (StructureScanner) ProxyUtils.getProxyMissionItem(updatedScan); return proxyScanner; diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/MissionUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/MissionUtils.java new file mode 100644 index 0000000000..d160b98503 --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/MissionUtils.java @@ -0,0 +1,298 @@ +package org.droidplanner.services.android.impl.utils; + +import android.content.Context; +import android.net.Uri; + +import com.MAVLink.common.msg_mission_item; +import com.MAVLink.enums.MAV_CMD; +import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; +import com.o3dr.services.android.lib.drone.mission.Mission; +import com.o3dr.services.android.lib.drone.mission.item.MissionItem; +import com.o3dr.services.android.lib.model.ICommandListener; +import com.o3dr.services.android.lib.util.ParcelableUtils; +import com.o3dr.services.android.lib.util.UriUtils; + +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.commands.CameraTriggerImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ChangeSpeedImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ConditionYawImpl; +import org.droidplanner.services.android.impl.core.mission.commands.DoJumpImpl; +import org.droidplanner.services.android.impl.core.mission.commands.EpmGripperImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ReturnToHomeImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetRelayImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetServoImpl; +import org.droidplanner.services.android.impl.core.mission.commands.TakeoffImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.CircleImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.DoLandStartImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.LandImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.RegionOfInterestImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.SplineWaypointImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.WaypointImpl; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import timber.log.Timber; + +/** + * Created by fhuya on 8/13/2016. + */ +public class MissionUtils { + + /** + * Waypoint file format: + * + * * QGC WPL + * + * + * + * See http://qgroundcontrol.org/mavlink/waypoint_protocol for details + */ + private static final String WAYPOINT_PROTOCOL_HEADER = "QGC WPL 110"; + + private MissionUtils(){} + + public static void saveMission(Context context, Mission mission, Uri saveUri, ICommandListener listener){ + saveMissionToWPL(context, mission, saveUri, listener); + } + + public static Mission loadMission(Context context, Uri loadUri){ + // Attempt to load the mission using the waypoint file format. + Mission mission = loadMissionFromWPL(context, loadUri); + if(mission == null){ + // Attempt to load using the deprecated dpwp formt + mission = loadMissionFromDpwp(context, loadUri); + } + return mission; + } + + private static void saveMissionToWPL(Context context, Mission mission, Uri saveUri, ICommandListener listener){ + try { + OutputStream saveOut = UriUtils.getOutputStream(context, saveUri); + try { + String header = WAYPOINT_PROTOCOL_HEADER + "\n"; + saveOut.write(header.getBytes()); + + // Get the list of msg mission item + List rawMissionItems = fromMission(mission); + for (int i = 0, msgMissionItemsSize = rawMissionItems.size(); i < msgMissionItemsSize; i++) { + final msg_mission_item msg = rawMissionItems.get(i); + + // write msg (TAB delimited) + saveOut.write(String.format(Locale.ENGLISH, + "%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%d\n", + i, + i == 0 ? 1 : 0, // set CURRENT_WP = 1 for 'home' - msg[0], 0 + // for all others + msg.frame, msg.command, msg.param1, msg.param2, msg.param3, msg.param4, msg.x, + msg.y, msg.z, msg.autocontinue).getBytes()); + } + + CommonApiUtils.postSuccessEvent(listener); + }finally{ + saveOut.close(); + } + } catch (IOException e) { + Timber.e(e, "Unable to write to uri %s", saveUri); + CommonApiUtils.postErrorEvent(CommandExecutionError.COMMAND_FAILED, listener); + } + } + + private static void saveMissionToDpwp(Context context, Mission mission, Uri saveUri, ICommandListener listener){ + try{ + OutputStream saveOut = UriUtils.getOutputStream(context, saveUri); + try{ + byte[] missionBytes = ParcelableUtils.marshall(mission); + saveOut.write(missionBytes); + CommonApiUtils.postSuccessEvent(listener); + }finally{ + saveOut.close(); + } + + } catch(IOException e){ + Timber.e(e, "Unable to write to uri %s", saveUri); + CommonApiUtils.postErrorEvent(CommandExecutionError.COMMAND_FAILED, listener); + } + } + + private static Mission loadMissionFromDpwp(Context context, Uri loadUri){ + try{ + InputStream loadIn = UriUtils.getInputStream(context, loadUri); + try{ + Map bytesList = new LinkedHashMap<>(); + int length = 0; + while(loadIn.available() > 0){ + byte[] missionBytes = new byte[2048]; + int bufferSize = loadIn.read(missionBytes); + bytesList.put(missionBytes, bufferSize); + length += bufferSize; + } + + ByteBuffer fullBuffer = ByteBuffer.allocate(length); + for(Map.Entry entry : bytesList.entrySet()){ + fullBuffer.put(entry.getKey(), 0, entry.getValue()); + } + + Mission mission = ParcelableUtils.unmarshall(fullBuffer.array(), 0, length, Mission.CREATOR); + return mission; + }finally{ + loadIn.close(); + } + }catch(IOException e){ + Timber.e(e, "Unable to read from uri %s", loadUri); + return null; + } + } + + private static Mission loadMissionFromWPL(Context context, Uri loadUri) { + try { + InputStream loadIn = UriUtils.getInputStream(context, loadUri); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(loadIn)); + + if (!reader.readLine().contains(WAYPOINT_PROTOCOL_HEADER)) { + // Invalid file header. + Timber.w("Invalid waypoint file format for %s", loadUri); + return null; + } + + List rawMissionItems = new LinkedList<>(); + String line; + while ((line = reader.readLine()) != null) { + // parse line (TAB delimited) + final String[] rowData = line.split("\t"); + + final msg_mission_item msg = new msg_mission_item(); + msg.seq = (Short.parseShort(rowData[0])); + msg.current = (Byte.parseByte(rowData[1])); + msg.frame = (Byte.parseByte(rowData[2])); + msg.command = (Short.parseShort(rowData[3])); + + msg.param1 = (Float.parseFloat(rowData[4])); + msg.param2 = (Float.parseFloat(rowData[5])); + msg.param3 = (Float.parseFloat(rowData[6])); + msg.param4 = (Float.parseFloat(rowData[7])); + + msg.x = (Float.parseFloat(rowData[8])); + msg.y = (Float.parseFloat(rowData[9])); + msg.z = (Float.parseFloat(rowData[10])); + + msg.autocontinue = (Byte.parseByte(rowData[11])); + + rawMissionItems.add(msg); + } + + return fromRawMissionItems(rawMissionItems); + }finally{ + loadIn.close(); + } + } catch (IOException e) { + Timber.e(e, "Unable to load mission from uri %s", loadUri); + return null; + } + } + + private static List fromMission(Mission mission){ + if(mission == null) + return null; + + List missionItems = mission.getMissionItems(); + if(missionItems.isEmpty()) + return Collections.emptyList(); + + MissionImpl missionImpl = new MissionImpl(null); + List rawMissionItems = new ArrayList<>(missionItems.size()); + for(MissionItem missionItem : missionItems){ + MissionItemImpl impl = ProxyUtils.getMissionItemImpl(missionImpl, missionItem); + rawMissionItems.addAll(impl.packMissionItem()); + } + + return rawMissionItems; + } + + private static Mission fromRawMissionItems(List rawMissionItems){ + Mission mission = new Mission(); + if(rawMissionItems == null || rawMissionItems.isEmpty()) + return mission; + + List impls = processMavLinkMessages(new MissionImpl(null), rawMissionItems); + if(!impls.isEmpty()) { + for (MissionItemImpl impl: impls) { + MissionItem missionItem = ProxyUtils.getProxyMissionItem(impl); + if(missionItem != null){ + mission.addMissionItem(missionItem); + } + } + } + return mission; + } + + public static List processMavLinkMessages(MissionImpl missionImpl, List msgs) { + List received = new ArrayList(); + for (msg_mission_item msg : msgs) { + switch (msg.command) { + case MAV_CMD.MAV_CMD_DO_SET_SERVO: + received.add(new SetServoImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_WAYPOINT: + received.add(new WaypointImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_SPLINE_WAYPOINT: + received.add(new SplineWaypointImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_LAND: + received.add(new LandImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_LAND_START: + received.add(new DoLandStartImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_TAKEOFF: + received.add(new TakeoffImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_CHANGE_SPEED: + received.add(new ChangeSpeedImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_SET_CAM_TRIGG_DIST: + received.add(new CameraTriggerImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_GRIPPER: + received.add(new EpmGripperImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_SET_ROI: + received.add(new RegionOfInterestImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_LOITER_TURNS: + received.add(new CircleImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_NAV_RETURN_TO_LAUNCH: + received.add(new ReturnToHomeImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_CONDITION_YAW: + received.add(new ConditionYawImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_SET_RELAY: + received.add(new SetRelayImpl(msg, missionImpl)); + break; + case MAV_CMD.MAV_CMD_DO_JUMP: + received.add(new DoJumpImpl(msg, missionImpl)); + break; + + default: + break; + } + } + return received; + } +} diff --git a/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/NetworkUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/NetworkUtils.java new file mode 100644 index 0000000000..acde99b221 --- /dev/null +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/NetworkUtils.java @@ -0,0 +1,112 @@ +package org.droidplanner.services.android.impl.utils; + +import android.annotation.TargetApi; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Build; +import android.os.Bundle; + +import com.o3dr.android.client.BuildConfig; + +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnection; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.SoloComp; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.DatagramSocket; +import java.net.Socket; + +import timber.log.Timber; + +/** + * Created by Fredia Huya-Kouadio on 5/11/15. + */ +public class NetworkUtils { + /** + * Is internet connection available. This method also returns true for the SITL build type + * @param context + * @return Internet connection availability. + */ + public static boolean isNetworkAvailable(Context context) { + if (!BuildConfig.SITL_DEBUG && isOnSololinkNetwork(context)) + return false; + + ConnectivityManager connectivityManager = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + return activeNetworkInfo != null && activeNetworkInfo.isConnected(); + } + + public static String getCurrentWifiLink(Context context) { + final WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + + final WifiInfo connectedWifi = wifiMgr.getConnectionInfo(); + final String connectedSSID = connectedWifi == null ? null : connectedWifi.getSSID().replace("\"", ""); + return connectedSSID; + } + + public static boolean isOnSololinkNetwork(Context context) { + if (BuildConfig.SITL_DEBUG) + return true; + + final String connectedSSID = getCurrentWifiLink(context); + return isSoloNetwork(connectedSSID); + } + + public static boolean isSoloNetwork(String ssid) { + return ssid != null && ssid.startsWith(SoloComp.SOLO_LINK_WIFI_PREFIX); + } + + public static void bindSocketToNetwork(Bundle extras, Socket socket) throws IOException { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Network network = extras == null + ? null + : (Network) extras.getParcelable(MavLinkConnection.EXTRA_NETWORK); + bindSocketToNetwork(network, socket); + } + } + + @TargetApi(21) + public static void bindSocketToNetwork(Network network, Socket socket) throws IOException { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (network != null && socket != null) { + Timber.d("Binding socket to network %s", network); + network.bindSocket(socket); + } + } + } + + public static void bindSocketToNetwork(Bundle extras, DatagramSocket socket) throws IOException { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Network network = extras == null + ? null + : (Network) extras.getParcelable(MavLinkConnection.EXTRA_NETWORK); + bindSocketToNetwork(network, socket); + } + } + + @TargetApi(21) + public static void bindSocketToNetwork(Network network, DatagramSocket socket) throws IOException { + if (network != null && socket != null) { + Timber.d("Binding datagram socket to network %s", network); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + network.bindSocket(socket); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + // Can be accessed through reflection. + try { + Method bindSocketMethod = Network.class.getMethod("bindSocket", DatagramSocket.class); + bindSocketMethod.invoke(network, socket); + } catch (NoSuchMethodException | IllegalAccessException e) { + Timber.e(e, "Unable to access Network#bindSocket(DatagramSocket)."); + } catch (InvocationTargetException e) { + Timber.e(e, "Unable to invoke Network#bindSocket(DatagramSocket)."); + } + } + } + } +} diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/ProxyUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/ProxyUtils.java similarity index 85% rename from ServiceApp/src/org/droidplanner/services/android/utils/ProxyUtils.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/ProxyUtils.java index 2261c7c526..568bee34a0 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/ProxyUtils.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/ProxyUtils.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; import android.util.Log; @@ -15,9 +15,9 @@ import com.o3dr.services.android.lib.drone.mission.item.command.Takeoff; import com.o3dr.services.android.lib.drone.mission.item.command.YawCondition; import com.o3dr.services.android.lib.drone.mission.item.complex.CameraDetail; +import com.o3dr.services.android.lib.drone.mission.item.complex.SplineSurvey; import com.o3dr.services.android.lib.drone.mission.item.complex.StructureScanner; import com.o3dr.services.android.lib.drone.mission.item.complex.Survey; -import com.o3dr.services.android.lib.drone.mission.item.complex.SplineSurvey; import com.o3dr.services.android.lib.drone.mission.item.complex.SurveyDetail; import com.o3dr.services.android.lib.drone.mission.item.spatial.Circle; import com.o3dr.services.android.lib.drone.mission.item.spatial.DoLandStart; @@ -26,28 +26,28 @@ import com.o3dr.services.android.lib.drone.mission.item.spatial.SplineWaypoint; import com.o3dr.services.android.lib.drone.mission.item.spatial.Waypoint; -import org.droidplanner.services.android.core.mission.Mission; -import org.droidplanner.services.android.core.mission.MissionItemImpl; -import org.droidplanner.services.android.core.mission.commands.CameraTriggerImpl; -import org.droidplanner.services.android.core.mission.commands.ChangeSpeedImpl; -import org.droidplanner.services.android.core.mission.commands.ConditionYawImpl; -import org.droidplanner.services.android.core.mission.commands.DoJumpImpl; -import org.droidplanner.services.android.core.mission.commands.EpmGripperImpl; -import org.droidplanner.services.android.core.mission.commands.ReturnToHomeImpl; -import org.droidplanner.services.android.core.mission.commands.SetRelayImpl; -import org.droidplanner.services.android.core.mission.commands.SetServoImpl; -import org.droidplanner.services.android.core.mission.commands.TakeoffImpl; -import org.droidplanner.services.android.core.mission.survey.SplineSurveyImpl; -import org.droidplanner.services.android.core.mission.survey.SurveyImpl; -import org.droidplanner.services.android.core.mission.waypoints.CircleImpl; -import org.droidplanner.services.android.core.mission.waypoints.DoLandStartImpl; -import org.droidplanner.services.android.core.mission.waypoints.LandImpl; -import org.droidplanner.services.android.core.mission.waypoints.RegionOfInterestImpl; -import org.droidplanner.services.android.core.mission.waypoints.SplineWaypointImpl; -import org.droidplanner.services.android.core.mission.waypoints.StructureScannerImpl; -import org.droidplanner.services.android.core.mission.waypoints.WaypointImpl; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.core.survey.SurveyData; +import org.droidplanner.services.android.impl.core.mission.MissionImpl; +import org.droidplanner.services.android.impl.core.mission.MissionItemImpl; +import org.droidplanner.services.android.impl.core.mission.commands.CameraTriggerImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ChangeSpeedImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ConditionYawImpl; +import org.droidplanner.services.android.impl.core.mission.commands.DoJumpImpl; +import org.droidplanner.services.android.impl.core.mission.commands.EpmGripperImpl; +import org.droidplanner.services.android.impl.core.mission.commands.ReturnToHomeImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetRelayImpl; +import org.droidplanner.services.android.impl.core.mission.commands.SetServoImpl; +import org.droidplanner.services.android.impl.core.mission.commands.TakeoffImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SplineSurveyImpl; +import org.droidplanner.services.android.impl.core.mission.survey.SurveyImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.CircleImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.DoLandStartImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.LandImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.RegionOfInterestImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.SplineWaypointImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.StructureScannerImpl; +import org.droidplanner.services.android.impl.core.mission.waypoints.WaypointImpl; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.core.survey.SurveyData; /** * Created by fhuya on 11/10/14. @@ -90,7 +90,7 @@ public static SurveyDetail getSurveyDetail(SurveyData surveyData) { return surveyDetail; } - public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem proxyItem) { + public static MissionItemImpl getMissionItemImpl(MissionImpl missionImpl, MissionItem proxyItem) { if (proxyItem == null) return null; @@ -100,7 +100,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case CAMERA_TRIGGER: { CameraTrigger proxy = (CameraTrigger) proxyItem; - CameraTriggerImpl temp = new CameraTriggerImpl(mission, (proxy.getTriggerDistance())); + CameraTriggerImpl temp = new CameraTriggerImpl(missionImpl, (proxy.getTriggerDistance())); missionItemImpl = temp; break; @@ -108,7 +108,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case CHANGE_SPEED: { ChangeSpeed proxy = (ChangeSpeed) proxyItem; - ChangeSpeedImpl temp = new ChangeSpeedImpl(mission, proxy.getSpeed()); + ChangeSpeedImpl temp = new ChangeSpeedImpl(missionImpl, proxy.getSpeed()); missionItemImpl = temp; break; @@ -116,7 +116,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case EPM_GRIPPER: { EpmGripper proxy = (EpmGripper) proxyItem; - EpmGripperImpl temp = new EpmGripperImpl(mission, proxy.isRelease()); + EpmGripperImpl temp = new EpmGripperImpl(missionImpl, proxy.isRelease()); missionItemImpl = temp; break; @@ -124,7 +124,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case RETURN_TO_LAUNCH: { ReturnToLaunch proxy = (ReturnToLaunch) proxyItem; - ReturnToHomeImpl temp = new ReturnToHomeImpl(mission); + ReturnToHomeImpl temp = new ReturnToHomeImpl(missionImpl); temp.setHeight((proxy.getReturnAltitude())); missionItemImpl = temp; @@ -133,7 +133,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case SET_SERVO: { SetServo proxy = (SetServo) proxyItem; - SetServoImpl temp = new SetServoImpl(mission, proxy.getChannel(), proxy.getPwm()); + SetServoImpl temp = new SetServoImpl(missionImpl, proxy.getChannel(), proxy.getPwm()); missionItemImpl = temp; break; @@ -141,7 +141,8 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case TAKEOFF: { Takeoff proxy = (Takeoff) proxyItem; - TakeoffImpl temp = new TakeoffImpl(mission, (proxy.getTakeoffAltitude())); + TakeoffImpl temp = new TakeoffImpl(missionImpl, proxy.getTakeoffAltitude(), + proxy.getTakeoffPitch()); missionItemImpl = temp; break; @@ -149,7 +150,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case CIRCLE: { Circle proxy = (Circle) proxyItem; - CircleImpl temp = new CircleImpl(mission, (proxy.getCoordinate())); + CircleImpl temp = new CircleImpl(missionImpl, (proxy.getCoordinate())); temp.setRadius(proxy.getRadius()); temp.setTurns(proxy.getTurns()); @@ -159,7 +160,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case LAND: { Land proxy = (Land) proxyItem; - LandImpl temp = new LandImpl(mission, (proxy.getCoordinate())); + LandImpl temp = new LandImpl(missionImpl, (proxy.getCoordinate())); missionItemImpl = temp; break; @@ -167,7 +168,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case DO_LAND_START: { DoLandStart proxy = (DoLandStart) proxyItem; - DoLandStartImpl temp = new DoLandStartImpl(mission, (proxy.getCoordinate())); + DoLandStartImpl temp = new DoLandStartImpl(missionImpl, (proxy.getCoordinate())); missionItemImpl = temp; break; @@ -176,7 +177,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case REGION_OF_INTEREST: { RegionOfInterest proxy = (RegionOfInterest) proxyItem; - RegionOfInterestImpl temp = new RegionOfInterestImpl(mission, (proxy.getCoordinate())); + RegionOfInterestImpl temp = new RegionOfInterestImpl(missionImpl, (proxy.getCoordinate())); missionItemImpl = temp; break; @@ -184,7 +185,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case RESET_ROI: { //Sending a roi with all coordinates set to 0 will reset the current roi. - RegionOfInterestImpl temp = new RegionOfInterestImpl(mission, new LatLongAlt(0, 0, 0)); + RegionOfInterestImpl temp = new RegionOfInterestImpl(missionImpl, new LatLongAlt(0, 0, 0)); missionItemImpl = temp; break; } @@ -192,7 +193,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case SPLINE_WAYPOINT: { SplineWaypoint proxy = (SplineWaypoint) proxyItem; - SplineWaypointImpl temp = new SplineWaypointImpl(mission, (proxy.getCoordinate())); + SplineWaypointImpl temp = new SplineWaypointImpl(missionImpl, (proxy.getCoordinate())); temp.setDelay(proxy.getDelay()); missionItemImpl = temp; @@ -201,7 +202,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case STRUCTURE_SCANNER: { StructureScanner proxy = (StructureScanner) proxyItem; - StructureScannerImpl temp = new StructureScannerImpl(mission, (proxy.getCoordinate())); + StructureScannerImpl temp = new StructureScannerImpl(missionImpl, (proxy.getCoordinate())); temp.setRadius((int) proxy.getRadius()); temp.setNumberOfSteps(proxy.getStepsCount()); temp.setAltitudeStep((int) proxy.getHeightStep()); @@ -217,7 +218,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case WAYPOINT: { Waypoint proxy = (Waypoint) proxyItem; - WaypointImpl temp = new WaypointImpl(mission, (proxy + WaypointImpl temp = new WaypointImpl(missionImpl, (proxy .getCoordinate())); temp.setAcceptanceRadius(proxy.getAcceptanceRadius()); temp.setDelay(proxy.getDelay()); @@ -232,7 +233,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr Survey proxy = (Survey) proxyItem; SurveyDetail surveyDetail = proxy.getSurveyDetail(); - SurveyImpl temp = new SurveyImpl(mission, proxy.getPolygonPoints()); + SurveyImpl temp = new SurveyImpl(missionImpl, proxy.getPolygonPoints()); temp.setStartCameraBeforeFirstWaypoint(proxy.isStartCameraBeforeFirstWaypoint()); if (surveyDetail != null) { @@ -257,7 +258,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr SplineSurvey proxy = (SplineSurvey) proxyItem; SurveyDetail surveyDetail = proxy.getSurveyDetail(); - SplineSurveyImpl temp = new SplineSurveyImpl(mission, proxy.getPolygonPoints()); + SplineSurveyImpl temp = new SplineSurveyImpl(missionImpl, proxy.getPolygonPoints()); temp.setStartCameraBeforeFirstWaypoint(proxy.isStartCameraBeforeFirstWaypoint()); if (surveyDetail != null) { @@ -281,7 +282,7 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case YAW_CONDITION: { YawCondition proxy = (YawCondition) proxyItem; - ConditionYawImpl temp = new ConditionYawImpl(mission, proxy.getAngle(), proxy.isRelative()); + ConditionYawImpl temp = new ConditionYawImpl(missionImpl, proxy.getAngle(), proxy.isRelative()); temp.setAngularSpeed(proxy.getAngularSpeed()); missionItemImpl = temp; @@ -290,13 +291,13 @@ public static MissionItemImpl getMissionItemImpl(Mission mission, MissionItem pr case SET_RELAY: { SetRelay proxy = (SetRelay) proxyItem; - missionItemImpl = new SetRelayImpl(mission, proxy.getRelayNumber(), proxy.isEnabled()); + missionItemImpl = new SetRelayImpl(missionImpl, proxy.getRelayNumber(), proxy.isEnabled()); break; } case DO_JUMP: { DoJump proxy = (DoJump) proxyItem; - missionItemImpl = new DoJumpImpl(mission, proxy.getWaypoint(), proxy.getRepeatCount()); + missionItemImpl = new DoJumpImpl(missionImpl, proxy.getWaypoint(), proxy.getRepeatCount()); break; } diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/SoloApiUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/SoloApiUtils.java similarity index 93% rename from ServiceApp/src/org/droidplanner/services/android/utils/SoloApiUtils.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/SoloApiUtils.java index cb057b248d..40de5d3cb8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/SoloApiUtils.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/SoloApiUtils.java @@ -1,20 +1,19 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; import android.os.RemoteException; import android.util.Pair; +import org.droidplanner.services.android.impl.core.drone.autopilot.Drone; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.ArduSolo; +import org.droidplanner.services.android.impl.core.drone.autopilot.apm.solo.SoloComp; import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; -import com.o3dr.services.android.lib.drone.companion.solo.controller.SoloControllerMode; import com.o3dr.services.android.lib.drone.companion.solo.SoloState; +import com.o3dr.services.android.lib.drone.companion.solo.controller.SoloControllerMode; import com.o3dr.services.android.lib.drone.companion.solo.controller.SoloControllerUnits; import com.o3dr.services.android.lib.drone.companion.solo.tlv.SoloButtonSettingSetter; import com.o3dr.services.android.lib.drone.companion.solo.tlv.TLVPacket; import com.o3dr.services.android.lib.model.ICommandListener; -import org.droidplanner.services.android.core.drone.autopilot.Drone; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.ArduSolo; -import org.droidplanner.services.android.core.drone.autopilot.apm.solo.SoloComp; - import timber.log.Timber; /** diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/TextUtils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/TextUtils.java similarity index 98% rename from ServiceApp/src/org/droidplanner/services/android/utils/TextUtils.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/TextUtils.java index f11a39405a..0f4bee47d3 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/TextUtils.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/TextUtils.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; import android.graphics.Typeface; import android.text.Spannable; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/Utils.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/Utils.java similarity index 77% rename from ServiceApp/src/org/droidplanner/services/android/utils/Utils.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/Utils.java index ca8641db86..bd0802dcb8 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/Utils.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/Utils.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils; +package org.droidplanner.services.android.impl.utils; /** * Created by Fredia Huya-Kouadio on 2/4/15. diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/connection/SshConnection.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/SshConnection.java similarity index 85% rename from ServiceApp/src/org/droidplanner/services/android/utils/connection/SshConnection.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/SshConnection.java index a8f232b251..a18435d1e2 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/connection/SshConnection.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/SshConnection.java @@ -1,5 +1,8 @@ -package org.droidplanner.services.android.utils.connection; +package org.droidplanner.services.android.impl.utils.connection; +import android.net.Network; +import android.os.Build; +import android.os.Bundle; import android.text.TextUtils; import com.jcraft.jsch.Channel; @@ -7,6 +10,10 @@ import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; +import com.jcraft.jsch.SocketFactory; + +import org.droidplanner.services.android.impl.communication.model.DataLink; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnection; import java.io.File; import java.io.FileInputStream; @@ -14,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.Socket; +import java.net.UnknownHostException; import timber.log.Timber; @@ -45,18 +54,28 @@ public interface DownloadListener { private final String host; private final String username; private final String password; + private final DataLink.DataLinkProvider linkProvider; - public SshConnection(String host, String username, String password) { + public SshConnection(String host, String username, String password, DataLink.DataLinkProvider linkProvider) { this.jsch = new JSch(); this.host = host; this.username = username; this.password = password; + this.linkProvider = linkProvider; } private Session getSession() throws JSchException { Session session = jsch.getSession(username, host); - //Try to connect with the password set. + Bundle extras = linkProvider.getConnectionExtras(); + if (extras != null && !extras.isEmpty()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Network network = extras.getParcelable(MavLinkConnection.EXTRA_NETWORK); + if (network != null) { + session.setSocketFactory(new SshSocketFactory(network.getSocketFactory())); + } + } + } session.setConfig("StrictHostKeyChecking", "no"); session.setPassword(this.password); session.connect(CONNECTION_TIMEOUT); @@ -367,4 +386,28 @@ private static int checkAck(InputStream in) throws IOException { return result; } + + private static class SshSocketFactory implements SocketFactory { + + private final javax.net.SocketFactory socketFactory; + + private SshSocketFactory(javax.net.SocketFactory socketFactory) { + this.socketFactory = socketFactory; + } + + @Override + public Socket createSocket(String host, int port) throws IOException, UnknownHostException { + return socketFactory.createSocket(host, port); + } + + @Override + public InputStream getInputStream(Socket socket) throws IOException { + return socket.getInputStream(); + } + + @Override + public OutputStream getOutputStream(Socket socket) throws IOException { + return socket.getOutputStream(); + } + } } diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/connection/WifiConnectionHandler.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/WifiConnectionHandler.java similarity index 79% rename from ServiceApp/src/org/droidplanner/services/android/utils/connection/WifiConnectionHandler.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/WifiConnectionHandler.java index c1488398a5..12f2bdcb36 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/connection/WifiConnectionHandler.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/connection/WifiConnectionHandler.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils.connection; +package org.droidplanner.services.android.impl.utils.connection; import android.annotation.TargetApi; import android.content.BroadcastReceiver; @@ -18,12 +18,14 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; +import android.os.Bundle; import android.text.TextUtils; import android.widget.Toast; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; -import org.droidplanner.services.android.utils.NetworkUtils; +import org.droidplanner.services.android.impl.core.MAVLink.connection.MavLinkConnection; +import org.droidplanner.services.android.impl.utils.NetworkUtils; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -35,8 +37,12 @@ */ public class WifiConnectionHandler { + public static final String EXTRA_SSID = "extra_ssid"; + public static final String EXTRA_SSID_PASSWORD = "extra_ssid_password"; + public static final String EXTRA_SCAN_RESULT = "extra_scan_result"; + public interface WifiConnectionListener { - void onWifiConnected(String wifiSsid); + void onWifiConnected(String wifiSsid, Bundle extras); void onWifiConnecting(); @@ -105,7 +111,7 @@ public void onReceive(Context context, Intent intent) { } if (wifiSSID != null) { - setDefaultNetworkIfNecessary(wifiSSID); + updateNetworkIfNecessary(wifiSSID, null); } break; @@ -119,7 +125,7 @@ public void onReceive(Context context, Intent intent) { NetworkInfo.DetailedState detailedState = netInfo.getDetailedState(); if (detailedState != null && detailedState == NetworkInfo.DetailedState.VERIFYING_POOR_LINK) { String connectingSsid = NetworkUtils.getCurrentWifiLink(context); - setDefaultNetworkIfNecessary(connectingSsid); + updateNetworkIfNecessary(connectingSsid, null); } } Timber.d("Connecting to wifi network."); @@ -180,26 +186,20 @@ public void onAvailable(Network network) { //Check if we're still connected to solo. If not, unregister the callbacks final String currentWifi = getCurrentWifiLink(); if (!isSoloWifi(currentWifi)) { - resetNetworkBindings(this); + try { + connMgr.unregisterNetworkCallback(this); + } catch (IllegalArgumentException e) { + Timber.w(e, "Network callback was not registered."); + } return; } Timber.i("Network %s is available", network); getNetworkInfo(network); - final boolean wasBound; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - wasBound = connMgr.bindProcessToNetwork(network); - } else { - wasBound = ConnectivityManager.setProcessDefaultNetwork(network); - } - - if (wasBound) { - Timber.i("Bound process to network %s", network); - notifyWifiConnected(currentWifi); - } else { - Timber.w("Unable to bind process to network %s", network); - } + Bundle extras = new Bundle(1); + extras.putParcelable(MavLinkConnection.EXTRA_NETWORK, network); + notifyWifiConnected(currentWifi, extras); } @Override @@ -242,25 +242,11 @@ public void stop() { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - resetNetworkBindings((ConnectivityManager.NetworkCallback) netReqCb); - } - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private void resetNetworkBindings(ConnectivityManager.NetworkCallback netCb) { - Timber.i("Unregistering network callbacks."); - - connectedWifi.set(NetworkUtils.getCurrentWifiLink(context)); - try { - connMgr.unregisterNetworkCallback(netCb); - } catch (IllegalArgumentException e) { - Timber.w(e, "Network callback was not registered."); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - connMgr.bindProcessToNetwork(null); - } else { - ConnectivityManager.setProcessDefaultNetwork(null); + try { + connMgr.unregisterNetworkCallback((ConnectivityManager.NetworkCallback) netReqCb); + } catch (IllegalArgumentException e) { + Timber.w(e, "Network callback was not registered."); + } } } @@ -289,19 +275,15 @@ public boolean isOnNetwork(String wifiSsid) { return wifiSsid.equalsIgnoreCase(getCurrentWifiLink()); } - public boolean isConnected(String wifiSSID) { + public boolean isConnected(String wifiSSID, Bundle info) { if (!isOnNetwork(wifiSSID)) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Network network; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - network = connMgr.getBoundNetworkForProcess(); - } else { - network = ConnectivityManager.getProcessDefaultNetwork(); - } - + Network network = info == null + ? null + : (Network) info.getParcelable(MavLinkConnection.EXTRA_NETWORK); if (network == null) { return false; } @@ -317,52 +299,58 @@ public List getScanResults() { return wifiMgr.getScanResults(); } - public int connectToWifi(String soloLinkId, String password) { - if (TextUtils.isEmpty(soloLinkId)) { - return LinkConnectionStatus.INVALID_CREDENTIALS; + private ScanResult getScanResult(String ssid) { + if (TextUtils.isEmpty(ssid)) { + return null; } - - ScanResult targetScanResult = null; final List scanResults = wifiMgr.getScanResults(); for (ScanResult result : scanResults) { - if (result.SSID.equalsIgnoreCase(soloLinkId)) { - targetScanResult = result; - break; + if (result.SSID.equalsIgnoreCase(ssid)) { + return result; } } + return null; + } - if (targetScanResult == null) { - Timber.i("No matching scan result was found for id %s", soloLinkId); - return LinkConnectionStatus.LINK_UNAVAILABLE; + public int connectToWifi(Bundle info) { + if (info == null || info.isEmpty()) { + return LinkConnectionStatus.INVALID_CREDENTIALS; } - return connectToWifi(targetScanResult, password); - } - - public int connectToWifi(ScanResult scanResult, String password) { + ScanResult scanResult = info.getParcelable(EXTRA_SCAN_RESULT); if (scanResult == null) { - return LinkConnectionStatus.LINK_UNAVAILABLE; + // Check if the ssid was given. + String ssid = info.getString(EXTRA_SSID); + if (TextUtils.isEmpty(ssid)) { + return LinkConnectionStatus.INVALID_CREDENTIALS; + } + + // Get the scan result that match the given ssid. + scanResult = getScanResult(ssid); + if (scanResult == null) { + Timber.i("No matching scan result was found for id %s", ssid); + return LinkConnectionStatus.LINK_UNAVAILABLE; + } } Timber.d("Connecting to wifi " + scanResult.SSID); - //Check if we're already connected to the given network. - if (isConnected(scanResult.SSID)) { + if (isConnected(scanResult.SSID, info)) { Timber.d("Already connected to " + scanResult.SSID); - notifyWifiConnected(scanResult.SSID); + notifyWifiConnected(scanResult.SSID, info); return 0; } else if (isOnNetwork(scanResult.SSID)) { - setDefaultNetworkIfNecessary(scanResult.SSID); + updateNetworkIfNecessary(scanResult.SSID, info); return 0; - } WifiConfiguration wifiConfig = getWifiConfigs(scanResult.SSID); //Network is not configured and needs a password to connect if (wifiConfig == null) { + String password = info.getString(EXTRA_SSID_PASSWORD); Timber.d("Connecting to closed wifi network."); if (TextUtils.isEmpty(password)) { return LinkConnectionStatus.INVALID_CREDENTIALS; @@ -434,35 +422,30 @@ public static boolean isSoloWifi(String wifiSsid) { return !TextUtils.isEmpty(wifiSsid) && wifiSsid.startsWith(SOLO_LINK_WIFI_PREFIX); } - private void setDefaultNetworkIfNecessary(String wifiSsid) { + private void updateNetworkIfNecessary(String wifiSsid, Bundle info) { final String trimmedSsid = trimWifiSsid(wifiSsid); - if (!trimmedSsid.equals(connectedWifi.get())) { - connectedWifi.set(trimmedSsid); - - if (isConnected(wifiSsid)) { - notifyWifiConnected(wifiSsid); - return; - } - - if (isSoloWifi(trimmedSsid)) { - //Attempt to connect to the vehicle. - Timber.i("Requesting route to sololink network"); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - connMgr.requestNetwork((NetworkRequest) netReq, (ConnectivityManager.NetworkCallback) netReqCb); - } else { - notifyWifiConnected(trimmedSsid); + if (isConnected(wifiSsid, info)) { + notifyWifiConnected(wifiSsid, info); + return; + } - } + if (isSoloWifi(trimmedSsid)) { + //Attempt to connect to the vehicle. + Timber.i("Requesting route to sololink network"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + connMgr.requestNetwork((NetworkRequest) netReq, (ConnectivityManager.NetworkCallback) netReqCb); } else { - notifyWifiConnected(trimmedSsid); + notifyWifiConnected(trimmedSsid, info); } + } else { + notifyWifiConnected(trimmedSsid, info); } } - private void notifyWifiConnected(String wifiSsid) { + private void notifyWifiConnected(String wifiSsid, Bundle extras) { if (listener != null) { - listener.onWifiConnected(wifiSsid); + listener.onWifiConnected(wifiSsid, extras); } } diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/AssetUtil.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/AssetUtil.java similarity index 86% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/AssetUtil.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/AssetUtil.java index c1da75d60e..6ac1e9197a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/AssetUtil.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/AssetUtil.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.utils.file; - -import java.io.IOException; +package org.droidplanner.services.android.impl.utils.file; import android.content.res.AssetManager; +import java.io.IOException; + public class AssetUtil { public static boolean exists(AssetManager assetManager, String directory, String fileName) diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/DirectoryPath.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/DirectoryPath.java similarity index 56% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/DirectoryPath.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/DirectoryPath.java index 7db28138e3..d1c77893be 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/DirectoryPath.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/DirectoryPath.java @@ -1,18 +1,16 @@ -package org.droidplanner.services.android.utils.file; - -import java.io.File; +package org.droidplanner.services.android.impl.utils.file; import android.content.Context; import android.os.Environment; -import org.droidplanner.services.android.R; +import java.io.File; public class DirectoryPath { /** * Main path used to store private data files related to the program * - * @return Path to 3DR Services private data folder in external storage + * @return Path to DroneKit-Android private data folder in external storage */ static public String getPrivateDataPath(Context context) { File dataDir = context.getExternalFilesDir(null); @@ -22,35 +20,13 @@ static public String getPrivateDataPath(Context context) { /** * Main path used to store public data files related to the app. * @param context application context - * @return Path to 3DR Services public data directory. + * @return Path to DroneKit-Android public data directory. */ public static String getPublicDataPath(Context context){ final String root = Environment.getExternalStorageDirectory().getPath(); return root + "/3DRServices/"; } - /** - * Folder where telemetry log files are stored - */ - static public File getTLogPath(Context context, String appId) { - File f = new File(getPrivateDataPath(context) + "/tlogs/" + appId); - if(!f.exists()) { - f.mkdirs(); - } - return f; - } - - /** - * After tlogs are uploaded they get moved to this directory - */ - static public File getTLogSentPath(Context context, String appId) { - File f = new File(getTLogPath(context, appId) + "/sent/"); - if(!f.exists()) { - f.mkdirs(); - } - return f; - } - /** * Storage folder for user camera description files */ diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoLoader.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoLoader.java similarity index 94% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoLoader.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoLoader.java index 8248f0585d..48b1109854 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoLoader.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoLoader.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.utils.file.IO; +package org.droidplanner.services.android.impl.utils.file.IO; import android.content.Context; -import org.droidplanner.services.android.core.survey.CameraInfo; -import org.droidplanner.services.android.utils.file.FileUtils; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; +import com.o3dr.android.client.utils.FileUtils; import java.io.File; import java.io.FileInputStream; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoReader.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoReader.java similarity index 96% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoReader.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoReader.java index 1e085f3212..7c2ffaa00b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/CameraInfoReader.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/CameraInfoReader.java @@ -1,13 +1,13 @@ -package org.droidplanner.services.android.utils.file.IO; +package org.droidplanner.services.android.impl.utils.file.IO; -import java.io.IOException; -import java.io.InputStream; +import android.util.Xml; -import org.droidplanner.services.android.core.survey.CameraInfo; +import org.droidplanner.services.android.impl.core.survey.CameraInfo; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import android.util.Xml; +import java.io.IOException; +import java.io.InputStream; /** * Class to parse a Kml file, based on the code from diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ExceptionWriter.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ExceptionWriter.java similarity index 81% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ExceptionWriter.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ExceptionWriter.java index 48ace678a2..fccefae57e 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ExceptionWriter.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ExceptionWriter.java @@ -1,10 +1,10 @@ -package org.droidplanner.services.android.utils.file.IO; +package org.droidplanner.services.android.impl.utils.file.IO; import android.content.Context; -import java.io.PrintStream; +import com.o3dr.android.client.utils.FileUtils; -import org.droidplanner.services.android.utils.file.FileUtils; +import java.io.PrintStream; public class ExceptionWriter { private final Context context; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ParameterMetadataLoader.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ParameterMetadataLoader.java similarity index 96% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ParameterMetadataLoader.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ParameterMetadataLoader.java index e22b1d9397..25b6b9f747 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/ParameterMetadataLoader.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/ParameterMetadataLoader.java @@ -1,9 +1,9 @@ -package org.droidplanner.services.android.utils.file.IO; +package org.droidplanner.services.android.impl.utils.file.IO; import android.content.Context; import android.util.Xml; -import org.droidplanner.services.android.core.drone.profiles.ParameterMetadata; +import org.droidplanner.services.android.impl.core.drone.profiles.ParameterMetadata; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/VehicleProfileReader.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/VehicleProfileReader.java similarity index 91% rename from ServiceApp/src/org/droidplanner/services/android/utils/file/IO/VehicleProfileReader.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/VehicleProfileReader.java index 31f4d21b42..da56cfdee0 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/file/IO/VehicleProfileReader.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/file/IO/VehicleProfileReader.java @@ -1,4 +1,15 @@ -package org.droidplanner.services.android.utils.file.IO; +package org.droidplanner.services.android.impl.utils.file.IO; + +import android.content.Context; +import android.content.res.AssetManager; +import android.util.Xml; + +import org.droidplanner.services.android.impl.core.drone.profiles.VehicleProfile; +import org.droidplanner.services.android.impl.core.firmware.FirmwareType; +import org.droidplanner.services.android.impl.utils.file.AssetUtil; +import org.droidplanner.services.android.impl.utils.file.DirectoryPath; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.FileInputStream; @@ -6,17 +17,6 @@ import java.io.IOException; import java.io.InputStream; -import org.droidplanner.services.android.utils.file.AssetUtil; -import org.droidplanner.services.android.utils.file.DirectoryPath; -import org.droidplanner.services.android.core.drone.profiles.VehicleProfile; -import org.droidplanner.services.android.core.firmware.FirmwareType; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import android.content.Context; -import android.content.res.AssetManager; -import android.util.Xml; - public class VehicleProfileReader { private static final String VEHICLEPROFILE_PATH = "VehicleProfiles"; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/video/StreamRecorder.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/StreamRecorder.java similarity index 99% rename from ServiceApp/src/org/droidplanner/services/android/utils/video/StreamRecorder.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/StreamRecorder.java index 08de14fe4e..3b8a36a96d 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/video/StreamRecorder.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/StreamRecorder.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils.video; +package org.droidplanner.services.android.impl.utils.video; import android.content.Context; import android.media.MediaScannerConnection; @@ -11,6 +11,7 @@ import com.googlecode.mp4parser.authoring.Movie; import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder; import com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl; + import com.o3dr.android.client.utils.video.MediaCodecManager; import com.o3dr.android.client.utils.video.NaluChunk; diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/video/VideoManager.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/VideoManager.java similarity index 97% rename from ServiceApp/src/org/droidplanner/services/android/utils/video/VideoManager.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/VideoManager.java index 7856e71329..fc995f6f8c 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/video/VideoManager.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/VideoManager.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils.video; +package org.droidplanner.services.android.impl.utils.video; import android.content.Context; import android.os.Bundle; @@ -17,6 +17,8 @@ import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError; import com.o3dr.services.android.lib.model.ICommandListener; +import org.droidplanner.services.android.impl.communication.model.DataLink; + import java.io.IOException; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; @@ -44,6 +46,7 @@ public class VideoManager implements IpConnectionListener { private static final int UDP_BUFFER_SIZE = 1500; private final AtomicBoolean videoStreamObserverUsed = new AtomicBoolean(false); + private final DataLink.DataLinkProvider linkProvider; public interface LinkListener { void onLinkConnected(); @@ -56,7 +59,7 @@ public interface LinkListener { public void run() { handler.removeCallbacks(reconnectTask); if(linkConn != null) - linkConn.connect(); + linkConn.connect(linkProvider.getConnectionExtras()); } }; @@ -76,12 +79,13 @@ public void run() { private int linkPort = -1; - public VideoManager(Context context, Handler handler) { + public VideoManager(Context context, Handler handler, DataLink.DataLinkProvider linkProvider) { this.streamRecorder = new StreamRecorder(context); this.handler = handler; this.mediaCodecManager = new MediaCodecManager(handler); this.mediaCodecManager.setNaluChunkListener(streamRecorder); + this.linkProvider = linkProvider; } private void enableLocalRecording(String filename) { @@ -164,7 +168,7 @@ private void start(int udpPort, LinkListener listener) { isStarted.set(true); this.streamRecorder.startConverterThread(); - this.linkConn.connect(); + this.linkConn.connect(linkProvider.getConnectionExtras()); this.linkListener = listener; } diff --git a/ServiceApp/src/org/droidplanner/services/android/utils/video/file/DecodeH264FromFile.java b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/file/DecodeH264FromFile.java similarity index 74% rename from ServiceApp/src/org/droidplanner/services/android/utils/video/file/DecodeH264FromFile.java rename to ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/file/DecodeH264FromFile.java index 2facaea140..0d543d71c4 100644 --- a/ServiceApp/src/org/droidplanner/services/android/utils/video/file/DecodeH264FromFile.java +++ b/ClientLib/src/main/java/org/droidplanner/services/android/impl/utils/video/file/DecodeH264FromFile.java @@ -1,4 +1,4 @@ -package org.droidplanner.services.android.utils.video.file; +package org.droidplanner.services.android.impl.utils.video.file; import android.view.Surface; diff --git a/ServiceApp/res/drawable-hdpi/ic_stat_notify.png b/ClientLib/src/main/res/drawable-hdpi/ic_stat_notify.png similarity index 100% rename from ServiceApp/res/drawable-hdpi/ic_stat_notify.png rename to ClientLib/src/main/res/drawable-hdpi/ic_stat_notify.png diff --git a/ServiceApp/res/drawable-mdpi/ic_stat_notify.png b/ClientLib/src/main/res/drawable-mdpi/ic_stat_notify.png similarity index 100% rename from ServiceApp/res/drawable-mdpi/ic_stat_notify.png rename to ClientLib/src/main/res/drawable-mdpi/ic_stat_notify.png diff --git a/ServiceApp/res/drawable-xhdpi/ic_stat_notify.png b/ClientLib/src/main/res/drawable-xhdpi/ic_stat_notify.png similarity index 100% rename from ServiceApp/res/drawable-xhdpi/ic_stat_notify.png rename to ClientLib/src/main/res/drawable-xhdpi/ic_stat_notify.png diff --git a/ServiceApp/res/drawable-xxhdpi/ic_stat_notify.png b/ClientLib/src/main/res/drawable-xxhdpi/ic_stat_notify.png similarity index 100% rename from ServiceApp/res/drawable-xxhdpi/ic_stat_notify.png rename to ClientLib/src/main/res/drawable-xxhdpi/ic_stat_notify.png diff --git a/ServiceApp/res/drawable-xxxhdpi/ic_stat_notify.png b/ClientLib/src/main/res/drawable-xxxhdpi/ic_stat_notify.png similarity index 100% rename from ServiceApp/res/drawable-xxxhdpi/ic_stat_notify.png rename to ClientLib/src/main/res/drawable-xxxhdpi/ic_stat_notify.png diff --git a/ClientLib/src/main/res/layout/activity_install_service_dialog.xml b/ClientLib/src/main/res/layout/activity_install_service_dialog.xml deleted file mode 100644 index ed97b124f2..0000000000 --- a/ClientLib/src/main/res/layout/activity_install_service_dialog.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - -