The Protocal Frame is the smallest unit for transmission. It contains the Header, Data and the Tail as follows:
|<---------------------Header-------------------------->|<--Data-->|<--Tail-->|
|SOF|LEN|VER|SESSION|ACK|RES0|PADDING|ENC|RES1|SEQ|CRC16| DATA | CRC32 |
Field | Index (byte) | Size (bit) | Description |
---|---|---|---|
SOF | 0 | 8 | starting byte, fixed to be 0xAA |
LEN | 1 | 10 | len of frame |
VER | 6 | version of the frame header, set to be 0 | |
SESSION | 3 | 5 | session ID |
ACK | 1 | frame type
|
|
RES0 | 2 | reserved, fixed to be 0 | |
PADDING | 4 | 5 | len of padding data used by the Data encryption |
ENC | 3 | encryption type
|
|
RES1 | 5 | 24 | reserved, fixed to be 0 |
SEQ | 8 | 16 | frame sequence num |
CRC16 | 10 | 16 | CRC16 frame header checksum |
DATA | 12 | variable size | frame data |
CRC32 | variable size | 32 | CRC32 whole frame checksum |
Note: When encryption is enabled, the order of operation sequence should be
encrypt DATA field
->update LEN and PADDING fields in frame header
->calculate CRC16
->calculate CRC32
Note2: The byte content inside field is in LSB at left order. i.e. an 3th byte(SESSION+ACK+RES0) with value 0b01000000, the first 5 bits 01000 means value 2. Don't get lost when you're trying to print out the raw data of protocol.
There are two types of frames.
Frame Type | Data Type | Transmission Direction | Content |
---|---|---|---|
CMD frame | CMD frame data | Onboard Device <=> N1 Autopilot | flight control related CMDs |
ACK frame | ACK frame data | N1 Autopilot <=> Onboard Device | ACK related data |
|<------CMD frame data------>|
| CMD SET | CMD ID | CMD VAL |
Field | Index (byte) | Size (byte) |
---|---|---|
CMD SET | 0 | 1 |
CMD ID | 1 | 1 |
CMD VAL | 2 | vary by CMDs |
|<-ACK frame data->|
| ACK VAL |
Field | Index (byte) | Size (byte) |
---|---|---|
ACK VAL | 0 | vary by ACKs |
SEQ field in ACK frame is the same as the one in corresponding CMD frame. Developers can use the SEQ field of the ACK frame to match the corresponding CMD frame.
The session mechanism has been used in order to prevent the exceptions such as package loss. 3 kinds of session have been introduced:
Type | SESSION | Description |
---|---|---|
0 | 0 | Sender doesn't need ACKs. |
1 | 1 | Sender needs ACKs but can be tolerated. |
2 | 2-31 | Sender needs ACKs.* |
Note: Type 1 and Type 2 can ONLY be applied to the CMDs which have ACKs.
*Since type 2 is designed to be reliable. Developers should implement the package loss & resending mechinism based on the current SEQ and SESSION fields. When package loss is found from the sender, the sender can send the CMD frame again with the same SEQ and SESSION lost previously to retrieve back the ACK frame.
DJI designs encryption interface in communication between Onboard Device and autopilot, considering it is possible that developer implement the communication with unsafe channel, for example various types of wireless transparent transmission module.
AES encrypting is designed only for data part of a frame. And developers can encrypt their own data with a key which is despatched when they register the APP ID, and encryption function in DJI_LIB
.
Due to encryption process, data need to be aligned into blocks and each one contains 16 bytes. 'PADDING' in frame header is the length of additional data generated in this progress. Also 'LEN' need to be caclulated again, and 'ENC' need to be set to '1'. For more details about encryption algorithm, please refer to sdk_encrypt_interface
in DJI_Pro_Codec.cpp
.
On the other hand, there is no need to encrypt data, when developers use a serial cable to connect Onboard Device and autopilot. In this case, just set 'ENC' to '0'.
The CMDs have three different sets
CMD Set | CMD ID | Transmission Direction | Description |
---|---|---|---|
Activation | 0x00 | Onboard Device ==> N1 Autopilot | activation related CMDs |
Flight Control | 0x01 | Onboard Device ==> N1 Autopilot | flight control related CMDs |
Push Data | 0x02 | N1 Autopilot ==> Onboard Device | push data related CMDs |
Each CMD Set contains some CMD IDs for different operations.
The execution of different CMDs needs an corresponding Authorization Level. A CMD will not be executed when the current Authorization Level granted is lower.
Levels | Description |
---|---|
0 | Activation related |
1 | Gimbal and Camera control related |
2 | Flight Control related |
Note: The Authorization Level of the N1 Autopilot can be changed by the 'Activation' CMD. The init level is set to be 0.
Function Index
CMD Set | CMD ID | Function | Level Required |
---|---|---|---|
0x00 Activation CMD Set |
0x00 | Get Protocal Version | 0 |
0x01 | Activation | 0 | |
0x01 Control CMD Set |
0x00 | Obtain/Release Control Authorization | 2 |
0x01 | Switch Flight Mode | 2 | |
0x02 | Request Switch Result | 2 | |
0x03 | Movement Control | 2 | |
0x1A | Gimbal Control in Rate | 1 | |
0x1B | Gimbal Control in Position | 1 | |
0x20 | Take Photo | 1 | |
0x21 | Start Recording Video | 1 | |
0x22 | Stop Recording Video | 1 | |
0x02 Push Data CMD Set |
0x00 | Flight Data | 0 |
0x01 | Lost of Flight Control | 0 |
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | arbitrary num |
ACK Val | 0 | 2 | Return Code
|
2 | 4 | The CRC val of the protocal version | |
6 | 32 | protocal version |
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 4 | app_id, app unique identifer |
4 | 4 | api_level, authorization level | |
8 | 4 | Fixed value, 0x02030A00 | |
12 | 32 | Fixed string, "12345678901234567890123456789012" | |
ACK Val | 0 | 2 | Return Code:
|
Please make sure the following conditions have been met:
- The 'enable API control' box is checked in the N1 assistant software.
- The IOC mode inside the DJI GO APP is off.
- The mode selection bar of the remote controller is placed at the F position. (After aircraft powered-up, switch the mode selector to A or P and then turn to F )
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 |
0x01:request to obtain control authorization 0x00:request to release control authorization |
ACK Val | 0 | 2 | Return Code
|
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | CMD Sequence Number |
1 | 1 |
0x01 : return to home(RTH) 0x04 : auto take off 0x06 : auto landing |
|
ACK Val | 0 | 2 | Return Code
|
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | CMD Sequence Number |
ACK Val | 0 | 2 | Return Code
|
For more info about Movement Control, please refer to Control mode byte part in Appendix.
Data Type | Offset (byte) | Size (byte) | Data Type | Description |
---|---|---|---|---|
CMD Val | 0 | 1 | --- | Control mode byte |
1 | 4 | float32 | Roll or X-axis control value | |
5 | 4 | float32 | Pitch or Y-axis control value | |
9 | 4 | float32 | Throttle or Z-axis control value | |
13 | 4 | float32 | Yaw control value | |
ACK Val | --- | --- | --- | N/A |
Data Type | Offset (byte) | Size (byte) | Data Type | Description |
---|---|---|---|---|
CMD Val | 0 | 2 | int16_t | Yaw in rate unit 0.1º/s, input range[-1800,1800] |
2 | 2 | int16_t | Roll in rate unit 0.1º/s, input range[-1800,1800] |
|
4 | 2 | int16_t | Pitch in rate unit 0.1º/s, input range[-1800,1800] |
|
6 | 1 | --- | Fixed value, 0x80 | |
ACK Val | --- | --- | --- | N/A |
Data Type | Offset (byte) | Size (byte) | Data Type | Description |
---|---|---|---|---|
CMD Val | 0 | 2 | int16_t | Yaw angle unit 0.1º, input range [-3200,3200] |
2 | 2 | int16_t | Roll angle unit 0.1º, input range [-350,350] |
|
4 | 2 | int16_t | Pitch angle unit 0.1º, input range [-900,300] |
|
6 | 1 | --- | control flag byte
|
|
7 | 1 | uint8_t | Command completion time unit 0.1s, for example 20 means gimbal will reach the commended postition in 2 seconds rotate rate beyond 400º/s is not recommand |
|
ACK Val | --- | --- | --- | N/A |
The relationship bewteen the angle reference in absolute control mode and gimbal mode configuration in DJI Go App
Gimbal Mode | Roll | Pitch | Yaw | Gimbal Follow UAV's nose |
---|---|---|---|---|
Follow | Ground | Ground | Body | Y |
FPV | N/A | Ground | N/A | Y |
Free | Ground | Ground | Ground | N |
Note: Rotating 90 degree in pitch
direction will cause gimbal lock problem, in which the value of roll
and yaw
are not reliable.
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | arbitrary number |
ACK Val | --- | --- | N/A |
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | arbitrary number |
ACK Val | --- | --- | N/A |
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | arbitrary number |
ACK Val | --- | --- | N/A |
The flight data from the N1 Autopilot can be configured by the DJI N1 assistant software.
More info about Flight Data, please refer to Flight Data part in Appendix .
Data Type | Offset (byte)* | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 2 | item presence byte, Bit with value 1 means this flight data contains corresponding data item
|
2 | 4 | Time stamp | |
6 | 16 | Attitude quaternion | |
22 | 12 | Linear acceleration | |
34 | 13 | Linear velocity | |
47 | 12 | Angular velocity | |
59 | 24 | GPS position, altitude, height and healthiness | |
83 | 12 | Magnetometer data | |
95 | 10 | Remote controller channels | |
105 | 12 | Roll, pitch and yaw of Gimbal | |
117 | 1 | Flight status | |
118 | 1 | Battery percentage | |
119 | 1 | Control device | |
ACK Val | --- | --- | N/A |
Note: The offset in the above table is with the assumption that all data items exist. The actual offset of data item in the flight data should be calculated by the flags of 'item presence byte'.
Onboard Device has the lowerest control priority. Its control authorization can be taken over by remote controller and Mobile Device. Once the flight control is lost from the Onboard Device, a push data will be sent by the N1 Autopilot.
Data Type | Offset (byte) | Size (byte) | Description |
---|---|---|---|
CMD Val | 0 | 1 | Fixed value, set to be 0x04 |
ACK Val | --- | --- | N/A |