ST work1--The deepest impression of a bug DJI activation times Sdk_active_sdk_version_error

Source: Internet
Author: User

Asynchronous thread activation, the data that should be shared by the asynchronous thread is set to the local variable of the function

1) Bug

Activation to use all data in the official demo test is no problem, but one in their own program to run the report the following error

  

My code was glued from the official demo, and the only thing that changed was to change the UI data into my own data, add header files, and declare some variables. The value of Sdk_version is the official own macro definition, which makes it impossible to make mistakes.

2) Debug method, find the function call chain, compare the output of my program and demo layer by level, find out the different place and reason of output

Helpless, I looked up the call chain for this function:

Dji_pro_activate_api (&user_act_data,mainwindow_activate_callback)

Dji_pro_create_thread (Activate_api_thread_func,p_user_data)

Activate_api_thread_func

Dji_pro_app_send_data (2, 0, My_activation_set, Api_user_activation,

(unsigned char*) &from_user_account_data,

sizeof (From_user_account_data)-sizeof (char *),

dji_pro_activate_api_callback,1000,1);

Pro_send_interface (&param)

Send_pro_data (CMD_SESSION->MMU->PMEM)

Dji_pro_activate_api (&user_act_data,mainwindow_activate_callback);

Pro_hw_send (buf,pheader->length);

Port->write ((char *) BUF + sent,len-sent)

The final write is the QT library function, it is visible here is the last, and then there is no source code.

The caller of write is port, which is

The caller of Pro_hw_send is DJI_PRO_HW, the official function used for serial communication.

Visible, the last two steps are already the PC through the serial port to the UAV's motherboard to send information.

The parameters of the function are always changing, but through the program it can be seen that the user_act_data is passed backwards, just in different variables.

A probable cause of the error is that the data in the process of transmission error, in order to determine whether the error is in the data out before or after the data out, (because if it is the wrong to wear out before, it is the error of the program, otherwise, the line or drone processing has been wrong) I want to output data validation in each function.

Because it was very unfamiliar to the drone, so afraid of the error is outside the program (I would probably not be able to fix it), so choose from the last function of the parameters start.

Output the Write parameter in 16-binary form

Call the following function in Pro_hw_send

void print (unsigned char *buf, int len) {

for (int i = 0; i < len; i++) {

if (i% = = 0) printf ("\ n");

printf ("%2x", Buf[i]);

}

}

As a result, the output in my program is:

  

Very different from the official code output.

3) Final cause

As the output is layered, the data is found to be incorrect in Activate_api_thread_func, and the data is correct before the function is passed in.

The reason is that Dji_pro_create_thread created a new thread to run, Activate_api_thread_func, and passed User_act_data as a parameter to the thread, but my program declares the User_act_ Data is a local variable within a function, and only global variables or dynamic variables can be shared by different threads of the same process, so access to Activate_api_thread_func is actually an illegal area.

The essence of this error is that the variables of the async thread share a problem.

ST work1--The deepest impression of a bug. DJI activation times Sdk_active_sdk_version_error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.