dji-sdk / Payload-SDK

DJI Payload SDK Official Repository
https://github.com/dji-sdk/Payload-SDK
Other
253 stars 111 forks source link

Payload SDK v3.4 segfault running Linux test_widget.c example #98

Closed bradgrissom closed 1 year ago

bradgrissom commented 1 year ago

Problem description: Payload SDK v3.4 segfault running Linux test_widget.c example

Payload SDK: Latest v3.4 DJI Payload SDK from: https://github.com/dji-sdk/Payload-SDK Payload SDK Version : V3.4.0-beta.0-build.1749

DJI Aircraft: Matrice 300 Series

Gimbal: Get serial number of Skyport V2 or X-Port is 34DDH5L000007H Identify AircraftType = Matrice 300 RTK, MountPosition = Payload Port NO1, SdkAdapterType = X-Portfile:///root/Desktop/2023.05.17_dji_payload_sdk.diff

Host Platform: Raspberry Pi CM4 Serial port: /dev/serial0 at 115200 baud Ethernet: eth0

Attached is a .diff file showing exactly what I changed from the default code, which is the serial port device, ethernet device, and a few print statements.

I'm having a hard time attaching a file, here is the diff below:

diff --git a/samples/sample_c/module_sample/widget/test_widget.c b/samples/sample_c/module_sample/widget/test_widget.c
index f51895a..0c27bc8 100644
--- a/samples/sample_c/module_sample/widget/test_widget.c
+++ b/samples/sample_c/module_sample/widget/test_widget.c
@@ -99,14 +99,17 @@ T_DjiReturnCode DjiTest_WidgetStartService(void)

     if (s_isWidgetFileDirPathConfigured == true) {
         snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/en_big_screen", s_widgetFileDirPath);
+        USER_LOG_INFO("BAG cfgdTRUE widget file path [%s]", tempPath);
     } else {
         snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/en_big_screen", curFileDirPath);
+        USER_LOG_INFO("BAG cfgdELSE widget file path [%s]", tempPath);
     }

     //set default ui config path
     djiStat = DjiWidget_RegDefaultUiConfigByDirPath(tempPath);
     if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
-        USER_LOG_ERROR("Add default widget ui config error, stat = 0x%08llX", djiStat);
+//        USER_LOG_ERROR("Add default widget ui config error, stat = 0x%08llX", djiStat);
+        USER_LOG_ERROR("Add default widget ui config error, path[%s] stat = 0x%08llX", tempPath, djiStat);
         return djiStat;
     }

diff --git a/samples/sample_c/platform/linux/manifold2/CMakeLists.txt b/samples/sample_c/platform/linux/manifold2/CMakeLists.txt
index 6a6cab8..b6fd418 100644
--- a/samples/sample_c/platform/linux/manifold2/CMakeLists.txt
+++ b/samples/sample_c/platform/linux/manifold2/CMakeLists.txt
@@ -83,5 +83,4 @@ endif (LIBUSB_FOUND)
 target_link_libraries(${PROJECT_NAME} m)

 add_custom_command(TARGET ${PROJECT_NAME}
-        PRE_LINK COMMAND cmake ..
         WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
diff --git a/samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h b/samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h
index 7330d8d..c751113 100644
--- a/samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h
+++ b/samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h
@@ -35,12 +35,18 @@ extern "C" {
 /* Exported constants --------------------------------------------------------*/
 // ATTENTION: User must goto https://developer.dji.com/user/apps/#all to create your own dji sdk application, get dji sdk application
 // information then fill in the application information here.
-#define USER_APP_NAME               "your_app_name"
-#define USER_APP_ID                 "your_app_id"
-#define USER_APP_KEY                "your_app_key"
-#define USER_APP_LICENSE            "your_app_license"
-#define USER_DEVELOPER_ACCOUNT      "your_developer_account"
-#define USER_BAUD_RATE              "460800"
+//#define USER_APP_NAME               "your_app_name"
+//#define USER_APP_ID                 "your_app_id"
+//#define USER_APP_KEY                "your_app_key"
+//#define USER_APP_LICENSE            "your_app_license"
+//#define USER_DEVELOPER_ACCOUNT      "your_developer_account"
+//#define USER_BAUD_RATE              "460800"
+#define USER_APP_NAME               "AI OGI Camera"
+#define USER_APP_ID                 "******"
+#define USER_APP_KEY                "*******************************"
+#define USER_APP_LICENSE         "********************************************************************************************************************************************************************************************************************************************************************************************************************************************************"
+#define USER_DEVELOPER_ACCOUNT      "****************************"
+#define USER_BAUD_RATE              "115200"  // was 460800

 /* Exported types ------------------------------------------------------------*/

diff --git a/samples/sample_c/platform/linux/manifold2/application/dji_sdk_config.h b/samples/sample_c/platform/linux/manifold2/application/dji_sdk_config.h
index 5e3f27f..f73e94b 100644
--- a/samples/sample_c/platform/linux/manifold2/application/dji_sdk_config.h
+++ b/samples/sample_c/platform/linux/manifold2/application/dji_sdk_config.h
@@ -46,25 +46,25 @@ extern "C" {
 * */
 #define CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON

-#define CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON
+//#define CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON

-#define CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
+//#define CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON

-#define CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
+//#define CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON

 #define CONFIG_MODULE_SAMPLE_XPORT_ON

 #define CONFIG_MODULE_SAMPLE_WIDGET_ON

-#define CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON
+//#define CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON

-#define CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
+//#define CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON

-#define CONFIG_MODULE_SAMPLE_UPGRADE_ON
+//#define CONFIG_MODULE_SAMPLE_UPGRADE_ON

-#define CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
+//#define CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON

-#define CONFIG_MODULE_SAMPLE_HMS_ON
+//#define CONFIG_MODULE_SAMPLE_HMS_ON

 /*!< Attention: This function needs to be used together with mobile sdk mop sample.
 * */
diff --git a/samples/sample_c/platform/linux/manifold2/hal/hal_network.h b/samples/sample_c/platform/linux/manifold2/hal/hal_network.h
index 302f8a9..6a06b73 100644
--- a/samples/sample_c/platform/linux/manifold2/hal/hal_network.h
+++ b/samples/sample_c/platform/linux/manifold2/hal/hal_network.h
@@ -42,7 +42,7 @@ extern "C" {
 #ifdef PLATFORM_ARCH_x86_64
 #define LINUX_NETWORK_DEV           "enxf8e43b7bbc2c"
 #else
-#define LINUX_NETWORK_DEV           "l4tbr0"
+#define LINUX_NETWORK_DEV           "eth0"
 #endif
 /**
  * @attention
diff --git a/samples/sample_c/platform/linux/manifold2/hal/hal_uart.h b/samples/sample_c/platform/linux/manifold2/hal/hal_uart.h
index f30a661..59af1e8 100644
--- a/samples/sample_c/platform/linux/manifold2/hal/hal_uart.h
+++ b/samples/sample_c/platform/linux/manifold2/hal/hal_uart.h
@@ -45,8 +45,8 @@ extern "C" {

 /* Exported constants --------------------------------------------------------*/
 //User can config dev based on there environmental conditions
-#define LINUX_UART_DEV1    "/dev/ttyUSB0"
-#define LINUX_UART_DEV2    "/dev/ttyACM0"
+#define LINUX_UART_DEV1    "/dev/serial0"
+#define LINUX_UART_DEV2    "/dev/serial0"

 /* Exported types ------------------------------------------------------------*/
bradgrissom commented 1 year ago

I forgot to paste the output from running it:

pi ~/Payload-SDK_vanilla/Payload-SDK/samples/sample_c/platform/linux/manifold2/bin ..) sudo ./dji_sdk_demo_linux-
[0.008][core]-[Info]-[DjiCore_Init:96) Payload SDK Version : V3.4.0-beta.0-build.1749-
[0.157][adapter]-[Info]-[DjiAccessAdapter_Init:180) Identify aircraft series is Matrice 300 Series-
[0.157][adapter]-[Info]-[DjiAccessAdapter_Init:198) Identify mount position type is Payload Port Type-
[0.163][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[1.195][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[2.195][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[3.195][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[4.195][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[5.195][adapter]-[Info]-[DjiPayloadNegotiate_Init:200) Waiting payload negotiate finished.-
[7.658][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:445) Updating dji sdk policy file...-
[8.658][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:448) Update dji sdk policy file successfully-
[9.718][infor]-[Info]-[DjiAircraftInfo_GetAdapterSerialNumber:669) Get serial number of Skyport V2 or X-Port is 34DDH5L000007H-
[9.721][core]-[Info]-[DjiCore_Init:164) Identify AircraftType = Matrice 300 RTK, MountPosition = Payload Port NO1, SdkAdapterType = X-Port-
[10.056][time_sync]-[Info]-[DjiTimeSync_PushAppTimeHandle:111) Current time: 2023.05.17 11:24:13.-
[11.128][user]-[Info]-[DjiTest_WidgetStartService:105) BAG cfgdELSE widget file path [/home/pi/Payload-SDK_vanilla/Payload-SDK/samples/sample_>
[11.130][core]-[Info]-[DjiCore_ApplicationStart:231) Start dji sdk application-
[12.407][infor]-[Info]-[DjiAircraftInfo_NotifyMobileAppInfoHandle:578) Set mobile app info, language is English, screen type is Big Screen-
Segmentation fault
bradgrissom commented 1 year ago

Here is the GDB backtrace:

[Detaching after vfork from child process 14295] [Detaching after vfork from child process 14299] [31.381][infor]-[Info]-[DjiAircraftInfo_NotifyMobileAppInfoHandle:578) Set mobile app info, language is English, screen type is Big Screen

Thread 10 "downloader_task" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fe77fe1c0 (LWP 14266)] 0x0000007ff7ebac50 in GI_pthread_mutex_lock (mutex=mutex@entry=0x0) at pthread_mutex_lock.c:67 67 pthread_mutex_lock.c: No such file or directory. (gdb) bt

0 0x0000007ff7ebac50 in GI_pthread_mutex_lock (mutex=mutex@entry=0x0) at pthread_mutex_lock.c:67

1 0x0000005555594b9c in Osal_MutexLock (mutex=0x0)

at /home/pi/Payload-SDK_vanilla/Payload-SDK/samples/sample_c/platform/linux/common/osal/osal.c:139

2 0x00000055555bd07c in DjiHighSpeedDataChannel_GetDownloadStreamState ()

3 0x0000005555623728 in DjiDataDownloader_GetDownloadChannelBandWidth ()

4 0x00000055556237a0 in DjiDataDownloader_GetSendFlowControlParam ()

5 0x000000555562260c in DjiDataDownloader_DataSending ()

6 0x00000055555e4174 in DjiStateMachine_Run ()

7 0x000000555562206c in DjiDataDownloader_WorkThread ()

8 0x0000007ff7eb8648 in start_thread (arg=0x7fe77fdac0) at pthread_create.c:477

9 0x0000007ff7e0ec1c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

(gdb) info frame Stack level 0, frame at 0x7fe77fd810: pc = 0x7ff7ebac50 in GI_pthread_mutex_lock (pthread_mutex_lock.c:67); saved pc = 0x5555594b9c called by frame at 0x7fe77fd830 source language c. Arglist at 0x7fe77fd7e0, args: mutex=mutex@entry=0x0 Locals at 0x7fe77fd7e0, Previous frame's sp is 0x7fe77fd810 Saved registers: x21 at 0x7fe77fd800, x22 at 0x7fe77fd808, x29 at 0x7fe77fd7e0, x30 at 0x7fe77fd7e8 (gdb)

bradgrissom commented 1 year ago

Pulling in the latest DJI Payload-SDK version 3.5 code (as of 2023.05.22) , I don't get the crash, but I get endless (millions) messages like these:

[121.376][channel]-[Error]-[DjiHighSpeedDataChannel_GetDownloadStreamState:643) Lock mutex error. [121.376][downloader]-[Error]-[DjiDataDownloader_GetDownloadChannelBandWidth:889) get download channel state error: 227. [121.376][downloader]-[Error]-[DjiDataDownloader_GetSendFlowControlParam:914) Get download channel bandwidth error, 0x000000E3 [121.376][downloader]-[Error]-[DjiDataDownloader_DataSending:503) Get send flow control param error, stat = 0x000000E3 [121.377][channel]-[Error]-[DjiHighSpeedDataChannel_GetDownloadStreamState:643) Lock mutex error.

bradgrissom commented 1 year ago

This is the fix from DJI email support. It worked:

Please enable the data transmission,widget functions are multiplexed within data transmission channels.