NEW: release DJI Payload-SDK version 3.0

Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
This commit is contained in:
DJI-Martin
2021-11-12 16:27:03 +08:00
parent 2cce11a80b
commit e478e9a7a5
541 changed files with 2192778 additions and 2 deletions

View File

@ -0,0 +1,311 @@
/**
********************************************************************
* @file psdk_osal.c
* @version V2.0.0
* @date 2019/07/01
* @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 DJIs 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 "osal.h"
#include "dji_typedef.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
/* Private functions definition-----------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *), uint32_t stackSize, void *arg,
T_DjiTaskHandle *task)
{
int result;
char nameDealed[16] = {0};
*task = malloc(sizeof(pthread_t));
if (*task == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
result = pthread_create(*task, NULL, taskFunc, arg);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (name != NULL)
strncpy(nameDealed, name, sizeof(nameDealed) - 1);
result = pthread_setname_np(*(pthread_t *) *task, nameDealed);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task)
{
pthread_cancel(*(pthread_t *) task);
free(task);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs)
{
usleep(1000 * timeMs);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Declare the mutex container, initialize the mutex, and
* create mutex ID.
* @param mutex: pointer to the created mutex ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex)
{
int result;
*mutex = malloc(sizeof(pthread_mutex_t));
if (*mutex == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
result = pthread_mutex_init(*mutex, NULL);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Delete the created mutex.
* @param mutex: pointer to the created mutex ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex)
{
int result;
result = pthread_mutex_destroy(mutex);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
free(mutex);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Acquire and lock the mutex when peripheral access is required
* @param mutex: pointer to the created mutex ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex)
{
int result = pthread_mutex_lock(mutex);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Unlock and release the mutex, when done with the peripheral access.
* @param mutex: pointer to the created mutex ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex)
{
int result = pthread_mutex_unlock(mutex);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Declare the semaphore container, initialize the semaphore, and
* create semaphore ID.
* @param semaphore: pointer to the created semaphore ID.
* @param initValue: initial value of semaphore.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore)
{
int result;
*semaphore = malloc(sizeof(sem_t));
if (*semaphore == NULL) {
return
DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
result = sem_init(*semaphore, 0, (unsigned int) initValue);
if (result != 0) {
return
DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Delete the created semaphore.
* @param semaphore: pointer to the created semaphore ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore)
{
int result;
result = sem_destroy((sem_t *) semaphore);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
free(semaphore);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Wait the semaphore until token becomes available.
* @param semaphore: pointer to the created semaphore ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore)
{
int result;
result = sem_wait(semaphore);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Wait the semaphore until token becomes available.
* @param semaphore: pointer to the created semaphore ID.
* @param waitTime: timeout value of waiting semaphore, unit: millisecond.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime)
{
int result;
struct timespec semaphoreWaitTime;
struct timeval systemTime;
gettimeofday(&systemTime, NULL);
systemTime.tv_usec += waitTime * 1000;
if (systemTime.tv_usec >= 1000000) {
systemTime.tv_sec += systemTime.tv_usec / 1000000;
systemTime.tv_usec %= 1000000;
}
semaphoreWaitTime.tv_sec = systemTime.tv_sec;
semaphoreWaitTime.tv_nsec = systemTime.tv_usec * 1000;
result = sem_timedwait(semaphore, &semaphoreWaitTime);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Release the semaphore token.
* @param semaphore: pointer to the created semaphore ID.
* @return an enum that represents a status of PSDK
*/
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore)
{
int result;
result = sem_post(semaphore);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Get the system time for ms.
* @return an uint32 that the time of system, uint:ms
*/
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms)
{
struct timeval time;
gettimeofday(&time, NULL);
*ms = (time.tv_sec * 1000 + time.tv_usec / 1000);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us)
{
struct timeval time;
gettimeofday(&time, NULL);
*us = (time.tv_sec * 1000000 + time.tv_usec);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
void *Osal_Malloc(uint32_t size)
{
if (size == 0) {
return NULL;
}
return malloc(size);
}
void Osal_Free(void *ptr)
{
free(ptr);
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,77 @@
/**
********************************************************************
* @file osal.h
* @version V2.0.0
* @date 2019/8/28
* @brief This is the header file for "osal.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 DJIs 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 OSAL_H
#define OSAL_H
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/time.h>
#include <unistd.h>
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *),
uint32_t stackSize, void *arg, T_DjiTaskHandle *task);
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task);
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs);
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex);
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex);
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex);
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex);
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore);
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore);
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore);
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime);
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore);
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms);
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us);
void *Osal_Malloc(uint32_t size);
void Osal_Free(void *ptr);
#ifdef __cplusplus
}
#endif
#endif // OSAL_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,293 @@
/**
********************************************************************
* @file osal_fs.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 DJIs 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 "osal_fs.h"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include <sys/stat.h>
#include <dirent.h>
#include "time.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj)
{
if (fileName == NULL || fileMode == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
*fileObj = malloc(sizeof(FILE));
if (*fileObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
*fileObj = fopen(fileName, fileMode);
if (*fileObj == NULL) {
goto out;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
out:
free(*fileObj);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj)
{
int32_t ret;
if (fileObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = fclose(fileObj);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = fwrite(buf, 1, len, fileObj);
if (ret >= 0) {
*realLen = ret;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = fread(buf, 1, len, fileObj);
if (ret >= 0) {
*realLen = ret;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset)
{
int32_t ret;
if (fileObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = fseek(fileObj, offset, SEEK_SET);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj)
{
int32_t ret;
if (fileObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = fflush(fileObj);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj)
{
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
*dirObj = opendir(filePath);
if (*dirObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj)
{
int32_t ret;
if (dirObj == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = closedir((DIR *) dirObj);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo)
{
struct dirent *dirent;
if (dirObj == NULL || fileInfo == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
dirent = readdir((DIR *) dirObj);
if (!dirent) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (dirent->d_type == DT_DIR) {
fileInfo->isDir = true;
} else {
fileInfo->isDir = false;
}
strcpy(fileInfo->path, dirent->d_name);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_Mkdir(const char *filePath)
{
int32_t ret;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = mkdir(filePath, S_IRWXU);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_Unlink(const char *filePath)
{
int32_t ret;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (filePath[strlen(filePath) - 1] == '/') {
ret = rmdir(filePath);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
} else {
ret = unlink(filePath);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath)
{
int32_t ret;
if (oldFilePath == NULL || newFilePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = rename(oldFilePath, newFilePath);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo)
{
struct stat st;
int32_t ret;
struct tm *fileTm;
if (filePath == NULL || fileInfo == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = stat(filePath, &st);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
fileTm = localtime(&(st.st_ctime));
if (fileTm == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
fileInfo->size = st.st_size;
fileInfo->createTime.year = fileTm->tm_year + 1900 - 1980;
fileInfo->createTime.month = fileTm->tm_mon;
fileInfo->createTime.day = fileTm->tm_mday;
fileInfo->createTime.hour = fileTm->tm_hour;
fileInfo->createTime.minute = fileTm->tm_min;
fileInfo->createTime.second = fileTm->tm_sec;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,73 @@
/**
********************************************************************
* @file osal_fs.h
* @brief This is the header file for "osal_fs.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 DJIs 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 OSAL_FS_H
#define OSAL_FS_H
/* Includes ------------------------------------------------------------------*/
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj);
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj);
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset);
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj);
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj);
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj);
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo);
T_DjiReturnCode Osal_Mkdir(const char *filePath);
T_DjiReturnCode Osal_Unlink(const char *filePath);
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath);
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo);
#ifdef __cplusplus
}
#endif
#endif // OSAL_FS_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.5)
project(dji_sdk_demo_linux_cxx CXX)
set(CMAKE_C_FLAGS "-pthread -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-pthread")
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")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
include_directories(../../../module_sample)
include_directories(../common)
file(GLOB_RECURSE MODULE_SAMPLE_SRC
../../../module_sample/liveview/*.c*
../../../module_sample/perception/*.c*
)
file(GLOB_RECURSE MODULE_COMMON_SRC ../common/*.c*)
file(GLOB_RECURSE MODULE_HAL_SRC hal/*.c*)
file(GLOB_RECURSE MODULE_APP_SRC application/*.c*)
execute_process(COMMAND uname -m
OUTPUT_VARIABLE DEVICE_SYSTEM_ID)
if (DEVICE_SYSTEM_ID MATCHES x86_64)
set(TOOLCHAIN_NAME x86_64-linux-gnu-gcc)
add_definitions(-DPLATFORM_ARCH_x86_64=1)
elseif (DEVICE_SYSTEM_ID MATCHES aarch64)
set(TOOLCHAIN_NAME aarch64-linux-gnu-gcc)
add_definitions(-DPLATFORM_ARCH_aarch64=1)
else ()
message(FATAL_ERROR "FATAL: Please confirm your platform.")
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(FFMPEG REQUIRED)
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)
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++)
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})
add_custom_command(TARGET ${PROJECT_NAME}
PRE_LINK COMMAND cmake ..
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})
if (OpenCV_FOUND)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
endif ()

View File

@ -0,0 +1,181 @@
#
# Find the native FFMPEG includes and library
#
# This module defines
# FFMPEG_INCLUDE_DIR, where to find avcodec.h, avformat.h ...
# FFMPEG_LIBRARIES, the libraries to link against to use FFMPEG.
# FFMPEG_FOUND, If false, do not try to use FFMPEG.
# also defined, but not for general use are
# FFMPEG_avformat_LIBRARY and FFMPEG_avcodec_LIBRARY, where to find the FFMPEG library.
# This is useful to do it this way so that we can always add more libraries
# if needed to FFMPEG_LIBRARIES if ffmpeg ever changes...
# if ffmpeg headers are all in one directory
FIND_PATH(FFMPEG_INCLUDE_DIR avformat.h
PATHS
$ENV{FFMPEG_DIR}/include
$ENV{OSGDIR}/include
$ENV{OSG_ROOT}/include
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
/usr/freeware/include
PATH_SUFFIXES ffmpeg
DOC "Location of FFMPEG Headers"
)
# if ffmpeg headers are seperated to each of libavformat, libavcodec etc..
IF( NOT FFMPEG_INCLUDE_DIR )
FIND_PATH(FFMPEG_INCLUDE_DIR libavformat/avformat.h
PATHS
$ENV{FFMPEG_DIR}/include
$ENV{OSGDIR}/include
$ENV{OSG_ROOT}/include
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
/usr/freeware/include
PATH_SUFFIXES ffmpeg
DOC "Location of FFMPEG Headers"
)
ENDIF( NOT FFMPEG_INCLUDE_DIR )
# we want the -I include line to use the parent directory of ffmpeg as
# ffmpeg uses relative includes such as <ffmpeg/avformat.h> or <libavcodec/avformat.h>
get_filename_component(FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} ABSOLUTE)
FIND_LIBRARY(FFMPEG_avformat_LIBRARY avformat
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_avcodec_LIBRARY avcodec
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_avutil_LIBRARY avutil
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_vorbis_LIBRARY vorbis
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_dc1394_LIBRARY dc1394_control
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_vorbisenc_LIBRARY vorbisenc
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_theora_LIBRARY theora
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_dts_LIBRARY dts
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_gsm_LIBRARY gsm
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_swscale_LIBRARY swscale
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(FFMPEG_z_LIBRARY z
/usr/local/lib
/usr/lib
)
SET(FFMPEG_LIBRARIES)
IF(FFMPEG_INCLUDE_DIR)
IF(FFMPEG_avformat_LIBRARY)
IF(FFMPEG_avcodec_LIBRARY)
IF(FFMPEG_avutil_LIBRARY)
SET( FFMPEG_FOUND "YES" )
SET( FFMPEG_BASIC_LIBRARIES
${FFMPEG_avcodec_LIBRARY}
${FFMPEG_avformat_LIBRARY}
${FFMPEG_avutil_LIBRARY}
)
# swscale is always a part of newer ffmpeg distros
IF(FFMPEG_swscale_LIBRARY)
LIST(APPEND FFMPEG_BASIC_LIBRARIES ${FFMPEG_swscale_LIBRARY})
ENDIF(FFMPEG_swscale_LIBRARY)
SET(FFMPEG_LIBRARIES ${FFMPEG_BASIC_LIBRARIES})
IF(FFMPEG_vorbis_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_vorbis_LIBRARY})
ENDIF(FFMPEG_vorbis_LIBRARY)
IF(FFMPEG_dc1394_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_dc1394_LIBRARY})
ENDIF(FFMPEG_dc1394_LIBRARY)
IF(FFMPEG_vorbisenc_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_vorbisenc_LIBRARY})
ENDIF(FFMPEG_vorbisenc_LIBRARY)
IF(FFMPEG_theora_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_theora_LIBRARY})
ENDIF(FFMPEG_theora_LIBRARY)
IF(FFMPEG_dts_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_dts_LIBRARY})
ENDIF(FFMPEG_dts_LIBRARY)
IF(FFMPEG_gsm_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_gsm_LIBRARY})
ENDIF(FFMPEG_gsm_LIBRARY)
IF(FFMPEG_z_LIBRARY)
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_z_LIBRARY})
ENDIF(FFMPEG_z_LIBRARY)
SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE INTERNAL "All presently found FFMPEG libraries.")
ENDIF(FFMPEG_avutil_LIBRARY)
ENDIF(FFMPEG_avcodec_LIBRARY)
ENDIF(FFMPEG_avformat_LIBRARY)
ENDIF(FFMPEG_INCLUDE_DIR)
MARK_AS_ADVANCED(
FFMPEG_INCLUDE_DIR
FFMPEG_avformat_LIBRARY
FFMPEG_avcodec_LIBRARY
FFMPEG_avutil_LIBRARY
FFMPEG_vorbis_LIBRARY
FFMPEG_dc1394_LIBRARY
FFMPEG_vorbisenc_LIBRARY
FFMPEG_theora_LIBRARY
FFMPEG_dts_LIBRARY
FFMPEG_gsm_LIBRARY
FFMPEG_swscale_LIBRARY
FFMPEG_z_LIBRARY
)

View File

@ -0,0 +1,356 @@
/**
********************************************************************
* @file application.cpp
* @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 DJIs 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 "application.hpp"
#include "dji_sdk_app_info.h"
#include <dji_platform.h>
#include <dji_logger.h>
#include <dji_core.h>
#include <dji_aircraft_info.h>
#include "../common/osal/osal.h"
#include "../common/osal/osal_fs.h"
#include "../manifold2//hal/hal_usb_bulk.h"
#include "../manifold2//hal/hal_uart.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_LOG_PATH "Logs/DJI"
#define DJI_LOG_INDEX_FILE_NAME "Logs/latest"
#define DJI_LOG_FOLDER_NAME "Logs"
#define DJI_LOG_PATH_MAX_SIZE (128)
#define DJI_LOG_FOLDER_NAME_MAX_SIZE (32)
#define DJI_LOG_SYSTEM_CMD_MAX_SIZE (64)
#define DJI_LOG_MAX_COUNT (10)
#define USER_UTIL_UNUSED(x) ((x) = (x))
#define USER_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define USER_UTIL_MAX(a, b) (((a) > (b)) ? (a) : (b))
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static FILE *s_djiLogFile;
static FILE *s_djiLogFileCnt;
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
Application::Application(int argc, char **argv)
{
Application::DjiUser_SetupEnvironment();
Application::DjiUser_ApplicationStart();
Osal_TaskSleepMs(1000);
}
Application::~Application()
= default;
/* Private functions definition-----------------------------------------------*/
void Application::DjiUser_SetupEnvironment()
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler osalHandler;
T_DjiHalUartHandler uartHandler;
T_DjiHalUsbBulkHandler usbBulkHandler;
T_DjiLoggerConsole printConsole;
T_DjiLoggerConsole localRecordConsole;
T_DjiFileSystemHandler fileSystemHandler;
osalHandler.TaskCreate = Osal_TaskCreate;
osalHandler.TaskDestroy = Osal_TaskDestroy;
osalHandler.TaskSleepMs = Osal_TaskSleepMs;
osalHandler.MutexCreate = Osal_MutexCreate;
osalHandler.MutexDestroy = Osal_MutexDestroy;
osalHandler.MutexLock = Osal_MutexLock;
osalHandler.MutexUnlock = Osal_MutexUnlock;
osalHandler.SemaphoreCreate = Osal_SemaphoreCreate;
osalHandler.SemaphoreDestroy = Osal_SemaphoreDestroy;
osalHandler.SemaphoreWait = Osal_SemaphoreWait;
osalHandler.SemaphoreTimedWait = Osal_SemaphoreTimedWait;
osalHandler.SemaphorePost = Osal_SemaphorePost;
osalHandler.Malloc = Osal_Malloc;
osalHandler.Free = Osal_Free;
osalHandler.GetTimeMs = Osal_GetTimeMs;
osalHandler.GetTimeUs = Osal_GetTimeUs;
printConsole.func = DjiUser_PrintConsole;
printConsole.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_INFO;
printConsole.isSupportColor = true;
localRecordConsole.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_DEBUG;
localRecordConsole.func = DjiUser_LocalWrite;
localRecordConsole.isSupportColor = false;
uartHandler.UartInit = HalUart_Init;
uartHandler.UartDeInit = HalUart_DeInit;
uartHandler.UartWriteData = HalUart_WriteData;
uartHandler.UartReadData = HalUart_ReadData;
uartHandler.UartGetStatus = HalUart_GetStatus;
usbBulkHandler.UsbBulkInit = HalUsbBulk_Init;
usbBulkHandler.UsbBulkDeInit = HalUsbBulk_DeInit;
usbBulkHandler.UsbBulkWriteData = HalUsbBulk_WriteData;
usbBulkHandler.UsbBulkReadData = HalUsbBulk_ReadData;
usbBulkHandler.UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo;
fileSystemHandler.FileOpen = Osal_FileOpen,
fileSystemHandler.FileClose = Osal_FileClose,
fileSystemHandler.FileWrite = Osal_FileWrite,
fileSystemHandler.FileRead = Osal_FileRead,
fileSystemHandler.FileSync = Osal_FileSync,
fileSystemHandler.FileSeek = Osal_FileSeek,
fileSystemHandler.DirOpen = Osal_DirOpen,
fileSystemHandler.DirClose = Osal_DirClose,
fileSystemHandler.DirRead = Osal_DirRead,
fileSystemHandler.Mkdir = Osal_Mkdir,
fileSystemHandler.Unlink = Osal_Unlink,
fileSystemHandler.Rename = Osal_Rename,
fileSystemHandler.Stat = Osal_Stat,
returnCode = DjiPlatform_RegOsalHandler(&osalHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Register osal handler error.");
}
returnCode = DjiPlatform_RegHalUartHandler(&uartHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Register hal uart handler error.");
}
returnCode = DjiPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Register hal usb bulk handler error.");
}
returnCode = DjiPlatform_RegFileSystemHandler(&fileSystemHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Register osal filesystem handler error.");
}
if (DjiUser_LocalWriteFsInit(DJI_LOG_PATH) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("File system init error.");
}
returnCode = DjiLogger_AddConsole(&printConsole);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Add printf console error.");
}
returnCode = DjiLogger_AddConsole(&localRecordConsole);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Add printf console error.");
}
}
void Application::DjiUser_ApplicationStart()
{
T_DjiUserInfo userInfo;
T_DjiReturnCode returnCode;
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
returnCode = DjiUser_FillInUserInfo(&userInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Fill user info error, please check user info config.");
}
returnCode = DjiCore_Init(&userInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Core init error.");
}
returnCode = DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Get aircraft base info error.");
}
if (aircraftInfoBaseInfo.mountPosition != DJI_MOUNT_POSITION_EXTENSION_PORT) {
throw std::runtime_error("Please run this sample on extension port.");
}
returnCode = DjiCore_SetAlias("PSDK_APPALIAS");
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Set alias error.");
}
returnCode = DjiCore_ApplicationStart();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
throw std::runtime_error("Start sdk application error.");
}
USER_LOG_INFO("Application start.");
}
T_DjiReturnCode Application::DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
{
printf("%s", data);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode Application::DjiUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
{
int32_t realLen;
if (s_djiLogFile == nullptr) {
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;
}
}
T_DjiReturnCode Application::DjiUser_FillInUserInfo(T_DjiUserInfo *userInfo)
{
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.");
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/manifold2/application/dji_sdk_app_info.h' file.");
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;
}
T_DjiReturnCode Application::DjiUser_LocalWriteFsInit(const char *path)
{
T_DjiReturnCode djiReturnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
char filePath[DJI_LOG_PATH_MAX_SIZE];
char systemCmd[DJI_LOG_SYSTEM_CMD_MAX_SIZE];
char folderName[DJI_LOG_FOLDER_NAME_MAX_SIZE];
time_t currentTime = time(nullptr);
struct tm *localTime = localtime(&currentTime);
uint16_t logFileIndex = 0;
uint16_t currentLogFileIndex;
uint8_t ret;
if (localTime == nullptr) {
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) {
printf("Create new log folder error, ret:%d.\r\n", ret);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
}
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "rb+");
if (s_djiLogFileCnt == nullptr) {
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "wb+");
if (s_djiLogFileCnt == nullptr) {
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 == nullptr) {
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;
}
}
return djiReturnCode;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,67 @@
/**
********************************************************************
* @file dji_application.hpp
* @brief This is the header file for "dji_application.cpp", 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 DJIs 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 APPLICATION_H
#define APPLICATION_H
/* Includes ------------------------------------------------------------------*/
#include <iostream>
#include <fstream>
#include "dji_typedef.h"
#include "dji_core.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
using namespace std;
class Application {
public:
Application(int argc, char **argv);
~Application();
private:
static void DjiUser_SetupEnvironment();
static void DjiUser_ApplicationStart();
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_FillInUserInfo(T_DjiUserInfo *userInfo);
static T_DjiReturnCode DjiUser_LocalWriteFsInit(const char *path);
};
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // APPLICATION_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -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 DJIs 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******/

View File

@ -0,0 +1,68 @@
/**
********************************************************************
* @file main.cpp
* @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 DJIs 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 <liveview/test_liveview_entry.hpp>
#include <perception/test_perception_entry.hpp>
#include "application.hpp"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
int main(int argc, char **argv)
{
Application application(argc, argv);
char inputChar;
std::cout
<< "\n"
<< "| Available commands: |\n"
<< "| [0] Camera stream view sample |\n"
<< "| [1] Stereo vision view sample |\n"
<< std::endl;
std::cin >> inputChar;
switch (inputChar) {
case '0':
DjiUser_RunCameraStreamViewSample();
break;
case '1':
DjiUser_RunStereoVisionViewSample();
break;
default:
break;
}
return 0;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,84 @@
/**
********************************************************************
* @file hal_network.c
* @version V2.0.0
* @date 3/27/20
* @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 DJIs 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 "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "hal_network.h"
#include "dji_logger.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj)
{
int32_t ret;
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
if (ipAddr == NULL || netMask == NULL) {
USER_LOG_ERROR("hal network config param error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
//Attention: need root permission to config ip addr and netmask.
memset(cmdStr, 0, sizeof(cmdStr));
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Can't open the network."
"Probably the program not execute with root permission."
"Please use the root permission to execute the program.");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Can't config the ip address of network."
"Probably the program not execute with root permission."
"Please use the root permission to execute the program.");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj)
{
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,68 @@
/**
********************************************************************
* @file hal_network.h
* @version V2.0.0
* @date 3/27/20
* @brief This is the header file for "hal_network.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 DJIs 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_NETWORK_H
#define HAL_NETWORK_H
/* Includes ------------------------------------------------------------------*/
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/** @attention User can config network card name here, if your device is not MF2C/G, please comment below and add your
* NIC name micro define as #define 'LINUX_NETWORK_DEV "your NIC name"'.
*/
#ifdef PLATFORM_ARCH_x86_64
#define LINUX_NETWORK_DEV "enp0s31f6"
#else
#define LINUX_NETWORK_DEV "eth0"
#endif
/**
* @attention
*/
#define LINUX_CMD_STR_MAX_SIZE (128)
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj);
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj);
#ifdef __cplusplus
}
#endif
#endif // HAL_NETWORK_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,260 @@
/**
********************************************************************
* @file hal_uart.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 DJIs 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_logger.h>
#include "hal_uart.h"
/* Private constants ---------------------------------------------------------*/
#define UART_DEV_NAME_STR_SIZE (128)
#define DJI_SYSTEM_CMD_MAX_SIZE (64)
#define DJI_SYSTEM_RESULT_STR_MAX_SIZE (128)
/* Private types -------------------------------------------------------------*/
typedef struct {
int uartFd;
} T_UartHandleStruct;
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle)
{
T_UartHandleStruct *uartHandleStruct;
struct termios options;
struct flock lock;
T_DjiReturnCode returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
char uartName[UART_DEV_NAME_STR_SIZE];
char systemCmd[DJI_SYSTEM_CMD_MAX_SIZE];
char *ret = NULL;
char lineBuf[DJI_SYSTEM_RESULT_STR_MAX_SIZE] = {0};
FILE *fp;
uartHandleStruct = malloc(sizeof(T_UartHandleStruct));
if (uartHandleStruct == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
if (uartNum == DJI_HAL_UART_NUM_0) {
strcpy(uartName, LINUX_UART_DEV1);
} else if (uartNum == DJI_HAL_UART_NUM_1) {
strcpy(uartName, LINUX_UART_DEV2);
} else {
goto free_uart_handle;
}
#ifdef USE_CLION_DEBUG
sprintf(systemCmd, "ls -l %s", uartName);
fp = popen(systemCmd, "r");
if (fp == NULL) {
goto free_uart_handle;
}
ret = fgets(lineBuf, sizeof(lineBuf), fp);
if (ret == NULL) {
goto close_fp;
}
if (strstr(lineBuf, "crwxrwxrwx") == NULL) {
USER_LOG_ERROR("Can't operation the device. "
"Probably the device has not operation permission. "
"Please execute command 'sudo chmod 777 %s' to add permission. ", uartName);
goto close_fp;
}
#else
sprintf(systemCmd, "chmod 777 %s", uartName);
fp = popen(systemCmd, "r");
if (fp == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#endif
uartHandleStruct->uartFd = open(uartName, (unsigned) O_RDWR | (unsigned) O_NOCTTY | (unsigned) O_NDELAY);
if (uartHandleStruct->uartFd == -1) {
goto close_fp;
}
// Forbid multiple psdk programs to access the serial port
lock.l_type = F_WRLCK;
lock.l_pid = getpid();
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
if (fcntl(uartHandleStruct->uartFd, F_GETLK, &lock) < 0) {
goto close_uart_fd;
}
if (lock.l_type != F_UNLCK) {
goto close_uart_fd;
}
lock.l_type = F_WRLCK;
lock.l_pid = getpid();
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
if (fcntl(uartHandleStruct->uartFd, F_SETLKW, &lock) < 0) {
goto close_uart_fd;
}
if (tcgetattr(uartHandleStruct->uartFd, &options) != 0) {
goto close_uart_fd;
}
switch (baudRate) {
case 115200:
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
break;
case 230400:
cfsetispeed(&options, B230400);
cfsetospeed(&options, B230400);
break;
case 460800:
cfsetispeed(&options, B460800);
cfsetospeed(&options, B460800);
break;
case 921600:
cfsetispeed(&options, B921600);
cfsetospeed(&options, B921600);
break;
case 1000000:
cfsetispeed(&options, B1000000);
cfsetospeed(&options, B1000000);
break;
default:
goto close_uart_fd;
}
options.c_cflag |= (unsigned) CLOCAL;
options.c_cflag |= (unsigned) CREAD;
options.c_cflag &= ~(unsigned) CRTSCTS;
options.c_cflag &= ~(unsigned) CSIZE;
options.c_cflag |= (unsigned) CS8;
options.c_cflag &= ~(unsigned) PARENB;
options.c_iflag &= ~(unsigned) INPCK;
options.c_cflag &= ~(unsigned) CSTOPB;
options.c_oflag &= ~(unsigned) OPOST;
options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG);
options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON);
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 0;
tcflush(uartHandleStruct->uartFd, TCIFLUSH);
if (tcsetattr(uartHandleStruct->uartFd, TCSANOW, &options) != 0) {
goto close_uart_fd;
}
*uartHandle = uartHandleStruct;
pclose(fp);
return returnCode;
close_uart_fd:
close(uartHandleStruct->uartFd);
close_fp:
pclose(fp);
free_uart_handle:
free(uartHandleStruct);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
ret = close(uartHandleStruct->uartFd);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
free(uartHandleStruct);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = write(uartHandleStruct->uartFd, buf, len);
if (ret >= 0) {
*realLen = ret;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = read(uartHandleStruct->uartFd, buf, len);
if (ret >= 0) {
*realLen = ret;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status)
{
if (uartNum == DJI_HAL_UART_NUM_0) {
status->isConnect = true;
} else if (uartNum == DJI_HAL_UART_NUM_1) {
status->isConnect = true;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,69 @@
/**
********************************************************************
* @file hal_uart.h
* @brief This is the header file for "hal_uart.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 DJIs 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_UART_H
#define HAL_UART_H
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include "stdlib.h"
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
//User can config dev based on there environmental conditions
#define LINUX_UART_DEV1 "/dev/ttyUSB0"
#define LINUX_UART_DEV2 "/dev/ttyACM0"
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle);
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle);
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status);
#ifdef __cplusplus
}
#endif
#endif // HAL_UART_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,199 @@
/**
********************************************************************
* @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 DJIs 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"
/* Private constants ---------------------------------------------------------*/
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1)
#define LINUX_USB_BULK_DEV1 "/dev/usb-ffs/bulk"
/* Private types -------------------------------------------------------------*/
typedef struct {
libusb_device_handle *handle;
int32_t ep1;
int32_t ep2;
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) {
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) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
if (ret != LIBUSB_SUCCESS) {
printf("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));
} else {
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open("/dev/usb-ffs/bulk/ep1", O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open("/dev/usb-ffs/bulk/ep2", 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) {
libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
osalHandler->TaskSleepMs(100);
libusb_exit(NULL);
} 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) {
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;
}
*realLen = actualLen;
} else {
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
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) {
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn,
buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER);
if (ret < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*realLen = actualLen;
} else {
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo)
{
//attention: need confirm your usb config in device mode.
deviceInfo->vid = 0x7020;
deviceInfo->pid = 0x9055;
deviceInfo->bulkChannelNum = 2;
deviceInfo->channelInfo[0].interfaceNum = 0;
deviceInfo->channelInfo[0].endPointIn = 0x01;
deviceInfo->channelInfo[0].endPointOut = 0x81;
deviceInfo->channelInfo[1].interfaceNum = 0;
deviceInfo->channelInfo[1].endPointIn = 0x02;
deviceInfo->channelInfo[1].endPointOut = 0x82;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,70 @@
/**
********************************************************************
* @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 DJIs 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>
#include <libusb-1.0/libusb.h>
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, 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_DeInit(T_DjiUsbBulkHandle usbBulkHandle);
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
#ifdef __cplusplus
}
#endif
#endif // HAL_USB_BULK_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/