Skip to content
2 changes: 1 addition & 1 deletion ClientLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
VERSION_MAJOR = 3
VERSION_MINOR = 0
VERSION_PATCH = 0
VERSION_SUFFIX = "beta2"
VERSION_SUFFIX = "beta3"

PUBLISH_ARTIFACT_ID = 'dronekit-android'
PUBLISH_VERSION = generateVersionName("", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_SUFFIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private IVideoStreamCallback getCallback() {
public void run() {
handler.removeCallbacks(reconnectTask);
if (linkConn != null)
linkConn.connect();
linkConn.connect(null);
}
};

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class FileUtils {

public static final String CAMERA_FILENAME_EXT = ".xml";
public static final SimpleDateFormat timestampFormatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US);
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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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).
Expand Down Expand Up @@ -43,6 +45,7 @@ public abstract class AbstractIpConnection {
private final LinkedBlockingQueue<PacketData> packetsToSend = new LinkedBlockingQueue<>();

private final AtomicInteger connectionStatus = new AtomicInteger(STATE_DISCONNECTED);
private final AtomicReference<Bundle> extrasHolder = new AtomicReference<>();

private final boolean isSendingDisabled;
private final boolean isReadingDisabled;
Expand All @@ -58,7 +61,7 @@ public void run() {

try {
try {
open();
open(extrasHolder.get());
connectionStatus.set(STATE_CONNECTED);
if(ipConnectionListener != null)
ipConnectionListener.onIpConnected();
Expand Down Expand Up @@ -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;

Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.droidplanner.services.android.impl.communication.connection;

import android.content.Context;
import android.os.Bundle;

import org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler;

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;

Expand Down Expand Up @@ -40,8 +41,8 @@ protected Logger initLogger() {
}

@Override
protected void onConnectionOpened() {
AndroidTcpConnection.this.onConnectionOpened();
protected void onConnectionOpened(Bundle extras) {
AndroidTcpConnection.this.onConnectionOpened(extras);
}

@Override
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand Down Expand Up @@ -43,8 +44,8 @@ protected Logger initLogger() {
}

@Override
protected void onConnectionOpened() {
AndroidUdpConnection.this.onConnectionOpened();
protected void onConnectionOpened(Bundle extras) {
AndroidUdpConnection.this.onConnectionOpened(extras);
}

@Override
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.util.Log;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -74,7 +75,7 @@ protected void openConnection() throws IOException {
out = bluetoothSocket.getOutputStream();
in = bluetoothSocket.getInputStream();

onConnectionOpened();
onConnectionOpened(connectionExtras);
}

@SuppressLint("NewApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 org.droidplanner.services.android.impl.utils.connection.WifiConnectionHandler;

import java.io.IOException;
Expand Down Expand Up @@ -39,8 +40,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
Expand All @@ -51,7 +52,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!");
Expand Down Expand Up @@ -97,13 +98,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());
Expand Down Expand Up @@ -151,7 +152,14 @@ private void checkScanResults(List<ScanResult> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -45,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);
}
Expand Down Expand Up @@ -76,6 +77,7 @@ public void run() {
}
};

private final AtomicReference<Bundle> extrasHolder = new AtomicReference<>();
private ScheduledExecutorService scheduler;

protected UsbCDCConnection(Context context, UsbConnection parentConn, int baudRate) {
Expand Down Expand Up @@ -103,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.
Expand All @@ -119,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();

Expand All @@ -130,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);

Expand All @@ -148,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 {
Expand Down
Loading