NEW: release DJI Payload-SDK version 3.12.0
This commit is contained in:
70
samples/sample_c/platform/linux/manifold3/CMakeLists.txt
Normal file
70
samples/sample_c/platform/linux/manifold3/CMakeLists.txt
Normal file
@ -0,0 +1,70 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(dji_sdk_demo_on_manifold3 C)
|
||||
|
||||
set(CMAKE_C_FLAGS "-pthread -std=gnu99")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -pthread")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-pthread")
|
||||
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
|
||||
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
|
||||
add_definitions(-D_GNU_SOURCE)
|
||||
|
||||
if (NOT USE_SYSTEM_ARCH)
|
||||
add_definitions(-DSYSTEM_ARCH_LINUX)
|
||||
endif ()
|
||||
|
||||
if (BUILD_TEST_CASES_ON MATCHES TRUE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
|
||||
endif ()
|
||||
|
||||
set(PACKAGE_NAME payloadsdk)
|
||||
|
||||
set(TOOLCHAIN_NAME aarch64-linux-gnu-gcc)
|
||||
add_definitions(-DPLATFORM_ARCH_aarch64=1)
|
||||
|
||||
file(GLOB_RECURSE MODULE_COMMON_SRC ../common/*.c)
|
||||
file(GLOB_RECURSE MODULE_HAL_SRC hal/*.c)
|
||||
file(GLOB_RECURSE MODULE_APP_SRC application/*.c)
|
||||
file(GLOB_RECURSE MODULE_SAMPLE_SRC ../../../module_sample/*.c)
|
||||
|
||||
include_directories(../../../module_sample)
|
||||
include_directories(../common)
|
||||
include_directories(application)
|
||||
|
||||
include_directories(../../../../../psdk_lib/include)
|
||||
link_directories(../../../../../psdk_lib/lib/${TOOLCHAIN_NAME})
|
||||
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/lib${PACKAGE_NAME}.a)
|
||||
|
||||
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})
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common/3rdparty)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} m dl)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
PRE_LINK COMMAND cmake ..
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
# set app.json and build_dpk.sh path
|
||||
set(JSON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/app_json/app.json)
|
||||
set(SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../tools/build_dpk/build_dpk.sh)
|
||||
|
||||
# set psdk_libput dpk path
|
||||
set(OUTPUT_PACKAGE ${CMAKE_BINARY_DIR}/dpk)
|
||||
|
||||
# generate .dpk app package
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
POST_BUILD # generate .dpk package after make
|
||||
COMMAND bash ${SCRIPT_FILE} -i ${JSON_FILE} -o ${OUTPUT_PACKAGE}
|
||||
DEPENDS ${JSON_FILE}
|
||||
COMMENT "Running build_dpk.sh, generating .dpk app package from app.json file"
|
||||
)
|
||||
211
samples/sample_c/platform/linux/manifold3/app_json/README.md
Normal file
211
samples/sample_c/platform/linux/manifold3/app_json/README.md
Normal file
@ -0,0 +1,211 @@
|
||||
# app.json 1.1
|
||||
|
||||
app.json is a necessary application configuration file for generating the .dpk application installation packgae.
|
||||
|
||||
# app.json filling specification:
|
||||
|
||||
## Documentation
|
||||
please visit Related URL, to be filled in, please refer to the following description.
|
||||
|
||||
Description of the tags in the app.json configuration file:
|
||||
|
||||
## user_app_id
|
||||
* Description:
|
||||
The APP ID generated by the developer website's user center is the unique identifier for the application.
|
||||
It is used to ensure the uniqueness of the application, and it must match the generated APP ID.
|
||||
It must be consistent with the USER_APP_ID in the code (39 line in samples/sample_c/platform/linux/manifold3/application/dji_sdk_app_info.h or 39 line in samples/sample_c++/platform/linux/manifold3/application/dji_sdk_app_info.h), otherwise, the application cannot be installed.
|
||||
* Data type:
|
||||
String
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## firmware_version
|
||||
* Description:
|
||||
App version, used for displaying application version information to users.
|
||||
It consists only of numbers and dots, following the four-segment format xx.xx.xx.xx, where each segment can range from 0 to 99.
|
||||
The firmware_version need to update when app update and it must match the firmwareVersion in the code(99 line in samples/sample_c/platform/linux/manifold3/application/main.c or 183 line in samples/sample_c++/platform/linux/manifold3/application/application.cpp). otherwise, the application cannot be installed.
|
||||
* Data type:
|
||||
String
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## is_ai_rendering
|
||||
* Description:
|
||||
Indicates whether the application uses AI rendering on the pilot.
|
||||
If it does, fill in true; if not, fill in false.
|
||||
If left blank, the default value is true.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
Yes, when the field is optional, its value is the default value, which is true
|
||||
|
||||
## platform
|
||||
* Description:
|
||||
Indicates the operating platform of the application. Supported values are:
|
||||
* manifold3, which means the application will run on the manifold3 device.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## name_cn
|
||||
* Description:
|
||||
Indicates the Chinese name of the application, which can be customized and should be a string not exceeding 47 bytes in length.
|
||||
It is recommended that the application name has a connection to its functionality, and you should try to avoid duplication with other application names.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Chinese, this field will display the application name.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## name_en
|
||||
* Description:
|
||||
Indicates the English name of the application, which can be customized. The filling rules are as follows:
|
||||
* Maximum length limit is 32 bytes.
|
||||
* Only allow letters(a-zA-Z), numbers(0-9), hyphens(-), and dots(.), no other characters are permitted, and it must begin with a letter or number.
|
||||
It is recommended that the application name has a connection to its functionality, and you should try to avoid duplication with other application names.
|
||||
It is advisable to avoid changing the application name afterward.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to English, or other languages that are not Chinese, Japanese, or French.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## name_jp
|
||||
* Description:
|
||||
Indicates the Japanese name of the application, which should be a string not exceeding 47 bytes in length.
|
||||
It is recommended that the name is relevant to the functionality and that you try to avoid duplication with other application names.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Japanese, this field will display the application name.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## name_fr
|
||||
* Description:
|
||||
Indicates the French name of the application, which should be a string not exceeding 47 bytes in length.
|
||||
It is recommended that the name is relevant to the functionality and that you try to avoid duplication with other application names.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to French, this field will display the application name.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## description_cn
|
||||
* Description:
|
||||
Indicates the Chinese description of the application, which should be a string not exceeding 367 bytes in length, containing a detailed custom description of the application.
|
||||
The specific filling rules are as follows:
|
||||
* Each item within the brackets [] represents the content of each line, with the next item representing the content of the next line. If a line break is needed, multiple items can be filled in within the brackets [].
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Chinese, this field will display the application description.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## description_en
|
||||
* Description:
|
||||
Indicates the English description of the application, which should be a string not exceeding 367 bytes in length, containing a detailed custom description of the application.
|
||||
The specific filling rules are as follows:
|
||||
* Each item within the brackets [] represents the content of each line, with the next item representing the content of the next line. If a line break is needed, multiple items can be filled in within the brackets [].
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to English, or other languages that are not Chinese, Japanese, or French, this field will display the application description.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## description_jp
|
||||
* Description:
|
||||
Indicates the Japanese description of the application, which should be a string not exceeding 367 bytes in length, containing a detailed custom description of the application.
|
||||
The specific filling rules are as follows:
|
||||
* Each item within the brackets [] represents the content of each line, with the next item representing the content of the next line. If a line break is needed, multiple items can be filled in within the brackets [].
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Japanese, this field will display the application description.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## description_fr
|
||||
* Description:
|
||||
Indicates the French description of the application, which should be a string not exceeding 367 bytes in length, containing a detailed custom description of the application.
|
||||
The specific filling rules are as follows:
|
||||
* Each item within the brackets [] represents the content of each line, with the next item representing the content of the next line. If a line break is needed, multiple items can be filled in within the brackets [].
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to French, this field will display the application description.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## maintainer_cn
|
||||
* Description:
|
||||
Indicates the developer information of the application in Chinese, which should be a string not exceeding 127 bytes in length.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Chinese, this field will display the developer information of the application.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## maintainer_en
|
||||
* Description:
|
||||
Indicates the developer information of the application in English, which should be a string not exceeding 127 bytes in length.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to English, or other languages that are not Chinese, Japanese, or French, this field will display the developer information of the application.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## maintainer_jp
|
||||
* Description:
|
||||
Indicates the developer information of the application in Japanese, which should be a string not exceeding 127 bytes in length.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to Japanese, this field will display the developer information of the application.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## maintainer_fr
|
||||
* Description:
|
||||
Indicates the developer information of the application in French, which should be a string not exceeding 127 bytes in length.
|
||||
This field can be used to display application information, such as in the application management interface, when the PILOT language is set to French, this field will display the developer information of the application.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## ver_min
|
||||
* Description:
|
||||
Indicates the minimum version of the Manifold3 device firmware package required for the application to run properly.
|
||||
If the firmware package version of the Manifold3 device is lower than this version, the application will not be able to install correctly.
|
||||
The value is in the format of xx.xx.xx.xx, where each segment can range from 0 to 99.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## ver_max
|
||||
* Description:
|
||||
Indicates the maximum version of the Manifold3 device firmware package required for the application to run properly.
|
||||
If the firmware package version of the Manifold3 device is higher than this version, the application will not be able to install correctly.
|
||||
The value is in the format of xx.xx.xx.xx, where each segment can range from 0 to 99.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## bin
|
||||
* Description:
|
||||
The relative path of the executable bin file generated by the compilation, indicating the application executable bin file.
|
||||
It must be a relative path, specifically the path relative to the app.json file, and there must be a corresponding bin file present at that path.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
No, this field is required
|
||||
|
||||
## userconfig
|
||||
* Description:
|
||||
The relative path of the relevant files that need to be read at runtime by the application, which is not integrated into the bin file.
|
||||
It must be a relative path, specifically the path relative to the app.json file, and there must be corresponding files present at that path.
|
||||
If there are no relevant files, this field can be left blank.
|
||||
* Data type:
|
||||
string
|
||||
* Whether the field is optional?
|
||||
yes, this field is optional
|
||||
44
samples/sample_c/platform/linux/manifold3/app_json/app.json
Normal file
44
samples/sample_c/platform/linux/manifold3/app_json/app.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"user_app_id": "226",
|
||||
"firmware_version": "01.00.00.00",
|
||||
"is_ai_rendering": "false",
|
||||
"platform": "manifold3",
|
||||
"name":{
|
||||
"name_cn": "测试demo",
|
||||
"name_en": "psdk-demo",
|
||||
"name_jp": "テストデモ",
|
||||
"name_fr": "Démo de test"
|
||||
},
|
||||
"description": {
|
||||
"description_cn": [
|
||||
"这是第一行",
|
||||
"这是第二行",
|
||||
"这是第三行",
|
||||
"这是第四行"
|
||||
],
|
||||
"description_en": [
|
||||
"This is the first line",
|
||||
"This is the second line",
|
||||
"This is the third line"
|
||||
],
|
||||
"description_jp": [
|
||||
"これは一行目です",
|
||||
"これは二行目です"
|
||||
],
|
||||
"description_fr": [
|
||||
"Ceci est la première ligne"
|
||||
]
|
||||
},
|
||||
"maintainer": {
|
||||
"maintainer_cn": "大疆创新科技有限公司",
|
||||
"maintainer_en": "DJI Innovation Technology Co., Ltd.",
|
||||
"maintainer_jp": "大疆イノベーションテクノロジー有限会社",
|
||||
"maintainer_fr": "Société à Responsabilité Limitée DJI Innovation Technology"
|
||||
},
|
||||
"ver_min": "00.00.00.00",
|
||||
"ver_max": "99.99.99.99",
|
||||
"bin": "../../../../../../build/bin/dji_sdk_demo_on_manifold3",
|
||||
"userconfig": [
|
||||
"../../../../../../samples"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_sdk_app_info.h
|
||||
* @brief This is the header file for defining the structure and (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_SDK_APP_INFO_H
|
||||
#define DJI_SDK_APP_INFO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 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"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_SDK_APP_INFO_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,83 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_sdk_config.h
|
||||
* @brief This is the header file for "dji_config.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_SDK_CONFIG_H
|
||||
#define DJI_SDK_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define DJI_USE_ONLY_UART (0)
|
||||
#define DJI_USE_UART_AND_USB_BULK_DEVICE (1)
|
||||
#define DJI_USE_UART_AND_NETWORK_DEVICE (2)
|
||||
#define DJI_USE_ONLY_USB_BULK_DEVICE (3)
|
||||
#define DJI_USE_ONLY_NETWORK_DEVICE (4)
|
||||
|
||||
/*!< Attention: Select your hardware connection mode here.
|
||||
* */
|
||||
#define CONFIG_HARDWARE_CONNECTION DJI_USE_ONLY_USB_BULK_DEVICE
|
||||
|
||||
/*!< Attention: Select the sample you want to run here.
|
||||
* */
|
||||
#define CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_XPORT_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_WIDGET_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_UPGRADE_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
|
||||
|
||||
/*!< Attention: This function needs to be used together with mobile sdk mop sample.
|
||||
* */
|
||||
|
||||
#define CONFIG_MODULE_SAMPLE_CLOUD_API_ON
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_SDK_CONFIG_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
676
samples/sample_c/platform/linux/manifold3/application/main.c
Normal file
676
samples/sample_c/platform/linux/manifold3/application/main.c
Normal file
@ -0,0 +1,676 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_platform.h>
|
||||
#include <dji_logger.h>
|
||||
#include <dji_core.h>
|
||||
#include <utils/util_misc.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <power_management/test_power_management.h>
|
||||
#include <gimbal_emu/test_payload_gimbal_emu.h>
|
||||
#include <fc_subscription/test_fc_subscription.h>
|
||||
#include <camera_emu/test_payload_cam_emu_media.h>
|
||||
#include <camera_emu/test_payload_cam_emu_base.h>
|
||||
#include <upgrade/test_upgrade.h>
|
||||
#include <upgrade_platform_opt/upgrade_platform_opt_linux.h>
|
||||
#include <mop_channel/test_mop_channel.h>
|
||||
#include <cloud_api/test_cloud_api_by_web_socket.h>
|
||||
#include <payload_collaboration/test_payload_collaboration.h>
|
||||
#include <xport/test_payload_xport.h>
|
||||
#include <hms/test_hms.h>
|
||||
#include "monitor/sys_monitor.h"
|
||||
#include "osal/osal.h"
|
||||
#include "osal/osal_fs.h"
|
||||
#include "osal/osal_socket.h"
|
||||
#include "../hal/hal_usb_bulk.h"
|
||||
#include "dji_sdk_app_info.h"
|
||||
#include "dji_aircraft_info.h"
|
||||
#include "widget/test_widget.h"
|
||||
#include "widget/test_widget_speaker.h"
|
||||
#include "widget_interaction_test/test_widget_interaction.h"
|
||||
#include "data_transmission/test_data_transmission.h"
|
||||
#include "dji_sdk_config.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define DJI_LOG_PATH "logs/DJI"
|
||||
#define DJI_LOG_INDEX_FILE_NAME "logs/index"
|
||||
#define DJI_LOG_FOLDER_NAME "logs"
|
||||
#define DJI_LOG_PATH_MAX_SIZE (128)
|
||||
#define DJI_LOG_FOLDER_NAME_MAX_SIZE (32)
|
||||
#define DJI_LOG_MAX_COUNT (10)
|
||||
#define DJI_SYSTEM_CMD_STR_MAX_SIZE (64)
|
||||
#define DJI_SYSTEM_RESULT_STR_MAX_SIZE (128)
|
||||
|
||||
#define DJI_USE_WIDGET_INTERACTION 1
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
pid_t tid;
|
||||
char name[16];
|
||||
float pcpu;
|
||||
} T_ThreadAttribute;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static FILE *s_djiLogFile;
|
||||
static FILE *s_djiLogFileCnt;
|
||||
static pthread_t s_monitorThread = 0;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static T_DjiReturnCode DjiUser_PrepareSystemEnvironment(void);
|
||||
static T_DjiReturnCode DjiUser_FillInUserInfo(T_DjiUserInfo *userInfo);
|
||||
static T_DjiReturnCode DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen);
|
||||
static T_DjiReturnCode DjiUser_LocalWrite(const uint8_t *data, uint16_t dataLen);
|
||||
static T_DjiReturnCode DjiUser_LocalWriteFsInit(const char *path);
|
||||
static void *DjiUser_MonitorTask(void *argument);
|
||||
static T_DjiReturnCode DjiTest_HighPowerApplyPinInit();
|
||||
static T_DjiReturnCode DjiTest_WriteHighPowerApplyPin(E_DjiPowerManagementPinState pinState);
|
||||
static void DjiUser_NormalExitHandler(int signalNum);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiUserInfo userInfo;
|
||||
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
|
||||
T_DjiAircraftVersion aircraftInfoVersion;
|
||||
T_DjiFirmwareVersion firmwareVersion = {
|
||||
.majorVersion = 1,
|
||||
.minorVersion = 0,
|
||||
.modifyVersion = 0,
|
||||
.debugVersion = 0,
|
||||
};
|
||||
|
||||
USER_UTIL_UNUSED(argc);
|
||||
USER_UTIL_UNUSED(argv);
|
||||
|
||||
// attention: when the program is hand up ctrl-c will generate the coredump file
|
||||
signal(SIGTERM, DjiUser_NormalExitHandler);
|
||||
signal(SIGINT, DjiUser_NormalExitHandler);
|
||||
|
||||
/*!< Step 1: Prepare system environment, such as osal, hal uart, console function and so on. */
|
||||
returnCode = DjiUser_PrepareSystemEnvironment();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Prepare system environment error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
/*!< Step 2: Fill your application information in dji_sdk_app_info.h and use this interface to fill it. */
|
||||
returnCode = DjiUser_FillInUserInfo(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Fill user info error, please check user info config");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
/*!< Step 3: Initialize the Payload SDK core by your application information. */
|
||||
returnCode = DjiCore_Init(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Core init error");
|
||||
sleep(1);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("get aircraft base info error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiAircraftInfo_GetAircraftVersion(&aircraftInfoVersion);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("get aircraft version info error");
|
||||
} else {
|
||||
USER_LOG_INFO("Aircraft version is V%02d.%02d.%02d.%02d", aircraftInfoVersion.majorVersion,
|
||||
aircraftInfoVersion.minorVersion, aircraftInfoVersion.modifyVersion,
|
||||
aircraftInfoVersion.debugVersion);
|
||||
}
|
||||
|
||||
returnCode = DjiCore_SetAlias("PSDK_APPALIAS");
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("set alias error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiCore_SetFirmwareVersion(firmwareVersion);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("set firmware version error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiCore_SetSerialNumber("PSDK12345678XX");
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("set serial number error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
/*!< Step 4: Initialize the selected modules by macros in dji_sdk_config.h . */
|
||||
#ifdef CONFIG_MODULE_SAMPLE_WIDGET_ON
|
||||
#if DJI_USE_WIDGET_INTERACTION
|
||||
returnCode = DjiTest_WidgetInteractionStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("widget interaction test init error");
|
||||
}
|
||||
#else
|
||||
returnCode = DjiTest_WidgetStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("widget sample init error");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
returnCode = DjiCore_ApplicationStart();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("start sdk application error");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON
|
||||
T_DjiTestApplyHighPowerHandler applyHighPowerHandler = {
|
||||
.pinInit = DjiTest_HighPowerApplyPinInit,
|
||||
.pinWrite = DjiTest_WriteHighPowerApplyPin,
|
||||
};
|
||||
|
||||
returnCode = DjiTest_RegApplyHighPowerHandler(&applyHighPowerHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("regsiter apply high power handler error");
|
||||
}
|
||||
|
||||
returnCode = DjiTest_PowerManagementStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("power management init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
|
||||
returnCode = DjiTest_DataTransmissionStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("data tramsmission sample init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_EXTENSION_PORT &&
|
||||
(aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M300_RTK ||
|
||||
aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M350_RTK)) {
|
||||
returnCode = DjiTest_WidgetInteractionStartService();
|
||||
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();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("camera emu common init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
|
||||
returnCode = DjiTest_CameraEmuMediaStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("camera emu media init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
|
||||
returnCode = DjiTest_FcSubscriptionStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("data subscription sample init error\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
|
||||
if (aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V2 ||
|
||||
aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_EPORT_V2_RIBBON_CABLE ||
|
||||
aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V3 ||
|
||||
aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_NONE) {
|
||||
if (DjiTest_GimbalStartService() != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("psdk gimbal init error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_XPORT_ON
|
||||
if (aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT) {
|
||||
if (DjiTest_XPortStartService() != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("psdk xport init error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_CLOUD_API_ON
|
||||
returnCode = DjiTest_CloudApiByWebSocketStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("CloudApiByWebSocket send data sample start error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_PAYLOAD_COLLABORATION_ON
|
||||
if (aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V2 ||
|
||||
aircraftInfoBaseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT) {
|
||||
returnCode = DjiTest_PayloadCollaborationStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Payload collaboration sample init error\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_UPGRADE_ON
|
||||
T_DjiTestUpgradePlatformOpt linuxUpgradePlatformOpt = {
|
||||
.rebootSystem = DjiUpgradePlatformLinux_RebootSystem,
|
||||
.cleanUpgradeProgramFileStoreArea = DjiUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea,
|
||||
.createUpgradeProgramFile = DjiUpgradePlatformLinux_CreateUpgradeProgramFile,
|
||||
.writeUpgradeProgramFile = DjiUpgradePlatformLinux_WriteUpgradeProgramFile,
|
||||
.readUpgradeProgramFile = DjiUpgradePlatformLinux_ReadUpgradeProgramFile,
|
||||
.closeUpgradeProgramFile = DjiUpgradePlatformLinux_CloseUpgradeProgramFile,
|
||||
.replaceOldProgram = DjiUpgradePlatformLinux_ReplaceOldProgram,
|
||||
.setUpgradeRebootState = DjiUpgradePlatformLinux_SetUpgradeRebootState,
|
||||
.getUpgradeRebootState = DjiUpgradePlatformLinux_GetUpgradeRebootState,
|
||||
.cleanUpgradeRebootState = DjiUpgradePlatformLinux_CleanUpgradeRebootState,
|
||||
};
|
||||
T_DjiTestUpgradeConfig testUpgradeConfig = {
|
||||
.firmwareVersion = firmwareVersion,
|
||||
.transferType = DJI_FIRMWARE_TRANSFER_TYPE_DCFTP,
|
||||
.needReplaceProgramBeforeReboot = true
|
||||
};
|
||||
if (DjiTest_UpgradeStartService(&linuxUpgradePlatformOpt, testUpgradeConfig) !=
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("psdk upgrade init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON
|
||||
returnCode = DjiTest_HmsCustomizationStartService();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("hms test init error");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pthread_create(&s_monitorThread, NULL, DjiUser_MonitorTask, NULL) != 0) {
|
||||
USER_LOG_ERROR("create monitor task fail.");
|
||||
}
|
||||
|
||||
if (pthread_setname_np(s_monitorThread, "monitor task") != 0) {
|
||||
USER_LOG_ERROR("set name for monitor task fail.");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_DjiReturnCode DjiUser_PrepareSystemEnvironment(void)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiOsalHandler osalHandler = {
|
||||
.TaskCreate = Osal_TaskCreate,
|
||||
.TaskDestroy = Osal_TaskDestroy,
|
||||
.TaskSleepMs = Osal_TaskSleepMs,
|
||||
.MutexCreate= Osal_MutexCreate,
|
||||
.MutexDestroy = Osal_MutexDestroy,
|
||||
.MutexLock = Osal_MutexLock,
|
||||
.MutexUnlock = Osal_MutexUnlock,
|
||||
.SemaphoreCreate = Osal_SemaphoreCreate,
|
||||
.SemaphoreDestroy = Osal_SemaphoreDestroy,
|
||||
.SemaphoreWait = Osal_SemaphoreWait,
|
||||
.SemaphoreTimedWait = Osal_SemaphoreTimedWait,
|
||||
.SemaphorePost = Osal_SemaphorePost,
|
||||
.Malloc = Osal_Malloc,
|
||||
.Free = Osal_Free,
|
||||
.GetRandomNum = Osal_GetRandomNum,
|
||||
.GetTimeMs = Osal_GetTimeMs,
|
||||
.GetTimeUs = Osal_GetTimeUs,
|
||||
};
|
||||
|
||||
T_DjiLoggerConsole printConsole = {
|
||||
.func = DjiUser_PrintConsole,
|
||||
.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_INFO,
|
||||
.isSupportColor = true,
|
||||
};
|
||||
|
||||
T_DjiLoggerConsole localRecordConsole = {
|
||||
.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_DEBUG,
|
||||
.func = DjiUser_LocalWrite,
|
||||
.isSupportColor = true,
|
||||
};
|
||||
|
||||
T_DjiHalUsbBulkHandler usbBulkHandler = {
|
||||
.UsbBulkInit = HalUsbBulk_Init,
|
||||
.UsbBulkDeInit = HalUsbBulk_DeInit,
|
||||
.UsbBulkWriteData = HalUsbBulk_WriteData,
|
||||
.UsbBulkReadData = HalUsbBulk_ReadData,
|
||||
.UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo,
|
||||
};
|
||||
|
||||
T_DjiFileSystemHandler fileSystemHandler = {
|
||||
.FileOpen = Osal_FileOpen,
|
||||
.FileClose = Osal_FileClose,
|
||||
.FileWrite = Osal_FileWrite,
|
||||
.FileRead = Osal_FileRead,
|
||||
.FileSync = Osal_FileSync,
|
||||
.FileSeek = Osal_FileSeek,
|
||||
.DirOpen = Osal_DirOpen,
|
||||
.DirClose = Osal_DirClose,
|
||||
.DirRead = Osal_DirRead,
|
||||
.Mkdir = Osal_Mkdir,
|
||||
.Unlink = Osal_Unlink,
|
||||
.Rename = Osal_Rename,
|
||||
.Stat = Osal_Stat,
|
||||
};
|
||||
|
||||
T_DjiSocketHandler socketHandler = {
|
||||
.Socket = Osal_Socket,
|
||||
.Bind = Osal_Bind,
|
||||
.Close = Osal_Close,
|
||||
.UdpSendData = Osal_UdpSendData,
|
||||
.UdpRecvData = Osal_UdpRecvData,
|
||||
.TcpListen = Osal_TcpListen,
|
||||
.TcpAccept = Osal_TcpAccept,
|
||||
.TcpConnect = Osal_TcpConnect,
|
||||
.TcpSendData = Osal_TcpSendData,
|
||||
.TcpRecvData = Osal_TcpRecvData,
|
||||
};
|
||||
|
||||
returnCode = DjiPlatform_RegOsalHandler(&osalHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("register osal handler error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (DjiUser_LocalWriteFsInit(DJI_LOG_PATH) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("file system init error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
returnCode = DjiLogger_AddConsole(&printConsole);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("add printf console error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiLogger_AddConsole(&localRecordConsole);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("add printf console error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("register hal usb bulk handler error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
//Attention: if you want to use camera stream view function, please uncomment it.
|
||||
returnCode = DjiPlatform_RegSocketHandler(&socketHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("register osal socket handler error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegFileSystemHandler(&fileSystemHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("register osal filesystem handler error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUser_FillInUserInfo(T_DjiUserInfo *userInfo)
|
||||
{
|
||||
if (userInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
memset(userInfo->appName, 0, sizeof(userInfo->appName));
|
||||
memset(userInfo->appId, 0, sizeof(userInfo->appId));
|
||||
memset(userInfo->appKey, 0, sizeof(userInfo->appKey));
|
||||
memset(userInfo->appLicense, 0, sizeof(userInfo->appLicense));
|
||||
memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount));
|
||||
memset(userInfo->baudRate, 0, sizeof(userInfo->baudRate));
|
||||
|
||||
if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) ||
|
||||
strlen(USER_APP_ID) > sizeof(userInfo->appId) ||
|
||||
strlen(USER_APP_KEY) > sizeof(userInfo->appKey) ||
|
||||
strlen(USER_APP_LICENSE) > sizeof(userInfo->appLicense) ||
|
||||
strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount) ||
|
||||
strlen(USER_BAUD_RATE) > sizeof(userInfo->baudRate)) {
|
||||
USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
|
||||
sleep(1);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (!strcmp(USER_APP_NAME, "your_app_name") ||
|
||||
!strcmp(USER_APP_ID, "your_app_id") ||
|
||||
!strcmp(USER_APP_KEY, "your_app_key") ||
|
||||
!strcmp(USER_BAUD_RATE, "your_app_license") ||
|
||||
!strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account") ||
|
||||
!strcmp(USER_BAUD_RATE, "your_baud_rate")) {
|
||||
USER_LOG_ERROR(
|
||||
"Please fill in correct user information to 'samples/sample_c/platform/linux/nvidia_jetson/application/dji_sdk_app_info.h' file.");
|
||||
sleep(1);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1);
|
||||
memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID)));
|
||||
memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY)));
|
||||
memcpy(userInfo->appLicense, USER_APP_LICENSE,
|
||||
USER_UTIL_MIN(sizeof(userInfo->appLicense), strlen(USER_APP_LICENSE)));
|
||||
memcpy(userInfo->baudRate, USER_BAUD_RATE, USER_UTIL_MIN(sizeof(userInfo->baudRate), strlen(USER_BAUD_RATE)));
|
||||
strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
USER_UTIL_UNUSED(dataLen);
|
||||
|
||||
printf("%s", data);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
uint32_t realLen;
|
||||
|
||||
if (s_djiLogFile == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
realLen = fwrite(data, 1, dataLen, s_djiLogFile);
|
||||
fflush(s_djiLogFile);
|
||||
if (realLen == dataLen) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUser_LocalWriteFsInit(const char *path)
|
||||
{
|
||||
T_DjiReturnCode djiReturnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
char filePath[DJI_LOG_PATH_MAX_SIZE];
|
||||
char systemCmd[DJI_SYSTEM_CMD_STR_MAX_SIZE];
|
||||
char folderName[DJI_LOG_FOLDER_NAME_MAX_SIZE];
|
||||
time_t currentTime = time(NULL);
|
||||
struct tm *localTime = localtime(¤tTime);
|
||||
uint16_t logFileIndex = 0;
|
||||
uint16_t currentLogFileIndex;
|
||||
uint8_t ret;
|
||||
|
||||
if (localTime == NULL) {
|
||||
printf("Get local time error.\r\n");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (access(DJI_LOG_FOLDER_NAME, F_OK) != 0) {
|
||||
sprintf(folderName, "mkdir %s", DJI_LOG_FOLDER_NAME);
|
||||
ret = system(folderName);
|
||||
if (ret != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "rb+");
|
||||
if (s_djiLogFileCnt == NULL) {
|
||||
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "wb+");
|
||||
if (s_djiLogFileCnt == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else {
|
||||
ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Read log file index error.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
currentLogFileIndex = logFileIndex;
|
||||
logFileIndex++;
|
||||
|
||||
ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Write log file index error.\r\n");
|
||||
fclose(s_djiLogFileCnt);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fclose(s_djiLogFileCnt);
|
||||
|
||||
sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex,
|
||||
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
|
||||
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
|
||||
|
||||
s_djiLogFile = fopen(filePath, "wb+");
|
||||
if (s_djiLogFile == NULL) {
|
||||
USER_LOG_ERROR("Open filepath time error.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (logFileIndex >= DJI_LOG_MAX_COUNT) {
|
||||
sprintf(systemCmd, "rm -rf %s_%04d*.log", path, currentLogFileIndex - DJI_LOG_MAX_COUNT);
|
||||
ret = system(systemCmd);
|
||||
if (ret != 0) {
|
||||
printf("Remove file error, ret:%d.\r\n", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(systemCmd, "ln -sfrv %s " DJI_LOG_FOLDER_NAME "/latest.log", filePath);
|
||||
system(systemCmd);
|
||||
return djiReturnCode;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
|
||||
#pragma GCC diagnostic ignored "-Wreturn-type"
|
||||
|
||||
static void *DjiUser_MonitorTask(void *argument)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int threadCount = 0;
|
||||
pid_t *tidList = NULL;
|
||||
T_ThreadAttribute *threadAttribute = NULL;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
USER_UTIL_UNUSED(argument);
|
||||
|
||||
while (1) {
|
||||
threadCount = Monitor_GetThreadCountOfProcess(getpid());
|
||||
tidList = osalHandler->Malloc(threadCount * sizeof(pid_t));
|
||||
if (tidList == NULL) {
|
||||
USER_LOG_ERROR("malloc fail.");
|
||||
goto delay;
|
||||
}
|
||||
Monitor_GetTidListOfProcess(getpid(), tidList, threadCount);
|
||||
|
||||
threadAttribute = osalHandler->Malloc(threadCount * sizeof(T_ThreadAttribute));
|
||||
if (threadAttribute == NULL) {
|
||||
USER_LOG_ERROR("malloc fail.");
|
||||
goto freeTidList;
|
||||
}
|
||||
for (i = 0; i < threadCount; ++i) {
|
||||
threadAttribute[i].tid = tidList[i];
|
||||
}
|
||||
|
||||
USER_LOG_DEBUG("thread pcpu:");
|
||||
USER_LOG_DEBUG("tid\tname\tpcpu");
|
||||
for (i = 0; i < threadCount; ++i) {
|
||||
threadAttribute[i].pcpu = Monitor_GetPcpuOfThread(getpid(), tidList[i]);
|
||||
Monitor_GetNameOfThread(getpid(), tidList[i], threadAttribute[i].name, sizeof(threadAttribute[i].name));
|
||||
USER_LOG_DEBUG("%d\t%15s\t%f %%.", threadAttribute[i].tid, threadAttribute[i].name,
|
||||
threadAttribute[i].pcpu);
|
||||
}
|
||||
|
||||
USER_LOG_DEBUG("heap used: %d B.", Monitor_GetHeapUsed(getpid()));
|
||||
USER_LOG_DEBUG("stack used: %d B.", Monitor_GetStackUsed(getpid()));
|
||||
|
||||
osalHandler->Free(threadAttribute);
|
||||
freeTidList:
|
||||
osalHandler->Free(tidList);
|
||||
|
||||
delay:
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiTest_HighPowerApplyPinInit()
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiTest_WriteHighPowerApplyPin(E_DjiPowerManagementPinState pinState)
|
||||
{
|
||||
//attention: please pull up the HWPR pin state by hardware.
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void DjiUser_NormalExitHandler(int signalNum)
|
||||
{
|
||||
USER_UTIL_UNUSED(signalNum);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
252
samples/sample_c/platform/linux/manifold3/hal/hal_usb_bulk.c
Normal file
252
samples/sample_c/platform/linux/manifold3/hal/hal_usb_bulk.c
Normal file
@ -0,0 +1,252 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hal_usb_bulk.h"
|
||||
#include "dji_logger.h"
|
||||
#include <errno.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
|
||||
#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
libusb_device_handle *handle;
|
||||
#else
|
||||
void *handle;
|
||||
#endif
|
||||
int32_t ep1;
|
||||
int32_t ep2;
|
||||
uint32_t interfaceNum;
|
||||
T_DjiHalUsbBulkInfo usbBulkInfo;
|
||||
} T_HalUsbBulkObj;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
*usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj));
|
||||
if (*usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_init(NULL);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
|
||||
if (handle == NULL) {
|
||||
USER_LOG_ERROR("libusb open device error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
|
||||
if (ret != LIBUSB_SUCCESS) {
|
||||
USER_LOG_ERROR("libusb claim interface error");
|
||||
libusb_close(handle);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((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));
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->interfaceNum = usbBulkInfo.channelInfo.interfaceNum;
|
||||
|
||||
if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK1_INTERFACE_NUM) {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK2_INTERFACE_NUM) {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK3_INTERFACE_NUM) {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK3_EP_IN_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK3_EP_OUT_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle)
|
||||
{
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
free(usbBulkHandle);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t actualLen;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
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) {
|
||||
USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
#endif
|
||||
} else {
|
||||
ret = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("write ret %d %d %s\n", ret, errno, strerror(errno));
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
*realLen = ret;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
int32_t actualLen;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
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 {
|
||||
ret = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("read ret %d %d %s\n", ret, errno, strerror(errno));
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
*realLen = ret;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo)
|
||||
{
|
||||
//attention: this interface only be called in usb device mode.
|
||||
deviceInfo->vid = LINUX_USB_VID;
|
||||
deviceInfo->pid = LINUX_USB_PID;
|
||||
|
||||
// This bulk channel is used to obtain DJI camera video stream and push 3rd-party camera video stream.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT;
|
||||
|
||||
// This bulk channel is used to obtain DJI perception image and download camera media file.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT;
|
||||
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_2].interfaceNum = LINUX_USB_BULK3_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_2].endPointIn = LINUX_USB_BULK3_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_2].endPointOut = LINUX_USB_BULK3_END_POINT_OUT;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
95
samples/sample_c/platform/linux/manifold3/hal/hal_usb_bulk.h
Normal file
95
samples/sample_c/platform/linux/manifold3/hal/hal_usb_bulk.h
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.h
|
||||
* @brief This is the header file for "hal_usb_bulk.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_USB_BULK_H
|
||||
#define HAL_USB_BULK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk2/ep2"
|
||||
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk2/ep1"
|
||||
|
||||
#define LINUX_USB_BULK1_INTERFACE_NUM (2)
|
||||
#define LINUX_USB_BULK1_END_POINT_IN (0x83)
|
||||
#define LINUX_USB_BULK1_END_POINT_OUT (0x02)
|
||||
|
||||
#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk6/ep2"
|
||||
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk6/ep1"
|
||||
|
||||
#define LINUX_USB_BULK2_INTERFACE_NUM (6)
|
||||
#define LINUX_USB_BULK2_END_POINT_IN (0x87)
|
||||
#define LINUX_USB_BULK2_END_POINT_OUT (0x06)
|
||||
|
||||
#define LINUX_USB_BULK3_EP_IN_FD "/dev/usb-ffs/bulk3/ep2"
|
||||
#define LINUX_USB_BULK3_EP_OUT_FD "/dev/usb-ffs/bulk3/ep1"
|
||||
|
||||
#define LINUX_USB_BULK3_INTERFACE_NUM (3)
|
||||
#define LINUX_USB_BULK3_END_POINT_IN (0x84)
|
||||
#define LINUX_USB_BULK3_END_POINT_OUT (0x03)
|
||||
|
||||
#define LINUX_USB_VID (0x2CA3)
|
||||
#define LINUX_USB_PID (0x3181)
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_USB_BULK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
Reference in New Issue
Block a user