Skip to content

Commit

Permalink
StarterApp: Adding in Bill Bonney's fix
Browse files Browse the repository at this point in the history
Fix to use new connection paradigm
From this PR dronekit#465
  • Loading branch information
gmorph authored and billbonney committed Nov 12, 2017
1 parent 836044c commit 25850de
Showing 1 changed file with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.droidplanner.services.android.impl;

import android.content.Context;
import android.os.Bundle;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.MAVLink.MAVLinkPacket;
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.drone.connection.ConnectionType;
import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus;

import org.junit.Assert;
Expand All @@ -29,6 +32,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static android.support.v4.app.ActivityCompat.startActivity;


/**
* Created by djmedina on 3/5/15.
Expand All @@ -38,9 +43,13 @@
@Config(constants = BuildConfig.class, sdk = 18)
public class BasicTest {

private static final String TAG = BasicTest.class.getSimpleName();

private MavLinkDrone drone;
private MockMAVLinkClient mavClient;

private boolean isUdpPingEnabled = false;

private final Handler dpHandler = new Handler();

private final DataLink.DataLinkListener inputStreamListener = new DataLink.DataLinkListener() {
Expand All @@ -57,7 +66,7 @@ public void onConnectionStatus(LinkConnectionStatus connectionStatus) {
public void setUp() throws Exception {
final Context context = RuntimeEnvironment.application.getApplicationContext();

ConnectionParameter connParams = new ConnectionParameter(0, new Bundle());
ConnectionParameter connParams = retrieveConnectionParameters();
mavClient = new MockMAVLinkClient(context, inputStreamListener, connParams);

drone = new ArduCopter("test:" + FirmwareType.ARDU_COPTER.getType(), context, mavClient, dpHandler, new AndroidApWarningParser(), new LogMessageListener() {
Expand Down Expand Up @@ -95,4 +104,59 @@ public void testArm() {
Assert.assertEquals(MAV_CMD.MAV_CMD_COMPONENT_ARM_DISARM, longMsg.command);
Assert.assertEquals(1f, longMsg.param1, 0.001);
}

private ConnectionParameter retrieveConnectionParameters() {
final @ConnectionType.Type int connectionType = ConnectionType.TYPE_USB;

ConnectionParameter connParams;
switch (connectionType) {
case ConnectionType.TYPE_USB:
connParams = ConnectionParameter.newUsbConnection(57600, null, 0L);
break;

case ConnectionType.TYPE_UDP:
if (isUdpPingEnabled) {
connParams = ConnectionParameter.newUdpWithPingConnection(
14550,
"127.0.0.1",
14550,
"Hello".getBytes(),
ConnectionType.DEFAULT_UDP_PING_PERIOD,
null,
0L);
}
else{
connParams = ConnectionParameter.newUdpConnection(14550,
null, 0l);
}
break;

case ConnectionType.TYPE_TCP:
connParams = ConnectionParameter.newTcpConnection("192.168.40.100",
5763, null, 0L);
break;

case ConnectionType.TYPE_BLUETOOTH:
String btAddress = null;
if (TextUtils.isEmpty(btAddress)) {
connParams = null;
// TODO: Add behaviour to obtain Bluetooth Address
// startActivity(new Intent(getApplicationContext(),
// BluetoothDevicesActivity.class)
// .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

} else {
connParams = ConnectionParameter.newBluetoothConnection(btAddress,
null, 0L);
}
break;

default:
Log.e(TAG, "Unrecognized connection type: " + connectionType);
connParams = null;
break;
}

return connParams;
}
}

0 comments on commit 25850de

Please sign in to comment.