SDK Interconnection

2024-08-23
No Rating

Overview

The application developed based on DJI OSDK can communicate with the Mobile App developed based on MSDK and the payload developed based on PSDK. For example, the user send a control command to the drone from Mobile App developed based on MSDK, the computer performs the specified tasks, the application program developed based on OSDK controls the load device to perform the required actions and sends status information to the mobile terminal APP developed based on MSDK. The developed application sends data such as video stream or file, as shown in Figure 1. SDK interconnection.

Figure 1. SDK interconnection

Using the SDK interconnection function, developers can:

  • Dynamically create the required transmission channels on demand
  • According to business needs, create a channel to transmit the data of the specified business
  • Full-duplex communication, data sending and receiving synchronization

Basic Concepts

This article refers to

  • Client: According to the specified channel ID, the end that initiates the channel connection, such as the Mobile App developed based on MSDK.
  • Server side: According to the actual needs of users, create a channel and specify one side of the channel type ID, such as an application developed based on OSDK.

Transfer Method

  • Reliable transmission

    To ensure reliable transmission between applications and devices developed based on different SDKs, DJI SDK provides developers with a reliable transmission method. In this method, DJI SDK uses packet loss retransmission, timeout retransmission, and error checking. and other mechanisms to ensure that the data sent and received between different SDKs is accurate and reliable.

    • Reliable data: Both parties who transmit data in a reliable transmission method need to use a verification function to verify the correctness of the transmitted data when sending and receiving data. At the same time, DJI SDK uses encryption algorithms to encrypt the transmitted data to ensure the security of the transmitted data. .
    • Reliable transmission: The data transmission function of the DJI SDK has a timer and ACK mechanism, which can retransmit the data after the data transmission times out to ensure that the peer can receive the sent data normally and prevent accidental loss of data; in addition, with reliable When transmitting data by means of transmission, the sender will set the number of the data to be sent, and the receiver can rearrange the received out-of-order data based on the data number to ensure the reliability of data transmission.
  • Unreliable transmission

    When data is transmitted in an unreliable transmission method, data can be transmitted at a faster speed between applications and devices developed using different SDKs, but reliable transmission of data cannot be guaranteed.

Object Specification

The interconnection function of the DJI SDK can accurately specify the device or module that needs to be communicated on the drone through the device type and device slot.

  • Device type: In order to facilitate developers to identify the identity and type of the peer end and better distinguish the objects of data transmission, the data transmission function provides three device types: MSDK, OSDK and PSDK according to the DJI SDK.

Note: In the SDK interconnection function, only applications developed based on OSDK and load devices developed based on PSDK can open channels to the Mobile App developed based on MSDK to connect and use, or connect to each other to transmit data .

  • Device slots: DJI's drones have powerful expansion capabilities. Developers can access three payload devices, dual controllers, and onboard computers in various expansion methods. Therefore, different slots can be used to distinguish mobile terminals. The current location of the APP, payload and onboard computer.

  • Channel ID: In order to facilitate developers to select and use communication channels and distinguish different channels on the same device, DJI SDK provides the function of setting channel IDs for the interconnection function. When creating channels, developers can specify IDs for the created channels.

Note:

  • Only applications developed based on OSDK and payload devices developed based on PSDK need to specify a channel ID for the created channel when using the data transmission function.
  • Developers can specify a channel ID for the created channel when creating a channel according to actual usage requirements, and a maximum of 65535 channels can be set.

Channel Management

In order to facilitate developers to quickly develop powerful and reliable applications and devices without paying attention to the underlying working logic of the SDK interconnection function, the DJI SDK provides the interconnection function with powerful communication management capabilities:

  • Link management: Manage link access, shutdown, destruction, reconnection and congestion management, etc.
  • Data management: data forwarding, data reading and writing, flow control, data verification, out-of-order rearrangement and packet loss retransmission, etc.

Note: In order to facilitate developers to use the SDK interconnection function and distinguish it from the existing interfaces, DJI MSDK uses "Pipeline" to represent the channel management function.

Channel Bandwidth

  • The maximum rate of MSDK upstream (sending data to server) reliable/unreliable transmission is generally 24-48 Kbps. The upper limit of bandwidth depends on the actual wireless link conditions.
  • The maximum rate of MSDK downstream (receiving data from server) reliable transmission is 16Mbps. The maximum unreliable transmission rate is 20Mbps.

**Note: ** The wireless link limits the channel bandwidth between MSDK and the server (OSDK/PSDK). In the case of a long distance, the upper limit of the bandwidth will decrease as the signal drops. Please refer to the actual test results.

  • For data transmission between OSDK and PSDK, the maximum reliable transmission rate is 24Mbps, and the maximum unreliable transmission rate is 30Mps.

Using the SDK Interconnection Function (MSDK Side)

When the Mobile App developed with MSDK uses the SDK interconnection function, it can establish a connection with the specified channel according to the user's usage requirements to realize data reception and transmission; when the SDK interconnection function is not required, the connected channel can be disconnected .

Note: The Mobile App developed based on MSDK can only be used as a client to establish a connection with the specified channel through the channel ID.

1. Channel Connection

When the channel is connected, please use the following interface to specify the channel transmission mode and the channel ID to be connected to establish a connection with the specified channel, and receive the transmitted data in the way of blocking callback.

  • iOS
- (void)connect:(uint16_t)Id pipelineType:(DJITransmissionControlType)transferType withCompletion:(void (^_Nullable)(DJIPipeline *_Nullable pipeline, NSError *_Nullable error))completion;
  • Java
void connect(int id, @NonNull TransmissionControlType transmissionType, @Nullable CommonCallbacks.CompletionCallback<PipelineError> callback);

2. Data Reception

After the channel is connected, the Mobile App developed based on MSDK uses the following interface to receive the data sent by the peer.

  • iOS
- (NSData *)readData:(uint32_t)readLength error:(NSError **)error;
  • Java
int readData(byte[] buff, int length);

3. Data Sending

After the channel is connected, the Mobile App developed based on MSDK uses the following interface to send data to the peer.

Note: In order to achieve good data transmission effect, it is recommended that the data transmitted each time does not exceed 1KB.

  • iOS
- (int32_t)writeData:(NSData *)data error:(NSError **)error;
  • Java
int writeData(byte[] data);

4. Close the Channel

After the communication ends, please use the following interface to disconnect the connected channel.

Note:

  • After performing the channel closing operation, the Mobile App developed based on MSDK will clear the local cache information.
  • After the channel is closed, DJI SDK will automatically destroy the created channel and release the system resources occupied by the channel.
  • iOS
- (void)disconnect:(uint16_t)Id withCompletion:(DJICompletionBlock)completion;
  • Java
void disconnect(int id, @Nullable CommonCallbacks.CompletionCallback<PipelineError> callback);

Use the SDK Interconnection Function (OSDK Side)

Description: Using MOP function based on OSDK 4.1.0

Only the onboard computer using the Linux platform supports developers to develop interconnection functions based on OSDK. Applications developed based on OSDK can be used as both client side and server side:

  • As a client, the user can establish a connection with the specified channel through the channel ID.
  • As a server, an application developed based on OSDK can create a channel and specify a channel ID according to the user's needs. Only after the server and the client are connected, the server can read and write data.

1. Initialization

If an application developed based on OSDK needs to use the SDK interconnection function, the SDK interconnection module needs to be initialized first.

as Client

When an application developed based on OSDK is used as the client, the onboard computer can be regarded as the payload device of the drone. Therefore, please use the PSDKManager class in the DJI Payload SDK to initialize the SDK interconnection function.

ErrorCode::ErrorCodeType ret = vehicle->psdkManager->initPSDKModule(
PAYLOAD_INDEX_0, "Main_psdk_device");
if (ret != ErrorCode::SysCommonErr::Success) {
DERROR("Init PSDK module Main_psdk_device failed.");
ErrorCode::printErrorCodeMsg(ret);
}

as Server Side

When an application developed based on OSDK is used as a server, the Vehicle class needs to be initialized first, and the specified channel ID is blocked by calling the accept interface in vehicle->mopServer.

#define TEST_MO_PIPELINE_ID 20

......
if (vehicle->mopServer->accept((PipelineID)TEST_MO_PIPELINE_ID, UNRELIABLE, MO_Pipeline) != MOP_PASSED) {
DERROR("MOP Pipeline accept failed");
return -1;
} else {
DSTATUS("Accept to mop pipeline id(%d) successfully", TEST_MO_PIPELINE_ID);
}
......

2. Get a Pointer to the Client Object

Only when the application developed based on OSDK is used as the client, you need to obtain the pointer of the client using the SDK interconnection function, and use the pointer to create a data transmission channel or read and write the data to be transmitted.

MopClient *mopClient = NULL;
ret = vehicle->psdkManager->getMopClient(PAYLOAD_INDEX_0, mopClient);
if (ret != ErrorCode::SysCommonErr::Success) {
DERROR("Get MOP client object for_psdk_device failed.");
ErrorCode::printErrorCodeMsg(ret);
return NULL;
}
 
if (!mopClient) {
DERROR("Get MOP client object is a null value.");
return NULL;
}

3. Channel Connection

Only when an application developed based on OSDK is used as a client, you need to specify the channel ID and channel type to be connected, and establish a connection with the specified channel.

#define TEST_OP_PIPELINE_ID 15

MopPipeline *OP_Pipeline = NULL;
if ((mopClient->connect(TEST_OP_PIPELINE_ID, RELIABLE, OP_Pipeline)
!= MOP_PASSED) || (OP_Pipeline == NULL)) {
DERROR("MOP Pipeline connect failed");
return NULL;
} else {
DSTATUS("Connect to mop pipeline id(%d) successfully", TEST_OP_PIPELINE_ID);
}

4. Data Reception

After the channel is created, the developer can receive the data transmitted by the peer end in the way of blocking callback (synchronous callback) on the channel.

Client Receives Data

Only when the application developed based on OSDK is used as the client, please use the following interface to receive the data sent by the server.

MopErrCode mopRet;
......
uint8_t recvBuf[1024];
MopPipeline::DataPackType readPack = {recvBuf, 1024};
mopRet = OP_Pipeline->recvData(readPack, &readPack.length);
......

Server Receives Data

Only when the application developed based on OSDK is used as the server, please use the following interface to read the data sent by the client.

MopErrCode mopRet;
......
uint8_t recvBuf[1024];
MopPipeline::DataPackType readPack = {recvBuf, 1024};
mopRet = MO_Pipeline->recvData(readPack, &readPack.length);
......

5. Data Sending

After the channel is created, the developer can send data to the peer on the channel.

Client Sends Data

Only when the application developed based on OSDK is used as the client, please use the following interface to send data to the server.

MopErrCode mopRet;
uint8_t sendBuf[1024];
......
MopPipeline::DataPackType reqPack = {sendBuf, 1024};
mopRet = OP_Pipeline->sendData(reqPack, &reqPack.length);
......

Server-side Sending Data

Only when the application developed based on OSDK is used as the server, please use the following interface to send data to the client.

MopErrCode mopRet;
uint8_t sendBuf[1024];
......
MopPipeline::DataPackType reqPack = {sendBuf, 1024};
mopRet = MO_Pipeline->sendData(reqPack, &reqPack.length);
......

6. Close the Channel

After the communication ends, please use the following interface to disconnect from the specified channel and release the system resources occupied by the channel.

Client Closes the Channel

Only when the application developed based on OSDK is used as the client, please use the following interface to close the created channel.

if (mopClient->disconnect(TEST_OP_PIPELINE_ID) != MOP_PASSED) {
DERROR("MOP Pipeline disconnect pipeline(%d) failed", TEST_OP_PIPELINE_ID);
} else {
DSTATUS("Disconnect mop pipeline id(%d) successfully", TEST_OP_PIPELINE_ID);
}

The Server Side Closes the Channel

Only when the application developed based on OSDK is used as the server side, please use the following interface to close the created channel.

if (vehicle->mopServer->close(TEST_MO_PIPELINE_ID) != MOP_PASSED) {
DERROR("MOP Pipeline disconnect pipeline(%d) failed", TEST_MO_PIPELINE_ID);
} else {
DSTATUS("Disconnect mop pipeline id(%d) successfully", TEST_MO_PIPELINE_ID);
}

Use the SDK Interconnection Function (PSDK Side)

Only load devices developed on the Linux platform support developers to develop interconnection functions based on PSDK. The application program developed based on PSDK can only be used as the server side. It can create a channel and specify the channel ID according to the user's usage requirements. Only after the connection with the client is established, the data can be read and written.

1. SDK Interconnection Function Initialization

If the load device developed based on PSDK needs to use the SDK interconnection function, the SDK interconnection module needs to be initialized first.

T_DjiReturnCode DjiMopChannel_Init(void);

2. Create a Channel

The load device developed based on PSDK creates corresponding channel types according to user-specified requirements: reliable transmission and unreliable transmission.

T_DjiReturnCode DjiMopChannel_Create(T_DjiMopChannelHandle *channelHandle, E_DjiMopChannelTransType transType);

3. Channel Connection

The load device developed based on PSDK is used as the server side. When establishing a connection with the peer end, the ID of the channel needs to be specified for the client to bind. In order to facilitate the establishment of connections with multiple clients at the same time, PSDK provides the outChannelHandle handle.

  1. Channel binding The payload device developed based on PSDK communicates with the client through the specified ID.
T_DjiReturnCode DjiMopChannel_Bind(T_DjiMopChannelHandle channelHandle,
uint16_t channelId);
  1. Accept the connection The load device developed based on PSDK accepts the connection request sent by the peer through the following interface.
T_DjiReturnCode DjiMopChannel_Accept(T_DjiMopChannelHandle channelHandle,
T_DjiMopChannelHandle *outChannelHandle);

Note: This interface is a blocking interface. When the PSDK-based load device is used as the server side, in order to be able to establish connections with multiple clients at the same time, please call this interface in a separate thread.

4. Data Reception

After the channel is created, the developer can receive the data transmitted by the peer on the channel.

T_DjiReturnCode DjiMopChannel_RecvData(T_DjiMopChannelHandle channelHandle,
uint8_t *data,
uint32_t len,
uint32_t *realLen);

5. Data Sending

After the channel is created, the developer can send data to the peer on the channel.

T_DjiReturnCode DjiMopChannel_SendData(T_DjiMopChannelHandle channelHandle,
uint8_t *data,
uint32_t len,
uint32_t *realLen);

6. Close the Channel

After the communication ends, please use the following interface to disconnect from the specified channel and release the system resources occupied by the channel.

  • close the channel Call the following interface to close the created channel. After closing, the channel will not be able to send and receive data, but it can re-establish connection with other channels.
T_DjiReturnCode DjiMopChannel_Close(T_DjiMopChannelHandle channelHandle);
  • Destroy the channel Call the following interface to destroy the specified channel.
T_DjiReturnCode DjiMopChannel_Destroy(T_DjiMopChannelHandle channelHandle);
If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.