NEW: release DJI Payload-SDK version 3.0
Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
@ -0,0 +1,95 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_camera_image_handler.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_camera_image_handler.hpp"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
DJICameraImageHandler::DJICameraImageHandler() : m_newImageFlag(false)
|
||||
{
|
||||
pthread_mutex_init(&m_mutex, NULL);
|
||||
pthread_cond_init(&m_condv, NULL);
|
||||
}
|
||||
|
||||
DJICameraImageHandler::~DJICameraImageHandler()
|
||||
{
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
pthread_cond_destroy(&m_condv);
|
||||
}
|
||||
|
||||
bool DJICameraImageHandler::getNewImageWithLock(CameraRGBImage ©OfImage, int timeoutMilliSec)
|
||||
{
|
||||
int result;
|
||||
|
||||
/*! @note
|
||||
* Here result == 0 means successful.
|
||||
* Because this is the behavior of pthread_cond_timedwait.
|
||||
*/
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
if (m_newImageFlag) {
|
||||
/* At this point, a copy of m_img is made, so it is safe to
|
||||
* do any modifications to copyOfImage in user code.
|
||||
*/
|
||||
copyOfImage = m_img;
|
||||
m_newImageFlag = false;
|
||||
result = 0;
|
||||
} else {
|
||||
struct timespec absTimeout;
|
||||
clock_gettime(CLOCK_REALTIME, &absTimeout);
|
||||
absTimeout.tv_nsec += timeoutMilliSec * 1e6;
|
||||
result = pthread_cond_timedwait(&m_condv, &m_mutex, &absTimeout);
|
||||
|
||||
if (result == 0) {
|
||||
copyOfImage = m_img;
|
||||
m_newImageFlag = false;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
return (result == 0) ? true : false;
|
||||
}
|
||||
|
||||
void DJICameraImageHandler::writeNewImageWithLock(uint8_t *buf, int bufSize, int width, int height)
|
||||
{
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
|
||||
m_img.rawData.assign(buf, buf + bufSize);
|
||||
m_img.height = height;
|
||||
m_img.width = width;
|
||||
m_newImageFlag = true;
|
||||
|
||||
pthread_cond_signal(&m_condv);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,74 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_camera_image_handler.hpp
|
||||
* @brief This is the header file for "dji_camera_image_handler.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_CAMERA_IMAGE_HANDLER_H
|
||||
#define DJI_CAMERA_IMAGE_HANDLER_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "pthread.h"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
struct CameraRGBImage {
|
||||
std::vector<uint8_t> rawData;
|
||||
int height;
|
||||
int width;
|
||||
};
|
||||
|
||||
typedef void (*CameraImageCallback)(CameraRGBImage pImg, void *userData);
|
||||
|
||||
typedef void (*H264Callback)(const uint8_t *buf, int bufLen, void *userData);
|
||||
|
||||
class DJICameraImageHandler {
|
||||
public:
|
||||
DJICameraImageHandler();
|
||||
~DJICameraImageHandler();
|
||||
|
||||
void writeNewImageWithLock(uint8_t *buf, int bufSize, int width, int height);
|
||||
bool getNewImageWithLock(CameraRGBImage ©OfImage, int timeoutMilliSec);
|
||||
|
||||
private:
|
||||
pthread_mutex_t m_mutex;
|
||||
pthread_cond_t m_condv;
|
||||
CameraRGBImage m_img;
|
||||
bool m_newImageFlag;
|
||||
};
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_CAMERA_IMAGE_HANDLER_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,277 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_camera_stream_decoder.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_camera_stream_decoder.hpp"
|
||||
#include "unistd.h"
|
||||
#include "pthread.h"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
DJICameraStreamDecoder::DJICameraStreamDecoder()
|
||||
: initSuccess(false),
|
||||
cbThreadIsRunning(false),
|
||||
cbThreadStatus(-1),
|
||||
cb(nullptr),
|
||||
cbUserParam(nullptr),
|
||||
pCodecCtx(nullptr),
|
||||
pCodec(nullptr),
|
||||
pCodecParserCtx(nullptr),
|
||||
pSwsCtx(nullptr),
|
||||
pFrameYUV(nullptr),
|
||||
pFrameRGB(nullptr),
|
||||
rgbBuf(nullptr),
|
||||
bufSize(0)
|
||||
{
|
||||
pthread_mutex_init(&decodemutex, nullptr);
|
||||
}
|
||||
|
||||
DJICameraStreamDecoder::~DJICameraStreamDecoder()
|
||||
{
|
||||
pthread_mutex_destroy(&decodemutex);
|
||||
if(cb)
|
||||
{
|
||||
registerCallback(nullptr, nullptr);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool DJICameraStreamDecoder::init()
|
||||
{
|
||||
pthread_mutex_lock(&decodemutex);
|
||||
|
||||
if (true == initSuccess) {
|
||||
USER_LOG_INFO("Decoder already initialized.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
avcodec_register_all();
|
||||
pCodecCtx = avcodec_alloc_context3(nullptr);
|
||||
if (!pCodecCtx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pCodecCtx->thread_count = 4;
|
||||
pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||
if (!pCodec || avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pCodecParserCtx = av_parser_init(AV_CODEC_ID_H264);
|
||||
if (!pCodecParserCtx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pFrameYUV = av_frame_alloc();
|
||||
if (!pFrameYUV) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pFrameRGB = av_frame_alloc();
|
||||
if (!pFrameRGB) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pSwsCtx = nullptr;
|
||||
|
||||
pCodecCtx->flags2 |= AV_CODEC_FLAG2_SHOW_ALL;
|
||||
initSuccess = true;
|
||||
|
||||
pthread_mutex_unlock(&decodemutex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DJICameraStreamDecoder::cleanup()
|
||||
{
|
||||
pthread_mutex_lock(&decodemutex);
|
||||
|
||||
initSuccess = false;
|
||||
if (nullptr != pSwsCtx) {
|
||||
sws_freeContext(pSwsCtx);
|
||||
pSwsCtx = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pFrameYUV) {
|
||||
av_free(pFrameYUV);
|
||||
pFrameYUV = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pCodecParserCtx) {
|
||||
av_parser_close(pCodecParserCtx);
|
||||
pCodecParserCtx = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pCodec) {
|
||||
avcodec_close(pCodecCtx);
|
||||
pCodec = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pCodecCtx) {
|
||||
av_free(pCodecCtx);
|
||||
pCodecCtx = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != rgbBuf) {
|
||||
av_free(rgbBuf);
|
||||
rgbBuf = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pFrameRGB) {
|
||||
av_free(pFrameRGB);
|
||||
pFrameRGB = nullptr;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&decodemutex);
|
||||
}
|
||||
|
||||
void *DJICameraStreamDecoder::callbackThreadEntry(void *p)
|
||||
{
|
||||
//DSTATUS_PRIVATE("****** Decoder Callback Thread Start ******\n");
|
||||
usleep(50 * 1000);
|
||||
static_cast<DJICameraStreamDecoder *>(p)->callbackThreadFunc();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DJICameraStreamDecoder::callbackThreadFunc()
|
||||
{
|
||||
while (cbThreadIsRunning) {
|
||||
CameraRGBImage copyOfImage;
|
||||
if (!decodedImageHandler.getNewImageWithLock(copyOfImage, 1000)) {
|
||||
//DDEBUG_PRIVATE("Decoder Callback Thread: Get image time out\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
(*cb)(copyOfImage, cbUserParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DJICameraStreamDecoder::decodeBuffer(const uint8_t *buf, int bufLen)
|
||||
{
|
||||
const uint8_t *pData = buf;
|
||||
int remainingLen = bufLen;
|
||||
int processedLen = 0;
|
||||
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
pthread_mutex_lock(&decodemutex);
|
||||
while (remainingLen > 0) {
|
||||
if (!pCodecParserCtx || !pCodecCtx) {
|
||||
//DSTATUS("Invalid decoder ctx.");
|
||||
break;
|
||||
}
|
||||
processedLen = av_parser_parse2(pCodecParserCtx, pCodecCtx,
|
||||
&pkt.data, &pkt.size,
|
||||
pData, remainingLen,
|
||||
AV_NOPTS_VALUE, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
|
||||
remainingLen -= processedLen;
|
||||
pData += processedLen;
|
||||
|
||||
if (pkt.size > 0) {
|
||||
int gotPicture = 0;
|
||||
avcodec_decode_video2(pCodecCtx, pFrameYUV, &gotPicture, &pkt);
|
||||
|
||||
if (!gotPicture) {
|
||||
////DSTATUS_PRIVATE("Got Frame, but no picture\n");
|
||||
continue;
|
||||
} else {
|
||||
int w = pFrameYUV->width;
|
||||
int h = pFrameYUV->height;
|
||||
////DSTATUS_PRIVATE("Got picture! size=%dx%d\n", w, h);
|
||||
|
||||
if (nullptr == pSwsCtx) {
|
||||
pSwsCtx = sws_getContext(w, h, pCodecCtx->pix_fmt,
|
||||
w, h, AV_PIX_FMT_RGB24,
|
||||
4, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (nullptr == rgbBuf) {
|
||||
bufSize = avpicture_get_size(AV_PIX_FMT_RGB24, w, h);
|
||||
rgbBuf = (uint8_t *) av_malloc(bufSize);
|
||||
avpicture_fill((AVPicture *) pFrameRGB, rgbBuf, AV_PIX_FMT_RGB24, w, h);
|
||||
}
|
||||
|
||||
if (nullptr != pSwsCtx && nullptr != rgbBuf) {
|
||||
sws_scale(pSwsCtx,
|
||||
(uint8_t const *const *) pFrameYUV->data, pFrameYUV->linesize, 0, pFrameYUV->height,
|
||||
pFrameRGB->data, pFrameRGB->linesize);
|
||||
|
||||
pFrameRGB->height = h;
|
||||
pFrameRGB->width = w;
|
||||
|
||||
decodedImageHandler.writeNewImageWithLock(pFrameRGB->data[0], bufSize, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&decodemutex);
|
||||
av_free_packet(&pkt);
|
||||
}
|
||||
|
||||
bool DJICameraStreamDecoder::registerCallback(CameraImageCallback f, void *param)
|
||||
{
|
||||
cb = f;
|
||||
cbUserParam = param;
|
||||
|
||||
/* When users register a non-nullptr callback, we will start the callback thread. */
|
||||
if (nullptr != cb) {
|
||||
if (!cbThreadIsRunning) {
|
||||
cbThreadStatus = pthread_create(&callbackThread, nullptr, callbackThreadEntry, this);
|
||||
if (0 == cbThreadStatus) {
|
||||
//DSTATUS_PRIVATE("User callback thread created successfully!\n");
|
||||
cbThreadIsRunning = true;
|
||||
return true;
|
||||
} else {
|
||||
//DERROR_PRIVATE("User called thread creation failed!\n");
|
||||
cbThreadIsRunning = false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//DERROR_PRIVATE("Callback thread already running!\n");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (cbThreadStatus == 0) {
|
||||
cbThreadIsRunning = false;
|
||||
pthread_join(callbackThread, nullptr);
|
||||
cbThreadStatus = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,96 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_camera_stream_decoder.hpp
|
||||
* @brief This is the header file for "dji_camera_stream_decoder.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_CAMERA_STREAM_DECCODER_H
|
||||
#define DJI_CAMERA_STREAM_DECCODER_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
#include "pthread.h"
|
||||
#include "dji_camera_image_handler.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
class DJICameraStreamDecoder {
|
||||
public:
|
||||
DJICameraStreamDecoder();
|
||||
~DJICameraStreamDecoder();
|
||||
bool init();
|
||||
void cleanup();
|
||||
|
||||
void callbackThreadFunc();
|
||||
void decodeBuffer(const uint8_t *pBuf, int len);
|
||||
static void *callbackThreadEntry(void *p);
|
||||
bool registerCallback(CameraImageCallback f, void *param);
|
||||
DJICameraImageHandler decodedImageHandler;
|
||||
|
||||
private:
|
||||
pthread_t callbackThread;
|
||||
bool initSuccess;
|
||||
bool cbThreadIsRunning;
|
||||
int cbThreadStatus;
|
||||
CameraImageCallback cb;
|
||||
void *cbUserParam;
|
||||
|
||||
pthread_mutex_t decodemutex;
|
||||
AVCodecContext *pCodecCtx;
|
||||
AVCodec *pCodec;
|
||||
AVCodecParserContext *pCodecParserCtx;
|
||||
SwsContext *pSwsCtx;
|
||||
|
||||
AVFrame *pFrameYUV;
|
||||
AVFrame *pFrameRGB;
|
||||
uint8_t *rgbBuf;
|
||||
size_t bufSize;
|
||||
};
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_CAMERA_STREAM_DECCODER_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
209
samples/sample_c++/module_sample/liveview/test_liveview.cpp
Normal file
@ -0,0 +1,209 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_liveview.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "test_liveview.hpp"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
std::map<::E_DjiLiveViewCameraPosition, DJICameraStreamDecoder *> streamDecoder;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static void LiveviewConvertH264ToRgbCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf, uint32_t bufLen);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
LiveviewSample::LiveviewSample()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_Init();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Liveview init failed");
|
||||
}
|
||||
|
||||
streamDecoder = {
|
||||
{DJI_LIVEVIEW_CAMERA_POSITION_FPV, (new DJICameraStreamDecoder())},
|
||||
{DJI_LIVEVIEW_CAMERA_POSITION_NO_1, (new DJICameraStreamDecoder())},
|
||||
{DJI_LIVEVIEW_CAMERA_POSITION_NO_2, (new DJICameraStreamDecoder())},
|
||||
{DJI_LIVEVIEW_CAMERA_POSITION_NO_3, (new DJICameraStreamDecoder())},
|
||||
};
|
||||
}
|
||||
|
||||
LiveviewSample::~LiveviewSample()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_Deinit();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Liveview deinit failed");
|
||||
}
|
||||
|
||||
for (auto pair : streamDecoder) {
|
||||
if (pair.second) {
|
||||
delete pair.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StartFpvCameraStream(CameraImageCallback callback, void *userData)
|
||||
{
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_FPV);
|
||||
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->init();
|
||||
deocder->second->registerCallback(callback, userData);
|
||||
|
||||
return DjiLiveview_StartH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_FPV, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
|
||||
LiveviewConvertH264ToRgbCallback);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StartMainCameraStream(CameraImageCallback callback, void *userData)
|
||||
{
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_1);
|
||||
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->init();
|
||||
deocder->second->registerCallback(callback, userData);
|
||||
|
||||
return DjiLiveview_StartH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_1, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
|
||||
LiveviewConvertH264ToRgbCallback);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StartViceCameraStream(CameraImageCallback callback, void *userData)
|
||||
{
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_2);
|
||||
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->init();
|
||||
deocder->second->registerCallback(callback, userData);
|
||||
|
||||
return DjiLiveview_StartH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_2, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
|
||||
LiveviewConvertH264ToRgbCallback);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StartTopCameraStream(CameraImageCallback callback, void *userData)
|
||||
{
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_3);
|
||||
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->init();
|
||||
deocder->second->registerCallback(callback, userData);
|
||||
|
||||
return DjiLiveview_StartH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_3, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT,
|
||||
LiveviewConvertH264ToRgbCallback);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StopFpvCameraStream()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_FPV);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_FPV);
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->cleanup();
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StopMainCameraStream()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_1);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_1);
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->cleanup();
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StopViceCameraStream()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_2);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_2);
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->cleanup();
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode LiveviewSample::StopTopCameraStream()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_NO_3);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
auto deocder = streamDecoder.find(DJI_LIVEVIEW_CAMERA_POSITION_NO_3);
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->cleanup();
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static void LiveviewConvertH264ToRgbCallback(E_DjiLiveViewCameraPosition position, const uint8_t *buf, uint32_t bufLen)
|
||||
{
|
||||
auto deocder = streamDecoder.find(position);
|
||||
if ((deocder != streamDecoder.end()) && deocder->second) {
|
||||
deocder->second->decodeBuffer(buf, bufLen);
|
||||
}
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
70
samples/sample_c++/module_sample/liveview/test_liveview.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_liveview.hpp
|
||||
* @brief This is the header file for "test_liveview.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef TEST_LIVEVIEW_H
|
||||
#define TEST_LIVEVIEW_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_liveview.h"
|
||||
#include <map>
|
||||
#include "dji_camera_stream_decoder.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
using namespace std;
|
||||
|
||||
class LiveviewSample {
|
||||
public:
|
||||
LiveviewSample();
|
||||
~LiveviewSample();
|
||||
|
||||
T_DjiReturnCode StartFpvCameraStream(CameraImageCallback callback, void *userData);
|
||||
T_DjiReturnCode StopFpvCameraStream();
|
||||
|
||||
T_DjiReturnCode StartMainCameraStream(CameraImageCallback callback, void *userData);
|
||||
T_DjiReturnCode StopMainCameraStream();
|
||||
|
||||
T_DjiReturnCode StartViceCameraStream(CameraImageCallback callback, void *userData);
|
||||
T_DjiReturnCode StopViceCameraStream();
|
||||
|
||||
T_DjiReturnCode StartTopCameraStream(CameraImageCallback callback, void *userData);
|
||||
T_DjiReturnCode StopTopCameraStream();
|
||||
};
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_LIVEVIEW_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
309
samples/sample_c++/module_sample/liveview/test_liveview_entry.cpp
Executable file
@ -0,0 +1,309 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_liveview_entry.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <iostream>
|
||||
#include <dji_logger.h>
|
||||
#include "test_liveview_entry.hpp"
|
||||
#include "test_liveview.hpp"
|
||||
|
||||
#ifdef OPEN_CV_INSTALLED
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/dnn.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "../../../sample_c/module_sample/utils/util_misc.h"
|
||||
|
||||
using namespace cv;
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
const char *classNames[] = {"background", "person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck",
|
||||
"boat", "traffic light",
|
||||
"fire hydrant", "background", "stop sign", "parking meter", "bench", "bird", "cat", "dog",
|
||||
"horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "background", "backpack",
|
||||
"umbrella", "background", "background", "handbag", "tie", "suitcase", "frisbee", "skis",
|
||||
"snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard",
|
||||
"surfboard", "tennis racket",
|
||||
"bottle", "background", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana",
|
||||
"apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut",
|
||||
"cake", "chair", "couch", "potted plant", "bed", "background", "dining table", "background",
|
||||
"background", "toilet", "background", "tv", "laptop", "mouse", "remote", "keyboard",
|
||||
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "background", "book",
|
||||
"clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"};
|
||||
|
||||
const size_t inWidth = 320;
|
||||
const size_t inHeight = 300;
|
||||
const float WHRatio = inWidth / (float) inHeight;
|
||||
static int32_t s_demoIndex = -1;
|
||||
char curFileDirPath[DJI_FILE_PATH_SIZE_MAX];
|
||||
char tempFileDirPath[DJI_FILE_PATH_SIZE_MAX];
|
||||
char prototxtFileDirPath[DJI_FILE_PATH_SIZE_MAX];
|
||||
char weightsFileDirPath[DJI_FILE_PATH_SIZE_MAX];
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static void DjiUser_ShowRgbImageCallback(CameraRGBImage img, void *userData);
|
||||
static T_DjiReturnCode DjiUser_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void DjiUser_RunCameraStreamViewSample()
|
||||
{
|
||||
char cameraIndexChar = 0;
|
||||
char demoIndexChar = 0;
|
||||
char isQuit = 0;
|
||||
CameraRGBImage camImg;
|
||||
char fpvName[] = "FPV_CAM";
|
||||
char mainName[] = "MAIN_CAM";
|
||||
char viceName[] = "VICE_CAM";
|
||||
char topName[] = "TOP_CAM";
|
||||
auto *liveviewSample = new LiveviewSample();
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiUser_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);
|
||||
}
|
||||
|
||||
cout << "Please enter the type of camera stream you want to view\n\n"
|
||||
<< "--> [f] Fpv Camera\n"
|
||||
<< "--> [m] Main Camera\n"
|
||||
<< "--> [v] Vice Camera\n"
|
||||
<< "--> [t] Top Camera\n"
|
||||
<< endl;
|
||||
cin >> cameraIndexChar;
|
||||
|
||||
switch (cameraIndexChar) {
|
||||
case 'f':
|
||||
case 'F':
|
||||
liveviewSample->StartFpvCameraStream(&DjiUser_ShowRgbImageCallback, &fpvName);
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
liveviewSample->StartMainCameraStream(&DjiUser_ShowRgbImageCallback, &mainName);
|
||||
break;
|
||||
case 'v':
|
||||
case 'V':
|
||||
liveviewSample->StartViceCameraStream(&DjiUser_ShowRgbImageCallback, &viceName);
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
liveviewSample->StartTopCameraStream(&DjiUser_ShowRgbImageCallback, &topName);
|
||||
break;
|
||||
default:
|
||||
cout << "No camera selected";
|
||||
delete liveviewSample;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Please choose the stream demo you want to run\n\n"
|
||||
<< "--> [0] Normal RGB image display\n"
|
||||
<< "--> [1] Binary image display\n"
|
||||
<< "--> [2] Faces detection demo\n"
|
||||
<< "--> [3] Tensorflow Object detection demo\n"
|
||||
<< endl;
|
||||
cin >> demoIndexChar;
|
||||
|
||||
switch (demoIndexChar) {
|
||||
case '0':
|
||||
s_demoIndex = 0;
|
||||
break;
|
||||
case '1':
|
||||
s_demoIndex = 1;
|
||||
break;
|
||||
case '2':
|
||||
s_demoIndex = 2;
|
||||
break;
|
||||
case '3':
|
||||
s_demoIndex = 3;
|
||||
break;
|
||||
default:
|
||||
cout << "No demo selected";
|
||||
delete liveviewSample;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Please enter the 'q' or 'Q' to quit camera stream view\n"
|
||||
<< endl;
|
||||
|
||||
while (true) {
|
||||
cin >> isQuit;
|
||||
if (isQuit == 'q' || isQuit == 'Q') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (cameraIndexChar) {
|
||||
case 'f':
|
||||
case 'F':
|
||||
liveviewSample->StopFpvCameraStream();
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
liveviewSample->StopMainCameraStream();
|
||||
break;
|
||||
case 'v':
|
||||
case 'V':
|
||||
liveviewSample->StopViceCameraStream();
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
liveviewSample->StopTopCameraStream();
|
||||
break;
|
||||
default:
|
||||
cout << "No camera selected";
|
||||
delete liveviewSample;
|
||||
return;
|
||||
}
|
||||
|
||||
delete liveviewSample;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static void DjiUser_ShowRgbImageCallback(CameraRGBImage img, void *userData)
|
||||
{
|
||||
string name = string(reinterpret_cast<char *>(userData));
|
||||
|
||||
#ifdef OPEN_CV_INSTALLED
|
||||
Mat mat(img.height, img.width, CV_8UC3, img.rawData.data(), img.width * 3);
|
||||
|
||||
if (s_demoIndex == 0) {
|
||||
cvtColor(mat, mat, COLOR_RGB2BGR);
|
||||
imshow(name, mat);
|
||||
} else if (s_demoIndex == 1) {
|
||||
cvtColor(mat, mat, COLOR_RGB2GRAY);
|
||||
Mat mask;
|
||||
cv::threshold(mat, mask, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
|
||||
imshow(name, mask);
|
||||
} else if (s_demoIndex == 2) {
|
||||
cvtColor(mat, mat, COLOR_RGB2BGR);
|
||||
snprintf(tempFileDirPath, DJI_FILE_PATH_SIZE_MAX, "%s/data/haarcascade_frontalface_alt.xml", curFileDirPath);
|
||||
auto faceDetector = cv::CascadeClassifier(tempFileDirPath);
|
||||
std::vector<Rect> faces;
|
||||
faceDetector.detectMultiScale(mat, faces, 1.1, 3, 0, Size(50, 50));
|
||||
|
||||
for (int i = 0; i < faces.size(); ++i) {
|
||||
cout << "index: " << i;
|
||||
cout << " x: " << faces[i].x;
|
||||
cout << " y: " << faces[i].y << endl;
|
||||
|
||||
cv::rectangle(mat, cvPoint(faces[i].x, faces[i].y),
|
||||
cvPoint(faces[i].x + faces[i].width, faces[i].y + faces[i].height),
|
||||
Scalar(0, 0, 255), 2, 1, 0);
|
||||
}
|
||||
imshow(name, mat);
|
||||
} else if (s_demoIndex == 3) {
|
||||
snprintf(prototxtFileDirPath, DJI_FILE_PATH_SIZE_MAX,
|
||||
"%s/data/tensorflow/ssd_inception_v2_coco_2017_11_17.pbtxt",
|
||||
curFileDirPath);
|
||||
//Attention: If you want to run the Tensorflow Object detection demo, Please download the tensorflow model.
|
||||
//Download Url: http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2017_11_17.tar.gz
|
||||
snprintf(weightsFileDirPath, DJI_FILE_PATH_SIZE_MAX, "%s/data/tensorflow/frozen_inference_graph.pb",
|
||||
curFileDirPath);
|
||||
|
||||
dnn::Net net = cv::dnn::readNetFromTensorflow(weightsFileDirPath, prototxtFileDirPath);
|
||||
Size frame_size = mat.size();
|
||||
|
||||
Size cropSize;
|
||||
if (frame_size.width / (float) frame_size.height > WHRatio) {
|
||||
cropSize = Size(static_cast<int>(frame_size.height * WHRatio),
|
||||
frame_size.height);
|
||||
} else {
|
||||
cropSize = Size(frame_size.width,
|
||||
static_cast<int>(frame_size.width / WHRatio));
|
||||
}
|
||||
|
||||
Rect crop(Point((frame_size.width - cropSize.width) / 2,
|
||||
(frame_size.height - cropSize.height) / 2),
|
||||
cropSize);
|
||||
|
||||
cv::Mat blob = cv::dnn::blobFromImage(mat, 1, Size(300, 300));
|
||||
net.setInput(blob);
|
||||
Mat output = net.forward();
|
||||
Mat detectionMat(output.size[2], output.size[3], CV_32F, output.ptr<float>());
|
||||
|
||||
mat = mat(crop);
|
||||
float confidenceThreshold = 0.50;
|
||||
|
||||
for (int i = 0; i < detectionMat.rows; i++) {
|
||||
float confidence = detectionMat.at<float>(i, 2);
|
||||
if (confidence > confidenceThreshold) {
|
||||
auto objectClass = (size_t) (detectionMat.at<float>(i, 1));
|
||||
|
||||
int xLeftBottom = static_cast<int>(detectionMat.at<float>(i, 3) * mat.cols);
|
||||
int yLeftBottom = static_cast<int>(detectionMat.at<float>(i, 4) * mat.rows);
|
||||
int xRightTop = static_cast<int>(detectionMat.at<float>(i, 5) * mat.cols);
|
||||
int yRightTop = static_cast<int>(detectionMat.at<float>(i, 6) * mat.rows);
|
||||
|
||||
ostringstream ss;
|
||||
ss << confidence;
|
||||
String conf(ss.str());
|
||||
|
||||
Rect object((int) xLeftBottom, (int) yLeftBottom,
|
||||
(int) (xRightTop - xLeftBottom),
|
||||
(int) (yRightTop - yLeftBottom));
|
||||
|
||||
rectangle(mat, object, Scalar(0, 255, 0), 2);
|
||||
String label = String(classNames[objectClass]) + ": " + conf;
|
||||
|
||||
int baseLine = 0;
|
||||
Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
|
||||
rectangle(mat, Rect(Point(xLeftBottom, yLeftBottom - labelSize.height),
|
||||
Size(labelSize.width, labelSize.height + baseLine)), Scalar(0, 255, 0), CV_FILLED);
|
||||
putText(mat, label, Point(xLeftBottom, yLeftBottom), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 0, 0));
|
||||
}
|
||||
}
|
||||
imshow(name, mat);
|
||||
}
|
||||
|
||||
cv::waitKey(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUser_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;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,48 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_liveview_entry.hpp
|
||||
* @brief This is the header file for "test_liveview_entry.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef TEST_LIVEVIEW_ENTRY_H
|
||||
#define TEST_LIVEVIEW_ENTRY_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
void DjiUser_RunCameraStreamViewSample();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_LIVEVIEW_ENTRY_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
120
samples/sample_c++/module_sample/perception/test_perception.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_perception.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdexcept>
|
||||
#include "test_perception.hpp"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
PerceptionSample::PerceptionSample()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiPerception_Init();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Perception init failed");
|
||||
}
|
||||
}
|
||||
|
||||
PerceptionSample::~PerceptionSample()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiPerception_Deinit();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Perception deinit failed");
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeFrontImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_FRONT, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeRearImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_REAR, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeLeftImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_LEFT, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeRightImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_RIGHT, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeUpImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_UP, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::SubscribeDownImage(DjiPerceptionImageCallback callback)
|
||||
{
|
||||
return DjiPerception_SubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_DOWN, callback);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeFrontImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_FRONT);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeRearImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_REAR);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeLeftImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_LEFT);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeRightImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_RIGHT);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeUpImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_UP);
|
||||
}
|
||||
|
||||
T_DjiReturnCode PerceptionSample::UnSubscribeDownImage()
|
||||
{
|
||||
return DjiPerception_UnsubscribePerceptionImage(DJI_PERCEPTION_RECTIFY_DOWN);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_perception.hpp
|
||||
* @brief This is the header file for "test_perception.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef TEST_PERCEPTION_H
|
||||
#define TEST_PERCEPTION_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_perception.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
using namespace std;
|
||||
|
||||
class PerceptionSample {
|
||||
public:
|
||||
PerceptionSample();
|
||||
~PerceptionSample();
|
||||
|
||||
T_DjiReturnCode SubscribeFrontImage(DjiPerceptionImageCallback callback);
|
||||
T_DjiReturnCode SubscribeRearImage(DjiPerceptionImageCallback callback);
|
||||
T_DjiReturnCode SubscribeLeftImage(DjiPerceptionImageCallback callback);
|
||||
T_DjiReturnCode SubscribeRightImage(DjiPerceptionImageCallback callback);
|
||||
T_DjiReturnCode SubscribeUpImage(DjiPerceptionImageCallback callback);
|
||||
T_DjiReturnCode SubscribeDownImage(DjiPerceptionImageCallback callback);
|
||||
|
||||
T_DjiReturnCode UnSubscribeFrontImage();
|
||||
T_DjiReturnCode UnSubscribeRearImage();
|
||||
T_DjiReturnCode UnSubscribeLeftImage();
|
||||
T_DjiReturnCode UnSubscribeRightImage();
|
||||
T_DjiReturnCode UnSubscribeUpImage();
|
||||
T_DjiReturnCode UnSubscribeDownImage();
|
||||
private:
|
||||
};
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_PERCEPTION_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,358 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_perception_entry.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dirent.h>
|
||||
#include "test_perception_entry.hpp"
|
||||
#include "dji_logger.h"
|
||||
#include "dji_perception.h"
|
||||
#include "test_perception.hpp"
|
||||
|
||||
#ifdef OPEN_CV_INSTALLED
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define USER_PERCEPTION_TASK_STACK_SIZE (1024)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
T_DjiPerceptionImageInfo info;
|
||||
uint8_t *imageRawBuffer;
|
||||
T_DjiMutexHandle mutex;
|
||||
bool gotData;
|
||||
} T_DjiTestStereoImagePacket;
|
||||
|
||||
typedef struct {
|
||||
E_DjiPerceptionCameraPosition cameraPosition;
|
||||
char const *name;
|
||||
} T_DjiTestPerceptionCameraPositionName;
|
||||
|
||||
typedef struct {
|
||||
E_DjiPerceptionDirection direction;
|
||||
char const *name;
|
||||
} T_DjiTestPerceptionDirectionName;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static T_DjiTaskHandle s_stereoImageThread;
|
||||
static T_DjiTestStereoImagePacket s_stereoImagePacket = {
|
||||
.info = {0},
|
||||
.imageRawBuffer = nullptr,
|
||||
.mutex = nullptr,
|
||||
.gotData = false};
|
||||
|
||||
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"},
|
||||
};
|
||||
|
||||
static const T_DjiTestPerceptionCameraPositionName positionName[] = {
|
||||
{.cameraPosition = RECTIFY_DOWN_LEFT, .name = "down_l"},
|
||||
{.cameraPosition = RECTIFY_DOWN_RIGHT, .name = "down_r"},
|
||||
{.cameraPosition = RECTIFY_FRONT_LEFT, .name = "front_l"},
|
||||
{.cameraPosition = RECTIFY_FRONT_RIGHT, .name = "front_r"},
|
||||
{.cameraPosition = RECTIFY_REAR_LEFT, .name = "rear_l"},
|
||||
{.cameraPosition = RECTIFY_REAR_RIGHT, .name = "rear_r"},
|
||||
{.cameraPosition = RECTIFY_UP_LEFT, .name = "up_l"},
|
||||
{.cameraPosition = RECTIFY_UP_RIGHT, .name = "up_r"},
|
||||
{.cameraPosition = RECTIFY_LEFT_LEFT, .name = "left_l"},
|
||||
{.cameraPosition = RECTIFY_LEFT_RIGHT, .name = "left_r"},
|
||||
{.cameraPosition = RECTIFY_RIGHT_LEFT, .name = "right_l"},
|
||||
{.cameraPosition = RECTIFY_RIGHT_RIGHT, .name = "right_r"},
|
||||
};
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static void DjiTest_PerceptionImageCallback(T_DjiPerceptionImageInfo imageInfo, uint8_t *imageRawBuffer,
|
||||
uint32_t bufferLen);
|
||||
static void *DjiTest_StereoImagesDisplayTask(void *arg);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void DjiUser_RunStereoVisionViewSample(void)
|
||||
{
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
char inputChar;
|
||||
char isQuit;
|
||||
auto *perceptionSample = new PerceptionSample;
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiPerceptionCameraParametersPacket cameraParametersPacket = {0};
|
||||
|
||||
returnCode = osalHandler->MutexCreate(&s_stereoImagePacket.mutex);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Crete mutex failed, return code:0x%08X", returnCode);
|
||||
goto DeletePerception;
|
||||
}
|
||||
|
||||
returnCode = osalHandler->TaskCreate("user_perception_task", DjiTest_StereoImagesDisplayTask,
|
||||
USER_PERCEPTION_TASK_STACK_SIZE, &s_stereoImagePacket, &s_stereoImageThread);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Crete task failed, return code:0x%08X", returnCode);
|
||||
goto DestroyMutex;
|
||||
}
|
||||
|
||||
returnCode = DjiPerception_GetStereoCameraParameters(&cameraParametersPacket);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Get camera parameters failed, return code:0x%08X", returnCode);
|
||||
goto DestroyTask;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cameraParametersPacket.directionNum; i++) {
|
||||
USER_LOG_INFO(" [%-05s] leftIntrinsics = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
|
||||
directionName[cameraParametersPacket.cameraParameters[i].direction].name,
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[0],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[1],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[2],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[3],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[4],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[5],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[6],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[7],
|
||||
cameraParametersPacket.cameraParameters[i].leftIntrinsics[8]);
|
||||
USER_LOG_INFO("[%-05s] rightIntrinsics = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
|
||||
directionName[cameraParametersPacket.cameraParameters[i].direction].name,
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[0],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[1],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[2],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[3],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[4],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[5],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[6],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[7],
|
||||
cameraParametersPacket.cameraParameters[i].rightIntrinsics[8]);
|
||||
USER_LOG_INFO("[%-05s] rotationLeftInRight = {%f, %f, %f, %f, %f, %f, %f, %f, %f }",
|
||||
directionName[cameraParametersPacket.cameraParameters[i].direction].name,
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[0],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[1],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[2],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[3],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[4],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[5],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[6],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[7],
|
||||
cameraParametersPacket.cameraParameters[i].rotationLeftInRight[8]);
|
||||
USER_LOG_INFO("[%-05s] translationLeftInRight = {%f, %f, %f }\r\n",
|
||||
directionName[cameraParametersPacket.cameraParameters[i].direction].name,
|
||||
cameraParametersPacket.cameraParameters[i].translationLeftInRight[0],
|
||||
cameraParametersPacket.cameraParameters[i].translationLeftInRight[1],
|
||||
cameraParametersPacket.cameraParameters[i].translationLeftInRight[2]);
|
||||
osalHandler->TaskSleepMs(100);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
std::cout
|
||||
<< "| Available commands: |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [d] Subscribe down stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [f] Subscribe front stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [r] Subscribe rear stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [u] Subscribe up stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [l] Subscribe left stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [t] Subscribe right stereo camera pair images |"
|
||||
<<
|
||||
std::endl;
|
||||
std::cout
|
||||
<< "| [q] quit |"
|
||||
<<
|
||||
std::endl;
|
||||
|
||||
std::cin >> inputChar;
|
||||
switch (inputChar) {
|
||||
case 'd':
|
||||
USER_LOG_INFO("Subscribe down stereo camera pair images.");
|
||||
perceptionSample->SubscribeDownImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 'f':
|
||||
USER_LOG_INFO("Subscribe front stereo camera pair images.");
|
||||
perceptionSample->SubscribeFrontImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 'r':
|
||||
USER_LOG_INFO("Subscribe rear stereo camera pair images.");
|
||||
perceptionSample->SubscribeRearImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 'u':
|
||||
USER_LOG_INFO("Subscribe up stereo camera pair images.");
|
||||
perceptionSample->SubscribeUpImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 'l':
|
||||
USER_LOG_INFO("Subscribe left stereo camera pair images.");
|
||||
perceptionSample->SubscribeLeftImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 't':
|
||||
USER_LOG_INFO("Subscribe right stereo camera pair images.");
|
||||
perceptionSample->SubscribeRightImage(DjiTest_PerceptionImageCallback);
|
||||
break;
|
||||
case 'g':
|
||||
USER_LOG_INFO("Do stereo camera parameters subscription");
|
||||
break;
|
||||
case 'q':
|
||||
goto DestroyTask;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
cin >> isQuit;
|
||||
if (isQuit == 'q' || isQuit == 'Q') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (inputChar) {
|
||||
case 'd':
|
||||
USER_LOG_INFO("Unsubscribe down stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeDownImage();
|
||||
break;
|
||||
case 'f':
|
||||
USER_LOG_INFO("Unsubscribe front stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeFrontImage();
|
||||
break;
|
||||
case 'r':
|
||||
USER_LOG_INFO("Unsubscribe rear stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeRearImage();
|
||||
break;
|
||||
case 'u':
|
||||
USER_LOG_INFO("Unsubscribe up stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeUpImage();
|
||||
break;
|
||||
case 'l':
|
||||
USER_LOG_INFO("Unsubscribe left stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeLeftImage();
|
||||
break;
|
||||
case 't':
|
||||
USER_LOG_INFO("Unsubscribe right stereo camera pair images.");
|
||||
perceptionSample->UnSubscribeRightImage();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
DestroyTask:
|
||||
returnCode = osalHandler->TaskDestroy(s_stereoImageThread);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Destroy task failed, return code:0x%08X", returnCode);
|
||||
}
|
||||
|
||||
DestroyMutex:
|
||||
returnCode = osalHandler->MutexDestroy(s_stereoImagePacket.mutex);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Destroy mutex failed, return code:0x%08X", returnCode);
|
||||
}
|
||||
|
||||
DeletePerception:
|
||||
delete perceptionSample;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static void DjiTest_PerceptionImageCallback(T_DjiPerceptionImageInfo imageInfo, uint8_t *imageRawBuffer,
|
||||
uint32_t bufferLen)
|
||||
{
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
USER_LOG_INFO("image info : dataId(%d) seq(%d) timestamp(%llu) datatype(%d) index(%d) h(%d) w(%d) dir(%d) "
|
||||
"bpp(%d) bufferlen(%d)", imageInfo.dataId, imageInfo.sequence, imageInfo.timeStamp,
|
||||
imageInfo.dataType,
|
||||
imageInfo.rawInfo.index, imageInfo.rawInfo.height, imageInfo.rawInfo.width,
|
||||
imageInfo.rawInfo.direction,
|
||||
imageInfo.rawInfo.bpp, bufferLen);
|
||||
|
||||
if (imageRawBuffer) {
|
||||
osalHandler->MutexLock(s_stereoImagePacket.mutex);
|
||||
s_stereoImagePacket.info = imageInfo;
|
||||
if (s_stereoImagePacket.imageRawBuffer) osalHandler->Free(s_stereoImagePacket.imageRawBuffer);
|
||||
s_stereoImagePacket.imageRawBuffer = (uint8_t *) osalHandler->Malloc(bufferLen);
|
||||
memcpy(s_stereoImagePacket.imageRawBuffer, imageRawBuffer, bufferLen);
|
||||
s_stereoImagePacket.gotData = true;
|
||||
osalHandler->MutexUnlock(s_stereoImagePacket.mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static void *DjiTest_StereoImagesDisplayTask(void *arg)
|
||||
{
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
auto *pack = (T_DjiTestStereoImagePacket *) arg;
|
||||
char nameStr[32] = {0};
|
||||
|
||||
while (true) {
|
||||
osalHandler->TaskSleepMs(1);
|
||||
#ifdef OPEN_CV_INSTALLED
|
||||
/*! Get data here */
|
||||
osalHandler->MutexLock(pack->mutex);
|
||||
if (!pack->gotData) {
|
||||
osalHandler->MutexUnlock(pack->mutex);
|
||||
continue;
|
||||
}
|
||||
cv::Mat cv_img_stereo = cv::Mat(pack->info.rawInfo.height, pack->info.rawInfo.width, CV_8U);
|
||||
int copySize = pack->info.rawInfo.height * pack->info.rawInfo.width;
|
||||
if (pack->imageRawBuffer) {
|
||||
memcpy(cv_img_stereo.data, pack->imageRawBuffer, copySize);
|
||||
osalHandler->Free(pack->imageRawBuffer);
|
||||
pack->imageRawBuffer = NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizeof(positionName) / sizeof(T_DjiTestPerceptionCameraPositionName); ++i) {
|
||||
if (positionName[i].cameraPosition == pack->info.dataType) {
|
||||
sprintf(nameStr, "Image position: %s", positionName[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pack->gotData = false;
|
||||
osalHandler->MutexUnlock(pack->mutex);
|
||||
|
||||
/*! Using Opencv display here */
|
||||
cv::imshow(nameStr, cv_img_stereo);
|
||||
cv::waitKey(1);
|
||||
#else
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
USER_LOG_WARN("Please install opencv to run this stereo image display sample.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,49 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file test_perception_entry.hpp
|
||||
* @brief This is the header file for "test_perception_entry.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef TEST_PERCEPTION_ENTRY_H
|
||||
#define TEST_PERCEPTION_ENTRY_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_perception.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
void DjiUser_RunStereoVisionViewSample(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_PERCEPTION_ENTRY_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
311
samples/sample_c++/platform/linux/common/osal/osal.c
Normal file
@ -0,0 +1,311 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file psdk_osal.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal.h"
|
||||
#include "dji_typedef.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *), uint32_t stackSize, void *arg,
|
||||
T_DjiTaskHandle *task)
|
||||
{
|
||||
int result;
|
||||
char nameDealed[16] = {0};
|
||||
|
||||
*task = malloc(sizeof(pthread_t));
|
||||
if (*task == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_create(*task, NULL, taskFunc, arg);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (name != NULL)
|
||||
strncpy(nameDealed, name, sizeof(nameDealed) - 1);
|
||||
result = pthread_setname_np(*(pthread_t *) *task, nameDealed);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task)
|
||||
{
|
||||
pthread_cancel(*(pthread_t *) task);
|
||||
free(task);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs)
|
||||
{
|
||||
usleep(1000 * timeMs);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the mutex container, initialize the mutex, and
|
||||
* create mutex ID.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
*mutex = malloc(sizeof(pthread_mutex_t));
|
||||
if (*mutex == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_mutex_init(*mutex, NULL);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created mutex.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = pthread_mutex_destroy(mutex);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
free(mutex);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquire and lock the mutex when peripheral access is required
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_lock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock and release the mutex, when done with the peripheral access.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_unlock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the semaphore container, initialize the semaphore, and
|
||||
* create semaphore ID.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param initValue: initial value of semaphore.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
*semaphore = malloc(sizeof(sem_t));
|
||||
if (*semaphore == NULL) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = sem_init(*semaphore, 0, (unsigned int) initValue);
|
||||
if (result != 0) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created semaphore.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_destroy((sem_t *) semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(semaphore);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_wait(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param waitTime: timeout value of waiting semaphore, unit: millisecond.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime)
|
||||
{
|
||||
int result;
|
||||
struct timespec semaphoreWaitTime;
|
||||
struct timeval systemTime;
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
|
||||
systemTime.tv_usec += waitTime * 1000;
|
||||
if (systemTime.tv_usec >= 1000000) {
|
||||
systemTime.tv_sec += systemTime.tv_usec / 1000000;
|
||||
systemTime.tv_usec %= 1000000;
|
||||
}
|
||||
|
||||
semaphoreWaitTime.tv_sec = systemTime.tv_sec;
|
||||
semaphoreWaitTime.tv_nsec = systemTime.tv_usec * 1000;
|
||||
|
||||
result = sem_timedwait(semaphore, &semaphoreWaitTime);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the semaphore token.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_post(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for ms.
|
||||
* @return an uint32 that the time of system, uint:ms
|
||||
*/
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*ms = (time.tv_sec * 1000 + time.tv_usec / 1000);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*us = (time.tv_sec * 1000000 + time.tv_usec);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void *Osal_Malloc(uint32_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void Osal_Free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
77
samples/sample_c++/platform/linux/common/osal/osal.h
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/28
|
||||
* @brief This is the header file for "osal.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_H
|
||||
#define OSAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *),
|
||||
uint32_t stackSize, void *arg, T_DjiTaskHandle *task);
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task);
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs);
|
||||
|
||||
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex);
|
||||
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex);
|
||||
|
||||
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime);
|
||||
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore);
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms);
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us);
|
||||
|
||||
void *Osal_Malloc(uint32_t size);
|
||||
void Osal_Free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
293
samples/sample_c++/platform/linux/common/osal/osal_fs.c
Normal file
@ -0,0 +1,293 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal_fs.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "time.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj)
|
||||
{
|
||||
if (fileName == NULL || fileMode == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*fileObj = malloc(sizeof(FILE));
|
||||
if (*fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
*fileObj = fopen(fileName, fileMode);
|
||||
if (*fileObj == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
free(*fileObj);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fclose(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fwrite(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fread(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fseek(fileObj, offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fflush(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj)
|
||||
{
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*dirObj = opendir(filePath);
|
||||
if (*dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = closedir((DIR *) dirObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct dirent *dirent;
|
||||
|
||||
if (dirObj == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dirent = readdir((DIR *) dirObj);
|
||||
if (!dirent) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (dirent->d_type == DT_DIR) {
|
||||
fileInfo->isDir = true;
|
||||
} else {
|
||||
fileInfo->isDir = false;
|
||||
}
|
||||
strcpy(fileInfo->path, dirent->d_name);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = mkdir(filePath, S_IRWXU);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (filePath[strlen(filePath) - 1] == '/') {
|
||||
ret = rmdir(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = unlink(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (oldFilePath == NULL || newFilePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = rename(oldFilePath, newFilePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct stat st;
|
||||
int32_t ret;
|
||||
struct tm *fileTm;
|
||||
|
||||
if (filePath == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = stat(filePath, &st);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileTm = localtime(&(st.st_ctime));
|
||||
if (fileTm == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileInfo->size = st.st_size;
|
||||
|
||||
fileInfo->createTime.year = fileTm->tm_year + 1900 - 1980;
|
||||
fileInfo->createTime.month = fileTm->tm_mon;
|
||||
fileInfo->createTime.day = fileTm->tm_mday;
|
||||
fileInfo->createTime.hour = fileTm->tm_hour;
|
||||
fileInfo->createTime.minute = fileTm->tm_min;
|
||||
fileInfo->createTime.second = fileTm->tm_sec;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
73
samples/sample_c++/platform/linux/common/osal/osal_fs.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.h
|
||||
* @brief This is the header file for "osal_fs.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_FS_H
|
||||
#define OSAL_FS_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset);
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo);
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath);
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_FS_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
84
samples/sample_c++/platform/linux/manifold2/CMakeLists.txt
Normal file
@ -0,0 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(dji_sdk_demo_linux_cxx CXX)
|
||||
|
||||
set(CMAKE_C_FLAGS "-pthread -std=gnu99")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-pthread")
|
||||
set(CMAKE_C_COMPILER "gcc")
|
||||
set(CMAKE_CXX_COMPILER "g++")
|
||||
add_definitions(-D_GNU_SOURCE)
|
||||
|
||||
# Try to see if user has OpenCV installed
|
||||
# if yes, default callback will display the image
|
||||
find_package( OpenCV QUIET )
|
||||
if (OpenCV_FOUND)
|
||||
message( "\n${PROJECT_NAME}...")
|
||||
message( STATUS "Found OpenCV installed in the system, will use it to display image in AdvancedSensing APIs")
|
||||
message( STATUS " - Includes: ${OpenCV_INCLUDE_DIRS}")
|
||||
message( STATUS " - Libraries: ${OpenCV_LIBRARIES}")
|
||||
add_definitions(-DOPEN_CV_INSTALLED)
|
||||
else()
|
||||
message( STATUS "Did not find OpenCV in the system, image data is inside RecvContainer as raw data")
|
||||
endif ()
|
||||
|
||||
set(COMMON_CXX_FLAGS "-std=c++11 -pthread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} -fprofile-arcs -ftest-coverage -Wno-deprecated-declarations")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
|
||||
|
||||
include_directories(../../../module_sample)
|
||||
include_directories(../common)
|
||||
|
||||
file(GLOB_RECURSE MODULE_SAMPLE_SRC
|
||||
../../../module_sample/liveview/*.c*
|
||||
../../../module_sample/perception/*.c*
|
||||
)
|
||||
file(GLOB_RECURSE MODULE_COMMON_SRC ../common/*.c*)
|
||||
file(GLOB_RECURSE MODULE_HAL_SRC hal/*.c*)
|
||||
file(GLOB_RECURSE MODULE_APP_SRC application/*.c*)
|
||||
|
||||
execute_process(COMMAND uname -m
|
||||
OUTPUT_VARIABLE DEVICE_SYSTEM_ID)
|
||||
if (DEVICE_SYSTEM_ID MATCHES x86_64)
|
||||
set(TOOLCHAIN_NAME x86_64-linux-gnu-gcc)
|
||||
add_definitions(-DPLATFORM_ARCH_x86_64=1)
|
||||
elseif (DEVICE_SYSTEM_ID MATCHES aarch64)
|
||||
set(TOOLCHAIN_NAME aarch64-linux-gnu-gcc)
|
||||
add_definitions(-DPLATFORM_ARCH_aarch64=1)
|
||||
else ()
|
||||
message(FATAL_ERROR "FATAL: Please confirm your platform.")
|
||||
endif ()
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
find_package(FFMPEG REQUIRED)
|
||||
|
||||
if(FFMPEG_FOUND)
|
||||
message("Found FFMPEG FFMPEG_INCLUDE_DIR = ${FFMPEG_INCLUDE_DIR}")
|
||||
message("Found FFMPEG FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}")
|
||||
else()
|
||||
message("Cannot Find FFMPEG")
|
||||
endif(FFMPEG_FOUND)
|
||||
include_directories(${FFMPEG_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/include)
|
||||
|
||||
link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME})
|
||||
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/libpayloadsdk.a -lstdc++)
|
||||
|
||||
if (NOT EXECUTABLE_OUTPUT_PATH)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
endif ()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${MODULE_APP_SRC}
|
||||
${MODULE_SAMPLE_SRC}
|
||||
${MODULE_COMMON_SRC}
|
||||
${MODULE_HAL_SRC})
|
||||
target_link_libraries(${PROJECT_NAME} m usb-1.0 ${FFMPEG_LIBRARIES})
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
PRE_LINK COMMAND cmake ..
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})
|
||||
if (OpenCV_FOUND)
|
||||
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
|
||||
endif ()
|
||||
181
samples/sample_c++/platform/linux/manifold2/FindFFMPEG.cmake
Normal file
@ -0,0 +1,181 @@
|
||||
#
|
||||
# Find the native FFMPEG includes and library
|
||||
#
|
||||
# This module defines
|
||||
# FFMPEG_INCLUDE_DIR, where to find avcodec.h, avformat.h ...
|
||||
# FFMPEG_LIBRARIES, the libraries to link against to use FFMPEG.
|
||||
# FFMPEG_FOUND, If false, do not try to use FFMPEG.
|
||||
|
||||
# also defined, but not for general use are
|
||||
# FFMPEG_avformat_LIBRARY and FFMPEG_avcodec_LIBRARY, where to find the FFMPEG library.
|
||||
# This is useful to do it this way so that we can always add more libraries
|
||||
# if needed to FFMPEG_LIBRARIES if ffmpeg ever changes...
|
||||
|
||||
# if ffmpeg headers are all in one directory
|
||||
FIND_PATH(FFMPEG_INCLUDE_DIR avformat.h
|
||||
PATHS
|
||||
$ENV{FFMPEG_DIR}/include
|
||||
$ENV{OSGDIR}/include
|
||||
$ENV{OSG_ROOT}/include
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
/sw/include # Fink
|
||||
/opt/local/include # DarwinPorts
|
||||
/opt/csw/include # Blastwave
|
||||
/opt/include
|
||||
/usr/freeware/include
|
||||
PATH_SUFFIXES ffmpeg
|
||||
DOC "Location of FFMPEG Headers"
|
||||
)
|
||||
|
||||
# if ffmpeg headers are seperated to each of libavformat, libavcodec etc..
|
||||
IF( NOT FFMPEG_INCLUDE_DIR )
|
||||
FIND_PATH(FFMPEG_INCLUDE_DIR libavformat/avformat.h
|
||||
PATHS
|
||||
$ENV{FFMPEG_DIR}/include
|
||||
$ENV{OSGDIR}/include
|
||||
$ENV{OSG_ROOT}/include
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
/sw/include # Fink
|
||||
/opt/local/include # DarwinPorts
|
||||
/opt/csw/include # Blastwave
|
||||
/opt/include
|
||||
/usr/freeware/include
|
||||
PATH_SUFFIXES ffmpeg
|
||||
DOC "Location of FFMPEG Headers"
|
||||
)
|
||||
|
||||
ENDIF( NOT FFMPEG_INCLUDE_DIR )
|
||||
|
||||
# we want the -I include line to use the parent directory of ffmpeg as
|
||||
# ffmpeg uses relative includes such as <ffmpeg/avformat.h> or <libavcodec/avformat.h>
|
||||
get_filename_component(FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} ABSOLUTE)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_avformat_LIBRARY avformat
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_avcodec_LIBRARY avcodec
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_avutil_LIBRARY avutil
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_vorbis_LIBRARY vorbis
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_dc1394_LIBRARY dc1394_control
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_vorbisenc_LIBRARY vorbisenc
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_theora_LIBRARY theora
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_dts_LIBRARY dts
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_gsm_LIBRARY gsm
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_swscale_LIBRARY swscale
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
FIND_LIBRARY(FFMPEG_z_LIBRARY z
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
SET(FFMPEG_LIBRARIES)
|
||||
IF(FFMPEG_INCLUDE_DIR)
|
||||
IF(FFMPEG_avformat_LIBRARY)
|
||||
IF(FFMPEG_avcodec_LIBRARY)
|
||||
IF(FFMPEG_avutil_LIBRARY)
|
||||
SET( FFMPEG_FOUND "YES" )
|
||||
SET( FFMPEG_BASIC_LIBRARIES
|
||||
${FFMPEG_avcodec_LIBRARY}
|
||||
${FFMPEG_avformat_LIBRARY}
|
||||
${FFMPEG_avutil_LIBRARY}
|
||||
)
|
||||
|
||||
# swscale is always a part of newer ffmpeg distros
|
||||
IF(FFMPEG_swscale_LIBRARY)
|
||||
LIST(APPEND FFMPEG_BASIC_LIBRARIES ${FFMPEG_swscale_LIBRARY})
|
||||
ENDIF(FFMPEG_swscale_LIBRARY)
|
||||
|
||||
SET(FFMPEG_LIBRARIES ${FFMPEG_BASIC_LIBRARIES})
|
||||
|
||||
IF(FFMPEG_vorbis_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_vorbis_LIBRARY})
|
||||
ENDIF(FFMPEG_vorbis_LIBRARY)
|
||||
|
||||
IF(FFMPEG_dc1394_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_dc1394_LIBRARY})
|
||||
ENDIF(FFMPEG_dc1394_LIBRARY)
|
||||
|
||||
IF(FFMPEG_vorbisenc_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_vorbisenc_LIBRARY})
|
||||
ENDIF(FFMPEG_vorbisenc_LIBRARY)
|
||||
|
||||
IF(FFMPEG_theora_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_theora_LIBRARY})
|
||||
ENDIF(FFMPEG_theora_LIBRARY)
|
||||
|
||||
IF(FFMPEG_dts_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_dts_LIBRARY})
|
||||
ENDIF(FFMPEG_dts_LIBRARY)
|
||||
|
||||
IF(FFMPEG_gsm_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_gsm_LIBRARY})
|
||||
ENDIF(FFMPEG_gsm_LIBRARY)
|
||||
|
||||
IF(FFMPEG_z_LIBRARY)
|
||||
LIST(APPEND FFMPEG_LIBRARIES ${FFMPEG_z_LIBRARY})
|
||||
ENDIF(FFMPEG_z_LIBRARY)
|
||||
|
||||
SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE INTERNAL "All presently found FFMPEG libraries.")
|
||||
|
||||
ENDIF(FFMPEG_avutil_LIBRARY)
|
||||
ENDIF(FFMPEG_avcodec_LIBRARY)
|
||||
ENDIF(FFMPEG_avformat_LIBRARY)
|
||||
ENDIF(FFMPEG_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
FFMPEG_INCLUDE_DIR
|
||||
FFMPEG_avformat_LIBRARY
|
||||
FFMPEG_avcodec_LIBRARY
|
||||
FFMPEG_avutil_LIBRARY
|
||||
FFMPEG_vorbis_LIBRARY
|
||||
FFMPEG_dc1394_LIBRARY
|
||||
FFMPEG_vorbisenc_LIBRARY
|
||||
FFMPEG_theora_LIBRARY
|
||||
FFMPEG_dts_LIBRARY
|
||||
FFMPEG_gsm_LIBRARY
|
||||
FFMPEG_swscale_LIBRARY
|
||||
FFMPEG_z_LIBRARY
|
||||
)
|
||||
@ -0,0 +1,356 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file application.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "application.hpp"
|
||||
#include "dji_sdk_app_info.h"
|
||||
#include <dji_platform.h>
|
||||
#include <dji_logger.h>
|
||||
#include <dji_core.h>
|
||||
#include <dji_aircraft_info.h>
|
||||
|
||||
#include "../common/osal/osal.h"
|
||||
#include "../common/osal/osal_fs.h"
|
||||
#include "../manifold2//hal/hal_usb_bulk.h"
|
||||
#include "../manifold2//hal/hal_uart.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define DJI_LOG_PATH "Logs/DJI"
|
||||
#define DJI_LOG_INDEX_FILE_NAME "Logs/latest"
|
||||
#define DJI_LOG_FOLDER_NAME "Logs"
|
||||
#define DJI_LOG_PATH_MAX_SIZE (128)
|
||||
#define DJI_LOG_FOLDER_NAME_MAX_SIZE (32)
|
||||
#define DJI_LOG_SYSTEM_CMD_MAX_SIZE (64)
|
||||
#define DJI_LOG_MAX_COUNT (10)
|
||||
|
||||
#define USER_UTIL_UNUSED(x) ((x) = (x))
|
||||
#define USER_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define USER_UTIL_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static FILE *s_djiLogFile;
|
||||
static FILE *s_djiLogFileCnt;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
Application::Application(int argc, char **argv)
|
||||
{
|
||||
Application::DjiUser_SetupEnvironment();
|
||||
Application::DjiUser_ApplicationStart();
|
||||
|
||||
Osal_TaskSleepMs(1000);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
= default;
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
void Application::DjiUser_SetupEnvironment()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiOsalHandler osalHandler;
|
||||
T_DjiHalUartHandler uartHandler;
|
||||
T_DjiHalUsbBulkHandler usbBulkHandler;
|
||||
T_DjiLoggerConsole printConsole;
|
||||
T_DjiLoggerConsole localRecordConsole;
|
||||
T_DjiFileSystemHandler fileSystemHandler;
|
||||
|
||||
osalHandler.TaskCreate = Osal_TaskCreate;
|
||||
osalHandler.TaskDestroy = Osal_TaskDestroy;
|
||||
osalHandler.TaskSleepMs = Osal_TaskSleepMs;
|
||||
osalHandler.MutexCreate = Osal_MutexCreate;
|
||||
osalHandler.MutexDestroy = Osal_MutexDestroy;
|
||||
osalHandler.MutexLock = Osal_MutexLock;
|
||||
osalHandler.MutexUnlock = Osal_MutexUnlock;
|
||||
osalHandler.SemaphoreCreate = Osal_SemaphoreCreate;
|
||||
osalHandler.SemaphoreDestroy = Osal_SemaphoreDestroy;
|
||||
osalHandler.SemaphoreWait = Osal_SemaphoreWait;
|
||||
osalHandler.SemaphoreTimedWait = Osal_SemaphoreTimedWait;
|
||||
osalHandler.SemaphorePost = Osal_SemaphorePost;
|
||||
osalHandler.Malloc = Osal_Malloc;
|
||||
osalHandler.Free = Osal_Free;
|
||||
osalHandler.GetTimeMs = Osal_GetTimeMs;
|
||||
osalHandler.GetTimeUs = Osal_GetTimeUs;
|
||||
|
||||
printConsole.func = DjiUser_PrintConsole;
|
||||
printConsole.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_INFO;
|
||||
printConsole.isSupportColor = true;
|
||||
|
||||
localRecordConsole.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_DEBUG;
|
||||
localRecordConsole.func = DjiUser_LocalWrite;
|
||||
localRecordConsole.isSupportColor = false;
|
||||
|
||||
uartHandler.UartInit = HalUart_Init;
|
||||
uartHandler.UartDeInit = HalUart_DeInit;
|
||||
uartHandler.UartWriteData = HalUart_WriteData;
|
||||
uartHandler.UartReadData = HalUart_ReadData;
|
||||
uartHandler.UartGetStatus = HalUart_GetStatus;
|
||||
|
||||
usbBulkHandler.UsbBulkInit = HalUsbBulk_Init;
|
||||
usbBulkHandler.UsbBulkDeInit = HalUsbBulk_DeInit;
|
||||
usbBulkHandler.UsbBulkWriteData = HalUsbBulk_WriteData;
|
||||
usbBulkHandler.UsbBulkReadData = HalUsbBulk_ReadData;
|
||||
usbBulkHandler.UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo;
|
||||
|
||||
fileSystemHandler.FileOpen = Osal_FileOpen,
|
||||
fileSystemHandler.FileClose = Osal_FileClose,
|
||||
fileSystemHandler.FileWrite = Osal_FileWrite,
|
||||
fileSystemHandler.FileRead = Osal_FileRead,
|
||||
fileSystemHandler.FileSync = Osal_FileSync,
|
||||
fileSystemHandler.FileSeek = Osal_FileSeek,
|
||||
fileSystemHandler.DirOpen = Osal_DirOpen,
|
||||
fileSystemHandler.DirClose = Osal_DirClose,
|
||||
fileSystemHandler.DirRead = Osal_DirRead,
|
||||
fileSystemHandler.Mkdir = Osal_Mkdir,
|
||||
fileSystemHandler.Unlink = Osal_Unlink,
|
||||
fileSystemHandler.Rename = Osal_Rename,
|
||||
fileSystemHandler.Stat = Osal_Stat,
|
||||
|
||||
returnCode = DjiPlatform_RegOsalHandler(&osalHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register osal handler error.");
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegHalUartHandler(&uartHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register hal uart handler error.");
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register hal usb bulk handler error.");
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegFileSystemHandler(&fileSystemHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register osal filesystem handler error.");
|
||||
}
|
||||
|
||||
if (DjiUser_LocalWriteFsInit(DJI_LOG_PATH) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("File system init error.");
|
||||
}
|
||||
|
||||
returnCode = DjiLogger_AddConsole(&printConsole);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Add printf console error.");
|
||||
}
|
||||
|
||||
returnCode = DjiLogger_AddConsole(&localRecordConsole);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Add printf console error.");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::DjiUser_ApplicationStart()
|
||||
{
|
||||
T_DjiUserInfo userInfo;
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
|
||||
|
||||
returnCode = DjiUser_FillInUserInfo(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Fill user info error, please check user info config.");
|
||||
}
|
||||
|
||||
returnCode = DjiCore_Init(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Core init error.");
|
||||
}
|
||||
|
||||
returnCode = DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Get aircraft base info error.");
|
||||
}
|
||||
|
||||
if (aircraftInfoBaseInfo.mountPosition != DJI_MOUNT_POSITION_EXTENSION_PORT) {
|
||||
throw std::runtime_error("Please run this sample on extension port.");
|
||||
}
|
||||
|
||||
returnCode = DjiCore_SetAlias("PSDK_APPALIAS");
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Set alias error.");
|
||||
}
|
||||
|
||||
returnCode = DjiCore_ApplicationStart();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Start sdk application error.");
|
||||
}
|
||||
|
||||
USER_LOG_INFO("Application start.");
|
||||
}
|
||||
|
||||
T_DjiReturnCode Application::DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
printf("%s", data);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Application::DjiUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
int32_t realLen;
|
||||
|
||||
if (s_djiLogFile == nullptr) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
realLen = fwrite(data, 1, dataLen, s_djiLogFile);
|
||||
fflush(s_djiLogFile);
|
||||
if (realLen == dataLen) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode Application::DjiUser_FillInUserInfo(T_DjiUserInfo *userInfo)
|
||||
{
|
||||
memset(userInfo->appName, 0, sizeof(userInfo->appName));
|
||||
memset(userInfo->appId, 0, sizeof(userInfo->appId));
|
||||
memset(userInfo->appKey, 0, sizeof(userInfo->appKey));
|
||||
memset(userInfo->appLicense, 0, sizeof(userInfo->appLicense));
|
||||
memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount));
|
||||
memset(userInfo->baudRate, 0, sizeof(userInfo->baudRate));
|
||||
|
||||
if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) ||
|
||||
strlen(USER_APP_ID) > sizeof(userInfo->appId) ||
|
||||
strlen(USER_APP_KEY) > sizeof(userInfo->appKey) ||
|
||||
strlen(USER_APP_LICENSE) > sizeof(userInfo->appLicense) ||
|
||||
strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount) ||
|
||||
strlen(USER_BAUD_RATE) > sizeof(userInfo->baudRate)) {
|
||||
USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (!strcmp(USER_APP_NAME, "your_app_name") ||
|
||||
!strcmp(USER_APP_ID, "your_app_id") ||
|
||||
!strcmp(USER_APP_KEY, "your_app_key") ||
|
||||
!strcmp(USER_BAUD_RATE, "your_app_license") ||
|
||||
!strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account") ||
|
||||
!strcmp(USER_BAUD_RATE, "your_baud_rate")) {
|
||||
USER_LOG_ERROR(
|
||||
"Please fill in correct user information to 'samples/sample_c++/platform/linux/manifold2/application/dji_sdk_app_info.h' file.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1);
|
||||
memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID)));
|
||||
memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY)));
|
||||
memcpy(userInfo->appLicense, USER_APP_LICENSE,
|
||||
USER_UTIL_MIN(sizeof(userInfo->appLicense), strlen(USER_APP_LICENSE)));
|
||||
memcpy(userInfo->baudRate, USER_BAUD_RATE, USER_UTIL_MIN(sizeof(userInfo->baudRate), strlen(USER_BAUD_RATE)));
|
||||
strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Application::DjiUser_LocalWriteFsInit(const char *path)
|
||||
{
|
||||
T_DjiReturnCode djiReturnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
char filePath[DJI_LOG_PATH_MAX_SIZE];
|
||||
char systemCmd[DJI_LOG_SYSTEM_CMD_MAX_SIZE];
|
||||
char folderName[DJI_LOG_FOLDER_NAME_MAX_SIZE];
|
||||
time_t currentTime = time(nullptr);
|
||||
struct tm *localTime = localtime(¤tTime);
|
||||
uint16_t logFileIndex = 0;
|
||||
uint16_t currentLogFileIndex;
|
||||
uint8_t ret;
|
||||
|
||||
if (localTime == nullptr) {
|
||||
printf("Get local time error.\r\n");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (access(DJI_LOG_FOLDER_NAME, F_OK) != 0) {
|
||||
sprintf(folderName, "mkdir %s", DJI_LOG_FOLDER_NAME);
|
||||
ret = system(folderName);
|
||||
if (ret != 0) {
|
||||
printf("Create new log folder error, ret:%d.\r\n", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "rb+");
|
||||
if (s_djiLogFileCnt == nullptr) {
|
||||
s_djiLogFileCnt = fopen(DJI_LOG_INDEX_FILE_NAME, "wb+");
|
||||
if (s_djiLogFileCnt == nullptr) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else {
|
||||
ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Read log file index error.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
currentLogFileIndex = logFileIndex;
|
||||
logFileIndex++;
|
||||
|
||||
ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Write log file index error.\r\n");
|
||||
fclose(s_djiLogFileCnt);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fclose(s_djiLogFileCnt);
|
||||
|
||||
sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex,
|
||||
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
|
||||
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
|
||||
|
||||
s_djiLogFile = fopen(filePath, "wb+");
|
||||
if (s_djiLogFile == nullptr) {
|
||||
USER_LOG_ERROR("Open filepath time error.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (logFileIndex >= DJI_LOG_MAX_COUNT) {
|
||||
sprintf(systemCmd, "rm -rf %s_%04d*.log", path, currentLogFileIndex - DJI_LOG_MAX_COUNT);
|
||||
ret = system(systemCmd);
|
||||
if (ret != 0) {
|
||||
printf("Remove file error, ret:%d.\r\n", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return djiReturnCode;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,67 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_application.hpp
|
||||
* @brief This is the header file for "dji_application.cpp", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef APPLICATION_H
|
||||
#define APPLICATION_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "dji_typedef.h"
|
||||
#include "dji_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
using namespace std;
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application(int argc, char **argv);
|
||||
~Application();
|
||||
|
||||
private:
|
||||
static void DjiUser_SetupEnvironment();
|
||||
static void DjiUser_ApplicationStart();
|
||||
static T_DjiReturnCode DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen);
|
||||
static T_DjiReturnCode DjiUser_LocalWrite(const uint8_t *data, uint16_t dataLen);
|
||||
static T_DjiReturnCode DjiUser_FillInUserInfo(T_DjiUserInfo *userInfo);
|
||||
static T_DjiReturnCode DjiUser_LocalWriteFsInit(const char *path);
|
||||
};
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APPLICATION_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,55 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_sdk_app_info.h
|
||||
* @brief This is the header file for defining the structure and (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_SDK_APP_INFO_H
|
||||
#define DJI_SDK_APP_INFO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
// ATTENTION: User must goto https://developer.dji.com/user/apps/#all to create your own dji sdk application, get dji sdk application
|
||||
// information then fill in the application information here.
|
||||
#define USER_APP_NAME "your_app_name"
|
||||
#define USER_APP_ID "your_app_id"
|
||||
#define USER_APP_KEY "your_app_key"
|
||||
#define USER_APP_LICENSE "your_app_license"
|
||||
#define USER_DEVELOPER_ACCOUNT "your_developer_account"
|
||||
#define USER_BAUD_RATE "460800"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_SDK_APP_INFO_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,68 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file main.cpp
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <liveview/test_liveview_entry.hpp>
|
||||
#include <perception/test_perception_entry.hpp>
|
||||
#include "application.hpp"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Application application(argc, argv);
|
||||
char inputChar;
|
||||
|
||||
std::cout
|
||||
<< "\n"
|
||||
<< "| Available commands: |\n"
|
||||
<< "| [0] Camera stream view sample |\n"
|
||||
<< "| [1] Stereo vision view sample |\n"
|
||||
<< std::endl;
|
||||
|
||||
std::cin >> inputChar;
|
||||
switch (inputChar) {
|
||||
case '0':
|
||||
DjiUser_RunCameraStreamViewSample();
|
||||
break;
|
||||
case '1':
|
||||
DjiUser_RunStereoVisionViewSample();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,84 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.c
|
||||
* @version V2.0.0
|
||||
* @date 3/27/20
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "hal_network.h"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj)
|
||||
{
|
||||
int32_t ret;
|
||||
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
|
||||
|
||||
if (ipAddr == NULL || netMask == NULL) {
|
||||
USER_LOG_ERROR("hal network config param error");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//Attention: need root permission to config ip addr and netmask.
|
||||
memset(cmdStr, 0, sizeof(cmdStr));
|
||||
|
||||
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV);
|
||||
ret = system(cmdStr);
|
||||
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Can't open the network."
|
||||
"Probably the program not execute with root permission."
|
||||
"Please use the root permission to execute the program.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask);
|
||||
ret = system(cmdStr);
|
||||
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Can't config the ip address of network."
|
||||
"Probably the program not execute with root permission."
|
||||
"Please use the root permission to execute the program.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj)
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,68 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.h
|
||||
* @version V2.0.0
|
||||
* @date 3/27/20
|
||||
* @brief This is the header file for "hal_network.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_NETWORK_H
|
||||
#define HAL_NETWORK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/** @attention User can config network card name here, if your device is not MF2C/G, please comment below and add your
|
||||
* NIC name micro define as #define 'LINUX_NETWORK_DEV "your NIC name"'.
|
||||
*/
|
||||
#ifdef PLATFORM_ARCH_x86_64
|
||||
#define LINUX_NETWORK_DEV "enp0s31f6"
|
||||
#else
|
||||
#define LINUX_NETWORK_DEV "eth0"
|
||||
#endif
|
||||
/**
|
||||
* @attention
|
||||
*/
|
||||
|
||||
|
||||
#define LINUX_CMD_STR_MAX_SIZE (128)
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj);
|
||||
|
||||
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_NETWORK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
260
samples/sample_c++/platform/linux/manifold2/hal/hal_uart.c
Normal file
@ -0,0 +1,260 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_uart.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_logger.h>
|
||||
#include "hal_uart.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define UART_DEV_NAME_STR_SIZE (128)
|
||||
#define DJI_SYSTEM_CMD_MAX_SIZE (64)
|
||||
#define DJI_SYSTEM_RESULT_STR_MAX_SIZE (128)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int uartFd;
|
||||
} T_UartHandleStruct;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle)
|
||||
{
|
||||
T_UartHandleStruct *uartHandleStruct;
|
||||
struct termios options;
|
||||
struct flock lock;
|
||||
T_DjiReturnCode returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
char uartName[UART_DEV_NAME_STR_SIZE];
|
||||
char systemCmd[DJI_SYSTEM_CMD_MAX_SIZE];
|
||||
char *ret = NULL;
|
||||
char lineBuf[DJI_SYSTEM_RESULT_STR_MAX_SIZE] = {0};
|
||||
FILE *fp;
|
||||
|
||||
uartHandleStruct = malloc(sizeof(T_UartHandleStruct));
|
||||
if (uartHandleStruct == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
if (uartNum == DJI_HAL_UART_NUM_0) {
|
||||
strcpy(uartName, LINUX_UART_DEV1);
|
||||
} else if (uartNum == DJI_HAL_UART_NUM_1) {
|
||||
strcpy(uartName, LINUX_UART_DEV2);
|
||||
} else {
|
||||
goto free_uart_handle;
|
||||
}
|
||||
|
||||
#ifdef USE_CLION_DEBUG
|
||||
sprintf(systemCmd, "ls -l %s", uartName);
|
||||
fp = popen(systemCmd, "r");
|
||||
if (fp == NULL) {
|
||||
goto free_uart_handle;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fp);
|
||||
if (ret == NULL) {
|
||||
goto close_fp;
|
||||
}
|
||||
|
||||
if (strstr(lineBuf, "crwxrwxrwx") == NULL) {
|
||||
USER_LOG_ERROR("Can't operation the device. "
|
||||
"Probably the device has not operation permission. "
|
||||
"Please execute command 'sudo chmod 777 %s' to add permission. ", uartName);
|
||||
goto close_fp;
|
||||
}
|
||||
#else
|
||||
sprintf(systemCmd, "chmod 777 %s", uartName);
|
||||
fp = popen(systemCmd, "r");
|
||||
if (fp == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
uartHandleStruct->uartFd = open(uartName, (unsigned) O_RDWR | (unsigned) O_NOCTTY | (unsigned) O_NDELAY);
|
||||
if (uartHandleStruct->uartFd == -1) {
|
||||
goto close_fp;
|
||||
}
|
||||
|
||||
// Forbid multiple psdk programs to access the serial port
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_pid = getpid();
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
|
||||
if (fcntl(uartHandleStruct->uartFd, F_GETLK, &lock) < 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
if (lock.l_type != F_UNLCK) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_pid = getpid();
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
if (fcntl(uartHandleStruct->uartFd, F_SETLKW, &lock) < 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
if (tcgetattr(uartHandleStruct->uartFd, &options) != 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
switch (baudRate) {
|
||||
case 115200:
|
||||
cfsetispeed(&options, B115200);
|
||||
cfsetospeed(&options, B115200);
|
||||
break;
|
||||
case 230400:
|
||||
cfsetispeed(&options, B230400);
|
||||
cfsetospeed(&options, B230400);
|
||||
break;
|
||||
case 460800:
|
||||
cfsetispeed(&options, B460800);
|
||||
cfsetospeed(&options, B460800);
|
||||
break;
|
||||
case 921600:
|
||||
cfsetispeed(&options, B921600);
|
||||
cfsetospeed(&options, B921600);
|
||||
break;
|
||||
case 1000000:
|
||||
cfsetispeed(&options, B1000000);
|
||||
cfsetospeed(&options, B1000000);
|
||||
break;
|
||||
default:
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
options.c_cflag |= (unsigned) CLOCAL;
|
||||
options.c_cflag |= (unsigned) CREAD;
|
||||
options.c_cflag &= ~(unsigned) CRTSCTS;
|
||||
options.c_cflag &= ~(unsigned) CSIZE;
|
||||
options.c_cflag |= (unsigned) CS8;
|
||||
options.c_cflag &= ~(unsigned) PARENB;
|
||||
options.c_iflag &= ~(unsigned) INPCK;
|
||||
options.c_cflag &= ~(unsigned) CSTOPB;
|
||||
options.c_oflag &= ~(unsigned) OPOST;
|
||||
options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG);
|
||||
options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON);
|
||||
options.c_cc[VTIME] = 0;
|
||||
options.c_cc[VMIN] = 0;
|
||||
|
||||
tcflush(uartHandleStruct->uartFd, TCIFLUSH);
|
||||
|
||||
if (tcsetattr(uartHandleStruct->uartFd, TCSANOW, &options) != 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
*uartHandle = uartHandleStruct;
|
||||
pclose(fp);
|
||||
|
||||
return returnCode;
|
||||
|
||||
close_uart_fd:
|
||||
close(uartHandleStruct->uartFd);
|
||||
|
||||
close_fp:
|
||||
pclose(fp);
|
||||
|
||||
free_uart_handle:
|
||||
free(uartHandleStruct);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
ret = close(uartHandleStruct->uartFd);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(uartHandleStruct);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = write(uartHandleStruct->uartFd, buf, len);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = read(uartHandleStruct->uartFd, buf, len);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status)
|
||||
{
|
||||
if (uartNum == DJI_HAL_UART_NUM_0) {
|
||||
status->isConnect = true;
|
||||
} else if (uartNum == DJI_HAL_UART_NUM_1) {
|
||||
status->isConnect = true;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
69
samples/sample_c++/platform/linux/manifold2/hal/hal_uart.h
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_uart.h
|
||||
* @brief This is the header file for "hal_uart.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_UART_H
|
||||
#define HAL_UART_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
//User can config dev based on there environmental conditions
|
||||
#define LINUX_UART_DEV1 "/dev/ttyUSB0"
|
||||
#define LINUX_UART_DEV2 "/dev/ttyACM0"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle);
|
||||
|
||||
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle);
|
||||
|
||||
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_UART_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
199
samples/sample_c++/platform/linux/manifold2/hal/hal_usb_bulk.c
Normal file
@ -0,0 +1,199 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hal_usb_bulk.h"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
|
||||
#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1)
|
||||
|
||||
#define LINUX_USB_BULK_DEV1 "/dev/usb-ffs/bulk"
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
libusb_device_handle *handle;
|
||||
int32_t ep1;
|
||||
int32_t ep2;
|
||||
T_DjiHalUsbBulkInfo usbBulkInfo;
|
||||
} T_HalUsbBulkObj;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
*usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj));
|
||||
if (*usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (usbBulkInfo.isUsbHost == true) {
|
||||
ret = libusb_init(NULL);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
|
||||
if (handle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
|
||||
if (ret != LIBUSB_SUCCESS) {
|
||||
printf("libusb claim interface error");
|
||||
libusb_close(handle);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
|
||||
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
|
||||
|
||||
} else {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
|
||||
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open("/dev/usb-ffs/bulk/ep1", O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open("/dev/usb-ffs/bulk/ep2", O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle)
|
||||
{
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
|
||||
osalHandler->TaskSleepMs(100);
|
||||
libusb_exit(NULL);
|
||||
} else {
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1);
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2);
|
||||
}
|
||||
|
||||
free(usbBulkHandle);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t actualLen;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut,
|
||||
(uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
} else {
|
||||
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
int32_t actualLen;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn,
|
||||
buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
} else {
|
||||
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo)
|
||||
{
|
||||
//attention: need confirm your usb config in device mode.
|
||||
deviceInfo->vid = 0x7020;
|
||||
deviceInfo->pid = 0x9055;
|
||||
|
||||
deviceInfo->bulkChannelNum = 2;
|
||||
|
||||
deviceInfo->channelInfo[0].interfaceNum = 0;
|
||||
deviceInfo->channelInfo[0].endPointIn = 0x01;
|
||||
deviceInfo->channelInfo[0].endPointOut = 0x81;
|
||||
|
||||
deviceInfo->channelInfo[1].interfaceNum = 0;
|
||||
deviceInfo->channelInfo[1].endPointIn = 0x02;
|
||||
deviceInfo->channelInfo[1].endPointOut = 0x82;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.h
|
||||
* @brief This is the header file for "hal_usb_bulk.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_USB_BULK_H
|
||||
#define HAL_USB_BULK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle);
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle);
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_USB_BULK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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, uint16_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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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, uint16_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, uint16_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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_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, uint16_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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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, uint16_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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_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, uint16_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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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, uint16_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******/
|
||||
|
After Width: | Height: | Size: 2.1 MiB |
|
After Width: | Height: | Size: 2.4 MiB |
|
After Width: | Height: | Size: 1.0 MiB |
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -0,0 +1,51 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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_CameraMediaGetFileInfo(const char *filePath, T_DjiCameraMediaFileInfo *fileInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_PAYLOAD_CAM_EMU_MEDIA_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
1270
samples/sample_c/module_sample/camera_manager/test_camera_manager.c
Normal file
@ -0,0 +1,265 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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_AEB_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_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 shoot AEB photo, using async api
|
||||
*
|
||||
* @note In this interface, camera will be set to be the SHOOT_PHOTO mode
|
||||
* then start to shoot a AEB photo.
|
||||
* @param index payload node index, input limit see enum
|
||||
* DJI::OSDK::PayloadIndexType
|
||||
* @param photoNum The number of pictures in each AEB shooting
|
||||
* @return T_DjiReturnCode error code
|
||||
*/
|
||||
T_DjiReturnCode DjiTest_CameraManagerStartShootAEBPhoto(E_DjiMountPosition position,
|
||||
E_DjiCameraManagerPhotoAEBCount aebCount);
|
||||
|
||||
/*! @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******/
|
||||
@ -0,0 +1,279 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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 ReceiveDataFromOnboardComputer(const uint8_t *data, uint16_t len);
|
||||
static T_DjiReturnCode ReceiveDataFromPayload(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.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, ReceiveDataFromOnboardComputer);
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("register receive data from onboard coputer 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) {
|
||||
channelAddress = DJI_CHANNEL_ADDRESS_PAYLOAD_PORT_NO1;
|
||||
djiStat = DjiLowSpeedDataChannel_RegRecvDataCallback(channelAddress, ReceiveDataFromPayload);
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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.\r\n";
|
||||
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.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 onboard computer error.");
|
||||
|
||||
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
|
||||
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_DEBUG(
|
||||
"send to onboard computer state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
|
||||
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
|
||||
state.busyState);
|
||||
} else {
|
||||
USER_LOG_ERROR("get send to onboard computer channel state error.");
|
||||
}
|
||||
|
||||
#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) {
|
||||
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 onboard computer error.");
|
||||
|
||||
djiStat = DjiLowSpeedDataChannel_GetSendDataState(channelAddress, &state);
|
||||
if (djiStat == DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_DEBUG(
|
||||
"send to onboard computer state: realtimeBandwidthBeforeFlowController: %d, realtimeBandwidthAfterFlowController: %d, busyState: %d.",
|
||||
state.realtimeBandwidthBeforeFlowController, state.realtimeBandwidthAfterFlowController,
|
||||
state.busyState);
|
||||
} else {
|
||||
USER_LOG_ERROR("get send to onboard computer 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 ReceiveDataFromOnboardComputer(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 onboard computer: %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;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_DATA_TRANSMISSION_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,329 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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 (2048)
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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_10_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");
|
||||
|
||||
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_10_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 20s\r\n");
|
||||
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
osalHandler->TaskSleepMs(1000 / FC_SUBSCRIPTION_TASK_FREQ);
|
||||
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,
|
||||
(uint8_t *) &velocity,
|
||||
sizeof(T_DjiFcSubscriptionVelocity),
|
||||
×tamp);
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("get value of topic velocity error.");
|
||||
} else {
|
||||
USER_LOG_INFO("velocity: x = %f y = %f z = %f healthFlag = %d.", velocity.data.x, velocity.data.y,
|
||||
velocity.data.z, velocity.health);
|
||||
}
|
||||
|
||||
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION,
|
||||
(uint8_t *) &gpsPosition,
|
||||
sizeof(T_DjiFcSubscriptionGpsPosition),
|
||||
×tamp);
|
||||
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),
|
||||
×tamp);
|
||||
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),
|
||||
×tamp);
|
||||
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: 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;
|
||||
}
|
||||
|
||||
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),
|
||||
×tamp);
|
||||
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),
|
||||
×tamp);
|
||||
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),
|
||||
×tamp);
|
||||
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->q1 * quaternion->q2 + 2 * quaternion->q0 * quaternion->q3,
|
||||
-2 * quaternion->q2 * quaternion->q2 - 2 * quaternion->q3 * quaternion->q3 + 1) *
|
||||
57.3;
|
||||
yaw = (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;
|
||||
|
||||
if (s_userFcSubscriptionDataShow == true) {
|
||||
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.\r\n", quaternion->q0, quaternion->q1, quaternion->q2, quaternion->q3);
|
||||
USER_LOG_INFO("euler angles: pitch = %.2f roll = %.2f yaw = %.2f.", pitch, yaw, roll);
|
||||
DjiTest_WidgetLogAppend("pitch = %.2f roll = %.2f yaw = %.2f.", pitch, yaw, roll);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
1502
samples/sample_c/module_sample/flight_control/test_flight_control.c
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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_DjiTestFlightCtrlSampleSelect;
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode DjiTest_FlightControlRunSample(E_DjiTestFlightCtrlSampleSelect flightCtrlSampleSelect);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_FLIGHT_CONTROL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
1122
samples/sample_c/module_sample/gimbal_emu/test_payload_gimbal_emu.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -0,0 +1,170 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* 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;
|
||||
|
||||
USER_LOG_INFO("Gimbal manager sample start");
|
||||
DjiTest_WidgetLogAppend("Gimbal manager sample start");
|
||||
|
||||
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: Rotate gimbal to target angle in relative angle mode\r\n");
|
||||
DjiTest_WidgetLogAppend("--> Step 3: Rotate gimbal to target angle in relative angle mode\r\n");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
USER_LOG_INFO("Target gimbal pry = (30, 0, 0) in the body coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 30, 0, 0, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (30, 0, 0) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal pry = (0, 30, 0) in the body coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 30, 0, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (0, 30, 0) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal pry = (0, 0, 30) in the body coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 0, 30, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (0, 0, 30) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal reset.\r\n");
|
||||
returnCode = DjiGimbalManager_Reset(mountPosition);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Reset gimbal failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(2000);
|
||||
}
|
||||
|
||||
USER_LOG_INFO("--> Step 4: Rotate gimbal to target angle in absolute angle mode\r\n");
|
||||
DjiTest_WidgetLogAppend("--> Step 4: Rotate gimbal to target angle in absolute angle mode\r\n");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
USER_LOG_INFO("Target gimbal pry = (30, 0, 0) in the ground coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, 30, 0, 0, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (30, 0, 0) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal pry = (0, 30, 0) in the ground coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, 0, 30, 0, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (0, 30, 0) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal pry = (0, 0, 30) in the ground coordinate system");
|
||||
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_ABSOLUTE_ANGLE, 0, 0, 30, 0.5};
|
||||
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Target gimbal pry = (0, 0, 30) failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(1000);
|
||||
|
||||
USER_LOG_INFO("Target gimbal reset.\r\n");
|
||||
returnCode = DjiGimbalManager_Reset(mountPosition);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Reset gimbal failed, error code: 0x%08X", returnCode);
|
||||
goto out;
|
||||
}
|
||||
osalHandler->TaskSleepMs(2000);
|
||||
}
|
||||
|
||||
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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
255
samples/sample_c/module_sample/hms/test_hms.c
Normal file
@ -0,0 +1,255 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <widget_interaction_test/test_widget_interaction.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"
|
||||
|
||||
/* 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
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static const char *oldReplaceAlarmIdStr = "%alarmid";
|
||||
static const char *oldReplaceIndexStr = "%index";
|
||||
static const char *oldReplaceComponentIndexStr = "%component_index";
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static T_DjiReturnCode DjiTest_HmsInit(void);
|
||||
static T_DjiReturnCode DjiTest_HmsDeInit(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 T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode DjiTest_HmsRunSample(void)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiOsalHandler *osalHandler;
|
||||
|
||||
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_HmsInit();
|
||||
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 = DjiHms_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(30000);
|
||||
|
||||
out:
|
||||
USER_LOG_INFO("--> Step 3: Deinit hms sample");
|
||||
DjiTest_WidgetLogAppend("--> Step 3: Deinit hms sample");
|
||||
returnCode = DjiTest_HmsDeInit();
|
||||
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;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_DjiReturnCode DjiTest_HmsInit(void)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return DjiHms_Init();
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiTest_HmsDeInit(void)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return DjiHms_DeInit();
|
||||
}
|
||||
|
||||
static T_DjiFcSubscriptionFlightStatus DjiTest_GetValueOfFlightStatus(void)
|
||||
{
|
||||
T_DjiReturnCode djiStat;
|
||||
T_DjiFcSubscriptionFlightStatus flightStatus;
|
||||
T_DjiDataTimestamp flightStatusTimestamp = {0};
|
||||
|
||||
djiStat = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
|
||||
(uint8_t *) &flightStatus,
|
||||
sizeof(T_DjiFcSubscriptionFlightStatus),
|
||||
&flightStatusTimestamp);
|
||||
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Get value of topic flight status failed, error code:0x%08llX", djiStat);
|
||||
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 T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable)
|
||||
{
|
||||
if (!DjiTest_MarchErrCodeInfoTable(hmsInfoTable)) {
|
||||
USER_LOG_ERROR("March HMS Information failed.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
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****/
|
||||
49
samples/sample_c/module_sample/hms/test_hms.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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_HmsRunSample(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_HMS_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
177
samples/sample_c/module_sample/liveview/test_liveview.c
Normal file
@ -0,0 +1,177 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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 "time.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define TEST_LIVEVIEW_STREAM_FILE_PATH_STR_MAX_SIZE 256
|
||||
#define TEST_LIVEVIEW_STREAM_STROING_TIME_IN_SECONDS 20
|
||||
|
||||
/* 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;
|
||||
|
||||
USER_LOG_INFO("Liveview sample start");
|
||||
DjiTest_WidgetLogAppend("Liveview sample start");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
localTime = localtime(¤tTime);
|
||||
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);
|
||||
|
||||
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");
|
||||
|
||||
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(¤tTime);
|
||||
sprintf(s_payloadCameraStreamFilePath, "payload%d_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);
|
||||
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");
|
||||
returnCode = DjiLiveview_StopH264Stream(DJI_LIVEVIEW_CAMERA_POSITION_FPV);
|
||||
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);
|
||||
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****/
|
||||
49
samples/sample_c/module_sample/liveview/test_liveview.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
833
samples/sample_c/module_sample/mop_channel/test_mop_channel.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include <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 command:0x%02X",
|
||||
clientNum, fileTransfor->cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
119
samples/sample_c/module_sample/mop_channel/test_mop_channel.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
210
samples/sample_c/module_sample/perception/test_perception.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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****/
|
||||
50
samples/sample_c/module_sample/perception/test_perception.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
161
samples/sample_c/module_sample/positioning/test_positioning.c
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define POSITIONING_TASK_FREQ (1)
|
||||
#define POSITIONING_TASK_STACK_SIZE (2048)
|
||||
|
||||
#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);
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static T_DjiTaskHandle s_userPositioningThread;
|
||||
static int32_t s_eventIndex = 0;
|
||||
|
||||
/* 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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -0,0 +1,143 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V2 ||
|
||||
baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT)) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
/* 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****/
|
||||
@ -0,0 +1,57 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEST_POWER_MANAGEMENT_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
173
samples/sample_c/module_sample/time_sync/test_time_sync.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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 (2048)
|
||||
|
||||
/* 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(¤tTimeMs);
|
||||
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 %d.%d.%d %d:%d %d %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****/
|
||||
57
samples/sample_c/module_sample/time_sync/test_time_sync.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
342
samples/sample_c/module_sample/upgrade/test_upgrade.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_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****/
|
||||
58
samples/sample_c/module_sample/upgrade/test_upgrade.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
127
samples/sample_c/module_sample/utils/util_buffer.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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);
|
||||
}
|
||||
59
samples/sample_c/module_sample/utils/util_buffer.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _DJI_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
|
||||
207
samples/sample_c/module_sample/utils/util_file.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#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, uint16_t len,
|
||||
uint8_t *data, uint16_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****/
|
||||
70
samples/sample_c/module_sample/utils/util_file.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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, uint16_t len,
|
||||
uint8_t *data, uint16_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******/
|
||||
238
samples/sample_c/module_sample/utils/util_md5.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* 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****/
|
||||
88
samples/sample_c/module_sample/utils/util_md5.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* 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******/
|
||||
102
samples/sample_c/module_sample/utils/util_misc.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#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****/
|
||||
57
samples/sample_c/module_sample/utils/util_misc.h
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MISC_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
62
samples/sample_c/module_sample/utils/util_time.c
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#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****/
|
||||
60
samples/sample_c/module_sample/utils/util_time.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_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******/
|
||||
464
samples/sample_c/module_sample/waypoint_v2/test_waypoint_v2.c
Normal file
@ -0,0 +1,464 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <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),
|
||||
×tamp);
|
||||
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);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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****/
|
||||
@ -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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
241
samples/sample_c/module_sample/widget/test_widget.c
Normal file
@ -0,0 +1,241 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "test_widget.h"
|
||||
#include <dji_widget.h>
|
||||
#include <dji_logger.h>
|
||||
#include "../utils/util_misc.h"
|
||||
#include <dji_platform.h>
|
||||
#include <stdio.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_BUTTON, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{2, DJI_WIDGET_TYPE_LIST, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{3, DJI_WIDGET_TYPE_SWITCH, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{4, DJI_WIDGET_TYPE_SCALE, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{5, DJI_WIDGET_TYPE_BUTTON, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{6, DJI_WIDGET_TYPE_SCALE, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{7, DJI_WIDGET_TYPE_INT_INPUT_BOX, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{8, DJI_WIDGET_TYPE_SWITCH, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
{9, DJI_WIDGET_TYPE_LIST, DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL},
|
||||
};
|
||||
|
||||
static 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);
|
||||
}
|
||||
snprintf(message, DJI_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN, "System time : %u ms", sysTimeMs);
|
||||
|
||||
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****/
|
||||
51
samples/sample_c/module_sample/widget/test_widget.h
Normal 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 DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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******/
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |