MSDK飞机注册回调方法分析
1
在开发中一直不太明白MSDK注册连接回调方法过程,今天从代码调试上确认下。结果仅提供参考,如果有错误,欢迎指正。先上结论导图
调试代码,重点看打印TAG的内容。
DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), new DJISDKManager.SDKManagerCallback() {
@Override
public void onRegister(DJIError djiError) {
if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
showToast("Register Success," + DJISDKManager.getInstance().getSDKVersion());
DJISDKManager.getInstance().startConnectionToProduct();
} else {
showToast("Register sdk fails, please check the bundle id and network connection!");
}
Log.v(TAG, djiError.getDeion());
}
@Override
public void onProductDisconnect() {
Log.d(TAG, "onProductDisconnect");
}
@Override
public void onProductConnect(BaseProduct baseProduct) {
// 参考了官方示例,来确认当前是不是只有遥控器连接,飞机未连接的状态,没有手持产品暂未进一步测试
// 实测如果baseProduct.toString()返回的是None,说明当前只有遥控器连接,且可以获取到遥控器示例来进行配对等操作
//官方代码: https://github.com/dji-sdk/Mobil ... inContent.java#L296
if(baseProduct != null){
Log.d(TAG, "onProductConnect:" + baseProduct.toString());
Aircraft aircraft = (Aircraft) baseProduct;
if (aircraft.getRemoteController() != null && aircraft.getRemoteController().isConnected()) {
Log.d("TAG", "RC is connected");
}
}
}
@Override
public void onProductChanged(BaseProduct baseProduct) {
if(baseProduct != null){
if(baseProduct.getModel() != null){
Log.d(TAG, "onProductChanged:" + baseProduct.getModel().getDisplayName());
}else{
Log.d(TAG, "onProductChanged:" + baseProduct.toString());
}
}
}
@Override
public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
BaseComponent newComponent) {
if (newComponent != null) {
newComponent.setComponentListener(new BaseComponent.ComponentListener() {
@Override
public void onConnectivityChange(boolean isConnected) {
Log.d(TAG, "onComponentConnectivityChanged: " + newComponent.toString() + " " + isConnected);
}
});
}
Log.d(TAG,
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
componentKey,
oldComponent,
newComponent));
}
@Override
public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
}
@Override
public void onDatabaseDownloadProgress(long l, long l1) {
}
});
调试过程,主要看TAG内容。
1.MSDK连接上遥控器,飞机未开机
2.第1步骤基础上,飞机开机且已经支持对频
3.第2步骤基础上,飞机关机,保持遥控器支持连接
4.第3步骤基础上,遥控器关机
|
|
|
|