7
7
import android .os .SystemClock ;
8
8
import android .util .Log ;
9
9
10
- import com .MAVLink .Messages .MAVLinkMessage ;
11
10
import com .o3dr .android .client .interfaces .DroneListener ;
12
11
import com .o3dr .services .android .lib .coordinate .LatLong ;
13
12
import com .o3dr .services .android .lib .drone .attribute .AttributeEvent ;
17
16
import com .o3dr .services .android .lib .drone .mission .Mission ;
18
17
import com .o3dr .services .android .lib .drone .mission .MissionItemType ;
19
18
import com .o3dr .services .android .lib .drone .mission .item .MissionItem ;
20
- import com .o3dr .services .android .lib .drone .mission .item .complex .StructureScanner ;
21
- import com .o3dr .services .android .lib .drone .mission .item .complex .Survey ;
22
19
import com .o3dr .services .android .lib .drone .property .Altitude ;
23
20
import com .o3dr .services .android .lib .drone .property .Attitude ;
24
21
import com .o3dr .services .android .lib .drone .property .Battery ;
@@ -65,6 +62,7 @@ public class Drone {
65
62
private final Handler handler ;
66
63
private final ServiceManager serviceMgr ;
67
64
private final DroneObserver droneObserver ;
65
+ private final DroneApiListener apiListener ;
68
66
private IDroneApi droneApi ;
69
67
70
68
private ConnectionParameter connectionParameter ;
@@ -78,6 +76,7 @@ public class Drone {
78
76
public Drone (ServiceManager serviceManager , Handler handler ) {
79
77
this .handler = handler ;
80
78
this .serviceMgr = serviceManager ;
79
+ this .apiListener = new DroneApiListener (this );
81
80
this .droneObserver = new DroneObserver (this );
82
81
}
83
82
@@ -89,7 +88,8 @@ public void start() {
89
88
return ;
90
89
91
90
try {
92
- this .droneApi = serviceMgr .get3drServices ().acquireDroneApi (serviceMgr .getApplicationId ());
91
+ this .droneApi = serviceMgr .get3drServices ().registerDroneApi (this .apiListener ,
92
+ serviceMgr .getApplicationId ());
93
93
} catch (RemoteException e ) {
94
94
throw new IllegalStateException ("Unable to retrieve a valid drone handle." );
95
95
}
@@ -178,7 +178,7 @@ public long getFlightTime() {
178
178
}
179
179
180
180
public Gps getGps () {
181
- Gps gps = getAttribute (AttributeType .GPS , Gps .class .getClassLoader ());
181
+ Gps gps = getAttribute (AttributeType .GPS , Gps .class .getClassLoader ());
182
182
return gps == null ? new Gps () : gps ;
183
183
}
184
184
@@ -205,7 +205,7 @@ private <T extends Parcelable> T getAttribute(String type, ClassLoader classLoad
205
205
T attribute = null ;
206
206
if (isStarted ()) {
207
207
Bundle carrier = getAttribute (type );
208
- if (carrier != null ) {
208
+ if (carrier != null ) {
209
209
carrier .setClassLoader (classLoader );
210
210
attribute = carrier .getParcelable (type );
211
211
}
@@ -311,12 +311,12 @@ public ConnectionParameter getConnectionParameter() {
311
311
}
312
312
313
313
public <T extends MissionItem > void buildComplexMissionItem (MissionItem .ComplexItem <T >
314
- complexItem ){
315
- if (isStarted ()){
316
- try {
314
+ complexItem ) {
315
+ if (isStarted ()) {
316
+ try {
317
317
T missionItem = (T ) complexItem ;
318
318
Bundle payload = missionItem .getType ().storeMissionItem (missionItem );
319
- if (payload == null )
319
+ if (payload == null )
320
320
return ;
321
321
322
322
droneApi .buildComplexMissionItem (payload );
@@ -345,8 +345,8 @@ private void addAttributesObserver(IObserver observer) {
345
345
}
346
346
}
347
347
348
- public void addMavlinkObserver (MavlinkObserver observer ){
349
- if (isStarted ()){
348
+ public void addMavlinkObserver (MavlinkObserver observer ) {
349
+ if (isStarted ()) {
350
350
try {
351
351
droneApi .addMavlinkObserver (observer );
352
352
} catch (RemoteException e ) {
@@ -355,8 +355,8 @@ public void addMavlinkObserver(MavlinkObserver observer){
355
355
}
356
356
}
357
357
358
- public void removeMavlinkObserver (MavlinkObserver observer ){
359
- if (isStarted ()){
358
+ public void removeMavlinkObserver (MavlinkObserver observer ) {
359
+ if (isStarted ()) {
360
360
try {
361
361
droneApi .removeMavlinkObserver (observer );
362
362
} catch (RemoteException e ) {
@@ -508,8 +508,8 @@ public void sendGuidedPoint(LatLong point, boolean force) {
508
508
}
509
509
}
510
510
511
- public void sendMavlinkMessage (MavlinkMessageWrapper messageWrapper ){
512
- if (messageWrapper != null && isStarted ()){
511
+ public void sendMavlinkMessage (MavlinkMessageWrapper messageWrapper ) {
512
+ if (messageWrapper != null && isStarted ()) {
513
513
try {
514
514
droneApi .sendMavlinkMessage (messageWrapper );
515
515
} catch (RemoteException e ) {
0 commit comments