Data Transmission
Tips
- "Mobile App" refers to the Mobile App or DJI Pilot developed using MSDK.
- "Load Device" is the load device developed using PSDK.
- "Airborne Computer" is a computing device such as Manifold that runs the drone control program developed based on PSDK.
Overview
The payload device and the drone use the data transmission module to transmit control commands between PSDK and MSDK in a transparent way on the control command transmission channel; data information is transparently transmitted between PSDK and MSDK on the high-speed data transmission channel and user-defined data. Using the data transmission function, you can not only set the proportion of the bandwidth of the high-speed data transmission channel occupied by different types of data, but also check the status of different data transmission channels.
Description: The data transmission module of PSDK transmits data between load equipment, airborne computer and drone by transparent transmission, which supports users to design data transmission protocol according to actual use requirements, so that the payload developed based on PSDK can The device can realize complex communication with Mobile App or onboard computer. Compatibility Note: If the video stream format is set to DJI H264 format, the data streaming function will not be available, it is recommended to switch to SDK interconnection function use.
Basic Concepts
Classification of channels
According to the actual transmission data type and data function, the data transmission channel of PSDK can be divided into command signal transmission channel and high-speed data transmission channel, as shown in Figure 1. Signal transmission channel.
- Command signal transmission channel: strong reliability, dedicated to transmitting signals that require high reliability, such as control instructions and status information.
- High-speed data transmission channel: It has a large bandwidth and is mainly used to transmit data with a large amount of data and high real-time requirements, such as radar signals and point cloud data.
Figure 1. Signal transmission channel
Bandwidth of the channel
- Channel bandwidth: The amount of data that the data channel can transmit under theoretical state
- Real-time bandwidth: The theoretical maximum amount of data that can be transmitted by the data channel in the working state
- Actual bandwidth: The amount of data actually transmitted by the data channel
Channel bandwidth limit
The bandwidth limit of the data transmission channel refers to the maximum amount of data (byte/s) that the channel can transmit in unit time. Subject to the physical characteristics of the interface components and the actual use environment, the bandwidth of the command signal transmission channel and the high-speed data transmission channel can be divided into static bandwidth limit and dynamic bandwidth limit.
Static Bandwidth Limit
The static bandwidth limit refers to the fixed bandwidth size of the command signal transmission channel, which cannot be changed due to the physical properties and inherent electrical properties of the material. For detailed parameters of the static bandwidth of the data transmission channel, please refer to Table 1 Static bandwidth.
Channel Type | Transmission direction | M30 | M30T | M300 RTK | M350 RTK | Dock 1 with aircraft | Dock 2 with aircraft |
---|---|---|---|---|---|---|---|
Command signaling channel | Mobile App ➟ Payload | 4KB/s | - | ||||
Payload ➟ Mobile App | |||||||
Onboard Computer ➟ Payload | |||||||
Payload ➟ Onboard Computer | |||||||
Payload ➟ Cloud Server | - | 4 KB/s, with a maximum transmission frequency of 20 Hz | |||||
Cloud Server ➟ Payload | |||||||
High-speed data transmission channel | Load Device ➟ Mobile App | - | 4Mbps | - |
Dynamic bandwidth limit
Dynamic bandwidth limitation means that the high-speed data transmission channel is affected by factors such as link status and electromagnetic environment, and the maximum amount of data that the channel can transmit will change dynamically. Therefore, the high-speed data transmission channel The actual bandwidth should be lower than the *real-time bandwidth *.
Set bandwidth usage ratio
PSDK supports users to set the high-speed data transmission channel bandwidth usage ratio for different data types, so as to achieve precise control over the bandwidth occupation of high-speed data transmission channels. ** actual bandwidth ** of a certain type of data = the dynamic bandwidth of the high-speed data transmission channel ✕ Bandwidth allocation ratio.
Note: The dynamic bandwidth limit of the command signal transmission channel is equal to the static bandwidth limit.
flow control
The data transmission module of PSDK implements the flow control function by using the flow threshold and buffer to limit the amount of data sent by the load device to the Mobile App or onboard computer, as shown in Figure 2. Flow control.
The flow control process of PSDK is as follows:
- The load device transmits data information to the onboard computer or Mobile App through the data channel;
- When the data sent by the load device is greater than the threshold of the flow control function, the flow control function will temporarily store the data exceeding the flow threshold in the buffer;
- When the buffer is full of data, the data sent by the load device that exceeds the traffic threshold will be discarded;
- When the data channel is idle, the flow control module will send the data temporarily stored in the buffer.
Note:
- The flow control period of the data transmission module is 1s. In each control period, the amount of data transmitted by the load device should be less than the traffic threshold set by the user.
- The traffic threshold determines the maximum data that can be transmitted by the current data transmission channel. The threshold is jointly determined by factors such as static bandwidth limit, dynamic bandwidth limit, and the bandwidth occupancy ratio of high-speed data transmission channels.
Figure 2. Flow Control
Channel Status
The payload device developed with PSDK can obtain the following information:
- Information data transmission channel actual bandwidth before the user uses the flow control function;
- Information data transmission channelAfter the user uses the flow control functionactual bandwidth;
- The busy state of the channel: When the data of the corresponding channel is stored in the buffer or discarded, the channel state of the data transmission module is "busy".
Using the data transfer function
To use the data transmission function of PSDK, after creating the project file and completing the initialization of the PSDK, initialize the data transmission module, set the proportion of different types of data occupying the high-speed data transmission channel, and then realize the data transmission function and the function of monitoring the status of the data channel.
1. Data transfer function module initialization
Before using the "data transmission" function, you need to use the following code to initialize the data transmission function module to ensure that the load device can transmit data normally.
djiStat = DjiLowSpeedDataChannel_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("init data transmission module error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
2. Set the bandwidth usage ratio
After the user sets the proportion of high-speed data transmission channel bandwidth for different types of data by using the Mobile App developed based on MSDK or the drone control program developed using PSDK, the load device developed using PSDK calls the DjiHighSpeedDataChannel_SetBandwidthProportion
interface, It is possible to set the proportion of high-speed data transmission channel bandwidth occupied by data such as downloaded video streams.
djiStat = DjiHighSpeedDataChannel_SetBandwidthProportion(bandwidthProportionOfHighspeedChannel);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set data channel bandwidth width proportion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
Note:
- Only the Linux system supports the function of "Setting the bandwidth usage ratio of high-speed data transmission channel";
- When the flow control function is not used, the default ratio of video, data and media download type data to high-speed data transmission channel bandwidth is 33%, 33% and 34% respectively.
3. Implement data sending function
The load device developed with PSDK sends test data to the Mobile App or the onboard computer through the command signal transmission channel and the high-speed data transmission channel.
- Send control commands to the Mobile App The load device developed using PSDK sends control commands to the Mobile App on the command signal transmission channel.
channelAddress = DJI_CHANNEL_ADDRESS_MASTER_RC_APP;
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to mobile error.");
The Mobile App receives the control commands sent by the load device through the command signal transmission channel, as shown in Figure 3. APP data reception (1).
Figure 3. Mobile App data reception (1)
- Send data information to Mobile App The load device developed by PSDK sends data information to the Mobile App on the high-speed data transmission channel.
djiStat = DjiHighSpeedDataChannel_SendDataStreamData(dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to data stream error.");
The Mobile App receives the data information sent by the load device through the high-speed data transmission channel, as shown in Figure 4. Mobile App data reception (2).
Figure 4. Mobile App data reception (2)
- Send control commands to the onboard computer The payload device developed using PSDK sends control commands to the onboard computer on the command signal transmission channel.
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to onboard computer error.");
The on-board computer receives the control commands sent by the load equipment through the command signal transmission channel, as shown in Figure 5. On-board computer data reception.
Figure 5. Onboard computer data reception
4. Implement data receiving function
After constructing and registering the data receiving function, the load device developed using PSDK can receive the control commands sent from the mobile terminal device and the onboard computer through the command signal transmission channel.
1. Construct the callback function
Construct the callback function to get and print the control commands sent from the Mobile App and the onboard computer.
static T_DjiReturnCode ReceiveDataFromMobile(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from mobile: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveDataFromOnboardComputer(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from onboard computer: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
2. Register callback function
By registering the callback function, the payload device can receive control commands sent from the Mobile App and the onboard computer.
channelAddress = DJI_CHANNEL_ADDRESS_MASTER_RC_APP;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromMobile);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from mobile error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO2 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO3) {
channelAddress = DJI_CHANNEL_ADDRESS_EXTENSION_PORT;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromOnboardComputer);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from onboard coputer error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiHighSpeedDataChannel_SetBandwidthProportion(bandwidthProportionOfHighspeedChannel);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set data channel bandwidth width proportion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiHighSpeedDataChannel_GetDataStreamRemoteAddress(ipAddr, &port);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG("Get data stream remote address: %s, port: %d", ipAddr, port);
} else {
USER_LOG_ERROR("get data stream remote address error.");
}
} else if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_EXTENSION_PORT) {
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO1;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromPayload);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from payload NO1 error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_NONSUPPORT;
}
The load device receives the test data sent by the Mobile App and the onboard computer from the command signal transmission channel, as shown in Figure 6. Load device data reception.
Figure 6. Load device data reception
5. Monitor the status of the data transmission channel
Get the status of the data channel in the data transfer thread and print to the terminal.
- Get the status information of the command signal transmission channel Obtain the status of the command signal transmission channel that the load device sends control commands to the Mobile App and the onboard computer.
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"send to onboard computer state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
state.busyState);
} else {
USER_LOG_ERROR("get send to onboard computer channel state error.");
}
- Get status information on high-speed data transmission channel
Note: Only the load device developed based on Linux can obtain the status information of the high-speed data transmission channel.
djiStat = DjiHighSpeedDataChannel_GetDataStreamState(&state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"data stream state: realtimeBandwidthLimit: %d, realtimeBandwidthBeforeFlowController: %d, busyState: %d.",
state.realtimeBandwidthLimit, state.realtimeBandwidthBeforeFlowController, state.busyState);
} else {
USER_LOG_ERROR("get data stream state error.");
}
The high-speed data transmission channel status is shown in Figure 7. Data transmission.
Note: The real-time bandwidth statistics period is 1s.
Figure 7. Data transfer