Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ServiceApp/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:allowBackup="true"
android:theme="@style/AppTheme"
android:icon="@drawable/ic_launcher"
android:largeHeap="true"
android:label="@string/app_title">

<meta-data
Expand Down
4 changes: 3 additions & 1 deletion ServiceApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ android {
//Write logs to file preferences
buildConfigField "boolean", "WRITE_LOG_FILE", "false"
buildConfigField "int", "LOG_FILE_LEVEL", "$logLevelDebug"
buildConfigField "boolean", "ENABLE_CRASHLYTICS", "false"
}

compileOptions {
Expand Down Expand Up @@ -133,7 +134,7 @@ android {
signingConfig signingConfigs.release
versionNameSuffix generateVersionNameSuffix(versionBuild, "beta")
buildConfigField "boolean", "WRITE_LOG_FILE", "true"
debuggable true
buildConfigField "boolean", "ENABLE_CRASHLYTICS", "true"
}

sitl {
Expand All @@ -145,6 +146,7 @@ android {

release {
signingConfig signingConfigs.release
buildConfigField "boolean", "ENABLE_CRASHLYTICS", "true"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
import android.app.Application;

import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

import org.droidplanner.services.android.utils.LogToFileTree;
import org.droidplanner.services.android.utils.analytics.GAUtils;
import org.droidplanner.services.android.utils.file.IO.ExceptionWriter;

import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

public class DroidPlannerServicesApp extends Application {

private LogToFileTree logToFileTree;

@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());

if (BuildConfig.DEBUG) {
if(BuildConfig.WRITE_LOG_FILE){
logToFileTree = new LogToFileTree();
Timber.plant(logToFileTree);
}
else {
Timber.plant(new Timber.DebugTree());
}
if(BuildConfig.ENABLE_CRASHLYTICS) {
Fabric.with(this, new Crashlytics());
}

if (BuildConfig.WRITE_LOG_FILE) {
logToFileTree = new LogToFileTree();
Timber.plant(logToFileTree);
} else if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}

final ExceptionWriter exceptionWriter = new ExceptionWriter(getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import timber.log.Timber;

class UsbCDCConnection extends UsbConnection.UsbConnectionImpl {
private static final String TAG = UsbCDCConnection.class.getSimpleName();
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
Expand Down Expand Up @@ -78,7 +80,11 @@ private void registerUsbPermissionBroadcastReceiver() {
}

private void unregisterUsbPermissionBroadcastReceiver() {
mContext.unregisterReceiver(broadcastReceiver);
try {
mContext.unregisterReceiver(broadcastReceiver);
}catch(IllegalArgumentException e){
Timber.e(e, "Receiver was not registered.");
}
}

private void removeWatchdog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.droidplanner.services.android.core.drone.autopilot.px4.Px4Native;
import org.droidplanner.services.android.core.drone.companion.solo.SoloComp;
import org.droidplanner.services.android.core.drone.variables.HeartBeat;
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;
Expand All @@ -77,6 +78,8 @@
import org.droidplanner.services.android.utils.analytics.GAUtils;
import org.droidplanner.services.android.utils.prefs.DroidPlannerPrefs;

import org.droidplanner.services.android.core.drone.profiles.Parameters;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -280,15 +283,26 @@ public void postDelayed(Runnable thread, long timeout) {
break;
}

this.drone.getStreamRates().setRates(dpPrefs.getRates());

this.followMe = new Follow(this, handler, new FusedLocation(context, handler));
this.returnToMe = new ReturnToMe(this, new FusedLocation(context, handler,
LocationRequest.PRIORITY_HIGH_ACCURACY, 1000L, 1000L, ReturnToMe.UPDATE_MINIMAL_DISPLACEMENT), this);

final StreamRates streamRates = drone.getStreamRates();
if(streamRates != null) {
streamRates.setRates(dpPrefs.getRates());
}

drone.addDroneListener(this);
drone.getParameters().setParameterListener(this);
drone.getMagnetometerCalibration().setListener(this);

final Parameters parameters = drone.getParameters();
if(parameters != null) {
parameters.setParameterListener(this);
}

final MagnetometerCalibrationImpl magnetometer = drone.getMagnetometerCalibration();
if(magnetometer != null) {
magnetometer.setListener(this);
}
}

public SoloComp getSoloComp() {
Expand Down Expand Up @@ -507,6 +521,8 @@ private void handleCommandAck(msg_command_ack ack) {
@Override
public void notifyReceivedData(MAVLinkPacket packet) {
MAVLinkMessage receivedMsg = packet.unpack();
if(receivedMsg == null)
return;

if (receivedMsg.msgid == msg_command_ack.MAVLINK_MSG_ID_COMMAND_ACK) {
final msg_command_ack commandAck = (msg_command_ack) receivedMsg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.droidplanner.services.android.core.drone.DroneInterfaces;
import org.droidplanner.services.android.core.drone.LogMessageListener;
import org.droidplanner.services.android.core.drone.Preferences;
import org.droidplanner.services.android.core.drone.autopilot.CommonMavLinkDrone;
import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone;
import org.droidplanner.services.android.core.drone.profiles.Parameters;
import org.droidplanner.services.android.core.drone.profiles.VehicleProfile;
import org.droidplanner.services.android.core.drone.variables.ApmModes;
Expand All @@ -69,7 +69,6 @@
import org.droidplanner.services.android.core.drone.variables.Magnetometer;
import org.droidplanner.services.android.core.drone.variables.MissionStats;
import org.droidplanner.services.android.core.drone.variables.RC;
import org.droidplanner.services.android.core.drone.variables.StreamRates;
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.helpers.coordinates.Coord3D;
Expand All @@ -81,7 +80,7 @@
/**
* Base class for the ArduPilot autopilots
*/
public abstract class ArduPilot extends CommonMavLinkDrone {
public abstract class ArduPilot extends GenericMavLinkDrone {

public static final int AUTOPILOT_COMPONENT_ID = 1;
public static final int ARTOO_COMPONENT_ID = 0;
Expand All @@ -94,7 +93,6 @@ public abstract class ArduPilot extends CommonMavLinkDrone {
private final Home home;
private final Mission mission;
private final MissionStats missionStats;
private final StreamRates streamRates;
private final GuidedPoint guidedPoint;
private final AccelCalibration accelCalibrationSetup;
private final WaypointManager waypointManager;
Expand Down Expand Up @@ -129,7 +127,6 @@ public ArduPilot(Context context, MAVLinkStreams.MAVLinkOutputStream mavClient,
this.home = new Home(this);
this.mission = new Mission(this);
this.missionStats = new MissionStats(this);
this.streamRates = new StreamRates(this);
this.guidedPoint = new GuidedPoint(this, handler);
this.accelCalibrationSetup = new AccelCalibration(this, handler);
this.magCalibration = new MagnetometerCalibrationImpl(this);
Expand Down Expand Up @@ -235,11 +232,6 @@ public MissionStats getMissionStats() {
return missionStats;
}

@Override
public StreamRates getStreamRates() {
return streamRates;
}

@Override
public GuidedPoint getGuidedPoint() {
return guidedPoint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.droidplanner.services.android.core.drone.autopilot;
package org.droidplanner.services.android.core.drone.autopilot.generic;

import android.os.Bundle;
import android.text.TextUtils;
Expand Down Expand Up @@ -31,7 +31,9 @@
import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds;
import org.droidplanner.services.android.core.drone.DroneEvents;
import org.droidplanner.services.android.core.drone.DroneInterfaces;
import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone;
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.model.AutopilotWarningParser;
import org.droidplanner.services.android.utils.CommonApiUtils;
Expand All @@ -42,13 +44,14 @@
*
* Created by Fredia Huya-Kouadio on 9/10/15.
*/
public abstract class CommonMavLinkDrone implements MavLinkDrone {
public abstract class GenericMavLinkDrone implements MavLinkDrone {

private final MAVLinkStreams.MAVLinkOutputStream MavClient;

private final DroneEvents events;
protected final Type type;
private final State state;
private final StreamRates streamRates;

private final DroneInterfaces.AttributeEventListener attributeListener;

Expand All @@ -59,11 +62,12 @@ public abstract class CommonMavLinkDrone implements MavLinkDrone {
protected final Attitude attitude = new Attitude();
protected final Vibration vibration = new Vibration();

protected CommonMavLinkDrone(DroneInterfaces.Handler handler, MAVLinkStreams.MAVLinkOutputStream mavClient, AutopilotWarningParser warningParser, DroneInterfaces.AttributeEventListener listener) {
protected GenericMavLinkDrone(DroneInterfaces.Handler handler, MAVLinkStreams.MAVLinkOutputStream mavClient, AutopilotWarningParser warningParser, DroneInterfaces.AttributeEventListener listener) {
this.MavClient = mavClient;

events = new DroneEvents(this, handler);
this.type = new Type(this);
this.streamRates = new StreamRates(this);
this.state = new State(this, handler, warningParser);

this.attributeListener = listener;
Expand All @@ -84,6 +88,11 @@ public void addDroneListener(DroneInterfaces.OnDroneListener listener) {
events.addDroneListener(listener);
}

@Override
public StreamRates getStreamRates() {
return streamRates;
}

@Override
public void removeDroneListener(DroneInterfaces.OnDroneListener listener) {
events.removeDroneListener(listener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.droidplanner.services.android.core.drone.autopilot.px4;

import com.o3dr.services.android.lib.model.ICommandListener;
import com.o3dr.services.android.lib.model.action.Action;

import org.droidplanner.services.android.core.MAVLink.MAVLinkStreams;
import org.droidplanner.services.android.core.MAVLink.WaypointManager;
import org.droidplanner.services.android.core.drone.DroneInterfaces;
import org.droidplanner.services.android.core.drone.Preferences;
import org.droidplanner.services.android.core.drone.autopilot.CommonMavLinkDrone;
import org.droidplanner.services.android.core.drone.autopilot.generic.GenericMavLinkDrone;
import org.droidplanner.services.android.core.drone.profiles.Parameters;
import org.droidplanner.services.android.core.drone.profiles.VehicleProfile;
import org.droidplanner.services.android.core.drone.variables.Camera;
Expand All @@ -16,7 +13,6 @@
import org.droidplanner.services.android.core.drone.variables.Home;
import org.droidplanner.services.android.core.drone.variables.Magnetometer;
import org.droidplanner.services.android.core.drone.variables.MissionStats;
import org.droidplanner.services.android.core.drone.variables.StreamRates;
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;
Expand All @@ -26,7 +22,7 @@
/**
* Created by Fredia Huya-Kouadio on 9/10/15.
*/
public class Px4Native extends CommonMavLinkDrone {
public class Px4Native extends GenericMavLinkDrone {

public Px4Native(DroneInterfaces.Handler handler, MAVLinkStreams.MAVLinkOutputStream mavClient, AutopilotWarningParser warningParser, DroneInterfaces.AttributeEventListener listener) {
super(handler, mavClient, warningParser, listener);
Expand Down Expand Up @@ -97,11 +93,6 @@ public Mission getMission() {
return null;
}

@Override
public StreamRates getStreamRates() {
return null;
}

@Override
public MissionStats getMissionStats() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public GCSHeartbeat(MAVLinkClient mavClient, int freqHz) {
*
* @param active true to activate the heartbeat, false to deactivate it
*/
public void setActive(boolean active) {
public synchronized void setActive(boolean active) {
if (active) {
if (heartbeatExecutor == null || heartbeatExecutor.isShutdown()) {
heartbeatExecutor = Executors.newSingleThreadScheduledExecutor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
Expand Down Expand Up @@ -139,7 +140,8 @@ public void onBindViewHolder(ViewHolder viewHolder, int position) {

viewHolder.actionButtonContainer.setVisibility(View.VISIBLE);

Intent tmpIntent = context.getPackageManager().getLaunchIntentForPackage(appId);
final PackageManager pm = context.getPackageManager();
Intent tmpIntent = pm.getLaunchIntentForPackage(appId);
if (tmpIntent != null) {
//The app is installed on the device.
viewHolder.actionButton.setText(R.string.label_action_button_open);
Expand All @@ -150,6 +152,12 @@ public void onBindViewHolder(ViewHolder viewHolder, int position) {
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.parse("market://details?id=" + appId));

if(pm.resolveActivity(tmpIntent, PackageManager.MATCH_DEFAULT_ONLY) == null){
tmpIntent = new Intent(Intent.ACTION_VIEW)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + appId));
}

viewHolder.actionButton.setText(R.string.label_action_button_install);
viewHolder.actionButton.setBackgroundResource(R.drawable.action_button_install_bg);
}
Expand Down