NOTE This article is Machine-Translated. If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. DJI appreciates your support and attention.
The application developed based on DJI OSDK can communicate with the Mobile App and the Payload, for example, user sends commands to the drone from the Mobile App to control the payload, and onboard computer; the application could control the payload and sends status to the Mobile app; the payload could send the data to Mobile App and the application such as video streams or files, as shown in Figure 1.
Figure1. SDK Interconnection.
Using SDK Interconnection, developers could:
NOTE
- Client: According to the channel ID, connect to the Others, such as Mobile App.
- Server: Create channel and specify the channel type and ID, such as Payload.
The interconnection function of the DJI SDK can accurately specify the devices or modules that need to communicate on the drone through the device type and device slot.
NOTE In the SDK interconnection, only applications developed based on OSDK and payload developed based on PSDK can creat the channels, the Mobile APP based on MSDK only can receive the data that connect to the peer.
Device Slots: DJI's drones have powerful expansion capabilities. Developers can access more than three payload, the Mobile App has two method, and onboard computer has variety expansion methods. so different slots can be used to distinguish Mobile APP, payload, and onboard computer.
Channel ID: In order to help developers select and use communication channels with different channels on the same object, DJI SDK use the channel ID for distinguished. Developers can specify the ID for the created channel when creating the channel.
NOTE
- Only applications developed based on OSDK and payload developed based on PSDK could specify the channel ID for the created channel.
- Developers can specify the channel ID for the created channel, the maximum is 65535.
In order to help developer develop the powerful and reliable applications and devices without paying attention to the underlying working logic of the SDK interconnection, the DJI SDK provides powerful communication management mechanism:
NOTE In order to help developers to use the SDK interconnection, to distinguish it from existing interfaces, DJI MSDK uses "Pipeline" to indicate channel management function.
Mobile App developed based on MSDK could use the SDK Interconnection to establish the connect with the specified channel ID.
NOTE The Mobile App developed based on MSDK can only used as the client to establish a connection with the specified channel by the channel ID.
When creating the channel, developer need use the following interface to specify the channel transmission mode and the channel ID to establish the connection with the specified channel, and receive the transmitted data in the blocking callback manner.
- (void)connect:(uint16_t)Id pipelineType:(DJITransmissionControlType)transferType withCompletion:(void (^_Nullable)(DJIPipeline *_Nullable pipeline, NSError *_Nullable error))completion; |
void connect(int id, @NonNull TransmissionControlType transmissionType, @Nullable CommonCallbacks.CompletionCallback<PipelineError> callback); |
After connected the channel , the Mobile App developed based on MSDK uses the following interface to receive data sent by the peer.
- (NSData *)readData:(uint32_t)readLength error:(NSError **)error; |
int readData(byte[] buff, int length); |
After connected the channel, the mobile APP developed based on MSDK uses the following interface send data to the peer.
NOTE It is recommended that the size of the transmitted data wouldn't exceed 1KB.
- (int32_t)writeData:(NSData *)data error:(NSError **)error; |
int writeData(byte[] data); |
After the communication, please use the following interface to disconnect the connected channel.
NOTE
- After closing the channel, the mobile APP developed based on MSDK will clear the local cache.
- After close the channel, the DJI SDK will automatically destroy the created channel and release the system resources occupied.
- (void)disconnect:(uint16_t)Id withCompletion:(DJICompletionBlock)completion; |
void disconnect(int id, @Nullable CommonCallbacks.CompletionCallback<PipelineError> callback); |
Only the application which developed based on the OSDK execute on the Linux supports developer develop with SDK Interconnection and to be the client and server:
If the application developed based on OSDK deveoped with the SDK Interconnection, developer should initialize the SDK Interconnection module at first.
When the application developed based on OSDK as the client, the onboard computer can be regarded as a payload of the drone, so please use the PSDKManager
class in the DJI Payload SDK to initialize the SDK Interconnection.
ErrorCode::ErrorCodeType ret = vehicle->psdkManager->initPSDKModule( |
When the application developed based on the OSDK is used as the server, developer need initialize the Vehicle class first, and block the specified channel ID by calling the accept interface in vehicle->mopServer
.
#define TEST_MO_PIPELINE_ID 20 |
Only the application developed based on OSDK is used as the client, developer need obtain the pointer of the client, and use this pointer to create the channel to read and write the data.
MopClient *mopClient = NULL; |
Only the application developed based on OSDK is used as the client, developer need specify the channel ID and channel type to establish the connection with the specified channel.
#define TEST_OP_PIPELINE_ID 15 |
After created the channel, developer could receive data transmitted by the peer in the blocking callback (synchronous callback) on the channel.
Only the application developed based on OSDK as the client, please use the following interface to receive the data sent by the server.
MopErrCode mopRet; |
Only the application developed based on OSDK as the server, please use the following interface to receive the data sent by the client.
MopErrCode mopRet; |
After creating the channel, developers could send data to the peer.
Only the application developed based on OSDK as the client, please use the following interface send data to the peer.
MopErrCode mopRet; |
Only the application developed based on OSDK as the server, please use the following interface send data to the peer.
MopErrCode mopRet; |
After the communication, please use the following interface to disconnect the connected channel and release the system resources occupied by the channel.
Only the application developed based on OSDK as the client, please use the following interface to close the created channel.
if (mopClient->disconnect(TEST_OP_PIPELINE_ID) != MOP_PASSED) { |
Only the application developed based on OSDK as the server, please use the following interface to close the created channel.
if (vehicle->mopServer->close(TEST_MO_PIPELINE_ID) != MOP_PASSED) { |
Only the payload which developed based on the OSDK execute on the Linux supports developer develop with SDK Interconnection and to be the server.
NOTE The sample of the PSDK developed on the Manifold 2-C/G, with the network port, make ensure that the network port of the development board is avilible.
If the application developed based on PSDK deveoped with the SDK Interconnection, developer should initialize the SDK Interconnection module at first.
T_PsdkReturnCode PsdkMopChannel_Init(void); |
The payload developed based on PSDK creates channel will specified the channel's type: reliable or unreliable.
T_PsdkReturnCode PsdkMopChannel_Create(T_PsdkMopChannelHandle *channelHandle, E_PsdkMopChannelTransType trans); |
The payload developed based on PSDK as the server establish the connection with the peer, need specified the channel ID for the client to bind. To establishment the connection with multiple clients at the same time, PSDK provides the handle outChannelHandle.
T_PsdkReturnCode PsdkMopChannel_Bind(T_PsdkMopChannelHandle channelHandle, uint16_t channelId); |
T_PsdkReturnCode PsdkMopChannel_Accept(T_PsdkMopChannelHandle channelHandle, T_PsdkMopChannelHandle *outChannelHandle); |
NOTE This interface is the blocking interface. When the payload as the server to establishment the connection with multiple clients at the same time, please call this interface in a separate thread.
After created the channel, developer could receive the data sent by the peer。
T_PsdkReturnCode PsdkMopChannel_RecvData(T_PsdkMopChannelHandle channelHandle, uint8_t *data, uint32_t len, uint32_t *realLen); |
After created the channel, developer could send the data to the peer.
T_PsdkReturnCode PsdkMopChannel_SendData(T_PsdkMopChannelHandle channelHandle, uint8_t *data, uint32_t len, uint32_t *realLen); |
After the communication, please use the following interface to disconnect the connected channel and release the system resources occupied by the channel.
T_PsdkReturnCode PsdkMopChannel_Close(T_PsdkMopChannelHandle channelHandle); |
T_PsdkReturnCode PsdkMopChannel_Destroy(T_PsdkMopChannelHandle channelHandle); |