当遥控器和无人机无法匹配时就需要进行遥控器对频。DJIRemoteController 中提供了遥控器对频的相关接口。

开始对频和停止对频

在进行对频前需要先调用isMultiDevicePairingSupported 方法判断遥控器是否支持多设备对频,多设备对频就是同时支持无人机对频和 RTK 基站对频。如果方法返回 NO , 则可以使用下面方法进行对频和停止对频:

  1. - (void)startPairingWithCompletion:(DJICompletionBlock)completion;
  2. - (void)stopPairingWithCompletion:(DJICompletionBlock)completion;

如果返回 YES ,则使用下面的方法:

  1. - (void)startMultiDevicePairingWithTarget:(DJIRCPairingDevice)target
  2. withCompletion:(DJICompletionBlock)completion;
  3. - (void)stopMultiDevicePairingWithCompletion:(DJICompletionBlock)completion;

DJIRCPairingDevice 定义了多设备对频的设备类型:

  1. typedef NS_ENUM (uint8_t, DJIRCPairingDevice){
  2. /**
  3. * The device to be paired with is an aircraft.
  4. */
  5. DJIRCPairingDeviceAircraft,
  6. /**
  7. * The device to be paired with is an RTK base station.
  8. */
  9. DJIRCPairingDeviceRTKBaseStation,
  10. /**
  11. * Unknown.
  12. */
  13. DJIRCPairingDeviceUnknown = 0xFF,
  14. };

获取对频状态

在对频的过程中,需要获取到对频的状态,我们可以通过 KeyManager 监听状态。 DJIRemoteControllerKey 中提供了 DJIRemoteControllerParamPairingState
DJIRemoteControllerParamMultiDevicePairingState

不过测试发现可以通过 DJIRemoteControllerParamPairingState 来获取单设备的对频状态,但是无法通过 DJIRemoteControllerParamMultiDevicePairingState 来获取多设备的对频状态,不过我们可以通过 DJIRemoteControllerDelegate 中的

  1. - (void)remoteController:(DJIRemoteController *)rc didUpdateMultiDevicePairingState:(DJIRCMultiDeviceAggregationState *)state;

代理方法,获取多设备对频的状态。

DJIRCMultiDeviceAggregationState 中定义了无人机和 RTK 基站的对频状态:

  1. @interface DJIRCMultiDeviceAggregationState : NSObject
  2. /**
  3. * The device state of aircraft.
  4. */
  5. @property (nonatomic, readonly) DJIRCMultiDeviceState aircraftState;
  6. /**
  7. * The device state of RTK base station.
  8. */
  9. @property (nonatomic, readonly) DJIRCMultiDeviceState RTKBaseStationState;
  10. @end

aircraftStateRTKBaseStationState 都是 DJIRCMultiDeviceState 类型,其定义如下:

  1. typedef NS_ENUM(uint8_t, DJIRCMultiDeviceState) {
  2. /**
  3. * The remote controller is unpaired with the device. This state is for both
  4. * aircraft and base station.
  5. */
  6. DJIRCMultiDeviceStateUnpaired = 0,
  7. /**
  8. * The remote controller is pairing with the device. This state is only for
  9. * aircraft.
  10. */
  11. DJIRCMultiDeviceStatePairing,
  12. /**
  13. * The remote controller is paired. This state is only for aircraft.
  14. */
  15. DJIRCMultiDeviceStatePaired,
  16. /**
  17. * The remote controller is paired with the device but the connection between the
  18. * device and the remote controller is broken. The remote controller already
  19. * remembers the device and the connection will receover automatically when it is
  20. * possible. This state is only for base station. Only Supported by Phantom 4 RTK.
  21. */
  22. DJIRCMultiDeviceStateDisconnected,
  23. /**
  24. * The remote controller is paired with the device and it is connected to the
  25. * device. This state is only for base station.
  26. */
  27. DJIRCMultiDeviceStateConnected,
  28. /**
  29. * Unknown.
  30. */
  31. DJIRCMultiDeviceStateUnknown = 0xFF,
  32. };

当我们使用 startMultiDevicePairingWithTarget:withCompletion: 进行 RTK 基站对频时,如果 RTKBaseStationState 的值是 DJIRCMultiDeviceStateConnected 则表示对频成功;当我们与飞机对频时,如果 aircraftState 的值是 DJIRCMultiDeviceStatePaired 则表示对频成功。