diff --git a/AidlLib/src/com/o3dr/services/android/lib/drone/mission/item/command/SetServo.java b/AidlLib/src/com/o3dr/services/android/lib/drone/mission/item/command/SetServo.java index 22ac60020e..d11ede9c0b 100644 --- a/AidlLib/src/com/o3dr/services/android/lib/drone/mission/item/command/SetServo.java +++ b/AidlLib/src/com/o3dr/services/android/lib/drone/mission/item/command/SetServo.java @@ -6,7 +6,7 @@ import com.o3dr.services.android.lib.drone.mission.MissionItemType; /** - * Created by fhuya on 11/6/14. + * Mission command used to move a servo to a particular pwm value. */ public class SetServo extends MissionItem implements MissionItem.Command, android.os.Parcelable { @@ -23,18 +23,31 @@ public SetServo(SetServo copy){ channel = copy.channel; } + /** + * @return PWM value to output to the servo + */ public int getPwm() { return pwm; } + /** + * Set PWM value to output to the servo + * @param pwm value to output to the servo + */ public void setPwm(int pwm) { this.pwm = pwm; } + /** + * @return the output channel the servo is attached to + */ public int getChannel() { return channel; } + /** + * @param channel the output channel the servo is attached to + */ public void setChannel(int channel) { this.channel = channel; } diff --git a/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java b/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java index 2e39c1a66b..013558da4a 100644 --- a/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java +++ b/ServiceApp/src/org/droidplanner/services/android/api/DroidPlannerService.java @@ -128,6 +128,7 @@ void connectMAVConnection(ConnectionParameter connParams, String listenerTag, mavConnections.put(connParams, conn); } + conn.addMavLinkConnectionListener(listenerTag, listener); if (conn.getConnectionStatus() == MavLinkConnection.MAVLINK_DISCONNECTED) { conn.connect(); @@ -137,8 +138,6 @@ void connectMAVConnection(ConnectionParameter connParams, String listenerTag, .setAction("MavLink connect") .setLabel(connParams.toString())); } - - conn.addMavLinkConnectionListener(listenerTag, listener); } void disconnectMAVConnection(ConnectionParameter connParams, String listenerTag) { diff --git a/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java b/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java index 82b770d8d3..0475b52ce9 100644 --- a/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java +++ b/ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java @@ -1329,7 +1329,16 @@ public void onDroneEvent(DroneInterfaces.DroneEventsType event, Drone drone) { case CONNECTING: extrasBundle = new Bundle(2); extrasBundle.putInt(AttributeEventExtra.EXTRA_AUTOPILOT_FAILSAFE_MESSAGE_LEVEL, Log.INFO); - extrasBundle.putString(AttributeEventExtra.EXTRA_AUTOPILOT_FAILSAFE_MESSAGE, "Connecting..."); + extrasBundle.putString(AttributeEventExtra.EXTRA_AUTOPILOT_FAILSAFE_MESSAGE, + "Connecting..."); + droneEvent = AttributeEvent.AUTOPILOT_FAILSAFE; + break; + + case CHECKING_VEHICLE_LINK: + extrasBundle = new Bundle(2); + extrasBundle.putInt(AttributeEventExtra.EXTRA_AUTOPILOT_FAILSAFE_MESSAGE_LEVEL, Log.INFO); + extrasBundle.putString(AttributeEventExtra.EXTRA_AUTOPILOT_FAILSAFE_MESSAGE, + "Checking vehicle link..."); droneEvent = AttributeEvent.AUTOPILOT_FAILSAFE; break; diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java index 97ae68031e..61e8b88237 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidTcpConnection.java @@ -35,6 +35,16 @@ protected String loadServerIP() { protected Logger initLogger() { return AndroidTcpConnection.this.initLogger(); } + + @Override + protected void onConnectionOpened(){ + AndroidTcpConnection.this.onConnectionOpened(); + } + + @Override + protected void onConnectionFailed(String errMsg){ + AndroidTcpConnection.this.onConnectionFailed(errMsg); + } }; } diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java index eb9230daeb..260483e18b 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/AndroidUdpConnection.java @@ -28,6 +28,16 @@ protected Logger initLogger() { return AndroidUdpConnection.this.initLogger(); } + @Override + protected void onConnectionOpened(){ + AndroidUdpConnection.this.onConnectionOpened(); + } + + @Override + protected void onConnectionFailed(String errMsg){ + AndroidUdpConnection.this.onConnectionFailed(errMsg); + } + }; } diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java index 0a4d3529ab..5cad1dba79 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/BluetoothConnection.java @@ -72,6 +72,8 @@ protected void openConnection() throws IOException { Log.d(BLUE, "## BT Connected ##"); out = bluetoothSocket.getOutputStream(); in = bluetoothSocket.getInputStream(); + + onConnectionOpened(); } @SuppressLint("NewApi") diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java index 67d7dade3d..8e01650cdb 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbCDCConnection.java @@ -1,8 +1,5 @@ package org.droidplanner.services.android.communication.connection.usb; -import java.io.IOException; -import java.util.List; - import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -15,13 +12,19 @@ import com.hoho.android.usbserial.driver.UsbSerialDriver; import com.hoho.android.usbserial.driver.UsbSerialProber; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + class UsbCDCConnection extends UsbConnection.UsbConnectionImpl { - private static final String TAG = UsbCDCConnection.class.getSimpleName(); + private static final String TAG = UsbCDCConnection.class.getSimpleName(); private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; private static final IntentFilter intentFilter = new IntentFilter(ACTION_USB_PERMISSION); - private static UsbSerialDriver sDriver = null; + private static UsbSerialDriver sDriver = null; private final PendingIntent usbPermissionIntent; @@ -29,67 +32,88 @@ class UsbCDCConnection extends UsbConnection.UsbConnectionImpl { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - if(ACTION_USB_PERMISSION.equals(action)){ - synchronized(this){ - UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); - - if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { - if(device != null){ - //call method to set up device communication - try { - openUsbDevice(device); - } catch (IOException e) { - Log.e(TAG, e.getMessage(), e); - } + if (ACTION_USB_PERMISSION.equals(action)) { + removeWatchdog(); + UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); + + if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { + if (device != null) { + //call method to set up device communication + try { + openUsbDevice(device); + } catch (IOException e) { + Log.e(TAG, e.getMessage(), e); } + } else { + onUsbConnectionFailed("Unable to access usb device."); } - else { - Log.d(TAG, "permission denied for device " + device); - } + } else { + Log.d(TAG, "permission denied for device " + device); + onUsbConnectionFailed("USB Permission denied."); } } } }; - protected UsbCDCConnection(Context context, int baudRate) { - super(context, baudRate); - this.usbPermissionIntent = PendingIntent.getBroadcast(context, 0, - new Intent(ACTION_USB_PERMISSION), 0); - } + private final Runnable permissionWatchdog = new Runnable() { + @Override + public void run() { + Log.d(TAG, "Permission request timeout."); + onUsbConnectionFailed("Unable to get usb access."); + + removeWatchdog(); + } + }; - private void registerUsbPermissionBroadcastReceiver(){ -// mContext.registerReceiver(broadcastReceiver, intentFilter); + private ScheduledExecutorService scheduler; + + protected UsbCDCConnection(Context context, UsbConnection parentConn, int baudRate) { + super(context, parentConn, baudRate); + this.usbPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); + } + + private void registerUsbPermissionBroadcastReceiver() { + mContext.registerReceiver(broadcastReceiver, intentFilter); + } + + private void unregisterUsbPermissionBroadcastReceiver() { + mContext.unregisterReceiver(broadcastReceiver); } - private void unregisterUsbPermissionBroadcastReceiver(){ -// mContext.unregisterReceiver(broadcastReceiver); + private void removeWatchdog() { + if (scheduler != null) { + scheduler.shutdown(); + scheduler = null; + } } - @Override - protected void openUsbConnection() throws IOException { + @Override + protected void openUsbConnection() throws IOException { registerUsbPermissionBroadcastReceiver(); - // Get UsbManager from Android. - UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); + // Get UsbManager from Android. + UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); //Get the list of available devices List availableDevices = UsbSerialProber.getAvailableSupportedDevices(manager); - if(availableDevices.isEmpty()){ + if (availableDevices.isEmpty()) { Log.d("USB", "No Devices found"); throw new IOException("No Devices found"); } //Pick the first device UsbDevice device = availableDevices.get(0); - if(manager.hasPermission(device)){ + if (manager.hasPermission(device)) { openUsbDevice(device); + } else { + removeWatchdog(); + + scheduler = Executors.newSingleThreadScheduledExecutor(); + scheduler.schedule(permissionWatchdog, 15, TimeUnit.SECONDS); + Log.d(TAG, "Requesting permission to access usb device " + device.getDeviceName()); + manager.requestPermission(device, usbPermissionIntent); } - else{ - //TODO: complete implementation -// manager.requestPermission(device, usbPermissionIntent); - throw new IOException("No permission to access usb device " + device.getDeviceName()); - } - } + } private void openUsbDevice(UsbDevice device) throws IOException { // Get UsbManager from Android. @@ -105,8 +129,9 @@ private void openUsbDevice(UsbDevice device) throws IOException { Log.d("USB", "Opening using Baud rate " + mBaudRate); try { sDriver.open(); - sDriver.setParameters(mBaudRate, 8, UsbSerialDriver.STOPBITS_1, - UsbSerialDriver.PARITY_NONE); + sDriver.setParameters(mBaudRate, 8, UsbSerialDriver.STOPBITS_1, UsbSerialDriver.PARITY_NONE); + + onUsbConnectionOpened(); } catch (IOException e) { Log.e("USB", "Error setting up device: " + e.getMessage(), e); try { @@ -119,57 +144,57 @@ private void openUsbDevice(UsbDevice device) throws IOException { } } - @Override - protected int readDataBlock(byte[] readData) throws IOException { - // Read data from driver. This call will return upto readData.length - // bytes. - // If no data is received it will timeout after 200ms (as set by - // parameter 2) - int iavailable = 0; - try { - iavailable = sDriver.read(readData, 200); - } catch (NullPointerException e) { - final String errorMsg = "Error Reading: " + e.getMessage() - + "\nAssuming inaccessible USB device. Closing connection."; - Log.e(TAG, errorMsg, e); - throw new IOException(errorMsg, e); - } - - if (iavailable == 0) - iavailable = -1; - return iavailable; - } - - @Override - protected void sendBuffer(byte[] buffer) { - // Write data to driver. This call should write buffer.length bytes - // if data cant be sent , then it will timeout in 500ms (as set by - // parameter 2) - if (sDriver != null) { - try { - sDriver.write(buffer, 500); - } catch (IOException e) { - Log.e("USB", "Error Sending: " + e.getMessage(), e); - } - } - } - - @Override - protected void closeUsbConnection() throws IOException { + @Override + protected int readDataBlock(byte[] readData) throws IOException { + // Read data from driver. This call will return upto readData.length + // bytes. + // If no data is received it will timeout after 200ms (as set by + // parameter 2) + int iavailable = 0; + try { + iavailable = sDriver.read(readData, 200); + } catch (NullPointerException e) { + final String errorMsg = "Error Reading: " + e.getMessage() + + "\nAssuming inaccessible USB device. Closing connection."; + Log.e(TAG, errorMsg, e); + throw new IOException(errorMsg, e); + } + + if (iavailable == 0) + iavailable = -1; + return iavailable; + } + + @Override + protected void sendBuffer(byte[] buffer) { + // Write data to driver. This call should write buffer.length bytes + // if data cant be sent , then it will timeout in 500ms (as set by + // parameter 2) + if (sDriver != null) { + try { + sDriver.write(buffer, 500); + } catch (IOException e) { + Log.e("USB", "Error Sending: " + e.getMessage(), e); + } + } + } + + @Override + protected void closeUsbConnection() throws IOException { unregisterUsbPermissionBroadcastReceiver(); - if (sDriver != null) { - try { - sDriver.close(); - } catch (IOException e) { - // Ignore. - } - sDriver = null; - } - } - - @Override - public String toString() { - return TAG; - } + if (sDriver != null) { + try { + sDriver.close(); + } catch (IOException e) { + // Ignore. + } + sDriver = null; + } + } + + @Override + public String toString() { + return TAG; + } } diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java index 1eee60564e..0a08da48fe 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbConnection.java @@ -53,7 +53,7 @@ protected void openConnection() throws IOException { } if (isFTDIdevice(mContext)) { - final UsbConnectionImpl tmp = new UsbFTDIConnection(mContext, mBaudRate); + final UsbConnectionImpl tmp = new UsbFTDIConnection(mContext, this, mBaudRate); try { tmp.openUsbConnection(); @@ -68,10 +68,9 @@ protected void openConnection() throws IOException { // Fallback if (mUsbConnection == null) { - final UsbConnectionImpl tmp = new UsbCDCConnection(mContext, mBaudRate); + final UsbConnectionImpl tmp = new UsbCDCConnection(mContext, this, mBaudRate); - // If an error happens here, let it propagate up the call chain since this is the - // fallback. + // If an error happens here, let it propagate up the call chain since this is the fallback. tmp.openUsbConnection(); mUsbConnection = tmp; Log.d(TAG, "Using open-source usb connection."); @@ -128,13 +127,23 @@ public String toString() { static abstract class UsbConnectionImpl { protected final int mBaudRate; protected final Context mContext; + private final UsbConnection parentConnection; protected final Logger mLogger = AndroidLogger.getLogger(); - protected UsbConnectionImpl(Context context, int baudRate) { + protected UsbConnectionImpl(Context context, UsbConnection parentConn, int baudRate) { mContext = context; + this.parentConnection = parentConn; mBaudRate = baudRate; } + protected void onUsbConnectionOpened(){ + parentConnection.onConnectionOpened(); + } + + protected void onUsbConnectionFailed(String errMsg){ + parentConnection.onConnectionFailed(errMsg); + } + protected abstract void closeUsbConnection() throws IOException; protected abstract void openUsbConnection() throws IOException; diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java index 6ccf1ecec3..155c6f8d71 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/connection/usb/UsbFTDIConnection.java @@ -16,8 +16,8 @@ class UsbFTDIConnection extends UsbConnection.UsbConnectionImpl { private FT_Device ftDev; - protected UsbFTDIConnection(Context context, int baudRate) { - super(context, baudRate); + protected UsbFTDIConnection(Context context, UsbConnection parentConn, int baudRate) { + super(context, parentConn, baudRate); } @Override @@ -65,6 +65,8 @@ protected void openUsbConnection() throws IOException { } else { Log.d("USB", "COM open"); } + + onUsbConnectionOpened(); } @Override diff --git a/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java b/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java index ce9b2c51df..ac83b12f55 100644 --- a/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java +++ b/ServiceApp/src/org/droidplanner/services/android/communication/service/MAVLinkClient.java @@ -37,6 +37,11 @@ public class MAVLinkClient implements MAVLinkStreams.MAVLinkOutputStream { private final MavLinkConnectionListener mConnectionListener = new MavLinkConnectionListener() { + @Override + public void onStartingConnection(){ + listener.notifyStartingConnection(); + } + @Override public void onConnect(long connectionTime) { startLoggingThread(connectionTime); diff --git a/ServiceApp/src/org/droidplanner/services/android/drone/DroneManager.java b/ServiceApp/src/org/droidplanner/services/android/drone/DroneManager.java index 9f9fe0d4d7..75f08cacea 100644 --- a/ServiceApp/src/org/droidplanner/services/android/drone/DroneManager.java +++ b/ServiceApp/src/org/droidplanner/services/android/drone/DroneManager.java @@ -166,6 +166,11 @@ public void disconnect() throws ConnectionException { onDroneEvent(DroneInterfaces.DroneEventsType.DISCONNECTED, drone); } + @Override + public void notifyStartingConnection() { + onDroneEvent(DroneInterfaces.DroneEventsType.CONNECTING, drone); + } + @Override public void notifyConnected() { if (this.connectionParams != null) { @@ -193,7 +198,7 @@ public void notifyConnected() { } } - this.drone.notifyDroneEvent(DroneInterfaces.DroneEventsType.CONNECTING); + this.drone.notifyDroneEvent(DroneInterfaces.DroneEventsType.CHECKING_VEHICLE_LINK); } public void kickStartDroneShareUpload(){ diff --git a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MAVLinkStreams.java b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MAVLinkStreams.java index 9a0fe4d716..d656917aec 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MAVLinkStreams.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/MAVLinkStreams.java @@ -19,6 +19,8 @@ public interface MAVLinkOutputStream { } public interface MavlinkInputStream { + public void notifyStartingConnection(); + public void notifyConnected(); public void notifyDisconnected(); diff --git a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnection.java b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnection.java index c952f2ead8..82f6e99839 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnection.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnection.java @@ -47,27 +47,46 @@ public abstract class MavLinkConnection { private final AtomicLong mConnectionTime = new AtomicLong(-1); /** - * Listen for incoming data on the mavlink connection. + * Start the connection process. */ private final Runnable mConnectingTask = new Runnable() { - @Override public void run() { - Thread sendingThread = null; - // Load the connection specific preferences loadPreferences(); - + // Open the connection try { - // Open the connection openConnection(); - mConnectionStatus.set(MAVLINK_CONNECTED); + } catch (IOException e) { + // Ignore errors while shutting down + if (mConnectionStatus.get() != MAVLINK_DISCONNECTED) { + reportComError(e.getMessage()); + mLogger.logErr(TAG, e); + } + disconnect(); + } + + mLogger.logInfo(TAG, "Exiting connecting thread."); + } + }; + + /** + * Manages the receiving and sending of messages. + */ + private final Runnable mManagerTask = new Runnable() { + + @Override + public void run() { + Thread sendingThread = null; + + try { final long connectionTime = System.currentTimeMillis(); mConnectionTime.set(connectionTime); reportConnect(connectionTime); // Launch the 'Sending' threads + mLogger.logInfo(TAG, "Starting sender thread."); sendingThread = new Thread(mSendingTask, "MavLinkConnection-Sending Thread"); sendingThread.start(); @@ -92,6 +111,7 @@ public void run() { } disconnect(); + mLogger.logInfo(TAG, "Exiting manager thread."); } } @@ -137,6 +157,7 @@ public void run() { protected final Logger mLogger = initLogger(); + private Thread mConnectThread; private Thread mTaskThread; /** @@ -145,17 +166,33 @@ public void run() { */ public void connect() { if (mConnectionStatus.compareAndSet(MAVLINK_DISCONNECTED, MAVLINK_CONNECTING)) { - mTaskThread = new Thread(mConnectingTask, "MavLinkConnection-Connecting Thread"); + mLogger.logInfo(TAG, "Starting connection thread."); + mConnectThread = new Thread(mConnectingTask, "MavLinkConnection-Connecting Thread"); + mConnectThread.start(); + reportConnecting(); + } + } + + protected void onConnectionOpened() { + if (mConnectionStatus.compareAndSet(MAVLINK_CONNECTING, MAVLINK_CONNECTED)) { + mLogger.logInfo(TAG, "Starting manager thread."); + mTaskThread = new Thread(mManagerTask, "MavLinkConnection-Manager Thread"); mTaskThread.start(); } } + protected void onConnectionFailed(String errMsg) { + mLogger.logInfo(TAG, "Unable to establish connection: " + errMsg); + reportComError(errMsg); + disconnect(); + } + /** * Disconnect a mavlink connection. If the operation is successful, it will * be reported through the MavLinkConnectionListener interface. */ public void disconnect() { - if (mConnectionStatus.get() == MAVLINK_DISCONNECTED || mTaskThread == null) { + if (mConnectionStatus.get() == MAVLINK_DISCONNECTED || (mConnectThread == null && mTaskThread == null)) { return; } @@ -164,7 +201,12 @@ public void disconnect() { mConnectionStatus.set(MAVLINK_DISCONNECTED); mConnectionTime.set(-1); - if (mTaskThread.isAlive() && !mTaskThread.isInterrupted()) { + + if (mConnectThread != null && mConnectThread.isAlive() && !mConnectThread.isInterrupted()) { + mConnectThread.interrupt(); + } + + if (mTaskThread != null && mTaskThread.isAlive() && !mTaskThread.isInterrupted()) { mTaskThread.interrupt(); } @@ -269,6 +311,12 @@ protected void reportComError(String errMsg) { } } + protected void reportConnecting(){ + for(MavLinkConnectionListener listener: mListeners.values()){ + listener.onStartingConnection(); + } + } + /** * Utility method to notify the mavlink listeners about a successful * connection. diff --git a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnectionListener.java b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnectionListener.java index 51dcdbea6f..01908180e8 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnectionListener.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/MavLinkConnectionListener.java @@ -7,6 +7,11 @@ */ public interface MavLinkConnectionListener { + /** + * Called when a connection is being established. + */ + public void onStartingConnection(); + /** * Called when the mavlink connection is established. */ diff --git a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/TcpConnection.java b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/TcpConnection.java index 35718074f8..22b7855368 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/TcpConnection.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/TcpConnection.java @@ -24,6 +24,7 @@ public abstract class TcpConnection extends MavLinkConnection { @Override public final void openConnection() throws IOException { getTCPStream(); + onConnectionOpened(); } @Override diff --git a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/UdpConnection.java b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/UdpConnection.java index d27e9a850c..3271ccf5fa 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/UdpConnection.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/MAVLink/connection/UdpConnection.java @@ -31,6 +31,7 @@ public final void closeConnection() throws IOException { @Override public final void openConnection() throws IOException { getUdpStream(); + onConnectionOpened(); } @Override diff --git a/dependencyLibs/Core/src/org/droidplanner/core/drone/DroneInterfaces.java b/dependencyLibs/Core/src/org/droidplanner/core/drone/DroneInterfaces.java index 3e315cdfe6..60191ba720 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/drone/DroneInterfaces.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/drone/DroneInterfaces.java @@ -157,6 +157,11 @@ public enum DroneEventsType { */ CONNECTING, + /** + * Vehicle link is being validated. + */ + CHECKING_VEHICLE_LINK, + /** * Connection failed event. */ diff --git a/dependencyLibs/Core/src/org/droidplanner/core/drone/variables/HeartBeat.java b/dependencyLibs/Core/src/org/droidplanner/core/drone/variables/HeartBeat.java index 1e31e35d14..ea705f292e 100644 --- a/dependencyLibs/Core/src/org/droidplanner/core/drone/variables/HeartBeat.java +++ b/dependencyLibs/Core/src/org/droidplanner/core/drone/variables/HeartBeat.java @@ -100,7 +100,7 @@ public void onDroneEvent(DroneEventsType event, Drone drone) { restartWatchdog(HEARTBEAT_IMU_CALIBRATION_TIMEOUT); break; - case CONNECTING: + case CHECKING_VEHICLE_LINK: System.out.println("Received connecting event."); gcsHeartbeat.setActive(true); notifyConnecting();