diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a2ac06..3d1ff571 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,7 @@ endif () if (USE_SYSTEM_ARCH MATCHES LINUX) add_definitions(-DSYSTEM_ARCH_LINUX) add_subdirectory(samples/sample_c/platform/linux/manifold2) - - message("-- Attention: If you want to use opencv C++ sample, please uncomment the next line.") -# add_subdirectory(samples/sample_c++/platform/linux/manifold2) + add_subdirectory(samples/sample_c++/platform/linux/manifold2) execute_process(COMMAND uname -m OUTPUT_VARIABLE DEVICE_SYSTEM_ID) if (DEVICE_SYSTEM_ID MATCHES x86_64) diff --git a/LICENSE.txt b/LICENSE.txt index 1590fa05..41755cde 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -6,11 +6,15 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   ├── dji_sdk_code_style │   │   ├── dji_sdk_template.c │   │   └── dji_sdk_template.h +│   ├── reference_designs +│   │   └── Type-C Schematic Reference.pdf │   └── simple_model │   ├── M300_OSDK_Adapter.stp │   ├── M300_RTK_1.stp │   ├── M300_RTK_2.stp │   ├── M300_RTK_3.stp +│   ├── M30T.stp +│   ├── PSDK Mounting Bracket(Payload).stp │   ├── Skyport_Adapter_2.stp │   └── X-Port 80mm.stp ├── EULA.txt @@ -43,6 +47,7 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   ├── dji_version.h │   │   ├── dji_waypoint_v2.h │   │   ├── dji_waypoint_v2_type.h +│   │   ├── dji_waypoint_v3.h │   │   ├── dji_widget.h │   │   ├── dji_xport.h │   │   └── legacy_psdk2.x @@ -75,7 +80,7 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   ├── aarch64-linux-gnu-gcc │   │   └── libpayloadsdk.a │   ├── armcc_cortex-m4 -│   │   └── libpayloadsdk.lib +│   │   └── libpayload.lib │   ├── arm-himix100-linux-gcc │   │   └── libpayloadsdk.a │   ├── arm-himix200-linux-gcc @@ -96,7 +101,9 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   └── libpayloadsdk.a │   ├── arm-none-eabi-gcc │   │   └── libpayloadsdk.a -│   └── x86_64-linux-gnu-gcc +│   ├── x86_64-linux-gnu-gcc +│   │   └── libpayloadsdk.a +│   └── xtensa-esp32-elf-gcc │   └── libpayloadsdk.a ├── README.md ├── samples @@ -186,11 +193,20 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   │   ├── waypoint_v2 │   │   │   │   ├── test_waypoint_v2.c │   │   │   │   └── test_waypoint_v2.h +│   │   │   ├── waypoint_v3 +│   │   │   │   ├── test_waypoint_v3.c +│   │   │   │   ├── test_waypoint_v3.h +│   │   │   │   ├── waypoint_file +│   │   │   │   │   └── waypoint_v3_test_file.kmz +│   │   │   │   └── waypoint_file_c +│   │   │   │   └── waypoint_v3_test_file_kmz.h │   │   │   ├── widget │   │   │   │   ├── file_binary_array_list_en.c │   │   │   │   ├── file_binary_array_list_en.h │   │   │   │   ├── test_widget.c │   │   │   │   ├── test_widget.h +│   │   │   │   ├── test_widget_speaker.c +│   │   │   │   ├── test_widget_speaker.h │   │   │   │   ├── widget_file │   │   │   │   │   ├── cn_big_screen │   │   │   │   │   │   ├── icon_button1.png @@ -261,8 +277,9 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   ├── linux │   │   │   ├── common │   │   │   │   ├── 3rdparty -│   │   │   │   │   └── ffmpeg -│   │   │   │   │   └── FindFFMPEG.cmake +│   │   │   │   │   ├── FindFFMPEG.cmake +│   │   │   │   │   ├── FindLIBUSB.cmake +│   │   │   │   │   └── FindOPUS.cmake │   │   │   │   ├── monitor │   │   │   │   │   ├── sys_monitor.c │   │   │   │   │   └── sys_monitor.h @@ -302,12 +319,24 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   │   ├── dji_sdk_config.h │   │   │   ├── FreeRTOSConfig.h │   │   │   └── main.c +│   │   ├── bootloader +│   │   │   ├── common.c +│   │   │   ├── common.h +│   │   │   ├── main.c +│   │   │   ├── main.h +│   │   │   ├── menu.c +│   │   │   ├── menu.h +│   │   │   └── ymodem.c │   │   ├── drivers │   │   │   ├── BSP │   │   │   │   ├── apply_high_power.c │   │   │   │   ├── apply_high_power.h +│   │   │   │   ├── button.c +│   │   │   │   ├── button.h │   │   │   │   ├── dji_ringbuffer.c │   │   │   │   ├── dji_ringbuffer.h +│   │   │   │   ├── flash_if.c +│   │   │   │   ├── flash_if.h │   │   │   │   ├── freertos.c │   │   │   │   ├── led.c │   │   │   │   ├── led.h @@ -321,15 +350,16 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   │   │   ├── stm32f4xx_it.h │   │   │   │   ├── syscalls.c │   │   │   │   ├── sysmem.c +│   │   │   │   ├── sysmem.h │   │   │   │   ├── system_stm32f4xx.c │   │   │   │   ├── uart.c -│   │   │   │   └── uart.h +│   │   │   │   ├── uart.h +│   │   │   │   ├── upgrade_platform_opt_stm32.c +│   │   │   │   └── upgrade_platform_opt_stm32.h │   │   │   ├── CMSIS │   │   │   │   ├── Device │   │   │   │   │   └── ST │   │   │   │   │   └── STM32F4xx -│   │   │   │   │   ├── Include -│   │   │   │   │   └── Source │   │   │   │   └── Include │   │   │   ├── STM32F4xx_HAL_Driver │   │   │   │   ├── Inc @@ -378,21 +408,22 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   │   ├── stream_buffer.c │   │   │   ├── tasks.c │   │   │   └── timers.c -│   │   └── project -│   │   ├── clion_app -│   │   │   ├── CMakeLists.txt -│   │   │   ├── STM32F407VGTX_FLASH.ld -│   │   │   └── stm32f4discovery.cfg -│   │   └── mdk_app -│   │   └── mdk_app.uvprojx +│   │   ├── project +│   │   │   ├── armgcc +│   │   │   │   ├── CMakeLists.txt +│   │   │   │   ├── STM32F407VGTX_FLASH.ld +│   │   │   │   └── stm32f4discovery.cfg +│   │   │   ├── mdk +│   │   │   │   └── mdk_app.uvprojx +│   │   │   └── mdk_bootloader +│   │   │   └── mdk_bootloader.uvprojx +│   │   └── readme.txt │   └── sample_c++ │   ├── module_sample │   │   ├── liveview │   │   │   ├── data -│   │   │   │   ├── cars.xml │   │   │   │   ├── haarcascade_frontalface_alt.xml │   │   │   │   └── tensorflow -│   │   │   │   ├── frozen_inference_graph.pb │   │   │   │   └── ssd_inception_v2_coco_2017_11_17.pbtxt │   │   │   ├── dji_camera_image_handler.cpp │   │   │   ├── dji_camera_image_handler.hpp @@ -410,9 +441,17 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   └── platform │   └── linux │   ├── common +│   │   ├── 3rdparty +│   │   │   ├── FindFFMPEG.cmake +│   │   │   ├── FindLIBUSB.cmake +│   │   │   └── FindOPUS.cmake │   │   └── osal │   │   ├── osal.c -│   │   └── osal.h +│   │   ├── osal_fs.c +│   │   ├── osal_fs.h +│   │   ├── osal.h +│   │   ├── osal_socket.c +│   │   └── osal_socket.h │   └── manifold2 │   ├── application │   │   ├── application.cpp @@ -420,14 +459,13 @@ The following portions of the DJI’s Payload SDK (“Software” referred to in │   │   ├── dji_sdk_app_info.h │   │   └── main.cpp │   ├── CMakeLists.txt -│   ├── FindFFMPEG.cmake │   └── hal │   ├── hal_network.c │   ├── hal_network.h │   ├── hal_uart.c │   ├── hal_uart.h │   ├── hal_usb_bulk.c -│ └── hal_usb_bulk.h +│   └── hal_usb_bulk.h └── tools └── file2c ├── file2c.exe diff --git a/README.md b/README.md index 8f036fc3..9910907c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DJI Payload SDK (PSDK) -![](https://img.shields.io/badge/version-V3.1.0-orange.svg) +![](https://img.shields.io/badge/version-V3.2.0-orange.svg) ![](https://img.shields.io/badge/platform-linux_|_rtos-green.svg) ![](https://img.shields.io/badge/license-MIT-blue.svg) [![Join the chat at https://gitter.im/dji-sdk/Payload-SDK](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dji-sdk/Payload-SDK?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -15,17 +15,31 @@ Payload Controller, Video Image Analysis Platform, Mapping Camera, Megaphone And ## Documentation -For full documentation, please visit the [DJI Developer Documentation](https://developer.dji.com/payload-sdk/documentation/). -Documentation regarding the code can be found in the [PSDK API Reference](https://developer.dji.com/payload-api-reference/introduction/index.html) section of the developer's website. -Please visit the [Latest Version Information](https://developer.dji.com/payload-sdk/documentation/appendix/firmware.html) to get the latest version information. +For full documentation, please visit +the [DJI Developer Documentation](https://developer.dji.com/payload-sdk/documentation/). Documentation regarding the +code can be found in the [PSDK API Reference](https://developer.dji.com/payload-api-reference/introduction/index.html) +section of the developer's website. Please visit +the [Latest Version Information](https://developer.dji.com/payload-sdk/documentation/appendix/firmware.html) to get the +latest version information. ## Latest Release -PSDK 3.1.0 was released on 21 March 2022. This version of Payload SDK mainly add some features support, such as add the -Matrice 30/30T support, add the standard speaker widget support on M30/M30T, add the waypoint 3.0 support on M30/30T, add the -get camera laser ranging data support on M30/30T, add the power-off notification support on M300 RTK OSDK port, etc. At -the same time, we also fixed some bugs on the last version, add more sample support and add ESP32 toolchain support. -Please refer to the release notes for detailed changes list. +PSDK 3.2.0 was released on 08 August 2022. This version of Payload SDK mainly add some features support and fixed some +bugs. Please refer to the release notes for detailed changes list. + +* Add the support of standard speaker on M300 RTK, M30/M30T Pilot +* Add the support of the mapping between the speaker with the remote controller button on M300 RTK, M30/M30T Pilot +* Add function support for H20N on M300 RTK +* Add infrared zoom function support of H20T on M300 RTK +* Fix the occasional problem of the Camera Livestream can not be subscribed on M30/M30T +* Fix the problem of some interfaces of camera management run error on M30/M30T +* Fix the problem of the infrared code stream can not be obtained on M30/M30T +* Fix the problem of RTOS platform data subscription crash on M30/M30T +* Fix the occasional problem of abnormal media download function on M300 RTK +* Fix the occasional problem of abnormal SDK interconnection function on M300 RTK +* Fix the occasional problem of the PSDK payload name displays abnormally +* Fix the coordinate system problem of the gimbal angle of the data subscription function +* Optimize the compilation dependency problems of third-party dependent libraries ## License diff --git a/psdk_lib/include/dji_camera_manager.h b/psdk_lib/include/dji_camera_manager.h index 614776a7..286a0c19 100644 --- a/psdk_lib/include/dji_camera_manager.h +++ b/psdk_lib/include/dji_camera_manager.h @@ -509,7 +509,8 @@ typedef enum { typedef struct { E_DjiDownloadFileEvent downloadFileEvent; uint32_t fileIndex; - uint8_t progressInPercent; + uint32_t fileSize; + float progressInPercent; } T_DjiDownloadFilePacketInfo; typedef struct { @@ -767,6 +768,15 @@ T_DjiReturnCode DjiCameraManager_SetOpticalZoomParam(E_DjiMountPosition position T_DjiReturnCode DjiCameraManager_GetOpticalZoomParam(E_DjiMountPosition position, T_DjiCameraManagerOpticalZoomParam *opticalZoomParam); +/** + * @brief Set parameters for camera infrared zooming of the selected camera mounted position. + * @param position: camera mounted position + * @param factor: target zoom factor. + * @return Execution result. + */ +T_DjiReturnCode DjiCameraManager_SetInfraredZoomParam(E_DjiMountPosition position, + dji_f32_t factor); + /** * @brief Stop camera optical zooming of the selected camera mounted position. * @note Called to stop focal length changing, when it currently is from @@ -957,6 +967,8 @@ T_DjiReturnCode DjiCameraManager_StopRecordVideo(E_DjiMountPosition position); /** * @brief Download selected camera media file list. + * @note The interface is a synchronous interface, which occupies more CPU resources when using it. + * If the download file fails, the timeout time is 3S. * @param position: the mount position of the camera * @param fileList: the pointer to the downloaded camera file list * @return Execution result. @@ -975,7 +987,8 @@ T_DjiReturnCode DjiCameraManager_RegDownloadFileDataCallback(E_DjiMountPosition /** * @brief Download selected camera media file by file index. * @note Only support download one file at the same time, the new file download need wait for the previous file - * download finished. + * download finished.The interface is a synchronous interface, which occupies more CPU resources when using it. + * If the download file fails, the timeout time is 3S. * @param position: the mount position of the camera * @param fileIndex: the index of the camera media file * @return Execution result. diff --git a/psdk_lib/include/dji_core.h b/psdk_lib/include/dji_core.h index e28890a5..c1b9276e 100644 --- a/psdk_lib/include/dji_core.h +++ b/psdk_lib/include/dji_core.h @@ -89,6 +89,12 @@ T_DjiReturnCode DjiCore_SetAlias(const char *productAlias); */ T_DjiReturnCode DjiCore_ApplicationStart(void); +/** + * @brief DeInitialize the Payload SDK core in blocking mode. + * @return Execution result. + */ +T_DjiReturnCode DjiCore_DeInit(void); + #ifdef __cplusplus } #endif diff --git a/psdk_lib/include/dji_fc_subscription.h b/psdk_lib/include/dji_fc_subscription.h index 1d73c8b0..6c02df6d 100644 --- a/psdk_lib/include/dji_fc_subscription.h +++ b/psdk_lib/include/dji_fc_subscription.h @@ -157,7 +157,6 @@ typedef enum { * * @note This value is updated each time the drone takes off. * - * @sensors Visual Odometry (M210 only), Barometer, IMU * @units m * @datastruct \ref T_DjiFcSubscriptionAltitudeOfHomePoint */ @@ -935,8 +934,7 @@ typedef struct BatterySingleInfo { */ typedef struct SDKCtrlInfo { uint8_t controlMode; /*!< See CtlrMode in dji_status.hpp*/ - uint8_t deviceStatus: 3; /*!< For M300 and M210V2(firmware version V01.00.0690 and later):0->rc 1->app 4->serial; - Other: 0->rc 1->app 2->serial*/ + uint8_t deviceStatus: 3; /*!< 0->rc 1->app 4->serial */ uint8_t flightStatus: 1; /*!< 1->opensd 0->close */ uint8_t vrcStatus: 1; uint8_t reserved: 3; @@ -1062,7 +1060,6 @@ typedef struct PositionVO { /*! * @brief struct for data broadcast and subscription, return obstacle info around the vehicle * - * @note available in M210 (front, up, down) */ typedef struct RelativePosition { dji_f32_t down; /*!< distance from obstacle (m) */ @@ -1170,7 +1167,8 @@ T_DjiReturnCode DjiFcSubscription_SubscribeTopic(E_DjiFcSubscriptionTopic topic, * @param timestamp: pointer to memory space used to store timestamps. The memory space used to store timestamps * have to have been allocated correctly, and should ensure its size is equal to data structure size of timestamp, * otherwise, this function will not be able to return data and timestamp (return error code) or even cause memory - * overflow event. If the user does not need timestamp information, can fill in NULL. + * overflow event. If the user does not need timestamp information, can fill in NULL. Use flight controller power-on + * timestamp on M300 RTK. Use payload local timestamp on M30/M30T. * @return Execution result. */ T_DjiReturnCode DjiFcSubscription_GetLatestValueOfTopic(E_DjiFcSubscriptionTopic topic, diff --git a/psdk_lib/include/dji_flight_controller.h b/psdk_lib/include/dji_flight_controller.h index 1a40bd4a..4069c796 100644 --- a/psdk_lib/include/dji_flight_controller.h +++ b/psdk_lib/include/dji_flight_controller.h @@ -294,7 +294,7 @@ DjiFlightController_GetRtkPositionEnableStatus(E_DjiFlightControllerRtkPositionE /** * @brief Set rc lost action. - * @note It will be valid when rc and osdk is both lost.It only support M320. + * @note It will be valid when rc and osdk is both lost.It only support M30. * @param rcLostAction: actions when rc is lost.(hover/landing/go home).It keeps in sync with pilot's param. * @return Execution result. */ @@ -302,7 +302,7 @@ T_DjiReturnCode DjiFlightController_SetRCLostAction(E_DjiFlightControllerRCLostA /** * @brief Get rc lost action(hover/landing/gohome). - * @note It will be valid when rc and osdk is both lost.It only support M320. + * @note It will be valid when rc and osdk is both lost.It only support M30. * @param rcLostAction: see reference of E_DjiFlightControllerRCLostAction.It keeps in sync with pilot's param. * @return Execution result. */ @@ -583,7 +583,7 @@ T_DjiReturnCode DjiFlightController_ExecuteEmergencyBrakeAction(void); /** * @brief Request cancel emergency brake action. - * @note It is only support on M320.If you use DjiFlightController_ExecuteEmergencyBrakeAction(), you need to use + * @note It is only support on M30.If you use DjiFlightController_ExecuteEmergencyBrakeAction(), you need to use * "DjiFlightController_CancelEmergencyBrakeAction()" to allow aircraft to execute drone action again. * @return Execution result. */ diff --git a/psdk_lib/include/dji_typedef.h b/psdk_lib/include/dji_typedef.h index 01ebb08a..f52c2eff 100644 --- a/psdk_lib/include/dji_typedef.h +++ b/psdk_lib/include/dji_typedef.h @@ -114,6 +114,7 @@ typedef enum { DJI_CAMERA_TYPE_XTS = 41, /*!< Camera type is XT S. */ DJI_CAMERA_TYPE_H20 = 42, /*!< Camera type is H20. */ DJI_CAMERA_TYPE_H20T = 43, /*!< Camera type is H20T. */ + DJI_CAMERA_TYPE_H20N = 61, /*!< Camera type is H20N. */ DJI_CAMERA_TYPE_P1 = 50, /*!< Camera type is P1. */ DJI_CAMERA_TYPE_L1, /*!< Camera type is L1. */ DJI_CAMERA_TYPE_M30, /*!< Camera type is M30. */ @@ -256,7 +257,7 @@ typedef enum { typedef enum { /*! The number of pictures to continuously take each time in BURST mode is 2 */ - DJI_CAMERA_BURST_COUNT_2 = 2, + DJI_CAMERA_BURST_COUNT_2 = 2, /*! The number of pictures to continuously take each time in BURST mode is 3 */ DJI_CAMERA_BURST_COUNT_3 = 3, @@ -359,7 +360,8 @@ typedef struct { * @param data: pointer to data of the topic, user need transfer type of this pointer to the corresponding data structure * pointer for getting every item of the topic conveniently. * @param dataSize: the size of memory space pointed by data argument, equal to data structure size corresponding to the topic. - * @param timestamp: pointer to timestamp corresponding this data. + * @param timestamp: pointer to timestamp corresponding this data. Use flight controller power-on timestamp on M300 RTK. + * Use payload local timestamp on M30/M30T. * @return Execution result. */ typedef T_DjiReturnCode (*DjiReceiveDataOfTopicCallback)(const uint8_t *data, uint16_t dataSize, diff --git a/psdk_lib/include/dji_version.h b/psdk_lib/include/dji_version.h index 11ebe094..15f6012b 100644 --- a/psdk_lib/include/dji_version.h +++ b/psdk_lib/include/dji_version.h @@ -34,10 +34,10 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ #define DJI_VERSION_MAJOR 3 /*!< DJI SDK major version num, when have incompatible API changes. Range from 0 to 99. */ -#define DJI_VERSION_MINOR 1 /*!< DJI SDK minor version num, when add functionality in a backwards compatible manner changes. Range from 0 to 99. */ +#define DJI_VERSION_MINOR 2 /*!< DJI SDK minor version num, when add functionality in a backwards compatible manner changes. Range from 0 to 99. */ #define DJI_VERSION_MODIFY 0 /*!< DJI SDK modify version num, when have backwards compatible bug fixes changes. Range from 0 to 99. */ #define DJI_VERSION_BETA 0 /*!< DJI SDK version beta info, release version will be 0, when beta version release changes. Range from 0 to 255. */ -#define DJI_VERSION_BUILD 1509 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */ +#define DJI_VERSION_BUILD 1539 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */ /* Exported types ------------------------------------------------------------*/ diff --git a/psdk_lib/include/dji_widget.h b/psdk_lib/include/dji_widget.h index b8c851af..bf13ea4e 100644 --- a/psdk_lib/include/dji_widget.h +++ b/psdk_lib/include/dji_widget.h @@ -191,13 +191,9 @@ typedef struct { typedef struct { T_DjiReturnCode (*GetSpeakerState)(T_DjiWidgetSpeakerState *speakerState); - T_DjiReturnCode (*SetWorkMode)(E_DjiWidgetSpeakerWorkMode workMode); - T_DjiReturnCode (*GetWorkMode)(E_DjiWidgetSpeakerWorkMode *workMode); T_DjiReturnCode (*SetPlayMode)(E_DjiWidgetSpeakerPlayMode playMode); - T_DjiReturnCode (*GetPlayMode)(E_DjiWidgetSpeakerPlayMode *playMode); T_DjiReturnCode (*SetVolume)(uint8_t volume); - T_DjiReturnCode (*GetVolume)(uint8_t *volume); T_DjiReturnCode (*StartPlay)(void); T_DjiReturnCode (*StopPlay)(void); diff --git a/psdk_lib/lib/aarch64-himix100-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/aarch64-himix100-linux-gcc/libpayloadsdk.a index 839f2e8c..6a596cb2 100644 Binary files a/psdk_lib/lib/aarch64-himix100-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/aarch64-himix100-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/aarch64-linux-android-gcc/libpayloadsdk.a b/psdk_lib/lib/aarch64-linux-android-gcc/libpayloadsdk.a index 727e943f..7f512f9a 100644 Binary files a/psdk_lib/lib/aarch64-linux-android-gcc/libpayloadsdk.a and b/psdk_lib/lib/aarch64-linux-android-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/aarch64-linux-gnu-gcc/libpayloadsdk.a b/psdk_lib/lib/aarch64-linux-gnu-gcc/libpayloadsdk.a index bd1d60be..885bc1e2 100644 Binary files a/psdk_lib/lib/aarch64-linux-gnu-gcc/libpayloadsdk.a and b/psdk_lib/lib/aarch64-linux-gnu-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-himix100-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-himix100-linux-gcc/libpayloadsdk.a index c9b2219c..c3cbbc4e 100644 Binary files a/psdk_lib/lib/arm-himix100-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-himix100-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-himix200-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-himix200-linux-gcc/libpayloadsdk.a index 47570934..109a5917 100644 Binary files a/psdk_lib/lib/arm-himix200-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-himix200-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-hisiv300-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-hisiv300-linux-gcc/libpayloadsdk.a index 61bf5be0..02ce26f9 100644 Binary files a/psdk_lib/lib/arm-hisiv300-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-hisiv300-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-hisiv400-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-hisiv400-linux-gcc/libpayloadsdk.a index 5e939c06..5b1c4ae3 100644 Binary files a/psdk_lib/lib/arm-hisiv400-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-hisiv400-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-hisiv500-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-hisiv500-linux-gcc/libpayloadsdk.a index 6dbe9cec..830d2f87 100644 Binary files a/psdk_lib/lib/arm-hisiv500-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-hisiv500-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-hisiv600-linux-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-hisiv600-linux-gcc/libpayloadsdk.a index fa1ef15b..fb0fa0a0 100644 Binary files a/psdk_lib/lib/arm-hisiv600-linux-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-hisiv600-linux-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-linux-androideabi-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-linux-androideabi-gcc/libpayloadsdk.a index 12a477fe..5c01fe46 100644 Binary files a/psdk_lib/lib/arm-linux-androideabi-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-linux-androideabi-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-linux-gnueabi-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-linux-gnueabi-gcc/libpayloadsdk.a index f34bbdd6..9e3aa20f 100644 Binary files a/psdk_lib/lib/arm-linux-gnueabi-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-linux-gnueabi-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-linux-gnueabihf-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-linux-gnueabihf-gcc/libpayloadsdk.a index 32b0b8eb..2f1d88c0 100644 Binary files a/psdk_lib/lib/arm-linux-gnueabihf-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-linux-gnueabihf-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/arm-none-eabi-gcc/libpayloadsdk.a b/psdk_lib/lib/arm-none-eabi-gcc/libpayloadsdk.a index 71b1a70b..08b5ced9 100644 Binary files a/psdk_lib/lib/arm-none-eabi-gcc/libpayloadsdk.a and b/psdk_lib/lib/arm-none-eabi-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/armcc_cortex-m4/libpayload.lib b/psdk_lib/lib/armcc_cortex-m4/libpayload.lib index 8e07d12a..fcdea586 100644 Binary files a/psdk_lib/lib/armcc_cortex-m4/libpayload.lib and b/psdk_lib/lib/armcc_cortex-m4/libpayload.lib differ diff --git a/psdk_lib/lib/x86_64-linux-gnu-gcc/libpayloadsdk.a b/psdk_lib/lib/x86_64-linux-gnu-gcc/libpayloadsdk.a index 5ba6cfeb..30f63cda 100644 Binary files a/psdk_lib/lib/x86_64-linux-gnu-gcc/libpayloadsdk.a and b/psdk_lib/lib/x86_64-linux-gnu-gcc/libpayloadsdk.a differ diff --git a/psdk_lib/lib/xtensa-esp32-elf-gcc/libpayloadsdk.a b/psdk_lib/lib/xtensa-esp32-elf-gcc/libpayloadsdk.a index 381717f0..dbc1bbe4 100644 Binary files a/psdk_lib/lib/xtensa-esp32-elf-gcc/libpayloadsdk.a and b/psdk_lib/lib/xtensa-esp32-elf-gcc/libpayloadsdk.a differ diff --git a/samples/sample_c++/platform/linux/manifold2/FindFFMPEG.cmake b/samples/sample_c++/platform/linux/common/3rdparty/FindFFMPEG.cmake similarity index 100% rename from samples/sample_c++/platform/linux/manifold2/FindFFMPEG.cmake rename to samples/sample_c++/platform/linux/common/3rdparty/FindFFMPEG.cmake diff --git a/samples/sample_c++/platform/linux/common/3rdparty/FindLIBUSB.cmake b/samples/sample_c++/platform/linux/common/3rdparty/FindLIBUSB.cmake new file mode 100644 index 00000000..43f94712 --- /dev/null +++ b/samples/sample_c++/platform/linux/common/3rdparty/FindLIBUSB.cmake @@ -0,0 +1,34 @@ +# +# Find the native LIBUSB includes and library +# +# This module defines +# LIBUSB_INCLUDE_DIR, where to find libusb.h +# LIBUSB_LIBRARY, the libraries to link against to use LIBUSB. +# LIBUSB_FOUND, If false, do not try to use LIBUSB. + +FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h + PATHS + /usr/local/include/libusb-1.0 + /usr/include/libusb-1.0 + /opt/local/include + /opt/include + ) + +get_filename_component(LIBUSB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR} ABSOLUTE) + +FIND_LIBRARY(LIBUSB_LIBRARY usb-1.0 + /usr/local/lib + /usr/lib + ) + +IF (LIBUSB_INCLUDE_DIR) + IF (LIBUSB_LIBRARY) + SET(LIBUSB_FOUND "YES") + ENDIF (LIBUSB_LIBRARY) +ENDIF (LIBUSB_INCLUDE_DIR) + +MARK_AS_ADVANCED( + LIBUSB_INCLUDE_DIR + LIBUSB_LIBRARY + LIBUSB_FOUND +) \ No newline at end of file diff --git a/samples/sample_c++/platform/linux/common/3rdparty/FindOPUS.cmake b/samples/sample_c++/platform/linux/common/3rdparty/FindOPUS.cmake new file mode 100644 index 00000000..269b6263 --- /dev/null +++ b/samples/sample_c++/platform/linux/common/3rdparty/FindOPUS.cmake @@ -0,0 +1,34 @@ +# +# Find the native OPUS includes and library +# +# This module defines +# OPUS_INCLUDE_DIR, where to find opus.h +# OPUS_LIBRARY, the libraries to link against to use OPUS. +# OPUS_FOUND, If false, do not try to use OPUS. + +FIND_PATH(OPUS_INCLUDE_DIR opus.h + PATHS + /usr/local/include/opus + /usr/include/opus + /opt/local/include + /opt/include + ) + +get_filename_component(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR} ABSOLUTE) + +FIND_LIBRARY(OPUS_LIBRARY opus + /usr/local/lib + /usr/lib + ) + +IF (OPUS_INCLUDE_DIR) + IF (OPUS_LIBRARY) + SET(OPUS_FOUND "YES") + ENDIF (OPUS_LIBRARY) +ENDIF (OPUS_INCLUDE_DIR) + +MARK_AS_ADVANCED( + OPUS_INCLUDE_DIR + OPUS_LIBRARY + OPUS_FOUND +) \ No newline at end of file diff --git a/samples/sample_c++/platform/linux/common/osal/osal.c b/samples/sample_c++/platform/linux/common/osal/osal.c index 6aa16fc2..f70952b2 100644 --- a/samples/sample_c++/platform/linux/common/osal/osal.c +++ b/samples/sample_c++/platform/linux/common/osal/osal.c @@ -1,8 +1,6 @@ /** ******************************************************************** - * @file psdk_osal.c - * @version V2.0.0 - * @date 2019/07/01 + * @file osal.c * @brief * * @copyright (c) 2021 DJI. All rights reserved. @@ -32,6 +30,10 @@ /* Private types -------------------------------------------------------------*/ +/* Private values -------------------------------------------------------------*/ +static uint32_t s_localTimeMsOffset = 0; +static uint64_t s_localTimeUsOffset = 0; + /* Private functions declaration ---------------------------------------------*/ /* Exported functions definition ---------------------------------------------*/ @@ -281,6 +283,12 @@ T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms) gettimeofday(&time, NULL); *ms = (time.tv_sec * 1000 + time.tv_usec / 1000); + if (s_localTimeMsOffset == 0) { + s_localTimeMsOffset = *ms; + } else { + *ms = *ms - s_localTimeMsOffset; + } + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } @@ -291,15 +299,17 @@ T_DjiReturnCode Osal_GetTimeUs(uint64_t *us) gettimeofday(&time, NULL); *us = (time.tv_sec * 1000000 + time.tv_usec); + if (s_localTimeUsOffset == 0) { + s_localTimeUsOffset = *us; + } else { + *us = *us - s_localTimeMsOffset; + } + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } void *Osal_Malloc(uint32_t size) { - if (size == 0) { - return NULL; - } - return malloc(size); } diff --git a/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt b/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt index 8b1055e0..961ecbf1 100644 --- a/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt +++ b/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt @@ -7,19 +7,6 @@ set(CMAKE_C_COMPILER "gcc") set(CMAKE_CXX_COMPILER "g++") add_definitions(-D_GNU_SOURCE) -# Try to see if user has OpenCV installed -# if yes, default callback will display the image -find_package( OpenCV QUIET ) -if (OpenCV_FOUND) - message( "\n${PROJECT_NAME}...") - message( STATUS "Found OpenCV installed in the system, will use it to display image in AdvancedSensing APIs") - message( STATUS " - Includes: ${OpenCV_INCLUDE_DIRS}") - message( STATUS " - Libraries: ${OpenCV_LIBRARIES}") - add_definitions(-DOPEN_CV_INSTALLED) -else() - message( STATUS "Did not find OpenCV in the system, image data is inside RecvContainer as raw data") -endif () - set(COMMON_CXX_FLAGS "-std=c++11 -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} -fprofile-arcs -ftest-coverage -Wno-deprecated-declarations") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") @@ -50,31 +37,72 @@ else () message(FATAL_ERROR "FATAL: Please confirm your platform.") endif () -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common/3rdparty) + +link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}) +link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/libpayloadsdk.a -lstdc++) + +add_executable(${PROJECT_NAME} + ${MODULE_APP_SRC} + ${MODULE_SAMPLE_SRC} + ${MODULE_COMMON_SRC} + ${MODULE_HAL_SRC}) + +# Try to see if user has OpenCV installed因为额 +# if yes, default callback will display the image +find_package(OpenCV QUIET) +if (OpenCV_FOUND) + message("\n${PROJECT_NAME}...") + message(STATUS "Found OpenCV installed in the system, will use it to display image in AdvancedSensing APIs") + message(STATUS " - Includes: ${OpenCV_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${OpenCV_LIBRARIES}") + add_definitions(-DOPEN_CV_INSTALLED) +else () + message(STATUS "Did not find OpenCV in the system, image data is inside RecvContainer as raw data") +endif () + find_package(FFMPEG REQUIRED) +if (FFMPEG_FOUND) + message(STATUS "Found FFMPEG installed in the system") + message(STATUS " - Includes: ${FFMPEG_INCLUDE_DIR}") + message(STATUS " - Libraries: ${FFMPEG_LIBRARIES}") -if(FFMPEG_FOUND) - message("Found FFMPEG FFMPEG_INCLUDE_DIR = ${FFMPEG_INCLUDE_DIR}") - message("Found FFMPEG FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}") -else() - message("Cannot Find FFMPEG") -endif(FFMPEG_FOUND) + target_link_libraries(${PROJECT_NAME} ${FFMPEG_LIBRARIES}) +else () + message(STATUS "Cannot Find FFMPEG") +endif (FFMPEG_FOUND) include_directories(${FFMPEG_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/include) -link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}) -link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/libpayloadsdk.a -lstdc++) +find_package(OPUS REQUIRED) +if (OPUS_FOUND) + message(STATUS "Found OPUS installed in the system") + message(STATUS " - Includes: ${OPUS_INCLUDE_DIR}") + message(STATUS " - Libraries: ${OPUS_LIBRARY}") + + add_definitions(-DOPUS_INSTALLED) + target_link_libraries(${PROJECT_NAME} /usr/local/lib/libopus.a) +else () + message(STATUS "Cannot Find OPUS") +endif (OPUS_FOUND) + +find_package(LIBUSB REQUIRED) +if (LIBUSB_FOUND) + message(STATUS "Found LIBUSB installed in the system") + message(STATUS " - Includes: ${LIBUSB_INCLUDE_DIR}") + message(STATUS " - Libraries: ${LIBUSB_LIBRARY}") + + add_definitions(-DLIBUSB_INSTALLED) + target_link_libraries(${PROJECT_NAME} usb-1.0) +else () + message(STATUS "Cannot Find LIBUSB") +endif (LIBUSB_FOUND) if (NOT EXECUTABLE_OUTPUT_PATH) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) endif () -add_executable(${PROJECT_NAME} - ${MODULE_APP_SRC} - ${MODULE_SAMPLE_SRC} - ${MODULE_COMMON_SRC} - ${MODULE_HAL_SRC}) -target_link_libraries(${PROJECT_NAME} m usb-1.0 ${FFMPEG_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} m) add_custom_command(TARGET ${PROJECT_NAME} PRE_LINK COMMAND cmake .. diff --git a/samples/sample_c++/platform/linux/manifold2/application/main.cpp b/samples/sample_c++/platform/linux/manifold2/application/main.cpp index 7d8ef8f9..32ef2787 100644 --- a/samples/sample_c++/platform/linux/manifold2/application/main.cpp +++ b/samples/sample_c++/platform/linux/manifold2/application/main.cpp @@ -64,28 +64,29 @@ int main(int argc, char **argv) start: std::cout << "\n" - << "| Available commands: |\n" - << "| [0] Fc subscribe sample - subscribe quaternion and gps data |\n" - << "| [1] Flight controller sample - take off landing |\n" - << "| [2] Flight controller sample - take off position ctrl landing |\n" - << "| [3] Flight controller sample - take off go home force landing |\n" - << "| [4] Flight controller sample - take off velocity ctrl landing |\n" - << "| [5] Flight controller sample - arrest flying |\n" - << "| [6] Flight controller sample - set get parameters |\n" - << "| [7] Hms info sample - get health manger system info |\n" - << "| [8] Waypoint 2.0 sample - run airline mission by settings (only support on M300 RTK) |\n" - << "| [9] Waypoint 3.0 sample - run airline mission by kmz file (only support on M30/30T) |\n" - << "| [a] Gimbal manager sample - rotate gimbal on free mode |\n" - << "| [b] Gimbal manager sample - rotate gimbal on yaw follow mode |\n" - << "| [c] Camera stream view sample - display the camera video stream |\n" - << "| [d] Stereo vision view sample - display the stereo image (only support on M300 RTK) |\n" - << "| [e] Start camera all feautes sample - you can operate the camera on DJI Pilot |\n" - << "| [f] Start gimbal all feautes sample - you can operate the gimbal on DJI Pilot |\n" - << "| [g] Start widget all feautes sample - you can operate the widget on DJI Pilot |\n" - << "| [h] Start widget speaker sample - you can operate the speaker on MSDK demo |\n" - << "| [i] Start power management sample - you will see notification when aircraft power off |\n" - << "| [j] Start data transmission sample - you can send or recv custom data on MSDK demo |\n" - << "| [l] Run camera manager sample - shoot photo by the selected camera mounted position |\n" + << "| Available commands: |\n" + << "| [0] Fc subscribe sample - subscribe quaternion and gps data |\n" + << "| [1] Flight controller sample - take off landing |\n" + << "| [2] Flight controller sample - take off position ctrl landing |\n" + << "| [3] Flight controller sample - take off go home force landing |\n" + << "| [4] Flight controller sample - take off velocity ctrl landing |\n" + << "| [5] Flight controller sample - arrest flying |\n" + << "| [6] Flight controller sample - set get parameters |\n" + << "| [7] Hms info sample - get health manger system info |\n" + << "| [8] Waypoint 2.0 sample - run airline mission by settings (only support on M300 RTK) |\n" + << "| [9] Waypoint 3.0 sample - run airline mission by kmz file (only support on M30/30T) |\n" + << "| [a] Gimbal manager sample - rotate gimbal on free mode |\n" + << "| [b] Gimbal manager sample - rotate gimbal on yaw follow mode |\n" + << "| [c] Camera stream view sample - display the camera video stream |\n" + << "| [d] Stereo vision view sample - display the stereo image (only support on M300 RTK) |\n" + << "| [e] Start camera all feautes sample - you can operate the camera on DJI Pilot |\n" + << "| [f] Start gimbal all feautes sample - you can operate the gimbal on DJI Pilot |\n" + << "| [g] Start widget all feautes sample - you can operate the widget on DJI Pilot |\n" + << "| [h] Start widget speaker sample - you can operate the speaker on MSDK demo |\n" + << "| [i] Start power management sample - you will see notification when aircraft power off |\n" + << "| [j] Start data transmission sample - you can send or recv custom data on MSDK demo |\n" + << "| [l] Run camera manager sample - shoot photo by the selected camera mounted position |\n" + << "| [m] Run camera manager download sample - download camera media file (only support on M300 RTK) |\n" << std::endl; std::cin >> inputChar; @@ -206,6 +207,11 @@ int main(int argc, char **argv) DjiTest_CameraManagerRunSample(DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1, E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SHOOT_SINGLE_PHOTO); break; + case 'm': + DjiTest_CameraManagerRunSample(DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1, + E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_DOWNLOAD_AND_DELETE_MEDIA_FILE); + exit(1); + break; default: break; } diff --git a/samples/sample_c++/platform/linux/manifold2/hal/hal_usb_bulk.c b/samples/sample_c++/platform/linux/manifold2/hal/hal_usb_bulk.c index 2ed2034f..e0c843be 100644 --- a/samples/sample_c++/platform/linux/manifold2/hal/hal_usb_bulk.c +++ b/samples/sample_c++/platform/linux/manifold2/hal/hal_usb_bulk.c @@ -32,12 +32,16 @@ #define LINUX_USB_BULK_EP_OUT "/dev/usb-ffs/bulk/ep1" #define LINUX_USB_BULK_EP_IN "/dev/usb-ffs/bulk/ep2" -#define LINUX_USB_PID (0x0955) -#define LINUX_USB_VID (0x7020) +#define LINUX_USB_PID (0x7020) +#define LINUX_USB_VID (0x0955) /* Private types -------------------------------------------------------------*/ typedef struct { +#ifdef LIBUSB_INSTALLED libusb_device_handle *handle; +#else + void *handle; +#endif int32_t ep1; int32_t ep2; T_DjiHalUsbBulkInfo usbBulkInfo; @@ -59,6 +63,7 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan } if (usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_init(NULL); if (ret < 0) { return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; @@ -78,7 +83,7 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); - +#endif } else { ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); @@ -109,9 +114,11 @@ T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle) handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum); osalHandler->TaskSleepMs(100); libusb_exit(NULL); +#endif } else { close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1); close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2); @@ -136,18 +143,21 @@ T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uin handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut, (uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS); if (ret < 0) { - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; + USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret); + return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; } *realLen = actualLen; +#endif } else { *realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len); } - return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, @@ -164,13 +174,16 @@ T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *b handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn, buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER); if (ret < 0) { + USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret); return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; } *realLen = actualLen; +#endif } else { *realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len); } diff --git a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_media.c b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_media.c index 120a8b14..6f7c86f6 100644 --- a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_media.c +++ b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_media.c @@ -189,11 +189,16 @@ T_DjiReturnCode DjiTest_CameraEmuMediaStartService(void) return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; } - returnCode = osalHandler->TaskCreate("user_camera_media_task", UserCameraMedia_SendVideoTask, 2048, - NULL, &s_userSendVideoThread); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("user send video task create error."); - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; + if (DjiPlatform_GetSocketHandler() != NULL) { + returnCode = osalHandler->TaskCreate("user_camera_media_task", UserCameraMedia_SendVideoTask, 2048, + NULL, &s_userSendVideoThread); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("user send video task create error."); + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; + } + } else { + USER_LOG_WARN( + "Socket handler is null. Probably because socket handler is not be registered. Camera media sample may not be running."); } return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; diff --git a/samples/sample_c/module_sample/camera_manager/test_camera_manager.c b/samples/sample_c/module_sample/camera_manager/test_camera_manager.c index 8725537a..fce26a87 100644 --- a/samples/sample_c/module_sample/camera_manager/test_camera_manager.c +++ b/samples/sample_c/module_sample/camera_manager/test_camera_manager.c @@ -31,8 +31,8 @@ #include "dji_logger.h" #include "dji_liveview.h" /* Private constants ---------------------------------------------------------*/ -#define TEST_CAMERA_MANAGER_MEDIA_FILE_NAME_MAX_SIZE 32 -#define TEST_CAMERA_MANAGER_MEDIA_EXTEND_INFO_MAX_SIZE 128 +#define TEST_CAMERA_MANAGER_MEDIA_FILE_NAME_MAX_SIZE 256 +#define TEST_CAMERA_MANAGER_MEDIA_DOWNLOAD_FILE_NUM 5 /* Private types -------------------------------------------------------------*/ typedef struct { @@ -53,10 +53,14 @@ static const T_DjiTestCameraTypeStr s_cameraTypeStrList[] = { {DJI_CAMERA_TYPE_L1, "Zenmuse L1"}, {DJI_CAMERA_TYPE_M30, "Zenmuse M30"}, {DJI_CAMERA_TYPE_M30T, "Zenmuse M30T"}, + {DJI_CAMERA_TYPE_H20N, "Zenmuse H20N"}, }; static FILE *s_downloadMediaFile = NULL; static T_DjiCameraManagerFileList s_meidaFileList; +static uint32_t downloadStartMs = 0; +static uint32_t downloadEndMs = 0; +static char downloadFileName[TEST_CAMERA_MANAGER_MEDIA_FILE_NAME_MAX_SIZE] = {0}; /* Private functions declaration ---------------------------------------------*/ static uint8_t DjiTest_CameraManagerGetCameraTypeIndex(E_DjiCameraType cameraType); @@ -817,7 +821,7 @@ T_DjiReturnCode DjiTest_CameraManagerRunSample(E_DjiMountPosition mountPosition, mountPosition, returnCode); goto exitCameraModule; } - USER_LOG_INFO("Mounted position %d camera's firmware is V%d.%d.%d.%d\r\n", mountPosition, + USER_LOG_INFO("Mounted position %d camera's firmware is V%02d.%02d.%02d.%02d\r\n", mountPosition, firmwareVersion.firmware_version[0], firmwareVersion.firmware_version[1], firmwareVersion.firmware_version[2], firmwareVersion.firmware_version[3]); @@ -850,7 +854,8 @@ T_DjiReturnCode DjiTest_CameraManagerRunSample(E_DjiMountPosition mountPosition, case E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_SHUTTER_SPEED: { USER_LOG_INFO("--> Function a: Set camera shutter speed to 1/100 s"); DjiTest_WidgetLogAppend("--> Function a: Set camera shutter speed to 1/100 s"); - if (cameraType == DJI_CAMERA_TYPE_H20 || cameraType == DJI_CAMERA_TYPE_H20T) { + if (cameraType == DJI_CAMERA_TYPE_H20 || cameraType == DJI_CAMERA_TYPE_H20T || + cameraType == DJI_CAMERA_TYPE_M30 || cameraType == DJI_CAMERA_TYPE_M30T) { USER_LOG_INFO("Set mounted position %d camera's exposure mode to manual mode.", mountPosition); returnCode = DjiTest_CameraManagerSetExposureMode(mountPosition, @@ -886,7 +891,8 @@ T_DjiReturnCode DjiTest_CameraManagerRunSample(E_DjiMountPosition mountPosition, case E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_APERTURE: { USER_LOG_INFO("--> Function b: Set camera aperture to 400(F/4)"); DjiTest_WidgetLogAppend("--> Function b: Set camera aperture to 400(F/4)"); - if (cameraType == DJI_CAMERA_TYPE_H20 || cameraType == DJI_CAMERA_TYPE_H20T) { + if (cameraType == DJI_CAMERA_TYPE_H20 || cameraType == DJI_CAMERA_TYPE_H20T + || cameraType == DJI_CAMERA_TYPE_M30 || cameraType == DJI_CAMERA_TYPE_M30T) { USER_LOG_INFO("Set mounted position %d camera's exposure mode to manual mode.", mountPosition); returnCode = DjiTest_CameraManagerSetExposureMode(mountPosition, @@ -1188,24 +1194,29 @@ static T_DjiReturnCode DjiTest_CameraManagerMediaDownloadAndDeleteMediaFile(E_Dj { T_DjiReturnCode returnCode; T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); + uint16_t downloadCount = 0; - returnCode = DjiCameraManager_DownloadFileList(position, &s_meidaFileList); + returnCode = DjiCameraManager_RegDownloadFileDataCallback(position, DjiTest_CameraManagerDownloadFileDataCallback); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("Download file list failed, error code: 0x%08X.", returnCode); + USER_LOG_ERROR("Register download file data callback failed, error code: 0x%08X.", returnCode); return returnCode; } - returnCode = DjiCameraManager_RegDownloadFileDataCallback(position, DjiTest_CameraManagerDownloadFileDataCallback); + returnCode = DjiCameraManager_DownloadFileList(position, &s_meidaFileList); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("Register download file data callback failed, error code: 0x%08X.", returnCode); + USER_LOG_ERROR("Download file list failed, error code: 0x%08X.", returnCode); return returnCode; } if (s_meidaFileList.totalCount > 0) { - for (int i = 0; i < s_meidaFileList.totalCount; ++i) { + downloadCount = s_meidaFileList.totalCount; + printf( + "\033[1;33;40m -> Download file list finished, total file count is %d, the following %d is list details: \033[0m\r\n", + s_meidaFileList.totalCount, downloadCount); + for (int i = 0; i < downloadCount; ++i) { if (s_meidaFileList.fileListInfo[i].fileSize < 1 * 1024 * 1024) { - USER_LOG_INFO( - "Media file_%03d name: %s, index: %d, time:%04d-%02d-%02d_%02d:%02d:%02d, size: %.2f KB, type: %d", + printf( + "\033[1;32;40m ### Media file_%03d name: %s, index: %d, time:%04d-%02d-%02d_%02d:%02d:%02d, size: %.2f KB, type: %d \033[0m\r\n", i, s_meidaFileList.fileListInfo[i].fileName, s_meidaFileList.fileListInfo[i].fileIndex, s_meidaFileList.fileListInfo[i].createTime.year, @@ -1217,8 +1228,8 @@ static T_DjiReturnCode DjiTest_CameraManagerMediaDownloadAndDeleteMediaFile(E_Dj (dji_f32_t) s_meidaFileList.fileListInfo[i].fileSize / 1024, s_meidaFileList.fileListInfo[i].type); } else { - USER_LOG_INFO( - "Media file_%03d name: %s, index: %d, time:%04d-%02d-%02d_%02d:%02d:%02d, size: %.2f MB, type: %d", + printf( + "\033[1;32;40m ### Media file_%03d name: %s, index: %d, time:%04d-%02d-%02d_%02d:%02d:%02d, size: %.2f MB, type: %d \033[0m\r\n", i, s_meidaFileList.fileListInfo[i].fileName, s_meidaFileList.fileListInfo[i].fileIndex, s_meidaFileList.fileListInfo[i].createTime.year, @@ -1231,16 +1242,23 @@ static T_DjiReturnCode DjiTest_CameraManagerMediaDownloadAndDeleteMediaFile(E_Dj s_meidaFileList.fileListInfo[i].type); } } + printf("\r\n"); osalHandler->TaskSleepMs(1000); - returnCode = DjiCameraManager_DownloadFileByIndex(position, s_meidaFileList.fileListInfo[0].fileIndex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("Download media file by index failed, error code: 0x%08X.", returnCode); - return returnCode; + if (s_meidaFileList.totalCount < TEST_CAMERA_MANAGER_MEDIA_DOWNLOAD_FILE_NUM) { + downloadCount = s_meidaFileList.totalCount; + } else { + downloadCount = TEST_CAMERA_MANAGER_MEDIA_DOWNLOAD_FILE_NUM; } - osalHandler->TaskSleepMs(1000); + for (int i = 0; i < downloadCount; ++i) { + returnCode = DjiCameraManager_DownloadFileByIndex(position, s_meidaFileList.fileListInfo[i].fileIndex); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("Download media file by index failed, error code: 0x%08X.", returnCode); + return returnCode; + } + } returnCode = DjiCameraManager_DeleteFileByIndex(position, s_meidaFileList.fileListInfo[0].fileIndex); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { @@ -1250,7 +1268,7 @@ static T_DjiReturnCode DjiTest_CameraManagerMediaDownloadAndDeleteMediaFile(E_Dj osalHandler->TaskSleepMs(1000); } else { - USER_LOG_WARN("Media file is not existed in sdcard."); + USER_LOG_WARN("Media file is not existed in sdcard.\r\n"); } return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; @@ -1259,11 +1277,9 @@ static T_DjiReturnCode DjiTest_CameraManagerMediaDownloadAndDeleteMediaFile(E_Dj static T_DjiReturnCode DjiTest_CameraManagerDownloadFileDataCallback(T_DjiDownloadFilePacketInfo packetInfo, const uint8_t *data, uint16_t len) { - char fileName[TEST_CAMERA_MANAGER_MEDIA_FILE_NAME_MAX_SIZE]; - char extendInfo[TEST_CAMERA_MANAGER_MEDIA_EXTEND_INFO_MAX_SIZE]; int32_t i; - - sprintf(extendInfo, " FileIndex: %d", packetInfo.fileIndex); + float downloadSpeed = 0.0f; + T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if (packetInfo.downloadFileEvent == DJI_DOWNLOAD_FILE_EVENT_START) { for (i = 0; i < s_meidaFileList.totalCount; ++i) { @@ -1271,9 +1287,12 @@ static T_DjiReturnCode DjiTest_CameraManagerDownloadFileDataCallback(T_DjiDownlo break; } } - sprintf(fileName, "%s", s_meidaFileList.fileListInfo[i].fileName); - USER_LOG_INFO("Start download media file %s", s_meidaFileList.fileListInfo[i].fileName); - s_downloadMediaFile = fopen(fileName, "wb+"); + osalHandler->GetTimeMs(&downloadStartMs); + + memset(downloadFileName, 0, sizeof(downloadFileName)); + snprintf(downloadFileName, sizeof(downloadFileName), "%s", s_meidaFileList.fileListInfo[i].fileName); + USER_LOG_INFO("Start download media file"); + s_downloadMediaFile = fopen(downloadFileName, "wb+"); if (s_downloadMediaFile == NULL) { return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; } @@ -1282,13 +1301,24 @@ static T_DjiReturnCode DjiTest_CameraManagerDownloadFileDataCallback(T_DjiDownlo if (s_downloadMediaFile != NULL) { fwrite(data, 1, len, s_downloadMediaFile); } + printf("\033[1;32;40m ### [Complete rate : %0.1f%%] (%s), size: %d, fileIndex: %d\033[0m\r\n", + packetInfo.progressInPercent, downloadFileName, packetInfo.fileSize, packetInfo.fileIndex); + printf("\033[1A"); + USER_LOG_DEBUG("Transfer download media file data, len: %d, percent: %.1f", len, packetInfo.progressInPercent); } else if (packetInfo.downloadFileEvent == DJI_DOWNLOAD_FILE_EVENT_END) { if (s_downloadMediaFile != NULL) { fwrite(data, 1, len, s_downloadMediaFile); } - - USER_LOG_INFO("End download media file"); + osalHandler->GetTimeMs(&downloadEndMs); + + downloadSpeed = (float) packetInfo.fileSize / (float) (downloadEndMs - downloadStartMs); + printf("\033[1;32;40m ### [Complete rate : %0.1f%%] (%s), size: %d, fileIndex: %d\033[0m\r\n", + packetInfo.progressInPercent, downloadFileName, packetInfo.fileSize, packetInfo.fileIndex); + printf("\033[1A"); + printf("\r\n"); + USER_LOG_INFO("End download media file, Download Speed %.2f KB/S\r\n\r\n", downloadSpeed); fclose(s_downloadMediaFile); + s_downloadMediaFile = NULL; } return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; diff --git a/samples/sample_c/module_sample/fc_subscription/test_fc_subscription.c b/samples/sample_c/module_sample/fc_subscription/test_fc_subscription.c index 2deaf958..35ec8108 100644 --- a/samples/sample_c/module_sample/fc_subscription/test_fc_subscription.c +++ b/samples/sample_c/module_sample/fc_subscription/test_fc_subscription.c @@ -156,8 +156,9 @@ T_DjiReturnCode DjiTest_FcSubscriptionRunSample(void) if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("get value of topic velocity error."); } else { - USER_LOG_INFO("velocity: x = %f y = %f z = %f healthFlag = %d.", velocity.data.x, velocity.data.y, - velocity.data.z, velocity.health); + USER_LOG_INFO("velocity: x = %f y = %f z = %f healthFlag = %d, timestamp ms = %d us = %d.", velocity.data.x, + velocity.data.y, + velocity.data.z, velocity.health, timestamp.millisecond, timestamp.microsecond); } djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, diff --git a/samples/sample_c/module_sample/flight_control/test_flight_control.c b/samples/sample_c/module_sample/flight_control/test_flight_control.c index ed5d67f4..30777d73 100644 --- a/samples/sample_c/module_sample/flight_control/test_flight_control.c +++ b/samples/sample_c/module_sample/flight_control/test_flight_control.c @@ -30,6 +30,7 @@ #include "dji_logger.h" #include #include +#include /* Private constants ---------------------------------------------------------*/ /* Private types -------------------------------------------------------------*/ @@ -665,6 +666,12 @@ void DjiTest_FlightControlSetGetParamSample() E_DjiFlightControllerGoHomeAltitude goHomeAltitude; E_DjiFlightControllerRtkPositionEnableStatus rtkEnableStatus; E_DjiFlightControllerRCLostAction rcLostAction; + T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo; + + returnCode = DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("get aircraft base info error"); + } USER_LOG_INFO("Flight control set-get-param sample start"); DjiTest_WidgetLogAppend("Flight control set-get-param sample start"); @@ -823,25 +830,27 @@ void DjiTest_FlightControlSetGetParamSample() s_osalHandler->TaskSleepMs(1000); /*! Set rc lost action */ - USER_LOG_INFO("--> Step 15: Set rc lost action"); - DjiTest_WidgetLogAppend("--> Step 15: Set rc lost action"); - returnCode = DjiFlightController_SetRCLostAction(DJI_FLIGHT_CONTROLLER_RC_LOST_ACTION_GOHOME); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("Set rc lost action failed, error code: 0x%08X", returnCode); - goto out; - } - s_osalHandler->TaskSleepMs(1000); + if (aircraftInfoBaseInfo.aircraftType != DJI_AIRCRAFT_TYPE_M300_RTK) { + USER_LOG_INFO("--> Step 15: Set rc lost action"); + DjiTest_WidgetLogAppend("--> Step 15: Set rc lost action"); + returnCode = DjiFlightController_SetRCLostAction(DJI_FLIGHT_CONTROLLER_RC_LOST_ACTION_GOHOME); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("Set rc lost action failed, error code: 0x%08X", returnCode); + goto out; + } + s_osalHandler->TaskSleepMs(1000); - USER_LOG_INFO("--> Step 16: Get rc lost action\r\n"); - DjiTest_WidgetLogAppend("--> Step 16: Get rc lost action\r\n"); - returnCode = DjiFlightController_GetRCLostAction(&rcLostAction); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("Get rc lost action failed, error code: 0x%08X", returnCode); - goto out; + USER_LOG_INFO("--> Step 16: Get rc lost action\r\n"); + DjiTest_WidgetLogAppend("--> Step 16: Get rc lost action\r\n"); + returnCode = DjiFlightController_GetRCLostAction(&rcLostAction); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("Get rc lost action failed, error code: 0x%08X", returnCode); + goto out; + } + USER_LOG_INFO("Current rc lost action is %d\r\n", rcLostAction); + DjiTest_WidgetLogAppend("Current rc lost action is %d\r\n", rcLostAction); + s_osalHandler->TaskSleepMs(1000); } - USER_LOG_INFO("Current rc lost action is %d\r\n", rcLostAction); - DjiTest_WidgetLogAppend("Current rc lost action is %d\r\n", rcLostAction); - s_osalHandler->TaskSleepMs(1000); out: USER_LOG_INFO("Flight control set-get-param sample end"); diff --git a/samples/sample_c/module_sample/utils/util_file.h b/samples/sample_c/module_sample/utils/util_file.h index bd212307..42a391f9 100644 --- a/samples/sample_c/module_sample/utils/util_file.h +++ b/samples/sample_c/module_sample/utils/util_file.h @@ -67,4 +67,4 @@ T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, #endif // UTIL_FILE_H -/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ \ No newline at end of file +/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ diff --git a/samples/sample_c/module_sample/widget/test_widget_speaker.c b/samples/sample_c/module_sample/widget/test_widget_speaker.c index e84d2a07..6445905b 100644 --- a/samples/sample_c/module_sample/widget/test_widget_speaker.c +++ b/samples/sample_c/module_sample/widget/test_widget_speaker.c @@ -36,7 +36,7 @@ #ifdef OPUS_INSTALLED -#include +#include #endif @@ -80,13 +80,10 @@ static bool s_isDecodeFinished = true; static void SetSpeakerState(E_DjiWidgetSpeakerState speakerState); static T_DjiReturnCode GetSpeakerState(T_DjiWidgetSpeakerState *speakerState); static T_DjiReturnCode SetWorkMode(E_DjiWidgetSpeakerWorkMode workMode); -static T_DjiReturnCode GetWorkMode(E_DjiWidgetSpeakerWorkMode *workMode); static T_DjiReturnCode SetPlayMode(E_DjiWidgetSpeakerPlayMode playMode); -static T_DjiReturnCode GetPlayMode(E_DjiWidgetSpeakerPlayMode *playMode); static T_DjiReturnCode StartPlay(void); static T_DjiReturnCode StopPlay(void); static T_DjiReturnCode SetVolume(uint8_t volume); -static T_DjiReturnCode GetVolume(uint8_t *volume); static T_DjiReturnCode ReceiveTtsData(E_DjiWidgetTransmitDataEvent event, uint32_t offset, uint8_t *buf, uint16_t size); static T_DjiReturnCode ReceiveAudioData(E_DjiWidgetTransmitDataEvent event, @@ -107,13 +104,10 @@ T_DjiReturnCode DjiTest_WidgetSpeakerStartService(void) s_speakerHandler.GetSpeakerState = GetSpeakerState; s_speakerHandler.SetWorkMode = SetWorkMode; - s_speakerHandler.GetWorkMode = GetWorkMode; s_speakerHandler.StartPlay = StartPlay; s_speakerHandler.StopPlay = StopPlay; s_speakerHandler.SetPlayMode = SetPlayMode; - s_speakerHandler.GetPlayMode = GetPlayMode; s_speakerHandler.SetVolume = SetVolume; - s_speakerHandler.GetVolume = GetVolume; s_speakerHandler.ReceiveTtsData = ReceiveTtsData; s_speakerHandler.ReceiveVoiceData = ReceiveAudioData; @@ -322,12 +316,13 @@ static T_DjiReturnCode DjiTest_PlayTtsData(void) SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_IN_TTS_CONVERSION); -#ifdef EKHO_INSTALLED +#if EKHO_INSTALLED /*! Attention: you can use other tts opensource function to convert txt to speech, example used ekho v7.5 */ - snprintf(cmdStr, sizeof(cmdStr), " ekho %s -s 20 -p 20 -a 100", data); + snprintf(cmdStr, sizeof(cmdStr), " ekho %s -s 20 -p 20 -a 100 -o %s", data, WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME); #else - snprintf(cmdStr, sizeof(cmdStr), "tts_offline_sample '%s' %s", data, - WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME); + USER_LOG_WARN( + "Ekho is not installed, please visit https://www.eguidedog.net/ekho.php to install it or use other TTS tools to convert audio"); +#endif DjiUserUtil_RunSystemCmd(cmdStr); SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_PLAYING); @@ -335,7 +330,6 @@ static T_DjiReturnCode DjiTest_PlayTtsData(void) memset(cmdStr, 0, sizeof(cmdStr)); snprintf(cmdStr, sizeof(cmdStr), "ffplay -nodisp -autoexit -ar 16000 -ac 1 -f s16le -i %s 2>/dev/null", WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME); -#endif return DjiUserUtil_RunSystemCmd(cmdStr); } @@ -453,28 +447,6 @@ static T_DjiReturnCode SetWorkMode(E_DjiWidgetSpeakerWorkMode workMode) return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } -static T_DjiReturnCode GetWorkMode(E_DjiWidgetSpeakerWorkMode *workMode) -{ - T_DjiReturnCode returnCode; - T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); - - returnCode = osalHandler->MutexLock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - *workMode = s_speakerState.workMode; - - returnCode = osalHandler->MutexUnlock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; -} - static T_DjiReturnCode SetPlayMode(E_DjiWidgetSpeakerPlayMode playMode) { T_DjiReturnCode returnCode; @@ -498,28 +470,6 @@ static T_DjiReturnCode SetPlayMode(E_DjiWidgetSpeakerPlayMode playMode) return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } -static T_DjiReturnCode GetPlayMode(E_DjiWidgetSpeakerPlayMode *playMode) -{ - T_DjiReturnCode returnCode; - T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); - - returnCode = osalHandler->MutexLock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - *playMode = s_speakerState.playMode; - - returnCode = osalHandler->MutexUnlock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; -} - static T_DjiReturnCode StartPlay(void) { uint32_t pid; @@ -581,9 +531,10 @@ static T_DjiReturnCode SetVolume(uint8_t volume) } realVolume = 1.5f * (float) volume; - USER_LOG_INFO("Set widget speaker volume: %d", volume); s_speakerState.volume = volume; +#ifdef PLATFORM_ARCH_x86_64 + USER_LOG_INFO("Set widget speaker volume: %d", volume); memset(cmdStr, 0, sizeof(cmdStr)); snprintf(cmdStr, sizeof(cmdStr), "pactl set-sink-volume %s %d%%", WIDGET_SPEAKER_USB_AUDIO_DEVICE_NAME, (int32_t) realVolume); @@ -592,28 +543,9 @@ static T_DjiReturnCode SetVolume(uint8_t volume) if (returnCode < 0) { USER_LOG_ERROR("Set widget speaker volume error: %d", ret); } - - returnCode = osalHandler->MutexUnlock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; -} - -static T_DjiReturnCode GetVolume(uint8_t *volume) -{ - T_DjiReturnCode returnCode; - T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); - - returnCode = osalHandler->MutexLock(s_speakerMutex); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode); - return returnCode; - } - - *volume = s_speakerState.volume; +#else + USER_LOG_WARN("Add set speaker volume function here!"); +#endif returnCode = osalHandler->MutexUnlock(s_speakerMutex); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { @@ -737,7 +669,7 @@ static void *DjiTest_WidgetSpeakerTask(void *arg) if (s_speakerState.state == DJI_WIDGET_SPEAKER_STATE_PLAYING) { if (s_speakerState.playMode == DJI_WIDGET_SPEAKER_PLAY_MODE_LOOP_PLAYBACK) { if (s_speakerState.workMode == DJI_WIDGET_SPEAKER_WORK_MODE_VOICE) { - USER_LOG_WARN("Waiting opus decoder finished..."); + USER_LOG_DEBUG("Waiting opus decoder finished..."); while (s_isDecodeFinished == false) { osalHandler->TaskSleepMs(1); } @@ -754,7 +686,7 @@ static void *DjiTest_WidgetSpeakerTask(void *arg) osalHandler->TaskSleepMs(1000); } else { if (s_speakerState.workMode == DJI_WIDGET_SPEAKER_WORK_MODE_VOICE) { - USER_LOG_WARN("Waiting opus decoder finished..."); + USER_LOG_DEBUG("Waiting opus decoder finished..."); while (s_isDecodeFinished == false) { osalHandler->TaskSleepMs(1); } diff --git a/samples/sample_c/module_sample/widget_interaction_test/widget_file/cn_big_screen/widget_config.json b/samples/sample_c/module_sample/widget_interaction_test/widget_file/cn_big_screen/widget_config.json index 508fb59e..c744acb2 100644 --- a/samples/sample_c/module_sample/widget_interaction_test/widget_file/cn_big_screen/widget_config.json +++ b/samples/sample_c/module_sample/widget_interaction_test/widget_file/cn_big_screen/widget_config.json @@ -7,6 +7,10 @@ "floating_window": { "is_enable": true }, + "speaker": { + "is_enable_tts": true, + "is_enable_voice": true + }, "widget_list": [ { "widget_index": 0, diff --git a/samples/sample_c/module_sample/widget_interaction_test/widget_file/en_big_screen/widget_config.json b/samples/sample_c/module_sample/widget_interaction_test/widget_file/en_big_screen/widget_config.json index a7a33fd6..ffd2de03 100644 --- a/samples/sample_c/module_sample/widget_interaction_test/widget_file/en_big_screen/widget_config.json +++ b/samples/sample_c/module_sample/widget_interaction_test/widget_file/en_big_screen/widget_config.json @@ -7,6 +7,10 @@ "floating_window": { "is_enable": true }, + "speaker": { + "is_enable_tts": true, + "is_enable_voice": true + }, "widget_list": [ { "widget_index": 0, diff --git a/samples/sample_c/platform/linux/common/3rdparty/ffmpeg/FindFFMPEG.cmake b/samples/sample_c/platform/linux/common/3rdparty/FindFFMPEG.cmake similarity index 100% rename from samples/sample_c/platform/linux/common/3rdparty/ffmpeg/FindFFMPEG.cmake rename to samples/sample_c/platform/linux/common/3rdparty/FindFFMPEG.cmake diff --git a/samples/sample_c/platform/linux/common/3rdparty/FindLIBUSB.cmake b/samples/sample_c/platform/linux/common/3rdparty/FindLIBUSB.cmake new file mode 100644 index 00000000..43f94712 --- /dev/null +++ b/samples/sample_c/platform/linux/common/3rdparty/FindLIBUSB.cmake @@ -0,0 +1,34 @@ +# +# Find the native LIBUSB includes and library +# +# This module defines +# LIBUSB_INCLUDE_DIR, where to find libusb.h +# LIBUSB_LIBRARY, the libraries to link against to use LIBUSB. +# LIBUSB_FOUND, If false, do not try to use LIBUSB. + +FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h + PATHS + /usr/local/include/libusb-1.0 + /usr/include/libusb-1.0 + /opt/local/include + /opt/include + ) + +get_filename_component(LIBUSB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR} ABSOLUTE) + +FIND_LIBRARY(LIBUSB_LIBRARY usb-1.0 + /usr/local/lib + /usr/lib + ) + +IF (LIBUSB_INCLUDE_DIR) + IF (LIBUSB_LIBRARY) + SET(LIBUSB_FOUND "YES") + ENDIF (LIBUSB_LIBRARY) +ENDIF (LIBUSB_INCLUDE_DIR) + +MARK_AS_ADVANCED( + LIBUSB_INCLUDE_DIR + LIBUSB_LIBRARY + LIBUSB_FOUND +) \ No newline at end of file diff --git a/samples/sample_c/platform/linux/common/3rdparty/FindOPUS.cmake b/samples/sample_c/platform/linux/common/3rdparty/FindOPUS.cmake new file mode 100644 index 00000000..269b6263 --- /dev/null +++ b/samples/sample_c/platform/linux/common/3rdparty/FindOPUS.cmake @@ -0,0 +1,34 @@ +# +# Find the native OPUS includes and library +# +# This module defines +# OPUS_INCLUDE_DIR, where to find opus.h +# OPUS_LIBRARY, the libraries to link against to use OPUS. +# OPUS_FOUND, If false, do not try to use OPUS. + +FIND_PATH(OPUS_INCLUDE_DIR opus.h + PATHS + /usr/local/include/opus + /usr/include/opus + /opt/local/include + /opt/include + ) + +get_filename_component(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR} ABSOLUTE) + +FIND_LIBRARY(OPUS_LIBRARY opus + /usr/local/lib + /usr/lib + ) + +IF (OPUS_INCLUDE_DIR) + IF (OPUS_LIBRARY) + SET(OPUS_FOUND "YES") + ENDIF (OPUS_LIBRARY) +ENDIF (OPUS_INCLUDE_DIR) + +MARK_AS_ADVANCED( + OPUS_INCLUDE_DIR + OPUS_LIBRARY + OPUS_FOUND +) \ No newline at end of file diff --git a/samples/sample_c/platform/linux/common/osal/osal.c b/samples/sample_c/platform/linux/common/osal/osal.c index 3f4ff9e0..f70952b2 100644 --- a/samples/sample_c/platform/linux/common/osal/osal.c +++ b/samples/sample_c/platform/linux/common/osal/osal.c @@ -30,6 +30,10 @@ /* Private types -------------------------------------------------------------*/ +/* Private values -------------------------------------------------------------*/ +static uint32_t s_localTimeMsOffset = 0; +static uint64_t s_localTimeUsOffset = 0; + /* Private functions declaration ---------------------------------------------*/ /* Exported functions definition ---------------------------------------------*/ @@ -279,6 +283,12 @@ T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms) gettimeofday(&time, NULL); *ms = (time.tv_sec * 1000 + time.tv_usec / 1000); + if (s_localTimeMsOffset == 0) { + s_localTimeMsOffset = *ms; + } else { + *ms = *ms - s_localTimeMsOffset; + } + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } @@ -289,6 +299,12 @@ T_DjiReturnCode Osal_GetTimeUs(uint64_t *us) gettimeofday(&time, NULL); *us = (time.tv_sec * 1000000 + time.tv_usec); + if (s_localTimeUsOffset == 0) { + s_localTimeUsOffset = *us; + } else { + *us = *us - s_localTimeMsOffset; + } + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } diff --git a/samples/sample_c/platform/linux/manifold2/CMakeLists.txt b/samples/sample_c/platform/linux/manifold2/CMakeLists.txt index 0064284d..674cf8d9 100644 --- a/samples/sample_c/platform/linux/manifold2/CMakeLists.txt +++ b/samples/sample_c/platform/linux/manifold2/CMakeLists.txt @@ -53,7 +53,33 @@ add_executable(${PROJECT_NAME} ${MODULE_SAMPLE_SRC} ${MODULE_COMMON_SRC} ${MODULE_HAL_SRC}) -target_link_libraries(${PROJECT_NAME} m usb-1.0) + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common/3rdparty) +find_package(OPUS REQUIRED) +if (OPUS_FOUND) + message(STATUS "Found OPUS installed in the system") + message(STATUS " - Includes: ${OPUS_INCLUDE_DIR}") + message(STATUS " - Libraries: ${OPUS_LIBRARY}") + + add_definitions(-DOPUS_INSTALLED) + target_link_libraries(${PROJECT_NAME} /usr/local/lib/libopus.a) +else () + message(STATUS "Cannot Find OPUS") +endif (OPUS_FOUND) + +find_package(LIBUSB REQUIRED) +if (LIBUSB_FOUND) + message(STATUS "Found LIBUSB installed in the system") + message(STATUS " - Includes: ${LIBUSB_INCLUDE_DIR}") + message(STATUS " - Libraries: ${LIBUSB_LIBRARY}") + + add_definitions(-DLIBUSB_INSTALLED) + target_link_libraries(${PROJECT_NAME} usb-1.0) +else () + message(STATUS "Cannot Find LIBUSB") +endif (LIBUSB_FOUND) + +target_link_libraries(${PROJECT_NAME} m) add_custom_command(TARGET ${PROJECT_NAME} PRE_LINK COMMAND cmake .. diff --git a/samples/sample_c/platform/linux/manifold2/application/main.c b/samples/sample_c/platform/linux/manifold2/application/main.c index d54ee283..eeeddbee 100644 --- a/samples/sample_c/platform/linux/manifold2/application/main.c +++ b/samples/sample_c/platform/linux/manifold2/application/main.c @@ -162,6 +162,11 @@ int main(int argc, char **argv) if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("widget interaction sample init error"); } + + returnCode = DjiTest_WidgetSpeakerStartService(); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("widget speaker test init error"); + } } else { #ifdef CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON returnCode = DjiTest_CameraEmuBaseStartService(); @@ -216,11 +221,9 @@ int main(int argc, char **argv) #endif #ifdef CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON - if (aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_NONE) { - returnCode = DjiTest_WidgetSpeakerStartService(); - if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { - USER_LOG_ERROR("widget speaker test init error"); - } + returnCode = DjiTest_WidgetSpeakerStartService(); + if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + USER_LOG_ERROR("widget speaker test init error"); } #endif diff --git a/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.c b/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.c index 2ed2034f..e0c843be 100644 --- a/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.c +++ b/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.c @@ -32,12 +32,16 @@ #define LINUX_USB_BULK_EP_OUT "/dev/usb-ffs/bulk/ep1" #define LINUX_USB_BULK_EP_IN "/dev/usb-ffs/bulk/ep2" -#define LINUX_USB_PID (0x0955) -#define LINUX_USB_VID (0x7020) +#define LINUX_USB_PID (0x7020) +#define LINUX_USB_VID (0x0955) /* Private types -------------------------------------------------------------*/ typedef struct { +#ifdef LIBUSB_INSTALLED libusb_device_handle *handle; +#else + void *handle; +#endif int32_t ep1; int32_t ep2; T_DjiHalUsbBulkInfo usbBulkInfo; @@ -59,6 +63,7 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan } if (usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_init(NULL); if (ret < 0) { return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; @@ -78,7 +83,7 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); - +#endif } else { ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); @@ -109,9 +114,11 @@ T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle) handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum); osalHandler->TaskSleepMs(100); libusb_exit(NULL); +#endif } else { close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1); close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2); @@ -136,18 +143,21 @@ T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uin handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut, (uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS); if (ret < 0) { - return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; + USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret); + return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; } *realLen = actualLen; +#endif } else { *realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len); } - return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, @@ -164,13 +174,16 @@ T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *b handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { +#ifdef LIBUSB_INSTALLED ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn, buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER); if (ret < 0) { + USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret); return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; } *realLen = actualLen; +#endif } else { *realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len); } diff --git a/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.h b/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.h index 6792529e..9c3ccbd3 100644 --- a/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.h +++ b/samples/sample_c/platform/linux/manifold2/hal/hal_usb_bulk.h @@ -38,9 +38,12 @@ #include #include #include +#include "dji_platform.h" + +#ifdef LIBUSB_INSTALLED #include +#endif -#include "dji_platform.h" #ifdef __cplusplus extern "C" { diff --git a/samples/sample_c/platform/rtos_freertos/stm32f4_discovery/project/armgcc/CMakeLists.txt b/samples/sample_c/platform/rtos_freertos/stm32f4_discovery/project/armgcc/CMakeLists.txt index 51c4f352..30f16195 100644 --- a/samples/sample_c/platform/rtos_freertos/stm32f4_discovery/project/armgcc/CMakeLists.txt +++ b/samples/sample_c/platform/rtos_freertos/stm32f4_discovery/project/armgcc/CMakeLists.txt @@ -46,7 +46,7 @@ include_directories(../../../../../module_sample ../../drivers/USB_HOST/App ../../drivers/BSP ../../hal/ - ../../osal/ + ../../../common/osal/ ../../middlewares/Third_Party/FreeRTOS/Source/include ../../middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS ../../middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F @@ -79,7 +79,7 @@ file(GLOB_RECURSE MODULE_SAMPLE_SRC ) file(GLOB_RECURSE SOURCES - "../../osal/*.*" + "../../../common/osal/*.*" "../../drivers/BSP/*.*" "../../hal/*.*" "../../drivers/USB_HOST/*.*"