第一次提交
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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
PSDK/samples/sample_c++/module_sample/liveview/test_liveview.cpp
Normal file
209
PSDK/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, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
|
||||
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, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
|
||||
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, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
|
||||
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, DJI_LIVEVIEW_CAMERA_SOURCE_DEFAULT);
|
||||
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****/
|
||||
@ -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******/
|
||||
@ -0,0 +1,301 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 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 type of camera stream you want to view\n\n"
|
||||
<< "--> [0] Fpv Camera\n"
|
||||
<< "--> [1] Main Camera\n"
|
||||
<< "--> [2] Vice Camera\n"
|
||||
<< "--> [3] Top Camera\n"
|
||||
<< endl;
|
||||
cin >> cameraIndexChar;
|
||||
|
||||
switch (cameraIndexChar) {
|
||||
case '0':
|
||||
liveviewSample->StartFpvCameraStream(&DjiUser_ShowRgbImageCallback, &fpvName);
|
||||
break;
|
||||
case '1':
|
||||
liveviewSample->StartMainCameraStream(&DjiUser_ShowRgbImageCallback, &mainName);
|
||||
break;
|
||||
case '2':
|
||||
liveviewSample->StartViceCameraStream(&DjiUser_ShowRgbImageCallback, &viceName);
|
||||
break;
|
||||
case '3':
|
||||
liveviewSample->StartTopCameraStream(&DjiUser_ShowRgbImageCallback, &topName);
|
||||
break;
|
||||
default:
|
||||
cout << "No camera 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 '0':
|
||||
liveviewSample->StopFpvCameraStream();
|
||||
break;
|
||||
case '1':
|
||||
liveviewSample->StopMainCameraStream();
|
||||
break;
|
||||
case '2':
|
||||
liveviewSample->StopViceCameraStream();
|
||||
break;
|
||||
case '3':
|
||||
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******/
|
||||
@ -0,0 +1,126 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* 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) {
|
||||
|
||||
if (returnCode == DJI_ERROR_SYSTEM_MODULE_CODE_NONSUPPORT) {
|
||||
USER_LOG_ERROR("Perception feature will support on later version.");
|
||||
}
|
||||
|
||||
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,366 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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;
|
||||
}
|
||||
#ifdef OPEN_CV_INSTALLED
|
||||
cv::destroyAllWindows();
|
||||
#endif
|
||||
}
|
||||
|
||||
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 */
|
||||
if (strstr(nameStr, "_l")) {
|
||||
cv::moveWindow(nameStr, 200, 0);
|
||||
} else {
|
||||
cv::moveWindow(nameStr, (200 + (int) pack->info.rawInfo.width), 0);
|
||||
}
|
||||
|
||||
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******/
|
||||
181
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindFFMPEG.cmake
vendored
Normal file
181
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindFFMPEG.cmake
vendored
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
|
||||
)
|
||||
34
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindLIBUSB.cmake
vendored
Normal file
34
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindLIBUSB.cmake
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# Find the native LIBUSB includes and library
|
||||
#
|
||||
# This module defines
|
||||
# LIBUSB_INCLUDE_DIR, where to find libusb.h
|
||||
# LIBUSB_LIBRARY, the libraries to link against to use LIBUSB.
|
||||
# LIBUSB_FOUND, If false, do not try to use LIBUSB.
|
||||
|
||||
FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
|
||||
PATHS
|
||||
/usr/local/include/libusb-1.0
|
||||
/usr/include/libusb-1.0
|
||||
/opt/local/include
|
||||
/opt/include
|
||||
)
|
||||
|
||||
get_filename_component(LIBUSB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR} ABSOLUTE)
|
||||
|
||||
FIND_LIBRARY(LIBUSB_LIBRARY usb-1.0
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
IF (LIBUSB_INCLUDE_DIR)
|
||||
IF (LIBUSB_LIBRARY)
|
||||
SET(LIBUSB_FOUND "YES")
|
||||
ENDIF (LIBUSB_LIBRARY)
|
||||
ENDIF (LIBUSB_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
LIBUSB_INCLUDE_DIR
|
||||
LIBUSB_LIBRARY
|
||||
LIBUSB_FOUND
|
||||
)
|
||||
34
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindOPUS.cmake
vendored
Normal file
34
PSDK/samples/sample_c++/platform/linux/common/3rdparty/FindOPUS.cmake
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# Find the native OPUS includes and library
|
||||
#
|
||||
# This module defines
|
||||
# OPUS_INCLUDE_DIR, where to find opus.h
|
||||
# OPUS_LIBRARY, the libraries to link against to use OPUS.
|
||||
# OPUS_FOUND, If false, do not try to use OPUS.
|
||||
|
||||
FIND_PATH(OPUS_INCLUDE_DIR opus.h
|
||||
PATHS
|
||||
/usr/local/include/opus
|
||||
/usr/include/opus
|
||||
/opt/local/include
|
||||
/opt/include
|
||||
)
|
||||
|
||||
get_filename_component(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR} ABSOLUTE)
|
||||
|
||||
FIND_LIBRARY(OPUS_LIBRARY opus
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
IF (OPUS_INCLUDE_DIR)
|
||||
IF (OPUS_LIBRARY)
|
||||
SET(OPUS_FOUND "YES")
|
||||
ENDIF (OPUS_LIBRARY)
|
||||
ENDIF (OPUS_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
OPUS_INCLUDE_DIR
|
||||
OPUS_LIBRARY
|
||||
OPUS_FOUND
|
||||
)
|
||||
129
PSDK/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt
Normal file
129
PSDK/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt
Normal file
@ -0,0 +1,129 @@
|
||||
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)
|
||||
|
||||
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(../../../../sample_c/module_sample)
|
||||
include_directories(../common)
|
||||
include_directories(../manifold2/application)
|
||||
|
||||
file(GLOB_RECURSE MODULE_SAMPLE_SRC
|
||||
../../../module_sample/liveview/*.c*
|
||||
../../../module_sample/perception/*.c*
|
||||
../../../../sample_c/module_sample/*.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}/../common/3rdparty)
|
||||
|
||||
link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME})
|
||||
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/libpayloadsdk.a -lstdc++)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${MODULE_APP_SRC}
|
||||
${MODULE_SAMPLE_SRC}
|
||||
${MODULE_COMMON_SRC}
|
||||
${MODULE_HAL_SRC})
|
||||
|
||||
# Try to see if user has OpenCV installed因为额
|
||||
# if yes, default callback will display the image
|
||||
find_package(OpenCV QUIET)
|
||||
if (OpenCV_FOUND)
|
||||
message("\n${PROJECT_NAME}...")
|
||||
message(STATUS "Found OpenCV installed in the system, will use it to display image in AdvancedSensing APIs")
|
||||
message(STATUS " - Includes: ${OpenCV_INCLUDE_DIRS}")
|
||||
message(STATUS " - Libraries: ${OpenCV_LIBRARIES}")
|
||||
add_definitions(-DOPEN_CV_INSTALLED)
|
||||
else ()
|
||||
message(STATUS "Did not find OpenCV in the system, image data is inside RecvContainer as raw data")
|
||||
endif ()
|
||||
|
||||
find_package(FFMPEG REQUIRED)
|
||||
if (FFMPEG_FOUND)
|
||||
message(STATUS "Found FFMPEG installed in the system")
|
||||
message(STATUS " - Includes: ${FFMPEG_INCLUDE_DIR}")
|
||||
message(STATUS " - Libraries: ${FFMPEG_LIBRARIES}")
|
||||
|
||||
EXECUTE_PROCESS(COMMAND ffmpeg -version
|
||||
OUTPUT_VARIABLE ffmpeg_version_psdk_libput
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
string(REGEX MATCH "version.*Copyright" ffmpeg_version_line ${ffmpeg_version_psdk_libput})
|
||||
string(REGEX MATCH " .* " ffmpeg_version ${ffmpeg_version_line})
|
||||
string(REGEX MATCH "^ 5.*$" ffmpeg_major_version ${ffmpeg_version})
|
||||
|
||||
if (HEAD${ffmpeg_major_version} STREQUAL "HEAD")
|
||||
message(STATUS " - Version: ${ffmpeg_version}")
|
||||
else ()
|
||||
message(FATAL_ERROR " - Not support FFMPEG version: ${ffmpeg_major_version}, please install 4.x.x instead.")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${FFMPEG_LIBRARIES})
|
||||
else ()
|
||||
message(STATUS "Cannot Find FFMPEG")
|
||||
endif (FFMPEG_FOUND)
|
||||
include_directories(${FFMPEG_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/include)
|
||||
|
||||
find_package(OPUS REQUIRED)
|
||||
if (OPUS_FOUND)
|
||||
message(STATUS "Found OPUS installed in the system")
|
||||
message(STATUS " - Includes: ${OPUS_INCLUDE_DIR}")
|
||||
message(STATUS " - Libraries: ${OPUS_LIBRARY}")
|
||||
|
||||
add_definitions(-DOPUS_INSTALLED)
|
||||
target_link_libraries(${PROJECT_NAME} /usr/local/lib/libopus.a)
|
||||
else ()
|
||||
message(STATUS "Cannot Find OPUS")
|
||||
endif (OPUS_FOUND)
|
||||
|
||||
find_package(LIBUSB REQUIRED)
|
||||
if (LIBUSB_FOUND)
|
||||
message(STATUS "Found LIBUSB installed in the system")
|
||||
message(STATUS " - Includes: ${LIBUSB_INCLUDE_DIR}")
|
||||
message(STATUS " - Libraries: ${LIBUSB_LIBRARY}")
|
||||
|
||||
add_definitions(-DLIBUSB_INSTALLED)
|
||||
target_link_libraries(${PROJECT_NAME} usb-1.0)
|
||||
else ()
|
||||
message(STATUS "Cannot Find LIBUSB")
|
||||
endif (LIBUSB_FOUND)
|
||||
|
||||
if (NOT EXECUTABLE_OUTPUT_PATH)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} m)
|
||||
|
||||
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 ()
|
||||
@ -0,0 +1,392 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 "dji_sdk_config.h"
|
||||
|
||||
#include "osal.h"
|
||||
#include "osal_fs.h"
|
||||
#include "osal_socket.h"
|
||||
#include "hal_usb_bulk.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_network.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_SYSTEM_CMD_STR_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(3000);
|
||||
}
|
||||
|
||||
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;
|
||||
T_DjiSocketHandler socketHandler;
|
||||
T_DjiHalNetworkHandler networkHandler;
|
||||
|
||||
networkHandler.NetworkInit = HalNetWork_Init;
|
||||
networkHandler.NetworkDeInit = HalNetWork_DeInit;
|
||||
networkHandler.NetworkGetDeviceInfo = HalNetWork_GetDeviceInfo;
|
||||
|
||||
socketHandler.Socket = Osal_Socket;
|
||||
socketHandler.Bind = Osal_Bind;
|
||||
socketHandler.Close = Osal_Close;
|
||||
socketHandler.UdpSendData = Osal_UdpSendData;
|
||||
socketHandler.UdpRecvData = Osal_UdpRecvData;
|
||||
socketHandler.TcpListen = Osal_TcpListen;
|
||||
socketHandler.TcpAccept = Osal_TcpAccept;
|
||||
socketHandler.TcpConnect = Osal_TcpConnect;
|
||||
socketHandler.TcpSendData = Osal_TcpSendData;
|
||||
socketHandler.TcpRecvData = Osal_TcpRecvData;
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
#if (CONFIG_HARDWARE_CONNECTION == DJI_USE_UART_AND_USB_BULK_DEVICE)
|
||||
returnCode = DjiPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register hal usb bulk handler error.");
|
||||
}
|
||||
#elif (CONFIG_HARDWARE_CONNECTION == DJI_USE_UART_AND_NETWORK_DEVICE)
|
||||
returnCode = DjiPlatform_RegHalNetworkHandler(&networkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("Register hal network handler error");
|
||||
}
|
||||
#elif (CONFIG_HARDWARE_CONNECTION == DJI_USE_ONLY_UART)
|
||||
/*!< Attention: Only use uart hardware connection.
|
||||
*/
|
||||
#endif
|
||||
|
||||
//Attention: if you want to use camera stream view function, please uncomment it.
|
||||
returnCode = DjiPlatform_RegSocketHandler(&socketHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
throw std::runtime_error("register osal socket 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_SYSTEM_CMD_STR_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 "Project_Grixis"
|
||||
#define USER_APP_ID "126401"
|
||||
#define USER_APP_KEY "a313e3617b16c56a11502bd91a61d6f"
|
||||
#define USER_APP_LICENSE "BNrpsD+UJ2lj8kmVgN4GnXg+AZiQwaxSuf/WvA072DFdLy2h+NCQizf+nR+WcjEEKeTknSzPbfqlvAc/WSJwrtqV/gYXSVPtSlK0AaV61SeKBvZQpogoyaZy07fWNCZrha3OAQsHj18TtU5RjOn6gYapzGDAPQVG6Q/At/H/9GSPQr5uwxI20fVWUTOkymYLM/04CNQGsToPD+fZwixExjjjHjdD9K7R0D4EgyvbqMpMLlkspBLR/9h6/oVxefOyaHJIi+pk+IdLFFC3omnrh7U3/4b95LA3t22J1GJvqvO2cyphjrSXsaDdctvtj6EjE8WhEXQCvmYm0VIHWz/0Qw=="
|
||||
#define USER_DEVELOPER_ACCOUNT "1033584732@qq.com"
|
||||
#define USER_BAUD_RATE "230400"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_SDK_APP_INFO_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,54 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_sdk_config.h
|
||||
* @brief This is the header file for "dji_config.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_SDK_CONFIG_H
|
||||
#define DJI_SDK_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define DJI_USE_ONLY_UART (0)
|
||||
#define DJI_USE_UART_AND_USB_BULK_DEVICE (1)
|
||||
#define DJI_USE_UART_AND_NETWORK_DEVICE (2)
|
||||
|
||||
/*!< Attention: Select your hardware connection mode here.
|
||||
* */
|
||||
#define CONFIG_HARDWARE_CONNECTION DJI_USE_UART_AND_USB_BULK_DEVICE
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_SDK_CONFIG_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@ -0,0 +1,92 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalNetWork_GetDeviceInfo(T_DjiHalNetworkDeviceInfo *deviceInfo)
|
||||
{
|
||||
deviceInfo->usbNetAdapter.vid = USB_NET_ADAPTER_VID;
|
||||
deviceInfo->usbNetAdapter.pid = USB_NET_ADAPTER_PID;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,73 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.h
|
||||
* @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 "enx000ec6688213"
|
||||
#else
|
||||
#define LINUX_NETWORK_DEV "l4tbr0"
|
||||
#endif
|
||||
/**
|
||||
* @attention
|
||||
*/
|
||||
|
||||
#ifdef PLATFORM_ARCH_x86_64
|
||||
#define USB_NET_ADAPTER_VID (0x0B95)
|
||||
#define USB_NET_ADAPTER_PID (0x1790)
|
||||
#else
|
||||
#define USB_NET_ADAPTER_VID (0x0955)
|
||||
#define USB_NET_ADAPTER_PID (0x7020)
|
||||
#endif
|
||||
|
||||
#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);
|
||||
T_DjiReturnCode HalNetWork_GetDeviceInfo(T_DjiHalNetworkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_NETWORK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
260
PSDK/samples/sample_c++/platform/linux/manifold2/hal/hal_uart.c
Normal file
260
PSDK/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_STR_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_STR_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****/
|
||||
@ -0,0 +1,65 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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/ttyS1"
|
||||
#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******/
|
||||
@ -0,0 +1,224 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
libusb_device_handle *handle;
|
||||
#else
|
||||
void *handle;
|
||||
#endif
|
||||
int32_t ep1;
|
||||
int32_t ep2;
|
||||
uint32_t interfaceNum;
|
||||
T_DjiHalUsbBulkInfo usbBulkInfo;
|
||||
} T_HalUsbBulkObj;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
*usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj));
|
||||
if (*usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_init(NULL);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
|
||||
if (handle == NULL) {
|
||||
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));
|
||||
#endif
|
||||
} else {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
|
||||
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->interfaceNum = usbBulkInfo.channelInfo.interfaceNum;
|
||||
|
||||
if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK1_INTERFACE_NUM) {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK2_INTERFACE_NUM) {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle)
|
||||
{
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
|
||||
osalHandler->TaskSleepMs(100);
|
||||
libusb_exit(NULL);
|
||||
#endif
|
||||
} else {
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1);
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2);
|
||||
}
|
||||
|
||||
free(usbBulkHandle);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t actualLen;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut,
|
||||
(uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
#endif
|
||||
} else {
|
||||
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
int32_t actualLen;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn,
|
||||
buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
#endif
|
||||
} else {
|
||||
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo)
|
||||
{
|
||||
//attention: this interface only be called in usb device mode.
|
||||
deviceInfo->vid = LINUX_USB_VID;
|
||||
deviceInfo->pid = LINUX_USB_PID;
|
||||
|
||||
// This bulk channel is used to obtain DJI camera video stream and push 3rd-party camera video stream.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT;
|
||||
|
||||
// This bulk channel is used to obtain DJI perception image and download camera media file.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,91 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.h
|
||||
* @brief This is the header file for "hal_usb_bulk.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_USB_BULK_H
|
||||
#define HAL_USB_BULK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep1"
|
||||
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep2"
|
||||
|
||||
#define LINUX_USB_BULK1_INTERFACE_NUM (2)
|
||||
#define LINUX_USB_BULK1_END_POINT_IN (0x83)
|
||||
#define LINUX_USB_BULK1_END_POINT_OUT (2)
|
||||
|
||||
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep1"
|
||||
#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep2"
|
||||
|
||||
#define LINUX_USB_BULK2_INTERFACE_NUM (3)
|
||||
#define LINUX_USB_BULK2_END_POINT_IN (0x84)
|
||||
#define LINUX_USB_BULK2_END_POINT_OUT (3)
|
||||
|
||||
#ifdef PLATFORM_ARCH_x86_64
|
||||
#define LINUX_USB_VID (0x0B95)
|
||||
#define LINUX_USB_PID (0x1790)
|
||||
#else
|
||||
#define LINUX_USB_VID (0x0955)
|
||||
#define LINUX_USB_PID (0x7020)
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_USB_BULK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
Reference in New Issue
Block a user