first commit

This commit is contained in:
DESKTOP-4HD0KC3\ZhangZhuo
2024-10-30 15:04:53 +08:00
commit e7d6f4c57b
723 changed files with 7515585 additions and 0 deletions

View File

@ -0,0 +1,262 @@
/**
********************************************************************
* @file dji_media_file_core.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 <string.h>
#include <dji_logger.h>
#include "dji_media_file_core.h"
#include "dji_media_file_jpg.h"
#include "dji_media_file_mp4.h"
#include "dji_platform.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Private values ------------------------------------------------------------*/
//@formatter:off
static const T_DjiMediaFileOptItem s_mediaFileOpt[] =
{
//JPEG File Operation Item
{
DJI_CAMERA_FILE_TYPE_JPEG ,
DjiMediaFile_IsSupported_JPG,
DjiMediaFile_GetAttrFunc_JPG,
DjiMediaFile_GetDataOrigin_JPG,
DjiMediaFile_GetFileSizeOrigin_JPG,
DjiMediaFile_CreateThumbNail_JPG,
DjiMediaFile_GetFileSizeThumbNail_JPG,
DjiMediaFile_GetDataThumbNail_JPG,
DjiMediaFile_DestroyThumbNail_JPG,
DjiMediaFile_CreateScreenNail_JPG,
DjiMediaFile_GetFileSizeScreenNail_JPG,
DjiMediaFile_GetDataScreenNail_JPG,
DjiMediaFile_DestroyScreenNail_JPG,
},
//MP4 File Operation Item
{
DJI_CAMERA_FILE_TYPE_MP4 ,
DjiMediaFile_IsSupported_MP4,
DjiMediaFile_GetAttrFunc_MP4,
DjiMediaFile_GetDataOrigin_MP4,
DjiMediaFile_GetFileSizeOrigin_MP4,
DjiMediaFile_CreateThumbNail_MP4,
DjiMediaFile_GetFileSizeThumbNail_MP4,
DjiMediaFile_GetDataThumbNail_MP4,
DjiMediaFile_DestroyThumbNail_MP4,
DjiMediaFile_CreateScreenNail_MP4,
DjiMediaFile_GetFileSizeScreenNail_MP4,
DjiMediaFile_GetDataScreenNail_MP4,
DjiMediaFile_DestroyScreenNail_MP4,
},
};
static const uint32_t s_mediaFileOptCount = sizeof (s_mediaFileOpt) / sizeof(T_DjiMediaFileOptItem);
//@formatter:on
/* Exported functions definition ---------------------------------------------*/
bool DjiMediaFile_IsSupported(const char *filePath)
{
int i;
for (i = 0; i < s_mediaFileOptCount; i++) {
if (s_mediaFileOpt[i].isSupportedFunc(filePath) == true) {
return true;
}
}
return false;
}
T_DjiReturnCode DjiMediaFile_CreateHandle(const char *filePath, T_DjiMediaFileHandle *pMediaFileHandle)
{
int optIndex;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
for (optIndex = 0; optIndex < s_mediaFileOptCount; optIndex++) {
if (s_mediaFileOpt[optIndex].isSupportedFunc(filePath) == true) {
break;
}
}
if (optIndex == s_mediaFileOptCount) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
*pMediaFileHandle = osalHandler->Malloc(sizeof(T_DjiMediaFile));
if (*pMediaFileHandle == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
(*pMediaFileHandle)->filePath = osalHandler->Malloc(strlen(filePath) + 1);
if ((*pMediaFileHandle)->filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
(*pMediaFileHandle)->mediaFileOptItem = s_mediaFileOpt[optIndex];
(*pMediaFileHandle)->mediaFileThm.privThm = NULL;
(*pMediaFileHandle)->mediaFileScr.privScr = NULL;
strcpy((*pMediaFileHandle)->filePath, filePath);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiMediaFile_DestroyHandle(T_DjiMediaFileHandle mediaFileHandle)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
osalHandler->Free(mediaFileHandle->filePath);
osalHandler->Free(mediaFileHandle);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiMediaFile_GetMediaFileType(T_DjiMediaFileHandle mediaFileHandle,
E_DjiCameraMediaFileType *mediaFileType)
{
*mediaFileType = mediaFileHandle->mediaFileOptItem.mediaFileType;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiMediaFile_GetMediaFileAttr(T_DjiMediaFileHandle mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr)
{
if (mediaFileHandle->mediaFileOptItem.getAttrFunc == NULL) {
USER_LOG_ERROR("Media file handle getAttrFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getAttrFunc(mediaFileHandle, mediaFileAttr);
}
T_DjiReturnCode DjiMediaFile_GetDataOrg(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen)
{
if (mediaFileHandle->mediaFileOptItem.getDataOrgFunc == NULL) {
USER_LOG_ERROR("Media file handle getDataOrgFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getDataOrgFunc(mediaFileHandle, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeOrg(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
if (mediaFileHandle->mediaFileOptItem.getFileSizeOrgFunc == NULL) {
USER_LOG_ERROR("Media file handle getFileSizeOrgFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getFileSizeOrgFunc(mediaFileHandle, fileSize);
}
T_DjiReturnCode DjiMediaFile_CreateThm(T_DjiMediaFileHandle mediaFileHandle)
{
if (mediaFileHandle->mediaFileOptItem.createThmFunc == NULL) {
USER_LOG_ERROR("Media file handle createThmFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.createThmFunc(mediaFileHandle);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeThm(T_DjiMediaFileHandle mediaFileHandle, uint32_t *fileSize)
{
if (mediaFileHandle->mediaFileOptItem.getFileSizeThmFunc == NULL) {
USER_LOG_ERROR("Media file handle getFileSizeThmFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getFileSizeThmFunc(mediaFileHandle, fileSize);
}
T_DjiReturnCode DjiMediaFile_GetDataThm(T_DjiMediaFileHandle mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
if (mediaFileHandle->mediaFileOptItem.getDataThmFunc == NULL) {
USER_LOG_ERROR("Media file handle getDataThmFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getDataThmFunc(mediaFileHandle, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestoryThm(T_DjiMediaFileHandle mediaFileHandle)
{
if (mediaFileHandle->mediaFileOptItem.destroyThmFunc == NULL) {
USER_LOG_ERROR("Media file handle destroyThmFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.destroyThmFunc(mediaFileHandle);
}
T_DjiReturnCode DjiMediaFile_CreateScr(T_DjiMediaFileHandle mediaFileHandle)
{
if (mediaFileHandle->mediaFileOptItem.creatScrFunc == NULL) {
USER_LOG_ERROR("Media file handle creatScrFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.creatScrFunc(mediaFileHandle);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeScr(T_DjiMediaFileHandle mediaFileHandle, uint32_t *fileSize)
{
if (mediaFileHandle->mediaFileOptItem.getFileSizeScrFunc == NULL) {
USER_LOG_ERROR("Media file handle getFileSizeScrFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getFileSizeScrFunc(mediaFileHandle, fileSize);
}
T_DjiReturnCode DjiMediaFile_GetDataScr(T_DjiMediaFileHandle mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
if (mediaFileHandle->mediaFileOptItem.getDataScrFunc == NULL) {
USER_LOG_ERROR("Media file handle getDataScrFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.getDataScrFunc(mediaFileHandle, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestroyScr(T_DjiMediaFileHandle mediaFileHandle)
{
if (mediaFileHandle->mediaFileOptItem.destroyScrFunc == NULL) {
USER_LOG_ERROR("Media file handle destroyScrFunc null error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return mediaFileHandle->mediaFileOptItem.destroyScrFunc(mediaFileHandle);
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,115 @@
/**
********************************************************************
* @file dji_media_file_core.h
* @brief This is the header file for "dji_media_file_core.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 PSDK_MEDIA_FILE_CORE_H
#define PSDK_MEDIA_FILE_CORE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <dji_typedef.h>
#include <dji_payload_camera.h>
/* Exported constants --------------------------------------------------------*/
#define PSDK_MEDIA_FILE_PATH_LEN_MAX 512 /*max file path len */
#define PSDK_MEDIA_DIR_PATH_LEN_MAX 256 /*max dir path len */
/* Exported types ------------------------------------------------------------*/
typedef struct {
void *privThm;
} T_DjiMediaFileThm;
typedef struct {
void *privScr;
} T_DjiMediaFileScr;
struct _DjiMediaFile;
typedef struct {
E_DjiCameraMediaFileType mediaFileType;
bool (*isSupportedFunc)(const char *filePath);
T_DjiReturnCode (*getAttrFunc)(struct _DjiMediaFile *mediaFileHandle, T_DjiCameraMediaFileAttr *mediaFileAttr);
T_DjiReturnCode (*getDataOrgFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen);
T_DjiReturnCode (*getFileSizeOrgFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode (*createThmFunc)(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode (*getFileSizeThmFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode (*getDataThmFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode (*destroyThmFunc)(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode (*creatScrFunc)(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode (*getFileSizeScrFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode (*getDataScrFunc)(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode (*destroyScrFunc)(struct _DjiMediaFile *mediaFileHandle);
} T_DjiMediaFileOptItem;
typedef struct _DjiMediaFile {
char *filePath;
T_DjiMediaFileOptItem mediaFileOptItem;
T_DjiMediaFileThm mediaFileThm;
T_DjiMediaFileScr mediaFileScr;
} T_DjiMediaFile, *T_DjiMediaFileHandle;
/* Exported functions --------------------------------------------------------*/
bool DjiMediaFile_IsSupported(const char *filePath);
T_DjiReturnCode DjiMediaFile_CreateHandle(const char *filePath, T_DjiMediaFileHandle *pMediaFileHandle);
T_DjiReturnCode DjiMediaFile_DestroyHandle(T_DjiMediaFileHandle mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetMediaFileType(T_DjiMediaFileHandle mediaFileHandle,
E_DjiCameraMediaFileType *mediaFileType);
T_DjiReturnCode DjiMediaFile_GetMediaFileAttr(T_DjiMediaFileHandle mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr);
T_DjiReturnCode DjiMediaFile_GetDataOrg(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen);
T_DjiReturnCode DjiMediaFile_GetFileSizeOrg(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode DjiMediaFile_CreateThm(T_DjiMediaFileHandle mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeThm(T_DjiMediaFileHandle mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode DjiMediaFile_GetDataThm(T_DjiMediaFileHandle mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestoryThm(T_DjiMediaFileHandle mediaFileHandle);
T_DjiReturnCode DjiMediaFile_CreateScr(T_DjiMediaFileHandle mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeScr(T_DjiMediaFileHandle mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode DjiMediaFile_GetDataScr(T_DjiMediaFileHandle mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestroyScr(T_DjiMediaFileHandle mediaFileHandle);
#ifdef __cplusplus
}
#endif
#endif // PSDK_MEDIA_FILE_CORE_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,228 @@
/**
********************************************************************
* @file dji_media_file_jpg.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_media_file_jpg.h"
#include "dji_media_file_core.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <dji_logger.h>
#include <utils/util_misc.h>
#include "dji_platform.h"
#include "utils/util_time.h"
#include "utils/util_file.h"
/* Private constants ---------------------------------------------------------*/
#define JPG_FILE_SUFFIX ".jpg"
#define JPG_TEMP_FILE_TEMPLATE_STR "JPG_TEMP_XXXXXX.jpg"
#define JPG_TEMP_FILE_PATH_MAX_LEN 50
#define FFMPEG_CMD_BUF_SIZE 1024
#define JPG_THM_SCALE_CFG_STR "scale=100:-1"
#define JPG_SCR_SCALE_CFG_STR "scale=600:-1"
/* Private types -------------------------------------------------------------*/
typedef struct {
FILE *tempFile;
char tempfilePath[JPG_TEMP_FILE_PATH_MAX_LEN];
} T_DjiJPGTempFilePriv;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiMediaFile_CreateTempFilePriv_JPG(const char *srcFilePath, const char *scaleCfgStr,
T_DjiJPGTempFilePriv **pTempFilePrivHandle);
static T_DjiReturnCode DjiMediaFile_DestroyTempFilePriv_JPG(T_DjiJPGTempFilePriv *tempFilePrivHandle);
/* Exported functions definition ---------------------------------------------*/
bool DjiMediaFile_IsSupported_JPG(const char *filePath)
{
if (filePath == NULL) {
USER_LOG_ERROR("input parameter is null error");
return false;
}
if (strcmp(&filePath[strlen(filePath) - 4], JPG_FILE_SUFFIX) == 0) {
return true;
}
return false;
}
T_DjiReturnCode DjiMediaFile_GetAttrFunc_JPG(struct _DjiMediaFile *mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr)
{
USER_UTIL_UNUSED(mediaFileHandle);
mediaFileAttr->attrVideoDuration = 0;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiMediaFile_GetDataOrigin_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen)
{
return UtilFile_GetFileDataByPath(mediaFileHandle->filePath, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeOrigin_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
return UtilFile_GetFileSizeByPath(mediaFileHandle->filePath, fileSize);
}
T_DjiReturnCode DjiMediaFile_CreateThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_CreateTempFilePriv_JPG(mediaFileHandle->filePath, JPG_THM_SCALE_CFG_STR,
(T_DjiJPGTempFilePriv **) &mediaFileHandle->mediaFileThm.privThm);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
T_DjiJPGTempFilePriv *jpgFileThmPriv = (T_DjiJPGTempFilePriv *) mediaFileHandle->mediaFileThm.privThm;
return UtilFile_GetFileSize(jpgFileThmPriv->tempFile, fileSize);
}
T_DjiReturnCode
DjiMediaFile_GetDataThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
T_DjiJPGTempFilePriv *jpgFileThmPriv = (T_DjiJPGTempFilePriv *) mediaFileHandle->mediaFileThm.privThm;
return UtilFile_GetFileData(jpgFileThmPriv->tempFile, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestroyThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_DestroyTempFilePriv_JPG(mediaFileHandle->mediaFileThm.privThm);
}
T_DjiReturnCode DjiMediaFile_CreateScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_CreateTempFilePriv_JPG(mediaFileHandle->filePath, JPG_SCR_SCALE_CFG_STR,
(T_DjiJPGTempFilePriv **) &mediaFileHandle->mediaFileScr.privScr);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
T_DjiJPGTempFilePriv *jpgFileScrPriv = (T_DjiJPGTempFilePriv *) mediaFileHandle->mediaFileScr.privScr;
return UtilFile_GetFileSize(jpgFileScrPriv->tempFile, fileSize);
}
T_DjiReturnCode
DjiMediaFile_GetDataScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
T_DjiJPGTempFilePriv *jpgFileScrPriv = (T_DjiJPGTempFilePriv *) mediaFileHandle->mediaFileScr.privScr;
return UtilFile_GetFileData(jpgFileScrPriv->tempFile, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestroyScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_DestroyTempFilePriv_JPG(mediaFileHandle->mediaFileScr.privScr);
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiMediaFile_CreateTempFilePriv_JPG(const char *srcFilePath, const char *scaleCfgStr,
T_DjiJPGTempFilePriv **pTempFilePrivHandle)
{
char ffmpeg_cmd[FFMPEG_CMD_BUF_SIZE];
int cmdRet;
T_DjiRunTimeStamps tiStart, tiEnd;
T_DjiJPGTempFilePriv *jpgTempFilePriv;
T_DjiReturnCode psdkStat;
int tempFd;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
tiStart = DjiUtilTime_GetRunTimeStamps();
*pTempFilePrivHandle = osalHandler->Malloc(sizeof(T_DjiJPGTempFilePriv));
if (*pTempFilePrivHandle == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
jpgTempFilePriv = *pTempFilePrivHandle;
//get temp file name
strcpy(jpgTempFilePriv->tempfilePath, JPG_TEMP_FILE_TEMPLATE_STR);
tempFd = mkstemps(jpgTempFilePriv->tempfilePath, strlen(JPG_FILE_SUFFIX));
if (tempFd < 0) {
USER_LOG_ERROR("JPG Create Temp File Error, tempFd = %d\n", tempFd);
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_create_temp;
}
close(tempFd);
unlink(jpgTempFilePriv->tempfilePath);
//ffmpeg cmd send
snprintf(ffmpeg_cmd, FFMPEG_CMD_BUF_SIZE, "ffmpeg -i \"%s\" -vf %s %s 1>/dev/null 2>&1",
srcFilePath, scaleCfgStr, jpgTempFilePriv->tempfilePath);
cmdRet = system(ffmpeg_cmd);
tiEnd = DjiUtilTime_GetRunTimeStamps();
USER_LOG_DEBUG("JPG Create TempFile, RealTime = %ld us\n", tiEnd.realUsec - tiStart.realUsec);
if (cmdRet != 0) {
USER_LOG_ERROR("JPG ffmpeg cmd call error, ret = %d\n", cmdRet);
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_system_cmd;
}
//open temp file
jpgTempFilePriv->tempFile = fopen(jpgTempFilePriv->tempfilePath, "rb+");
if (jpgTempFilePriv->tempFile == NULL) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_file_open;
}
//unlink temp file
unlink(jpgTempFilePriv->tempfilePath);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
err_file_open:
unlink(jpgTempFilePriv->tempfilePath);
err_system_cmd:
err_create_temp:
osalHandler->Free(*pTempFilePrivHandle);
return psdkStat;
}
static T_DjiReturnCode DjiMediaFile_DestroyTempFilePriv_JPG(T_DjiJPGTempFilePriv *tempFilePrivHandle)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
fclose(tempFilePrivHandle->tempFile);
osalHandler->Free(tempFilePrivHandle);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,75 @@
/**
********************************************************************
* @file dji_media_file_jpg.h
* @brief This is the header file for "dji_media_file_jpg.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 PSDK_MEDIA_FILE_JPG_H
#define PSDK_MEDIA_FILE_JPG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <dji_payload_camera.h>
#include <dji_typedef.h>
#include "dji_media_file_core.h"
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
bool DjiMediaFile_IsSupported_JPG(const char *filePath);
T_DjiReturnCode DjiMediaFile_GetAttrFunc_JPG(struct _DjiMediaFile *mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr);
T_DjiReturnCode DjiMediaFile_GetDataOrigin_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen);
T_DjiReturnCode DjiMediaFile_GetFileSizeOrigin_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode DjiMediaFile_CreateThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode
DjiMediaFile_GetDataThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestroyThumbNail_JPG(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode DjiMediaFile_CreateScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode
DjiMediaFile_GetDataScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestroyScreenNail_JPG(struct _DjiMediaFile *mediaFileHandle);
#ifdef __cplusplus
}
#endif
#endif // PSDK_MEIDA_FILE_JPG_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,262 @@
/**
********************************************************************
* @file dji_media_file_mp4.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_media_file_mp4.h"
#include "dji_media_file_core.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <dji_logger.h>
#include <stdlib.h>
#include "dji_platform.h"
#include "utils/util_time.h"
#include "utils/util_file.h"
/* Private constants ---------------------------------------------------------*/
#define MP4_FILE_SUFFIX ".mp4"
#define MP4_TEMP_FILE_TEMPLATE_STR "MP4_TEMP_XXXXXX.jpg"
#define MP4_TEMP_FILE_PATH_MAX_LEN 50
#define FFMPEG_CMD_BUF_SIZE (256 + 256)
#define MP4_THM_SCALE_CFG_STR "scale=100:-1"
#define MP4_SCR_SCALE_CFG_STR "scale=600:-1"
/* Private types -------------------------------------------------------------*/
typedef struct {
FILE *tempFile;
char tempfilePath[MP4_TEMP_FILE_PATH_MAX_LEN];
} T_DjiMP4TempPicPriv;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiMediaFile_CreateTempPicPriv_MP4(const char *srcFilePath, const char *scaleCfgStr,
T_DjiMP4TempPicPriv **pTempPicPrivHandle);
static T_DjiReturnCode DjiMediaFile_DestroyTempPicPriv_MP4(T_DjiMP4TempPicPriv *tempPicPrivHandle);
/* Private values ------------------------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
bool DjiMediaFile_IsSupported_MP4(const char *filePath)
{
if (filePath == NULL) {
USER_LOG_ERROR("input parameter is null error");
return false;
}
if (strcmp(&filePath[strlen(filePath) - 4], MP4_FILE_SUFFIX) == 0) {
return true;
}
return false;
}
T_DjiReturnCode DjiMediaFile_GetAttrFunc_MP4(struct _DjiMediaFile *mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr)
{
FILE *fp;
char ffmpegCmdStr[FFMPEG_CMD_BUF_SIZE];
float hour, minute, second;
char tempTailStr[128];
int ret;
T_DjiReturnCode psdkStat;
snprintf(ffmpegCmdStr, FFMPEG_CMD_BUF_SIZE, "ffmpeg -i \"%s\" 2>&1 | grep \"Duration\"", mediaFileHandle->filePath);
fp = popen(ffmpegCmdStr, "r");
if (fp == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = fscanf(fp, " Duration: %f:%f:%f,%127s", &hour, &minute, &second, tempTailStr);
if (ret <= 0) {
USER_LOG_ERROR("MP4 File Get Duration Error\n");
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto out;
}
mediaFileAttr->attrVideoDuration = (uint32_t) (hour * 3600 + minute * 60 + second + 0.5);
/*! The user needs to obtain the frame rate and resolution of the video file by ffmpeg tools.
* Also the frame rate and resolution of video need convert to enum E_DjiCameraVideoFrameRate or
* E_DjiCameraVideoResolution.
*/
mediaFileAttr->attrVideoFrameRate = DJI_CAMERA_VIDEO_FRAME_RATE_30_FPS;
mediaFileAttr->attrVideoResolution = DJI_CAMERA_VIDEO_RESOLUTION_1920x1080;
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
out:
pclose(fp);
return psdkStat;
}
T_DjiReturnCode DjiMediaFile_GetDataOrigin_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen)
{
return UtilFile_GetFileDataByPath(mediaFileHandle->filePath, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeOrigin_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
return UtilFile_GetFileSizeByPath(mediaFileHandle->filePath, fileSize);
}
T_DjiReturnCode DjiMediaFile_CreateThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_CreateTempPicPriv_MP4(mediaFileHandle->filePath, MP4_THM_SCALE_CFG_STR,
(T_DjiMP4TempPicPriv **) &mediaFileHandle->mediaFileThm.privThm);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
T_DjiMP4TempPicPriv *jpgFileThmPriv = (T_DjiMP4TempPicPriv *) mediaFileHandle->mediaFileThm.privThm;
return UtilFile_GetFileSize(jpgFileThmPriv->tempFile, fileSize);
}
T_DjiReturnCode
DjiMediaFile_GetDataThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
T_DjiMP4TempPicPriv *jpgFileThmPriv = (T_DjiMP4TempPicPriv *) mediaFileHandle->mediaFileThm.privThm;
return UtilFile_GetFileData(jpgFileThmPriv->tempFile, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestroyThumbNail_MP4(struct _DjiMediaFile *MediaFileHandle)
{
return DjiMediaFile_DestroyTempPicPriv_MP4(MediaFileHandle->mediaFileThm.privThm);
}
T_DjiReturnCode DjiMediaFile_CreateScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_CreateTempPicPriv_MP4(mediaFileHandle->filePath, MP4_SCR_SCALE_CFG_STR,
(T_DjiMP4TempPicPriv **) &mediaFileHandle->mediaFileScr.privScr);
}
T_DjiReturnCode DjiMediaFile_GetFileSizeScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize)
{
T_DjiMP4TempPicPriv *jpgFileScrPriv = (T_DjiMP4TempPicPriv *) mediaFileHandle->mediaFileScr.privScr;
return UtilFile_GetFileSize(jpgFileScrPriv->tempFile, fileSize);
}
T_DjiReturnCode
DjiMediaFile_GetDataScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen)
{
T_DjiMP4TempPicPriv *jpgFileScrPriv = (T_DjiMP4TempPicPriv *) mediaFileHandle->mediaFileScr.privScr;
return UtilFile_GetFileData(jpgFileScrPriv->tempFile, offset, len, data, realLen);
}
T_DjiReturnCode DjiMediaFile_DestroyScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle)
{
return DjiMediaFile_DestroyTempPicPriv_MP4(mediaFileHandle->mediaFileScr.privScr);
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiMediaFile_CreateTempPicPriv_MP4(const char *srcFilePath, const char *scaleCfgStr,
T_DjiMP4TempPicPriv **pTempPicPrivHandle)
{
char ffmpeg_cmd[FFMPEG_CMD_BUF_SIZE];
int cmdRet;
T_DjiRunTimeStamps tiStart, tiEnd;
T_DjiMP4TempPicPriv *mp4TempPicFile;
T_DjiReturnCode psdkStat;
int tempFd;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
tiStart = DjiUtilTime_GetRunTimeStamps();
*pTempPicPrivHandle = osalHandler->Malloc(sizeof(T_DjiMP4TempPicPriv));
if (*pTempPicPrivHandle == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
mp4TempPicFile = *pTempPicPrivHandle;
//get temp file name
strcpy(mp4TempPicFile->tempfilePath, MP4_TEMP_FILE_TEMPLATE_STR);
tempFd = mkstemps(mp4TempPicFile->tempfilePath, strlen(MP4_FILE_SUFFIX));
if (tempFd < 0) {
USER_LOG_ERROR("JPG Create Temp File Error, tempFd = %d\n", tempFd);
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_create_temp;
}
close(tempFd);
unlink(mp4TempPicFile->tempfilePath);
//ffmpeg cmd send
snprintf(ffmpeg_cmd, FFMPEG_CMD_BUF_SIZE, "ffmpeg -i \"%s\" -vf %s -ss 00:00:00 -vframes 1 %s 1>/dev/null 2>&1",
srcFilePath, scaleCfgStr, mp4TempPicFile->tempfilePath);
cmdRet = system(ffmpeg_cmd);
tiEnd = DjiUtilTime_GetRunTimeStamps();
USER_LOG_DEBUG("JPG Create TempFile, RealTime = %ld us\n", tiEnd.realUsec - tiStart.realUsec);
if (cmdRet != 0) {
USER_LOG_ERROR("JPG ffmpeg cmd call error, ret = %d\n", cmdRet);
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_system_cmd;
}
//open temp file
mp4TempPicFile->tempFile = fopen(mp4TempPicFile->tempfilePath, "rb+");
if (mp4TempPicFile->tempFile == NULL) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto err_file_open;
}
//unlink temp file
unlink(mp4TempPicFile->tempfilePath);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
err_file_open:
unlink(mp4TempPicFile->tempfilePath);
err_system_cmd:
err_create_temp:
osalHandler->Free(*pTempPicPrivHandle);
return psdkStat;
}
static T_DjiReturnCode DjiMediaFile_DestroyTempPicPriv_MP4(T_DjiMP4TempPicPriv *tempPicPrivHandle)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
fclose(tempPicPrivHandle->tempFile);
osalHandler->Free(tempPicPrivHandle);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,75 @@
/**
********************************************************************
* @file dji_media_file_mp4.h
* @brief This is the header file for "dji_media_file_mp4.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 PSDK_MEDIA_FILE_MP4_H
#define PSDK_MEDIA_FILE_MP4_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <dji_payload_camera.h>
#include <dji_typedef.h>
#include "dji_media_file_core.h"
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
bool DjiMediaFile_IsSupported_MP4(const char *filePath);
T_DjiReturnCode DjiMediaFile_GetAttrFunc_MP4(struct _DjiMediaFile *mediaFileHandle,
T_DjiCameraMediaFileAttr *mediaFileAttr);
T_DjiReturnCode DjiMediaFile_GetDataOrigin_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint32_t *realLen);
T_DjiReturnCode DjiMediaFile_GetFileSizeOrigin_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode DjiMediaFile_CreateThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode
DjiMediaFile_GetDataThumbNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestroyThumbNail_MP4(struct _DjiMediaFile *MediaFileHandle);
T_DjiReturnCode DjiMediaFile_CreateScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle);
T_DjiReturnCode DjiMediaFile_GetFileSizeScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t *fileSize);
T_DjiReturnCode
DjiMediaFile_GetDataScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle, uint32_t offset, uint16_t len,
uint8_t *data, uint16_t *realLen);
T_DjiReturnCode DjiMediaFile_DestroyScreenNail_MP4(struct _DjiMediaFile *mediaFileHandle);
#ifdef __cplusplus
}
#endif
#endif // PSDK_MEDIA_FILE_MP4_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
/**
********************************************************************
* @file test_payload_cam_emu_common.h
* @brief This is the header file for "test_payload_cam_emu.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 TEST_PAYLOAD_CAM_EMU_BASE_H
#define TEST_PAYLOAD_CAM_EMU_BASE_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_payload_camera.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_CameraEmuBaseStartService(void);
T_DjiReturnCode DjiTest_CameraGetDigitalZoomFactor(dji_f32_t *factor);
T_DjiReturnCode DjiTest_CameraGetOpticalZoomFactor(dji_f32_t *factor);
T_DjiReturnCode DjiTest_CameraGetMode(E_DjiCameraMode *mode);
T_DjiReturnCode DjiTest_CameraGetVideoStreamType(E_DjiCameraVideoStreamType *type);
bool DjiTest_CameraIsInited(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_PAYLOAD_CAM_EMU_BASE_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
/**
********************************************************************
* @file test_payload_cam_emu_media.h
* @brief This is the header file for "test_payload_cam_media.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 TEST_PAYLOAD_CAM_EMU_MEDIA_H
#define TEST_PAYLOAD_CAM_EMU_MEDIA_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_payload_camera.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_CameraEmuMediaStartService(void);
T_DjiReturnCode DjiTest_CameraEmuSetMediaFilePath(const char *path);
T_DjiReturnCode DjiTest_CameraMediaGetFileInfo(const char *filePath, T_DjiCameraMediaFileInfo *fileInfo);
#ifdef __cplusplus
}
#endif
#endif // TEST_PAYLOAD_CAM_EMU_MEDIA_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,274 @@
/**
********************************************************************
* @file test_camera_manager.h
* @brief This is the header file for "test_camera_manager.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 TEST_CAMERA_MANAGER_H
#define TEST_CAMERA_MANAGER_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_camera_manager.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum {
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_SHUTTER_SPEED,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_APERTURE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_EV,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_ISO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_FOCUS_POINT,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_TAP_ZOOM_POINT,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAMERA_ZOOM_PARAM,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SHOOT_SINGLE_PHOTO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SHOOT_BURST_PHOTO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SHOOT_INTERVAL_PHOTO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_RECORD_VIDEO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_DOWNLOAD_AND_DELETE_MEDIA_FILE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_DOWNLOAD_FILE_LIST_BY_SLICES,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_THERMOMETRY,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_GET_LIDAR_RANGING_INFO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_IR_CAMERA_ZOOM_PARAM,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_NIGHT_SCENE_MODE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_CAPTURE_RECORDING_STREAMS,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SHOW_STORAGE_INFO,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_FORMAT_SD_CARD,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_LINK_ZOOM,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_USER_CUSTOM_DIR_FILE_NAME,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_RESET_CAMERA_SETTINGS,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_AE_LOCK_MODE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_FOCUS_RING_VALUE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_CONNECT_STATUS_TEST,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_GET_PHOTO_VIDEO_PARAM,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_METERING_MODE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_METERING_POINT,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_FFC_MODE_AND_TRRIGER,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SET_GAIN_MODE,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_GET_CAMERA_STATUS,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_SUBSCRIBE_POINT_CLOUD,
E_DJI_TEST_CAMERA_MANAGER_SAMPLE_SELECT_INDEX_MAX
} E_DjiTestCameraManagerSampleSelect;
/* Exported functions --------------------------------------------------------*/
/*! @brief Sample to set exposure compensation value for camera, using async
* api
*
* @note In this interface, exposure compensation value will be got then be
* set.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param dataTarget the target exposure compensation value
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetEV(E_DjiMountPosition position,
E_DjiCameraManagerExposureCompensation exposureCompensation);
/*! @brief Sample to set exposure mode for camera, using async api
*
* @note In this interface, exposure will be got then be set.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param dataTarget the target exposure mode
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetExposureMode(E_DjiMountPosition position,
E_DjiCameraManagerExposureMode exposureMode);
/*! @brief Sample to set ISO value for camera, using async api
*
* @note In this interface, ISO will be got then be set.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param dataTarget the target ISO value
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetISO(E_DjiMountPosition position,
E_DjiCameraManagerISO isoData);
/*! @brief Sample to set shutter speed for camera, using async api
*
* @note In this interface, shutter speed will be got then be set.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param dataTarget the target shutter speed
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetShutterSpeed(E_DjiMountPosition position,
E_DjiCameraManagerShutterSpeed shutterSpeed);
/*! @brief Sample to set shutter aperture value for camera, using async api
*
* @note In this interface, aperture value will be got then be set.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param dataTarget the target aperture value
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetAperture(E_DjiMountPosition position,
E_DjiCameraManagerAperture aperture);
/*! @brief Sample to set focus point for camera, using async api
*
* @note In this interface, focus mode will be set to be AUTO. Then the
* focus point will be set to be (x, y)
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param x the x value of target focus point, 0~1
* @param y the y value of target focus point, 0~1
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetFocusPoint(E_DjiMountPosition position,
T_DjiCameraManagerFocusPosData tapFocusPos);
/*! @brief Sample to set tap-zoom point for camera, using async api
*
* @note In this interface, tap-zoom function will be enable and the
* multiplier will be set. Then the tap-zoom function will start with the
* target tap-zoom point (x, y)
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param multiplier the zoom multiplier of each tap zoom
* @param x the x value of target tap-zoom point, 0~1
* @param y the y value of target tap-zoom point, 0~1
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerSetTapZoomPoint(E_DjiMountPosition position, uint8_t multiplier,
T_DjiCameraManagerTapZoomPosData tapZoomPosData);
/*! @brief Sample to execute continuous zoom on camera, using sync api
*
* @note It is only supported by X5, X5R and X5S camera on Osmo with lens
* Olympus M.Zuiko ED 14-42mm f/3.5-5.6 EZ, Z3 camera, Z30 camera.
* @note In this interface, the zoom will start with the designated direction
* and speed, and will stop after zoomTimeInSecond second(s).
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param direction the choice of zoom out or zoom in
* @param speed zooming speed
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStartContinuousZoom(E_DjiMountPosition position,
E_DjiCameraZoomDirection zoomDirection,
E_DjiCameraZoomSpeed zoomSpeed);
/*! @brief Sample to execute position zoom on camera, using sync api
*
* @note It is only supported by X5, X5R and X5S camera on Osmo with lens
* Olympus M.Zuiko ED 14-42mm f/3.5-5.6 EZ, Z3 camera, Z30 camera.
* @note In this interface, the zoom will set the zoom factor as the your
* target value.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param factor target zoom factor
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerOpticalZoom(E_DjiMountPosition position,
E_DjiCameraZoomDirection zoomDirection,
dji_f32_t factor);
/*! @brief Sample to stop continuous zoom on camera, using async api
*
* @note It is only supported by X5, X5R and X5S camera on Osmo with lens
* Olympus M.Zuiko ED 14-42mm f/3.5-5.6 EZ, Z3 camera, Z30 camera.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStopContinuousZoom(E_DjiMountPosition position);
/*! @brief Sample to shoot single photo, using async api
*
* @note In this interface, camera will be set to be the SHOOT_PHOTO mode
* then start to shoot a single photo.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStartShootSinglePhoto(E_DjiMountPosition position);
/*! @brief Sample to shoot burst photo, using async api
*
* @note In this interface, camera will be set to be the SHOOT_PHOTO mode
* then start to shoot a burst photo.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param count The number of pictures in each burst shooting
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStartShootBurstPhoto(E_DjiMountPosition position,
E_DjiCameraBurstCount burstCount);
/*! @brief Sample to start shooting interval photo, using async api
*
* @note In this interface, camera will be set to be the SHOOT_PHOTO mode
* then start to shoot a interval photo.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @param intervalData the parameter of interval shooting
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStartShootIntervalPhoto(E_DjiMountPosition position,
T_DjiCameraPhotoTimeIntervalSettings intervalData);
/*! @brief Sample to stop shooting, using async api
*
* @note In this interface, camera will stop all the shooting action
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStopShootPhoto(E_DjiMountPosition position);
/*! @brief Sample to start record video, using async api
*
* @note In this interface, camera will be set to be the RECORD_VIDEO mode
* then start to record video.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStartRecordVideo(E_DjiMountPosition position);
/*! @brief Sample to stop record video, using async api
*
* @note In this interface, camera will be set to be the RECORD_VIDEO mode
* then stop recording video.
* @param index payload node index, input limit see enum
* DJI::OSDK::PayloadIndexType
* @return T_DjiReturnCode error code
*/
T_DjiReturnCode DjiTest_CameraManagerStopRecordVideo(E_DjiMountPosition position);
T_DjiReturnCode DjiTest_CameraManagerRunSample(E_DjiMountPosition mountPosition,
E_DjiTestCameraManagerSampleSelect cameraManagerSampleSelect);
#ifdef __cplusplus
}
#endif
#endif // TEST_CAMERA_MANAGER_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,387 @@
/**
********************************************************************
* @file test_data_transmission.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 "test_data_transmission.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "utils/util_misc.h"
#include "dji_low_speed_data_channel.h"
#include "dji_high_speed_data_channel.h"
#include "dji_aircraft_info.h"
#include "widget_interaction_test/test_widget_interaction.h"
/* Private constants ---------------------------------------------------------*/
#define DATA_TRANSMISSION_TASK_FREQ (1)
#define DATA_TRANSMISSION_TASK_STACK_SIZE (2048)
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void *UserDataTransmission_Task(void *arg);
static T_DjiReturnCode ReceiveDataFromMobile(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromCloud(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromExtensionPort(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromPayload(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromPayload1(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromPayload2(const uint8_t *data, uint16_t len);
static T_DjiReturnCode ReceiveDataFromPayload3(const uint8_t *data, uint16_t len);
/* Private variables ---------------------------------------------------------*/
static T_DjiTaskHandle s_userDataTransmissionThread;
static T_DjiAircraftInfoBaseInfo s_aircraftInfoBaseInfo;
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_DataTransmissionStartService(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
E_DjiChannelAddress channelAddress;
const T_DjiDataChannelBandwidthProportionOfHighspeedChannel bandwidthProportionOfHighspeedChannel =
{10, 60, 30};
char ipAddr[DJI_IP_ADDR_STR_SIZE_MAX];
uint16_t port;
djiStat = DjiLowSpeedDataChannel_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("init data transmission module error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiAircraftInfo_GetBaseInfo(&s_aircraftInfoBaseInfo);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get aircraft base info error");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
channelAddress = DJI_CHANNEL_ADDRESS_MASTER_RC_APP;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromMobile);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from mobile error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (s_aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M30 ||
s_aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M30T) {
channelAddress = DJI_CHANNEL_ADDRESS_CLOUD_API;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromCloud);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from cloud error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
}
if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO2 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO3) {
channelAddress = DJI_CHANNEL_ADDRESS_EXTENSION_PORT;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromExtensionPort);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from extension port error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiHighSpeedDataChannel_SetBandwidthProportion(bandwidthProportionOfHighspeedChannel);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set data channel bandwidth width proportion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiHighSpeedDataChannel_GetDataStreamRemoteAddress(ipAddr, &port);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG("Get data stream remote address: %s, port: %d", ipAddr, port);
} else {
USER_LOG_ERROR("get data stream remote address error.");
}
} else if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_EXTENSION_PORT
|| DJI_MOUNT_POSITION_EXTENSION_LITE_PORT == s_aircraftInfoBaseInfo.mountPosition) {
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO1;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromPayload1);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from payload NO1 error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO2;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromPayload2);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from payload NO1 error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO3;
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromPayload3);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register receive data from payload NO1 error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_NONSUPPORT;
}
if (osalHandler->TaskCreate("user_transmission_task", UserDataTransmission_Task,
DATA_TRANSMISSION_TASK_STACK_SIZE, NULL, &s_userDataTransmissionThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user data transmission task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_DataTransmissionStopService(void)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiReturnCode returnCode;
if (osalHandler->TaskDestroy(s_userDataTransmissionThread) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user data transmission task destroy error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = DjiLowSpeedDataChannel_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("deinit data transmission module error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *UserDataTransmission_Task(void *arg)
{
T_DjiReturnCode djiStat;
const uint8_t dataToBeSent[] = "DJI Data Transmission Test Data.";
T_DjiDataChannelState state = {0};
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
E_DjiChannelAddress channelAddress;
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->TaskSleepMs(1000 / DATA_TRANSMISSION_TASK_FREQ);
channelAddress = DJI_CHANNEL_ADDRESS_MASTER_RC_APP;
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to mobile error.");
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"send to mobile state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
state.busyState);
} else {
USER_LOG_ERROR("get send to mobile channel state error.");
}
if (s_aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M30 ||
s_aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M30T) {
channelAddress = DJI_CHANNEL_ADDRESS_CLOUD_API;
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to cloud error.");
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"send to cloud state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
state.busyState);
} else {
USER_LOG_ERROR("get send to cloud channel state error.");
}
}
if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO2 ||
s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_PAYLOAD_PORT_NO3) {
channelAddress = DJI_CHANNEL_ADDRESS_EXTENSION_PORT;
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to extension port error.");
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"send to extension port state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
state.busyState);
} else {
USER_LOG_ERROR("get send to extension port channel state error.");
}
if (DjiPlatform_GetSocketHandler() != NULL) {
#ifdef SYSTEM_ARCH_LINUX
djiStat = DjiHighSpeedDataChannel_SendDataStreamData(dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to data stream error.");
djiStat = DjiHighSpeedDataChannel_GetDataStreamState(&state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"data stream state: realtimeBandwidthLimit: %d, realtimeBandwidthBeforeFlowController: %d, busyState: %d.",
state.realtimeBandwidthLimit, state.realtimeBandwidthBeforeFlowController, state.busyState);
} else {
USER_LOG_ERROR("get data stream state error.");
}
#endif
}
} else if (s_aircraftInfoBaseInfo.mountPosition == DJI_MOUNT_POSITION_EXTENSION_PORT
|| DJI_MOUNT_POSITION_EXTENSION_LITE_PORT == s_aircraftInfoBaseInfo.mountPosition) {
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO1;
djiStat = DjiLowSpeedDataChannel_SendData(channelAddress, dataToBeSent, sizeof(dataToBeSent));
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
USER_LOG_ERROR("send data to extension port error.");
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_DEBUG(
"send to extension port state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
state.busyState);
} else {
USER_LOG_ERROR("get send to extension port channel state error.");
}
}
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
static T_DjiReturnCode ReceiveDataFromMobile(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from mobile: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveDataFromCloud(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from cloud: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveDataFromExtensionPort(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from extension port: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveDataFromPayload(const uint8_t *data, uint16_t len)
{
char *printData = NULL;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
printData = osalHandler->Malloc(len + 1);
if (printData == NULL) {
USER_LOG_ERROR("malloc memory for printData fail.");
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
strncpy(printData, (const char *) data, len);
printData[len] = '\0';
USER_LOG_INFO("receive data from payload port: %s, len:%d.", printData, len);
DjiTest_WidgetLogAppend("receive data: %s, len:%d.", printData, len);
osalHandler->Free(printData);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveDataFromPayload1(const uint8_t *data, uint16_t len)
{
USER_LOG_INFO("Receive from payload on port 1");
return ReceiveDataFromPayload(data, len);
}
static T_DjiReturnCode ReceiveDataFromPayload2(const uint8_t *data, uint16_t len)
{
USER_LOG_INFO("Receive from payload on port 2");
return ReceiveDataFromPayload(data, len);
}
static T_DjiReturnCode ReceiveDataFromPayload3(const uint8_t *data, uint16_t len)
{
USER_LOG_INFO("Receive from payload on port 3");
return ReceiveDataFromPayload(data, len);
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,52 @@
/**
********************************************************************
* @file test_data_transmission.h
* @brief This is the header file for "test_data_transmission.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 TEST_DATA_TRANSMISSION_H
#define TEST_DATA_TRANSMISSION_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_DataTransmissionStartService(void);
T_DjiReturnCode DjiTest_DataTransmissionStopService(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_DATA_TRANSMISSION_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,355 @@
/**
********************************************************************
* @file test_fc_subscription.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 <utils/util_misc.h>
#include <math.h>
#include "test_fc_subscription.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "widget_interaction_test/test_widget_interaction.h"
/* Private constants ---------------------------------------------------------*/
#define FC_SUBSCRIPTION_TASK_FREQ (1)
#define FC_SUBSCRIPTION_TASK_STACK_SIZE (1024)
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void *UserFcSubscription_Task(void *arg);
static T_DjiReturnCode DjiTest_FcSubscriptionReceiveQuaternionCallback(const uint8_t *data, uint16_t dataSize,
const T_DjiDataTimestamp *timestamp);
/* Private variables ---------------------------------------------------------*/
static T_DjiTaskHandle s_userFcSubscriptionThread;
static bool s_userFcSubscriptionDataShow = false;
static uint8_t s_totalSatelliteNumberUsed = 0;
static uint32_t s_userFcSubscriptionDataCnt = 0;
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_FcSubscriptionStartService(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = NULL;
osalHandler = DjiPlatform_GetOsalHandler();
djiStat = DjiFcSubscription_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("init data subscription module error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ,
DjiTest_FcSubscriptionReceiveQuaternionCallback);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic quaternion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
} else {
USER_LOG_DEBUG("Subscribe topic quaternion success.");
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic velocity error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
} else {
USER_LOG_DEBUG("Subscribe topic velocity success.");
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic gps position error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
} else {
USER_LOG_DEBUG("Subscribe topic gps position success.");
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_DETAILS, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic gps details error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
} else {
USER_LOG_DEBUG("Subscribe topic gps details success.");
}
if (osalHandler->TaskCreate("user_subscription_task", UserFcSubscription_Task,
FC_SUBSCRIPTION_TASK_STACK_SIZE, NULL, &s_userFcSubscriptionThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user data subscription task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_FcSubscriptionRunSample(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiFcSubscriptionVelocity velocity = {0};
T_DjiDataTimestamp timestamp = {0};
T_DjiFcSubscriptionGpsPosition gpsPosition = {0};
T_DjiFcSubscriptionSingleBatteryInfo singleBatteryInfo = {0};
USER_LOG_INFO("Fc subscription sample start");
s_userFcSubscriptionDataShow = true;
USER_LOG_INFO("--> Step 1: Init fc subscription module");
djiStat = DjiFcSubscription_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("init data subscription module error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
USER_LOG_INFO("--> Step 2: Subscribe the topics of quaternion, velocity and gps position");
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ,
DjiTest_FcSubscriptionReceiveQuaternionCallback);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic quaternion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic velocity error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic gps position error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
USER_LOG_INFO("--> Step 3: Get latest value of the subscribed topics in the next 10 seconds\r\n");
for (int i = 0; i < 10; ++i) {
osalHandler->TaskSleepMs(1000 / FC_SUBSCRIPTION_TASK_FREQ);
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,
(uint8_t *) &velocity,
sizeof(T_DjiFcSubscriptionVelocity),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic velocity error.");
} else {
USER_LOG_INFO("velocity: x = %f y = %f z = %f healthFlag = %d, timestamp ms = %d us = %d.", velocity.data.x,
velocity.data.y,
velocity.data.z, velocity.health, timestamp.millisecond, timestamp.microsecond);
}
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION,
(uint8_t *) &gpsPosition,
sizeof(T_DjiFcSubscriptionGpsPosition),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic gps position error.");
} else {
USER_LOG_INFO("gps position: x = %d y = %d z = %d.", gpsPosition.x, gpsPosition.y, gpsPosition.z);
}
//Attention: if you want to subscribe the single battery info on M300 RTK, you need connect USB cable to
//OSDK device or use topic DJI_FC_SUBSCRIPTION_TOPIC_BATTERY_INFO instead.
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_BATTERY_SINGLE_INFO_INDEX1,
(uint8_t *) &singleBatteryInfo,
sizeof(T_DjiFcSubscriptionSingleBatteryInfo),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic battery single info index1 error.");
} else {
USER_LOG_INFO(
"battery single info index1: capacity percent = %ld% voltage = %ldV temperature = %.2f degree.",
singleBatteryInfo.batteryCapacityPercent,
singleBatteryInfo.currentVoltage / 1000,
(dji_f32_t) singleBatteryInfo.batteryTemperature / 10);
}
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_BATTERY_SINGLE_INFO_INDEX2,
(uint8_t *) &singleBatteryInfo,
sizeof(T_DjiFcSubscriptionSingleBatteryInfo),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic battery single info index2 error.");
} else {
USER_LOG_INFO(
"battery single info index2: capacity percent = %ld% voltage = %ldV temperature = %.2f degree.\r\n",
singleBatteryInfo.batteryCapacityPercent,
singleBatteryInfo.currentVoltage / 1000,
(dji_f32_t) singleBatteryInfo.batteryTemperature / 10);
}
}
USER_LOG_INFO("--> Step 4: Unsubscribe the topics of quaternion, velocity and gps position");
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("UnSubscribe topic quaternion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("UnSubscribe topic quaternion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("UnSubscribe topic quaternion error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
USER_LOG_INFO("--> Step 5: Deinit fc subscription module");
djiStat = DjiFcSubscription_DeInit();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit fc subscription error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
s_userFcSubscriptionDataShow = false;
USER_LOG_INFO("Fc subscription sample end");
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_FcSubscriptionDataShowTrigger(void)
{
s_userFcSubscriptionDataShow = !s_userFcSubscriptionDataShow;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_FcSubscriptionGetTotalSatelliteNumber(uint8_t *number)
{
*number = s_totalSatelliteNumberUsed;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *UserFcSubscription_Task(void *arg)
{
T_DjiReturnCode djiStat;
T_DjiFcSubscriptionVelocity velocity = {0};
T_DjiDataTimestamp timestamp = {0};
T_DjiFcSubscriptionGpsPosition gpsPosition = {0};
T_DjiFcSubscriptionGpsDetails gpsDetails = {0};
T_DjiOsalHandler *osalHandler = NULL;
USER_UTIL_UNUSED(arg);
osalHandler = DjiPlatform_GetOsalHandler();
while (1) {
osalHandler->TaskSleepMs(1000 / FC_SUBSCRIPTION_TASK_FREQ);
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,
(uint8_t *) &velocity,
sizeof(T_DjiFcSubscriptionVelocity),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic velocity error.");
}
if (s_userFcSubscriptionDataShow == true) {
USER_LOG_INFO("velocity: x %f y %f z %f, healthFlag %d.", velocity.data.x, velocity.data.y,
velocity.data.z, velocity.health);
}
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION,
(uint8_t *) &gpsPosition,
sizeof(T_DjiFcSubscriptionGpsPosition),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic gps position error.");
}
if (s_userFcSubscriptionDataShow == true) {
USER_LOG_INFO("gps position: x %d y %d z %d.", gpsPosition.x, gpsPosition.y, gpsPosition.z);
}
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_DETAILS,
(uint8_t *) &gpsDetails,
sizeof(T_DjiFcSubscriptionGpsDetails),
&timestamp);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get value of topic gps details error.");
}
if (s_userFcSubscriptionDataShow == true) {
USER_LOG_INFO("gps total satellite number used: %d %d %d.",
gpsDetails.gpsSatelliteNumberUsed,
gpsDetails.glonassSatelliteNumberUsed,
gpsDetails.totalSatelliteNumberUsed);
s_totalSatelliteNumberUsed = gpsDetails.totalSatelliteNumberUsed;
}
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
static T_DjiReturnCode DjiTest_FcSubscriptionReceiveQuaternionCallback(const uint8_t *data, uint16_t dataSize,
const T_DjiDataTimestamp *timestamp)
{
T_DjiFcSubscriptionQuaternion *quaternion = (T_DjiFcSubscriptionQuaternion *) data;
dji_f64_t pitch, yaw, roll;
USER_UTIL_UNUSED(dataSize);
pitch = (dji_f64_t) asinf(-2 * quaternion->q1 * quaternion->q3 + 2 * quaternion->q0 * quaternion->q2) * 57.3;
roll = (dji_f64_t) atan2f(2 * quaternion->q2 * quaternion->q3 + 2 * quaternion->q0 * quaternion->q1,
-2 * quaternion->q1 * quaternion->q1 - 2 * quaternion->q2 * quaternion->q2 + 1) * 57.3;
yaw = (dji_f64_t) atan2f(2 * quaternion->q1 * quaternion->q2 + 2 * quaternion->q0 * quaternion->q3,
-2 * quaternion->q2 * quaternion->q2 - 2 * quaternion->q3 * quaternion->q3 + 1) *
57.3;
if (s_userFcSubscriptionDataShow == true) {
if (s_userFcSubscriptionDataCnt++ % DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ == 0) {
USER_LOG_INFO("receive quaternion data.");
USER_LOG_INFO("timestamp: millisecond %u microsecond %u.", timestamp->millisecond,
timestamp->microsecond);
USER_LOG_INFO("quaternion: %f %f %f %f.", quaternion->q0, quaternion->q1, quaternion->q2,
quaternion->q3);
USER_LOG_INFO("euler angles: pitch = %.2f roll = %.2f yaw = %.2f.\r\n", pitch, roll, yaw);
DjiTest_WidgetLogAppend("pitch = %.2f roll = %.2f yaw = %.2f.", pitch, roll, yaw);
}
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,55 @@
/**
********************************************************************
* @file test_fc_subscription.h
* @brief This is the header file for "test_fc_subscription.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 TEST_FC_SUBSCRIPTION_H
#define TEST_FC_SUBSCRIPTION_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_fc_subscription.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_FcSubscriptionStartService(void);
T_DjiReturnCode DjiTest_FcSubscriptionRunSample(void);
T_DjiReturnCode DjiTest_FcSubscriptionDataShowTrigger(void);
T_DjiReturnCode DjiTest_FcSubscriptionGetTotalSatelliteNumber(uint8_t *number);
#ifdef __cplusplus
}
#endif
#endif // TEST_FC_SUBSCRIPTION_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
/**
********************************************************************
* @file test_flight_control.h
* @brief This is the header file for "test_flight_control.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 TEST_FLIGHT_CONTROL_H
#define TEST_FLIGHT_CONTROL_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
typedef enum {
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_TAKE_OFF_LANDING,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_TAKE_OFF_POSITION_CTRL_LANDING,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_TAKE_OFF_GO_HOME_FORCE_LANDING,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_TAKE_OFF_VELOCITY_CTRL_LANDING,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_ARREST_FLYING,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_SET_GET_PARAM,
E_DJI_TEST_FLIGHT_CTRL_SAMPLE_SELECT_FTS_TRIGGER,
} E_DjiTestFlightCtrlSampleSelect;
#pragma pack(1)
typedef struct {
dji_f32_t x;
dji_f32_t y;
dji_f32_t z;
} T_DjiTestFlightControlVector3f; // pack(1)
#pragma pack()
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_FlightControlRunSample(E_DjiTestFlightCtrlSampleSelect flightCtrlSampleSelect);
void DjiTest_FlightControlVelocityAndYawRateCtrl(const T_DjiTestFlightControlVector3f offsetDesired, float yawRate,
uint32_t timeMs);
#ifdef __cplusplus
}
#endif
#endif // TEST_FLIGHT_CONTROL_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/**
********************************************************************
* @file test_payload_gimbal_emu.h
* @brief This is the header file for "test_payload_gimbal_emu.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 TEST_PAYLOAD_GIMBAL_EMU_H
#define TEST_PAYLOAD_GIMBAL_EMU_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_gimbal.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_GimbalStartService(void);
T_DjiReturnCode DjiTest_GimbalDeInit(void);
T_DjiReturnCode DjiTest_GimbalRotate(E_DjiGimbalRotationMode rotationMode,
T_DjiGimbalRotationProperty rotationProperty,
T_DjiAttitude3d rotationValue); // unit if angle control: 0.1 degree, unit if speed control: 0.1 degree/s
#ifdef __cplusplus
}
#endif
#endif // TEST_PAYLOAD_GIMBAL_EMU_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,189 @@
/**
********************************************************************
* @file test_gimbal_manager.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 <utils/util_misc.h>
#include <widget_interaction_test/test_widget_interaction.h>
#include "test_gimbal_manager.h"
#include "dji_platform.h"
#include "dji_logger.h"
#include "dji_gimbal_manager.h"
#include "dji_fc_subscription.h"
#include "dji_aircraft_info.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
typedef enum {
DJI_TEST_GIMBAL_ROTATION,
DJI_TEST_GIMBAL_RESET,
} E_DjiTestGimbalAction;
typedef struct {
E_DjiTestGimbalAction action;
T_DjiGimbalManagerRotation rotation;
} T_DjiTestGimbalActionList;
/* Private values -------------------------------------------------------------*/
static const T_DjiTestGimbalActionList s_rotationActionList[] =
{
{.action = DJI_TEST_GIMBAL_RESET},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 30, 0, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, -30, 0, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, -30, 0, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 30, 0, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 30, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, -30, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, -30, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 30, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 0, 4, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 0, -4, 0.2},
{.action = DJI_TEST_GIMBAL_RESET},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, 30, 0, 0, 0.2},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, -90, 0, 0, 0.5},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, -60, 0, 0, 0.5},
{.action = DJI_TEST_GIMBAL_ROTATION, .rotation.rotationMode = DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, -30, 0, 0, 0.5},
{.action = DJI_TEST_GIMBAL_RESET},
};
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_GimbalManagerRunSample(E_DjiMountPosition mountPosition, E_DjiGimbalMode gimbalMode)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiReturnCode returnCode;
T_DjiGimbalManagerRotation rotation;
T_DjiAircraftInfoBaseInfo baseInfo;
E_DjiAircraftSeries aircraftSeries;
returnCode = DjiAircraftInfo_GetBaseInfo(&baseInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Failed to get aircraft base info, return code 0x%08X", returnCode);
goto out;
}
aircraftSeries = baseInfo.aircraftSeries;
USER_LOG_INFO("Gimbal manager sample start");
DjiTest_WidgetLogAppend("Gimbal manager sample start");
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ, NULL);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Failed to subscribe topic %d, 0x%08X", DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES, returnCode);
goto out;
}
USER_LOG_INFO("--> Step 1: Init gimbal manager module");
DjiTest_WidgetLogAppend("--> Step 1: Init gimbal manager module");
returnCode = DjiGimbalManager_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init gimbal manager failed, error code: 0x%08X", returnCode);
goto out;
}
if (gimbalMode == DJI_GIMBAL_MODE_FREE) {
USER_LOG_INFO("--> Step 2: Set gimbal to free mode");
DjiTest_WidgetLogAppend("--> Step 2: Set gimbal to free mode");
} else if (gimbalMode == DJI_GIMBAL_MODE_YAW_FOLLOW) {
USER_LOG_INFO("--> Step 2: Set gimbal to yaw follow mode");
DjiTest_WidgetLogAppend("--> Step 2: Set gimbal to yaw follow mode");
}
returnCode = DjiGimbalManager_SetMode(mountPosition, gimbalMode);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set gimbal mode failed, error code: 0x%08X", returnCode);
goto out;
}
USER_LOG_INFO("--> Step 3: Reset gimbal angles.\r\n");
returnCode = DjiGimbalManager_Reset(mountPosition, DJI_GIMBAL_RESET_MODE_PITCH_AND_YAW);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Reset gimbal failed, error code: 0x%08X", returnCode);
}
USER_LOG_INFO("--> Step 4: Rotate gimbal to target angle by action list\r\n");
for (int i = 0; i < sizeof(s_rotationActionList) / sizeof(T_DjiTestGimbalActionList); ++i) {
if (s_rotationActionList[i].action == DJI_TEST_GIMBAL_RESET) {
USER_LOG_INFO("Target gimbal reset.\r\n");
returnCode = DjiGimbalManager_Reset(mountPosition, DJI_GIMBAL_RESET_MODE_PITCH_AND_YAW);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Reset gimbal failed, error code: 0x%08X", returnCode);
}
osalHandler->TaskSleepMs(2000);
} else if (s_rotationActionList[i].action == DJI_TEST_GIMBAL_ROTATION) {
if (gimbalMode == DJI_GIMBAL_MODE_FREE &&
s_rotationActionList[i].rotation.rotationMode == DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE) {
continue;
}
rotation = s_rotationActionList[i].rotation;
if (aircraftSeries == DJI_AIRCRAFT_SERIES_M3 || aircraftSeries == DJI_AIRCRAFT_SERIES_M30
|| aircraftSeries == DJI_AIRCRAFT_SERIES_M3D) {
if (s_rotationActionList[i].rotation.rotationMode == DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE) {
T_DjiFcSubscriptionGimbalAngles gimbalAngles = {0};
T_DjiDataTimestamp timestamp = {0};
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES,
(uint8_t *) &gimbalAngles,
sizeof(T_DjiFcSubscriptionGimbalAngles),
&timestamp);
rotation.yaw = gimbalAngles.z;
}
}
USER_LOG_INFO("Target gimbal pry = (%.1f, %.1f, %.1f)", rotation.pitch, rotation.roll, rotation.yaw);
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Target gimbal pry = (%.1f, %.1f, %.1f) failed, error code: 0x%08X",
s_rotationActionList[i].rotation.pitch, s_rotationActionList[i].rotation.roll,
s_rotationActionList[i].rotation.yaw,
returnCode);
}
osalHandler->TaskSleepMs(1000);
}
}
returnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Failed to unsubscribe topic %d, 0x%08X", DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES, returnCode);
}
USER_LOG_INFO("--> Step 5: Deinit gimbal manager module");
DjiTest_WidgetLogAppend("--> Step 5: Deinit gimbal manager module");
returnCode = DjiGimbalManager_Deinit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit gimbal manager failed, error code: 0x%08X", returnCode);
goto out;
}
out:
USER_LOG_INFO("Gimbal manager sample end");
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,49 @@
/**
********************************************************************
* @file test_gimbal_manager.h
* @brief This is the header file for "test_gimbal_manager.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 TEST_GIMBAL_MANAGER_H
#define TEST_GIMBAL_MANAGER_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_GimbalManagerRunSample(E_DjiMountPosition mountPosition, E_DjiGimbalMode gimbalMode);
#ifdef __cplusplus
}
#endif
#endif // TEST_GIMBAL_MANAGER_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,76 @@
{
"version": {
"major": 1,
"minor": 0
},
"hms_database": {
"hms_position_desc": "负载%position_index",
"hms_error_code_list": [
{
"hms_error_code": "0x1E020000",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题0",
"message_content": "HMS测试文案: 我是错误码内容0"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误0",
"is_keep_history_on_the_ground": false,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误0",
"is_keep_history_in_the_sky": false
}
},
{
"hms_error_code": "0x1E020001",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题1",
"message_content": "HMS测试文案: 我是错误码内容1"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误1",
"is_keep_history_on_the_ground": false,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误1",
"is_keep_history_in_the_sky": false
}
},
{
"hms_error_code": "0x1E020002",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题2",
"message_content": "HMS测试文案: 我是错误码内容2"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误2",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误2",
"is_keep_history_in_the_sky": true
}
},
{
"hms_error_code": "0x1E020003",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题3",
"message_content": "HMS测试文案: 我是错误码内容3"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误3",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误3",
"is_keep_history_in_the_sky": true
}
},
{
"hms_error_code": "0x1E020004",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题4",
"message_content": "HMS测试文案: 我是错误码内容4"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误4",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误4",
"is_keep_history_in_the_sky": true
}
}
]
}
}

View File

@ -0,0 +1,76 @@
{
"version": {
"major": 1,
"minor": 0
},
"hms_database": {
"hms_position_desc": "Payload %position_index",
"hms_error_code_list": [
{
"hms_error_code": "0x1E020000",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 0",
"message_content": "HMS test text: I am error code Content 0"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 0",
"is_keep_history_on_the_ground": false,
"message_in_the_sky": "HMS test text: I got error in the sky 0",
"is_keep_history_in_the_sky": false
}
},
{
"hms_error_code": "0x1E020001",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 1",
"message_content": "HMS test text: I am error code Content 1"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 1",
"is_keep_history_on_the_ground": false,
"message_in_the_sky": "HMS test text: I got error in the sky 1",
"is_keep_history_in_the_sky": false
}
},
{
"hms_error_code": "0x1E020002",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 2",
"message_content": "HMS test text: I am error code Content 2"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 2",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS test text: I got error in the sky 2",
"is_keep_history_in_the_sky": true
}
},
{
"hms_error_code": "0x1E020003",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 3",
"message_content": "HMS test text: I am error code Content 3"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 3",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS test text: I got error in the sky 3",
"is_keep_history_in_the_sky": true
}
},
{
"hms_error_code": "0x1E020004",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 4",
"message_content": "HMS test text: I am error code Content 4"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 4",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS test text: I got error in the sky 4",
"is_keep_history_in_the_sky": true
}
}
]
}
}

View File

@ -0,0 +1,188 @@
/* Generated by file2c, do not edit manually */
#ifndef __hms_text_config_json_h_included
#define __hms_text_config_json_h_included
#include <stdint.h>
/* Contents of file hms_text_config.json */
#define hms_text_config_json_fileName "hms_text_config.json"
#define hms_text_config_json_fileSize 2783
static const uint8_t hms_text_config_json_fileBinaryArray[2783] = {
0x7B, 0x0A, 0x20, 0x20, 0x22, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x22, 0x3A, 0x20, 0x7B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x61, 0x6A, 0x6F, 0x72, 0x22, 0x3A, 0x20, 0x31, 0x2C,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x69, 0x6E, 0x6F, 0x72, 0x22, 0x3A, 0x20, 0x30, 0x0A,
0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x64, 0x61, 0x74, 0x61,
0x62, 0x61, 0x73, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D,
0x73, 0x5F, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x5F, 0x64, 0x65, 0x73, 0x63, 0x22,
0x3A, 0x20, 0x22, 0x50, 0x61, 0x79, 0x6C, 0x6F, 0x61, 0x64, 0x20, 0x25, 0x70, 0x6F, 0x73, 0x69,
0x74, 0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x5F, 0x63, 0x6F, 0x64, 0x65,
0x5F, 0x6C, 0x69, 0x73, 0x74, 0x22, 0x3A, 0x20, 0x5B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x65,
0x72, 0x72, 0x6F, 0x72, 0x5F, 0x63, 0x6F, 0x64, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x30, 0x78, 0x31,
0x45, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65,
0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x22, 0x3A, 0x20,
0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20,
0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20,
0x54, 0x69, 0x74, 0x6C, 0x65, 0x20, 0x30, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x63, 0x6F, 0x6E,
0x74, 0x65, 0x6E, 0x74, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74,
0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F,
0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x20, 0x30,
0x22, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x66, 0x70, 0x76, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66,
0x61, 0x63, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68,
0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20,
0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74,
0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x6F, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x67, 0x72,
0x6F, 0x75, 0x6E, 0x64, 0x20, 0x30, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74,
0x6F, 0x72, 0x79, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E,
0x64, 0x22, 0x3A, 0x20, 0x66, 0x61, 0x6C, 0x73, 0x65, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x69, 0x6E,
0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20,
0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74,
0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x69, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x6B,
0x79, 0x20, 0x30, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79,
0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x66, 0x61,
0x6C, 0x73, 0x65, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x65, 0x72, 0x72, 0x6F,
0x72, 0x5F, 0x63, 0x6F, 0x64, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x30, 0x78, 0x31, 0x45, 0x30, 0x32,
0x30, 0x30, 0x30, 0x31, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x68, 0x6D, 0x73, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x3A, 0x20,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x5F, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D,
0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61,
0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20, 0x54, 0x69, 0x74,
0x6C, 0x65, 0x20, 0x31, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x63, 0x6F, 0x6E, 0x74, 0x65, 0x6E,
0x74, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65,
0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63,
0x6F, 0x64, 0x65, 0x20, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x20, 0x31, 0x22, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x66, 0x70, 0x76, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65,
0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67,
0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73,
0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72,
0x72, 0x6F, 0x72, 0x20, 0x6F, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x67, 0x72, 0x6F, 0x75, 0x6E,
0x64, 0x20, 0x31, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79,
0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A,
0x20, 0x66, 0x61, 0x6C, 0x73, 0x65, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68,
0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73,
0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72,
0x72, 0x6F, 0x72, 0x20, 0x69, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x6B, 0x79, 0x20, 0x31,
0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x73,
0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79, 0x5F, 0x69, 0x6E,
0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x66, 0x61, 0x6C, 0x73, 0x65,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x5F, 0x63,
0x6F, 0x64, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x30, 0x78, 0x31, 0x45, 0x30, 0x32, 0x30, 0x30, 0x30,
0x32, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73,
0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x5F, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74,
0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65,
0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20, 0x54, 0x69, 0x74, 0x6C, 0x65, 0x20,
0x32, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x63, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x22, 0x3A,
0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A,
0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65,
0x20, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x20, 0x32, 0x22, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x66, 0x70, 0x76, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x3A, 0x20,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75,
0x6E, 0x64, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74,
0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72,
0x20, 0x6F, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x20, 0x32,
0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x73,
0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79, 0x5F, 0x6F, 0x6E,
0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20, 0x74, 0x72,
0x75, 0x65, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B,
0x79, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65,
0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20,
0x69, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x6B, 0x79, 0x20, 0x32, 0x22, 0x2C, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65,
0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79, 0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65,
0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x68, 0x6D, 0x73, 0x5F, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x5F, 0x63, 0x6F, 0x64, 0x65, 0x22, 0x3A,
0x20, 0x22, 0x30, 0x78, 0x31, 0x45, 0x30, 0x32, 0x30, 0x30, 0x30, 0x33, 0x22, 0x2C, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x74, 0x69, 0x74,
0x6C, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74,
0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20,
0x63, 0x6F, 0x64, 0x65, 0x20, 0x54, 0x69, 0x74, 0x6C, 0x65, 0x20, 0x33, 0x22, 0x2C, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x5F, 0x63, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53,
0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D,
0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20, 0x43, 0x6F, 0x6E, 0x74,
0x65, 0x6E, 0x74, 0x20, 0x33, 0x22, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D,
0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x66, 0x70, 0x76, 0x5F, 0x69,
0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F,
0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20,
0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20,
0x49, 0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x6F, 0x6E, 0x20, 0x74,
0x68, 0x65, 0x20, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x20, 0x33, 0x22, 0x2C, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70,
0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F,
0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2C, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x22,
0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49,
0x20, 0x67, 0x6F, 0x74, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x69, 0x6E, 0x20, 0x74, 0x68,
0x65, 0x20, 0x73, 0x6B, 0x79, 0x20, 0x33, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73,
0x74, 0x6F, 0x72, 0x79, 0x5F, 0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22,
0x3A, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x65,
0x72, 0x72, 0x6F, 0x72, 0x5F, 0x63, 0x6F, 0x64, 0x65, 0x22, 0x3A, 0x20, 0x22, 0x30, 0x78, 0x31,
0x45, 0x30, 0x32, 0x30, 0x30, 0x30, 0x34, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x68, 0x6D, 0x73, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65,
0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x22, 0x3A, 0x20,
0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20,
0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20,
0x54, 0x69, 0x74, 0x6C, 0x65, 0x20, 0x34, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x63, 0x6F, 0x6E,
0x74, 0x65, 0x6E, 0x74, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74, 0x65, 0x73, 0x74,
0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x61, 0x6D, 0x20, 0x65, 0x72, 0x72, 0x6F,
0x72, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x20, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x20, 0x34,
0x22, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x2C, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x66, 0x70, 0x76, 0x5F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66,
0x61, 0x63, 0x65, 0x22, 0x3A, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68,
0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20,
0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74,
0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x6F, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x67, 0x72,
0x6F, 0x75, 0x6E, 0x64, 0x20, 0x34, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x22, 0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74,
0x6F, 0x72, 0x79, 0x5F, 0x6F, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x67, 0x72, 0x6F, 0x75, 0x6E,
0x64, 0x22, 0x3A, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x22, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5F, 0x69, 0x6E, 0x5F,
0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x22, 0x48, 0x4D, 0x53, 0x20, 0x74,
0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3A, 0x20, 0x49, 0x20, 0x67, 0x6F, 0x74, 0x20,
0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x69, 0x6E, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x6B, 0x79,
0x20, 0x34, 0x22, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x69, 0x73, 0x5F, 0x6B, 0x65, 0x65, 0x70, 0x5F, 0x68, 0x69, 0x73, 0x74, 0x6F, 0x72, 0x79, 0x5F,
0x69, 0x6E, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x73, 0x6B, 0x79, 0x22, 0x3A, 0x20, 0x74, 0x72, 0x75,
0x65, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x5D, 0x0A, 0x20, 0x20, 0x7D, 0x0A, 0x7D
};
#endif /* __hms_text_config_json_h_included */

View File

@ -0,0 +1,431 @@
/**
********************************************************************
* @file test_hms.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 <widget_interaction_test/test_widget_interaction.h>
#include <utils/util_misc.h>
#include <utils/cJSON.h>
#include <utils/util_file.h>
#include "test_hms.h"
#include "dji_hms.h"
#include "dji_hms_info_table.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "dji_fc_subscription.h"
#include "hms_text_c/en/hms_text_config_json.h"
/* Private constants ---------------------------------------------------------*/
#define MAX_HMS_PRINT_COUNT (150)
#define MAX_BUFFER_LEN (256)
#define MIN_HMS_ERROR_LEVEL (0)
#define MID_HMS_ERROR_LEVEL (3)
#define MAX_HMS_ERROR_LEVEL (6)
#define HMS_DIR_PATH_LEN_MAX (256)
#define DJI_CUSTOM_HMS_CODE_INJECT_ON (0)
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static const char *oldReplaceAlarmIdStr = "%alarmid";
static const char *oldReplaceIndexStr = "%index";
static const char *oldReplaceComponentIndexStr = "%component_index";
static T_DjiHmsFileBinaryArray s_EnHmsTextConfigFileBinaryArrayList[] = {
{hms_text_config_json_fileName, hms_text_config_json_fileSize, hms_text_config_json_fileBinaryArray},
};
static uint8_t *s_hmsJsonData = NULL;
static E_DjiMobileAppLanguage s_hmsLanguage = DJI_MOBILE_APP_LANGUAGE_ENGLISH;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTest_HmsManagerInit(void);
static T_DjiReturnCode DjiTest_HmsManagerDeInit(void);
static T_DjiFcSubscriptionFlightStatus DjiTest_GetValueOfFlightStatus(void);
static bool DjiTest_ReplaceStr(char *buffer, uint32_t bufferMaxLen, const char *target, const char *dest);
static bool DjiTest_MarchErrCodeInfoTable(T_DjiHmsInfoTable hmsInfoTable);
static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable);
static T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_HmsManagerRunSample(E_DjiMobileAppLanguage language)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler;
s_hmsLanguage = language;
USER_LOG_INFO("Hms Sample Start");
DjiTest_WidgetLogAppend("Hms Sample Start");
USER_LOG_INFO("--> Step 1: Init hms sample");
DjiTest_WidgetLogAppend("--> Step 1: Init hms sample");
returnCode = DjiTest_HmsManagerInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Hms sample init error, error code:0x%08llX", returnCode);
goto out;
}
osalHandler = DjiPlatform_GetOsalHandler();
USER_LOG_INFO("--> Step 2: Register callback function of push HMS information");
DjiTest_WidgetLogAppend("--> Step 2: Register callback function of push HMS information");
returnCode = DjiHmsManager_RegHmsInfoCallback(DjiTest_HmsInfoCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register callback function of push HMS information failed, error code:0x%08llX", returnCode);
goto out;
}
osalHandler->TaskSleepMs(10000);
out:
USER_LOG_INFO("--> Step 3: Deinit hms sample");
DjiTest_WidgetLogAppend("--> Step 3: Deinit hms sample");
returnCode = DjiTest_HmsManagerDeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Hms sample deinit error, error code:0x%08llX", returnCode);
}
USER_LOG_INFO("Hms Sample End");
DjiTest_WidgetLogAppend("Hms Sample End");
return returnCode;
}
T_DjiReturnCode DjiTest_HmsCustomizationStartService(void)
{
T_DjiReturnCode returnCode;
#ifdef SYSTEM_ARCH_LINUX
char curFileDirPath[HMS_DIR_PATH_LEN_MAX];
char tempPath[HMS_DIR_PATH_LEN_MAX];
#endif
returnCode = DjiHmsCustomization_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Hms init error, error code:0x%08llX", returnCode);
return returnCode;
}
#ifdef SYSTEM_ARCH_LINUX
//Step 2 : Set hms text Config (Linux environment)
returnCode = DjiUserUtil_GetCurrentFileDirPath(__FILE__, HMS_DIR_PATH_LEN_MAX, curFileDirPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", returnCode);
return returnCode;
}
snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/en", curFileDirPath);
//set default hms text config path
returnCode = DjiHmsCustomization_RegDefaultHmsTextConfigByDirPath(tempPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add default hms text config error, stat = 0x%08llX", returnCode);
return returnCode;
}
//set hms text config for English language
returnCode = DjiHmsCustomization_RegHmsTextConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_ENGLISH,
tempPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add hms text config error, stat = 0x%08llX", returnCode);
return returnCode;
}
//set hms text config for Chinese language
snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/cn", curFileDirPath);
returnCode = DjiHmsCustomization_RegHmsTextConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_CHINESE,
tempPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add hms text config error, stat = 0x%08llX", returnCode);
return returnCode;
}
#else
//Step 2 : Set hms text Config (RTOS environment)
T_DjiHmsBinaryArrayConfig enHmsTextBinaryArrayConfig = {
.binaryArrayCount = sizeof(s_EnHmsTextConfigFileBinaryArrayList) / sizeof(T_DjiHmsFileBinaryArray),
.fileBinaryArrayList = s_EnHmsTextConfigFileBinaryArrayList
};
//set default hms text config
returnCode = DjiHmsCustomization_RegDefaultHmsTextConfigByBinaryArray(&enHmsTextBinaryArrayConfig);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add default hms text config error, stat = 0x%08llX", returnCode);
return returnCode;
}
#endif
#if DJI_CUSTOM_HMS_CODE_INJECT_ON
DjiHmsCustomization_InjectHmsErrorCode(0x1E020000, DJI_HMS_ERROR_LEVEL_FATAL);
#endif
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTest_HmsManagerInit(void)
{
T_DjiReturnCode returnCode;
char curFileDirPath[HMS_DIR_PATH_LEN_MAX];
char tempFileDirPath[HMS_DIR_PATH_LEN_MAX];
uint32_t fileSize = 0;
uint32_t readRealSize = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = DjiFcSubscription_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Hms sample init data subscription module failed, error code:0x%08llX", returnCode);
return returnCode;
}
/*! subscribe fc data */
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
DJI_DATA_SUBSCRIPTION_TOPIC_10_HZ,
NULL);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("HMS sample subscribe topic flight status error, error code:0x%08llX", returnCode);
return returnCode;
}
#ifdef SYSTEM_ARCH_LINUX
returnCode = DjiUserUtil_GetCurrentFileDirPath(__FILE__, HMS_DIR_PATH_LEN_MAX, curFileDirPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", returnCode);
return returnCode;
}
snprintf(tempFileDirPath, HMS_DIR_PATH_LEN_MAX, "%s/data/hms.json", curFileDirPath);
returnCode = UtilFile_GetFileSizeByPath(tempFileDirPath, &fileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file size by path failed, stat = 0x%08llX", returnCode);
return returnCode;
}
USER_LOG_DEBUG("Hms json file size is %d", fileSize);
s_hmsJsonData = osalHandler->Malloc(fileSize);
if (s_hmsJsonData == NULL) {
USER_LOG_ERROR("Malloc failed.");
}
UtilFile_GetFileDataByPath(tempFileDirPath, 0, fileSize, s_hmsJsonData, &readRealSize);
#endif
return DjiHmsManager_Init();
}
static T_DjiReturnCode DjiTest_HmsManagerDeInit(void)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = DjiFcSubscription_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit data subscription module failed, error code:0x%08llX",
returnCode);
return returnCode;
}
#ifdef SYSTEM_ARCH_LINUX
osalHandler->Free(s_hmsJsonData);
#endif
return DjiHmsManager_DeInit();
}
static T_DjiFcSubscriptionFlightStatus DjiTest_GetValueOfFlightStatus(void)
{
T_DjiReturnCode returnCode;
T_DjiFcSubscriptionFlightStatus flightStatus;
T_DjiDataTimestamp flightStatusTimestamp = {0};
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
(uint8_t *) &flightStatus,
sizeof(T_DjiFcSubscriptionFlightStatus),
&flightStatusTimestamp);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get value of topic flight status failed, error code:0x%08llX", returnCode);
flightStatus = 0;
} else {
USER_LOG_DEBUG("Timestamp: millisecond %u microsecond %u.", flightStatusTimestamp.millisecond,
flightStatusTimestamp.microsecond);
USER_LOG_DEBUG("Flight status: %d.", flightStatus);
}
return flightStatus;
}
static bool DjiTest_ReplaceStr(char *buffer, uint32_t bufferMaxLen, const char *target, const char *dest)
{
char printBuffHeader[MAX_BUFFER_LEN] = {0};
uint32_t printBuffHeaderCpyCnt = 0;
char printBuffTail[MAX_BUFFER_LEN] = {0};
uint32_t printBuffTailCpyCnt = 0;
char *targetOffset = NULL;
targetOffset = strstr(buffer, target);
if (!targetOffset) {
return false;
}
printBuffHeaderCpyCnt = targetOffset - buffer;
if (printBuffHeaderCpyCnt > sizeof(printBuffHeader)) {
printBuffHeaderCpyCnt = sizeof(printBuffHeader);
}
memcpy(printBuffHeader, buffer, printBuffHeaderCpyCnt);
printBuffTailCpyCnt = strlen(targetOffset + strlen(target));
if (printBuffTailCpyCnt > sizeof(printBuffTail)) {
printBuffTailCpyCnt = sizeof(printBuffTail);
}
memcpy(printBuffTail, targetOffset + strlen(target), printBuffTailCpyCnt);
snprintf(buffer, bufferMaxLen, "%s%s%s", printBuffHeader, dest, printBuffTail);
return true;
}
static bool DjiTest_MarchErrCodeInfoTable(T_DjiHmsInfoTable hmsInfoTable)
{
char alarmIdStr[20] = {0};
char sensorIdStr[20] = {0};
char componentIdStr[20] = {0};
char printBuff[256] = {0};
const char *originalAlarmInfo = NULL;
uint8_t hmsCodeMatchFlag = 0;
if (!hmsInfoTable.hmsInfo) {
USER_LOG_ERROR("Hms info table is null");
return false;
}
for (int i = 0; i < hmsInfoTable.hmsInfoNum; i++) {
hmsCodeMatchFlag = 0;
for (int j = 0; j < sizeof(hmsErrCodeInfoTbl) / sizeof(T_DjiHmsErrCodeInfo); j++) {
if (hmsInfoTable.hmsInfo[i].errorCode == hmsErrCodeInfoTbl[j].alarmId) {
hmsCodeMatchFlag = 1;
snprintf(alarmIdStr, sizeof(alarmIdStr), "%u", hmsInfoTable.hmsInfo[i].errorCode);
//note:sensor_idx:[0,5].In order to be consistent with the display of pilot, add one.
snprintf(sensorIdStr, sizeof(sensorIdStr), "%d", hmsInfoTable.hmsInfo[i].componentIndex + 1);
snprintf(componentIdStr, sizeof(componentIdStr), "0x%02X", hmsInfoTable.hmsInfo[i].componentIndex + 1);
if (DjiTest_GetValueOfFlightStatus() == DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_IN_AIR) {
originalAlarmInfo = hmsErrCodeInfoTbl[j].flyAlarmInfo;
} else {
originalAlarmInfo = hmsErrCodeInfoTbl[j].groundAlarmInfo;
}
originalAlarmInfo = hmsErrCodeInfoTbl[j].groundAlarmInfo;
if (strlen(originalAlarmInfo)) {
snprintf(printBuff, sizeof(printBuff), "%s", originalAlarmInfo);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceAlarmIdStr, alarmIdStr);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceIndexStr, sensorIdStr);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceComponentIndexStr, componentIdStr);
if (hmsInfoTable.hmsInfo[i].errorLevel > MIN_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MID_HMS_ERROR_LEVEL) {
USER_LOG_WARN("[ErrorCode:0x%2x] %s", hmsInfoTable.hmsInfo[i].errorCode, printBuff);
} else if (hmsInfoTable.hmsInfo[i].errorLevel >= MID_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MAX_HMS_ERROR_LEVEL) {
USER_LOG_ERROR("[ErrorCode:0x%2x] %s", hmsInfoTable.hmsInfo[i].errorCode, printBuff);
}
}
}
}
if (!hmsCodeMatchFlag) {
USER_LOG_WARN("[ErrorCode:0x%2x] There are no matching documents in the current hmsErrCodeInfoTbl for now.",
hmsInfoTable.hmsInfo[i].errorCode);
}
}
return true;
}
static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable)
{
cJSON *hmsJsonRoot = NULL;
cJSON *hmsErrorCode = NULL;
cJSON *hmsLanguage = NULL;
char hmsErrorCodeString[HMS_DIR_PATH_LEN_MAX] = {0};
hmsJsonRoot = cJSON_Parse((char *) s_hmsJsonData);
if (hmsJsonRoot == NULL) {
return 0;
}
for (int i = 0; i < hmsInfoTable.hmsInfoNum; i++) {
if (DjiTest_GetValueOfFlightStatus() == DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_IN_AIR) {
sprintf(hmsErrorCodeString, "fpv_tip_0x%08X_in_the_sky", hmsInfoTable.hmsInfo[i].errorCode);
} else {
sprintf(hmsErrorCodeString, "fpv_tip_0x%08X", hmsInfoTable.hmsInfo[i].errorCode);
}
hmsErrorCode = cJSON_GetObjectItem(hmsJsonRoot, hmsErrorCodeString);
if (hmsErrorCode != NULL) {
if (s_hmsLanguage == DJI_MOBILE_APP_LANGUAGE_CHINESE) {
hmsLanguage = cJSON_GetObjectItem(hmsErrorCode, "zh");
} else if (s_hmsLanguage == DJI_MOBILE_APP_LANGUAGE_ENGLISH) {
hmsLanguage = cJSON_GetObjectItem(hmsErrorCode, "en");
} else if (s_hmsLanguage == DJI_MOBILE_APP_LANGUAGE_JAPANESE) {
hmsLanguage = cJSON_GetObjectItem(hmsErrorCode, "ja");
} else if (s_hmsLanguage == DJI_MOBILE_APP_LANGUAGE_FRENCH) {
hmsLanguage = cJSON_GetObjectItem(hmsErrorCode, "fr");
}
if (hmsLanguage != NULL) {
if (hmsInfoTable.hmsInfo[i].errorLevel > MIN_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MID_HMS_ERROR_LEVEL) {
USER_LOG_WARN("[ErrorCode: 0x%2x]: %s", hmsInfoTable.hmsInfo[i].errorCode,
hmsLanguage->valuestring);
} else if (hmsInfoTable.hmsInfo[i].errorLevel >= MID_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MAX_HMS_ERROR_LEVEL) {
USER_LOG_ERROR("[ErrorCode: 0x%2x]: %s", hmsInfoTable.hmsInfo[i].errorCode,
hmsLanguage->valuestring);
}
} else {
USER_LOG_WARN("[ErrorCode: 0x%2x] There are no matching documents for this language for now.",
hmsInfoTable.hmsInfo[i].errorCode);
}
} else {
USER_LOG_WARN("[ErrorCode: 0x%2x] There are no matching documents in the current json for now.",
hmsInfoTable.hmsInfo[i].errorCode);
}
}
cJSON_Delete(hmsJsonRoot);
}
static T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable)
{
#ifdef SYSTEM_ARCH_LINUX
DjiTest_MarchErrCodeInfoTableByJson(hmsInfoTable);
#else
if (!DjiTest_MarchErrCodeInfoTable(hmsInfoTable)) {
USER_LOG_ERROR("March HMS Information failed.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
#endif
if (hmsInfoTable.hmsInfoNum == 0) {
USER_LOG_INFO("All systems of drone are running well now.");
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,50 @@
/**
********************************************************************
* @file test_hms.h
* @brief This is the header file for "test_hms.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 TEST_HMS_H
#define TEST_HMS_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_HmsManagerRunSample(E_DjiMobileAppLanguage language);
T_DjiReturnCode DjiTest_HmsCustomizationStartService(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_HMS_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,131 @@
/**
********************************************************************
* @file test_interest_point.c
* @brief
*
* @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.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "test_interest_point.h"
#include "dji_interest_point.h"
#include "dji_logger.h"
#include "dji_flight_controller.h"
#include "flight_control/test_flight_control.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiReturnCode DjiUser_InterestPointMissionStateCallback(T_DjiInterestPointMissionState missionState);
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_InterestPointRunSample(void)
{
T_DjiReturnCode returnCode;
T_DjiInterestPointSettings interestPointSettings = {0};
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiFlightControllerRidInfo ridInfo = {0};
ridInfo.latitude = 22.542812;
ridInfo.longitude = 113.958902;
ridInfo.altitude = 10;
returnCode = DjiFlightController_Init(ridInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Flight control init failed, errno=%lld", returnCode);
return returnCode;
}
returnCode = DjiInterestPoint_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Point interest init failed, errno=%lld", returnCode);
return returnCode;
}
osalHandler->TaskSleepMs(1000);
DjiFlightController_ObtainJoystickCtrlAuthority();
osalHandler->TaskSleepMs(1000);
DjiFlightController_StartTakeoff();
osalHandler->TaskSleepMs(1000);
DjiTest_FlightControlVelocityAndYawRateCtrl((T_DjiTestFlightControlVector3f) {0, 0, 5}, 0, 10000);
osalHandler->TaskSleepMs(1000);
DjiTest_FlightControlVelocityAndYawRateCtrl((T_DjiTestFlightControlVector3f) {3, 0, 0}, 0, 5000);
interestPointSettings.latitude = 22.542812;
interestPointSettings.longitude = 113.958902;
returnCode = DjiInterestPoint_RegMissionStateCallback(DjiUser_InterestPointMissionStateCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register mission state callback failed, errno=%lld", returnCode);
return returnCode;
}
returnCode = DjiInterestPoint_Start(interestPointSettings);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Point interest start failed, errno=%lld", returnCode);
return returnCode;
}
DjiInterestPoint_SetSpeed(5.0f);
for (int i = 0; i < 60; ++i) {
USER_LOG_INFO("Interest point mission running %d.", i);
osalHandler->TaskSleepMs(1000);
}
returnCode = DjiInterestPoint_Stop();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Point interest stop failed, errno=%lld", returnCode);
return returnCode;
}
DjiFlightController_StartForceLanding();
returnCode = DjiInterestPoint_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Point interest deinit failed, errno=%lld", returnCode);
return returnCode;
}
returnCode = DjiFlightController_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Flight control init failed, errno=%lld", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiUser_InterestPointMissionStateCallback(T_DjiInterestPointMissionState missionState)
{
USER_LOG_INFO("Interest point state: %d, radius: %.2f m, speed: %.2f m/s", missionState.state, missionState.radius,
missionState.curSpeed);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,49 @@
/**
********************************************************************
* @file test_interest_point.h
* @brief This is the header file for "test_interest_point.c", 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 TEST_INTEREST_POINT_H
#define TEST_INTEREST_POINT_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_InterestPointRunSample(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_INTEREST_POINT_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,240 @@
/**
********************************************************************
* @file test_liveview.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 <utils/util_misc.h>
#include <widget_interaction_test/test_widget_interaction.h>
#include "test_liveview.h"
#include "dji_liveview.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "dji_aircraft_info.h"
#include "time.h"
/* Private constants ---------------------------------------------------------*/
#define TEST_LIVEVIEW_STREAM_FILE_PATH_STR_MAX_SIZE 256
#define TEST_LIVEVIEW_STREAM_STROING_TIME_IN_SECONDS 20
#define TEST_LIVEVIEW_STREAM_REQUEST_I_FRAME_ON 1
#define TEST_LIVEVIEW_STREAM_REQUEST_I_FRAME_TICK_IN_SECONDS 5
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static char s_fpvCameraStreamFilePath[TEST_LIVEVIEW_STREAM_FILE_PATH_STR_MAX_SIZE];
static char s_payloadCameraStreamFilePath[TEST_LIVEVIEW_STREAM_FILE_PATH_STR_MAX_SIZE];
/* Private functions declaration ---------------------------------------------*/
static void DjiTest_FpvCameraStreamCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf,
uint32_t bufLen);
static void DjiTest_PayloadCameraStreamCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf,
uint32_t bufLen);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_LiveviewRunSample(E_DjiMountPosition mountPosition)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
time_t currentTime = time(NULL);
struct tm *localTime = NULL;
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo = {0};
USER_LOG_INFO("Liveview sample start");
DjiTest_WidgetLogAppend("Liveview sample start");
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;
}
USER_LOG_INFO("--> Step 1: Init liveview module");
DjiTest_WidgetLogAppend("--> Step 1: Init liveview module");
returnCode = DjiLiveview_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Liveview init failed, error code: 0x%08X", returnCode);
goto out;
}
USER_LOG_INFO("--> Step 2: Start h264 stream of the fpv and selected payload\r\n");
DjiTest_WidgetLogAppend("--> Step 2: Start h264 stream of the fpv and selected payload\r\n");
if (aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M300 ||
aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M350 ||
aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M30) {
localTime = localtime(&currentTime);
sprintf(s_fpvCameraStreamFilePath, "fpv_stream_%04d%02d%02d_%02d-%02d-%02d.h264",
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
returnCode = DjiLiveview_StartH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_FPV, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
DjiTest_FpvCameraStreamCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request h264 of fpv failed, error code: 0x%08X", returnCode);
goto out;
}
}
localTime = localtime(&currentTime);
sprintf(s_payloadCameraStreamFilePath, "payload%d_vis_stream_%04d%02d%02d_%02d-%02d-%02d.h264",
mountPosition, localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
returnCode = DjiLiveview_StartH264Stream((E_DjiLiveViewCameraPosition) mountPosition,
DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
DjiTest_PayloadCameraStreamCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request h264 of payload %d failed, error code: 0x%08X", mountPosition, returnCode);
}
for (int i = 0; i < TEST_LIVEVIEW_STREAM_STROING_TIME_IN_SECONDS; ++i) {
USER_LOG_INFO("Storing camera h264 stream, second: %d.", i + 1);
#if TEST_LIVEVIEW_STREAM_REQUEST_I_FRAME_ON
if (i % TEST_LIVEVIEW_STREAM_REQUEST_I_FRAME_TICK_IN_SECONDS == 0) {
returnCode = DjiLiveview_RequestIntraframeFrameData((E_DjiLiveViewCameraPosition) mountPosition,
DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request stream I frame of payload %d failed, error code: 0x%08X", mountPosition,
returnCode);
}
}
#endif
osalHandler->TaskSleepMs(1000);
}
USER_LOG_INFO("--> Step 3: Stop h264 stream of the fpv and selected payload\r\n");
DjiTest_WidgetLogAppend("--> Step 3: Stop h264 stream of the fpv and selected payload");
if (aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M300 ||
aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M350 ||
aircraftInfoBaseInfo.aircraftSeries == DJI_AIRCRAFT_SERIES_M30) {
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_FPV, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request to stop h264 of fpv failed, error code: 0x%08X", returnCode);
goto out;
}
}
returnCode = DjiLiveview_StopH264Stream((E_DjiLiveViewCameraPosition) mountPosition,
DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request to stop h264 of payload %d failed, error code: 0x%08X", mountPosition, returnCode);
goto out;
}
USER_LOG_INFO("Fpv stream is saved to file: %s", s_fpvCameraStreamFilePath);
USER_LOG_INFO("Payload%d stream is saved to file: %s\r\n", mountPosition, s_payloadCameraStreamFilePath);
if (aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3T ||
aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3TD) {
USER_LOG_INFO("--> Start h264 stream of the fpv and selected payload\r\n");
localTime = localtime(&currentTime);
sprintf(s_payloadCameraStreamFilePath, "payload%d_ir_stream_%04d%02d%02d_%02d-%02d-%02d.h264",
mountPosition, localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
returnCode = DjiLiveview_StartH264Stream((E_DjiLiveViewCameraPosition) mountPosition,
DJI_LIVEVIEW_CAMERA_SOURCE_M3T_IR,
DjiTest_PayloadCameraStreamCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request h264 of payload %d failed, error code: 0x%08X", mountPosition, returnCode);
}
for (int i = 0; i < TEST_LIVEVIEW_STREAM_STROING_TIME_IN_SECONDS; ++i) {
USER_LOG_INFO("Storing camera h264 stream, second: %d.", i + 1);
osalHandler->TaskSleepMs(1000);
}
returnCode = DjiLiveview_StopH264Stream((E_DjiLiveViewCameraPosition) mountPosition,
DJI_LIVEVIEW_CAMERA_SOURCE_M3T_IR);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Request to stop h264 of payload %d failed, error code: 0x%08X", mountPosition, returnCode);
goto out;
}
}
USER_LOG_INFO("Fpv stream is saved to file: %s", s_fpvCameraStreamFilePath);
USER_LOG_INFO("Payload%d stream is saved to file: %s\r\n", mountPosition, s_payloadCameraStreamFilePath);
USER_LOG_INFO("--> Step 4: Deinit liveview module");
DjiTest_WidgetLogAppend("--> Step 4: Deinit liveview module");
returnCode = DjiLiveview_Deinit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Liveview deinit failed, error code: 0x%08X", returnCode);
goto out;
}
out:
USER_LOG_INFO("Liveview sample end");
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static void DjiTest_FpvCameraStreamCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf,
uint32_t bufLen)
{
FILE *fp = NULL;
size_t size;
fp = fopen(s_fpvCameraStreamFilePath, "ab+");
if (fp == NULL) {
printf("fopen failed!\n");
return;
}
size = fwrite(buf, 1, bufLen, fp);
if (size != bufLen) {
fclose(fp);
return;
}
fflush(fp);
fclose(fp);
}
static void DjiTest_PayloadCameraStreamCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf,
uint32_t bufLen)
{
FILE *fp = NULL;
size_t size;
fp = fopen(s_payloadCameraStreamFilePath, "ab+");
if (fp == NULL) {
printf("fopen failed!\n");
return;
}
size = fwrite(buf, 1, bufLen, fp);
if (size != bufLen) {
fclose(fp);
return;
}
fflush(fp);
fclose(fp);
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,49 @@
/**
********************************************************************
* @file test_liveview.h
* @brief This is the header file for "test_liveview.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 TEST_LIVEVIEW_H
#define TEST_LIVEVIEW_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_LiveviewRunSample(E_DjiMountPosition mountPosition);
#ifdef __cplusplus
}
#endif
#endif // TEST_LIVEVIEW_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,833 @@
/**
********************************************************************
* @file test_mop_channel.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 <utils/util_misc.h>
#include <stdio.h>
#include <utils/util_md5.h>
#include "dji_mop_channel.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "test_mop_channel.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_MOP_CHANNEL_TASK_STACK_SIZE 2048
#define TEST_MOP_CHANNEL_INIT_TIMEMS (3 * 1000)
#define TEST_MOP_CHANNEL_RETRY_TIMEMS (3 * 1000)
#define TEST_MOP_CHANNEL_NORMAL_TRANSFOR_CHANNEL_ID 49152
#define TEST_MOP_CHANNEL_NORMAL_TRANSFOR_USING_RELIABLE_TRANS 0
#define TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_TASK_FREQ 1
#define TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_BUFFER (64 * 1024)
#define TEST_MOP_CHANNEL_NORMAL_TRANSFOR_RECV_BUFFER (100 * 1024)
#define TEST_MOP_CHANNEL_FILE_SERVICE_CHANNEL_ID 49153
#define TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER (3 * 1024 * 1024)
#define TEST_MOP_CHANNEL_FILE_SERVICE_RECV_BUFFER (100 * 1024)
#define TEST_MOP_CHANNEL_FILE_SERVICE_CLIENT_MAX_SUPPORT_NUM 10
/* Private types -------------------------------------------------------------*/
typedef enum {
MOP_FILE_SERVICE_DOWNLOAD_IDEL = 0,
MOP_FILE_SERVICE_DOWNLOAD_REQUEST_START,
MOP_FILE_SERVICE_DOWNLOAD_FILE_INFO_SUCCESS,
MOP_FILE_SERVICE_DOWNLOAD_FILE_INFO_FAILED,
MOP_FILE_SERVICE_DOWNLOAD_DATA_SENDING,
MOP_FILE_SERVICE_DOWNLOAD_FINISHED_SUCCESS,
MOP_FILE_SERVICE_DOWNLOAD_FINISHED_FAILED,
MOP_FILE_SERVICE_DOWNLOAD_STOP,
} E_MopFileServiceDownloadState;
typedef enum {
MOP_FILE_SERVICE_UPLOAD_IDEL = 0,
MOP_FILE_SERVICE_UPLOAD_REQUEST_START,
MOP_FILE_SERVICE_UPLOAD_FILE_INFO_SUCCESS,
MOP_FILE_SERVICE_UPLOAD_FILE_INFO_FAILED,
MOP_FILE_SERVICE_UPLOAD_DATA_SENDING,
MOP_FILE_SERVICE_UPLOAD_FINISHED_SUCCESS,
MOP_FILE_SERVICE_UPLOAD_FINISHED_FAILED,
MOP_FILE_SERVICE_UPLOAD_STOP,
} E_MopFileServiceUploadState;
typedef struct {
uint8_t index;
T_DjiTaskHandle clientRecvTask;
T_DjiTaskHandle clientSendTask;
T_DjiMopChannelHandle clientHandle;
E_MopFileServiceDownloadState downloadState;
uint16_t downloadSeqNum;
E_MopFileServiceUploadState uploadState;
uint16_t uploadSeqNum;
} T_MopFileServiceClientContent;
/* Private values -------------------------------------------------------------*/
static T_DjiMopChannelHandle s_testMopChannelNormalHandle;
static T_DjiMopChannelHandle s_testMopChannelNormalOutHandle;
static T_DjiTaskHandle s_testMopChannelNormalSendTask;
static T_DjiTaskHandle s_testMopChannelNormalRecvTask;
static T_DjiSemaHandle s_testMopChannelReadySema;
static bool s_testMopChannelConnected = false;
static T_DjiTaskHandle s_fileServiceMopChannelAcceptTask;
static T_DjiMopChannelHandle s_fileServiceMopChannelHandle;
static T_MopFileServiceClientContent s_fileServiceContent[TEST_MOP_CHANNEL_FILE_SERVICE_CLIENT_MAX_SUPPORT_NUM];
/* Private functions declaration ---------------------------------------------*/
static void *DjiTest_MopChannelSendNormalTask(void *arg);
static void *DjiTest_MopChannelRecvNormalTask(void *arg);
static void *DjiTest_MopChannelFileServiceAcceptTask(void *arg);
static void *DjiTest_MopChannelFileServiceRecvTask(void *arg);
static void *DjiTest_MopChannelFileServiceSendTask(void *arg);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_MopChannelStartService(void)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->SemaphoreCreate(0, &s_testMopChannelReadySema);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel create msdk sema error, stat:0x%08llX.", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = DjiMopChannel_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel init error, stat:0x%08llX.", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = osalHandler->TaskCreate("mop_msdk_send_task", DjiTest_MopChannelSendNormalTask,
DJI_MOP_CHANNEL_TASK_STACK_SIZE, NULL, &s_testMopChannelNormalSendTask);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel msdk send task create error, stat:0x%08llX.", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = osalHandler->TaskCreate("mop_msdk_recv_task", DjiTest_MopChannelRecvNormalTask,
DJI_MOP_CHANNEL_TASK_STACK_SIZE, NULL, &s_testMopChannelNormalRecvTask);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel msdk recv task create error, stat:0x%08llX.", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = osalHandler->TaskCreate("mop_msdk_accept_task", DjiTest_MopChannelFileServiceAcceptTask,
DJI_MOP_CHANNEL_TASK_STACK_SIZE, NULL, &s_fileServiceMopChannelAcceptTask);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel osdk recv task create error, stat:0x%08llX.", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
static void *DjiTest_MopChannelSendNormalTask(void *arg)
{
uint8_t *sendBuf = NULL;
uint32_t realLen = 0;
T_DjiReturnCode returnCode;
uint32_t sendDataCount = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
USER_UTIL_UNUSED(arg);
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_INIT_TIMEMS);
sendBuf = osalHandler->Malloc(TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_BUFFER);
if (sendBuf == NULL) {
USER_LOG_ERROR("malloc send buffer error");
return NULL;
}
REWAIT:
returnCode = osalHandler->SemaphoreWait(s_testMopChannelReadySema);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel wait sema error, stat:0x%08llX.", returnCode);
return NULL;
}
while (1) {
if (s_testMopChannelConnected == false) {
sendDataCount = 0;
goto REWAIT;
}
sendDataCount++;
memset(sendBuf, sendDataCount, TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_BUFFER);
returnCode = DjiMopChannel_SendData(s_testMopChannelNormalOutHandle, sendBuf,
TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_BUFFER, &realLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel send data to channel error,stat:0x%08llX", returnCode);
} else {
USER_LOG_INFO("mop channel send data to channel length:%d count:%d", realLen, sendDataCount);
}
osalHandler->TaskSleepMs(1000 / TEST_MOP_CHANNEL_NORMAL_TRANSFOR_SEND_TASK_FREQ);
}
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
static void *DjiTest_MopChannelRecvNormalTask(void *arg)
{
USER_UTIL_UNUSED(arg);
uint8_t *recvBuf = NULL;
uint32_t realLen;
T_DjiReturnCode returnCode;
uint32_t recvDataCount = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_INIT_TIMEMS);
#if TEST_MOP_CHANNEL_NORMAL_TRANSFOR_USING_RELIABLE_TRANS
returnCode = DjiMopChannel_Create(&s_testMopChannelNormalHandle, DJI_MOP_CHANNEL_TRANS_RELIABLE);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel create send handle error, stat:0x%08llX.", returnCode);
return NULL;
}
#else
returnCode = DjiMopChannel_Create(&s_testMopChannelNormalHandle, DJI_MOP_CHANNEL_TRANS_UNRELIABLE);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel create send handle error, stat:0x%08llX.", returnCode);
return NULL;
}
#endif
REBIND:
returnCode = DjiMopChannel_Bind(s_testMopChannelNormalHandle, TEST_MOP_CHANNEL_NORMAL_TRANSFOR_CHANNEL_ID);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop bind channel error :0x%08llX", returnCode);
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_RETRY_TIMEMS);
goto REBIND;
}
REACCEPT:
returnCode = DjiMopChannel_Accept(s_testMopChannelNormalHandle, &s_testMopChannelNormalOutHandle);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_WARN("mop accept channel error :0x%08llX", returnCode);
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_RETRY_TIMEMS);
goto REACCEPT;
}
USER_LOG_INFO("mop channel is connected");
recvBuf = osalHandler->Malloc(TEST_MOP_CHANNEL_NORMAL_TRANSFOR_RECV_BUFFER);
if (recvBuf == NULL) {
USER_LOG_ERROR("malloc recv buffer error");
return NULL;
}
s_testMopChannelConnected = true;
returnCode = osalHandler->SemaphorePost(s_testMopChannelReadySema);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel post sema error, stat:0x%08llX.", returnCode);
return NULL;
}
while (1) {
memset(recvBuf, 0, TEST_MOP_CHANNEL_NORMAL_TRANSFOR_RECV_BUFFER);
returnCode = DjiMopChannel_RecvData(s_testMopChannelNormalOutHandle, recvBuf,
TEST_MOP_CHANNEL_NORMAL_TRANSFOR_RECV_BUFFER, &realLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
if (returnCode == DJI_ERROR_MOP_CHANNEL_MODULE_CODE_CONNECTION_CLOSE) {
USER_LOG_INFO("mop channel is disconnected");
s_testMopChannelConnected = false;
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_RETRY_TIMEMS);
DjiMopChannel_Close(s_testMopChannelNormalOutHandle);
DjiMopChannel_Destroy(s_testMopChannelNormalOutHandle);
goto REACCEPT;
}
} else {
USER_LOG_INFO("mop channel recv data from channel length:%d count:%d", realLen, recvDataCount++);
}
}
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
static void *DjiTest_MopChannelFileServiceAcceptTask(void *arg)
{
T_DjiReturnCode returnCode;
uint8_t currentClientNum = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
USER_UTIL_UNUSED(arg);
USER_LOG_DEBUG("[File-Service] Start the file service.");
returnCode = DjiMopChannel_Create(&s_fileServiceMopChannelHandle, DJI_MOP_CHANNEL_TRANS_RELIABLE);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("[File-Service] mop channel create send handle error, stat:0x%08llX.", returnCode);
return NULL;
}
REBIND:
returnCode = DjiMopChannel_Bind(s_fileServiceMopChannelHandle, TEST_MOP_CHANNEL_FILE_SERVICE_CHANNEL_ID);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("[File-Service] mop bind channel error :0x%08llX", returnCode);
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_RETRY_TIMEMS);
goto REBIND;
}
while (1) {
REACCEPT:
returnCode = DjiMopChannel_Accept(s_fileServiceMopChannelHandle,
&s_fileServiceContent[currentClientNum].clientHandle);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_WARN("[File-Service] mop accept channel error :0x%08llX", returnCode);
osalHandler->TaskSleepMs(TEST_MOP_CHANNEL_RETRY_TIMEMS);
goto REACCEPT;
}
USER_LOG_INFO("[File-Service] [Client:%d] mop channel is connected", currentClientNum);
s_fileServiceContent[currentClientNum].index = currentClientNum;
returnCode = osalHandler->TaskCreate("mop_file_service_recv_task",
DjiTest_MopChannelFileServiceRecvTask,
DJI_MOP_CHANNEL_TASK_STACK_SIZE,
&s_fileServiceContent[currentClientNum].index,
&s_fileServiceContent[currentClientNum].clientRecvTask);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel recv task create error, stat:0x%08llX.", returnCode);
return NULL;
}
returnCode = osalHandler->TaskCreate("mop_file_service_send_task",
DjiTest_MopChannelFileServiceSendTask,
DJI_MOP_CHANNEL_TASK_STACK_SIZE,
&s_fileServiceContent[currentClientNum].index,
&s_fileServiceContent[currentClientNum].clientSendTask);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("mop channel send task create error, stat:0x%08llX.", returnCode);
return NULL;
}
currentClientNum++;
if (currentClientNum > TEST_MOP_CHANNEL_FILE_SERVICE_CLIENT_MAX_SUPPORT_NUM) {
currentClientNum = 0;
}
}
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
static void *DjiTest_MopChannelFileServiceSendTask(void *arg)
{
T_DjiReturnCode returnCode;
uint8_t clientNum = *(uint8_t *) arg;
uint32_t sendRealLen = 0;
uint8_t *sendBuf;
MD5_CTX downloadFileMd5Ctx;
FILE *downloadFile = NULL;
uint8_t downloadFileMd5[DJI_MD5_BUFFER_LEN] = {0};
uint64_t downloadFileTotalSize = 0;
uint64_t downloadWriteLen;
uint16_t downloadPackCount = 0;
T_DjiMopChannel_FileInfo downloadFileInfo = {0};
T_DjiMopChannel_FileTransfor transforAck = {0};
T_DjiMopChannel_FileTransfor fileData = {0};
T_DjiMopChannel_FileTransfor fileInfo = {0};
uint32_t downloadStartMs = 0;
uint32_t downloadEndMs = 0;
uint32_t downloadDurationMs;
dji_f32_t downloadRate;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
char curFileDirPath[DJI_FILE_PATH_SIZE_MAX];
char tempPath[DJI_FILE_PATH_SIZE_MAX];
sendBuf = osalHandler->Malloc(TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER);
if (sendBuf == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] malloc send buffer error", clientNum);
return NULL;
}
while (1) {
switch (s_fileServiceContent[clientNum].uploadState) {
case MOP_FILE_SERVICE_UPLOAD_REQUEST_START:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_OK;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, (uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_DEBUG("[File-Service] [Client:%d] upload request ack", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
case MOP_FILE_SERVICE_UPLOAD_FILE_INFO_SUCCESS:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_OK;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, (uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_DEBUG("[File-Service] [Client:%d] upload file info success", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
case MOP_FILE_SERVICE_UPLOAD_FILE_INFO_FAILED:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_REJECTED;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, (uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_ERROR("[File-Service] [Client:%d] upload file info failed", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
case MOP_FILE_SERVICE_UPLOAD_FINISHED_SUCCESS:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_RESULT;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_RESULT_OK;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum++;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle,
(uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_DEBUG("[File-Service] [Client:%d] upload finished success", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
case MOP_FILE_SERVICE_UPLOAD_FINISHED_FAILED:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_RESULT;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_RESULT_FAILED;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum++;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle,
(uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_ERROR("[File-Service] [Client:%d] upload finished failed", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
case MOP_FILE_SERVICE_UPLOAD_STOP:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_STOP_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_UPLOAD;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum++;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle,
(uint8_t *) &transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
break;
default:
break;
}
switch (s_fileServiceContent[clientNum].downloadState) {
case MOP_FILE_SERVICE_DOWNLOAD_REQUEST_START:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_OK;
transforAck.seqNum = s_fileServiceContent[clientNum].downloadSeqNum;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, (uint8_t * ) & transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
USER_LOG_DEBUG("[File-Service] [Client:%d] download request ack", clientNum);
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_IDEL;
break;
case MOP_FILE_SERVICE_DOWNLOAD_STOP:
transforAck.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_STOP_ACK;
transforAck.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_DOWNLOAD;
transforAck.seqNum = s_fileServiceContent[clientNum].uploadSeqNum++;
transforAck.dataLen = 0;
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle,
(uint8_t *) &transforAck,
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data),
&sendRealLen);
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_IDEL;
break;
case MOP_FILE_SERVICE_DOWNLOAD_FILE_INFO_SUCCESS:
UtilMd5_Init(&downloadFileMd5Ctx);
osalHandler->GetTimeMs(&downloadStartMs);
if (downloadFile != NULL) {
fclose(downloadFile);
}
returnCode = DjiUserUtil_GetCurrentFileDirPath(__FILE__, DJI_FILE_PATH_SIZE_MAX, curFileDirPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", returnCode);
exit(1);
}
snprintf(tempPath, DJI_FILE_PATH_SIZE_MAX, "%smop_channel_test_file/mop_send_test_file.mp4", curFileDirPath);
downloadFile = fopen(tempPath, "rb");
if (downloadFile == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] download open file error",
clientNum);
return NULL;
}
downloadFileTotalSize = 0;
while (1) {
returnCode = fseek(downloadFile, downloadFileTotalSize, SEEK_SET);
if (returnCode != 0) {
USER_LOG_ERROR(
"[File-Service] [Client:%d] mop channel fseek file data fail.", clientNum);
}
downloadWriteLen = fread(sendBuf, 1, TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER,
downloadFile);
if (downloadWriteLen > 0) {
downloadFileTotalSize += downloadWriteLen;
UtilMd5_Update(&downloadFileMd5Ctx, sendBuf, downloadWriteLen);
if (downloadWriteLen < TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER) {
break;
}
}
}
UtilMd5_Final(&downloadFileMd5Ctx, downloadFileMd5);
fileInfo.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_INFO;
fileInfo.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_DOWNLOAD_REQUEST;
fileInfo.seqNum = s_fileServiceContent[clientNum].downloadSeqNum;
fileInfo.dataLen = sizeof(fileInfo) - UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data);
fileInfo.data.fileInfo.isExist = true;
downloadFileInfo.fileLength = downloadFileTotalSize;
fileInfo.data.fileInfo.fileLength = downloadFileTotalSize;
strcpy(fileInfo.data.fileInfo.fileName, "test.mp4");
memcpy(&fileInfo.data.fileInfo.md5Buf, &downloadFileMd5, sizeof(downloadFileMd5));
DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, (uint8_t *) &fileInfo,
sizeof(T_DjiMopChannel_FileTransfor),
&sendRealLen);
USER_LOG_DEBUG(
"[File-Service] [Client:%d] download ack file info exist:%d length:%d name:%s",
clientNum, fileInfo.data.fileInfo.isExist,
fileInfo.data.fileInfo.fileLength, fileInfo.data.fileInfo.fileName);
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_DATA_SENDING;
downloadFileTotalSize = 0;
downloadPackCount = 0;
break;
case MOP_FILE_SERVICE_DOWNLOAD_DATA_SENDING:
if (downloadFile == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] download file object is NULL.");
break;
}
returnCode = fseek(downloadFile, downloadFileTotalSize, SEEK_SET);
if (returnCode != 0) {
USER_LOG_ERROR("[File-Service] [Client:%d] download fseek file data fail.",
clientNum);
break;
}
downloadWriteLen = fread(&sendBuf[UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)],
1,
(TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER -
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)),
downloadFile);
if (downloadWriteLen > 0) {
downloadFileTotalSize += downloadWriteLen;
downloadPackCount++;
fileData.cmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_DATA;
fileData.dataLen = downloadWriteLen;
fileData.seqNum++;
if (downloadWriteLen ==
(TEST_MOP_CHANNEL_FILE_SERVICE_SEND_BUFFER -
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data))) {
fileData.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_NORMAL;
} else {
fileData.subcmd = DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_END;
}
memcpy(sendBuf, &fileData, UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data));
returnCode = DjiMopChannel_SendData(s_fileServiceContent[clientNum].clientHandle, sendBuf,
(downloadWriteLen +
UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)),
&sendRealLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR(
"[File-Service] [Client:%d] download send file data error,stat:0x%08llX",
clientNum, returnCode);
if (returnCode == DJI_ERROR_MOP_CHANNEL_MODULE_CODE_CONNECTION_CLOSE) {
break;
}
} else {
USER_LOG_INFO(
"[File-Service] [Client:%d] download send file data length:%d count:%d total:%d percent: %.1f %%",
clientNum, sendRealLen, downloadPackCount, downloadFileTotalSize,
(dji_f32_t)(downloadFileTotalSize) * 100 / (dji_f32_t) downloadFileInfo.fileLength);
}
if (fileData.subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_END) {
osalHandler->GetTimeMs(&downloadEndMs);
downloadDurationMs = downloadEndMs - downloadStartMs;
if (downloadDurationMs != 0) {
downloadRate = (dji_f32_t) downloadFileInfo.fileLength * 1000 /
(dji_f32_t) (downloadDurationMs);
USER_LOG_INFO(
"[File-Service] [Client:%d] download finished totalTime:%d, rate:%.2f Byte/s",
clientNum, downloadDurationMs, downloadRate);
}
}
break;
default:
break;
}
}
}
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
static void *DjiTest_MopChannelFileServiceRecvTask(void *arg)
{
T_DjiReturnCode returnCode;
uint8_t clientNum = *(uint8_t *) arg;
uint32_t recvRealLen;
uint8_t *recvBuf;
MD5_CTX uploadFileMd5Ctx;
FILE *uploadFile = NULL;
uint8_t uploadFileMd5[DJI_MD5_BUFFER_LEN] = {0};
uint32_t uploadFileTotalSize = 0;
int32_t uploadWriteLen;
T_DjiMopChannel_FileInfo uploadFileInfo = {0};
uint32_t uploadStartMs = 0;
uint32_t uploadEndMs = 0;
dji_f32_t uploadRate;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
recvBuf = osalHandler->Malloc(TEST_MOP_CHANNEL_FILE_SERVICE_RECV_BUFFER);
if (recvBuf == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] malloc recv buffer error", clientNum);
return NULL;
}
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_IDEL;
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_IDEL;
while (1) {
returnCode = DjiMopChannel_RecvData(s_fileServiceContent[clientNum].clientHandle, recvBuf,
TEST_MOP_CHANNEL_FILE_SERVICE_RECV_BUFFER, &recvRealLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
osalHandler->TaskSleepMs(1000);
if (returnCode == DJI_ERROR_MOP_CHANNEL_MODULE_CODE_CONNECTION_CLOSE) {
USER_LOG_INFO("[File-Service] [Client:%d] mop channel is disconnected", clientNum);
osalHandler->TaskDestroy(s_fileServiceContent[clientNum].clientRecvTask);
DjiMopChannel_Close(s_fileServiceContent[clientNum].clientHandle);
DjiMopChannel_Destroy(s_fileServiceContent[clientNum].clientHandle);
}
} else {
if (&recvRealLen > 0) {
T_DjiMopChannel_FileTransfor *fileTransfor = (T_DjiMopChannel_FileTransfor *) recvBuf;
switch (fileTransfor->cmd) {
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_REQUEST:
if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_REQUEST_UPLOAD) {
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_REQUEST_START;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
USER_LOG_DEBUG("[File-Service] [Client:%d] upload request is ok", clientNum);
UtilMd5_Init(&uploadFileMd5Ctx);
uploadFileTotalSize = 0;
osalHandler->GetTimeMs(&uploadStartMs);
} else if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_REQUEST_DOWNLOAD) {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_REQUEST_START;
s_fileServiceContent[clientNum].downloadSeqNum = fileTransfor->seqNum;
USER_LOG_DEBUG("[File-Service] [Client:%d] download request is ok", clientNum);
}
break;
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_DOWNLOAD_REQ:
USER_LOG_DEBUG("[File-Service] [Client:%d] download request file name:%s", clientNum,
fileTransfor->data.dwonloadReq.fileName);
if (strcmp(fileTransfor->data.dwonloadReq.fileName, "test.mp4") == 0) {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_FILE_INFO_SUCCESS;
s_fileServiceContent[clientNum].downloadSeqNum = fileTransfor->seqNum;
} else {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_FILE_INFO_FAILED;
s_fileServiceContent[clientNum].downloadSeqNum = fileTransfor->seqNum;
}
break;
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_INFO:
USER_LOG_DEBUG(
"[File-Service] [Client:%d] upload file info length:%d exist:%d name:%s seq:%d", clientNum,
fileTransfor->data.fileInfo.fileLength,
fileTransfor->data.fileInfo.isExist,
fileTransfor->data.fileInfo.fileName, fileTransfor->seqNum);
uploadFileInfo.fileLength = fileTransfor->data.fileInfo.fileLength;
memcpy(uploadFileInfo.md5Buf, fileTransfor->data.fileInfo.md5Buf,
sizeof(uploadFileInfo.md5Buf));
if (uploadFile != NULL) {
fclose(uploadFile);
}
uploadFile = fopen(fileTransfor->data.fileInfo.fileName, "wb");
if (uploadFile == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] open file error", clientNum);
return NULL;
}
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_FILE_INFO_SUCCESS;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
break;
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_DATA:
if (uploadFile == NULL) {
USER_LOG_ERROR("[File-Service] [Client:%d] open file error", clientNum);
return NULL;
}
if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_NORMAL) {
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_DATA_SENDING;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
uploadWriteLen = fwrite(&recvBuf[UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)], 1,
fileTransfor->dataLen, uploadFile);
if (uploadWriteLen < 0) {
USER_LOG_ERROR(
"[File-Service] [Client:%d] upload write normal data to file error, stat:%d.",
clientNum,
uploadWriteLen);
} else {
uploadFileTotalSize += uploadWriteLen;
UtilMd5_Update(&uploadFileMd5Ctx,
&recvBuf[UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)],
fileTransfor->dataLen);
if (uploadFileInfo.fileLength != 0) {
USER_LOG_INFO(
"[File-Service] [Client:%d] upload write data to file success, len:%d percent:%.1f %%",
clientNum, uploadWriteLen,
(dji_f32_t)(uploadFileTotalSize * 100) /
(dji_f32_t) uploadFileInfo.fileLength);
}
}
} else if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_END) {
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_DATA_SENDING;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
uploadWriteLen = fwrite(&recvBuf[UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)], 1,
fileTransfor->dataLen, uploadFile);
if (uploadWriteLen < 0) {
USER_LOG_ERROR(
"[File-Service] [Client:%d] upload write end data to file error, stat:%d.",
clientNum,
uploadWriteLen);
} else {
uploadFileTotalSize += uploadWriteLen;
UtilMd5_Update(&uploadFileMd5Ctx,
&recvBuf[UTIL_OFFSETOF(T_DjiMopChannel_FileTransfor, data)],
fileTransfor->dataLen);
UtilMd5_Final(&uploadFileMd5Ctx, uploadFileMd5);
osalHandler->GetTimeMs(&uploadEndMs);
if (uploadEndMs - uploadStartMs > 0) {
uploadRate = (dji_f32_t) uploadFileTotalSize * 1000 /
(dji_f32_t) (uploadEndMs - uploadStartMs);
USER_LOG_INFO(
"[File-Service] [Client:%d] upload write data to file success, len:%d percent:%.1f %%",
clientNum, uploadWriteLen,
(dji_f32_t)(uploadFileTotalSize * 100) /
(dji_f32_t) uploadFileInfo.fileLength);
USER_LOG_INFO(
"[File-Service] [Client:%d] upload file finished, totalTime:%d ms rate:%.2f Byte/s",
clientNum, (uploadEndMs - uploadStartMs), uploadRate);
}
fclose(uploadFile);
uploadFile = NULL;
if (uploadFileInfo.fileLength == uploadFileTotalSize) {
if (memcmp(uploadFileInfo.md5Buf, uploadFileMd5, sizeof(uploadFileMd5)) == 0) {
USER_LOG_DEBUG(
"[File-Service] [Client:%d] upload file md5 check success", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_FINISHED_SUCCESS;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
} else {
USER_LOG_ERROR(
"[File-Service] [Client:%d] upload file md5 check failed", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_FINISHED_FAILED;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
}
} else {
USER_LOG_ERROR(
"[File-Service] [Client:%d] upload file check file length error", clientNum);
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_FINISHED_FAILED;
s_fileServiceContent[clientNum].uploadSeqNum = fileTransfor->seqNum;
}
}
}
break;
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_RESULT:
if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_RESULT_OK) {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_FINISHED_SUCCESS;
USER_LOG_DEBUG("[File-Service] [Client:%d] download file result notify success",
clientNum);
} else {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_FINISHED_FAILED;
USER_LOG_ERROR("[File-Service] [Client:%d] download file result notify failed",
clientNum);
}
break;
case DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_STOP_REQUEST:
if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_UPLOAD) {
s_fileServiceContent[clientNum].uploadState = MOP_FILE_SERVICE_UPLOAD_STOP;
USER_LOG_DEBUG("[File-Service] [Client:%d] upload file stop", clientNum);
} else if (fileTransfor->subcmd == DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_DOWNLOAD) {
s_fileServiceContent[clientNum].downloadState = MOP_FILE_SERVICE_DOWNLOAD_STOP;
USER_LOG_DEBUG("[File-Service] [Client:%d] download file stop", clientNum);
}
break;
default:
USER_LOG_WARN("[File-Service] [Client:%d] recv the unknown command0x%02X",
clientNum, fileTransfor->cmd);
break;
}
}
}
}
}
#pragma GCC diagnostic pop
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,119 @@
/**
********************************************************************
* @file test_mop_channel.h
* @brief This is the header file for "test_mop_channel.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 TEST_MOP_CHANNEL_H
#define TEST_MOP_CHANNEL_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_REQUEST = 0x50,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_ACK = 0x51,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_RESULT = 0x52,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_INFO = 0x60,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_DOWNLOAD_REQ = 0x61,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_FILE_DATA = 0x62,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_STOP_REQUEST = 0x63,
DJI_MOP_CHANNEL_FILE_TRANSFOR_CMD_STOP_ACK = 0x64,
} E_DjiMopChannel_FileTransforCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_REQUEST_UPLOAD = 0x00,
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_REQUEST_DOWNLOAD = 0x01,
} E_DjiMopChannel_FileTransforRequestSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_OK = 0x00,
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_ACK_REJECTED = 0x01,
} E_DjiMopChannel_FileTransforAckSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_RESULT_OK = 0x00,
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_RESULT_FAILED = 0x01,
} E_DjiMopChannel_FileTransforResultSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_INFO_DEFAULT = 0xFF,
} E_DjiMopChannel_FileTransforFileInfoSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_DOWNLOAD_REQUEST = 0xFF,
} E_DjiMopChannel_FileTransforFileDownloadRequestSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_NORMAL = 0x00,
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_FILE_DATA_END = 0x01,
} E_DjiMopChannel_FileTransforFileDataSubCmd;
typedef enum {
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_UPLOAD = 0x00,
DJI_MOP_CHANNEL_FILE_TRANSFOR_SUBCMD_STOP_DOWNLOAD = 0x01,
} E_DjiMopChannel_FileTransforStopSubCmd;
#pragma pack(1)
typedef struct {
bool isExist;
uint32_t fileLength;
char fileName[32];
uint8_t md5Buf[16];
} T_DjiMopChannel_FileInfo;
typedef struct {
char fileName[32];
} T_DjiMopChannel_DwonloadReq;
typedef struct {
uint8_t cmd;
uint8_t subcmd;
uint16_t seqNum;
uint32_t dataLen;
union dataType {
T_DjiMopChannel_FileInfo fileInfo;
T_DjiMopChannel_DwonloadReq dwonloadReq;
uint8_t fileData[0];
} data;
} T_DjiMopChannel_FileTransfor;
#pragma pack()
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_MopChannelStartService(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_MOP_CHANNEL_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,174 @@
/**
********************************************************************
* @file test_payload_collaboration.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_payload_camera.h>
#include "test_payload_collaboration.h"
#include "dji_aircraft_info.h"
#include "dji_typedef.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "utils/util_misc.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_TEST_PAYLOAD_COLLABORATION_TASK_FREQ (1)
#define DJI_TEST_PAYLOAD_COLLABORATION_TASK_STACK_SIZE (2048)
#define DJI_TEST_PAYLOAD_COLLABORATION_PAYLOADS_IN_DRONE_MAX_COUNT (3)
/* Private types -------------------------------------------------------------*/
typedef struct {
E_DjiCameraType cameraType;
bool hasOpticalZoomSpec;
bool hasHybridZoomFocalLength;
} T_DjiTestPayloadPara;
/* Private functions declaration ---------------------------------------------*/
static void *DjiTest_PayloadCollaborationTask(void *arg);
/* Private variables ---------------------------------------------------------*/
static T_DjiTaskHandle s_payloadCollaborationThread;
static const T_DjiTestPayloadPara s_payloadPara[] = {
{DJI_CAMERA_TYPE_Z30, true, true},
{DJI_CAMERA_TYPE_XT2, true, true},
{DJI_CAMERA_TYPE_XTS, false, false},
{DJI_CAMERA_TYPE_H20, true, true},
{DJI_CAMERA_TYPE_H20T, true, true},
};
static bool s_userPayloadCollaborationDataShow = false;
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_PayloadCollaborationStartService(void)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
if (osalHandler->TaskCreate("user_payload_collaboration_task", DjiTest_PayloadCollaborationTask,
DJI_TEST_PAYLOAD_COLLABORATION_TASK_STACK_SIZE,
NULL, &s_payloadCollaborationThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user payload collaboration task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_PayloadCollaborationDataShowTrigger(void)
{
s_userPayloadCollaborationDataShow = !s_userPayloadCollaborationDataShow;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_PayloadCollaborationTask(void *arg)
{
int i = 0;
unsigned int payloadParaIndex = 0;
T_DjiReturnCode djiStat;
E_DjiCameraType cameraType = DJI_CAMERA_TYPE_UNKNOWN;
uint16_t cameraHybridZoomFocalLength = 0;
T_DjiAircraftInfoBaseInfo aircraftBaseInfo = {0};
E_DjiMountPosition requestedPayloadMountPosition;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiCameraOpticalZoomSpec cameraOpticalZoomSpec = {0};
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->TaskSleepMs(1000 / DJI_TEST_PAYLOAD_COLLABORATION_TASK_FREQ);
djiStat = DjiAircraftInfo_GetBaseInfo(&aircraftBaseInfo);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get aircraft information error: 0x%08llX.", djiStat);
continue;
}
for (i = 0; i < DJI_TEST_PAYLOAD_COLLABORATION_PAYLOADS_IN_DRONE_MAX_COUNT; ++i) {
requestedPayloadMountPosition =
(E_DjiMountPosition) (i + DJI_MOUNT_POSITION_PAYLOAD_PORT_NO1);
if (requestedPayloadMountPosition == aircraftBaseInfo.mountPosition)
continue;
djiStat = DjiPayloadCamera_GetCameraTypeOfPayload(requestedPayloadMountPosition, &cameraType);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
continue;
}
if (s_userPayloadCollaborationDataShow == true) {
USER_LOG_INFO("camera type of payload mounted on NO.%d gimbal connector is %d.",
requestedPayloadMountPosition, cameraType);
}
for (payloadParaIndex = 0; payloadParaIndex < UTIL_ARRAY_SIZE(s_payloadPara); ++payloadParaIndex) {
if (s_payloadPara[payloadParaIndex].cameraType == cameraType)
break;
}
if (payloadParaIndex == UTIL_ARRAY_SIZE(s_payloadPara)) {
USER_LOG_ERROR("Not find payload parameters.");
continue;
}
if (s_payloadPara[payloadParaIndex].hasOpticalZoomSpec) {
djiStat = DjiPayloadCamera_GetCameraOpticalZoomSpecOfPayload(requestedPayloadMountPosition,
&cameraOpticalZoomSpec);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get optical zoom specification error.");
}
if (s_userPayloadCollaborationDataShow == true) {
USER_LOG_INFO(
"camera optical zoom specification of payload mounted on NO.%d gimbal connector, maxFocalLength: %d, minFocalLength: %d, focalLengthStep: %d.",
requestedPayloadMountPosition, cameraOpticalZoomSpec.maxFocalLength,
cameraOpticalZoomSpec.minFocalLength, cameraOpticalZoomSpec.focalLengthStep);
}
}
if (s_payloadPara[payloadParaIndex].hasHybridZoomFocalLength) {
djiStat = DjiPayloadCamera_GetCameraHybridZoomFocalLengthOfPayload(requestedPayloadMountPosition,
&cameraHybridZoomFocalLength);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get hybrid zoom focal length error.");
}
if (s_userPayloadCollaborationDataShow == true) {
USER_LOG_INFO(
"camera hybrid zoom focal length of payload mounted on NO.%d gimbal connector, focalLength: %d.\r\n",
requestedPayloadMountPosition, cameraHybridZoomFocalLength);
}
}
}
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,53 @@
/**
********************************************************************
* @file test_payload_collaboration.h
* @brief This is the header file for "test_payload_collaboration.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 TEST_PAYLOAD_COLLABORATION_H
#define TEST_PAYLOAD_COLLABORATION_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_PayloadCollaborationStartService(void);
T_DjiReturnCode DjiTest_PayloadCollaborationDataShowTrigger(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_PAYLOAD_COLLABORATION_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,210 @@
/**
********************************************************************
* @file test_perception.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 <utils/util_misc.h>
#include <widget_interaction_test/test_widget_interaction.h>
#include "test_perception.h"
#include "dji_logger.h"
#include "dji_platform.h"
/* Private constants ---------------------------------------------------------*/
#define TEST_PERCEPTION_SAVE_IMAGE_MAX_NUM 10
/* Private types -------------------------------------------------------------*/
typedef struct {
E_DjiPerceptionDirection direction;
char *name;
} T_DjiTestPerceptionDirectionName;
/* Private values -------------------------------------------------------------*/
static uint16_t s_perceptionImageCount = 0;
static const T_DjiTestPerceptionDirectionName directionName[] = {
{.direction = DJI_PERCEPTION_RECTIFY_DOWN, .name = "down"},
{.direction = DJI_PERCEPTION_RECTIFY_FRONT, .name = "front"},
{.direction = DJI_PERCEPTION_RECTIFY_REAR, .name = "rear"},
{.direction = DJI_PERCEPTION_RECTIFY_UP, .name = "up"},
{.direction = DJI_PERCEPTION_RECTIFY_LEFT, .name = "left"},
{.direction = DJI_PERCEPTION_RECTIFY_RIGHT, .name = "right"},
};
/* Private functions declaration ---------------------------------------------*/
static void DjiTest_PerceptionImageCallback(T_DjiPerceptionImageInfo imageInfo, uint8_t *imageRawBuffer,
uint32_t bufferLen);
static int32_t DjiTest_SaveImageData(char *filePath, const uint8_t *data, uint32_t len);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_PerceptionRunSample(E_DjiPerceptionDirection direction)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiPerceptionCameraParametersPacket cameraParametersetersPacket = {0};
USER_LOG_INFO("Perception sample start");
DjiTest_WidgetLogAppend("Perception sample start");
USER_LOG_INFO("--> Step 1: Init Perception module");
DjiTest_WidgetLogAppend("--> Step 1: Init Perception module");
returnCode = DjiPerception_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Perception init failed, error code: 0x%08X", returnCode);
goto out;
}
s_perceptionImageCount = 0;
USER_LOG_INFO("--> Step 2: Get stereo camera parameters\r\n");
DjiTest_WidgetLogAppend("--> Step 2: Get stereo camera parameters\r\n");
returnCode = DjiPerception_GetStereoCameraParameters(&cameraParametersetersPacket);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get stereo camera parameters failed, error code: 0x%08X", returnCode);
goto out;
}
if (cameraParametersetersPacket.directionNum <= IMAGE_MAX_DIRECTION_NUM)
for (int i = 0; i < cameraParametersetersPacket.directionNum; i++) {
USER_LOG_INFO(" [%-05s] leftIntrinsics = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
directionName[cameraParametersetersPacket.cameraParameters[i].direction].name,
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[0],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[1],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[2],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[3],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[4],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[5],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[6],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[7],
cameraParametersetersPacket.cameraParameters[i].leftIntrinsics[8]);
USER_LOG_INFO("[%-05s] rightIntrinsics = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
directionName[cameraParametersetersPacket.cameraParameters[i].direction].name,
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[0],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[1],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[2],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[3],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[4],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[5],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[6],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[7],
cameraParametersetersPacket.cameraParameters[i].rightIntrinsics[8]);
USER_LOG_INFO("[%-05s] rotationLeftInRight = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
directionName[cameraParametersetersPacket.cameraParameters[i].direction].name,
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[0],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[1],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[2],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[3],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[4],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[5],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[6],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[7],
cameraParametersetersPacket.cameraParameters[i].rotationLeftInRight[8]);
USER_LOG_INFO("[%-05s] translationLeftInRight = {%f, %f, %f }\r\n",
directionName[cameraParametersetersPacket.cameraParameters[i].direction].name,
cameraParametersetersPacket.cameraParameters[i].translationLeftInRight[0],
cameraParametersetersPacket.cameraParameters[i].translationLeftInRight[1],
cameraParametersetersPacket.cameraParameters[i].translationLeftInRight[2]);
osalHandler->TaskSleepMs(100);
}
USER_LOG_INFO("--> Step 3: Subscribe perception image\r\n");
DjiTest_WidgetLogAppend("--> Step 3: Subscribe perception image\r\n");
returnCode = DjiPerception_SubscribePerceptionImage(direction, DjiTest_PerceptionImageCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe perception image failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(5000);
USER_LOG_INFO("--> Step 4: Unsubscribe perception image");
DjiTest_WidgetLogAppend("--> Step 4: Unsubscribe perception image");
returnCode = DjiPerception_UnsubscribePerceptionImage(direction);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Unsubscribe perception image failed, error code: 0x%08X", returnCode);
goto out;
}
USER_LOG_INFO("--> Step 5: Deinit Perception module");
DjiTest_WidgetLogAppend("--> Step 5: Deinit Perception module");
returnCode = DjiPerception_Deinit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Perception deinit failed, error code: 0x%08X", returnCode);
goto out;
}
out:
USER_LOG_INFO("Perception sample end");
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static int32_t DjiTest_SaveImageData(char *filePath, const uint8_t *data, uint32_t len)
{
FILE *fp = NULL;
size_t size;
fp = fopen(filePath, "w+");
if (fp == NULL) {
return -1;
}
size = fwrite(data, 1, len, fp);
if (size != len) {
if (fp) {
fclose(fp);
}
return -1;
}
if (fp) {
fclose(fp);
}
return 0;
}
static void DjiTest_PerceptionImageCallback(T_DjiPerceptionImageInfo imageInfo, uint8_t *imageRawBuffer,
uint32_t bufferLen)
{
char fileName[256] = {0};
snprintf(fileName, sizeof(fileName), "./image_%s_%d.raw",
directionName[imageInfo.rawInfo.direction].name,
s_perceptionImageCount);
if (s_perceptionImageCount < TEST_PERCEPTION_SAVE_IMAGE_MAX_NUM) {
DjiTest_SaveImageData(fileName, imageRawBuffer, bufferLen);
USER_LOG_INFO(
"Save perception image to path: ${binary_execute_path}/image_%s_%d.raw, direction:%s, position:%d, size:%dx%d",
directionName[imageInfo.rawInfo.direction].name,
s_perceptionImageCount,
directionName[imageInfo.rawInfo.direction].name,
imageInfo.dataType,
imageInfo.rawInfo.width,
imageInfo.rawInfo.height);
s_perceptionImageCount++;
}
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,50 @@
/**
********************************************************************
* @file test_perception.h
* @brief This is the header file for "test_perception.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 TEST_PERCEPTION_H
#define TEST_PERCEPTION_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_perception.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_PerceptionRunSample(E_DjiPerceptionDirection direction);
#ifdef __cplusplus
}
#endif
#endif // TEST_PERCEPTION_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,248 @@
/**
********************************************************************
* @file test_positioning.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 <fc_subscription/test_fc_subscription.h>
#include "test_positioning.h"
#include "dji_positioning.h"
#include "dji_logger.h"
#include "utils/util_misc.h"
#include "dji_platform.h"
#include "time_sync/test_time_sync.h"
#ifdef SYSTEM_ARCH_LINUX
#include "time.h"
#endif
/* Private constants ---------------------------------------------------------*/
#define POSITIONING_TASK_FREQ (1)
#define POSITIONING_TASK_STACK_SIZE (2048)
#define TEST_RTCM_FILE_PATH_STR_MAX_SIZE (64)
#define DJI_TEST_POSITIONING_EVENT_COUNT (2)
#define DJI_TEST_TIME_INTERVAL_AMONG_EVENTS_US (200000)
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void *DjiTest_PositioningTask(void *arg);
static T_DjiReturnCode DjiTest_ReceiveRtkOnAircraftRtcmDataCallback(uint8_t index, const uint8_t *data,
uint16_t dataLen);
static T_DjiReturnCode DjiTest_ReceiveRtkBaseStationRtcmDataCallback(uint8_t index, const uint8_t *data,
uint16_t dataLen);
/* Private variables ---------------------------------------------------------*/
static T_DjiTaskHandle s_userPositioningThread;
static int32_t s_eventIndex = 0;
static char s_rtkOnAircraftRtcmFilePath[TEST_RTCM_FILE_PATH_STR_MAX_SIZE];
static char s_rtkBaseStationRtcmFilePath[TEST_RTCM_FILE_PATH_STR_MAX_SIZE];
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_PositioningStartService(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
djiStat = DjiPositioning_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("positioning module init error.");
return djiStat;
}
DjiPositioning_SetTaskIndex(0);
#ifndef SYSTEM_ARCH_LINUX
if (osalHandler->TaskCreate("user_positioning_task", DjiTest_PositioningTask,
POSITIONING_TASK_STACK_SIZE, NULL, &s_userPositioningThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user positioning task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
#else
time_t currentTime = time(NULL);
struct tm *localTime = NULL;
localTime = localtime(&currentTime);
sprintf(s_rtkOnAircraftRtcmFilePath, "rtk_on_aircraft_%04d%02d%02d_%02d-%02d-%02d.rtcm",
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
localTime = localtime(&currentTime);
sprintf(s_rtkBaseStationRtcmFilePath, "rtk_base_station_%04d%02d%02d_%02d-%02d-%02d.rtcm",
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
#endif
djiStat = DjiPositioning_RegReceiveRtcmDataCallback(DJI_POSITIONING_RTCM_DATA_TYPE_RTK_BASE_STATION,
DjiTest_ReceiveRtkBaseStationRtcmDataCallback);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register receive rtk base station callback error.");
return djiStat;
}
djiStat = DjiPositioning_RegReceiveRtcmDataCallback(DJI_POSITIONING_RTCM_DATA_TYPE_RTK_ON_AIRCRAFT,
DjiTest_ReceiveRtkOnAircraftRtcmDataCallback);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register receive rtk on aircraft callback error.");
return djiStat;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_PositioningTask(void *arg)
{
int32_t i = 0;
T_DjiReturnCode djiStat;
uint64_t ppsNewestTriggerTimeUs = 0;
T_DjiPositioningEventInfo eventInfo[DJI_TEST_POSITIONING_EVENT_COUNT] = {0};
T_DjiPositioningPositionInfo positionInfo[DJI_TEST_POSITIONING_EVENT_COUNT] = {0};
T_DjiTimeSyncAircraftTime aircraftTime = {0};
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
uint8_t totalSatelliteNumber = 0;
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->TaskSleepMs(1000 / POSITIONING_TASK_FREQ);
djiStat = DjiTest_FcSubscriptionGetTotalSatelliteNumber(&totalSatelliteNumber);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get total satellite number error: 0x%08llX.", djiStat);
continue;
}
djiStat = DjiTest_TimeSyncGetNewestPpsTriggerLocalTimeUs(&ppsNewestTriggerTimeUs);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get newest pps trigger time error: 0x%08llX.", djiStat);
continue;
}
for (i = 0; i < DJI_TEST_POSITIONING_EVENT_COUNT; ++i) {
eventInfo[i].eventSetIndex = s_eventIndex;
eventInfo[i].targetPointIndex = i;
djiStat = DjiTimeSync_TransferToAircraftTime(
ppsNewestTriggerTimeUs - 1000000 - i * DJI_TEST_TIME_INTERVAL_AMONG_EVENTS_US, &aircraftTime);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("transfer to aircraft time error: 0x%08llX.", djiStat);
continue;
}
eventInfo[i].eventTime = aircraftTime;
}
djiStat = DjiPositioning_GetPositionInformationSync(DJI_TEST_POSITIONING_EVENT_COUNT, eventInfo, positionInfo);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get position information error.");
continue;
}
USER_LOG_DEBUG("request position of target points success.");
USER_LOG_DEBUG("detail position information:");
for (i = 0; i < DJI_TEST_POSITIONING_EVENT_COUNT; ++i) {
USER_LOG_DEBUG("position solution property: %d.", positionInfo[i].positionSolutionProperty);
USER_LOG_DEBUG("pitchAttitudeAngle: %d\trollAttitudeAngle: %d\tyawAttitudeAngle: %d",
positionInfo[i].uavAttitude.pitch, positionInfo[i].uavAttitude.roll,
positionInfo[i].uavAttitude.yaw);
USER_LOG_DEBUG("northPositionOffset: %d\tearthPositionOffset: %d\tdownPositionOffset: %d",
positionInfo[i].offsetBetweenMainAntennaAndTargetPoint.x,
positionInfo[i].offsetBetweenMainAntennaAndTargetPoint.y,
positionInfo[i].offsetBetweenMainAntennaAndTargetPoint.z);
USER_LOG_DEBUG("longitude: %.8f\tlatitude: %.8f\theight: %.8f",
positionInfo[i].targetPointPosition.longitude,
positionInfo[i].targetPointPosition.latitude,
positionInfo[i].targetPointPosition.height);
USER_LOG_DEBUG(
"longStandardDeviation: %.8f\tlatStandardDeviation: %.8f\thgtStandardDeviation: %.8f",
positionInfo[i].targetPointPositionStandardDeviation.longitude,
positionInfo[i].targetPointPositionStandardDeviation.latitude,
positionInfo[i].targetPointPositionStandardDeviation.height);
}
s_eventIndex++;
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
static int32_t DjiTest_SaveRtcmData(char *filePath, const uint8_t *data, uint32_t len)
{
#ifdef SYSTEM_ARCH_LINUX
FILE *fp = NULL;
size_t size;
fp = fopen(filePath, "ab+");
if (fp == NULL) {
printf("fopen failed!\n");
return -1;
}
size = fwrite(data, 1, len, fp);
if (size != len) {
fclose(fp);
return -1;
}
fflush(fp);
fclose(fp);
#endif
return 0;
}
static T_DjiReturnCode DjiTest_ReceiveRtkOnAircraftRtcmDataCallback(uint8_t index, const uint8_t *data,
uint16_t dataLen)
{
USER_LOG_INFO("Receive rtcm data from rtk on aircraft, index: %d, len: %d", index, dataLen);
#ifdef SYSTEM_ARCH_LINUX
DjiTest_SaveRtcmData(s_rtkOnAircraftRtcmFilePath, data, dataLen);
#endif
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_ReceiveRtkBaseStationRtcmDataCallback(uint8_t index, const uint8_t *data,
uint16_t dataLen)
{
USER_LOG_INFO("Receive rtcm data from rtk base station, index: %d, len: %d", index, dataLen);
#ifdef SYSTEM_ARCH_LINUX
DjiTest_SaveRtcmData(s_rtkBaseStationRtcmFilePath, data, dataLen);
#endif
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,52 @@
/**
********************************************************************
* @file test_positioning.h
* @brief This is the header file for "test_positioning.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 TEST_POSITIONING_H
#define TEST_POSITIONING_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_PositioningStartService(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_POSITIONING_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,156 @@
/**
********************************************************************
* @file test_power_management.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 "test_power_management.h"
#include "dji_logger.h"
#include "dji_aircraft_info.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag);
/* Private variables ---------------------------------------------------------*/
static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler;
/* Exported functions definition ---------------------------------------------*/
/**
* @brief Register handler function for applying high power. This function have to be called before calling
* DjiTest_PowerManagementInit(), except for in Linux, because DjiTest_PowerManagementInit() do not apply high power
* in Linux OS.
* @param applyHighPowerHandler: pointer to handler function for applying high power.
* @return Execution result.
*/
T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler)
{
if (applyHighPowerHandler->pinInit == NULL) {
USER_LOG_ERROR("reg apply high power handler pinInit error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (applyHighPowerHandler->pinWrite == NULL) {
USER_LOG_ERROR("reg apply high power handler pinWrite error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
memcpy(&s_applyHighPowerHandler, applyHighPowerHandler, sizeof(T_DjiTestApplyHighPowerHandler));
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/**
* @brief Initialise power management module, including apply high power (only RTOS) and register power off notification
* callback function.
* @note DJI development board 1.0 can not accept high power, so do not call this function in DJI development board
* 1.0 project.
* @return Execution result.
*/
T_DjiReturnCode DjiTest_PowerManagementStartService(void)
{
T_DjiReturnCode returnCode;
T_DjiAircraftInfoBaseInfo baseInfo = {0};
returnCode = DjiPowerManagement_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("power management init error: 0x%08llX.", returnCode);
return returnCode;
}
returnCode = DjiAircraftInfo_GetBaseInfo(&baseInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get aircraft base info error: 0x%08llX.", returnCode);
return returnCode;
}
if (((baseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M300_RTK || baseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M350_RTK) &&
(baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V2 || baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT)) ||
baseInfo.aircraftType == DJI_AIRCRAFT_TYPE_FC30) {
// apply high power
if (s_applyHighPowerHandler.pinInit == NULL) {
USER_LOG_ERROR("apply high power pin init interface is NULL error");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (s_applyHighPowerHandler.pinWrite == NULL) {
USER_LOG_ERROR("apply high power pin write interface is NULL error");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = s_applyHighPowerHandler.pinInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("apply high power pin init error");
return returnCode;
}
returnCode = DjiPowerManagement_RegWriteHighPowerApplyPinCallback(s_applyHighPowerHandler.pinWrite);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register WriteHighPowerApplyPinCallback error.");
return returnCode;
}
returnCode = DjiPowerManagement_ApplyHighPowerSync();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("apply high power error");
return returnCode;
}
}
// register power off notification callback function
returnCode = DjiPowerManagement_RegPowerOffNotificationCallback(DjiTest_PowerOffNotificationCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register power off notification callback function error");
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_PowerManagementStopService(void)
{
T_DjiReturnCode returnCode;
returnCode = DjiPowerManagement_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("power management deinit error: 0x%08llX.", returnCode);
return returnCode;
}
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag)
{
USER_LOG_INFO("aircraft will power off soon.");
*powerOffPreparationFlag = true;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,58 @@
/**
********************************************************************
* @file test_power_management.h
* @brief This is the header file for "test_power_management.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 TEST_POWER_MANAGEMENT_H
#define TEST_POWER_MANAGEMENT_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#include "dji_power_management.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
T_DjiReturnCode (*pinInit)(void);
T_DjiReturnCode (*pinWrite)(E_DjiPowerManagementPinState pinState);
} T_DjiTestApplyHighPowerHandler;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_PowerManagementStartService(void);
T_DjiReturnCode DjiTest_PowerManagementStopService(void);
T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler);
#ifdef __cplusplus
}
#endif
#endif // TEST_POWER_MANAGEMENT_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,173 @@
/**
********************************************************************
* @file test_time_sync.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 <fc_subscription/test_fc_subscription.h>
#include "test_time_sync.h"
#include "dji_time_sync.h"
#include "dji_logger.h"
#include "utils/util_misc.h"
#include "dji_platform.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_TEST_TIME_SYNC_TASK_FREQ (1)
#define DJI_TEST_TIME_SYNC_TASK_STACK_SIZE (1024)
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void *DjiTest_TimeSyncTask(void *arg);
/* Private variables ---------------------------------------------------------*/
static T_DjiTestTimeSyncHandler s_timeSyncHandler;
static T_DjiTaskHandle s_timeSyncThread;
/* Exported functions definition ---------------------------------------------*/
/**
* @brief Register handler function for initialising PPS pin configure and reporting the latest local time when PPS is
* triggered. This function have to be called before calling DjiTest_TimeSyncInit().
* @param timeSyncHandler: pointer to handler function for time synchronization.
* @return Execution result.
*/
T_DjiReturnCode DjiTest_TimeSyncRegHandler(T_DjiTestTimeSyncHandler *timeSyncHandler)
{
if (timeSyncHandler->PpsSignalResponseInit == NULL) {
USER_LOG_ERROR("reg time sync handler PpsSignalResponseInit error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (timeSyncHandler->GetNewestPpsTriggerLocalTimeUs == NULL) {
USER_LOG_ERROR("reg time sync handler GetNewestPpsTriggerLocalTimeUs error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
memcpy(&s_timeSyncHandler, timeSyncHandler, sizeof(T_DjiTestTimeSyncHandler));
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_TimeSyncStartService(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
djiStat = DjiTimeSync_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("time synchronization module init error.");
return djiStat;
}
if (s_timeSyncHandler.PpsSignalResponseInit == NULL) {
USER_LOG_ERROR("time sync handler PpsSignalResponseInit interface is NULL error");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (s_timeSyncHandler.GetNewestPpsTriggerLocalTimeUs == NULL) {
USER_LOG_ERROR("time sync handler GetNewestPpsTriggerLocalTimeUs interface is NULL error");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
// users must register getNewestPpsTriggerTime callback function
djiStat = DjiTimeSync_RegGetNewestPpsTriggerTimeCallback(s_timeSyncHandler.GetNewestPpsTriggerLocalTimeUs);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("register GetNewestPpsTriggerLocalTimeUsCallback error.");
return djiStat;
}
if (osalHandler->TaskCreate("user_time_sync_task", DjiTest_TimeSyncTask,
DJI_TEST_TIME_SYNC_TASK_STACK_SIZE, NULL, &s_timeSyncThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("user time sync task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
djiStat = s_timeSyncHandler.PpsSignalResponseInit();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("pps signal response init error");
return djiStat;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_TimeSyncGetNewestPpsTriggerLocalTimeUs(uint64_t *localTimeUs)
{
if (s_timeSyncHandler.GetNewestPpsTriggerLocalTimeUs == NULL) {
USER_LOG_ERROR("GetNewestPpsTriggerLocalTimeUs null error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return s_timeSyncHandler.GetNewestPpsTriggerLocalTimeUs(localTimeUs);
}
/* Private functions definition-----------------------------------------------*/
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_TimeSyncTask(void *arg)
{
T_DjiReturnCode djiStat;
uint32_t currentTimeMs = 0;
T_DjiTimeSyncAircraftTime aircraftTime = {0};
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
uint8_t totalSatelliteNumber = 0;
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->TaskSleepMs(1000 / DJI_TEST_TIME_SYNC_TASK_FREQ);
djiStat = DjiTest_FcSubscriptionGetTotalSatelliteNumber(&totalSatelliteNumber);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get total satellite number error: 0x%08llX.", djiStat);
continue;
}
djiStat = osalHandler->GetTimeMs(&currentTimeMs);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get current time error: 0x%08llX.", djiStat);
continue;
}
djiStat = DjiTimeSync_TransferToAircraftTime(currentTimeMs * 1000, &aircraftTime);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("transfer to aircraft time error: 0x%08llX.", djiStat);
continue;
}
USER_LOG_DEBUG("current aircraft time is %04d-%02d-%02d %02d:%02d:%02d %d.",
aircraftTime.year, aircraftTime.month, aircraftTime.day,
aircraftTime.hour, aircraftTime.minute, aircraftTime.second, aircraftTime.microsecond);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,57 @@
/**
********************************************************************
* @file test_time_sync.h
* @brief This is the header file for "test_time_sync.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 TEST_TIME_SYNC_H
#define TEST_TIME_SYNC_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
T_DjiReturnCode (*PpsSignalResponseInit)(void);
T_DjiReturnCode (*GetNewestPpsTriggerLocalTimeUs)(uint64_t *localTimeUs);
} T_DjiTestTimeSyncHandler;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_TimeSyncStartService(void);
T_DjiReturnCode DjiTest_TimeSyncGetNewestPpsTriggerLocalTimeUs(uint64_t *localTimeUs);
T_DjiReturnCode DjiTest_TimeSyncRegHandler(T_DjiTestTimeSyncHandler *timeSyncHandler);
#ifdef __cplusplus
}
#endif
#endif // TEST_TIME_SYNC_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,342 @@
/**
********************************************************************
* @file test_upgrade.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 <dji_platform.h>
#include <utils/util_misc.h>
#include "test_upgrade_common_file_transfer.h"
#include "test_upgrade_platform_opt.h"
#include "test_upgrade.h"
/* Private constants ---------------------------------------------------------*/
#define UPGRADE_TASK_STACK_SIZE (2048)
#define DJI_TEST_UPGRADE_TASK_FREQ (50)
#define DJI_TEST_ENTER_UPGRADE_WAIT_TIME (10) //wait 10s for enter upgrade process
#define DJI_TEST_UPGRADE_REBOOT_TIMEOUT (30) //reboot timeout 30s
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiUpgradeState s_upgradeState = {0};
static T_DjiMutexHandle s_upgradeStateMutex = {0};
static T_DjiTaskHandle s_upgradeProcessThread;
static T_DjiTaskHandle s_enterUpgradeModeProcessThread;
static bool s_isNeedEnterUpgradeModeProcess = false;
static bool s_isNeedReplaceProgramBeforeReboot = false;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTest_EnterUpgradeMode(uint16_t *waitTime);
static T_DjiReturnCode DjiTest_CheckFirmware(void);
static T_DjiReturnCode DjiTest_StartUpgrade(void);
static T_DjiReturnCode DjiTest_FinishUpgrade(void);
static void *DjiTest_UpgradeProcessTask(void *arg);
static void *DjiTest_EnterUpgradeModeProcessTask(void *arg);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode
DjiTest_UpgradeStartService(const T_DjiTestUpgradePlatformOpt *upgradePlatformOpt,
T_DjiTestUpgradeConfig testUpgradeConfig)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiReturnCode returnCode;
bool isUpgradeReboot = false;
T_DjiUpgradeEndInfo upgradeEndInfo = {0};
T_DjiUpgradeConfig upgradeConfig = {
.currentFirmwareVersion = testUpgradeConfig.firmwareVersion,
.firmwareTransferInfo = {
.transferType = testUpgradeConfig.transferType,
.ftpTransferInfo.port = 21,
.dcftpFileTransferOpt = {
.start = DjiTestCommonFileTransfer_Start,
.transfer = DjiTestCommonFileTransfer_Transfer,
.finish = DjiTestCommonFileTransfer_Finish,
}
}
};
s_isNeedReplaceProgramBeforeReboot = testUpgradeConfig.needReplaceProgramBeforeReboot;
T_DjiUpgradeHandler s_upgradeHandler = {
.EnterUpgradeMode = DjiTest_EnterUpgradeMode,
.CheckFirmware = DjiTest_CheckFirmware,
.StartUpgrade = DjiTest_StartUpgrade,
.FinishUpgrade = DjiTest_FinishUpgrade
};
returnCode = DjiTest_RegUpgradePlatformOpt(upgradePlatformOpt);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Reg upgrade platform opt error, return code = 0x%08llX", returnCode);
return returnCode;
}
returnCode = osalHandler->MutexCreate(&s_upgradeStateMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Create mutex error");
return returnCode;
}
returnCode = DjiTest_GetUpgradeRebootState(&isUpgradeReboot, &upgradeEndInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get upgrade reboot state error");
isUpgradeReboot = false;
}
returnCode = DjiTest_CleanUpgradeRebootState();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Clean upgrade reboot state error");
}
osalHandler->MutexLock(s_upgradeStateMutex);
if (isUpgradeReboot == true) {
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo = upgradeEndInfo;
} else {
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_IDLE;
}
osalHandler->MutexUnlock(s_upgradeStateMutex);
returnCode = DjiUpgrade_Init(&upgradeConfig);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("DjiUpgrade_Init error, return code = %d", returnCode);
return returnCode;
}
returnCode = DjiUpgrade_RegHandler(&s_upgradeHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("DjiUpgrade_RegHandler error, return code = %d", returnCode);
return returnCode;
}
returnCode = DjiUpgrade_EnableLocalUpgrade();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("DjiUpgrade_EnableLocalUpgrade error, return code = %d", returnCode);
return returnCode;
}
if (osalHandler->TaskCreate("upgrade_task", DjiTest_UpgradeProcessTask, UPGRADE_TASK_STACK_SIZE, NULL,
&s_upgradeProcessThread) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Dji upgrade test task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (osalHandler->TaskCreate("enter_upgrade_mode_task", DjiTest_EnterUpgradeModeProcessTask, UPGRADE_TASK_STACK_SIZE,
NULL, &s_enterUpgradeModeProcessThread) !=
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Dji upgrade test task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTest_EnterUpgradeMode(uint16_t *waitTime)
{
// need 10s for upgrade preprocess work.
*waitTime = DJI_TEST_ENTER_UPGRADE_WAIT_TIME;
// enable is need enter upgrade mode process, the process is in DjiTest_EnterUpgradeModeProcessTask
s_isNeedEnterUpgradeModeProcess = true;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_CheckFirmware(void)
{
// you can do decrypt and check firmware in this stage
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_StartUpgrade(void)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 0;
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_ONGOING;
osalHandler->MutexUnlock(s_upgradeStateMutex);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_FinishUpgrade(void)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_IDLE;
osalHandler->MutexUnlock(s_upgradeStateMutex);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_EnterUpgradeModeProcessTask(void *arg)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiReturnCode returnCode;
USER_UTIL_UNUSED(arg);
while (1) {
if (s_isNeedEnterUpgradeModeProcess) {
// prepare enter upgrade mode
// you can do some thing before enter upgrade mode.
// clear upgrade program file store area
returnCode = DjiTest_CleanUpgradeProgramFileStoreArea();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Clean upgrade file dir error, please check dir permission");
}
s_isNeedEnterUpgradeModeProcess = false;
USER_LOG_INFO("Clean upgrade store area");
}
osalHandler->TaskSleepMs(1000 / DJI_TEST_UPGRADE_TASK_FREQ);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_UpgradeProcessTask(void *arg)
{
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiUpgradeState tempUpgradeState;
T_DjiUpgradeEndInfo upgradeEndInfo;
T_DjiReturnCode returnCode;
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->MutexLock(s_upgradeStateMutex);
tempUpgradeState = s_upgradeState;
osalHandler->MutexUnlock(s_upgradeStateMutex);
if (tempUpgradeState.upgradeStage == DJI_UPGRADE_STAGE_ONGOING) {
if (s_isNeedReplaceProgramBeforeReboot) {
// Step 1 : Replace old program
returnCode = DjiTest_ReplaceOldProgram();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Replace firmware error, return code = 0x%08llX", returnCode);
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = DJI_UPGRADE_END_STATE_UNKNOWN_ERROR;
osalHandler->MutexUnlock(s_upgradeStateMutex);
continue;
}
osalHandler->TaskSleepMs(1000);
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 20;
DjiUpgrade_PushUpgradeState(&s_upgradeState);
osalHandler->MutexUnlock(s_upgradeStateMutex);
// Step 2 : Clean upgrade program file store area
returnCode = DjiTest_CleanUpgradeProgramFileStoreArea();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Clean upgrade file dir error, please check dir permission");
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = DJI_UPGRADE_END_STATE_UNKNOWN_ERROR;
osalHandler->MutexUnlock(s_upgradeStateMutex);
continue;
}
osalHandler->TaskSleepMs(1000);
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 30;
DjiUpgrade_PushUpgradeState(&s_upgradeState);
osalHandler->MutexUnlock(s_upgradeStateMutex);
}
//attention emulation upgrade progress, user don't need this process
do {
osalHandler->TaskSleepMs(1000);
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress += 10;
tempUpgradeState = s_upgradeState;
DjiUpgrade_PushUpgradeState(&s_upgradeState);
osalHandler->MutexUnlock(s_upgradeStateMutex);
} while (tempUpgradeState.upgradeOngoingInfo.upgradeProgress < 100);
// Step 3 : Reboot device
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_DEVICE_REBOOT;
s_upgradeState.upgradeRebootInfo.rebootTimeout = DJI_TEST_UPGRADE_REBOOT_TIMEOUT;
DjiUpgrade_PushUpgradeState(&s_upgradeState);
osalHandler->MutexUnlock(s_upgradeStateMutex);
osalHandler->TaskSleepMs(1000); // sleep 1000ms to ensure push send terminal.
upgradeEndInfo.upgradeEndState = DJI_UPGRADE_END_STATE_SUCCESS;
returnCode = DjiTest_SetUpgradeRebootState(&upgradeEndInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set Upgrade reboot state error");
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = DJI_UPGRADE_END_STATE_UNKNOWN_ERROR;
osalHandler->MutexUnlock(s_upgradeStateMutex);
continue;
}
returnCode = DjiTest_RebootSystem();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Reboot system error");
osalHandler->MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = DJI_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = DJI_UPGRADE_END_STATE_UNKNOWN_ERROR;
osalHandler->MutexUnlock(s_upgradeStateMutex);
continue;
}
while (1) {
osalHandler->TaskSleepMs(500);
}
} else if (s_upgradeState.upgradeStage == DJI_UPGRADE_STAGE_END) {
osalHandler->MutexLock(s_upgradeStateMutex);
DjiUpgrade_PushUpgradeState(&s_upgradeState);
osalHandler->MutexUnlock(s_upgradeStateMutex);
}
osalHandler->TaskSleepMs(500);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,58 @@
/**
********************************************************************
* @file test_upgrade.h
* @brief This is the header file for "test_upgrade.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 TEST_UPGRADE_H
#define TEST_UPGRADE_H
/* Includes ------------------------------------------------------------------*/
#include <dji_upgrade.h>
#include "test_upgrade_platform_opt.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
T_DjiFirmwareVersion firmwareVersion;
E_DjiFirmwareTransferType transferType;
//For linux: need replace program before reboot system
//For mcu: don't need replace program before reboot system, replace program in loader
bool needReplaceProgramBeforeReboot;
} T_DjiTestUpgradeConfig;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_UpgradeStartService(const T_DjiTestUpgradePlatformOpt *upgradePlatformOpt,
T_DjiTestUpgradeConfig testUpgradeConfig);
#ifdef __cplusplus
}
#endif
#endif
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,149 @@
/**
********************************************************************
* @file test_upgrade_common_file_transfer.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 "test_upgrade_common_file_transfer.h"
#include "dji_logger.h"
#include <utils/util_md5.h>
#include "test_upgrade_platform_opt.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_TEST_FILE_MD5_BUFFER_SIZE 256
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiUpgradeFileInfo s_upgradeFileInfo = {0};
static uint32_t s_alreadyTransferFileSize = 0;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTestFile_GetUpgradeFileMd5(uint8_t md5[DJI_MD5_BUFFER_LEN]);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTestCommonFileTransfer_Start(const T_DjiUpgradeFileInfo *fileInfo)
{
T_DjiReturnCode returnCode;
s_upgradeFileInfo.fileSize = 0;
memset(s_upgradeFileInfo.fileName, 0, sizeof(s_upgradeFileInfo.fileName));
s_alreadyTransferFileSize = 0;
returnCode = DjiTest_CreateUpgradeProgramFile(fileInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Create upgrade program file error");
return returnCode;
}
s_upgradeFileInfo = *fileInfo;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTestCommonFileTransfer_Transfer(const uint8_t *data, uint16_t dataLen)
{
T_DjiReturnCode returnCode;
if (s_alreadyTransferFileSize >= s_upgradeFileInfo.fileSize) {
USER_LOG_ERROR("Already transfer file size is more than file real size");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
returnCode = DjiTest_WriteUpgradeProgramFile(s_alreadyTransferFileSize, data, dataLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Write upgrade program file error, return code = 0x%08llX", returnCode);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
s_alreadyTransferFileSize += dataLen;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTestCommonFileTransfer_Finish(const uint8_t md5[DJI_MD5_BUFFER_LEN])
{
uint8_t localFileMd5[DJI_MD5_BUFFER_LEN] = {0};
T_DjiReturnCode returnCode;
if (s_alreadyTransferFileSize != s_upgradeFileInfo.fileSize) {
USER_LOG_ERROR("Transfer finish error, transfer file size is not equal");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
returnCode = DjiTestFile_GetUpgradeFileMd5(localFileMd5);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file md5 error, return code = 0x%08llX", returnCode);
goto out;
}
if (memcmp(md5, localFileMd5, DJI_MD5_BUFFER_LEN) == 0) {
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
out:
DjiTest_CloseUpgradeProgramFile();
s_upgradeFileInfo.fileSize = 0;
memset(s_upgradeFileInfo.fileName, 0, sizeof(s_upgradeFileInfo.fileName));
s_alreadyTransferFileSize = 0;
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTestFile_GetUpgradeFileMd5(uint8_t md5[DJI_MD5_BUFFER_LEN])
{
uint8_t fileBuffer[DJI_TEST_FILE_MD5_BUFFER_SIZE] = {0};
T_DjiReturnCode returnCode;
uint32_t offset;
MD5_CTX fileMd5Ctx;
uint16_t realLen = 0;
offset = 0;
UtilMd5_Init(&fileMd5Ctx);
while (s_upgradeFileInfo.fileSize - offset > DJI_TEST_FILE_MD5_BUFFER_SIZE) {
returnCode = DjiTest_ReadUpgradeProgramFile(offset, DJI_TEST_FILE_MD5_BUFFER_SIZE,
fileBuffer, &realLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS || realLen != DJI_TEST_FILE_MD5_BUFFER_SIZE) {
USER_LOG_ERROR("Get file data error, return code = 0x%08llX", returnCode);
return returnCode;
}
UtilMd5_Update(&fileMd5Ctx, fileBuffer, DJI_TEST_FILE_MD5_BUFFER_SIZE);
offset += DJI_TEST_FILE_MD5_BUFFER_SIZE;
}
returnCode = DjiTest_ReadUpgradeProgramFile(offset, s_upgradeFileInfo.fileSize - offset, fileBuffer, &realLen);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS || realLen != s_upgradeFileInfo.fileSize - offset) {
USER_LOG_ERROR("Get file data error, return code = 0x%08llX", returnCode);
return returnCode;
}
UtilMd5_Update(&fileMd5Ctx, fileBuffer, s_upgradeFileInfo.fileSize - offset);
UtilMd5_Final(&fileMd5Ctx, md5);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,51 @@
/**
********************************************************************
* @file test_upgrade_common_file_transfer.h
* @brief This is the header file for "test_upgrade_common_file_transfer.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 TEST_UPGRADE_COMMON_FILE_TRANSFER_H
#define TEST_UPGRADE_COMMON_FILE_TRANSFER_H
/* Includes ------------------------------------------------------------------*/
#include <dji_upgrade.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTestCommonFileTransfer_Start(const T_DjiUpgradeFileInfo *fileInfo);
T_DjiReturnCode DjiTestCommonFileTransfer_Transfer(const uint8_t *data, uint16_t dataLen);
T_DjiReturnCode DjiTestCommonFileTransfer_Finish(const uint8_t md5[DJI_MD5_BUFFER_LEN]);
#ifdef __cplusplus
}
#endif
#endif // TEST_UPGRADE_COMMON_FILE_TRANSFER_LINUX_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,139 @@
/**
********************************************************************
* @file test_upgrade_platform_opt.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 "test_upgrade_platform_opt.h"
#include <dji_logger.h>
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiTestUpgradePlatformOpt s_upgradePlatformOpt = {0};
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_RegUpgradePlatformOpt(const T_DjiTestUpgradePlatformOpt *upgradePlatformOpt)
{
if (upgradePlatformOpt->rebootSystem == NULL) {
USER_LOG_ERROR("rebootSystem callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->cleanUpgradeProgramFileStoreArea == NULL) {
USER_LOG_ERROR("cleanUpgradeProgramFileStoreArea callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->createUpgradeProgramFile == NULL) {
USER_LOG_ERROR("createUpgradeProgramFile callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->readUpgradeProgramFile == NULL) {
USER_LOG_ERROR("readUpgradeProgramFile callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->writeUpgradeProgramFile == NULL) {
USER_LOG_ERROR("writeUpgradeProgramFile callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->closeUpgradeProgramFile == NULL) {
USER_LOG_ERROR("closeUpgradeProgramFile callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->replaceOldProgram == NULL) {
USER_LOG_ERROR("replaceOldProgram callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->setUpgradeRebootState == NULL) {
USER_LOG_ERROR("setUpgradeRebootState callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->getUpgradeRebootState == NULL) {
USER_LOG_ERROR("getUpgradeRebootState callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->cleanUpgradeRebootState == NULL) {
USER_LOG_ERROR("cleanUpgradeRebootState callback can't be NULL");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
s_upgradePlatformOpt = *upgradePlatformOpt;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_RebootSystem(void)
{
return s_upgradePlatformOpt.rebootSystem();
}
T_DjiReturnCode DjiTest_CleanUpgradeProgramFileStoreArea(void)
{
return s_upgradePlatformOpt.cleanUpgradeProgramFileStoreArea();
}
T_DjiReturnCode DjiTest_CreateUpgradeProgramFile(const T_DjiUpgradeFileInfo *fileInfo)
{
return s_upgradePlatformOpt.createUpgradeProgramFile(fileInfo);
}
T_DjiReturnCode DjiTest_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data, uint16_t dataLen)
{
return s_upgradePlatformOpt.writeUpgradeProgramFile(offset, data, dataLen);
}
T_DjiReturnCode DjiTest_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen)
{
return s_upgradePlatformOpt.readUpgradeProgramFile(offset, readDataLen, data, realLen);
}
T_DjiReturnCode DjiTest_CloseUpgradeProgramFile(void)
{
return s_upgradePlatformOpt.closeUpgradeProgramFile();
}
T_DjiReturnCode DjiTest_ReplaceOldProgram(void)
{
return s_upgradePlatformOpt.replaceOldProgram();
}
T_DjiReturnCode DjiTest_SetUpgradeRebootState(const T_DjiUpgradeEndInfo *upgradeEndInfo)
{
return s_upgradePlatformOpt.setUpgradeRebootState(upgradeEndInfo);
}
T_DjiReturnCode DjiTest_GetUpgradeRebootState(bool *isUpgradeReboot, T_DjiUpgradeEndInfo *upgradeEndInfo)
{
return s_upgradePlatformOpt.getUpgradeRebootState(isUpgradeReboot, upgradeEndInfo);
}
T_DjiReturnCode DjiTest_CleanUpgradeRebootState(void)
{
return s_upgradePlatformOpt.cleanUpgradeRebootState();
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,84 @@
/**
********************************************************************
* @file test_upgrade_platform_opt.h
* @brief This is the header file for "test_upgrade_platform_opt.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 TEST_UPGRADE_PLATFORM_OPT_H
#define TEST_UPGRADE_PLATFORM_OPT_H
#include <dji_typedef.h>
#include <dji_upgrade.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
T_DjiReturnCode (*rebootSystem)(void);
T_DjiReturnCode (*cleanUpgradeProgramFileStoreArea)(void);
T_DjiReturnCode (*createUpgradeProgramFile)(const T_DjiUpgradeFileInfo *fileInfo);
T_DjiReturnCode (*writeUpgradeProgramFile)(uint32_t offset, const uint8_t *data, uint16_t dataLen);
T_DjiReturnCode (*readUpgradeProgramFile)(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen);
T_DjiReturnCode (*closeUpgradeProgramFile)(void);
T_DjiReturnCode (*replaceOldProgram)(void);
T_DjiReturnCode (*setUpgradeRebootState)(const T_DjiUpgradeEndInfo *upgradeEndInfo);
T_DjiReturnCode (*getUpgradeRebootState)(bool *isUpgradeReboot, T_DjiUpgradeEndInfo *upgradeEndInfo);
T_DjiReturnCode (*cleanUpgradeRebootState)(void);
} T_DjiTestUpgradePlatformOpt;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_RegUpgradePlatformOpt(const T_DjiTestUpgradePlatformOpt *upgradePlatformOpt);
T_DjiReturnCode DjiTest_RebootSystem(void);
T_DjiReturnCode DjiTest_CleanUpgradeProgramFileStoreArea(void);
T_DjiReturnCode DjiTest_CreateUpgradeProgramFile(const T_DjiUpgradeFileInfo *fileInfo);
T_DjiReturnCode DjiTest_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data, uint16_t dataLen);
T_DjiReturnCode DjiTest_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen);
T_DjiReturnCode DjiTest_CloseUpgradeProgramFile(void);
T_DjiReturnCode DjiTest_ReplaceOldProgram(void);
T_DjiReturnCode DjiTest_SetUpgradeRebootState(const T_DjiUpgradeEndInfo *upgradeEndInfo);
T_DjiReturnCode DjiTest_GetUpgradeRebootState(bool *isUpgradeReboot, T_DjiUpgradeEndInfo *upgradeEndInfo);
T_DjiReturnCode DjiTest_CleanUpgradeRebootState(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_UPGRADE_PLATFORM_OPT_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,290 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 12
#include <stddef.h>
#include <stdint.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON {
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks {
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*)cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *)cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *)cJSON_ParseByJsonData(const uint8_t *json_data, uint16_t data_len);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *)cJSON_ParseWithOpts(const char *value, const char **return_parse_end,
cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *)cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *)cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *)cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *)cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *)cJSON_GetObjectItem(const cJSON *const object, const char *const string);
CJSON_PUBLIC(cJSON *)cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *)cJSON_GetErrorPtr(void);
/* Check if the item is a string and return its valuestring */
CJSON_PUBLIC(char *)cJSON_GetStringValue(cJSON *item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *)cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *)cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *)cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *)cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *)cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *)cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *)cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *)cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *)cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *)cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *)cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *)cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *)cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *)cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *)cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *)cJSON_CreateStringArray(const char **strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *)cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item);
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(void)
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *)cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*)cJSON_AddNullToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*)cJSON_AddTrueToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*)cJSON_AddFalseToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*)cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*)cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
CJSON_PUBLIC(cJSON*)cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string);
CJSON_PUBLIC(cJSON*)cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
CJSON_PUBLIC(cJSON*)cJSON_AddObjectToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON*)cJSON_AddArrayToObject(cJSON *const object, const char *const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *)cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,339 @@
/**
********************************************************************
* @file dji_config_manager.c
* @brief
*
* @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.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <utils/util_misc.h>
#include <dji_logger.h>
#include <utils/util_file.h>
#include <dji_aircraft_info.h>
#include "dji_config_manager.h"
#include "utils/cJSON.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiUserInfo s_configManagerUserInfo = {0};
static T_DjiUserLinkConfig s_configManagerLinkInfo = {0};
static bool s_configManagerIsEnable = false;
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiUserConfigManager_GetAppInfoInner(const char *path, T_DjiUserInfo *userInfo);
static T_DjiReturnCode DjiUserConfigManager_GetLinkConfigInner(const char *path, T_DjiUserLinkConfig *linkConfig);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiUserConfigManager_LoadConfiguration(const char *path)
{
T_DjiReturnCode returnCode;
if (path == NULL) {
perror("Config file path is null.\n");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
printf("Load configuration start, config file path is: %s\r\n", path);
returnCode = DjiUserConfigManager_GetAppInfoInner(path, &s_configManagerUserInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
perror("Get app info failed.\n");
}
returnCode = DjiUserConfigManager_GetLinkConfigInner(path, &s_configManagerLinkInfo);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
perror("Get link info failed.\n");
}
printf("\r\nLoad configuration successfully.\r\n");
s_configManagerIsEnable = true;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
void DjiUserConfigManager_GetAppInfo(T_DjiUserInfo *userInfo)
{
memcpy(userInfo, &s_configManagerUserInfo, sizeof(T_DjiUserInfo));
}
void DjiUserConfigManager_GetLinkConfig(T_DjiUserLinkConfig *linkConfig)
{
memcpy(linkConfig, &s_configManagerLinkInfo, sizeof(T_DjiUserLinkConfig));
}
bool DjiUserConfigManager_IsEnable(void)
{
return s_configManagerIsEnable;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiUserConfigManager_GetAppInfoInner(const char *path, T_DjiUserInfo *userInfo)
{
T_DjiReturnCode returnCode;
uint32_t fileSize = 0;
uint32_t readRealSize = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
uint8_t *jsonData = NULL;
cJSON *jsonRoot = NULL;
cJSON *jsonItem = NULL;
cJSON *jsonValue = NULL;
#ifdef SYSTEM_ARCH_LINUX
returnCode = UtilFile_GetFileSizeByPath(path, &fileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file size by path failed, stat = 0x%08llX", returnCode);
return returnCode;
}
USER_LOG_DEBUG("Get config json file size is %d", fileSize);
jsonData = osalHandler->Malloc(fileSize + 1);
if (jsonData == NULL) {
USER_LOG_ERROR("Malloc failed.");
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
memset(jsonData, 0, fileSize);
UtilFile_GetFileDataByPath(path, 0, fileSize, jsonData, &readRealSize);
jsonData[readRealSize] = '\0';
jsonRoot = cJSON_Parse((char *) jsonData);
if (jsonRoot == NULL) {
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
goto jsonDataFree;
}
jsonItem = cJSON_GetObjectItem(jsonRoot, "dji_sdk_app_info");
if (jsonItem != NULL) {
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_name");
if (jsonValue != NULL) {
strcpy(userInfo->appName, jsonValue->valuestring);
}
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_id");
if (jsonValue != NULL) {
strcpy(userInfo->appId, jsonValue->valuestring);
}
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_key");
if (jsonValue != NULL) {
strcpy(userInfo->appKey, jsonValue->valuestring);
}
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_license");
if (jsonValue != NULL) {
strcpy(userInfo->appLicense, jsonValue->valuestring);
}
jsonValue = cJSON_GetObjectItem(jsonItem, "user_develop_account");
if (jsonValue != NULL) {
strcpy(userInfo->developerAccount, jsonValue->valuestring);
}
jsonValue = cJSON_GetObjectItem(jsonItem, "user_baud_rate");
if (jsonValue != NULL) {
strcpy(userInfo->baudRate, jsonValue->valuestring);
}
}
if (strlen(userInfo->appName) >= sizeof(userInfo->appName) ||
strlen(userInfo->appId) > sizeof(userInfo->appId) ||
strlen(userInfo->appKey) > sizeof(userInfo->appKey) ||
strlen(userInfo->appLicense) > sizeof(userInfo->appLicense) ||
strlen(userInfo->developerAccount) >= sizeof(userInfo->developerAccount) ||
strlen(userInfo->baudRate) > sizeof(userInfo->baudRate)) {
USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
goto jsonDataFree;
}
if (!strcmp(userInfo->appName, "your_app_name") ||
!strcmp(userInfo->appId, "your_app_id") ||
!strcmp(userInfo->appKey, "your_app_key") ||
!strcmp(userInfo->appLicense, "your_app_license") ||
!strcmp(userInfo->developerAccount, "your_developer_account") ||
!strcmp(userInfo->baudRate, "your_baud_rate")) {
USER_LOG_ERROR(
"Please fill in correct user information to 'samples/sample_c++/platform/linux/manifold2/application/dji_sdk_config.json' file.");
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
goto jsonDataFree;
}
jsonDataFree:
osalHandler->Free(jsonData);
#endif
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiUserConfigManager_GetLinkConfigInner(const char *path, T_DjiUserLinkConfig *linkConfig)
{
T_DjiReturnCode returnCode;
uint32_t fileSize = 0;
uint32_t readRealSize = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
uint8_t *jsonData = NULL;
cJSON *jsonRoot = NULL;
cJSON *jsonItem = NULL;
cJSON *jsonValue = NULL;
cJSON *jsonConfig = NULL;
int32_t configValue;
#ifdef SYSTEM_ARCH_LINUX
returnCode = UtilFile_GetFileSizeByPath(path, &fileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file size by path failed, stat = 0x%08llX", returnCode);
return returnCode;
}
USER_LOG_DEBUG("Get config json file size is %d", fileSize);
jsonData = osalHandler->Malloc(fileSize + 1);
if (jsonData == NULL) {
USER_LOG_ERROR("Malloc failed.");
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
memset(jsonData, 0, fileSize);
UtilFile_GetFileDataByPath(path, 0, fileSize, jsonData, &readRealSize);
jsonData[readRealSize] = '\0';
jsonRoot = cJSON_Parse((char *) jsonData);
if (jsonRoot == NULL) {
goto jsonDataFree;
}
jsonItem = cJSON_GetObjectItem(jsonRoot, "dji_sdk_link_config");
if (jsonItem != NULL) {
jsonValue = cJSON_GetObjectItem(jsonItem, "link_select");
if (jsonValue != NULL) {
printf("\r\nSelect link type: %s\r\n", jsonValue->valuestring);
if (strcmp(jsonValue->valuestring, "use_only_uart") == 0) {
linkConfig->type = DJI_USER_LINK_CONFIG_USE_ONLY_UART;
} else if (strcmp(jsonValue->valuestring, "use_uart_and_network_device") == 0) {
linkConfig->type = DJI_USER_LINK_CONFIG_USE_UART_AND_NETWORK_DEVICE;
} else if (strcmp(jsonValue->valuestring, "use_uart_and_usb_bulk_device") == 0) {
linkConfig->type = DJI_USER_LINK_CONFIG_USE_UART_AND_USB_BULK_DEVICE;
}
}
jsonValue = cJSON_GetObjectItem(jsonItem, "uart_config");
if (jsonValue != NULL) {
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart1_device_name");
printf("\r\nConfig uart1 device name: %s\r\n", jsonConfig->valuestring);
strcpy(linkConfig->uartConfig.uart1DeviceName, jsonConfig->valuestring);
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart2_device_name");
printf("Config uart2 device name: %s\r\n", jsonConfig->valuestring);
strcpy(linkConfig->uartConfig.uart2DeviceName, jsonConfig->valuestring);
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart2_device_enable");
printf("Config uart2 device enable: %s\r\n", jsonConfig->valuestring);
if (strcmp(jsonConfig->valuestring, "true") == 0) {
linkConfig->uartConfig.uart2DeviceEnable = true;
} else {
linkConfig->uartConfig.uart2DeviceEnable = false;
}
}
jsonValue = cJSON_GetObjectItem(jsonItem, "network_config");
if (jsonValue != NULL) {
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_device_name");
printf("\r\nConfig network device name: %s\r\n", jsonConfig->valuestring);
strcpy(linkConfig->networkConfig.networkDeviceName, jsonConfig->valuestring);
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_usb_adapter_vid");
printf("Config network usb adapter vid: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->networkConfig.networkUsbAdapterVid = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_usb_adapter_pid");
printf("Config network usb adapter vid: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->networkConfig.networkUsbAdapterPid = configValue;
}
jsonValue = cJSON_GetObjectItem(jsonItem, "usb_bulk_config");
if (jsonValue != NULL) {
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_device_vid");
printf("\r\nConfig usb device vid: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbDeviceVid = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_device_pid");
printf("Config usb device pid: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbDevicePid = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_device_name");
printf("Config usb bulk1 device name: %s\r\n", jsonConfig->valuestring);
strcpy(linkConfig->usbBulkConfig.usbBulk1DeviceName, jsonConfig->valuestring);
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_interface_num");
printf("Config usb bulk1 interface num: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbBulk1InterfaceNum = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_endpoint_in");
printf("Config usb bulk1 endpoint in: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbBulk1EndpointIn = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_endpoint_out");
printf("Config usb bulk1 endpoint out: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbBulk1EndpointOut = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_device_name");
printf("Config usb bulk2 device name: %s\r\n", jsonConfig->valuestring);
strcpy(linkConfig->usbBulkConfig.usbBulk2DeviceName, jsonConfig->valuestring);
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_interface_num");
printf("Config usb bulk2 interface num: %s\r\n", jsonConfig->valuestring);
sscanf(jsonConfig->valuestring, "%X", &configValue);
linkConfig->usbBulkConfig.usbBulk2InterfaceNum = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_endpoint_in");
printf("Config usb bulk2 endpoint in: %s\r\n", jsonConfig->valuestring);
linkConfig->usbBulkConfig.usbBulk2EndpointIn = configValue;
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_endpoint_out");
printf("Config usb bulk2 endpoint out: %s\r\n", jsonConfig->valuestring);
linkConfig->usbBulkConfig.usbBulk2EndpointOut = configValue;
}
}
jsonDataFree:
osalHandler->Free(jsonData);
#endif
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,88 @@
/**
********************************************************************
* @file dji_config_manager.h
* @brief This is the header file for "dji_config_manager.c", 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_CONFIG_MANAGER_H
#define DJI_CONFIG_MANAGER_H
/* Includes ------------------------------------------------------------------*/
#include "dji_platform.h"
#include "dji_core.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define USER_DEVICE_NAME_STR_MAX_SIZE (64)
/* Exported types ------------------------------------------------------------*/
typedef enum {
DJI_USER_LINK_CONFIG_USE_ONLY_UART,
DJI_USER_LINK_CONFIG_USE_UART_AND_NETWORK_DEVICE,
DJI_USER_LINK_CONFIG_USE_UART_AND_USB_BULK_DEVICE,
} E_DjiUserLinkConfigType;
typedef struct {
E_DjiUserLinkConfigType type;
struct {
char uart1DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
bool uart2DeviceEnable;
char uart2DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
} uartConfig;
struct {
char networkDeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
// M300/M350 RTK payload port no need
uint16_t networkUsbAdapterVid;
uint16_t networkUsbAdapterPid;
} networkConfig;
struct {
uint16_t usbDeviceVid;
uint16_t usbDevicePid;
char usbBulk1DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
uint8_t usbBulk1InterfaceNum;
uint8_t usbBulk1EndpointIn;
uint8_t usbBulk1EndpointOut;
char usbBulk2DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
uint8_t usbBulk2InterfaceNum;
uint8_t usbBulk2EndpointIn;
uint8_t usbBulk2EndpointOut;
} usbBulkConfig;
} T_DjiUserLinkConfig;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiUserConfigManager_LoadConfiguration(const char *path);
void DjiUserConfigManager_GetAppInfo(T_DjiUserInfo *userInfo);
void DjiUserConfigManager_GetLinkConfig(T_DjiUserLinkConfig *linkConfig);
bool DjiUserConfigManager_IsEnable(void);
#ifdef __cplusplus
}
#endif
#endif // DJI_CONFIG_MANAGER_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,127 @@
/**
******************************************************************************
* @file util_buffer.c
* @brief The file defines buffer related functions, including initialize, put data to buffer,
* get data from buffer and get unused count of bytes of buffer.
*
* @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 "util_buffer.h"
#include <string.h>
#include "util_misc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Cut buffer size to power of 2, in order to increase the convenience of get and put operating of buffer.
* @param bufSize Original buffer size.
* @return Buffer size after handling.
*/
static uint16_t UtilBuffer_CutBufSizeToPowOfTwo(uint16_t bufSize)
{
uint16_t i = 0;
while ((1 << (++i)) <= bufSize);
return (uint16_t) (1 << (--i));
}
/* Exported functions --------------------------------------------------------*/
/**
* @brief Buffer initialization.
* @param pthis Pointer to buffer structure.
* @param pBuf Pointer to data buffer.
* @param bufSize Size of data buffer.
* @return None.
*/
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize)
{
pthis->readIndex = 0;
pthis->writeIndex = 0;
pthis->bufferPtr = pBuf;
pthis->bufferSize = UtilBuffer_CutBufSizeToPowOfTwo(bufSize);
}
/**
* @brief Put a block of data into buffer.
* @param pthis Pointer to buffer structure.
* @param pData Pointer to data to be stored.
* @param dataLen Length of data to be stored.
* @return Length of data to be stored.
*/
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen)
{
uint16_t writeUpLen;
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex));
//fill up data
writeUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->writeIndex & (pthis->bufferSize - 1))));
memcpy(pthis->bufferPtr + (pthis->writeIndex & (pthis->bufferSize - 1)), pData, writeUpLen);
//fill begin data
memcpy(pthis->bufferPtr, pData + writeUpLen, dataLen - writeUpLen);
pthis->writeIndex += dataLen;
return dataLen;
}
/**
* @brief Get a block of data from buffer.
* @param pthis Pointer to buffer structure.
* @param pData Pointer to data to be read.
* @param dataLen Length of data to be read.
* @return Length of data to be read.
*/
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen)
{
uint16_t readUpLen;
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->writeIndex - pthis->readIndex));
//get up data
readUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->readIndex & (pthis->bufferSize - 1))));
memcpy(pData, pthis->bufferPtr + (pthis->readIndex & (pthis->bufferSize - 1)), readUpLen);
//get begin data
memcpy(pData + readUpLen, pthis->bufferPtr, dataLen - readUpLen);
pthis->readIndex += dataLen;
return dataLen;
}
/**
* @brief Get unused size of buffer.
* @param pthis Pointer to buffer structure.
* @return Unused size of buffer.
*/
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis)
{
return (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex);
}

View File

@ -0,0 +1,59 @@
/**
******************************************************************************
* @file util_buffer.h
* @brief This is the header file for "util_buffer.c".
*
* @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 _DJI_UTIL_BUFFER_H_
#define _DJI_UTIL_BUFFER_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
//Note: not need lock for just one producer / one consumer
//need mutex to protect for multi-producer / multi-consumer
typedef struct {
uint8_t *bufferPtr;
uint16_t bufferSize;
uint16_t readIndex;
uint16_t writeIndex;
} T_UtilBuffer;
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize);
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen);
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen);
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis);
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#endif

View File

@ -0,0 +1,207 @@
/**
********************************************************************
* @file util_file.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 ------------------------------------------------------------------*/
#ifdef SYSTEM_ARCH_LINUX
#include "util_file.h"
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Private values ------------------------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime)
{
struct stat st;
struct tm *fileTm;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (stat(filePath, &st) != 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;
}
createTime->year = fileTm->tm_year + 1900 - 1980;
createTime->month = fileTm->tm_mon;
createTime->day = fileTm->tm_mday;
createTime->hour = fileTm->tm_hour;
createTime->minute = fileTm->tm_min;
createTime->second = fileTm->tm_sec;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize)
{
struct stat st;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (stat(filePath, &st) != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*fileSize = st.st_size;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint32_t len,
uint8_t *data, uint32_t *realLen)
{
FILE *pF;
T_DjiReturnCode psdkStat;
uint32_t readRtn;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
pF = fopen(filePath, "rb+");
if (pF == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (fseek(pF, offset, SEEK_SET) != 0) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto out;
}
readRtn = fread(data, 1, len, pF);
if (readRtn == 0 || readRtn > len) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto out;
}
*realLen = readRtn;
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
out:
fclose(pF);
return psdkStat;
}
T_DjiReturnCode UtilFile_Delete(const char *filePath)
{
int ret;
if (filePath == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = unlink(filePath);
if (ret != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
}
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize)
{
int result;
if (file == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
long int curSeek = ftell(file);
result = fseek(file, 0L, SEEK_END);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
*fileSize = ftell(file);
if (curSeek < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
result = fseek(file, curSeek, SEEK_SET);
if (result != 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen)
{
T_DjiReturnCode psdkStat;
uint32_t readRtn;
if (file == NULL) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
goto out;
}
if (fseek(file, offset, SEEK_SET) != 0) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto out;
}
readRtn = fread(data, 1, len, file);
if (readRtn == 0 || readRtn > len) {
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
goto out;
}
*realLen = readRtn;
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
out:
return psdkStat;
}
/* Private functions definition-----------------------------------------------*/
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,70 @@
/**
********************************************************************
* @file util_file.h
* @brief This is the header file for "util_file.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 UTIL_FILE_H
#define UTIL_FILE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SYSTEM_ARCH_LINUX
/* Includes ------------------------------------------------------------------*/
#include <dji_typedef.h>
#include <stdio.h>
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
uint32_t second: 5;
uint32_t minute: 6;
uint32_t hour: 5;
uint32_t day: 5;
uint32_t month: 4;
uint32_t year: 7;
} T_UtilFileCreateTime;
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime);
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize);
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint32_t len,
uint8_t *data, uint32_t *realLen);
T_DjiReturnCode DjiFile_Delete(const char *filePath);
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize);
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen);
#ifdef __cplusplus
}
#endif
#endif
#endif // UTIL_FILE_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,218 @@
/**
********************************************************************
* @file util_link_list.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.
*
*********************************************************************
*/
#define UTIL_LINK_LIST_C
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "util_link_list.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Private values ------------------------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
void DjiUserUtil_ListNodeDeleteDataOnly( T_UtilListNode *node )
{
if ( NULL == node) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
if ( NULL != node->data ) {
UTIL_OSAL_MEMRY_FREE( node->data );
node->data = NULL;
}
return;
}
void DjiUserUtil_ListNodeDeleteNodeSelf( T_UtilListNode *node )
{
if ( NULL == node) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
UTIL_OSAL_MEMRY_FREE( node );
return;
}
void DjiUserUtil_InitListNode( T_UtilListNode *node, void *data )
{
if ( NULL == node ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
node->prev = NULL;
node->next = NULL;
node->data = data;
return;
}
T_UtilListNode *DjiUserUtil_NewListNode( void *data )
{
T_UtilListNode *node = NULL;
node = (T_UtilListNode *)UTIL_OSAL_MEMRY_ALLOC( sizeof(T_UtilListNode) );
if ( NULL == node ) {
UTIL_REPORT_ERROR( "null pointer" );
return NULL;
}
DjiUserUtil_InitListNode( node, data );
return node;
}
void DjiUserUtil_LinkListDestory( T_UtilLinkList *linkList )
{
T_UtilListNode *node = NULL;
T_UtilListNode *next = NULL;
if ( NULL == linkList ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
for ( node = linkList->first; NULL != node ; node = next ) {
next = node->next;
DjiUserUtil_ListNodeDeleteDataOnly( node );
DjiUserUtil_ListNodeDeleteNodeSelf( node );
}
}
void DjiUserUtil_LinkListAddNodeFirst( T_UtilLinkList *linkList, T_UtilListNode *node )
{
if ( ( NULL == linkList ) || ( NULL == node ) ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
if ( UTIL_LINKLIST_IS_EMPTY( *linkList ) ) {
node->prev = NULL;
node->next = NULL;
linkList->first = node;
linkList->last = node;
} else {
node->prev = NULL;
node->next = linkList->first;
linkList->first = node;
node->next->prev = node;
}
linkList->count ++;
return;
}
void DjiUserUtil_LinkListAddNodeLast( T_UtilLinkList *linkList, T_UtilListNode *node )
{
if ( ( NULL == linkList ) || ( NULL == node ) ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
if ( UTIL_LINKLIST_IS_EMPTY( *linkList ) ) {
node->prev = NULL;
node->next = NULL;
linkList->first = node;
linkList->last = node;
} else {
node->next = NULL;
node->prev = linkList->last;
linkList->last = node;
node->prev->next = node;
}
linkList->count ++;
return;
}
void DjiUserUtil_InitLinkList( T_UtilLinkList *linkList )
{
if ( NULL == linkList ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
linkList->first = NULL;
linkList->last = NULL;
linkList->count = 0;
return;
}
T_UtilLinkList *DjiUserUtil_NewLinkList( void )
{
T_UtilLinkList *linkList = NULL;
linkList = (T_UtilLinkList *)UTIL_OSAL_MEMRY_ALLOC( sizeof( T_UtilLinkList ) );
if ( NULL == linkList ) {
UTIL_REPORT_ERROR( "null pointer" );
return NULL;
}
DjiUserUtil_InitLinkList( linkList );
return linkList;
}
void DjiUserUtil_LinkListRemoveNodeOnly( T_UtilLinkList *linkList, T_UtilListNode *node )
{
if ( ( NULL == linkList ) || ( NULL == node ) ) {
UTIL_REPORT_ERROR( "null pointer" );
return;
}
if ( node == linkList->first ) {
linkList->first = linkList->first->next;
}
if ( node == linkList->last ) {
linkList->last = linkList->last->prev;
}
if ( NULL != node->next ) {
node->next->prev = node->prev;
}
if ( NULL != node->prev ) {
node->prev->next = node->next;
}
if ( 0 != linkList->count ) {
linkList->count --;
}
DjiUserUtil_ListNodeDeleteNodeSelf( node );
return;
}
/* Private functions definition-----------------------------------------------*/
#ifdef __cplusplus
}
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,94 @@
/**
********************************************************************
* @file link_list.h
* @brief This is the header file for "link_list.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 UTIL_LINK_LIST_H
#define UTIL_LINK_LIST_H
/* Includes ------------------------------------------------------------------*/
#include "dji_platform.h"
#ifdef UTIL_LINK_LIST_C
#define UTIL_LINK_LIST_EXT
#else
#define UTIL_LINK_LIST_EXT extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define UTIL_REPORT_ERROR( exp... )
#define UTIL_OSAL_MEMRY_ALLOC(size) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); osalHandler->Malloc( size ); } )
#define UTIL_OSAL_MEMRY_FREE(ptr) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); osalHandler->Free( ptr ); } )
#define UTIL_OSAL_SEM_FREE_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreDestroy( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_SEM_INIT_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreCreate( 0, sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_SEM_POST_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphorePost( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_SEM_WAIT_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreWait( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_SEM_WAIT_FOR(sem,ms) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreTimedWait( sem, ms ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_MUTEX_FREE_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexDestroy( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_MUTEX_INIT_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexCreate( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_MUTEX_LOCK_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexLock( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_OSAL_MUTEX_UNLOCK_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexUnlock( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
#define UTIL_LINKLIST_IS_EMPTY(l) ( ((l).first == NULL) ? true : false )
/* Exported types ------------------------------------------------------------*/
typedef struct tagT_UtilListNode {
struct tagT_UtilListNode *next;
struct tagT_UtilListNode *prev;
void *data;
} T_UtilListNode;
typedef struct tagT_UtilLinkList {
T_UtilListNode *first;
T_UtilListNode *last;
uint32_t count;
} T_UtilLinkList;
/* Exported functions --------------------------------------------------------*/
UTIL_LINK_LIST_EXT void DjiUserUtil_ListNodeDeleteDataOnly( T_UtilListNode *node );
UTIL_LINK_LIST_EXT void DjiUserUtil_ListNodeDeleteNodeSelf( T_UtilListNode *node );
UTIL_LINK_LIST_EXT void DjiUserUtil_InitListNode( T_UtilListNode *node, void *data );
UTIL_LINK_LIST_EXT T_UtilListNode *DjiUserUtil_NewListNode( void *data );
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListDestory( T_UtilLinkList *linkList );
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListAddNodeFirst( T_UtilLinkList *linkList, T_UtilListNode *node );
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListAddNodeLast( T_UtilLinkList *linkList, T_UtilListNode *node );
UTIL_LINK_LIST_EXT void DjiUserUtil_InitLinkList( T_UtilLinkList *linkList );
UTIL_LINK_LIST_EXT T_UtilLinkList *DjiUserUtil_NewLinkList( void );
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListRemoveNodeOnly( T_UtilLinkList *linkList, T_UtilListNode *node );
#ifdef __cplusplus
}
#endif
#endif // UTIL_LINK_LIST_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,238 @@
/**
********************************************************************
* @file util_md5.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.
*
* crypto-algorithms
* =================
*
* About
* ---
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
* author.
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
* and should not be used in contexts that need cryptographically secure implementations.
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
* basic optimization techniques have been employed.
* Building
* ---
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
* matters. Compiling them should be as easy as adding the relevent source code to the project.
*
* @statement DJI has modified some symbols' name.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "util_md5.h"
/* Private constants ---------------------------------------------------------*/
#define ROTLEFT(a, b) ((a << b) | (a >> (32-b)))
#define F(x, y, z) ((x & y) | (~x & z))
#define G(x, y, z) ((x & z) | (y & ~z))
#define H(x, y, z) (x ^ y ^ z)
#define I(x, y, z) (y ^ (x | ~z))
#define FF(a, b, c, d, m, s, t) { a += F(b,c,d) + m + t; \
a = b + ROTLEFT(a,s); }
#define GG(a, b, c, d, m, s, t) { a += G(b,c,d) + m + t; \
a = b + ROTLEFT(a,s); }
#define HH(a, b, c, d, m, s, t) { a += H(b,c,d) + m + t; \
a = b + ROTLEFT(a,s); }
#define II(a, b, c, d, m, s, t) { a += I(b,c,d) + m + t; \
a = b + ROTLEFT(a,s); }
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
void UtilMd5_Transform(MD5_CTX *ctx, const BYTE *data)
{
WORD a, b, c, d, m[16], i, j;
// MD5 specifies big endian byte order, but this implementation assumes a little
// endian byte order CPU. Reverse all the bytes upon input, and re-reverse them
// on output (in md5_final()).
for (i = 0, j = 0; i < 16; ++i, j += 4) {
m[i] = (data[j]) + (data[j + 1] << 8) + (data[j + 2] << 16) + (data[j + 3] << 24);
}
a = ctx->state[0];
b = ctx->state[1];
c = ctx->state[2];
d = ctx->state[3];
FF(a, b, c, d, m[0], 7, 0xd76aa478);
FF(d, a, b, c, m[1], 12, 0xe8c7b756);
FF(c, d, a, b, m[2], 17, 0x242070db);
FF(b, c, d, a, m[3], 22, 0xc1bdceee);
FF(a, b, c, d, m[4], 7, 0xf57c0faf);
FF(d, a, b, c, m[5], 12, 0x4787c62a);
FF(c, d, a, b, m[6], 17, 0xa8304613);
FF(b, c, d, a, m[7], 22, 0xfd469501);
FF(a, b, c, d, m[8], 7, 0x698098d8);
FF(d, a, b, c, m[9], 12, 0x8b44f7af);
FF(c, d, a, b, m[10], 17, 0xffff5bb1);
FF(b, c, d, a, m[11], 22, 0x895cd7be);
FF(a, b, c, d, m[12], 7, 0x6b901122);
FF(d, a, b, c, m[13], 12, 0xfd987193);
FF(c, d, a, b, m[14], 17, 0xa679438e);
FF(b, c, d, a, m[15], 22, 0x49b40821);
GG(a, b, c, d, m[1], 5, 0xf61e2562);
GG(d, a, b, c, m[6], 9, 0xc040b340);
GG(c, d, a, b, m[11], 14, 0x265e5a51);
GG(b, c, d, a, m[0], 20, 0xe9b6c7aa);
GG(a, b, c, d, m[5], 5, 0xd62f105d);
GG(d, a, b, c, m[10], 9, 0x02441453);
GG(c, d, a, b, m[15], 14, 0xd8a1e681);
GG(b, c, d, a, m[4], 20, 0xe7d3fbc8);
GG(a, b, c, d, m[9], 5, 0x21e1cde6);
GG(d, a, b, c, m[14], 9, 0xc33707d6);
GG(c, d, a, b, m[3], 14, 0xf4d50d87);
GG(b, c, d, a, m[8], 20, 0x455a14ed);
GG(a, b, c, d, m[13], 5, 0xa9e3e905);
GG(d, a, b, c, m[2], 9, 0xfcefa3f8);
GG(c, d, a, b, m[7], 14, 0x676f02d9);
GG(b, c, d, a, m[12], 20, 0x8d2a4c8a);
HH(a, b, c, d, m[5], 4, 0xfffa3942);
HH(d, a, b, c, m[8], 11, 0x8771f681);
HH(c, d, a, b, m[11], 16, 0x6d9d6122);
HH(b, c, d, a, m[14], 23, 0xfde5380c);
HH(a, b, c, d, m[1], 4, 0xa4beea44);
HH(d, a, b, c, m[4], 11, 0x4bdecfa9);
HH(c, d, a, b, m[7], 16, 0xf6bb4b60);
HH(b, c, d, a, m[10], 23, 0xbebfbc70);
HH(a, b, c, d, m[13], 4, 0x289b7ec6);
HH(d, a, b, c, m[0], 11, 0xeaa127fa);
HH(c, d, a, b, m[3], 16, 0xd4ef3085);
HH(b, c, d, a, m[6], 23, 0x04881d05);
HH(a, b, c, d, m[9], 4, 0xd9d4d039);
HH(d, a, b, c, m[12], 11, 0xe6db99e5);
HH(c, d, a, b, m[15], 16, 0x1fa27cf8);
HH(b, c, d, a, m[2], 23, 0xc4ac5665);
II(a, b, c, d, m[0], 6, 0xf4292244);
II(d, a, b, c, m[7], 10, 0x432aff97);
II(c, d, a, b, m[14], 15, 0xab9423a7);
II(b, c, d, a, m[5], 21, 0xfc93a039);
II(a, b, c, d, m[12], 6, 0x655b59c3);
II(d, a, b, c, m[3], 10, 0x8f0ccc92);
II(c, d, a, b, m[10], 15, 0xffeff47d);
II(b, c, d, a, m[1], 21, 0x85845dd1);
II(a, b, c, d, m[8], 6, 0x6fa87e4f);
II(d, a, b, c, m[15], 10, 0xfe2ce6e0);
II(c, d, a, b, m[6], 15, 0xa3014314);
II(b, c, d, a, m[13], 21, 0x4e0811a1);
II(a, b, c, d, m[4], 6, 0xf7537e82);
II(d, a, b, c, m[11], 10, 0xbd3af235);
II(c, d, a, b, m[2], 15, 0x2ad7d2bb);
II(b, c, d, a, m[9], 21, 0xeb86d391);
ctx->state[0] += a;
ctx->state[1] += b;
ctx->state[2] += c;
ctx->state[3] += d;
}
void UtilMd5_Init(MD5_CTX *ctx)
{
ctx->datalen = 0;
ctx->bitlen = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
}
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len)
{
size_t i;
for (i = 0; i < len; ++i) {
ctx->data[ctx->datalen] = data[i];
ctx->datalen++;
if (ctx->datalen == 64) {
UtilMd5_Transform(ctx, ctx->data);
ctx->bitlen += 512;
ctx->datalen = 0;
}
}
}
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash)
{
size_t i;
i = ctx->datalen;
// Pad whatever data is left in the buffer.
if (ctx->datalen < 56) {
ctx->data[i++] = 0x80;
while (i < 56) {
ctx->data[i++] = 0x00;
}
} else if (ctx->datalen >= 56) {
ctx->data[i++] = 0x80;
while (i < 64) {
ctx->data[i++] = 0x00;
}
UtilMd5_Transform(ctx, ctx->data);
memset(ctx->data, 0, 56);
}
// Append to the padding the total message's length in bits and transform.
ctx->bitlen += ctx->datalen * 8;
ctx->data[56] = ctx->bitlen;
ctx->data[57] = ctx->bitlen >> 8;
ctx->data[58] = ctx->bitlen >> 16;
ctx->data[59] = ctx->bitlen >> 24;
ctx->data[60] = ctx->bitlen >> 32;
ctx->data[61] = ctx->bitlen >> 40;
ctx->data[62] = ctx->bitlen >> 48;
ctx->data[63] = ctx->bitlen >> 56;
UtilMd5_Transform(ctx, ctx->data);
// Since this implementation uses little endian byte ordering and MD uses big endian,
// reverse all the bytes when copying the final state to the output hash.
for (i = 0; i < 4; ++i) {
hash[i] = (ctx->state[0] >> (i * 8)) & 0x000000ff;
hash[i + 4] = (ctx->state[1] >> (i * 8)) & 0x000000ff;
hash[i + 8] = (ctx->state[2] >> (i * 8)) & 0x000000ff;
hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
}
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,88 @@
/**
********************************************************************
* @file util_md5.h
* @brief This is the header file for "util_md5.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.
*
* crypto-algorithms
* =================
*
* About
* ---
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
* author.
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
* and should not be used in contexts that need cryptographically secure implementations.
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
* basic optimization techniques have been employed.
* Building
* ---
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
* matters. Compiling them should be as easy as adding the relevent source code to the project.
*
* @statement DJI has modified some symbols' name.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef UTIL_MD5_H
#define UTIL_MD5_H
/* Includes ------------------------------------------------------------------*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
/* Exported types ------------------------------------------------------------*/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
typedef struct {
BYTE data[64];
WORD datalen;
unsigned long long bitlen;
WORD state[4];
} MD5_CTX;
/* Exported functions --------------------------------------------------------*/
void UtilMd5_Init(MD5_CTX *ctx);
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len);
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash);
#ifdef __cplusplus
}
#endif
#endif // UTIL_MD5_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,102 @@
/**
********************************************************************
* @file util_misc.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 ------------------------------------------------------------------*/
#ifdef SYSTEM_ARCH_LINUX
#include <stdio.h>
#include "util_misc.h"
/* Private constants ---------------------------------------------------------*/
const char *baseStr = "[>>>>>>>>>>>>>---------------------------------------------------------------------------------------] 13%";
/* Private types -------------------------------------------------------------*/
/* Private values ------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath)
{
uint32_t i = strlen(filePath) - 1;
uint32_t dirPathLen;
while (filePath[i] != '/') {
i--;
}
dirPathLen = i + 1;
if (dirPathLen + 1 > pathBufferSize) {
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
memcpy(dirPath, filePath, dirPathLen);
dirPath[dirPathLen] = 0;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr)
{
FILE *fp;
fp = popen(systemCmdStr, "r");
if (fp == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
pclose(fp);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData)
{
for (int j = 0; j < strlen(baseStr) + strlen(userData) + 4; ++j) {
printf("\b");
}
printf("[");
for (int j = 0; j < totalProgress; ++j) {
if (j < currentProgress) {
printf("%c", '>');
} else {
printf("-");
}
}
printf("] ");
printf("%3d%%", currentProgress);
printf("%s", userData);
fflush(stdout);
}
/* Private functions definition-----------------------------------------------*/
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,58 @@
/**
********************************************************************
* @file util_misc.h
* @brief This is the header file for "util_misc.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 UTIL_MISC_H
#define UTIL_MISC_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#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))
#define USER_UTIL_IS_WORK_TURN(step, workfreq, taskfreq) (!((step) % (uint32_t) ((taskfreq) / (workfreq))))
#define UTIL_OFFSETOF(type, member) ((size_t) & ((type *)0 )-> member)
#define UTIL_ARRAY_SIZE(array) ((unsigned int) (sizeof(array) / sizeof((array)[0])))
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath);
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData);
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr);
#ifdef __cplusplus
}
#endif
#endif // UTIL_MISC_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,62 @@
/**
********************************************************************
* @file util_time.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 ------------------------------------------------------------------*/
#ifdef SYSTEM_ARCH_LINUX
#include "util_time.h"
#include <sys/resource.h>
#include <time.h>
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Private values ------------------------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void)
{
T_DjiRunTimeStamps timeStamps;
struct rusage rusage;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
timeStamps.realUsec = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
getrusage(RUSAGE_SELF, &rusage);
timeStamps.userUsec =
(rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
timeStamps.sysUsec =
(rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
return timeStamps;
}
/* Private functions definition-----------------------------------------------*/
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,60 @@
/**
********************************************************************
* @file util_time.h
* @brief This is the header file for "util_time.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 DJI_UTIL_TIME_H
#define DJI_UTIL_TIME_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SYSTEM_ARCH_LINUX
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
uint64_t realUsec;
uint64_t userUsec;
uint64_t sysUsec;
} T_DjiRunTimeStamps;
/* Exported functions --------------------------------------------------------*/
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void);
#ifdef __cplusplus
}
#endif
#endif
#endif // DJI_DP_UTILS_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,465 @@
/**
********************************************************************
* @file test_waypoint_v2.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 <widget_interaction_test/test_widget_interaction.h>
#include "test_waypoint_v2.h"
#include "dji_waypoint_v2.h"
#include "dji_fc_subscription.h"
#include "dji_logger.h"
#include "dji_platform.h"
#include "math.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
typedef struct {
uint8_t eventID;
char *eventStr;
} T_DjiTestWaypointV2EventStr;
typedef struct {
uint8_t missionState;
char *stateStr;
} T_DjiTestWaypointV2StateStr;
/* Private values -------------------------------------------------------------*/
static T_DjiOsalHandler *osalHandler = NULL;
static const dji_f32_t TEST_EARTH_RADIUS = 6378137.0;
static uint32_t s_missionID = 12345;
//reference note of "T_DjiWaypointV2MissionEventPush"
static const T_DjiTestWaypointV2EventStr s_waypointV2EventStr[] = {
{.eventID = 0x01, .eventStr = "Interrupt Event"},
{.eventID = 0x02, .eventStr = "Resume Event"},
{.eventID = 0x03, .eventStr = "Stop Event"},
{.eventID = 0x10, .eventStr = "Arrival Event"},
{.eventID = 0x11, .eventStr = "Finished Event"},
{.eventID = 0x12, .eventStr = "Avoid Obstacle Event"},
{.eventID = 0x30, .eventStr = "Action Switch Event"},
{.eventID = 0xFF, .eventStr = "Unknown"}
};
//reference note of "T_DjiWaypointV2MissionStatePush"
static const T_DjiTestWaypointV2StateStr s_waypointV2StateStr[] = {
{.missionState = 0x00, .stateStr = "Ground station not start"},
{.missionState = 0x01, .stateStr = "Mission prepared"},
{.missionState = 0x02, .stateStr = "Enter mission"},
{.missionState = 0x03, .stateStr = "Execute mission"},
{.missionState = 0x04, .stateStr = "Pause Mission"},
{.missionState = 0x05, .stateStr = "Enter mission after ending pause"},
{.missionState = 0x06, .stateStr = "Exit mission"},
{.missionState = 0xFF, .stateStr = "Unknown"}
};
/* Private functions declaration ---------------------------------------------*/
uint8_t DJiTest_WaypointV2GetMissionEventIndex(uint8_t eventID);
uint8_t DjiTest_WaypointV2GetMissionStateIndex(uint8_t state);
static T_DJIWaypointV2Action *DjiTest_WaypointV2GenerateWaypointV2Actions(uint16_t actionNum);
static T_DjiWaypointV2 *DjiTest_WaypointV2GeneratePolygonWaypointV2(dji_f32_t radius, uint16_t polygonNum);
static void DjiTest_WaypointV2SetDefaultSetting(T_DjiWaypointV2 *waypointV2);
static T_DjiReturnCode DjiTest_WaypointV2UploadMission(uint16_t missionNum);
static T_DjiReturnCode DjiTest_WaypointV2EventCallback(T_DjiWaypointV2MissionEventPush eventData);
static T_DjiReturnCode DjiTest_WaypointV2StateCallback(T_DjiWaypointV2MissionStatePush stateData);
static T_DjiReturnCode DjiTest_WaypointV2Init(void);
static T_DjiReturnCode DjiTest_WaypointV2DeInit(void);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_WaypointV2RunSample(void)
{
T_DjiReturnCode returnCode;
uint32_t timeOutMs = 1000;
uint16_t missionNum = 8;
T_DjiWaypointV2GlobalCruiseSpeed setGlobalCruiseSpeed = 0;
T_DjiWaypointV2GlobalCruiseSpeed getGlobalCruiseSpeed = 0;
USER_LOG_INFO("Waypoint V2 sample start");
DjiTest_WidgetLogAppend("Waypoint V2 sample start");
USER_LOG_INFO("--> Step 1: Init Waypoint V2 sample");
DjiTest_WidgetLogAppend("--> Step 1: Init Waypoint V2 sample");
returnCode = DjiTest_WaypointV2Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init waypoint V2 sample failed, error code: 0x%08X", returnCode);
USER_LOG_INFO("Waypoint V2 sample end");
return returnCode;
}
USER_LOG_INFO("--> Step 2: Subscribe gps fused data");
DjiTest_WidgetLogAppend("--> Step 2: Subscribe gps fused data");
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_POSITION_FUSED,
DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ, NULL);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe gps fused data failed, error code: 0x%08X", returnCode);
goto out;
}
USER_LOG_INFO("--> Step 3: Register waypoint V2 event and state callback\r\n");
DjiTest_WidgetLogAppend("--> Step 3: Register waypoint V2 event and state callback\r\n");
returnCode = DjiWaypointV2_RegisterMissionEventCallback(DjiTest_WaypointV2EventCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register waypoint V2 event failed, error code: 0x%08X", returnCode);
goto out;
}
returnCode = DjiWaypointV2_RegisterMissionStateCallback(DjiTest_WaypointV2StateCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register waypoint V2 state failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(timeOutMs);
USER_LOG_INFO("--> Step 4: Upload waypoint V2 mission\r\n");
DjiTest_WidgetLogAppend("--> Step 4: Upload waypoint V2 mission\r\n");
returnCode = DjiTest_WaypointV2UploadMission(missionNum);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Upload waypoint V2 mission failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(timeOutMs);
USER_LOG_INFO("--> Step 5: Start waypoint V2 mission\r\n");
DjiTest_WidgetLogAppend("--> Step 5: Start waypoint V2 mission\r\n");
returnCode = DjiWaypointV2_Start();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Start waypoint V2 mission failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(20 * timeOutMs);
USER_LOG_INFO("--> Step 6: Set global cruise speed\r\n");
DjiTest_WidgetLogAppend("--> Step 6: Set global cruise speed\r\n");
setGlobalCruiseSpeed = 1.5;
returnCode = DjiWaypointV2_SetGlobalCruiseSpeed(setGlobalCruiseSpeed);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set global cruise speed failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(timeOutMs);
USER_LOG_INFO("--> Step 7: Get global cruise speed\r\n");
DjiTest_WidgetLogAppend("--> Step 7: Get global cruise speed\r\n");
returnCode = DjiWaypointV2_GetGlobalCruiseSpeed(&getGlobalCruiseSpeed);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get global cruise speed failed, error code: 0x%08X", returnCode);
goto out;
}
USER_LOG_INFO("Current global cruise speed is %f m/s", getGlobalCruiseSpeed);
osalHandler->TaskSleepMs(timeOutMs);
USER_LOG_INFO("--> Step 8: Pause waypoint V2 for 5 s\r\n");
DjiTest_WidgetLogAppend("--> Step 8: Pause waypoint V2 for 5 s\r\n");
returnCode = DjiWaypointV2_Pause();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Pause waypoint V2 failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(5 * timeOutMs);
USER_LOG_INFO("--> Step 9: Resume waypoint V2\r\n");
DjiTest_WidgetLogAppend("--> Step 9: Resume waypoint V2\r\n");
returnCode = DjiWaypointV2_Resume();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Resume waypoint V2 failed, error code: 0x%08X", returnCode);
goto out;
}
osalHandler->TaskSleepMs(50 * timeOutMs);
USER_LOG_INFO("--> Step 10: Deinit Waypoint V2 sample\r\n");
DjiTest_WidgetLogAppend("--> Step 10: Deinit Waypoint V2 sample\r\n");
out:
returnCode = DjiTest_WaypointV2DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit waypoint V2 sample failed, error code: 0x%08X", returnCode);
}
USER_LOG_INFO("Waypoint V2 sample end");
DjiTest_WidgetLogAppend("Waypoint V2 sample end");
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static T_DJIWaypointV2Action *DjiTest_WaypointV2GenerateWaypointV2Actions(uint16_t actionNum)
{
T_DJIWaypointV2Action *actions = NULL;
uint16_t i;
T_DJIWaypointV2Trigger trigger = {0};
T_DJIWaypointV2SampleReachPointTriggerParam sampleReachPointTriggerParam = {0};
T_DJIWaypointV2Actuator actuator = {0};
T_DJIWaypointV2Action action = {0};
actions = osalHandler->Malloc(actionNum * sizeof(T_DJIWaypointV2Action));
if (actions == NULL) {
return NULL;
}
for (i = 0; i < actionNum; i++) {
sampleReachPointTriggerParam.waypointIndex = i;
sampleReachPointTriggerParam.terminateNum = 0;
trigger.actionTriggerType = DJI_WAYPOINT_V2_ACTION_TRIGGER_TYPE_SAMPLE_REACH_POINT;
trigger.sampleReachPointTriggerParam.terminateNum = sampleReachPointTriggerParam.terminateNum;
trigger.sampleReachPointTriggerParam.waypointIndex = sampleReachPointTriggerParam.waypointIndex;
actuator.actuatorType = DJI_WAYPOINT_V2_ACTION_ACTUATOR_TYPE_CAMERA;
actuator.actuatorIndex = 0;
actuator.cameraActuatorParam.operationType = DJI_WAYPOINT_V2_ACTION_ACTUATOR_CAMERA_OPERATION_TYPE_TAKE_PHOTO;
action.actionId = i;
memcpy(&action.actuator, &actuator, sizeof(actuator));
memcpy(&action.trigger, &trigger, sizeof(trigger));
actions[i] = action;
}
return actions;
}
static void DjiTest_WaypointV2SetDefaultSetting(T_DjiWaypointV2 *waypointV2)
{
waypointV2->waypointType = DJI_WAYPOINT_V2_FLIGHT_PATH_MODE_GO_TO_POINT_IN_STRAIGHT_AND_STOP;
waypointV2->headingMode = DJI_WAYPOINT_V2_HEADING_MODE_AUTO;
waypointV2->config.useLocalMaxVel = 0;
waypointV2->config.useLocalCruiseVel = 0;
waypointV2->dampingDistance = 40;
waypointV2->heading = 0;
waypointV2->turnMode = DJI_WAYPOINT_V2_TURN_MODE_CLOCK_WISE;
waypointV2->pointOfInterest.positionX = 0;
waypointV2->pointOfInterest.positionY = 0;
waypointV2->pointOfInterest.positionZ = 0;
waypointV2->maxFlightSpeed = 9;
waypointV2->autoFlightSpeed = 2;
}
static T_DjiWaypointV2 *DjiTest_WaypointV2GeneratePolygonWaypointV2(dji_f32_t radius, uint16_t polygonNum)
{
// Let's create a vector to store our waypoints in.
T_DjiReturnCode returnCode;
T_DjiWaypointV2 *waypointV2List = (T_DjiWaypointV2 *) osalHandler->Malloc(
(polygonNum + 2) * sizeof(T_DjiWaypointV2));
T_DjiWaypointV2 startPoint;
T_DjiWaypointV2 waypointV2;
T_DjiFcSubscriptionPositionFused positionFused = {0};
T_DjiDataTimestamp timestamp = {0};
osalHandler->TaskSleepMs(1000);
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_POSITION_FUSED,
(uint8_t *) &positionFused,
sizeof(T_DjiFcSubscriptionPositionFused),
&timestamp);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get value of topic GPS Fused error");
} else {
USER_LOG_DEBUG("Timestamp: millisecond %u microsecond %u.", timestamp.millisecond,
timestamp.microsecond);
USER_LOG_DEBUG("Position: %f %f %f %d.", positionFused.latitude, positionFused.longitude,
positionFused.altitude,
positionFused.visibleSatelliteNumber);
}
startPoint.latitude = positionFused.latitude;
startPoint.longitude = positionFused.longitude;
startPoint.relativeHeight = 15;
DjiTest_WaypointV2SetDefaultSetting(&startPoint);
waypointV2List[0] = startPoint;
// Iterative algorithm
for (int i = 0; i < polygonNum; i++) {
dji_f32_t angle = i * 2 * DJI_PI / polygonNum;
DjiTest_WaypointV2SetDefaultSetting(&waypointV2);
dji_f32_t X = radius * cos(angle);
dji_f32_t Y = radius * sin(angle);
waypointV2.latitude = X / TEST_EARTH_RADIUS + startPoint.latitude;
waypointV2.longitude = Y / (TEST_EARTH_RADIUS * cos(startPoint.latitude)) + startPoint.longitude;
waypointV2.relativeHeight = startPoint.relativeHeight;
waypointV2List[i + 1] = waypointV2;
}
waypointV2List[polygonNum + 1] = startPoint;
return waypointV2List;
}
uint8_t DJiTest_WaypointV2GetMissionEventIndex(uint8_t eventID)
{
uint8_t i;
for (i = 0; i < sizeof(s_waypointV2EventStr) / sizeof(T_DjiTestWaypointV2EventStr); i++) {
if (s_waypointV2EventStr[i].eventID == eventID) {
return i;
}
}
return i;
}
uint8_t DjiTest_WaypointV2GetMissionStateIndex(uint8_t state)
{
uint8_t i;
for (i = 0; i < sizeof(s_waypointV2StateStr) / sizeof(T_DjiTestWaypointV2StateStr); i++) {
if (s_waypointV2StateStr[i].missionState == state) {
return i;
}
}
return i;
}
static T_DjiReturnCode DjiTest_WaypointV2EventCallback(T_DjiWaypointV2MissionEventPush eventData)
{
if (eventData.event == 0x01) {
USER_LOG_INFO("[%s]: Mission interrupted reason is 0x%x",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.interruptReason);
} else if (eventData.event == 0x02) {
USER_LOG_INFO("[%s]: Mission recover reason is 0x%x",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.recoverProcess);
} else if (eventData.event == 0x03) {
USER_LOG_INFO("[%s]: Mission exit reason is 0x%x",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.exitReason);
} else if (eventData.event == 0x10) {
USER_LOG_INFO("[%s]: Current waypoint index is %d",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.waypointIndex);
} else if (eventData.event == 0x11) {
USER_LOG_INFO("[%s]: Current mission execute times is %d",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.T_DjiWaypointV2MissionExecEvent.currentMissionExecTimes);
} else if (eventData.event == 0x12) {
USER_LOG_INFO("[%s]: avoid obstacle state:%d",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.avoidState);
} else if (eventData.event == 0x30) {
USER_LOG_INFO(
"[%s]: action id:%d, pre actuator state:%d, current actuator state:%d, result:0x%08llX",
s_waypointV2EventStr[DJiTest_WaypointV2GetMissionEventIndex(eventData.event)].eventStr,
eventData.data.T_DjiWaypointV2ActionExecEvent.actionId,
eventData.data.T_DjiWaypointV2ActionExecEvent.preActuatorState,
eventData.data.T_DjiWaypointV2ActionExecEvent.curActuatorState,
eventData.data.T_DjiWaypointV2ActionExecEvent.result
);
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV2StateCallback(T_DjiWaypointV2MissionStatePush stateData)
{
static uint32_t curMs = 0;
static uint32_t preMs = 0;
osalHandler->GetTimeMs(&curMs);
if (curMs - preMs >= 1000) {
preMs = curMs;
USER_LOG_INFO("[Waypoint Index:%d]: State: %s, velocity:%.2f m/s",
stateData.curWaypointIndex,
s_waypointV2StateStr[DjiTest_WaypointV2GetMissionStateIndex(stateData.state)].stateStr,
(dji_f32_t) stateData.velocity / 100);
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV2Init(void)
{
T_DjiReturnCode returnCode;
osalHandler = DjiPlatform_GetOsalHandler();
if (!osalHandler) return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
returnCode = DjiFcSubscription_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init waypoint V2 data subscription module error, stat:0x%08llX", returnCode);
return returnCode;
}
returnCode = DjiWaypointV2_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init waypoint V2 module error, stat:0x%08llX", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV2DeInit(void)
{
T_DjiReturnCode returnCode;
returnCode = DjiFcSubscription_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit waypoint V2 data subscription module error, stat:0x%08llX", returnCode);
return returnCode;
}
returnCode = DjiWaypointV2_Deinit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Deinit waypoint V2 module error, stat:0x%08llX", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV2UploadMission(uint16_t missionNum)
{
T_DjiReturnCode returnCode;
uint16_t polygonNum = missionNum - 2;
dji_f32_t radius = 6;
uint16_t actionNum = 5;
T_DjiWayPointV2MissionSettings missionInitSettings = {0};
T_DJIWaypointV2ActionList actionList = {NULL, 0};
/*! Generate actions*/
actionList.actions = DjiTest_WaypointV2GenerateWaypointV2Actions(actionNum);
actionList.actionNum = actionNum;
/*! Init waypoint settings*/
missionInitSettings.missionID = s_missionID + 10;
USER_LOG_DEBUG("Generate mission id:%d", missionInitSettings.missionID);
missionInitSettings.repeatTimes = 1;
missionInitSettings.finishedAction = DJI_WAYPOINT_V2_FINISHED_GO_HOME;
missionInitSettings.maxFlightSpeed = 10;
missionInitSettings.autoFlightSpeed = 2;
missionInitSettings.actionWhenRcLost = DJI_WAYPOINT_V2_MISSION_KEEP_EXECUTE_WAYPOINT_V2;
missionInitSettings.gotoFirstWaypointMode = DJI_WAYPOINT_V2_MISSION_GO_TO_FIRST_WAYPOINT_MODE_POINT_TO_POINT;
missionInitSettings.mission = DjiTest_WaypointV2GeneratePolygonWaypointV2(radius, polygonNum);
missionInitSettings.missTotalLen = missionNum;
missionInitSettings.actionList = actionList;
returnCode = DjiWaypointV2_UploadMission(&missionInitSettings);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init waypoint V2 mission setting failed, ErrorCode:0x%lX", returnCode);
goto out;
}
out:
osalHandler->Free(actionList.actions);
return returnCode;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,49 @@
/**
********************************************************************
* @file test_waypoint_v2.h
* @brief This is the header file for "test_waypoint_v2.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 TEST_WAYPOINT_V2_H
#define TEST_WAYPOINT_V2_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_WaypointV2RunSample(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_WAYPOINT_V2_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,260 @@
/**
********************************************************************
* @file test_waypoint_v3.c
* @brief
*
* @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.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <utils/util_file.h>
#include <utils/util_misc.h>
#include "test_waypoint_v3.h"
#include "dji_logger.h"
#include "dji_waypoint_v3.h"
#include "waypoint_file_c/waypoint_v3_test_file_kmz.h"
#include "dji_fc_subscription.h"
/* Private constants ---------------------------------------------------------*/
#define DJI_TEST_WAYPOINT_V3_KMZ_FILE_PATH_LEN_MAX (256)
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiWaypointV3MissionState s_lastWaypointV3MissionState = {0};
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTest_WaypointV3MissionStateCallback(T_DjiWaypointV3MissionState missionState);
static T_DjiReturnCode DjiTest_WaypointV3ActionStateCallback(T_DjiWaypointV3ActionState actionState);
static T_DjiReturnCode DjiTest_WaypointV3WaitEndFlightStatus(T_DjiFcSubscriptionFlightStatus status);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_WaypointV3RunSample(void)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiFcSubscriptionFlightStatus flightStatus = 0;
T_DjiDataTimestamp flightStatusTimestamp = {0};
#ifdef SYSTEM_ARCH_LINUX
FILE *kmzFile = NULL;
uint32_t kmzFileSize = 0;
uint8_t *kmzFileBuf;
uint16_t readLen;
char curFileDirPath[DJI_TEST_WAYPOINT_V3_KMZ_FILE_PATH_LEN_MAX];
char tempPath[DJI_TEST_WAYPOINT_V3_KMZ_FILE_PATH_LEN_MAX];
returnCode = DjiWaypointV3_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Waypoint v3 init failed.");
return returnCode;
}
returnCode = DjiWaypointV3_RegMissionStateCallback(DjiTest_WaypointV3MissionStateCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register waypoint v3 state callback failed.");
goto out;
}
returnCode = DjiWaypointV3_RegActionStateCallback(DjiTest_WaypointV3ActionStateCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register waypoint v3 action state callback failed.");
goto out;
}
returnCode = DjiUserUtil_GetCurrentFileDirPath(__FILE__, DJI_TEST_WAYPOINT_V3_KMZ_FILE_PATH_LEN_MAX,
curFileDirPath);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", returnCode);
goto out;
}
/*! Attention: suggest use the exported kmz file by DJI pilot. If use this test file, you need set the longitude as
* 113.94255, latitude as 22.57765 on DJI Assistant 2 simulator */
snprintf(tempPath, DJI_TEST_WAYPOINT_V3_KMZ_FILE_PATH_LEN_MAX, "%s/waypoint_file/waypoint_v3_test_file.kmz",
curFileDirPath);
kmzFile = fopen(tempPath, "r");
if (kmzFile == NULL) {
USER_LOG_ERROR("Open kmz file failed.");
goto out;
}
returnCode = UtilFile_GetFileSize(kmzFile, &kmzFileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get kmz file size failed.");
goto close_file;
}
kmzFileBuf = osalHandler->Malloc(kmzFileSize);
if (kmzFileBuf == NULL) {
USER_LOG_ERROR("Malloc kmz file buf error.");
goto close_file;
}
readLen = fread(kmzFileBuf, 1, kmzFileSize, kmzFile);
if (readLen != kmzFileSize) {
USER_LOG_ERROR("Read kmz file data failed.");
goto close_file;
}
returnCode = DjiWaypointV3_UploadKmzFile(kmzFileBuf, kmzFileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Upload kmz file failed.");
goto close_file;
}
osalHandler->Free(kmzFileBuf);
#else
returnCode = DjiWaypointV3_UploadKmzFile(waypoint_v3_test_file_kmz_fileBinaryArray,
waypoint_v3_test_file_kmz_fileSize);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Upload kmz file binary array failed.");
return returnCode;
}
#endif
USER_LOG_INFO("Execute start action");
returnCode = DjiWaypointV3_Action(DJI_WAYPOINT_V3_ACTION_START);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Execute start action failed.");
goto close_file;
}
close_file:
#ifdef SYSTEM_ARCH_LINUX
returnCode = fclose(kmzFile);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Close KMZ file failed.");
}
kmzFile = NULL;
#endif
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
DJI_DATA_SUBSCRIPTION_TOPIC_10_HZ,
NULL);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Subscribe topic flight status failed, error code:0x%08llX", returnCode);
goto out;
}
USER_LOG_INFO("The aircraft is on the ground and motors are stoped...");
returnCode = DjiTest_WaypointV3WaitEndFlightStatus(DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_STOPED);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Wait end flight status error.");
goto out;
}
USER_LOG_INFO("The aircraft is on the ground and motors are rotating...");
returnCode = DjiTest_WaypointV3WaitEndFlightStatus(DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_ON_GROUND);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Wait end flight status error.");
goto out;
}
USER_LOG_INFO("The aircraft is in the air...");
returnCode = DjiTest_WaypointV3WaitEndFlightStatus(DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_IN_AIR);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Wait end flight status error.");
goto out;
}
USER_LOG_INFO("The aircraft is on the ground and motors are rotating...");
returnCode = DjiTest_WaypointV3WaitEndFlightStatus(DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_ON_GROUND);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Wait end flight status error.");
goto out;
}
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
(uint8_t *) &flightStatus,
sizeof(T_DjiFcSubscriptionFlightStatus),
&flightStatusTimestamp);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get value of topic flight status failed, error code:0x%08llX", returnCode);
goto out;
}
if (flightStatus != DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_STOPED) {
USER_LOG_ERROR("Aircraft's flight status error, motors are not stoped.");
goto out;
}
USER_LOG_INFO("The aircraft is on the ground now, and motor are stoped.");
out:
#ifdef SYSTEM_ARCH_LINUX
if (kmzFile != NULL) {
fclose(kmzFile);
}
#endif
return DjiWaypointV3_DeInit();
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTest_WaypointV3MissionStateCallback(T_DjiWaypointV3MissionState missionState)
{
if (s_lastWaypointV3MissionState.state == missionState.state
&& s_lastWaypointV3MissionState.currentWaypointIndex == missionState.currentWaypointIndex
&& s_lastWaypointV3MissionState.wayLineId == missionState.wayLineId) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
USER_LOG_INFO("Waypoint v3 mission state: %d, current waypoint index: %d, wayLine id: %d", missionState.state,
missionState.currentWaypointIndex, missionState.wayLineId);
memcpy(&s_lastWaypointV3MissionState, &missionState, sizeof(T_DjiWaypointV3MissionState));
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV3ActionStateCallback(T_DjiWaypointV3ActionState actionState)
{
USER_LOG_INFO(
"Waypoint v3 action state: %d, current waypoint index: %d, wayLine id: %d, action group: %d, action id: %d",
actionState.state,
actionState.currentWaypointIndex, actionState.wayLineId,
actionState.actionGroupId, actionState.actionId);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTest_WaypointV3WaitEndFlightStatus(T_DjiFcSubscriptionFlightStatus status) {
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
T_DjiDataTimestamp flightStatusTimestamp = {0};
T_DjiFcSubscriptionFlightStatus flightStatus = 0;
do {
osalHandler->TaskSleepMs(20);
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
(uint8_t *)&flightStatus,
sizeof(T_DjiFcSubscriptionFlightStatus),
&flightStatusTimestamp);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get value of topic flight status failed, error code:0x%08llX", returnCode);
}
} while(flightStatus == status);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,49 @@
/**
********************************************************************
* @file test_waypoint_v3.h
* @brief This is the header file for "test_waypoint_v3.c", 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 TEST_WAYPOINT_V3_H
#define TEST_WAYPOINT_V3_H
/* Includes ------------------------------------------------------------------*/
#include "dji_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_WaypointV3RunSample(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_WAYPOINT_V3_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,255 @@
/* Generated by file2c, do not edit manually */
#ifndef __waypoint_v3_test_file_kmz_h_included
#define __waypoint_v3_test_file_kmz_h_included
#include <stdint.h>
/* Contents of file waypoint_v3_test_file.kmz */
#define waypoint_v3_test_file_kmz_fileName "waypoint_v3_test_file.kmz"
#define waypoint_v3_test_file_kmz_fileSize 3856
static const uint8_t waypoint_v3_test_file_kmz_fileBinaryArray[3856] = {
0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x08, 0x08, 0x08, 0x00, 0x8A, 0x81, 0x3E, 0x56, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x77, 0x70,
0x6D, 0x7A, 0x2F, 0x74, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65, 0x2E, 0x6B, 0x6D, 0x6C, 0xED,
0x5C, 0xCD, 0x72, 0xDB, 0x36, 0x10, 0xBE, 0xE7, 0x29, 0x3C, 0x3E, 0xA7, 0x12, 0x00, 0xFE, 0x80,
0xCC, 0x28, 0xCC, 0xA4, 0x76, 0xEC, 0x64, 0x26, 0x6D, 0x34, 0x91, 0x53, 0x4F, 0x8F, 0x30, 0x05,
0x49, 0xA8, 0x49, 0x42, 0x25, 0xC1, 0xC8, 0xCE, 0xB1, 0xA7, 0x3E, 0x4B, 0xDF, 0xA0, 0x4F, 0xD4,
0x3E, 0x46, 0xC1, 0x3F, 0x89, 0xA0, 0x40, 0xC5, 0x36, 0xE3, 0xD4, 0x96, 0xE9, 0x83, 0x47, 0xC2,
0xEE, 0x7E, 0xF8, 0xDB, 0xFD, 0x16, 0x00, 0x41, 0x8D, 0x5E, 0x5D, 0x85, 0xC1, 0xC1, 0x67, 0x1A,
0x27, 0x8C, 0x47, 0x2F, 0x0F, 0xE1, 0x00, 0x1C, 0x1E, 0xD0, 0xC8, 0xE7, 0x53, 0x16, 0xCD, 0x5F,
0x1E, 0x7E, 0x3A, 0x3B, 0xF9, 0xC1, 0x39, 0x7C, 0xE5, 0x3D, 0x1B, 0x5D, 0x4A, 0x2D, 0xA9, 0x19,
0x25, 0x2F, 0x0F, 0x17, 0x42, 0x2C, 0x5F, 0x0C, 0x87, 0xAB, 0xD5, 0x6A, 0xC0, 0x97, 0x34, 0x9A,
0xB3, 0x64, 0x10, 0x51, 0x31, 0x94, 0x1A, 0x43, 0x34, 0x40, 0x87, 0x85, 0xDA, 0x8B, 0xD5, 0x32,
0x0C, 0x14, 0xDD, 0xE9, 0x6F, 0x6C, 0xE0, 0xF3, 0x70, 0x28, 0x05, 0x5F, 0x86, 0xB2, 0x9E, 0x81,
0x71, 0xE8, 0x3D, 0x3B, 0x38, 0x18, 0x1D, 0x73, 0x3F, 0x0D, 0x69, 0x24, 0xB2, 0x2F, 0xF2, 0x6B,
0x66, 0xF7, 0xC2, 0x8F, 0x29, 0x11, 0xF4, 0x8C, 0x85, 0xD4, 0x83, 0x36, 0xB6, 0x80, 0x6D, 0x23,
0xD3, 0x76, 0x0C, 0x67, 0x34, 0x6C, 0x8A, 0x6B, 0x46, 0xE9, 0x72, 0xDA, 0x30, 0x32, 0x90, 0x83,
0x5D, 0x58, 0x1A, 0xD5, 0xC4, 0x35, 0xA3, 0x90, 0x25, 0x59, 0xCF, 0x8F, 0x78, 0x34, 0x63, 0xF3,
0x42, 0x50, 0x89, 0x66, 0xC1, 0xF5, 0x19, 0x3F, 0x27, 0xD7, 0x01, 0x8B, 0xE8, 0x4F, 0x7C, 0x4A,
0xBD, 0x84, 0xCC, 0x68, 0x70, 0x5D, 0xC2, 0x6D, 0x49, 0x55, 0x5B, 0x16, 0xB1, 0x64, 0xF1, 0xDA,
0x17, 0x12, 0xDB, 0x9B, 0xF3, 0xB7, 0x3C, 0xA4, 0x95, 0x5D, 0x5D, 0xA2, 0xD8, 0xD0, 0x2B, 0x26,
0x3E, 0x44, 0x1F, 0x8F, 0xDE, 0xF3, 0x44, 0x78, 0xF4, 0x8A, 0xFA, 0xA9, 0xA0, 0xD9, 0xE7, 0x42,
0xB7, 0x34, 0x57, 0x94, 0x1A, 0xE6, 0xB9, 0x45, 0x21, 0x5A, 0xD7, 0xFC, 0x23, 0xF1, 0x2F, 0xD7,
0xA6, 0xDB, 0x0A, 0x0A, 0x82, 0x20, 0x97, 0xF4, 0xC3, 0x6C, 0x36, 0x91, 0x6A, 0x31, 0x13, 0xD7,
0x6F, 0x29, 0x9B, 0x2F, 0x84, 0x87, 0x40, 0x69, 0xAF, 0x17, 0x2B, 0x08, 0xF3, 0x80, 0x5F, 0x90,
0xE0, 0x2C, 0x26, 0x51, 0xC2, 0x32, 0x7C, 0x12, 0x4C, 0x96, 0x94, 0x4E, 0x3D, 0x68, 0x95, 0x18,
0x6D, 0x0A, 0x0A, 0xCA, 0x34, 0xE6, 0x11, 0x7D, 0x17, 0xCD, 0x78, 0x55, 0xAC, 0x08, 0xDE, 0x44,
0x69, 0xF8, 0x0B, 0x09, 0x52, 0xEA, 0x61, 0x5C, 0xA2, 0x36, 0xCA, 0x75, 0x56, 0x93, 0xF4, 0x62,
0xA3, 0x00, 0xEA, 0x76, 0x8A, 0xA4, 0x6A, 0xC7, 0x50, 0xDF, 0x90, 0x02, 0x70, 0x29, 0x67, 0x9D,
0x93, 0xA9, 0xAE, 0x85, 0xA5, 0x68, 0x03, 0x68, 0xDB, 0x25, 0xD6, 0x96, 0x44, 0x6F, 0xA9, 0x6D,
0xA7, 0x4E, 0xA6, 0x37, 0x1F, 0xF3, 0x62, 0x5C, 0xDF, 0x45, 0x53, 0x7A, 0xD5, 0xB4, 0x57, 0x85,
0x6A, 0x57, 0xB7, 0xFA, 0x54, 0x96, 0x6B, 0xE2, 0x63, 0x74, 0xC2, 0x83, 0x29, 0x8D, 0x1B, 0xBE,
0x43, 0xC3, 0x65, 0x90, 0xC5, 0xD7, 0xF5, 0x92, 0x7A, 0x2B, 0x72, 0xBD, 0xE4, 0x2C, 0x12, 0x95,
0xE3, 0xD4, 0x65, 0x5A, 0xAB, 0x77, 0xD3, 0x75, 0x5B, 0x6B, 0x45, 0x8A, 0xEA, 0xAA, 0x08, 0xB5,
0x23, 0xCE, 0x63, 0xC9, 0x4D, 0x52, 0x61, 0x72, 0x9D, 0x8C, 0x49, 0x4C, 0xC2, 0xE6, 0x48, 0xF8,
0x6B, 0x8D, 0x3C, 0x2C, 0xCF, 0x4F, 0x27, 0x8E, 0x59, 0xF1, 0x86, 0x2A, 0x6A, 0x18, 0x2E, 0x72,
0x87, 0xCE, 0x25, 0x31, 0x95, 0x4D, 0x60, 0x9F, 0xE9, 0x19, 0x9F, 0x08, 0x12, 0x8B, 0x71, 0xAD,
0x33, 0x35, 0xAD, 0xE6, 0x14, 0x94, 0xC3, 0x2B, 0x99, 0x33, 0xEF, 0xE9, 0xE9, 0x78, 0x52, 0x0D,
0x6E, 0x43, 0xA2, 0x0E, 0xFD, 0x57, 0x7B, 0x56, 0xC0, 0x93, 0x54, 0xF0, 0x93, 0x20, 0xAB, 0xBC,
0x08, 0x99, 0x2A, 0xA4, 0x9A, 0xE5, 0x9A, 0x80, 0x2C, 0x43, 0x15, 0x02, 0xA0, 0x84, 0xA1, 0x2E,
0x82, 0x7D, 0x12, 0xB0, 0x02, 0xED, 0x4D, 0x44, 0x2E, 0x82, 0x8D, 0x0F, 0x6E, 0x09, 0xD4, 0x7A,
0x58, 0x28, 0x01, 0xC7, 0x4C, 0xF8, 0x8B, 0x7C, 0x68, 0x42, 0x12, 0xA5, 0x24, 0xA8, 0x6A, 0x6B,
0x08, 0x35, 0x2D, 0x3C, 0x2F, 0x3D, 0xE6, 0x2D, 0x25, 0x59, 0xE6, 0xD1, 0x4E, 0xEC, 0x4A, 0xD5,
0xC9, 0xA1, 0x66, 0x3C, 0x08, 0xF8, 0xAA, 0xA4, 0xE1, 0xCD, 0x78, 0x6E, 0xE9, 0xED, 0x86, 0x7A,
0x1D, 0xCD, 0x6B, 0x3D, 0xD5, 0x0A, 0x5B, 0x00, 0xA4, 0x67, 0xE4, 0xCE, 0xE1, 0x81, 0x01, 0xC8,
0xFF, 0x9E, 0x6F, 0x7D, 0x68, 0xA0, 0xAE, 0x2D, 0x76, 0x37, 0x49, 0xEA, 0xA8, 0x31, 0xDC, 0x26,
0x57, 0x7D, 0xE9, 0xEB, 0xA3, 0xA9, 0x1B, 0xF5, 0xB3, 0x34, 0x8E, 0xF2, 0x61, 0x12, 0x3C, 0x6F,
0xDB, 0xEB, 0x68, 0x3A, 0x11, 0x7C, 0x79, 0xCE, 0xC4, 0xE2, 0x98, 0x25, 0x3E, 0x8F, 0x04, 0x8B,
0x52, 0x49, 0xF9, 0x47, 0x69, 0xFC, 0x99, 0x88, 0x34, 0xA6, 0xDA, 0xDA, 0xD6, 0x28, 0x9A, 0x9A,
0x3E, 0x25, 0x74, 0x22, 0x62, 0x92, 0xB9, 0xCF, 0x7B, 0x39, 0x53, 0x1E, 0x54, 0x10, 0x9A, 0xD2,
0x0A, 0x60, 0x1C, 0x10, 0x9F, 0x86, 0x24, 0xBE, 0xAC, 0x0D, 0x56, 0x63, 0xF0, 0x64, 0xC9, 0x26,
0xAA, 0x93, 0x7A, 0xF9, 0xC1, 0x01, 0x84, 0xC6, 0xC0, 0x35, 0x0D, 0x88, 0x0C, 0x8C, 0x5D, 0x0B,
0x98, 0xCF, 0x11, 0x1A, 0x58, 0x18, 0x9B, 0xAE, 0xE1, 0x3A, 0xB6, 0x69, 0xD7, 0x31, 0x86, 0x5A,
0x90, 0xD1, 0x50, 0x3B, 0x55, 0x4C, 0x99, 0x18, 0x56, 0x9F, 0x86, 0x75, 0x32, 0x0E, 0x02, 0xB6,
0x4C, 0x38, 0x9B, 0x6E, 0x85, 0x5E, 0x53, 0xA2, 0x25, 0xA1, 0x9A, 0xFE, 0x42, 0xAB, 0x96, 0x26,
0xF4, 0x54, 0x09, 0xED, 0x6A, 0x91, 0xD3, 0x28, 0x6F, 0x33, 0x2B, 0xD3, 0x72, 0xD3, 0x4A, 0x61,
0x10, 0x4D, 0x5D, 0x35, 0x77, 0xD2, 0xD4, 0xD8, 0x1E, 0xBA, 0x6B, 0xA5, 0xCC, 0x47, 0x5A, 0xEC,
0x37, 0xA2, 0x6D, 0x63, 0xC5, 0x3B, 0xC0, 0xC6, 0x52, 0xE7, 0x35, 0x6B, 0xBE, 0xCC, 0x57, 0x38,
0xA7, 0x31, 0x4F, 0x97, 0x8A, 0xBB, 0x34, 0x85, 0xB5, 0xDC, 0xA3, 0x96, 0xEE, 0x32, 0xCA, 0xD3,
0x82, 0x1A, 0xA0, 0x7A, 0xE9, 0x2E, 0x90, 0x37, 0xD1, 0xB4, 0x15, 0x62, 0x2D, 0xDB, 0x05, 0x50,
0xAC, 0x4A, 0xE9, 0xEF, 0xA9, 0x5C, 0xB1, 0xD3, 0x6D, 0x0C, 0x95, 0xF9, 0x54, 0xFB, 0xB3, 0x98,
0xCD, 0xE7, 0x9B, 0x24, 0xDE, 0xAA, 0x90, 0xE7, 0x2B, 0xB9, 0xDC, 0xF6, 0x17, 0xF5, 0x24, 0xB8,
0xAD, 0xA2, 0x04, 0xD3, 0xEE, 0x7A, 0xEA, 0xB5, 0xB4, 0xD7, 0xBF, 0x35, 0x2D, 0xEA, 0x8C, 0xA8,
0xCA, 0x72, 0x35, 0x9B, 0x12, 0xC1, 0xE3, 0x93, 0x34, 0xF2, 0xBD, 0x6C, 0x9D, 0x3A, 0x5E, 0x70,
0xC1, 0x15, 0x73, 0x45, 0xE5, 0x46, 0x40, 0x0D, 0x67, 0xAC, 0x2B, 0xCF, 0x58, 0x20, 0xD7, 0x8D,
0xB3, 0x19, 0xBB, 0xF2, 0xFE, 0xFD, 0xF3, 0xAF, 0x7F, 0xFE, 0xF8, 0xBB, 0xF2, 0xE6, 0x9A, 0x40,
0x6B, 0x78, 0xE7, 0x65, 0x9A, 0x0A, 0xB3, 0x0E, 0x9A, 0x71, 0x61, 0xF2, 0x9E, 0x46, 0x89, 0x8A,
0xD5, 0xAE, 0xA1, 0xF6, 0xBD, 0x6D, 0x88, 0xB6, 0x3A, 0xAF, 0x68, 0xD6, 0x29, 0xB2, 0x2D, 0xD8,
0x24, 0x79, 0x36, 0xE9, 0xFB, 0x5B, 0x11, 0x3A, 0xB0, 0x4D, 0x64, 0x9A, 0xD0, 0x29, 0x08, 0x5D,
0xEE, 0xF3, 0x0C, 0xD3, 0x72, 0x80, 0x8D, 0x60, 0x47, 0x4A, 0x87, 0x3D, 0xA5, 0xEF, 0x0B, 0xA5,
0xC3, 0x2E, 0x94, 0xAE, 0x31, 0xBE, 0x2D, 0xA5, 0x6B, 0x20, 0x7A, 0x4A, 0xBF, 0x33, 0xA5, 0x27,
0xD9, 0xE8, 0x7F, 0xA4, 0xBE, 0x0C, 0xE8, 0xEF, 0x48, 0xEA, 0xE8, 0xA9, 0x92, 0xFA, 0xF7, 0x98,
0x50, 0xBE, 0xBC, 0xEF, 0xF9, 0xEC, 0x38, 0x2D, 0x8F, 0x31, 0x35, 0x22, 0x03, 0xD8, 0xAE, 0x09,
0x1C, 0x6C, 0x95, 0xA9, 0x11, 0x02, 0x68, 0xC8, 0x7F, 0x26, 0xB4, 0x3A, 0xA6, 0x46, 0xD4, 0xA7,
0xC6, 0x7D, 0x49, 0x8D, 0xA8, 0x4B, 0x6A, 0xD4, 0x18, 0xDF, 0x36, 0x35, 0x6A, 0x20, 0xFA, 0xD4,
0x78, 0x67, 0x26, 0x2D, 0x0E, 0xD7, 0x3E, 0x72, 0x21, 0x83, 0xF9, 0xFE, 0xB8, 0xB4, 0x5E, 0x4B,
0x3E, 0xD0, 0xE4, 0x22, 0xE1, 0x41, 0x2A, 0x68, 0x7E, 0x3A, 0xA6, 0x9C, 0xF3, 0xD5, 0x94, 0x76,
0x40, 0xE5, 0xA7, 0x81, 0x85, 0x6A, 0x79, 0x9E, 0x08, 0x15, 0x94, 0x6D, 0xF9, 0xCD, 0xC0, 0xD4,
0xA3, 0xBC, 0x16, 0xF1, 0xCE, 0x2E, 0x06, 0x81, 0x52, 0x2D, 0x68, 0x74, 0xAE, 0x21, 0xBE, 0x11,
0x94, 0xAE, 0x51, 0x4D, 0xE9, 0x0E, 0xA0, 0x5F, 0xC9, 0x6A, 0x47, 0x93, 0x9A, 0xD2, 0x9B, 0x00,
0xE9, 0x1A, 0xD4, 0x10, 0x7E, 0xD5, 0x0D, 0xB2, 0x27, 0x69, 0x2D, 0x63, 0xD4, 0x10, 0xDF, 0x08,
0xAA, 0x15, 0xA4, 0x4F, 0xEE, 0x65, 0x72, 0x87, 0x36, 0x46, 0x10, 0x39, 0x0E, 0xC2, 0x55, 0x72,
0x87, 0xAE, 0x6B, 0x20, 0x17, 0xBA, 0xB8, 0x63, 0x72, 0x37, 0xFA, 0xE4, 0xBE, 0x2F, 0xC9, 0xDD,
0xE8, 0x92, 0xDC, 0x35, 0xC6, 0xB7, 0x4D, 0xEE, 0x1A, 0x88, 0x3E, 0xB9, 0xDF, 0x39, 0xB9, 0x7F,
0xE1, 0x3C, 0xBC, 0xC7, 0x0D, 0x2F, 0xF7, 0x49, 0x20, 0xF7, 0x90, 0x73, 0xB1, 0xF0, 0xCC, 0xEA,
0x6E, 0x45, 0xBD, 0x50, 0x6B, 0xC5, 0x92, 0x4F, 0x09, 0x3D, 0xC9, 0xB4, 0x4E, 0x64, 0x6D, 0x3C,
0xDE, 0x3C, 0x08, 0x69, 0x0A, 0x7A, 0xE2, 0x2E, 0x89, 0x1B, 0x62, 0x49, 0xD5, 0x06, 0x2E, 0x1F,
0x40, 0xD9, 0xD8, 0xB0, 0x91, 0x2B, 0xC9, 0xDC, 0x72, 0x3B, 0xF2, 0xB6, 0xD9, 0xF3, 0xF6, 0xBE,
0xF0, 0xB6, 0xD9, 0x85, 0xB7, 0x35, 0xC6, 0xB7, 0xE5, 0x6D, 0x0D, 0x44, 0xCF, 0xDB, 0x8F, 0xEA,
0x11, 0x54, 0x75, 0x1F, 0xA4, 0x3F, 0xAD, 0xFC, 0xE6, 0xD3, 0xF9, 0xFF, 0x1C, 0x3F, 0xF7, 0x13,
0xDA, 0x1F, 0x3F, 0x3F, 0xE8, 0x51, 0xEC, 0x8F, 0x9E, 0xFA, 0xA3, 0xA7, 0xFE, 0xE8, 0x69, 0x0F,
0x03, 0xBB, 0xDF, 0x76, 0xEE, 0xC5, 0xB6, 0x13, 0xB9, 0x06, 0x30, 0xA0, 0x55, 0xDD, 0x7B, 0x34,
0x2C, 0x80, 0x10, 0x80, 0x96, 0xDD, 0xF5, 0xE6, 0x63, 0xB5, 0x30, 0xE9, 0xB7, 0x9D, 0x8F, 0x7E,
0xDB, 0x69, 0x6D, 0xFB, 0xE5, 0xCD, 0xB7, 0x9D, 0x1A, 0xE3, 0xDB, 0x6E, 0x3B, 0x35, 0x10, 0xFD,
0xB6, 0xF3, 0xCE, 0xBC, 0xED, 0xA7, 0x72, 0x61, 0x1B, 0x1E, 0xB3, 0xF8, 0x67, 0x12, 0xDE, 0xE3,
0x8A, 0xEC, 0x29, 0x72, 0xA9, 0x65, 0x01, 0x68, 0x60, 0x60, 0x96, 0xCF, 0x5E, 0xB0, 0x6B, 0x5B,
0x10, 0x62, 0xE0, 0x5A, 0x5D, 0x9F, 0xBD, 0xD8, 0x3D, 0x99, 0x3E, 0x48, 0x32, 0xBD, 0xBF, 0x3B,
0x3A, 0x08, 0xB8, 0x00, 0xC9, 0xB4, 0x0C, 0x0B, 0x57, 0x72, 0x2C, 0xC3, 0xC8, 0x8E, 0x88, 0x2D,
0xD0, 0xD5, 0x95, 0x70, 0xEF, 0x4A, 0x0F, 0xD2, 0x95, 0xEE, 0x90, 0x97, 0xED, 0x2E, 0x79, 0x19,
0x77, 0xCF, 0xCB, 0x1A, 0x88, 0x07, 0x95, 0x97, 0xC3, 0x34, 0x10, 0x6C, 0x19, 0xD0, 0x63, 0x96,
0x08, 0xD2, 0xAC, 0xAA, 0x25, 0x3B, 0x6B, 0xD1, 0xCA, 0xA9, 0x07, 0x3A, 0x80, 0xDD, 0xF9, 0x68,
0x3F, 0x8F, 0x95, 0xF7, 0xEE, 0x30, 0xF1, 0x7F, 0x58, 0x2C, 0xC8, 0x7D, 0x97, 0xE9, 0xB8, 0xC8,
0xC1, 0xE5, 0x0B, 0x0A, 0x8E, 0x09, 0x4D, 0xC3, 0x42, 0x06, 0x80, 0x4E, 0x47, 0x86, 0x77, 0x7A,
0x86, 0x7F, 0x90, 0x0C, 0x7F, 0x7F, 0xEF, 0xBA, 0x20, 0x60, 0x42, 0x60, 0xB8, 0x6E, 0xB5, 0xEC,
0x44, 0x8E, 0x69, 0xB8, 0x08, 0xBB, 0x5D, 0x3D, 0xC9, 0xED, 0x3D, 0xE9, 0x69, 0x79, 0x12, 0xC2,
0xB6, 0x09, 0x5D, 0x8C, 0xAA, 0xAB, 0xE1, 0xD8, 0x74, 0x11, 0x82, 0x8E, 0x2C, 0xE9, 0x7A, 0x1C,
0xB4, 0x4E, 0x9E, 0xBD, 0x2F, 0x3D, 0x15, 0x5F, 0x32, 0x90, 0x4C, 0x72, 0xC0, 0xB2, 0xCB, 0x2D,
0x0C, 0x06, 0x96, 0xE5, 0xBA, 0x8E, 0x6D, 0x5B, 0x46, 0x57, 0x5F, 0xEA, 0x5F, 0xC1, 0x7B, 0x62,
0xBE, 0x24, 0x39, 0x09, 0x9B, 0x16, 0x34, 0x9D, 0xEA, 0x95, 0x15, 0x1B, 0x5A, 0x8E, 0xED, 0x22,
0xC3, 0xE9, 0xFC, 0x36, 0x67, 0xFF, 0xCE, 0xCA, 0x53, 0xF3, 0x25, 0xEC, 0x58, 0x0E, 0xC6, 0xB0,
0x5A, 0x78, 0x63, 0xCB, 0x34, 0x6C, 0xDB, 0x31, 0xB0, 0xDD, 0x75, 0xB9, 0x04, 0xFB, 0x2B, 0xD2,
0x8F, 0xC7, 0x97, 0x94, 0xBD, 0xAA, 0xAE, 0x8E, 0x6F, 0xF4, 0x63, 0x49, 0x35, 0xEC, 0xD1, 0x70,
0xF3, 0xA3, 0x48, 0xA3, 0xE1, 0xE6, 0x27, 0xCD, 0x46, 0xD9, 0xCF, 0xA2, 0x79, 0xCF, 0xFE, 0x03,
0x50, 0x4B, 0x07, 0x08, 0xF2, 0xB2, 0xDF, 0xE7, 0xD1, 0x06, 0x00, 0x00, 0x66, 0x4D, 0x00, 0x00,
0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x08, 0x08, 0x08, 0x00, 0x8A, 0x81, 0x3E, 0x56, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x77, 0x70,
0x6D, 0x7A, 0x2F, 0x77, 0x61, 0x79, 0x6C, 0x69, 0x6E, 0x65, 0x73, 0x2E, 0x77, 0x70, 0x6D, 0x6C,
0xED, 0x5D, 0xCB, 0x72, 0xDB, 0x36, 0x14, 0xDD, 0xE7, 0x2B, 0x3C, 0x5E, 0xA7, 0x12, 0x01, 0x90,
0x04, 0x99, 0x51, 0x94, 0x49, 0xE3, 0xB8, 0xC9, 0x8C, 0xDB, 0x78, 0x6C, 0xA5, 0x69, 0x96, 0x34,
0x05, 0x49, 0x68, 0x48, 0x42, 0x25, 0xC1, 0xD8, 0xCE, 0xB2, 0xAB, 0x7E, 0x4B, 0xFF, 0xA0, 0x5F,
0xD4, 0x7E, 0x46, 0xC1, 0x97, 0x44, 0x90, 0xA0, 0xAC, 0x47, 0x64, 0xCB, 0x09, 0xB2, 0xC8, 0x58,
0xB8, 0xF7, 0x1E, 0x80, 0xB8, 0xE0, 0xB9, 0x47, 0x00, 0x4D, 0x0F, 0x5E, 0xDC, 0x84, 0xC1, 0xD1,
0x67, 0x12, 0x27, 0x94, 0x45, 0xCF, 0x8F, 0x41, 0xCF, 0x38, 0x3E, 0x22, 0x91, 0xCF, 0xC6, 0x34,
0x9A, 0x3E, 0x3F, 0x7E, 0x3F, 0x3A, 0xFD, 0xC1, 0x39, 0x7E, 0x31, 0x7C, 0x32, 0xF8, 0x24, 0xBC,
0x84, 0x67, 0x94, 0x3C, 0x3F, 0x9E, 0x71, 0x3E, 0x7F, 0xD6, 0xEF, 0x5F, 0x5F, 0x5F, 0xF7, 0xD8,
0x9C, 0x44, 0x53, 0x9A, 0xF4, 0x22, 0xC2, 0xFB, 0xC2, 0xA3, 0x0F, 0x7B, 0xF0, 0xB8, 0x70, 0x7B,
0x76, 0x3D, 0x0F, 0x03, 0xC9, 0x77, 0xFC, 0x3B, 0xED, 0xF9, 0x2C, 0xEC, 0x0B, 0xC3, 0x97, 0xBE,
0xE8, 0xA7, 0x87, 0x8E, 0x87, 0x4F, 0x8E, 0x8E, 0x06, 0x27, 0xCC, 0x4F, 0x43, 0x12, 0xF1, 0xEC,
0x83, 0xF8, 0x98, 0xC5, 0x3D, 0x0B, 0x69, 0x92, 0x8D, 0xE7, 0x15, 0x8B, 0x26, 0x74, 0x5A, 0x18,
0x2A, 0xD3, 0x24, 0xB8, 0x1D, 0xB1, 0x0F, 0xDE, 0x6D, 0x40, 0x23, 0xF2, 0x33, 0x1B, 0x93, 0x61,
0xE2, 0x4D, 0x48, 0x70, 0x3B, 0xE8, 0xAB, 0xAD, 0x72, 0x2C, 0x8D, 0x68, 0x32, 0x7B, 0xE9, 0x73,
0x81, 0x3D, 0x9C, 0xB2, 0x37, 0x2C, 0x24, 0x55, 0x5C, 0xDD, 0x22, 0xC5, 0x90, 0x1B, 0xCA, 0xDF,
0x45, 0x17, 0xAF, 0xCE, 0x58, 0xC2, 0x87, 0xE4, 0x86, 0xF8, 0x29, 0x27, 0xD9, 0xCF, 0x85, 0x6F,
0x19, 0x2E, 0x39, 0x35, 0xC2, 0xF3, 0x88, 0xC2, 0xB4, 0xE8, 0xF9, 0x47, 0xCF, 0xFF, 0xB4, 0x08,
0x6D, 0x3B, 0x48, 0x08, 0xDC, 0xFB, 0x44, 0xDE, 0x4D, 0x26, 0x97, 0xC2, 0x2D, 0xA6, 0xFC, 0xF6,
0x0D, 0xA1, 0xD3, 0x19, 0x1F, 0x42, 0xA3, 0x8C, 0x57, 0x9B, 0x25, 0x84, 0x69, 0xC0, 0xAE, 0xBC,
0x60, 0x14, 0x7B, 0x51, 0x42, 0x33, 0x7C, 0x2F, 0xB8, 0x9C, 0x13, 0x32, 0x1E, 0x02, 0xAB, 0xC4,
0xE8, 0x72, 0x90, 0x50, 0xC6, 0x31, 0x8B, 0xC8, 0xDB, 0x68, 0xC2, 0xAA, 0x66, 0xC9, 0xF0, 0x3A,
0x4A, 0xC3, 0x5F, 0xBD, 0x20, 0x25, 0x43, 0x8C, 0x4B, 0xD4, 0x46, 0xBB, 0x2A, 0xEA, 0x32, 0xBD,
0x5A, 0x3A, 0x18, 0xF5, 0x38, 0xC9, 0x52, 0x8D, 0xA3, 0xAF, 0x1E, 0x48, 0x01, 0x38, 0x17, 0x59,
0x67, 0xDE, 0x58, 0x35, 0xC2, 0xD2, 0xB4, 0x04, 0xB4, 0xED, 0x12, 0xAB, 0x65, 0x51, 0x47, 0x2A,
0xC7, 0xA9, 0xB2, 0xA9, 0xC3, 0xCF, 0x59, 0x31, 0xAF, 0x6F, 0xA3, 0x31, 0xB9, 0x69, 0xC6, 0xCB,
0x46, 0xF9, 0x52, 0x5B, 0xD7, 0x54, 0xB6, 0x2B, 0xEE, 0x8F, 0xC1, 0x29, 0x0B, 0xC6, 0x24, 0x6E,
0xAC, 0x1D, 0x12, 0xCE, 0x03, 0x8F, 0x93, 0xB7, 0xE3, 0x45, 0xAF, 0xB5, 0x26, 0xD5, 0x42, 0x2D,
0xD6, 0x4F, 0x7E, 0xEB, 0xC4, 0x44, 0xF8, 0xD1, 0xCF, 0x64, 0xC4, 0x2E, 0xB9, 0x17, 0xF3, 0x73,
0x46, 0x23, 0x2E, 0x2F, 0xDA, 0x9A, 0xB3, 0x84, 0x75, 0x5D, 0xDC, 0x80, 0xB5, 0x5E, 0x97, 0x2D,
0xF2, 0x9A, 0xA2, 0x09, 0xF7, 0x22, 0x9F, 0x0C, 0x81, 0x01, 0x70, 0xCF, 0x32, 0xB1, 0x65, 0xDA,
0xC8, 0xB1, 0x31, 0xAC, 0x52, 0x5D, 0xD9, 0xE5, 0xA8, 0x34, 0xF6, 0xF2, 0xFB, 0x04, 0x9A, 0x46,
0xCF, 0xC5, 0x8E, 0x6D, 0xDB, 0xC8, 0xB0, 0x2C, 0x73, 0x11, 0x55, 0xD9, 0xA5, 0x28, 0x2F, 0xE5,
0xEC, 0x34, 0xC8, 0x06, 0x5C, 0x2C, 0xEE, 0x6A, 0xF1, 0x37, 0xDB, 0xAB, 0xA0, 0xF3, 0xC0, 0xF3,
0x49, 0xE8, 0xC5, 0x9F, 0x6A, 0x49, 0xCD, 0xE7, 0x60, 0xF9, 0x59, 0xB4, 0xF8, 0x8C, 0xC5, 0x82,
0x2B, 0xC5, 0x84, 0x26, 0xF5, 0xF6, 0xA3, 0x23, 0x00, 0x50, 0xCF, 0x35, 0x11, 0x80, 0x08, 0x63,
0xD7, 0x32, 0xCC, 0xA7, 0x10, 0xF6, 0x2C, 0x8C, 0x4D, 0x17, 0xB9, 0x8E, 0x6D, 0xDA, 0x75, 0x8C,
0xBE, 0x12, 0x64, 0xD0, 0x6F, 0xF4, 0x56, 0x5C, 0x06, 0x95, 0xD6, 0x10, 0xAD, 0x2F, 0x1A, 0x65,
0x2A, 0xC5, 0xD4, 0x1A, 0xAA, 0xAC, 0x35, 0x83, 0x44, 0x86, 0xE6, 0x59, 0x7F, 0xF2, 0xE4, 0xC8,
0xAD, 0x1D, 0x21, 0x6F, 0x88, 0x97, 0x95, 0x8B, 0x73, 0x2F, 0xF6, 0x42, 0x69, 0x72, 0x54, 0x5E,
0xF9, 0x6A, 0x99, 0xB0, 0x20, 0x60, 0xD7, 0x25, 0x4F, 0x37, 0xBA, 0xAA, 0xFB, 0xDD, 0x05, 0xF6,
0x32, 0x9A, 0x06, 0xA4, 0xBE, 0xC8, 0xDA, 0xC6, 0x4E, 0x08, 0x31, 0xBB, 0xC5, 0x04, 0x1B, 0x3D,
0x23, 0xFF, 0xF7, 0xB4, 0xF5, 0x43, 0x03, 0x77, 0x11, 0xB1, 0xD6, 0xB0, 0x5E, 0x47, 0xDE, 0xD5,
0x1D, 0x83, 0x2B, 0x5D, 0xEE, 0x82, 0x13, 0x9D, 0xCA, 0xCC, 0xD1, 0x65, 0xAF, 0xAD, 0x9D, 0x35,
0x12, 0x24, 0xF7, 0x35, 0x4A, 0xE3, 0xE8, 0x8E, 0x0C, 0x66, 0x2E, 0x79, 0x5A, 0x38, 0xCB, 0xE7,
0xE1, 0x65, 0x34, 0xBE, 0xE4, 0x6C, 0xFE, 0x81, 0xF2, 0xD9, 0x09, 0x4D, 0x7C, 0x16, 0x71, 0x1A,
0xA5, 0xA2, 0x06, 0xBD, 0x4A, 0xE3, 0xCF, 0x1E, 0x4F, 0xE3, 0x66, 0x66, 0x17, 0xF1, 0x2B, 0x7B,
0x38, 0xF1, 0xC2, 0xB9, 0x18, 0xAC, 0x40, 0xE4, 0xAD, 0x0B, 0x6E, 0xDA, 0xBB, 0x2E, 0x58, 0x71,
0x31, 0x45, 0x47, 0x69, 0x42, 0x2E, 0x79, 0xEC, 0x65, 0x37, 0xC0, 0x99, 0x58, 0x7A, 0x43, 0x50,
0x06, 0x36, 0xDB, 0x1B, 0x61, 0x5E, 0x5E, 0x97, 0x7F, 0x8A, 0x59, 0x3A, 0x6F, 0x0F, 0xBE, 0x66,
0xAC, 0x31, 0x9E, 0xDC, 0xBA, 0x2A, 0x28, 0x67, 0x57, 0x39, 0xC1, 0x6A, 0xEB, 0x2A, 0x90, 0xD7,
0xD1, 0xB8, 0x13, 0x62, 0x61, 0x5B, 0x05, 0x50, 0x68, 0x29, 0xF2, 0x47, 0x2A, 0xD4, 0x1F, 0x69,
0x63, 0xA8, 0xF3, 0x56, 0x38, 0x8C, 0x62, 0x3A, 0x9D, 0x2E, 0x4B, 0x4F, 0xA7, 0xC3, 0xE8, 0x76,
0x9E, 0x55, 0x15, 0xCF, 0x9F, 0xD5, 0x6B, 0x49, 0xDB, 0x45, 0xE2, 0xC6, 0xD5, 0xFD, 0xD4, 0x7B,
0xE9, 0xEE, 0xBF, 0x95, 0x16, 0x39, 0x23, 0xB2, 0xB3, 0xD0, 0x60, 0xA9, 0xC7, 0x59, 0x7C, 0x9A,
0x46, 0xBE, 0x20, 0x2A, 0x3F, 0x4D, 0xA4, 0x50, 0xC9, 0xBC, 0x16, 0x48, 0xEB, 0xAE, 0x5A, 0x3A,
0xE7, 0xF0, 0xBF, 0x09, 0x06, 0x82, 0x15, 0xE1, 0x96, 0x2D, 0xDD, 0xDE, 0x1F, 0x5B, 0xDE, 0x1F,
0x57, 0x78, 0x5F, 0x90, 0xA9, 0x18, 0xCD, 0x07, 0x3A, 0xE6, 0x33, 0x11, 0x27, 0x85, 0xD5, 0x4D,
0x77, 0x01, 0x94, 0x25, 0x43, 0x89, 0xD0, 0x2C, 0x27, 0x75, 0x08, 0x9A, 0xE4, 0x99, 0x3E, 0xCD,
0xBC, 0x97, 0x35, 0xAB, 0xDE, 0xD8, 0x11, 0x26, 0x14, 0x8F, 0x50, 0xE4, 0x9C, 0x34, 0x23, 0xE5,
0x76, 0x65, 0xF0, 0xD6, 0x9A, 0xAB, 0x04, 0xE9, 0x4A, 0x76, 0x9B, 0x1C, 0xFB, 0x1D, 0x8B, 0x6F,
0xED, 0x45, 0x09, 0xB6, 0x5B, 0x94, 0x99, 0xE4, 0x3F, 0x9F, 0x31, 0xCE, 0xF6, 0xB8, 0x30, 0x69,
0x20, 0x24, 0xF8, 0x64, 0x42, 0x6F, 0x86, 0xFF, 0xFD, 0xF5, 0xF7, 0xBF, 0x7F, 0xFE, 0x53, 0x0D,
0xB5, 0x66, 0xD8, 0xC7, 0xEC, 0xD7, 0x78, 0xFA, 0xA7, 0xFC, 0x4B, 0xC9, 0x79, 0x11, 0x72, 0x46,
0xA2, 0x44, 0xC6, 0xEA, 0xF6, 0xF8, 0xBA, 0xE9, 0x6C, 0x53, 0xE1, 0x52, 0xA3, 0xB7, 0x24, 0xE2,
0xD7, 0x12, 0x8D, 0x86, 0x6D, 0x42, 0xD3, 0x04, 0x4E, 0x21, 0x1A, 0x85, 0xBC, 0x45, 0xA6, 0xE5,
0x18, 0x36, 0x04, 0x3B, 0xCA, 0xC6, 0x2A, 0x8B, 0x5A, 0x36, 0x6A, 0xD9, 0xA8, 0x65, 0xE3, 0x21,
0xC9, 0x46, 0xD0, 0xE6, 0x99, 0xF5, 0x65, 0xA3, 0x22, 0x78, 0x53, 0xD9, 0xA8, 0x80, 0xD0, 0xB2,
0x71, 0x6B, 0xD9, 0x98, 0x64, 0xB3, 0x7F, 0x41, 0x7C, 0xC1, 0xCF, 0xF7, 0x58, 0xA3, 0xE1, 0xF7,
0x5A, 0xA3, 0xF7, 0x2F, 0xB9, 0x12, 0x41, 0x58, 0xFB, 0xCE, 0xE7, 0x43, 0x0B, 0xD7, 0x07, 0x50,
0x3A, 0x10, 0x19, 0xB6, 0x6B, 0x1A, 0x0E, 0xB6, 0x4A, 0xA5, 0x03, 0x0C, 0x80, 0xC4, 0x7F, 0x26,
0xB0, 0x76, 0x54, 0x3A, 0x50, 0x2B, 0x1D, 0xAD, 0x74, 0xB4, 0xD2, 0x39, 0x40, 0xA5, 0x03, 0x77,
0x51, 0x3A, 0x8A, 0xE0, 0x4D, 0x95, 0x8E, 0x02, 0x42, 0x2B, 0x9D, 0xAD, 0x95, 0xCE, 0x94, 0x86,
0xA2, 0xBE, 0x5F, 0x30, 0x2E, 0xB8, 0x79, 0x7F, 0xA5, 0xB1, 0xDE, 0x4B, 0x3E, 0xD1, 0xDE, 0x55,
0xC2, 0x02, 0x41, 0xD5, 0x39, 0x4B, 0x54, 0xA7, 0x98, 0x4D, 0xA7, 0x15, 0x50, 0xE7, 0x94, 0xFB,
0xB3, 0xC2, 0xB5, 0xE4, 0x18, 0x20, 0xA1, 0xB4, 0xED, 0xEB, 0x81, 0xC9, 0x7C, 0xDB, 0x61, 0x5E,
0x79, 0x89, 0x41, 0x20, 0x75, 0x6B, 0x34, 0x2E, 0xAE, 0x61, 0x5E, 0x0B, 0x4A, 0x35, 0xA8, 0xA6,
0x75, 0x05, 0xD0, 0x47, 0xEF, 0x7A, 0xC5, 0x90, 0x9A, 0xD6, 0x75, 0x80, 0x54, 0x03, 0x6A, 0x18,
0xEF, 0x5C, 0x06, 0x23, 0x1A, 0x76, 0xCD, 0x51, 0xC3, 0xBC, 0x16, 0x54, 0x27, 0x88, 0xD6, 0x6A,
0xA5, 0x56, 0x03, 0x36, 0x86, 0x00, 0x3A, 0x0E, 0xC4, 0x95, 0x56, 0x03, 0xAE, 0x8B, 0xA0, 0x0B,
0x5C, 0xBC, 0xA3, 0x56, 0x43, 0x5A, 0xAB, 0x69, 0xAD, 0xA6, 0xB5, 0xDA, 0x01, 0x6A, 0x35, 0xD4,
0xE6, 0x99, 0xF5, 0xB5, 0x9A, 0x22, 0x78, 0x53, 0xAD, 0xA6, 0x80, 0xD0, 0x5A, 0x6D, 0x6B, 0xAD,
0xF6, 0x85, 0xB1, 0x70, 0xAF, 0x67, 0x99, 0x5E, 0x70, 0x46, 0xA2, 0x29, 0x9F, 0x0D, 0x4D, 0x67,
0x79, 0x4E, 0xB8, 0x68, 0x54, 0x46, 0xD1, 0xE4, 0x7D, 0x92, 0x9D, 0xE6, 0x79, 0xC1, 0xA9, 0xE8,
0x8D, 0xC5, 0xB5, 0xB3, 0xBE, 0x86, 0x41, 0xD7, 0xE1, 0xB2, 0x0E, 0x03, 0x2C, 0x2A, 0x2F, 0xC2,
0xE5, 0x13, 0x45, 0x36, 0x46, 0x36, 0x74, 0x45, 0x6D, 0xB6, 0xDC, 0x1D, 0xCB, 0xB0, 0xA9, 0xCB,
0xB0, 0x2E, 0xC3, 0xBA, 0x0C, 0x1F, 0x60, 0x19, 0x36, 0x77, 0x29, 0xC3, 0x8A, 0xE0, 0x4D, 0xCB,
0xB0, 0x02, 0x42, 0x97, 0x61, 0xFD, 0x4C, 0x91, 0x7E, 0xA6, 0xE8, 0xBE, 0x64, 0xC6, 0x06, 0x8B,
0xF2, 0x11, 0x3D, 0x53, 0xB4, 0x48, 0xBC, 0x3E, 0xAF, 0xEC, 0x4C, 0x27, 0xDC, 0x2E, 0x9D, 0x0F,
0x73, 0x00, 0xAD, 0x13, 0x7A, 0x77, 0x42, 0xD1, 0xB6, 0x09, 0xFD, 0xF6, 0x0F, 0xA0, 0x37, 0x98,
0x45, 0x73, 0xBB, 0x59, 0xD4, 0xA7, 0x15, 0xFA, 0xB4, 0x42, 0x9F, 0x56, 0x1C, 0xF2, 0x8D, 0x6D,
0x6D, 0x77, 0x63, 0xEB, 0xAD, 0xAD, 0x6F, 0x62, 0x6B, 0x0B, 0xBA, 0xC8, 0x40, 0xC0, 0xAA, 0x7E,
0x59, 0x0E, 0x59, 0x06, 0x84, 0x06, 0xB0, 0xEC, 0x5D, 0x7F, 0x5D, 0xAE, 0x5A, 0x55, 0x7A, 0x6B,
0x4B, 0x6F, 0x6D, 0xE9, 0xAD, 0xAD, 0x43, 0xDA, 0xDA, 0xB2, 0xDA, 0x34, 0xB3, 0xFE, 0xD6, 0x96,
0x22, 0x78, 0xD3, 0xAD, 0x2D, 0x05, 0x84, 0xDE, 0xDA, 0xDA, 0x7A, 0x6B, 0xCB, 0x4F, 0xC5, 0xF7,
0x94, 0xF0, 0x84, 0xC6, 0xBF, 0x78, 0xE1, 0x1E, 0x05, 0xF6, 0xF7, 0x58, 0x1A, 0x2D, 0xCB, 0x00,
0x08, 0x1B, 0x66, 0xF9, 0xF4, 0x05, 0x76, 0x6D, 0x0B, 0x00, 0x6C, 0xB8, 0xD6, 0xAE, 0x4F, 0x5F,
0xD8, 0xBA, 0x36, 0xEA, 0xDA, 0xA8, 0x6B, 0xE3, 0xBE, 0x6B, 0xE3, 0xFE, 0x9E, 0xA1, 0x87, 0x86,
0x6B, 0x40, 0x21, 0x9A, 0x41, 0xC1, 0x0C, 0x8E, 0x85, 0x50, 0x76, 0x48, 0x6C, 0x19, 0xBB, 0x32,
0x03, 0xD6, 0xCC, 0xA0, 0x99, 0x41, 0x33, 0xC3, 0x01, 0xAA, 0x66, 0xBB, 0xAD, 0x40, 0xD6, 0x57,
0xCD, 0xB8, 0x1D, 0xBC, 0xA9, 0x6A, 0x56, 0x40, 0x1C, 0x94, 0x6A, 0x0E, 0xD3, 0x80, 0xD3, 0x79,
0x40, 0x4E, 0xCA, 0xF7, 0x07, 0xAD, 0xA3, 0x9D, 0x95, 0x68, 0x45, 0x7E, 0x81, 0xA1, 0x02, 0x58,
0xAD, 0x16, 0xF5, 0xC1, 0xB2, 0x3E, 0x58, 0xD6, 0x07, 0xCB, 0xF7, 0x72, 0xB0, 0xFC, 0xCD, 0x1D,
0x27, 0x3E, 0xC0, 0xF7, 0x4B, 0xE8, 0x22, 0xD3, 0x71, 0xA1, 0x83, 0xCB, 0x77, 0x4E, 0x38, 0x26,
0x30, 0x91, 0x05, 0x91, 0x01, 0x9C, 0x1D, 0x55, 0x64, 0xB5, 0x5F, 0xAE, 0x55, 0xA4, 0x56, 0x91,
0x5A, 0x45, 0x3E, 0xBE, 0xEF, 0x97, 0x08, 0x1A, 0x26, 0x30, 0x90, 0xEB, 0x56, 0x1B, 0x4F, 0xD0,
0x31, 0x91, 0x0B, 0xB1, 0xBB, 0x2B, 0x31, 0xB8, 0x9A, 0x18, 0x34, 0x31, 0x68, 0x62, 0x78, 0xB4,
0xC4, 0x00, 0xB1, 0x6D, 0x02, 0x17, 0xC3, 0xEA, 0xE5, 0x0D, 0xD8, 0x74, 0x21, 0x04, 0x8E, 0x68,
0xD9, 0xF5, 0xB8, 0x76, 0xF1, 0x7D, 0x4B, 0x53, 0x83, 0xA6, 0x06, 0x4D, 0x0D, 0x8F, 0x90, 0x1A,
0x10, 0x14, 0xDF, 0x28, 0x0C, 0xCB, 0x2E, 0xF7, 0xA4, 0xB1, 0x61, 0x59, 0xAE, 0xEB, 0xD8, 0xB6,
0x85, 0x76, 0xA5, 0x06, 0xFD, 0x0A, 0x3B, 0x4D, 0x0D, 0x9A, 0x1A, 0x1E, 0x2F, 0x35, 0x08, 0xC5,
0x80, 0x4D, 0x0B, 0x98, 0x4E, 0xF5, 0xCA, 0x27, 0x1B, 0x58, 0x8E, 0xED, 0x42, 0xE4, 0xEC, 0xFC,
0x72, 0x4B, 0xFD, 0xCE, 0x27, 0x4D, 0x0D, 0x9A, 0x1A, 0x1E, 0x31, 0x35, 0x60, 0xC7, 0x72, 0x30,
0x06, 0xD5, 0x1E, 0x24, 0xB6, 0x4C, 0x64, 0xDB, 0x0E, 0xC2, 0xF6, 0xAE, 0x5B, 0x0D, 0x40, 0xBF,
0x62, 0x44, 0x53, 0x83, 0xA6, 0x86, 0xFB, 0xA7, 0x86, 0x41, 0x7F, 0xF9, 0x67, 0x69, 0x06, 0xFD,
0xE5, 0x9F, 0x7A, 0x1A, 0x64, 0x7F, 0x2E, 0x6A, 0xF8, 0xE4, 0x7F, 0x50, 0x4B, 0x07, 0x08, 0x9F,
0x7E, 0x60, 0xC2, 0x2B, 0x07, 0x00, 0x00, 0x7E, 0x6A, 0x00, 0x00, 0x50, 0x4B, 0x01, 0x02, 0x14,
0x00, 0x14, 0x00, 0x08, 0x08, 0x08, 0x00, 0x8A, 0x81, 0x3E, 0x56, 0xF2, 0xB2, 0xDF, 0xE7, 0xD1,
0x06, 0x00, 0x00, 0x66, 0x4D, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x70, 0x6D, 0x7A, 0x2F, 0x74, 0x65,
0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65, 0x2E, 0x6B, 0x6D, 0x6C, 0x50, 0x4B, 0x01, 0x02, 0x14, 0x00,
0x14, 0x00, 0x08, 0x08, 0x08, 0x00, 0x8A, 0x81, 0x3E, 0x56, 0x9F, 0x7E, 0x60, 0xC2, 0x2B, 0x07,
0x00, 0x00, 0x7E, 0x6A, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x07, 0x00, 0x00, 0x77, 0x70, 0x6D, 0x7A, 0x2F, 0x77, 0x61, 0x79,
0x6C, 0x69, 0x6E, 0x65, 0x73, 0x2E, 0x77, 0x70, 0x6D, 0x6C, 0x50, 0x4B, 0x05, 0x06, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7B, 0x0E, 0x00, 0x00, 0x00, 0x00
};
#endif /* __waypoint_v3_test_file_kmz_h_included */

View File

@ -0,0 +1,58 @@
/**
********************************************************************
* @file file_binary_array_list_en.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 "file_binary_array_list_en.h"
#include "widget_file_c/en_big_screen/icon_button1_png.h"
#include "widget_file_c/en_big_screen/icon_button2_png.h"
#include "widget_file_c/en_big_screen/icon_list_item1_png.h"
#include "widget_file_c/en_big_screen/icon_list_item2_png.h"
#include "widget_file_c/en_big_screen/icon_scale_png.h"
#include "widget_file_c/en_big_screen/icon_switch_select_png.h"
#include "widget_file_c/en_big_screen/icon_switch_unselect_png.h"
#include "widget_file_c/en_big_screen/widget_config_json.h"
/* Private constants ---------------------------------------------------------*/
/* Export types -------------------------------------------------------------*/
// English language file binary array list
static T_DjiWidgetFileBinaryArray s_EnWidgetFileBinaryArrayList[] = {
{widget_config_json_fileName, widget_config_json_fileSize, widget_config_json_fileBinaryArray},
{icon_button1_png_fileName, icon_button1_png_fileSize, icon_button1_png_fileBinaryArray},
{icon_button2_png_fileName, icon_button2_png_fileSize, icon_button2_png_fileBinaryArray},
{icon_list_item1_png_fileName, icon_list_item1_png_fileSize, icon_list_item1_png_fileBinaryArray},
{icon_list_item2_png_fileName, icon_list_item2_png_fileSize, icon_list_item2_png_fileBinaryArray},
{icon_scale_png_fileName, icon_scale_png_fileSize, icon_scale_png_fileBinaryArray},
{icon_switch_select_png_fileName, icon_switch_select_png_fileSize, icon_switch_select_png_fileBinaryArray},
{icon_switch_unselect_png_fileName, icon_switch_unselect_png_fileSize, icon_switch_unselect_png_fileBinaryArray}
};
/* Export values -------------------------------------------------------------*/
uint32_t g_EnBinaryArrayCount = sizeof(s_EnWidgetFileBinaryArrayList) / sizeof(T_DjiWidgetFileBinaryArray);
T_DjiWidgetFileBinaryArray * g_EnFileBinaryArrayList = s_EnWidgetFileBinaryArrayList;
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,57 @@
/**
********************************************************************
* @file file_binary_array_list_en.h
* @brief This is the header file for "file_binary_array_list_en.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 FILE_BINARY_ARRAY_LIST_EN_H
#define FILE_BINARY_ARRAY_LIST_EN_H
#include <stdint.h>
#include <dji_widget.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
extern uint32_t g_EnBinaryArrayCount;
extern T_DjiWidgetFileBinaryArray * g_EnFileBinaryArrayList;
#ifdef __cplusplus
}
#endif
#endif // FILE_BINARY_ARRAY_LIST_EN_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,251 @@
/**
********************************************************************
* @file test_widget.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 "test_widget.h"
#include <dji_widget.h>
#include <dji_logger.h>
#include "../utils/util_misc.h"
#include <dji_platform.h>
#include <stdio.h>
#include "dji_sdk_config.h"
#include "file_binary_array_list_en.h"
/* Private constants ---------------------------------------------------------*/
#define WIDGET_DIR_PATH_LEN_MAX (256)
#define WIDGET_TASK_STACK_SIZE (2048)
/* Private types -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void *DjiTest_WidgetTask(void *arg);
static T_DjiReturnCode DjiTestWidget_SetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t value,
void *userData);
static T_DjiReturnCode DjiTestWidget_GetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t *value,
void *userData);
/* Private values ------------------------------------------------------------*/
static T_DjiTaskHandle s_widgetTestThread;
static bool s_isWidgetFileDirPathConfigured = false;
static char s_widgetFileDirPath[DJI_FILE_PATH_SIZE_MAX] = {0};
static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = {
{0, DJI_WIDGET_TYPE_BUTTON, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{1, DJI_WIDGET_TYPE_LIST, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{2, DJI_WIDGET_TYPE_SWITCH, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{3, DJI_WIDGET_TYPE_SCALE, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{4, DJI_WIDGET_TYPE_BUTTON, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{5, DJI_WIDGET_TYPE_SCALE, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{6, DJI_WIDGET_TYPE_INT_INPUT_BOX, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{7, DJI_WIDGET_TYPE_SWITCH, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
{8, DJI_WIDGET_TYPE_LIST, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
};
static const char *s_widgetTypeNameArray[] = {
"Unknown",
"Button",
"Switch",
"Scale",
"List",
"Int input box"
};
static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem);
static int32_t s_widgetValueList[sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0};
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_WidgetStartService(void)
{
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
//Step 1 : Init DJI Widget
djiStat = DjiWidget_Init();
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Dji test widget init error, stat = 0x%08llX", djiStat);
return djiStat;
}
#ifdef SYSTEM_ARCH_LINUX
//Step 2 : Set UI Config (Linux environment)
char curFileDirPath[WIDGET_DIR_PATH_LEN_MAX];
char tempPath[WIDGET_DIR_PATH_LEN_MAX];
djiStat = DjiUserUtil_GetCurrentFileDirPath(__FILE__, WIDGET_DIR_PATH_LEN_MAX, curFileDirPath);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", djiStat);
return djiStat;
}
if (s_isWidgetFileDirPathConfigured == true) {
snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/en_big_screen", s_widgetFileDirPath);
} else {
snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/en_big_screen", curFileDirPath);
}
//set default ui config path
djiStat = DjiWidget_RegDefaultUiConfigByDirPath(tempPath);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add default widget ui config error, stat = 0x%08llX", djiStat);
return djiStat;
}
//set ui config for English language
djiStat = DjiWidget_RegUiConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_ENGLISH,
DJI_MOBILE_APP_SCREEN_TYPE_BIG_SCREEN,
tempPath);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add widget ui config error, stat = 0x%08llX", djiStat);
return djiStat;
}
//set ui config for Chinese language
if (s_isWidgetFileDirPathConfigured == true) {
snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/cn_big_screen", s_widgetFileDirPath);
} else {
snprintf(tempPath, WIDGET_DIR_PATH_LEN_MAX, "%swidget_file/cn_big_screen", curFileDirPath);
}
djiStat = DjiWidget_RegUiConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_CHINESE,
DJI_MOBILE_APP_SCREEN_TYPE_BIG_SCREEN,
tempPath);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add widget ui config error, stat = 0x%08llX", djiStat);
return djiStat;
}
#else
//Step 2 : Set UI Config (RTOS environment)
T_DjiWidgetBinaryArrayConfig enWidgetBinaryArrayConfig = {
.binaryArrayCount = g_EnBinaryArrayCount,
.fileBinaryArrayList = g_EnFileBinaryArrayList
};
//set default ui config
djiStat = DjiWidget_RegDefaultUiConfigByBinaryArray(&enWidgetBinaryArrayConfig);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Add default widget ui config error, stat = 0x%08llX", djiStat);
return djiStat;
}
#endif
//Step 3 : Set widget handler list
djiStat = DjiWidget_RegHandlerList(s_widgetHandlerList, s_widgetHandlerListCount);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set widget handler list error, stat = 0x%08llX", djiStat);
return djiStat;
}
//Step 4 : Run widget api sample task
if (osalHandler->TaskCreate("user_widget_task", DjiTest_WidgetTask, WIDGET_TASK_STACK_SIZE, NULL,
&s_widgetTestThread) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Dji widget test task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode DjiTest_WidgetSetConfigFilePath(const char *path)
{
memset(s_widgetFileDirPath, 0, sizeof(s_widgetFileDirPath));
memcpy(s_widgetFileDirPath, path, USER_UTIL_MIN(strlen(path), sizeof(s_widgetFileDirPath) - 1));
s_isWidgetFileDirPathConfigured = true;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
__attribute__((weak)) void DjiTest_WidgetLogAppend(const char *fmt, ...)
{
}
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wformat"
#endif
/* Private functions definition-----------------------------------------------*/
static void *DjiTest_WidgetTask(void *arg)
{
char message[DJI_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN];
uint32_t sysTimeMs = 0;
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
USER_UTIL_UNUSED(arg);
while (1) {
djiStat = osalHandler->GetTimeMs(&sysTimeMs);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Get system time ms error, stat = 0x%08llX", djiStat);
}
#ifndef USER_FIRMWARE_MAJOR_VERSION
snprintf(message, DJI_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN, "System time : %u ms", sysTimeMs);
#else
snprintf(message, DJI_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN,
"System time : %u ms\r\nVersion: v%02d.%02d.%02d.%02d\r\nBuild time: %s %s", sysTimeMs,
USER_FIRMWARE_MAJOR_VERSION, USER_FIRMWARE_MINOR_VERSION,
USER_FIRMWARE_MODIFY_VERSION, USER_FIRMWARE_DEBUG_VERSION,
__DATE__, __TIME__);
#endif
djiStat = DjiWidgetFloatingWindow_ShowMessage(message);
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Floating window show message error, stat = 0x%08llX", djiStat);
}
osalHandler->TaskSleepMs(1000);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
static T_DjiReturnCode DjiTestWidget_SetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t value,
void *userData)
{
USER_UTIL_UNUSED(userData);
USER_LOG_INFO("Set widget value, widgetType = %s, widgetIndex = %d ,widgetValue = %d",
s_widgetTypeNameArray[widgetType], index, value);
s_widgetValueList[index] = value;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode DjiTestWidget_GetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t *value,
void *userData)
{
USER_UTIL_UNUSED(userData);
USER_UTIL_UNUSED(widgetType);
*value = s_widgetValueList[index];
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,51 @@
/**
********************************************************************
* @file test_widget.h
* @brief This is the header file for "test_widget.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 TEST_WIDGET_H
#define TEST_WIDGET_H
/* Includes ------------------------------------------------------------------*/
#include <dji_typedef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_WidgetStartService(void);
T_DjiReturnCode DjiTest_WidgetSetConfigFilePath(const char *path);
__attribute__((weak)) void DjiTest_WidgetLogAppend(const char *fmt, ...);
#ifdef __cplusplus
}
#endif
#endif // TEST_WIDGET_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,800 @@
/**
********************************************************************
* @file test_widget_speaker.c
* @brief
*
* @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.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "test_widget_speaker.h"
#include "dji_logger.h"
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "utils/util_misc.h"
#include "utils/util_md5.h"
#include <dji_aircraft_info.h>
#ifdef OPUS_INSTALLED
#include <opus/opus.h>
#endif
/* Private constants ---------------------------------------------------------*/
#define WIDGET_SPEAKER_TASK_STACK_SIZE (2048)
/*! Attention: replace your audio device name here. */
#define WIDGET_SPEAKER_USB_AUDIO_DEVICE_NAME "alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo"
#define WIDGET_SPEAKER_AUDIO_OPUS_FILE_NAME "test_audio.opus"
#define WIDGET_SPEAKER_AUDIO_PCM_FILE_NAME "test_audio.pcm"
#define WIDGET_SPEAKER_TTS_FILE_NAME "test_tts.txt"
#define WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME "tts_audio.wav"
#define WIDGET_SPEAKER_TTS_FILE_MAX_SIZE (3000)
/* The frame size is hardcoded for this sample code but it doesn't have to be */
#define WIDGET_SPEAKER_AUDIO_OPUS_MAX_PACKET_SIZE (3 * 1276)
#define WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE (6 * 960)
#define WIDGET_SPEAKER_AUDIO_OPUS_SAMPLE_RATE (16000)
#define WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS (1)
#define WIDGET_SPEAKER_AUDIO_OPUS_DECODE_FRAME_SIZE_8KBPS (40)
#define WIDGET_SPEAKER_AUDIO_OPUS_DECODE_BITRATE_8KBPS (8000)
/* The speaker initialization parameters */
#define WIDGET_SPEAKER_DEFAULT_VOLUME (60)
#define EKHO_INSTALLED (1)
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_DjiWidgetSpeakerHandler s_speakerHandler = {0};
static T_DjiMutexHandle s_speakerMutex = {0};
static T_DjiWidgetSpeakerState s_speakerState = {0};
static T_DjiTaskHandle s_widgetSpeakerTestThread;
static FILE *s_audioFile = NULL;
static FILE *s_ttsFile = NULL;
static bool s_isDecodeFinished = true;
static uint16_t s_decodeBitrate = 0;
/* Private functions declaration ---------------------------------------------*/
static void SetSpeakerState(E_DjiWidgetSpeakerState speakerState);
static T_DjiReturnCode GetSpeakerState(T_DjiWidgetSpeakerState *speakerState);
static T_DjiReturnCode SetWorkMode(E_DjiWidgetSpeakerWorkMode workMode);
static T_DjiReturnCode SetPlayMode(E_DjiWidgetSpeakerPlayMode playMode);
static T_DjiReturnCode StartPlay(void);
static T_DjiReturnCode StopPlay(void);
static T_DjiReturnCode SetVolume(uint8_t volume);
static T_DjiReturnCode ReceiveTtsData(E_DjiWidgetTransmitDataEvent event,
uint32_t offset, uint8_t *buf, uint16_t size);
static T_DjiReturnCode ReceiveAudioData(E_DjiWidgetTransmitDataEvent event,
uint32_t offset, uint8_t *buf, uint16_t size);
#ifdef SYSTEM_ARCH_LINUX
static void *DjiTest_WidgetSpeakerTask(void *arg);
static uint32_t DjiTest_GetVoicePlayProcessId(void);
static uint32_t DjiTest_KillVoicePlayProcess(uint32_t pid);
static T_DjiReturnCode DjiTest_DecodeAudioData(void);
static T_DjiReturnCode DjiTest_PlayAudioData(void);
static T_DjiReturnCode DjiTest_PlayTtsData(void);
static T_DjiReturnCode DjiTest_CheckFileMd5Sum(const char *path, uint8_t *buf, uint16_t size);
#endif
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode DjiTest_WidgetSpeakerStartService(void)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
s_speakerHandler.GetSpeakerState = GetSpeakerState;
s_speakerHandler.SetWorkMode = SetWorkMode;
s_speakerHandler.StartPlay = StartPlay;
s_speakerHandler.StopPlay = StopPlay;
s_speakerHandler.SetPlayMode = SetPlayMode;
s_speakerHandler.SetVolume = SetVolume;
s_speakerHandler.ReceiveTtsData = ReceiveTtsData;
s_speakerHandler.ReceiveVoiceData = ReceiveAudioData;
returnCode = osalHandler->MutexCreate(&s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Create speaker mutex error: 0x%08llX", returnCode);
return returnCode;
}
returnCode = DjiWidget_RegSpeakerHandler(&s_speakerHandler);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Register speaker handler error: 0x%08llX", returnCode);
return returnCode;
}
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
s_speakerState.state = DJI_WIDGET_SPEAKER_STATE_IDEL;
s_speakerState.workMode = DJI_WIDGET_SPEAKER_WORK_MODE_VOICE;
s_speakerState.playMode = DJI_WIDGET_SPEAKER_PLAY_MODE_SINGLE_PLAY;
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
returnCode = SetVolume(WIDGET_SPEAKER_DEFAULT_VOLUME);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set speaker volume error: 0x%08llX", returnCode);
return returnCode;
}
#ifdef SYSTEM_ARCH_LINUX
if (osalHandler->TaskCreate("user_widget_speaker_task", DjiTest_WidgetSpeakerTask, WIDGET_SPEAKER_TASK_STACK_SIZE,
NULL,
&s_widgetSpeakerTestThread) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Dji widget speaker test task create error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
#endif
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
#ifdef SYSTEM_ARCH_LINUX
static uint32_t DjiTest_GetVoicePlayProcessId(void)
{
FILE *fp;
char cmdStr[128];
uint32_t pid;
int ret;
snprintf(cmdStr, 128, "pgrep ffplay");
fp = popen(cmdStr, "r");
if (fp == NULL) {
USER_LOG_ERROR("fp is null.");
return 0;
}
ret = fscanf(fp, "%u", &pid);
if (ret <= 0) {
pid = 0;
goto out;
}
out:
pclose(fp);
return pid;
}
static uint32_t DjiTest_KillVoicePlayProcess(uint32_t pid)
{
FILE *fp;
char cmdStr[128];
snprintf(cmdStr, 128, "kill %d", pid);
fp = popen(cmdStr, "r");
if (fp == NULL) {
USER_LOG_ERROR("fp is null.");
return 0;
}
pclose(fp);
return pid;
}
static T_DjiReturnCode DjiTest_DecodeAudioData(void)
{
#ifdef OPUS_INSTALLED
FILE *fin;
FILE *fout;
OpusDecoder *decoder;
opus_int16 out[WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS];
uint8_t cbits[WIDGET_SPEAKER_AUDIO_OPUS_MAX_PACKET_SIZE];
int32_t nbBytes;
int32_t err;
/*! Attention: you can use "ffmpeg -i xxx.mp3 -ar 16000 -ac 1 out.wav" and use opus-tools to generate opus file for test */
fin = fopen(WIDGET_SPEAKER_AUDIO_OPUS_FILE_NAME, "r");
if (fin == NULL) {
fprintf(stderr, "failed to open input file: %s\n", strerror(errno));
return EXIT_FAILURE;
}
/* Create a new decoder state. */
decoder = opus_decoder_create(WIDGET_SPEAKER_AUDIO_OPUS_SAMPLE_RATE, WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS, &err);
if (err < 0) {
fprintf(stderr, "failed to create decoder: %s\n", opus_strerror(err));
goto close_fin;
}
fout = fopen(WIDGET_SPEAKER_AUDIO_PCM_FILE_NAME, "w");
if (fout == NULL) {
fprintf(stderr, "failed to open output file: %s\n", strerror(errno));
goto close_fin;
}
while (1) {
int i;
unsigned char pcm_bytes[WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * 2];
int frame_size;
/* Read a 16 bits/sample audio frame. */
nbBytes = fread(cbits, 1, s_decodeBitrate / WIDGET_SPEAKER_AUDIO_OPUS_DECODE_BITRATE_8KBPS *
WIDGET_SPEAKER_AUDIO_OPUS_DECODE_FRAME_SIZE_8KBPS, fin);
if (feof(fin))
break;
/* Decode the data. In this example, frame_size will be constant because
the encoder is using a constant frame size. However, that may not
be the case for all encoders, so the decoder must always check
the frame size returned. */
frame_size = opus_decode(decoder, cbits, nbBytes, out, WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE, 0);
if (frame_size < 0) {
fprintf(stderr, "decoder failed: %s\n", opus_strerror(frame_size));
goto close_fout;
}
USER_LOG_DEBUG("decode data to file: %d\r\n", frame_size * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS);
/* Convert to little-endian ordering. */
for (i = 0; i < WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * frame_size; i++) {
pcm_bytes[2 * i] = out[i] & 0xFF;
pcm_bytes[2 * i + 1] = (out[i] >> 8) & 0xFF;
}
/* Write the decoded audio to file. */
fwrite(pcm_bytes, sizeof(short), frame_size * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS, fout);
}
USER_LOG_INFO("Decode Finished...");
s_isDecodeFinished = true;
decode_data_failed:
opus_decoder_destroy(decoder);
create_decoder_failed:
fclose(fout);
open_pcm_audio_failed:
fclose(fin);
#endif
return EXIT_SUCCESS;
#ifdef OPUS_INSTALLED
close_fout:
fclose(fout);
close_fin:
fclose(fin);
return EXIT_FAILURE;
#endif
}
static T_DjiReturnCode DjiTest_PlayAudioData(void)
{
char cmdStr[128];
memset(cmdStr, 0, sizeof(cmdStr));
USER_LOG_INFO("Start Playing...");
snprintf(cmdStr, sizeof(cmdStr), "ffplay -nodisp -autoexit -ar 16000 -ac 1 -f s16le -i %s 2>/dev/null",
WIDGET_SPEAKER_AUDIO_PCM_FILE_NAME);
return DjiUserUtil_RunSystemCmd(cmdStr);
}
static T_DjiReturnCode DjiTest_PlayTtsData(void)
{
FILE *txtFile;
uint8_t data[WIDGET_SPEAKER_TTS_FILE_MAX_SIZE] = {0};
int32_t readLen;
char cmdStr[WIDGET_SPEAKER_TTS_FILE_MAX_SIZE + 128];
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
T_DjiReturnCode returnCode;
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;
}
if (aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3E ||
aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3T ||
aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3D ||
aircraftInfoBaseInfo.aircraftType == DJI_AIRCRAFT_TYPE_M3TD) {
return DjiTest_PlayAudioData();
} else {
txtFile = fopen(WIDGET_SPEAKER_TTS_FILE_NAME, "r");
if (txtFile == NULL) {
USER_LOG_ERROR("failed to open input file: %s\n", strerror(errno));
return EXIT_FAILURE;
}
readLen = fread(data, 1, WIDGET_SPEAKER_TTS_FILE_MAX_SIZE - 1, txtFile);
if (readLen <= 0) {
USER_LOG_ERROR("Read tts file failed, error code: %d", readLen);
fclose(txtFile);
return DJI_ERROR_SYSTEM_MODULE_CODE_NOT_FOUND;
}
data[readLen] = '\0';
fclose(txtFile);
USER_LOG_INFO("Read tts file success, len: %d", readLen);
USER_LOG_INFO("Content: %s", data);
memset(cmdStr, 0, sizeof(cmdStr));
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_IN_TTS_CONVERSION);
#if EKHO_INSTALLED
/*! Attention: you can use other tts opensource function to convert txt to speech, example used ekho v7.5 */
snprintf(cmdStr, sizeof(cmdStr), " ekho %s -s 20 -p 20 -a 100 -o %s", data,
WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME);
#else
USER_LOG_WARN(
"Ekho is not installed, please visit https://www.eguidedog.net/ekho.php to install it or use other TTS tools to convert audio");
#endif
DjiUserUtil_RunSystemCmd(cmdStr);
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_PLAYING);
USER_LOG_INFO("Start TTS Playing...");
memset(cmdStr, 0, sizeof(cmdStr));
snprintf(cmdStr, sizeof(cmdStr), "ffplay -nodisp -autoexit -ar 16000 -ac 1 -f s16le -i %s 2>/dev/null",
WIDGET_SPEAKER_TTS_OUTPUT_FILE_NAME);
return DjiUserUtil_RunSystemCmd(cmdStr);
}
}
static T_DjiReturnCode DjiTest_CheckFileMd5Sum(const char *path, uint8_t *buf, uint16_t size)
{
MD5_CTX md5Ctx;
uint32_t readFileTotalSize = 0;
uint16_t readLen;
T_DjiReturnCode returnCode;
uint8_t readBuf[1024] = {0};
uint8_t md5Sum[16] = {0};
FILE *file = NULL;;
UtilMd5_Init(&md5Ctx);
file = fopen(path, "rb");
if (file == NULL) {
USER_LOG_ERROR("Open tts file error.");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
while (1) {
returnCode = fseek(file, readFileTotalSize, SEEK_SET);
if (returnCode != 0) {
USER_LOG_INFO("fseek file error");
}
readLen = fread(readBuf, 1, sizeof(readBuf), file);
if (readLen > 0) {
readFileTotalSize += readLen;
UtilMd5_Update(&md5Ctx, readBuf, readLen);
}
if (feof(file))
break;
}
UtilMd5_Final(&md5Ctx, md5Sum);
fclose(file);
if (size == sizeof(md5Sum)) {
if (memcmp(md5Sum, buf, sizeof(md5Sum)) == 0) {
USER_LOG_INFO("MD5 sum check success");
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
} else {
USER_LOG_ERROR("MD5 sum length error");
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
#endif
static void SetSpeakerState(E_DjiWidgetSpeakerState speakerState)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
}
s_speakerState.state = speakerState;
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
}
}
static T_DjiReturnCode GetSpeakerState(T_DjiWidgetSpeakerState *speakerState)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
*speakerState = s_speakerState;
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode SetWorkMode(E_DjiWidgetSpeakerWorkMode workMode)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
USER_LOG_INFO("Set widget speaker work mode: %d", workMode);
s_speakerState.workMode = workMode;
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode SetPlayMode(E_DjiWidgetSpeakerPlayMode playMode)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
USER_LOG_INFO("Set widget speaker play mode: %d", playMode);
s_speakerState.playMode = playMode;
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode StartPlay(void)
{
uint32_t pid;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
#ifdef SYSTEM_ARCH_LINUX
pid = DjiTest_GetVoicePlayProcessId();
if (pid != 0) {
DjiTest_KillVoicePlayProcess(pid);
}
#endif
osalHandler->TaskSleepMs(5);
USER_LOG_INFO("Start widget speaker play");
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_PLAYING);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode StopPlay(void)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
uint32_t pid;
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
USER_LOG_INFO("Stop widget speaker play");
s_speakerState.state = DJI_WIDGET_SPEAKER_STATE_IDEL;
#ifdef SYSTEM_ARCH_LINUX
pid = DjiTest_GetVoicePlayProcessId();
if (pid != 0) {
DjiTest_KillVoicePlayProcess(pid);
}
#endif
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode SetVolume(uint8_t volume)
{
T_DjiReturnCode returnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
char cmdStr[128];
int32_t ret = 0;
float realVolume;
returnCode = osalHandler->MutexLock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
realVolume = 1.5f * (float) volume;
s_speakerState.volume = volume;
USER_LOG_INFO("Set widget speaker volume: %d", volume);
#ifdef PLATFORM_ARCH_x86_64
snprintf(cmdStr, sizeof(cmdStr), "pactl list | grep %s -q", WIDGET_SPEAKER_USB_AUDIO_DEVICE_NAME);
ret = system(cmdStr);
if (ret == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
memset(cmdStr, 0, sizeof(cmdStr));
snprintf(cmdStr, sizeof(cmdStr), "pactl set-sink-volume %s %d%%", WIDGET_SPEAKER_USB_AUDIO_DEVICE_NAME,
(int32_t) realVolume);
returnCode = DjiUserUtil_RunSystemCmd(cmdStr);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Set widget speaker volume error: %d", ret);
}
} else {
USER_LOG_WARN("No audio device found, please add audio device and init speaker volume here.");
}
#else
USER_LOG_WARN("No audio device found, please add audio device and init speaker volume here!!!");
#endif
returnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveTtsData(E_DjiWidgetTransmitDataEvent event,
uint32_t offset, uint8_t *buf, uint16_t size)
{
uint16_t writeLen;
T_DjiReturnCode returnCode;
if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_START) {
USER_LOG_INFO("Create tts file.");
#ifdef SYSTEM_ARCH_LINUX
s_ttsFile = fopen(WIDGET_SPEAKER_TTS_FILE_NAME, "wb");
if (s_ttsFile == NULL) {
USER_LOG_ERROR("Open tts file error.");
}
#endif
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_TRANSMITTING);
}
} else if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_TRANSMIT) {
USER_LOG_INFO("Transmit tts file, offset: %d, size: %d", offset, size);
#ifdef SYSTEM_ARCH_LINUX
if (s_ttsFile != NULL) {
fseek(s_ttsFile, offset, SEEK_SET);
writeLen = fwrite(buf, 1, size, s_ttsFile);
if (writeLen != size) {
USER_LOG_ERROR("Write tts file error %d", writeLen);
}
}
#endif
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_TRANSMITTING);
}
} else if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_FINISH) {
USER_LOG_INFO("Close tts file.");
#ifdef SYSTEM_ARCH_LINUX
if (s_ttsFile != NULL) {
fclose(s_ttsFile);
s_ttsFile = NULL;
}
returnCode = DjiTest_CheckFileMd5Sum(WIDGET_SPEAKER_TTS_FILE_NAME, buf, size);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("File md5 sum check failed");
}
#endif
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_IDEL);
}
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_DjiReturnCode ReceiveAudioData(E_DjiWidgetTransmitDataEvent event,
uint32_t offset, uint8_t *buf, uint16_t size)
{
uint16_t writeLen;
T_DjiReturnCode returnCode;
T_DjiWidgetTransDataContent transDataContent = {0};
if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_START) {
s_isDecodeFinished = false;
#ifdef SYSTEM_ARCH_LINUX
USER_LOG_INFO("Create voice file.");
s_audioFile = fopen(WIDGET_SPEAKER_AUDIO_OPUS_FILE_NAME, "wb");
if (s_audioFile == NULL) {
USER_LOG_ERROR("Create tts file error.");
}
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_TRANSMITTING);
}
#endif
memcpy(&transDataContent, buf, size);
s_decodeBitrate = transDataContent.transDataStartContent.fileDecodeBitrate;
USER_LOG_INFO("Create voice file: %s, decoder bitrate: %d.", transDataContent.transDataStartContent.fileName,
transDataContent.transDataStartContent.fileDecodeBitrate);
} else if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_TRANSMIT) {
USER_LOG_INFO("Transmit voice file, offset: %d, size: %d", offset, size);
#ifdef SYSTEM_ARCH_LINUX
if (s_audioFile != NULL) {
fseek(s_audioFile, offset, SEEK_SET);
writeLen = fwrite(buf, 1, size, s_audioFile);
if (writeLen != size) {
USER_LOG_ERROR("Write tts file error %d", writeLen);
}
}
#endif
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_TRANSMITTING);
}
} else if (event == DJI_WIDGET_TRANSMIT_DATA_EVENT_FINISH) {
USER_LOG_INFO("Close voice file.");
if (s_audioFile != NULL) {
fclose(s_audioFile);
s_audioFile = NULL;
}
#ifdef SYSTEM_ARCH_LINUX
returnCode = DjiTest_CheckFileMd5Sum(WIDGET_SPEAKER_AUDIO_OPUS_FILE_NAME, buf, size);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("File md5 sum check failed");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#endif
if (s_speakerState.state != DJI_WIDGET_SPEAKER_STATE_PLAYING) {
SetSpeakerState(DJI_WIDGET_SPEAKER_STATE_IDEL);
}
#ifdef SYSTEM_ARCH_LINUX
DjiTest_DecodeAudioData();
#endif
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
#ifdef SYSTEM_ARCH_LINUX
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *DjiTest_WidgetSpeakerTask(void *arg)
{
T_DjiReturnCode djiReturnCode;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
USER_UTIL_UNUSED(arg);
while (1) {
osalHandler->TaskSleepMs(10);
if (s_speakerState.state == DJI_WIDGET_SPEAKER_STATE_PLAYING) {
if (s_speakerState.playMode == DJI_WIDGET_SPEAKER_PLAY_MODE_LOOP_PLAYBACK) {
if (s_speakerState.workMode == DJI_WIDGET_SPEAKER_WORK_MODE_VOICE) {
USER_LOG_DEBUG("Waiting opus decoder finished...");
while (s_isDecodeFinished == false) {
osalHandler->TaskSleepMs(1);
}
djiReturnCode = DjiTest_PlayAudioData();
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Play audio data failed, error: 0x%08llX.", djiReturnCode);
}
} else {
djiReturnCode = DjiTest_PlayTtsData();
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Play tts data failed, error: 0x%08llX.", djiReturnCode);
}
}
osalHandler->TaskSleepMs(1000);
} else {
if (s_speakerState.workMode == DJI_WIDGET_SPEAKER_WORK_MODE_VOICE) {
USER_LOG_DEBUG("Waiting opus decoder finished...");
while (s_isDecodeFinished == false) {
osalHandler->TaskSleepMs(1);
}
djiReturnCode = DjiTest_PlayAudioData();
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Play audio data failed, error: 0x%08llX.", djiReturnCode);
}
} else {
djiReturnCode = DjiTest_PlayTtsData();
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Play tts data failed, error: 0x%08llX.", djiReturnCode);
}
}
djiReturnCode = osalHandler->MutexLock(s_speakerMutex);
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", djiReturnCode);
}
if (s_speakerState.playMode == DJI_WIDGET_SPEAKER_PLAY_MODE_SINGLE_PLAY) {
s_speakerState.state = DJI_WIDGET_SPEAKER_STATE_IDEL;
}
djiReturnCode = osalHandler->MutexUnlock(s_speakerMutex);
if (djiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", djiReturnCode);
}
}
}
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,50 @@
/**
********************************************************************
* @file test_widget_speaker.h
* @brief This is the header file for "test_widget_speaker.c", 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 TEST_WIDGET_SPEAKER_H
#define TEST_WIDGET_SPEAKER_H
/* Includes ------------------------------------------------------------------*/
#include "dji_widget.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
T_DjiReturnCode DjiTest_WidgetSpeakerStartService(void);
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // TEST_WIDGET_SPEAKER_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,148 @@
{
"version": {
"major": 1,
"minor": 0
},
"main_interface": {
"floating_window": {
"is_enable": true
},
"speaker": {
"is_enable_tts": true,
"is_enable_voice": true
},
"widget_list": [
{
"widget_index": 0,
"widget_type": "button",
"widget_name": "按钮",
"icon_file_set": {
"icon_file_name_selected": "icon_button1.png",
"icon_file_name_unselected": "icon_button1.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 0
}
},
{
"widget_index": 1,
"widget_type": "list",
"widget_name": "列表",
"list_item": [
{
"item_name": "选项_1",
"icon_file_set": {
"icon_file_name_selected": "icon_list_item1.png",
"icon_file_name_unselected": "icon_list_item1.png"
}
},
{
"item_name": "选项_2",
"icon_file_set": {
"icon_file_name_selected": "icon_list_item2.png",
"icon_file_name_unselected": "icon_list_item2.png"
}
}
],
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 1
}
},
{
"widget_index": 2,
"widget_type": "switch",
"widget_name": "开关",
"icon_file_set": {
"icon_file_name_selected": "icon_switch_select.png",
"icon_file_name_unselected": "icon_switch_unselect.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 2
}
},
{
"widget_index": 3,
"widget_type": "scale",
"widget_name": "范围条",
"icon_file_set": {
"icon_file_name_selected": "icon_scale.png",
"icon_file_name_unselected": "icon_scale.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 3,
"button_value_step_length": 5
}
}
]
},
"config_interface": {
"text_input_box": {
"widget_name": "文本输入框",
"placeholder_text": "请输入消息",
"is_enable": true
},
"widget_list": [
{
"widget_index": 4,
"widget_type": "button",
"widget_name": "按钮 4",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 4
}
},
{
"widget_index": 5,
"widget_type": "scale",
"widget_name": "范围条 5",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 5,
"button_value_step_length": 5
}
},
{
"widget_index": 6,
"widget_type": "int_input_box",
"widget_name": "整形值输入框 6",
"int_input_box_hint": "unit:s"
},
{
"widget_index": 7,
"widget_type": "switch",
"widget_name": "开关 7",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 7
}
},
{
"widget_index": 8,
"widget_type": "list",
"widget_name": "列表 8",
"list_item": [
{
"item_name": "选项 1"
},
{
"item_name": "选项 2"
},
{
"item_name": "选项 3"
},
{
"item_name": "选项 4"
}
],
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 8
}
}
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,148 @@
{
"version": {
"major": 1,
"minor": 0
},
"main_interface": {
"floating_window": {
"is_enable": true
},
"speaker": {
"is_enable_tts": true,
"is_enable_voice": true
},
"widget_list": [
{
"widget_index": 0,
"widget_type": "button",
"widget_name": "Button",
"icon_file_set": {
"icon_file_name_selected": "icon_button1.png",
"icon_file_name_unselected": "icon_button1.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 0
}
},
{
"widget_index": 1,
"widget_type": "list",
"widget_name": "List",
"list_item": [
{
"item_name": "Item_1",
"icon_file_set": {
"icon_file_name_selected": "icon_list_item1.png",
"icon_file_name_unselected": "icon_list_item1.png"
}
},
{
"item_name": "Item_2",
"icon_file_set": {
"icon_file_name_selected": "icon_list_item2.png",
"icon_file_name_unselected": "icon_list_item2.png"
}
}
],
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 1
}
},
{
"widget_index": 2,
"widget_type": "switch",
"widget_name": "Switch",
"icon_file_set": {
"icon_file_name_selected": "icon_switch_select.png",
"icon_file_name_unselected": "icon_switch_unselect.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 2
}
},
{
"widget_index": 3,
"widget_type": "scale",
"widget_name": "Scale",
"icon_file_set": {
"icon_file_name_selected": "icon_scale.png",
"icon_file_name_unselected": "icon_scale.png"
},
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 3,
"button_value_step_length": 5
}
}
]
},
"config_interface": {
"text_input_box": {
"widget_name": "TextInputBox",
"placeholder_text": "Please input message",
"is_enable": true
},
"widget_list": [
{
"widget_index": 4,
"widget_type": "button",
"widget_name": "Button 4",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 4
}
},
{
"widget_index": 5,
"widget_type": "scale",
"widget_name": "Scale 5",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 5,
"button_value_step_length": 5
}
},
{
"widget_index": 6,
"widget_type": "int_input_box",
"widget_name": "Integer Input Box 6",
"int_input_box_hint": "unit:s"
},
{
"widget_index": 7,
"widget_type": "switch",
"widget_name": "Switch 7",
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 7
}
},
{
"widget_index": 8,
"widget_type": "list",
"widget_name": "List 8",
"list_item": [
{
"item_name": "Item 1"
},
{
"item_name": "Item 2"
},
{
"item_name": "Item 3"
},
{
"item_name": "Item 4"
}
],
"customize_rc_buttons_config": {
"is_enable": true,
"mapping_config_display_order": 8
}
}
]
}
}

Some files were not shown because too many files have changed in this diff Show More