当遥控器和无人机无法匹配时就需要进行遥控器对频。DJIRemoteController  中提供了遥控器对频的相关接口。
开始对频和停止对频
在进行对频前需要先调用isMultiDevicePairingSupported 方法判断遥控器是否支持多设备对频,多设备对频就是同时支持无人机对频和 RTK 基站对频。如果方法返回 NO , 则可以使用下面方法进行对频和停止对频:
- (void)startPairingWithCompletion:(DJICompletionBlock)completion;- (void)stopPairingWithCompletion:(DJICompletionBlock)completion;
如果返回 YES ,则使用下面的方法:
- (void)startMultiDevicePairingWithTarget:(DJIRCPairingDevice)targetwithCompletion:(DJICompletionBlock)completion;- (void)stopMultiDevicePairingWithCompletion:(DJICompletionBlock)completion;
DJIRCPairingDevice 定义了多设备对频的设备类型:
typedef NS_ENUM (uint8_t, DJIRCPairingDevice){/*** The device to be paired with is an aircraft.*/DJIRCPairingDeviceAircraft,/*** The device to be paired with is an RTK base station.*/DJIRCPairingDeviceRTKBaseStation,/*** Unknown.*/DJIRCPairingDeviceUnknown = 0xFF,};
获取对频状态
在对频的过程中,需要获取到对频的状态,我们可以通过 KeyManager 监听状态。 DJIRemoteControllerKey 中提供了 DJIRemoteControllerParamPairingState
和 DJIRemoteControllerParamMultiDevicePairingState。
不过测试发现可以通过 DJIRemoteControllerParamPairingState 来获取单设备的对频状态,但是无法通过 DJIRemoteControllerParamMultiDevicePairingState 来获取多设备的对频状态,不过我们可以通过 DJIRemoteControllerDelegate 中的 
- (void)remoteController:(DJIRemoteController *)rc didUpdateMultiDevicePairingState:(DJIRCMultiDeviceAggregationState *)state;
代理方法,获取多设备对频的状态。
 DJIRCMultiDeviceAggregationState  中定义了无人机和 RTK 基站的对频状态:
@interface DJIRCMultiDeviceAggregationState : NSObject/*** The device state of aircraft.*/@property (nonatomic, readonly) DJIRCMultiDeviceState aircraftState;/*** The device state of RTK base station.*/@property (nonatomic, readonly) DJIRCMultiDeviceState RTKBaseStationState;@end
aircraftState 和 RTKBaseStationState  都是 DJIRCMultiDeviceState 类型,其定义如下:
typedef NS_ENUM(uint8_t, DJIRCMultiDeviceState) {/*** The remote controller is unpaired with the device. This state is for both* aircraft and base station.*/DJIRCMultiDeviceStateUnpaired = 0,/*** The remote controller is pairing with the device. This state is only for* aircraft.*/DJIRCMultiDeviceStatePairing,/*** The remote controller is paired. This state is only for aircraft.*/DJIRCMultiDeviceStatePaired,/*** The remote controller is paired with the device but the connection between the* device and the remote controller is broken. The remote controller already* remembers the device and the connection will receover automatically when it is* possible. This state is only for base station. Only Supported by Phantom 4 RTK.*/DJIRCMultiDeviceStateDisconnected,/*** The remote controller is paired with the device and it is connected to the* device. This state is only for base station.*/DJIRCMultiDeviceStateConnected,/*** Unknown.*/DJIRCMultiDeviceStateUnknown = 0xFF,};
当我们使用 startMultiDevicePairingWithTarget:withCompletion: 进行 RTK 基站对频时,如果 RTKBaseStationState 的值是 DJIRCMultiDeviceStateConnected 则表示对频成功;当我们与飞机对频时,如果 aircraftState 的值是 DJIRCMultiDeviceStatePaired 则表示对频成功。
