Open source adapting : Do adapting for project adjusting.
Open source adapting : 1.Change the source code of linker to be lib and headers files. 2.Add comment in some hpp to prepare to be open-source. 3.Adapting the CMakeList.txt to build dependence between projects. 4.Install place setting for CMakeLists.txt.
Esse commit está contido em:
+6
-1
@@ -65,10 +65,12 @@ if (WAYPT2_CORE)
|
||||
add_definitions(-DWAYPT2_CORE)
|
||||
endif()
|
||||
|
||||
add_subdirectory(osdk-core)
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
|
||||
add_subdirectory(sample/platform/linux)
|
||||
endif()
|
||||
|
||||
#[[
|
||||
INSTALL(DIRECTORY osdk-lib/${ARCH}/osdk-core/inc/
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
|
||||
FILES_MATCHING PATTERN "*.h*")
|
||||
@@ -91,4 +93,7 @@ INSTALL(DIRECTORY osdk-lib/${ARCH}/advanced-sensing-2.0.3/lib/
|
||||
|
||||
INSTALL(DIRECTORY osdk-lib/${ARCH}/waypointv2-core-1.0.0/lib/
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
|
||||
FILES_MATCHING PATTERN "*.a*")
|
||||
FILES_MATCHING PATTERN "*.a*")
|
||||
]]
|
||||
|
||||
|
||||
|
||||
+60
-35
@@ -62,7 +62,22 @@ endif ()
|
||||
|
||||
add_definitions(-DPLATFORM_OSDK)
|
||||
|
||||
include (${CMAKE_CURRENT_SOURCE_DIR}/../contrib/DJIConfig.cmake)
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64|x86_64")
|
||||
set(ARCH x86)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=3)
|
||||
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch"))
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH armv7)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=1)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH armv8)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=2)
|
||||
endif()
|
||||
elseif()
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=0)
|
||||
endif()
|
||||
|
||||
include (${CMAKE_CURRENT_SOURCE_DIR}/contrib/DJIConfig.cmake)
|
||||
include_directories(
|
||||
api/inc
|
||||
modules/inc/firewall
|
||||
@@ -74,17 +89,7 @@ include_directories(
|
||||
platform/inc
|
||||
logger/inc
|
||||
utility/inc
|
||||
linker
|
||||
linker/core
|
||||
linker/core/mop
|
||||
linker/core/mop/mop_core/inc
|
||||
linker/core/utils/inc
|
||||
linker/core/channel
|
||||
linker/core/command
|
||||
linker/core/logger
|
||||
linker/core/platform
|
||||
linker/core/protocol
|
||||
linker/core/root_task)
|
||||
linker/${ARCH}/inc)
|
||||
|
||||
## Source code for OSDK CORE
|
||||
FILE(GLOB OSDK_LIB_SRCS
|
||||
@@ -97,22 +102,28 @@ FILE(GLOB OSDK_LIB_SRCS
|
||||
modules/src/mop/*.cpp
|
||||
platform/src/*.c*
|
||||
logger/src/*.cpp
|
||||
utility/src/*.cpp
|
||||
linker/*.cpp
|
||||
linker/core/mop/*.c*
|
||||
linker/core/mop/mop_core/src/*.c
|
||||
linker/core/channel/*.c
|
||||
linker/core/command/*.c
|
||||
linker/core/logger/*.c
|
||||
linker/core/protocol/*.c
|
||||
linker/core/platform/*.c
|
||||
linker/core/utils/src/*.c
|
||||
linker/core/root_task/*.c)
|
||||
utility/src/*.cpp)
|
||||
|
||||
link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/linker/${ARCH}/lib/libdji-linker.a)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
STATIC
|
||||
${OSDK_LIB_SRCS})
|
||||
|
||||
add_subdirectory(advanced-sensing)
|
||||
|
||||
|
||||
set(ADVANCED_SENSING_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/advanced-sensing)
|
||||
set(ADVANCED_SENSING_HEADERS_DIR
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/api/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/platform/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/protocol/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/camera_stream/src
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/protocol/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/hal/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/platform/linux/inc
|
||||
)
|
||||
|
||||
## Libraries to propagate as dependencies to third-party code depending on osdk-core
|
||||
## Append to this variable when you want a dependency to get propagated
|
||||
SET(OSDK_INTERFACE_LIBS pthread) # pthread is assumed available on linux
|
||||
@@ -128,9 +139,14 @@ if(ADVANCED_SENSING)
|
||||
set(CMAKE_MODULE_PATH ${CURRENT_CMAKE_MODULE_PATH})
|
||||
|
||||
find_package(LibUSB REQUIRED)
|
||||
find_package(AdvancedSensing REQUIRED)
|
||||
#find_package(AdvancedSensing REQUIRED)
|
||||
find_package(FFMPEG REQUIRED)
|
||||
|
||||
message(${ADVANCED_SENSING_HEADERS_DIR})
|
||||
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
|
||||
|
||||
|
||||
|
||||
if(FFMPEG_FOUND)
|
||||
message( STATUS "Found FFmpeg ${FFMPEG_VERSION} installed in the system.")
|
||||
message( STATUS " - Includes: ${FFMPEG_INCLUDE_DIRS}")
|
||||
@@ -140,8 +156,8 @@ if(ADVANCED_SENSING)
|
||||
endif(FFMPEG_FOUND)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${ADVANCED_SENSING_INCLUDE_DIRS}>)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${ADVANCED_SENSING_LIBRARY})
|
||||
$<BUILD_INTERFACE:${ADVANCED_SENSING_HEADERS_DIR}>)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE advanced-sensing)
|
||||
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_1_INCLUDE_DIRS})
|
||||
@@ -151,8 +167,8 @@ if(ADVANCED_SENSING)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
|
||||
|
||||
set(OSDK_INTERFACE_LIBS ${OSDK_INTERFACE_LIBS} ${LIBUSB_1_LIBRARIES} ${FFMPEG_LIBRARIES})
|
||||
set(MODULE_BUILD_INTERFACE ${MODULE_BUILD_INTERFACE} ${ADVANCED_SENSING_LIBRARY})
|
||||
set(MODULE_INSTALL_INTERFACE ${MODULE_INSTALL_INTERFACE} $<INSTALL_PREFIX>/lib/libadvanced-sensing.a)
|
||||
set(MODULE_BUILD_INTERFACE ${MODULE_BUILD_INTERFACE} advanced-sensing)
|
||||
set(MODULE_INSTALL_INTERFACE ${MODULE_INSTALL_INTERFACE} advanced-sensing)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC -DADVANCED_SENSING)
|
||||
|
||||
@@ -249,10 +265,11 @@ FILE(GLOB OSDK_LIB_HEADERS
|
||||
logger/inc/*.h*
|
||||
utility/inc/*.h*
|
||||
##linker layer related header files
|
||||
linker/core/mop/mop_entry_osdk.h
|
||||
linker/core/osdk_typedef.h
|
||||
linker/core/logger/osdk_logger.h
|
||||
linker/core/platform/osdk_platform.h
|
||||
##linker/core/mop/mop_entry_osdk.h
|
||||
##linker/core/osdk_typedef.h
|
||||
##linker/core/logger/osdk_logger.h
|
||||
##linker/core/platform/osdk_platform.h
|
||||
linker/inc/*.h*
|
||||
modules/inc/filemgr/*.h*
|
||||
modules/inc/filemgr/impl/*.h*
|
||||
)
|
||||
@@ -269,13 +286,21 @@ FILE(GLOB OSDK_LIB_HEADERS
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
PUBLIC_HEADER "${OSDK_LIB_HEADERS}")
|
||||
|
||||
#[[
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT djiosdkTargets
|
||||
ARCHIVE DESTINATION "${OSDK_CORE_INSTALL_LIB_DIR}" COMPONENT shlib
|
||||
PUBLIC_HEADER DESTINATION "${OSDK_CORE_INSTALL_INCLUDE_DIR}" COMPONENT dev
|
||||
)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/advanced-sensing-2.0.3
|
||||
DESTINATION ${OSDK_LIB_ARCH_DIR} )
|
||||
]]
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT djiosdkTargets
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" COMPONENT shlib
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT dev
|
||||
)
|
||||
|
||||
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/advanced-sensing-2.0.3
|
||||
# DESTINATION ${OSDK_LIB_ARCH_DIR} )
|
||||
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/waypointv2-core-1.0.0
|
||||
# DESTINATION ${OSDK_LIB_ARCH_DIR} )
|
||||
@@ -26,26 +26,31 @@ elseif(WIN32)
|
||||
set(MY_OS "WIN32")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64|x86_64")
|
||||
set(ARCH x86)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=3)
|
||||
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch"))
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH armv7)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=1)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH armv8)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=2)
|
||||
endif()
|
||||
elseif()
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=0)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -w -fPIC -Wextra -finline-functions -O3 -fno-strict-aliasing -fvisibility=hidden -D${MY_CPU_ARCH} -D${MY_OS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
set(ORI_OSDK_CORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/ori-osdk-core")
|
||||
set(NEW_OSDK_CORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../osdk-core")
|
||||
set(NEW_OSDK_CORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
|
||||
include_directories(
|
||||
${NEW_OSDK_CORE_SRC}/platform/inc
|
||||
${NEW_OSDK_CORE_SRC}/logger/inc
|
||||
${NEW_OSDK_CORE_SRC}/utility/inc
|
||||
${NEW_OSDK_CORE_SRC}/linker
|
||||
${NEW_OSDK_CORE_SRC}/linker/core
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/mop
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/mop/mop_core/inc
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/utils/inc
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/channel
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/command
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/logger
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/platform
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/protocol
|
||||
${NEW_OSDK_CORE_SRC}/linker/core/root_task)
|
||||
${NEW_OSDK_CORE_SRC}/linker/${ARCH}/inc)
|
||||
|
||||
include_directories(${NEW_OSDK_CORE_SRC}/api/inc)
|
||||
include_directories(${NEW_OSDK_CORE_SRC}/modules/inc/payload)
|
||||
@@ -124,6 +129,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
PUBLIC_HEADER "${ADVANCED_SENSING_HEADERS}")
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
ARCHIVE DESTINATION "${CLOSED_SOURCE_LIBS}/lib" COMPONENT shlib
|
||||
PUBLIC_HEADER DESTINATION "${CLOSED_SOURCE_LIBS}/inc" COMPONENT dev
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" COMPONENT shlib
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT dev
|
||||
)
|
||||
|
||||
@@ -92,6 +92,8 @@ typedef enum
|
||||
OSDKSubSuccess = 0,
|
||||
} HMSSubcribeStatus;
|
||||
|
||||
/*! @brief DJI health manager system of drone
|
||||
*/
|
||||
class DJIHMS {
|
||||
public:
|
||||
DJIHMS(Vehicle *vehicle = 0);
|
||||
|
||||
@@ -284,7 +284,6 @@ public:
|
||||
bool initMissionManager();
|
||||
bool initWaypointV2Mission();
|
||||
bool initHardSync();
|
||||
bool initVirtualRC();
|
||||
bool initCameraManager();
|
||||
bool initFlightController();
|
||||
bool initPSDKManager();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# * @Copyright (c) 2016-2017 DJI
|
||||
# *
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# * of this software and associated documentation files (the "Software"), to deal
|
||||
# * in the Software without restriction, including without limitation the rights
|
||||
# * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# * copies of the Software, and to permit persons to whom the Software is
|
||||
# * furnished to do so, subject to the following conditions:
|
||||
# *
|
||||
# * The above copyright notice and this permission notice shall be included in
|
||||
# * all copies or substantial portions of the Software.
|
||||
# *
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# * SOFTWARE.
|
||||
# *
|
||||
# *
|
||||
|
||||
|
||||
#Detecting target architecture to decide which precompiled library to link against
|
||||
|
||||
if((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
|
||||
set(TARGET_ARCH "x86_64")
|
||||
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 4))
|
||||
set(TARGET_ARCH "x86")
|
||||
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch*"))
|
||||
set(TARGET_ARCH "arm")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(PROC_VERSION "v7")
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(PROC_VERSION "v8")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#Detect platform - from https://gist.github.com/CoolerVoid/1781717
|
||||
|
||||
#### DEPRECATED BEHAVIOR ####
|
||||
if(USE_PRECISION_MISSIONS OR USE_COLLISION_AVOIDANCE OR USE_POINTCLOUD2LAS)
|
||||
message(DEPRECATION "DJI external modules are no longer supported!")
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND cat /etc/lsb-release
|
||||
COMMAND grep DISTRIB_RELEASE
|
||||
COMMAND awk -F= "{ print $2 }"
|
||||
COMMAND tr "\n" " "
|
||||
COMMAND sed "s/ //"
|
||||
OUTPUT_VARIABLE LSB_VER
|
||||
)
|
||||
|
||||
if( ${LSB_VER} STREQUAL "16.04")
|
||||
set(DISTRO_VERSION 1604)
|
||||
elseif(${LSB_VER} STREQUAL "14.04")
|
||||
set(DISTRO_VERSION 1404)
|
||||
elseif(${LSB_VER} STREQUAL "18")
|
||||
set(DISTRO_VERSION 1604)
|
||||
else()
|
||||
set(DISTRO_VERSION UNKNOWN)
|
||||
endif()
|
||||
endif()
|
||||
@@ -1,762 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_channel.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/17
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_channel.h"
|
||||
#include "osdk_channel_internal.h"
|
||||
#include "osdk_root_task.h"
|
||||
#include "osdk_util.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define OSDK_CHANNEL_TASK_FREQ (1000)
|
||||
#define UART_MAX_BUF_SIZE (1024)
|
||||
#define USB_LIVEVIEW_MAX_BUF_SIZE (1024*128)
|
||||
#define USB_ADVANCED_SENSING_MAX_BUF_SIZE (1024*512)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static T_ChannelListItem s_chnListItem;
|
||||
static T_ChannelListItem s_bigDataChnListItem;
|
||||
const static T_ProtocolMapKey protoMapTable[] = {
|
||||
{FC_UART_CHANNEL_ID, PROTOCOL_SDK},
|
||||
{USB_ACM_CHANNEL_ID, PROTOCOL_V1},
|
||||
{USB_BULK_LIVEVIEW_CHANNEL_ID, PROTOCOL_USBMC},
|
||||
{USB_BULK_ADVANCED_SENSING_CHANNEL_ID, PROTOCOL_USBMC}};
|
||||
|
||||
static T_msgQueue *s_msgQueuePointer;
|
||||
static T_OsdkWorkNode s_osdkChannelWorkNode = {0};
|
||||
static uint32_t s_osdkChannelWorkStep = 0;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static E_OsdkStat OsdkChannel_MsgQueueInit(void);
|
||||
static E_OsdkStat OsdkChannel_MsgQueueDeinit(void);
|
||||
static void OsdkChannel_Task(void *arg);
|
||||
static E_OsdkStat OsdkChannel_RecvProcess(T_ChannelItem *channelItem,
|
||||
const uint8_t *pData, uint32_t len);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Check if there are duplicates in channel list.
|
||||
* @param chnListCtx: pointer to channel list.
|
||||
* @param channelItem: pointer to channel item.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_CheckDuplicate(T_ChannelListItem *chnListCtx,
|
||||
T_ChannelItem *channelItem) {
|
||||
T_ChannelItem *pNode = NULL;
|
||||
T_ChannelItem *pBackup = NULL;
|
||||
|
||||
if (!chnListCtx || !channelItem) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL,
|
||||
"OsdkChannel_CheckDuplicate param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (chnListCtx->chnCount > 0) {
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &chnListCtx->head, head) {
|
||||
if (channelItem->channelId == pNode->channelId) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_CHANNEL, "channel id exist: %d",
|
||||
channelItem->channelId);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add channel item to channel list
|
||||
* @param channelItem: pointer to channel item.
|
||||
* @param chnListCtx: pointer to channel list item.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_AddChannel(T_ChannelItem *channelItem, T_ChannelListItem *chnListCtx) {
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
if(!channelItem || !chnListCtx) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL,
|
||||
"OsdkChannel_AddChannel param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkChannel_CheckDuplicate(chnListCtx, channelItem);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "osdk channel add new node error:%d",
|
||||
osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
if (chnListCtx->chnCount >= CHANNEL_MAX_SUPPORT_NUM) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "do not have enough resource");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
OsdkList_AddTail(&channelItem->head, &chnListCtx->head);
|
||||
|
||||
chnListCtx->chnCount++;
|
||||
OSDK_LOG_INFO(MODULE_NAME_CHANNEL, "channel list add new node success:%d",
|
||||
chnListCtx->chnCount);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_ChannelListInit(T_ChannelListItem *chnListCtx) {
|
||||
if(!chnListCtx) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL,
|
||||
"OsdkChannel_ChannelListInit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
OsdkList_Init(&chnListCtx->head);
|
||||
chnListCtx->chnCount = 0;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_ChannelListDeinit(T_ChannelListItem *chnListCtx) {
|
||||
T_ChannelItem *pNode = NULL;
|
||||
T_ChannelItem *pBackup = NULL;
|
||||
|
||||
if(!chnListCtx) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL,
|
||||
"OsdkChannel_ChannelListDeinit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
if (chnListCtx->chnCount > 0) {
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &chnListCtx->head, head) {
|
||||
pNode->halOps.Close(&pNode->halObject);
|
||||
OsdkOsal_Free(pNode->recvParse.parseBuff);
|
||||
OsdkOsal_Free(pNode->sendFrameBuff);
|
||||
pNode->protocolOps.Deinit(pNode->protocolExtData);
|
||||
OsdkOsal_MutexDestroy(pNode->sendMutex);
|
||||
OsdkOsal_MutexDestroy(pNode->seqMutex);
|
||||
OsdkList_Del(&pNode->head);
|
||||
}
|
||||
}
|
||||
chnListCtx->chnCount = 0;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_ChannelTaskInit() {
|
||||
E_OsdkStat osdkStat;
|
||||
s_osdkChannelWorkNode.name = "channelTask";
|
||||
s_osdkChannelWorkNode.taskFunc = OsdkChannel_Task;
|
||||
s_osdkChannelWorkNode.arg = (void *)NULL;
|
||||
|
||||
osdkStat =
|
||||
OsdkWork_AddNode(OsdkCore_GetWorkInstance(), &s_osdkChannelWorkNode);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "create command task error:%d",
|
||||
osdkStat);
|
||||
}
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_ChannelTaskDeinit() {
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat =
|
||||
OsdkWork_DeleteNode(OsdkCore_GetWorkInstance(), &s_osdkChannelWorkNode);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "destroy command task error:%d",
|
||||
osdkStat);
|
||||
}
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get channel item by channel id.
|
||||
* @param chnListCtx: pointer to channel list.
|
||||
* @param channelId: target channel id.
|
||||
* @param channelItem: pointer to channel item.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_GetChannelItemByChnId(T_ChannelListItem *chnListCtx,
|
||||
uint32_t channelId,
|
||||
T_ChannelItem **channelItem) {
|
||||
T_ChannelItem *pNode = NULL;
|
||||
T_ChannelItem *pBackup = NULL;
|
||||
|
||||
if (!chnListCtx) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "GetChannelItemByDevId param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (chnListCtx->chnCount > 0) {
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &chnListCtx->head, head) {
|
||||
if (channelId == pNode->channelId) {
|
||||
*channelItem = pNode;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Init uart channel item.
|
||||
* @param port: uart port name.
|
||||
* @param baudRate: uart port baud rate.
|
||||
* @param id: channel id.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_InitUartChannel(const char *port,
|
||||
const uint32_t baudRate,
|
||||
E_ChannelIDType id) {
|
||||
T_ChannelItem *channelItem = NULL;
|
||||
|
||||
if(!port) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_InitUartChannel param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
channelItem = OsdkOsal_Malloc(sizeof(T_ChannelItem));
|
||||
if (channelItem == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for channel item failed");
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
|
||||
channelItem->channelName = "UART";
|
||||
channelItem->channelId = id;
|
||||
channelItem->bufMaxSize = UART_MAX_BUF_SIZE;
|
||||
channelItem->seqNum = 0;
|
||||
channelItem->recvParse.parseIndex = 0;
|
||||
channelItem->recvParse.parseBuff = OsdkOsal_Malloc(channelItem->bufMaxSize);
|
||||
if(channelItem->recvParse.parseBuff == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for parse buffer failed");
|
||||
goto parse_buff_malloc_err;
|
||||
}
|
||||
memset(channelItem->recvParse.parseBuff, 0, channelItem->bufMaxSize);
|
||||
channelItem->Send = OsdkChannel_CommonSend;
|
||||
channelItem->Recv = OsdkChannel_CommonRecv;
|
||||
channelItem->sendFrameBuff = OsdkOsal_Malloc(channelItem->bufMaxSize);
|
||||
if(channelItem->sendFrameBuff == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for send buffer failed");
|
||||
goto send_buff_malloc_err;
|
||||
}
|
||||
memset(channelItem->sendFrameBuff, 0, sizeof(channelItem->sendFrameBuff));
|
||||
|
||||
if (OsdkHal_GetHalOps("UART", &channelItem->halOps) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "can't get hal ops");
|
||||
goto get_hal_ops_err;
|
||||
}
|
||||
|
||||
if (OsdkHal_UartInit(port, baudRate, &channelItem->halObject) !=
|
||||
OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "UART init failed");
|
||||
goto uart_init_err;
|
||||
}
|
||||
|
||||
if (OsdkChannel_GetProtoOps(channelItem->channelId,
|
||||
&channelItem->protocolOps) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "can't get protocol ops");
|
||||
goto get_proto_ops_err;
|
||||
}
|
||||
|
||||
if (channelItem->protocolOps.Init(&channelItem->protocolExtData) !=
|
||||
OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "protocol init error");
|
||||
goto proto_init_err;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexCreate(&channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "send mutex create error");
|
||||
goto send_mutex_create_err;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexCreate(&channelItem->seqMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "seq mutex create error");
|
||||
goto seq_mutex_create_err;
|
||||
}
|
||||
|
||||
if (OsdkChannel_AddChannel(channelItem, OsdkChannel_GetListInstance()) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "add uart channel error");
|
||||
goto add_channel_err;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
|
||||
add_channel_err:
|
||||
OsdkOsal_MutexDestroy(channelItem->seqMutex);
|
||||
seq_mutex_create_err:
|
||||
OsdkOsal_MutexDestroy(channelItem->sendMutex);
|
||||
send_mutex_create_err:
|
||||
channelItem->protocolOps.Deinit(&channelItem->protocolExtData);
|
||||
proto_init_err:
|
||||
get_proto_ops_err:
|
||||
channelItem->halOps.Close(&channelItem->halObject);
|
||||
uart_init_err:
|
||||
get_hal_ops_err:
|
||||
OsdkOsal_Free(channelItem->sendFrameBuff);
|
||||
send_buff_malloc_err:
|
||||
OsdkOsal_Free(channelItem->recvParse.parseBuff);
|
||||
parse_buff_malloc_err:
|
||||
OsdkOsal_Free(channelItem);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/**
|
||||
* @brief Init usb bulk channel item.
|
||||
* @param pid: usb bulk pid.
|
||||
* @param vid: usb bulk vid.
|
||||
* @param num: usb bulk interface num.
|
||||
* @param epIn usb bulk endpoint in.
|
||||
* @param epOut usb bulk endpoint out.
|
||||
* @param id channel id.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_InitUSBBulkChannel(uint16_t pid, uint16_t vid, uint16_t num,
|
||||
uint16_t epIn, uint16_t epOut,
|
||||
E_ChannelIDType id) {
|
||||
T_ChannelItem *channelItem = NULL;
|
||||
E_OsdkStat osdkStat = OSDK_STAT_OK;
|
||||
|
||||
channelItem = OsdkOsal_Malloc(sizeof(T_ChannelItem));
|
||||
if (channelItem == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for channel fail");
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
|
||||
channelItem->channelName = "USB_BULK";
|
||||
channelItem->channelId = id;
|
||||
if(id == USB_BULK_LIVEVIEW_CHANNEL_ID)
|
||||
channelItem->bufMaxSize = USB_LIVEVIEW_MAX_BUF_SIZE;
|
||||
else
|
||||
channelItem->bufMaxSize = USB_ADVANCED_SENSING_MAX_BUF_SIZE;
|
||||
channelItem->seqNum = 0;
|
||||
channelItem->recvParse.parseIndex = 0;
|
||||
channelItem->recvParse.parseBuff = OsdkOsal_Malloc(channelItem->bufMaxSize);
|
||||
if(channelItem->recvParse.parseBuff == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for parse buffer failed");
|
||||
goto parse_buff_malloc_err;
|
||||
}
|
||||
memset(channelItem->recvParse.parseBuff, 0, channelItem->bufMaxSize);
|
||||
channelItem->Send = OsdkChannel_BigDataSend;
|
||||
channelItem->Recv = OsdkChannel_BigDataRecv;
|
||||
channelItem->sendFrameBuff = OsdkOsal_Malloc(channelItem->bufMaxSize);
|
||||
if(channelItem->sendFrameBuff == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "malloc memory for send buffer failed");
|
||||
goto send_buff_malloc_err;
|
||||
}
|
||||
memset(channelItem->sendFrameBuff, 0, sizeof(channelItem->sendFrameBuff));
|
||||
|
||||
if (OsdkHal_GetHalOps("USB_BULK", &channelItem->halOps) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "get hal ops failed");
|
||||
goto get_hal_ops_err;
|
||||
}
|
||||
|
||||
if (OsdkHal_USBBulkInit(pid, vid, num, epIn, epOut, &channelItem->halObject) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "USB BULK init failed");
|
||||
goto hal_init_err;
|
||||
}
|
||||
|
||||
if (OsdkChannel_GetProtoOps(channelItem->channelId,
|
||||
&channelItem->protocolOps) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "can't get protocol ops");
|
||||
goto get_proto_ops_err;
|
||||
}
|
||||
|
||||
if (channelItem->protocolOps.Init(&channelItem->protocolExtData) !=
|
||||
OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "protocol init error");
|
||||
goto proto_init_err;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexCreate(&channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "send mutex create error");
|
||||
goto send_mutex_create_err;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexCreate(&channelItem->seqMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "seq mutex create error");
|
||||
goto seq_mutex_create_err;
|
||||
}
|
||||
|
||||
if (OsdkChannel_AddChannel(channelItem, OsdkChannel_GetBigDataListInstance()) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "add usb channel error");
|
||||
goto add_channel_err;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
|
||||
add_channel_err:
|
||||
OsdkOsal_MutexDestroy(channelItem->seqMutex);
|
||||
seq_mutex_create_err:
|
||||
OsdkOsal_MutexDestroy(channelItem->sendMutex);
|
||||
send_mutex_create_err:
|
||||
channelItem->protocolOps.Deinit(&channelItem->protocolExtData);
|
||||
proto_init_err:
|
||||
get_proto_ops_err:
|
||||
channelItem->halOps.Close(&channelItem->halObject);
|
||||
hal_init_err:
|
||||
get_hal_ops_err:
|
||||
OsdkOsal_Free(channelItem->sendFrameBuff);
|
||||
send_buff_malloc_err:
|
||||
OsdkOsal_Free(channelItem->recvParse.parseBuff);
|
||||
parse_buff_malloc_err:
|
||||
OsdkOsal_Free(channelItem);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get protocol oprations.
|
||||
* @param interface: communication interface name.
|
||||
* @param ops: pointer to protocol operations.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_GetProtoOps(const uint32_t channelId,
|
||||
T_ProtocolOps *ops) {
|
||||
int i = 0;
|
||||
E_ProtocolType type;
|
||||
|
||||
if(!ops) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_GetProtoOps param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
for (; i < sizeof(protoMapTable) / sizeof(protoMapTable[0]); ++i) {
|
||||
if (protoMapTable[i].channelId == channelId) {
|
||||
type = protoMapTable[i].type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == sizeof(protoMapTable) / sizeof(protoMapTable[0])) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "can't find channelId");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (OsdkProtocol_getProtocolOps(type, ops) == OSDK_STAT_ERR) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "can't find protocol");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get channel sequence number.
|
||||
* @param channelItem: pointer to channel item.
|
||||
* @param seq: pointer to store sequence number.
|
||||
* @return error code.
|
||||
*/
|
||||
E_OsdkStat OsdkChannel_GetSeqNum(T_ChannelItem *channelItem, uint16_t *seq) {
|
||||
|
||||
if(!channelItem || !seq) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_GetSeqNum param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
if (OsdkOsal_MutexLock(channelItem->seqMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex lock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
channelItem->seqNum++;
|
||||
*seq = channelItem->seqNum;
|
||||
|
||||
if (OsdkOsal_MutexUnlock(channelItem->seqMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex unlock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* @TODO To be completed */
|
||||
E_OsdkStat OsdkChannel_CommonSend(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData) {
|
||||
uint32_t length = 0;
|
||||
|
||||
if(!channelItem || !cmdInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_CommonSend param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexLock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex lock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (channelItem->protocolOps.Pack(channelItem->protocolExtData,
|
||||
channelItem->sendFrameBuff, &length,
|
||||
cmdInfo, cmdData) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "protocol pack error");
|
||||
if (OsdkOsal_MutexUnlock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex unlock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (channelItem->halOps.Send(&channelItem->halObject,
|
||||
channelItem->sendFrameBuff,
|
||||
length) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "hal send error");
|
||||
if (OsdkOsal_MutexUnlock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex unlock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexUnlock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex unlock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_BigDataSend(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData) {
|
||||
uint32_t length = 0;
|
||||
|
||||
if(!channelItem || !cmdInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_CommonSend param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexLock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex lock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (channelItem->protocolOps.Pack(channelItem->protocolExtData,
|
||||
channelItem->sendFrameBuff, &length,
|
||||
cmdInfo, cmdData) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "protocol pack error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (channelItem->halOps.Send(&channelItem->halObject,
|
||||
channelItem->sendFrameBuff,
|
||||
length) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "hal send error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexUnlock(channelItem->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "mutex unlock error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_BigDataRecv(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint32_t parseLen;
|
||||
uint8_t *pFrame;
|
||||
|
||||
if(!channelItem) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_CommonRecv param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
T_recvBufferCtx *bufferCtx = channelItem->protocolExtData;
|
||||
if(bufferCtx->bufferLen == 0) {
|
||||
bufferCtx->bufferLen = channelItem->bufMaxSize;
|
||||
osdkStat =
|
||||
channelItem->halOps.Read(&channelItem->halObject, bufferCtx->buffer, &bufferCtx->bufferLen);
|
||||
if (osdkStat != OSDK_STAT_OK || bufferCtx->bufferLen == 0) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_CHANNEL, "hal read error");
|
||||
bufferCtx->bufferLen == 0;
|
||||
return osdkStat;
|
||||
}
|
||||
}
|
||||
for(; bufferCtx->useIdx < bufferCtx->bufferLen; bufferCtx->useIdx++) {
|
||||
osdkStat = channelItem->protocolOps.Parse(&channelItem->recvParse,
|
||||
bufferCtx->buffer[bufferCtx->useIdx], &pFrame, &parseLen);
|
||||
if (osdkStat == OSDK_STAT_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(bufferCtx->useIdx == bufferCtx->bufferLen) {
|
||||
bufferCtx->useIdx = 0;
|
||||
bufferCtx->bufferLen = 0;
|
||||
}
|
||||
|
||||
if(osdkStat == OSDK_STAT_OK) {
|
||||
osdkStat = channelItem->protocolOps.Unpack(channelItem->protocolExtData,
|
||||
pFrame, cmdInfo, cmdData);
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_CHANNEL, "protocol unpack error");
|
||||
return osdkStat;
|
||||
}
|
||||
}
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/* @TODO To be completed */
|
||||
E_OsdkStat OsdkChannel_CommonRecv(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint32_t recvLen = 0;
|
||||
uint8_t *dataRecv = NULL;
|
||||
|
||||
if(!channelItem) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_CommonRecv param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
dataRecv = OsdkOsal_Malloc(channelItem->bufMaxSize);
|
||||
|
||||
osdkStat =
|
||||
channelItem->halOps.Read(&channelItem->halObject, dataRecv, &recvLen);
|
||||
if (osdkStat == OSDK_STAT_OK) {
|
||||
if (recvLen != 0) {
|
||||
OsdkChannel_RecvProcess(channelItem, dataRecv, recvLen);
|
||||
}
|
||||
} else {
|
||||
OSDK_LOG_WARN(MODULE_NAME_CHANNEL, "hal read error");
|
||||
}
|
||||
|
||||
OsdkOsal_Free(dataRecv);
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkChannel_RecvProcess(T_ChannelItem *channelItem,
|
||||
const uint8_t *pData, uint32_t len) {
|
||||
uint32_t parseLen;
|
||||
uint8_t *pFrame;
|
||||
E_OsdkStat OsdkStat = OSDK_STAT_OK;
|
||||
int i;
|
||||
|
||||
if(!channelItem || !pData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "OsdkChannel_RecvProcess param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
OsdkStat = channelItem->protocolOps.Parse(&channelItem->recvParse, pData[i],
|
||||
&pFrame, &parseLen);
|
||||
|
||||
if (OsdkStat == OSDK_STAT_OK) {
|
||||
uint8_t *buf = OsdkOsal_Malloc(channelItem->bufMaxSize + sizeof(T_CmdInfo));
|
||||
T_CmdInfo *cmdInfo = (T_CmdInfo *)buf;
|
||||
uint8_t *databuf = &buf[sizeof(T_CmdInfo)];
|
||||
if (channelItem->protocolOps.Unpack(channelItem->protocolExtData, pFrame,
|
||||
cmdInfo, databuf) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_CHANNEL, "protocol unpack error");
|
||||
} else {
|
||||
cmdInfo->channelId = channelItem->channelId;
|
||||
#ifdef OS_DEBUG
|
||||
uint64_t timeFuncBefore;
|
||||
uint64_t timeFuncAfter;
|
||||
if (OsdkOsal_GetTimeUs(&timeFuncBefore) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "get system time error");
|
||||
}
|
||||
#endif
|
||||
if (OsdkMsgq_Send(OsdkChannel_GetMsgqInstance(), (void *)buf,
|
||||
sizeof(T_CmdInfo) + cmdInfo->dataLen,
|
||||
OSDK_WAIT_ONE_SECOND) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_CHANNEL, "msg send error");
|
||||
}
|
||||
#ifdef OS_DEBUG
|
||||
if (OsdkOsal_GetTimeUs(&timeFuncAfter) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CHANNEL, "get system time error");
|
||||
}
|
||||
if((timeFuncAfter - timeFuncBefore) > 1000)
|
||||
OSDK_LOG_DEBUG(MODULE_NAME_CHANNEL, "OsdkMsgq_Send about: %d us",
|
||||
(timeFuncAfter - timeFuncBefore));
|
||||
#endif
|
||||
}
|
||||
OsdkOsal_Free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
return OsdkStat;
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkChannel_MsgQueueInit(void) {
|
||||
T_msgqAttrib attrib;
|
||||
attrib.name = "channelMsgQueue";
|
||||
attrib.bufSize = MSGQ_SIZE;
|
||||
return OsdkMsgq_Create(&attrib, &s_msgQueuePointer);
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkChannel_MsgQueueDeinit(void) {
|
||||
return OsdkMsgq_Destroy(s_msgQueuePointer);
|
||||
}
|
||||
|
||||
T_ChannelListItem *OsdkChannel_GetListInstance(void) { return &s_chnListItem; }
|
||||
|
||||
T_ChannelListItem *OsdkChannel_GetBigDataListInstance(void) { return &s_bigDataChnListItem; }
|
||||
|
||||
E_OsdkStat OsdkChannel_InitInstance(void) {
|
||||
if (OsdkChannel_MsgQueueInit() != OSDK_STAT_OK) {
|
||||
goto msgq_init_err;
|
||||
}
|
||||
if (OsdkChannel_ChannelListInit(&s_bigDataChnListItem) != OSDK_STAT_OK) {
|
||||
goto channle_list_init_err;
|
||||
}
|
||||
if (OsdkChannel_ChannelListInit(&s_chnListItem) != OSDK_STAT_OK) {
|
||||
goto channle_list_init_err;
|
||||
}
|
||||
if(OsdkChannel_ChannelTaskInit() != OSDK_STAT_OK) {
|
||||
goto channel_task_init_err;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
|
||||
channel_task_init_err:
|
||||
channle_list_init_err:
|
||||
OsdkChannel_MsgQueueDeinit();
|
||||
msgq_init_err:
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkChannel_DeinitInstance(void) {
|
||||
OsdkChannel_ChannelTaskDeinit();
|
||||
OsdkChannel_ChannelListDeinit(&s_bigDataChnListItem);
|
||||
OsdkChannel_ChannelListDeinit(&s_chnListItem);
|
||||
OsdkChannel_MsgQueueDeinit();
|
||||
}
|
||||
|
||||
T_msgQueue *OsdkChannel_GetMsgqInstance(void) { return s_msgQueuePointer; }
|
||||
|
||||
void OsdkChannel_Task(void *arg) {
|
||||
T_ChannelItem *pNode = NULL;
|
||||
T_ChannelItem *pBackup = NULL;
|
||||
T_ChannelListItem *chnListCtx = NULL;
|
||||
|
||||
if (OSDK_UTIL_WORK_RUN(s_osdkChannelWorkStep++, OSDK_CHANNEL_TASK_FREQ,
|
||||
OsdkCore_GetRootTaskFreq())) {
|
||||
chnListCtx = OsdkChannel_GetListInstance();
|
||||
if (chnListCtx->chnCount > 0) {
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &chnListCtx->head, head) {
|
||||
if (pNode->Recv(pNode, NULL, NULL) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_CHANNEL, "channel recv error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_channel_internal.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief This is the header file for "osdk_channel.c", defining the structure
|
||||
*and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_CHANNEL_INTERNAL_H
|
||||
#define OSDK_CHANNEL_INTERNAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_hal.h"
|
||||
#include "osdk_msgq.h"
|
||||
#include "osdk_osal.h"
|
||||
#include "osdk_protocol.h"
|
||||
#include "osdk_routetable.h"
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_work.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
struct _ChannelItem;
|
||||
|
||||
typedef E_OsdkStat (*ChannelSend)(struct _ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
|
||||
/* @TODO param need to be change*/
|
||||
typedef E_OsdkStat (*ChannelRecv)(struct _ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
|
||||
typedef struct _ChannelItem {
|
||||
T_OsdkList head;
|
||||
char *channelName;
|
||||
uint32_t channelId;
|
||||
uint16_t seqNum;
|
||||
uint32_t bufMaxSize;
|
||||
uint8_t *sendFrameBuff;
|
||||
T_ProtocolOps protocolOps;
|
||||
T_HalObj halObject;
|
||||
T_HalOps halOps;
|
||||
T_OsdkMutexHandle sendMutex;
|
||||
T_OsdkMutexHandle seqMutex;
|
||||
ChannelSend Send;
|
||||
ChannelRecv Recv;
|
||||
T_CmdParse recvParse;
|
||||
void *protocolExtData;
|
||||
} T_ChannelItem;
|
||||
|
||||
typedef struct {
|
||||
T_OsdkList head;
|
||||
uint32_t chnCount;
|
||||
} T_ChannelListItem;
|
||||
|
||||
typedef struct {
|
||||
uint32_t channelId;
|
||||
E_ProtocolType type;
|
||||
} T_ProtocolMapKey;
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkChannel_CheckDuplicate(T_ChannelListItem *chnListCtx,
|
||||
T_ChannelItem *channelItem);
|
||||
E_OsdkStat OsdkChannel_AddChannel(T_ChannelItem *channelItem, T_ChannelListItem *chnListCtx);
|
||||
E_OsdkStat OsdkChannel_ChannelListInit(T_ChannelListItem *chnListCtx);
|
||||
E_OsdkStat OsdkChannel_ChannelListDeinit(T_ChannelListItem *chnListCtx);
|
||||
E_OsdkStat OsdkChannel_GetChannelItemByChnId(T_ChannelListItem *chnListCtx,
|
||||
uint32_t channelId,
|
||||
T_ChannelItem **channelItem);
|
||||
|
||||
E_OsdkStat OsdkChannel_GetProtoOps(const uint32_t channelId,
|
||||
T_ProtocolOps *ops);
|
||||
E_OsdkStat OsdkChannel_GetSeqNum(T_ChannelItem *channelItem, uint16_t *seq);
|
||||
|
||||
E_OsdkStat OsdkChannel_BigDataSend(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkChannel_BigDataRecv(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkChannel_CommonSend(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkChannel_CommonRecv(T_ChannelItem *channelItem,
|
||||
const T_CmdInfo *cmdInfo,
|
||||
const uint8_t *cmdData);
|
||||
T_msgQueue *OsdkChannel_GetMsgqInstance(void);
|
||||
T_ChannelListItem *OsdkChannel_GetListInstance(void);
|
||||
T_ChannelListItem *OsdkChannel_GetBigDataListInstance(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_CHANNEL_INTERNAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_command_instance.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_command_instance.h"
|
||||
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#ifdef STM32
|
||||
#include "stm32f4xx.h"
|
||||
/*! STM32F4 family includes a 64-Kbyte of CCM (core coupled memory) data RAM.
|
||||
* Start Address : CCMDATARAM_BASE(0x10000000)
|
||||
* Should be paid attention that only STM32F4XX support this defination */
|
||||
static T_CmdHandle s_commandHandle __attribute__((at(CCMDATARAM_BASE)));
|
||||
#else
|
||||
static T_CmdHandle s_commandHandle;
|
||||
#endif
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkCommand_InitInstance(void) {
|
||||
T_CmdInitConf conf = {0};
|
||||
memset(&s_commandHandle, 0, sizeof(s_commandHandle));
|
||||
return OsdkCommand_Init(&s_commandHandle, &conf);
|
||||
}
|
||||
|
||||
T_CmdHandle *OsdkCommand_GetInstance(void) { return &s_commandHandle; }
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_common_define.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief This is the header file for defining the structure and enum
|
||||
*
|
||||
* @copyright (c) 2018-2019 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_COMMON_DEFINE_H
|
||||
#define DJI_COMMON_DEFINE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
OSDK_COMMON_CMD_ID_SIMPLE_TIME_SYNC = 0x58,
|
||||
} E_DJIExtendCmdId;
|
||||
|
||||
typedef enum {
|
||||
DJI_SYN_REQUEST = 1, // 同步请求
|
||||
DJI_FOLLOW_REQUEST = 2, // 跟随请求
|
||||
DJI_DELAY_COMPUTER_REQUEST = 3, // 延迟测算请求
|
||||
DJI_MAIN_CLOCK_TIME_PUSH = 4, // 主时钟时间推送
|
||||
} DJI_COMMON_SIMPLE_TIME_SYN;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
// 子命令ID
|
||||
uint8_t sub_command_id; // enum-type: DJI_COMMON_SIMPLE_TIME_SYN
|
||||
// 甲方汇报自身的时间
|
||||
uint32_t timestamp;
|
||||
} dji_general_get_simple_time_sync_req;
|
||||
typedef struct {
|
||||
// 返回码
|
||||
uint8_t ret_code;
|
||||
// 收到的甲方发来的甲方时间
|
||||
uint32_t remote_time;
|
||||
// 乙方收到该协议时的乙方时间
|
||||
uint32_t recv_time;
|
||||
// 乙方应答该协议时的乙方时间
|
||||
uint32_t send_time;
|
||||
} dji_general_get_simple_time_sync_ack;
|
||||
#pragma pack()
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_COMMON_DEFINE_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,156 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_logger.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_logger.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LOGGER_BUF_MAX_SIZE 512
|
||||
|
||||
// attention:hex printf length should be less than this macro
|
||||
#define LOGGER_HEX_MAX_NUM 64
|
||||
#define LOGGER_HEX_LINEBREAK_NUM 16
|
||||
|
||||
#define LOGGER_CONSOLE_MAX_NUM 8
|
||||
#define LOGGER_REMOTE_RECORD_LEVEL OSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
static T_OsdkLoggerConsole s_consoleList[LOGGER_CONSOLE_MAX_NUM];
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static void OsdkLogger_RemoteRecord(const uint8_t *data, uint16_t dataLen);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkLogger_AddConsole(T_OsdkLoggerConsole *console) {
|
||||
int i;
|
||||
|
||||
if (console->consoleLevel > OSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG ||
|
||||
console->consoleLevel < OSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR ||
|
||||
console->func == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
for (i = 0; i < LOGGER_CONSOLE_MAX_NUM; i++) {
|
||||
if (s_consoleList[i].func == NULL ||
|
||||
s_consoleList[i].consoleLevel < OSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR ||
|
||||
s_consoleList[i].consoleLevel > OSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == LOGGER_CONSOLE_MAX_NUM) {
|
||||
return OSDK_STAT_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
s_consoleList[i].func = console->func;
|
||||
s_consoleList[i].consoleLevel = console->consoleLevel;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
void OsdkLogger_Log(const char *moduleName, uint8_t level, const char *fmt,
|
||||
...) {
|
||||
va_list args;
|
||||
int length;
|
||||
char *logBuf;
|
||||
char *formatBuf;
|
||||
uint32_t timeMs;
|
||||
|
||||
OsdkOsal_GetTimeMs(&timeMs);
|
||||
logBuf = OsdkOsal_Malloc(LOGGER_BUF_MAX_SIZE);
|
||||
if (logBuf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
formatBuf = OsdkOsal_Malloc(LOGGER_BUF_MAX_SIZE);
|
||||
if (formatBuf == NULL) {
|
||||
OsdkOsal_Free(logBuf);
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
snprintf(formatBuf, LOGGER_BUF_MAX_SIZE, "[%d.%03d][module_%s]-%s\r\n",
|
||||
timeMs / 1000, timeMs % 1000, moduleName, fmt);
|
||||
length = vsnprintf(logBuf, LOGGER_BUF_MAX_SIZE, formatBuf, args);
|
||||
|
||||
if (length > 0) {
|
||||
for (int i = 0; i < LOGGER_CONSOLE_MAX_NUM; i++) {
|
||||
if (s_consoleList[i].consoleLevel > OSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG ||
|
||||
s_consoleList[i].consoleLevel < OSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR ||
|
||||
s_consoleList[i].func == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (level <= s_consoleList[i].consoleLevel) {
|
||||
s_consoleList[i].func((uint8_t *)logBuf, length);
|
||||
}
|
||||
}
|
||||
|
||||
if (level <= LOGGER_REMOTE_RECORD_LEVEL) {
|
||||
OsdkLogger_RemoteRecord((uint8_t *)logBuf, length);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
OsdkOsal_Free(logBuf);
|
||||
OsdkOsal_Free(formatBuf);
|
||||
}
|
||||
|
||||
void OsdkLogger_PrintfHex(const uint8_t *data, uint16_t dataLen) {
|
||||
char *logBuf;
|
||||
int len = 0;
|
||||
|
||||
if (dataLen >= LOGGER_HEX_MAX_NUM) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_LOGGER, "hex data length out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
logBuf = OsdkOsal_Malloc(LOGGER_BUF_MAX_SIZE);
|
||||
if (logBuf == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_LOGGER, "logger malloc error");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < dataLen; i++) {
|
||||
if ((i + 1) % LOGGER_HEX_LINEBREAK_NUM == 0 && i > 0) {
|
||||
len += sprintf(&logBuf[len], "0x%02X\r\n", data[i]);
|
||||
} else {
|
||||
len += sprintf(&logBuf[len], "0x%02X ", data[i]);
|
||||
}
|
||||
}
|
||||
OsdkLogger_Log(MODULE_NAME_LOGGER, OSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG,
|
||||
"PrintHex:\r\n%s", logBuf);
|
||||
|
||||
OsdkOsal_Free(logBuf);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static void OsdkLogger_RemoteRecord(const uint8_t *data, uint16_t dataLen) {
|
||||
// TODO: add the remote record to UAV later
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
Submodule osdk-core/linker/core/mop/mop_core deleted from ad5a14438c
@@ -1,356 +0,0 @@
|
||||
/*************************************************************************
|
||||
> File Name: mop_entry_osdk.c
|
||||
> Author: dafeng.xu
|
||||
> Email: dafeng.xu@dji.com
|
||||
> Created Time: Thu 12 Dec 2019 03:10:50 PM CST
|
||||
************************************************************************/
|
||||
|
||||
#include "mop_osal.h"
|
||||
#include "mop_link_layer.h"
|
||||
#include "mop_net_layer.h"
|
||||
#include "mop_priv.h"
|
||||
#include "mop_buffer.h"
|
||||
#include "mop_trans_layer.h"
|
||||
#include "mop_entry_osdk.h"
|
||||
#include "osdk_command.h"
|
||||
#include "osdk_command_instance.h"
|
||||
|
||||
#define MAX_BACKLOG (20)
|
||||
#define ASSEMBLE_LEN (32768)
|
||||
#define MOP_RECV_BUFFER_MAX_NUM (8)
|
||||
#define MOP_RECV_BUFFER_LENGTH (32*1024)
|
||||
|
||||
typedef struct {
|
||||
void *send_buf;
|
||||
void *recv_buf;
|
||||
uint32_t send_len;
|
||||
uint32_t recv_len;
|
||||
} link_buffer;
|
||||
|
||||
typedef struct {
|
||||
bool flag;
|
||||
void *buffer;
|
||||
uint32_t length;
|
||||
} __attribute__((packed)) T_recvBufferItem;
|
||||
|
||||
typedef struct {
|
||||
T_recvBufferItem bufferItem[MOP_RECV_BUFFER_MAX_NUM];
|
||||
int writeIdx;
|
||||
int readIdx;
|
||||
} __attribute__((packed)) T_mopRecvCtx;
|
||||
|
||||
static link_buffer assemble_buf = {NULL, NULL, 0, 0};
|
||||
|
||||
static E_OsdkStat mopRecvHandler(struct _CommandHandle *cmdHandle,
|
||||
const T_CmdInfo *cmdInfo, const uint8_t *cmdData, void *userData);
|
||||
|
||||
static T_mopRecvCtx s_recvCtx;
|
||||
static mop_route_item_t o2e1e_slv_route_tab[] = {{NULL, MOP_DEVICE_ROUTER, 1},
|
||||
{NULL, MOP_DEVICE_ROUTER, 0},
|
||||
{NULL, MOP_DEVICE_PSDK, 0},
|
||||
{NULL, MOP_DEVICE_PSDK, 1},
|
||||
{NULL, MOP_DEVICE_PSDK, 2},
|
||||
{NULL, MOP_DEVICE_MSDK, 0},
|
||||
{NULL, MOP_DEVICE_MSDK, 1}};
|
||||
|
||||
static T_RecvCmdItem s_bulkCmdList[] = {
|
||||
PROT_CMD_ITEM(0, 0, 0x66, 0x01, MASK_HOST_DEVICE_SET_ID, NULL,
|
||||
mopRecvHandler),
|
||||
};
|
||||
|
||||
E_OsdkStat mopRecvHandler(struct _CommandHandle *cmdHandle,
|
||||
const T_CmdInfo *cmdInfo, const uint8_t *cmdData, void *userData)
|
||||
{
|
||||
int count = 0, i;
|
||||
static int index = 1;
|
||||
i = s_recvCtx.writeIdx;
|
||||
|
||||
while (s_recvCtx.bufferItem[i].flag != 0 && count < 5) {
|
||||
count++;
|
||||
OsdkOsal_TaskSleepMs(4);
|
||||
}
|
||||
if (count == 5) {
|
||||
index++;
|
||||
MOP_ENTRY_LOGE("can't get buffer to write data, length %d", cmdInfo->dataLen);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (cmdInfo->dataLen > MOP_RECV_BUFFER_LENGTH) {
|
||||
index++;
|
||||
MOP_ENTRY_LOGE("recv data is too large");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
mop_packet_head_t *head = (mop_packet_head_t *) cmdData;
|
||||
#if 0
|
||||
printf("seq num = %u\n", head->seq_num);
|
||||
printf("trans type = %x\n", head->trans_type);
|
||||
printf("data = %d %d %d\n", head->data[0], head->data[1], head->data[2]);
|
||||
printf("start to memcpy, dataLen = %d, index = %d!\n", cmdInfo->dataLen, index);
|
||||
#endif
|
||||
memcpy(s_recvCtx.bufferItem[i].buffer, cmdData, cmdInfo->dataLen);
|
||||
s_recvCtx.bufferItem[i].length = cmdInfo->dataLen;
|
||||
s_recvCtx.bufferItem[i].flag = 1;
|
||||
s_recvCtx.writeIdx = (i + 1) % MOP_RECV_BUFFER_MAX_NUM;
|
||||
index++;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
static int32_t osdk_check_liveview_usb_connection()
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
osdkStat = OsdkCommand_CheckLiveViewChannel();
|
||||
if (osdkStat == OSDK_STAT_OK) {
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
|
||||
static int32_t osdk_notify_slave()
|
||||
{
|
||||
T_CmdInfo info;
|
||||
T_CmdInfo ackInfo;
|
||||
uint8_t ackData[1024];
|
||||
int result;
|
||||
uint8_t data = 0;
|
||||
|
||||
info.cmdSet = 0x49;
|
||||
info.cmdId = 0x30;
|
||||
info.dataLen = 1;
|
||||
info.needAck = OSDK_COMMAND_NEED_ACK_FINISH_ACK;
|
||||
info.packetType = OSDK_COMMAND_PACKET_TYPE_REQUEST;
|
||||
info.addr = GEN_ADDR(0, ADDR_V1_COMMAND_INDEX);
|
||||
info.encType = 0;
|
||||
info.sender = 0xca;
|
||||
info.receiver = 0x07;
|
||||
result = OsdkCommand_SendSync(OsdkCommand_GetInstance(), &info, &data,
|
||||
&ackInfo, ackData, 2000, 3);
|
||||
|
||||
if (result != OSDK_STAT_OK) {
|
||||
if (result == OSDK_STAT_ERR_TIMEOUT) {
|
||||
MOP_ENTRY_LOGE("timeout, no ack receive!\n");
|
||||
}
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t send_bulk_data(void *plink, void *buf, uint16_t length, uint8_t immediate)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
T_CmdInfo sendInfo;
|
||||
int ret = 0;
|
||||
mop_link_layer_node_t *plink_node = NULL;
|
||||
uint32_t data_len = 0;
|
||||
mop_packet_head_t *packet_head;
|
||||
static int err_count = 0;
|
||||
|
||||
if (length > 0) {
|
||||
memcpy((void *) ((uint8_t *) assemble_buf.send_buf + assemble_buf.send_len), buf, length);
|
||||
assemble_buf.send_len += MOP_PACKET_LENGTH;
|
||||
} else if (assemble_buf.send_len == 0) {
|
||||
return length;
|
||||
}
|
||||
|
||||
if ((immediate == 0) && (assemble_buf.send_len <= (ASSEMBLE_LEN - MOP_PACKET_LENGTH))) {
|
||||
return length;
|
||||
}
|
||||
|
||||
//send_buf
|
||||
sendInfo.cmdSet = 0x66;
|
||||
sendInfo.cmdId = 0x01;
|
||||
sendInfo.dataLen = assemble_buf.send_len;
|
||||
sendInfo.needAck = OSDK_COMMAND_NEED_ACK_FINISH_ACK;
|
||||
sendInfo.packetType = OSDK_COMMAND_PACKET_TYPE_REQUEST;
|
||||
sendInfo.addr = GEN_ADDR(0, ADDR_BIGDATA_LIVEVIEW_INDEX);
|
||||
sendInfo.encType = 0;
|
||||
|
||||
MOP_ENTRY_LOGE("start send bulk data, len = %d, err_cnt = %d", assemble_buf.send_len, err_count);
|
||||
osdkStat = OsdkCommand_BigDataSend(&sendInfo, (uint8_t *) assemble_buf.send_buf);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
MOP_ENTRY_LOGE("send bulk data failed");
|
||||
err_count++;
|
||||
}
|
||||
assemble_buf.send_len = 0;
|
||||
memset(assemble_buf.send_buf, 0, ASSEMBLE_LEN);
|
||||
return length;
|
||||
}
|
||||
|
||||
static int32_t recv_bulk_data(void *plink, void *buf, uint16_t plength)
|
||||
{
|
||||
int count = 0, i = 0;
|
||||
static int offset = 0;
|
||||
i = s_recvCtx.readIdx;
|
||||
while (s_recvCtx.bufferItem[i].flag != 1 && count < 50) {
|
||||
count++;
|
||||
OsdkOsal_TaskSleepMs(4);
|
||||
}
|
||||
if (count == 50) {
|
||||
//MOP_ENTRY_LOGE("no data to read"); MOP_ENTRY_LOGE("recv data = %d %d %d %d",
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s_recvCtx.bufferItem[i].length >= plength) {
|
||||
memcpy(buf, s_recvCtx.bufferItem[i].buffer + offset, plength);
|
||||
s_recvCtx.bufferItem[i].length -= plength;
|
||||
offset += plength;
|
||||
} else {
|
||||
memcpy(buf, s_recvCtx.bufferItem[i].buffer + offset, s_recvCtx.bufferItem[i].length);
|
||||
s_recvCtx.bufferItem[i].length = 0;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (s_recvCtx.bufferItem[i].length == 0) {
|
||||
offset = 0;
|
||||
s_recvCtx.bufferItem[i].flag = 0;
|
||||
s_recvCtx.readIdx = (i + 1) % MOP_RECV_BUFFER_MAX_NUM;
|
||||
}
|
||||
|
||||
return plength;
|
||||
}
|
||||
|
||||
static int32_t osdk_create_e1e_slave_connection(mop_link_layer_node_t *plink)
|
||||
{
|
||||
|
||||
int32_t ret = 0;
|
||||
|
||||
//First step: init recv ctx.
|
||||
s_recvCtx.readIdx = 0;
|
||||
s_recvCtx.writeIdx = 0;
|
||||
for (int i = 0; i < MOP_RECV_BUFFER_MAX_NUM; i++) {
|
||||
s_recvCtx.bufferItem[i].flag = 0;
|
||||
s_recvCtx.bufferItem[i].length = 0;
|
||||
s_recvCtx.bufferItem[i].buffer = OsdkOsal_Malloc(MOP_RECV_BUFFER_LENGTH);
|
||||
memset(s_recvCtx.bufferItem[i].buffer, 0, MOP_RECV_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
//Second step: register recv handle func.
|
||||
T_RecvCmdHandle recvCmdHandle;
|
||||
recvCmdHandle.cmdList = s_bulkCmdList;
|
||||
recvCmdHandle.cmdCount = sizeof(s_bulkCmdList) / sizeof(T_RecvCmdItem);
|
||||
recvCmdHandle.protoType = PROTOCOL_USBMC;
|
||||
ret = OsdkCommand_RegRecvCmdHandler(OsdkCommand_GetInstance(), &recvCmdHandle);
|
||||
if (ret != OSDK_STAT_OK) {
|
||||
MOP_ENTRY_LOGE("register cmd handler failed, ret = %d\n", ret);
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t bulk_close(void *plink)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t bulk_get_link_bandwidth(void *plink, uint32_t *bandwidth_limit_bytes)
|
||||
{
|
||||
*bandwidth_limit_bytes = 1000000;
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t init_assemble_buffer()
|
||||
{
|
||||
assemble_buf.send_buf = mop_osal_malloc(ASSEMBLE_LEN);
|
||||
if (assemble_buf.send_buf == NULL) {
|
||||
MOP_ENTRY_LOGE("malloc send assemble buffer failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
assemble_buf.send_len = 0;
|
||||
assemble_buf.recv_buf = mop_osal_malloc(ASSEMBLE_LEN);
|
||||
if (assemble_buf.recv_buf == NULL) {
|
||||
MOP_ENTRY_LOGE("malloc recv assemble buffer failed");
|
||||
mop_osal_free(assemble_buf.send_buf);
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
assemble_buf.recv_len = 0;
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t destroy_assemble_buffer()
|
||||
{
|
||||
mop_osal_free(assemble_buf.send_buf);
|
||||
mop_osal_free(assemble_buf.recv_buf);
|
||||
assemble_buf.send_len = 0;
|
||||
assemble_buf.recv_len = 0;
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_check_hardware_status(void *plink)
|
||||
{
|
||||
|
||||
//First step: check usb connection.
|
||||
int32_t ret = 0;
|
||||
plink = plink;
|
||||
|
||||
ret = osdk_check_liveview_usb_connection();
|
||||
if (MOP_SUCCESS != ret) {
|
||||
MOP_ENTRY_LOGE("connection check failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (osdk_notify_slave() != MOP_SUCCESS) {
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
//@TODO
|
||||
int32_t mop_osdk_deinit()
|
||||
{
|
||||
mop_trans_layer_stop_task();
|
||||
mop_net_layer_stop_task();
|
||||
mop_net_layer_release_resource();
|
||||
mop_trans_layer_release_resource();
|
||||
mop_deinit_buffer();
|
||||
|
||||
//release resources here
|
||||
destroy_assemble_buffer();
|
||||
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osdk_init()
|
||||
{
|
||||
int32_t ret = 0;
|
||||
mop_link_layer_node_t *plink_node_to_slave = (mop_link_layer_node_t *) (0);
|
||||
|
||||
ret = mop_link_layer_node_init(&plink_node_to_slave, MOP_LINK_USBBULK, MOP_DEVICE_ROUTER, 1, MOP_DEVICE_OSDK, 0);
|
||||
if (MOP_SUCCESS != ret) {
|
||||
MOP_ENTRY_LOGE("osdk init link node to slave failed,ret:%d", ret);
|
||||
return NULL;
|
||||
}
|
||||
(plink_node_to_slave->link_layer_ops).send_data = send_bulk_data;
|
||||
(plink_node_to_slave->link_layer_ops).recv_data = recv_bulk_data;
|
||||
(plink_node_to_slave->link_layer_ops).check_hw_status = mop_check_hardware_status;
|
||||
(plink_node_to_slave->link_layer_ops).link_reconnect = osdk_create_e1e_slave_connection;
|
||||
(plink_node_to_slave->link_layer_ops).close = bulk_close;
|
||||
(plink_node_to_slave->link_layer_ops).get_link_bandwidth = bulk_get_link_bandwidth;
|
||||
plink_node_to_slave->route_table = (mop_route_item_t *) o2e1e_slv_route_tab;
|
||||
plink_node_to_slave->table_length = sizeof(o2e1e_slv_route_tab) / sizeof(o2e1e_slv_route_tab[0]);
|
||||
|
||||
init_assemble_buffer();
|
||||
|
||||
ret = mop_init_buffer();
|
||||
if (MOP_SUCCESS != ret) {
|
||||
MOP_ENTRY_LOGE("init buffer failed,ret:%d", ret);
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
|
||||
ret = mop_net_layer_init(MOP_DEVICE_OSDK, 0);
|
||||
if (MOP_SUCCESS != ret) {
|
||||
MOP_ENTRY_LOGE("osdk init net layer failed,ret:%d", ret);
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
|
||||
ret = mop_trans_layer_init();
|
||||
if (ret != MOP_SUCCESS) {
|
||||
MOP_ENTRY_LOGE("trans layer init failed, ret = %d", ret);
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
mop_trans_layer_start();
|
||||
|
||||
mop_link_layer_connect(plink_node_to_slave);
|
||||
|
||||
sleep(1);
|
||||
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
/*************************************************************************
|
||||
> File Name: mop_osal_osdk.c
|
||||
> Author: dafeng.xu
|
||||
> Created Time: Thu 12 Dec 2019 09:06:13 PM CST
|
||||
************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "mop_osal.h"
|
||||
#include "mop_priv.h"
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_platform.h"
|
||||
#include "osdk_msgq.h"
|
||||
#include "time.h"
|
||||
#include "signal.h"
|
||||
|
||||
#define MOP_OSAL_LOGF(format, ...) \
|
||||
MOP_LOGF("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
#define MOP_OSAL_LOGE(format, ...) \
|
||||
MOP_LOGE("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
#define MOP_OSAL_LOGW(format, ...) \
|
||||
MOP_LOGW("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
#define MOP_OSAL_LOGI(format, ...) \
|
||||
MOP_LOGI("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
#define MOP_OSAL_LOGT(format, ...) \
|
||||
MOP_LOGT("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
#define MOP_OSAL_LOGV(format, ...) \
|
||||
MOP_LOGV("MOP_OSAL:" format, ##__VA_ARGS__)
|
||||
|
||||
int32_t mop_osal_task_create(const char *name, void (*start_routine)(void *),
|
||||
void *arg, uint16_t stack_size, mop_osal_task_t *task)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
osdkStat = OsdkOsal_TaskCreate((T_OsdkTaskHandle *)task, start_routine, stack_size, arg);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk task create failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_task_join(mop_osal_task_t task)
|
||||
{
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
|
||||
int32_t mop_osal_task_destroy(mop_osal_task_t task)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
osdkStat = OsdkOsal_TaskDestroy((T_OsdkTaskHandle)task);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk task destroy failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_msgq_create(const char *name, uint32_t length, mop_osal_msgq_t *msgq)
|
||||
{
|
||||
T_msgqAttrib attrib;
|
||||
attrib.name = name;
|
||||
attrib.bufSize = length;
|
||||
E_OsdkStat osdkStat = OsdkMsgq_Create(&attrib, (T_msgQueue **)msgq);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk msgq create failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_msgq_destroy(mop_osal_msgq_t msgq)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkMsgq_Destroy((T_msgQueue *)msgq);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk msgq destroy failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_msgq_send(mop_osal_msgq_t msgq, void *message, uint32_t size, uint32_t timeout_ms)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkMsgq_Send((T_msgQueue *)msgq, message, size, timeout_ms);
|
||||
|
||||
if(osdkStat == OSDK_STAT_OK) {
|
||||
return MOP_SUCCESS;
|
||||
}else if(osdkStat == OSDK_STAT_ERR_TIMEOUT) {
|
||||
return MOP_ERR_TIMEOUT;
|
||||
}else {
|
||||
MOP_OSAL_LOGE("osdk msgq send failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mop_osal_msgq_recv(mop_osal_msgq_t msgq, void *buffer, uint32_t *size, uint32_t timeout_ms)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkMsgq_Recv((T_msgQueue *)msgq, (uint8_t *)buffer, size, timeout_ms);
|
||||
|
||||
if(osdkStat == OSDK_STAT_OK) {
|
||||
return MOP_SUCCESS;
|
||||
}else if(osdkStat == OSDK_STAT_ERR_TIMEOUT) {
|
||||
return MOP_ERR_TIMEOUT;
|
||||
}else if(osdkStat == OSDK_STAT_NOT_READY) {
|
||||
return MOP_ERR_NOTREADY;
|
||||
}else {
|
||||
MOP_OSAL_LOGE("osdk msgq recv failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mop_osal_msgq_get_count(mop_osal_msgq_t msgq, uint32_t *count)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkMsgq_GetCount((T_msgQueue *)msgq, count);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk msgq get count failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_msleep(uint32_t time_ms)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_TaskSleepMs(time_ms);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk msleep failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_get_time_ms(uint32_t *time_ms)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_GetTimeMs(time_ms);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk get time ms failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_sema_create(mop_osal_sema_t *sema, uint32_t init_cnt)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_SemaphoreCreate((T_OsdkSemHandle *)sema, init_cnt);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk sema create failed");
|
||||
return MOP_ERR_TIMEOUT;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_sema_destroy(mop_osal_sema_t sema)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_SemaphoreDestroy((T_OsdkSemHandle)sema);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk sema destroy failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_sema_wait(mop_osal_sema_t sema, uint32_t timeout_ms)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
if(timeout_ms == MOP_WAIT_FOREVER) {
|
||||
osdkStat = OsdkOsal_SemaphoreWait((T_OsdkSemHandle)sema);
|
||||
} else {
|
||||
osdkStat = OsdkOsal_SemaphoreTimedWait((T_OsdkSemHandle)sema, timeout_ms);
|
||||
}
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk sema timed wait failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_sema_post(mop_osal_sema_t sema)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_SemaphorePost((T_OsdkSemHandle)sema);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk sema post failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_mutex_create(mop_osal_mutex_t *mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_MutexCreate((T_OsdkMutexHandle *)mutex);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk mutex create failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_mutex_lock(mop_osal_mutex_t mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_MutexLock((T_OsdkMutexHandle)mutex);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk mutex lock failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_mutex_unlock(mop_osal_mutex_t mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_MutexUnlock((T_OsdkMutexHandle)mutex);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk mutex unlock failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_mutex_destroy(mop_osal_mutex_t mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat = OsdkOsal_MutexDestroy((T_OsdkMutexHandle)mutex);
|
||||
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
MOP_OSAL_LOGE("osdk mutex destroy failed");
|
||||
return MOP_ERR_FAILED;
|
||||
}
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
void *mop_osal_malloc(uint32_t size)
|
||||
{
|
||||
return OsdkOsal_Malloc(size);
|
||||
}
|
||||
|
||||
void mop_osal_free(void* ptr)
|
||||
{
|
||||
return OsdkOsal_Free(ptr);
|
||||
}
|
||||
|
||||
int32_t mop_osal_timer_create(void (*timer_entry)(void), uint32_t timeout_ms, mop_osal_timer_t *timer)
|
||||
{
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mop_osal_timer_destroy(mop_osal_timer_t timer)
|
||||
{
|
||||
return MOP_SUCCESS;
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_hal.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_hal.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
static T_OsdkHalUartHandler s_osdkHalUart;
|
||||
#ifdef __linux__
|
||||
static T_OsdkHalUSBBulkHandler s_osdkHalUSBBulk;
|
||||
#endif
|
||||
|
||||
static T_HalOps halOps[] = {
|
||||
{"UART", OsdkHal_UartSendData, OsdkHal_UartReadData, OsdkHal_UartClose},
|
||||
#ifdef __linux__
|
||||
{"USB_BULK", OsdkHal_USBBulkSendData, OsdkHal_USBBulkReadData, OsdkHal_USBBulkClose},
|
||||
#endif
|
||||
};
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkPlatform_RegHalUartHandler(const T_OsdkHalUartHandler *halUartHandler)
|
||||
{
|
||||
if (halUartHandler->UartInit == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUartHandler->UartWriteData == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUartHandler->UartReadData == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUartHandler->UartClose == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
memcpy(&s_osdkHalUart, halUartHandler, sizeof(T_OsdkHalUartHandler));
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uart interface init function.
|
||||
* @param port: uart interface port.
|
||||
* @param baudrate: uart interface baudrate.
|
||||
* @param obj: pointer to the hal object, which is used to store uart interface parameters.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_UartInit(const char *port, const int baudrate, T_HalObj *obj)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUart.UartInit(port, baudrate, obj);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "uart init error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uart interface send function.
|
||||
* @param obj: pointer to the hal object, which including uart interface parameters.
|
||||
* @param pBuf: pointer to the buffer which is used to store send data.
|
||||
* @param bufLen: send data length.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_UartSendData(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUart.UartWriteData(obj, pBuf, bufLen);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "uart write data error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uart interface send function.
|
||||
* @param obj: pointer to the hal object, which including uart interface parameters.
|
||||
* @param pBuf: pointer to the buffer which is used to store receive data.
|
||||
* @param bufLen: receive data length.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_UartReadData(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUart.UartReadData(obj, pBuf, bufLen);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "uart read data error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uart interface close function.
|
||||
* @param obj: pointer to the hal object, which including uart interface parameters.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_UartClose(T_HalObj *obj)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUart.UartClose(obj);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "uart close error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
E_OsdkStat OsdkPlatform_RegHalUSBBulkHandler(const T_OsdkHalUSBBulkHandler *halUSBBulkHandler)
|
||||
{
|
||||
if (halUSBBulkHandler->USBBulkInit == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUSBBulkHandler->USBBulkWriteData == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUSBBulkHandler->USBBulkReadData == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (halUSBBulkHandler->USBBulkClose == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
memcpy(&s_osdkHalUSBBulk, halUSBBulkHandler, sizeof(T_OsdkHalUSBBulkHandler));
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBBulk interface init function.
|
||||
* @param pid: USBBulk product id.
|
||||
* @param vid: USBBulk vendor id.
|
||||
* @param num: USBBulk interface num.
|
||||
* @param epIn: USBBulk input endpoint .
|
||||
* @param epOut: USBBulk output endpoint.
|
||||
* @param obj: pointer to the hal object, which is used to store USBBulk interface parameters.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_USBBulkInit(uint16_t pid, uint16_t vid, uint16_t num, uint16_t epIn, uint16_t epOut, T_HalObj *obj)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUSBBulk.USBBulkInit(pid, vid, num, epIn, epOut, obj);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "USBBulk init error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBBulk interface send function.
|
||||
* @param obj: pointer to the hal object, which including USBBulk interface parameters.
|
||||
* @param pBuf: pointer to the buffer which is used to store send data.
|
||||
* @param bufLen: send data length.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_USBBulkSendData(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUSBBulk.USBBulkWriteData(obj, pBuf, bufLen);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "uart write data error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBBulk interface receive function.
|
||||
* @param obj: pointer to the hal object, which including USBBulk interface parameters.
|
||||
* @param pBuf: pointer to the buffer which is used to store receive data.
|
||||
* @param bufLen: receive data length.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_USBBulkReadData(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUSBBulk.USBBulkReadData(obj, pBuf, bufLen);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "USBBulk read data error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBBulk interface close function.
|
||||
* @param obj: pointer to the hal object, which including USBBulk interface parameters.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_USBBulkClose(T_HalObj *obj)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkHalUSBBulk.USBBulkClose(obj);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "USBBulk close error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @brief Function used to get hal operations.
|
||||
* @param interface: hal interface name.
|
||||
* @param ops: pointer to the hal interface operations.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkHal_GetHalOps(const char *interface, T_HalOps *ops)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < (sizeof(halOps) / sizeof(T_HalOps)); ++i) {
|
||||
if (strcmp(halOps[i].name, interface) == 0) {
|
||||
*ops = halOps[i];
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "can't find related HAL interface");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_hal.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/28
|
||||
* @brief This is the header file for "osdk_hal.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_HAL_H
|
||||
#define OSDK_HAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define HAL_ONCE_READ_LEN 1024
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef E_OsdkStat (*Hal_Send)(
|
||||
const T_HalObj *obj,
|
||||
const uint8_t *pBuf,
|
||||
uint32_t bufLen);
|
||||
|
||||
typedef E_OsdkStat (*Hal_Read)(
|
||||
const T_HalObj *obj,
|
||||
uint8_t *pBuf,
|
||||
uint32_t *bufLen);
|
||||
|
||||
typedef E_OsdkStat (*Hal_Close)(
|
||||
T_HalObj *obj);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
Hal_Send Send;
|
||||
Hal_Read Read;
|
||||
Hal_Close Close;
|
||||
} T_HalOps;
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkHal_UartInit(const char *port, const int baudrate, T_HalObj *obj);
|
||||
E_OsdkStat OsdkHal_UartSendData(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen);
|
||||
E_OsdkStat OsdkHal_UartReadData(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen);
|
||||
E_OsdkStat OsdkHal_UartClose(T_HalObj *obj);
|
||||
#ifdef __linux__
|
||||
E_OsdkStat OsdkHal_USBBulkInit(uint16_t pid, uint16_t vid, uint16_t num, uint16_t epIn, uint16_t epOut, T_HalObj *obj);
|
||||
E_OsdkStat OsdkHal_USBBulkSendData(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen);
|
||||
E_OsdkStat OsdkHal_USBBulkReadData(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen);
|
||||
E_OsdkStat OsdkHal_USBBulkClose(T_HalObj *obj);
|
||||
#endif
|
||||
E_OsdkStat OsdkHal_GetHalOps(const char *interface, T_HalOps *ops);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_HAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,366 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_osal.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_platform.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_OsdkOsalHandler s_osdkPlatformOsal;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkPlatform_RegOsalHandler(const T_OsdkOsalHandler *osalHandler)
|
||||
{
|
||||
if (osalHandler->TaskCreate == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->TaskDestroy == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->TaskSleepMs == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->MutexCreate == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->MutexDestroy == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->MutexLock == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->MutexUnlock == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->SemaphoreCreate == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->SemaphoreDestroy == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->SemaphorePost == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->SemaphoreWait == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->SemaphoreTimedWait == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->GetTimeMs == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->Malloc == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (osalHandler->Free == NULL) {
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
memcpy(&s_osdkPlatformOsal, osalHandler, sizeof(T_OsdkOsalHandler));
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat
|
||||
OsdkOsal_TaskCreate(T_OsdkTaskHandle *task, void *(*taskFunc)(void *), uint32_t stackSize, void *arg)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.TaskCreate(task, taskFunc, stackSize, arg);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "task create error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkOsal_TaskDestroy(T_OsdkTaskHandle task)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.TaskDestroy(task);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "task destroy error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkOsal_TaskSleepMs(uint32_t timeMs)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.TaskSleepMs(timeMs);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "task sleep ms error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the mutex container, initialize the mutex, and
|
||||
* create mutex ID.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_MutexCreate(T_OsdkMutexHandle *mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.MutexCreate(mutex);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "mutex create error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created mutex.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_MutexDestroy(T_OsdkMutexHandle mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.MutexDestroy(mutex);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "mutex destroy error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquire and lock the mutex when peripheral access is required
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_MutexLock(T_OsdkMutexHandle mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.MutexLock(mutex);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "mutex lock error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock and release the mutex, when done with the peripheral access.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_MutexUnlock(T_OsdkMutexHandle mutex)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.MutexUnlock(mutex);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "mutex unlock error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the semaphore container, initialize the semaphore, and
|
||||
* create semaphore ID.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param initValue: initial value of semaphore.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_SemaphoreCreate(T_OsdkSemHandle *semaphore, uint32_t initValue)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.SemaphoreCreate(semaphore, initValue);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "semaphore create error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created semaphore.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_SemaphoreDestroy(T_OsdkSemHandle semaphore)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.SemaphoreDestroy(semaphore);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "semaphore destroy error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_SemaphoreWait(T_OsdkSemHandle semaphore)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.SemaphoreWait(semaphore);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "semaphore wait error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param waitTime: timeout value of waiting semaphore, unit: millisecond.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_SemaphoreTimedWait(T_OsdkSemHandle semaphore, uint32_t waitTime)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.SemaphoreTimedWait(semaphore, waitTime);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "semaphore wait time error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the semaphore token.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_SemaphorePost(T_OsdkSemHandle semaphore)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.SemaphorePost(semaphore);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "semaphore post error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for ms.
|
||||
* @param us: time of system, uint:ms
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
E_OsdkStat OsdkOsal_GetTimeMs(uint32_t *ms)
|
||||
{
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.GetTimeMs(ms);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "get time ms error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for us, os related.
|
||||
* @param us: time of system, uint:us
|
||||
* @return an enum that represents a status of OSDK
|
||||
*/
|
||||
#ifdef OS_DEBUG
|
||||
E_OsdkStat OsdkOsal_GetTimeUs(uint64_t *us) {
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
osdkStat = s_osdkPlatformOsal.GetTimeUs(us);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PLATFORM, "get time ms error, stat:%lld", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *OsdkOsal_Malloc(uint32_t size)
|
||||
{
|
||||
return s_osdkPlatformOsal.Malloc(size);
|
||||
}
|
||||
|
||||
void OsdkOsal_Free(void *ptr)
|
||||
{
|
||||
s_osdkPlatformOsal.Free(ptr);
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_protocol.h"
|
||||
|
||||
/* Private functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private constants --------------------------------------------------------*/
|
||||
const static T_ProtocolOps protocolOps[] = {
|
||||
{PROTOCOL_SDK, OsdkProtocol_sdkInit, OsdkProtocol_sdkDeinit, OsdkProtocol_sdkPack,
|
||||
OsdkProtocol_sdkParse, OsdkProtocol_sdkUnpack,
|
||||
OsdkProtocol_sdkGetLen, OsdkProtocol_setSdkKey},
|
||||
{PROTOCOL_V1, OsdkProtocol_v1Init, OsdkProtocol_v1Deinit, OsdkProtocol_v1Pack,
|
||||
OsdkProtocol_v1Parse, OsdkProtocol_v1Unpack,
|
||||
OsdkProtocol_v1GetLen, NULL},
|
||||
#ifdef __linux__
|
||||
{PROTOCOL_USBMC, OsdkProtocol_usbmcInit, OsdkProtocol_usbmcDeinit,
|
||||
OsdkProtocol_usbmcPack, OsdkProtocol_usbmcParse,
|
||||
OsdkProtocol_usbmcUnpack, OsdkProtocol_usbmcGetLen,
|
||||
NULL}
|
||||
#endif
|
||||
};
|
||||
/* Private types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkProtocol_getProtocolOps(E_ProtocolType type,
|
||||
T_ProtocolOps *ops) {
|
||||
int i;
|
||||
if(!ops) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL,
|
||||
"OsdkProtocol_getProtocolOps param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
for (i = 0; i < (sizeof(protocolOps) / sizeof(T_ProtocolOps)) ; ++i) {
|
||||
if (protocolOps[i].type == type) {
|
||||
*ops = protocolOps[i];
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,502 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_sdk.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_protocol_sdk.h"
|
||||
#include "dji_aes.h"
|
||||
#include "osdk_crc.h"
|
||||
|
||||
/* Private functions definition ---------------------------------------------*/
|
||||
#define _SDK_U32_SET(_addr, _val) (*((uint32_t *)(_addr)) = (_val))
|
||||
|
||||
/* Private constants --------------------------------------------------------*/
|
||||
#define SDK_COMMAND_LENGTH_MAX 1024
|
||||
#define SDK_COMMAND_LENGTH_MIN \
|
||||
(sizeof(T_SdkProtocolHeader) + SDK_COMMAND_CRCDATA_LEN)
|
||||
#define SDK_COMMAND_CRCHEAD_POSITION \
|
||||
(sizeof(T_SdkProtocolHeader) - SDK_COMMAND_CRCHEAD_LEN)
|
||||
#define SDK_COMMAND_CRCDATA_LEN (sizeof(uint32_t))
|
||||
#define SDK_COMMAND_CRCHEAD_LEN (sizeof(uint16_t))
|
||||
#define SDK_COMMAND_SOF 0xAA
|
||||
#define SDK_COMMAND_CMDSET_LEN 2
|
||||
#define SDK_COMMAND_MIN_HEADER_LEN (sizeof(T_SdkProtocolHeader))
|
||||
#define SDK_COMMAND_VERSION 0
|
||||
#define SDK_ACK_SIZE 10
|
||||
|
||||
#define SDK_PROTOCOL_ALIGN (16u)
|
||||
#define SDK_SESSION_START_NUM 2
|
||||
#define SDK_MAX_SESSION_NUM (32 - SDK_SESSION_START_NUM)
|
||||
#define SDK_SESSION_ID_NO_ACK 0
|
||||
#define SDK_SESSION_ID_IS_USE 1
|
||||
#define SDK_SESSION_ID_IS_IDLE 0
|
||||
|
||||
#define SDK_COMMAND_GET_ACK_FRAME_DATAPTR(frame) \
|
||||
((uint8_t *)frame + sizeof(T_SdkProtocolHeader))
|
||||
#define SDK_COMMAND_GET_REQ_FRAME_DATAPTR(frame) \
|
||||
((uint8_t *)frame + sizeof(T_SdkProtocolHeader)) + SDK_COMMAND_CMDSET_LEN
|
||||
#define SDK_COMMAND_GET_FRAME_CRC32(frame) \
|
||||
((uint8_t *)frame + ((T_SdkProtocolHeader *)frame)->length - \
|
||||
SDK_COMMAND_CRCDATA_LEN)
|
||||
|
||||
/* Private types ------------------------------------------------------------*/
|
||||
// ack code define
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct {
|
||||
uint32_t sof : 8;
|
||||
uint32_t length : 10;
|
||||
uint32_t version : 6;
|
||||
uint32_t sessionId : 5;
|
||||
uint32_t isAck : 1;
|
||||
uint32_t reserved0 : 2; // always 0
|
||||
uint32_t padding : 5;
|
||||
uint32_t enc : 3;
|
||||
uint32_t reserved1 : 24;
|
||||
uint32_t seqNum : 16;
|
||||
uint32_t crc : 16;
|
||||
} T_SdkProtocolHeader;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sof : 8;
|
||||
uint32_t length : 10;
|
||||
uint32_t version : 6;
|
||||
uint32_t sessionId : 5;
|
||||
uint32_t isAck : 1;
|
||||
uint32_t reserved0 : 2; // always 0
|
||||
uint32_t padding : 5;
|
||||
uint32_t enc : 3;
|
||||
uint32_t reserved1 : 24;
|
||||
uint32_t seqNum : 16;
|
||||
uint32_t crc : 16;
|
||||
uint8_t cmdSet;
|
||||
uint8_t cmdId;
|
||||
uint8_t pData[1];
|
||||
} T_SdkProtocolAll;
|
||||
|
||||
typedef struct {
|
||||
uint8_t sessionId;
|
||||
uint8_t flag;
|
||||
uint8_t cmdSet;
|
||||
uint8_t cmdId;
|
||||
uint16_t seqNum;
|
||||
} T_sdkSessionCtx;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
typedef struct {
|
||||
uint8_t sdkKey[32];
|
||||
uint8_t encode;
|
||||
} SDKFilter;
|
||||
|
||||
static SDKFilter s_sdkFilter = {0};
|
||||
|
||||
static void OsdkProtocol_sdkEncodeData(T_SdkProtocolHeader *pHeader,
|
||||
ptr_aes256_codec codecFunc);
|
||||
static void OsdkProtocol_sdkCalculateCRC(void *pFrame);
|
||||
static E_OsdkStat OsdkProtocol_sdkGetSessionId(void *protocolExtData,
|
||||
uint8_t *sessionId,
|
||||
uint16_t seqNum, uint8_t cmdSet,
|
||||
uint8_t cmdId);
|
||||
static E_OsdkStat OsdkProtocol_sdkFindSessionId(void *protocolExtData,
|
||||
uint8_t sessionId,
|
||||
uint16_t seqNum,
|
||||
uint8_t *cmdSet,
|
||||
uint8_t *cmdId);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
E_OsdkStat OsdkProtocol_setSdkKey(const char *key) {
|
||||
int i;
|
||||
char temp_area[3];
|
||||
uint32_t temp8;
|
||||
temp_area[0] = temp_area[1] = temp_area[2] = 0;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
temp_area[0] = key[0];
|
||||
temp_area[1] = key[1];
|
||||
sscanf(temp_area, "%x", &temp8);
|
||||
s_sdkFilter.sdkKey[i] = temp8;
|
||||
key += 2;
|
||||
}
|
||||
s_sdkFilter.encode = 1;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkInit(void **pProtocolExtData) {
|
||||
T_sdkSessionCtx *sessionData;
|
||||
int i = 0;
|
||||
|
||||
if(!pProtocolExtData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_sdkInit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
*pProtocolExtData =
|
||||
OsdkOsal_Malloc(sizeof(T_sdkSessionCtx) * SDK_MAX_SESSION_NUM);
|
||||
if (*pProtocolExtData == NULL) {
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
|
||||
sessionData = (T_sdkSessionCtx *)(*pProtocolExtData);
|
||||
|
||||
for (i = 0; i < SDK_MAX_SESSION_NUM; i++) {
|
||||
sessionData[i].sessionId = (i + SDK_SESSION_START_NUM);
|
||||
sessionData[i].seqNum = 0;
|
||||
sessionData[i].cmdSet = 0xFF;
|
||||
sessionData[i].cmdId = 0xFF;
|
||||
sessionData[i].flag = SDK_SESSION_ID_IS_IDLE;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkDeinit(void *pProtocolExtData) {
|
||||
|
||||
if(!pProtocolExtData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_sdkDeinit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
OsdkOsal_Free(pProtocolExtData);
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkPack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData) {
|
||||
E_OsdkStat osdkStat = OSDK_STAT_OK;
|
||||
T_SdkProtocolHeader *pHeader = (T_SdkProtocolHeader *)pFrame;
|
||||
T_SdkProtocolAll *pAll = (T_SdkProtocolAll *)pFrame;
|
||||
uint32_t frameLen;
|
||||
uint32_t frameDataLen;
|
||||
uint8_t padding = 0;
|
||||
uint8_t sessionId = 0;
|
||||
|
||||
if(!protocolExtData || !pFrame || !len || !pInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_sdkPack param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
frameDataLen = pInfo->dataLen;
|
||||
if (frameDataLen + sizeof(T_SdkProtocolHeader) + sizeof(uint32_t) >
|
||||
SDK_COMMAND_LENGTH_MAX) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "frame length error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if ((pInfo->encType) && (frameDataLen > 0)) {
|
||||
padding = 16 - (frameDataLen % SDK_PROTOCOL_ALIGN);
|
||||
frameDataLen += padding;
|
||||
}
|
||||
frameLen = frameDataLen + sizeof(T_SdkProtocolHeader);
|
||||
|
||||
if (pInfo->packetType) {
|
||||
if (frameDataLen) {
|
||||
frameLen += SDK_COMMAND_CRCDATA_LEN;
|
||||
}
|
||||
memcpy((pFrame + sizeof(T_SdkProtocolHeader)), cmdData, pInfo->dataLen);
|
||||
} else {
|
||||
frameLen += SDK_COMMAND_CMDSET_LEN;
|
||||
if (frameDataLen) {
|
||||
frameLen += SDK_COMMAND_CRCDATA_LEN;
|
||||
}
|
||||
|
||||
pAll->cmdSet = (uint8_t)(pInfo->cmdSet & 0xff);
|
||||
pAll->cmdId = (uint8_t)(pInfo->cmdId & 0xff);
|
||||
memcpy(pAll->pData, cmdData, pInfo->dataLen);
|
||||
}
|
||||
|
||||
if (pInfo->needAck) {
|
||||
osdkStat =
|
||||
OsdkProtocol_sdkGetSessionId(protocolExtData, &sessionId, pInfo->seqNum,
|
||||
pInfo->cmdSet, pInfo->cmdId);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "get session id error");
|
||||
return osdkStat;
|
||||
}
|
||||
pHeader->sessionId = sessionId;
|
||||
} else {
|
||||
pHeader->sessionId = SDK_SESSION_ID_NO_ACK;
|
||||
}
|
||||
pHeader->sof = SDK_COMMAND_SOF;
|
||||
pHeader->length = frameLen;
|
||||
pHeader->version = SDK_COMMAND_VERSION;
|
||||
if (pInfo->packetType)
|
||||
pHeader->isAck = 1;
|
||||
else
|
||||
pHeader->isAck = 0;
|
||||
pHeader->enc = pInfo->encType;
|
||||
pHeader->seqNum = pInfo->seqNum;
|
||||
pHeader->padding = padding;
|
||||
pHeader->reserved0 = 0;
|
||||
*len = frameLen;
|
||||
if (pHeader->enc && s_sdkFilter.encode) {
|
||||
OsdkProtocol_sdkEncodeData(pHeader, aes256_encrypt_ecb);
|
||||
} else if (pHeader->enc) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "app key not set");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
OsdkProtocol_sdkCalculateCRC(pFrame);
|
||||
|
||||
OSDK_LOG_DEBUG(
|
||||
MODULE_NAME_PROTOCOL,
|
||||
"Pack - sender:0x%02X receiver:0x%02X cmdset:0x%02X cmdid:0x%02X",
|
||||
pInfo->sender, pInfo->receiver, pInfo->cmdSet, pInfo->cmdId);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkGetLen(char *buffer, uint32_t *length) {
|
||||
T_SdkProtocolHeader *pHeader = (T_SdkProtocolHeader *)buffer;
|
||||
*length = pHeader->length;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkParse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen) {
|
||||
uint32_t frameLen;
|
||||
uint32_t frameVer;
|
||||
|
||||
if(!protParse || !pParseFrame || !parseLen) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_sdkParse param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == 0) {
|
||||
if (byte != SDK_COMMAND_SOF) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
protParse->parseBuff[protParse->parseIndex] = byte;
|
||||
protParse->parseIndex++;
|
||||
|
||||
if (protParse->parseIndex >= 3) {
|
||||
frameLen = ((T_SdkProtocolHeader *)(protParse->parseBuff))->length;
|
||||
frameVer = ((T_SdkProtocolHeader *)(protParse->parseBuff))->version;
|
||||
|
||||
if (frameLen < SDK_COMMAND_LENGTH_MIN ||
|
||||
frameLen > SDK_COMMAND_LENGTH_MAX || frameVer != SDK_COMMAND_VERSION) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame length error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == SDK_COMMAND_MIN_HEADER_LEN) {
|
||||
uint16_t calCrc16;
|
||||
calCrc16 = OsdkCrc_ibmCrc16Calc(protParse->parseBuff,
|
||||
SDK_COMMAND_MIN_HEADER_LEN - SDK_COMMAND_CRCHEAD_LEN);
|
||||
if (((T_SdkProtocolHeader *)(protParse->parseBuff))->crc != calCrc16) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame crc16 error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == frameLen) {
|
||||
uint32_t calCrc32;
|
||||
calCrc32 = OsdkCrc_crc32Calc(protParse->parseBuff,
|
||||
(frameLen - SDK_COMMAND_CRCDATA_LEN));
|
||||
if (*(uint32_t *)SDK_COMMAND_GET_FRAME_CRC32(protParse->parseBuff) !=
|
||||
calCrc32) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame crc32 error");
|
||||
return OSDK_STAT_ERR;
|
||||
} else {
|
||||
*pParseFrame = protParse->parseBuff;
|
||||
protParse->parseIndex = 0;
|
||||
*parseLen = frameLen;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (protParse->parseIndex > frameLen) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame length error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_sdkUnpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData) {
|
||||
|
||||
if(!protocolExtData || !pFrame || !pInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_sdkUnpack param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
T_SdkProtocolHeader *pHeader = (T_SdkProtocolHeader *)pFrame;
|
||||
if (pHeader->enc) OsdkProtocol_sdkEncodeData(pHeader, aes256_decrypt_ecb);
|
||||
uint32_t frameDataLen = pHeader->length - SDK_COMMAND_LENGTH_MIN;
|
||||
pInfo->packetType = pHeader->isAck;
|
||||
pInfo->encType = pHeader->enc;
|
||||
pInfo->protoType = PROTOCOL_SDK;
|
||||
pInfo->seqNum = pHeader->seqNum;
|
||||
pInfo->sessionId = pHeader->sessionId;
|
||||
pInfo->dataLen = frameDataLen;
|
||||
pInfo->sender = 0;
|
||||
pInfo->receiver = 0;
|
||||
|
||||
if (pHeader->isAck) {
|
||||
if (OsdkProtocol_sdkFindSessionId(protocolExtData, pInfo->sessionId,
|
||||
pInfo->seqNum, &pInfo->cmdSet,
|
||||
&pInfo->cmdId) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL,
|
||||
"Unpack error:unknown ack session id");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (frameDataLen != 0) {
|
||||
memcpy(cmdData, SDK_COMMAND_GET_ACK_FRAME_DATAPTR(pFrame), frameDataLen);
|
||||
}
|
||||
} else {
|
||||
T_SdkProtocolAll *pAll = (T_SdkProtocolAll *)pFrame;
|
||||
pInfo->cmdSet = pAll->cmdSet;
|
||||
pInfo->cmdId = pAll->cmdId;
|
||||
if (frameDataLen != 0) {
|
||||
memcpy(cmdData, SDK_COMMAND_GET_REQ_FRAME_DATAPTR(pFrame), frameDataLen);
|
||||
}
|
||||
}
|
||||
|
||||
OSDK_LOG_DEBUG(
|
||||
MODULE_NAME_PROTOCOL,
|
||||
"Unpack - sender:0x%02X receiver:0x%02X cmdset:0x%02X cmdid:0x%02X",
|
||||
pInfo->sender, pInfo->receiver, pInfo->cmdSet, pInfo->cmdId);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
static void OsdkProtocol_sdkEncodeData(T_SdkProtocolHeader *pHeader,
|
||||
ptr_aes256_codec codecFunc) {
|
||||
aes256_context ctx;
|
||||
uint32_t buf_i;
|
||||
uint32_t loop_blk;
|
||||
uint32_t data_len;
|
||||
uint32_t data_idx;
|
||||
uint8_t *data_ptr;
|
||||
|
||||
if (pHeader->enc == 0) return;
|
||||
if (pHeader->length <= SDK_COMMAND_LENGTH_MIN) return;
|
||||
|
||||
data_ptr = (uint8_t *)pHeader + sizeof(T_SdkProtocolHeader);
|
||||
data_len = pHeader->length - SDK_COMMAND_LENGTH_MIN;
|
||||
|
||||
loop_blk = data_len / 16;
|
||||
data_idx = 0;
|
||||
|
||||
aes256_init(&ctx, s_sdkFilter.sdkKey);
|
||||
for (buf_i = 0; buf_i < loop_blk; buf_i++) {
|
||||
codecFunc(&ctx, data_ptr + data_idx);
|
||||
data_idx += 16;
|
||||
}
|
||||
aes256_done(&ctx);
|
||||
|
||||
if (codecFunc == aes256_decrypt_ecb)
|
||||
pHeader->length =
|
||||
pHeader->length - pHeader->padding; // minus padding length;
|
||||
}
|
||||
|
||||
static void OsdkProtocol_sdkCalculateCRC(void *pFrame) {
|
||||
T_SdkProtocolHeader *pHeader = (T_SdkProtocolHeader *)pFrame;
|
||||
uint8_t *pData = (uint8_t *)pFrame;
|
||||
uint32_t crc32Index;
|
||||
|
||||
if (pHeader->sof != SDK_COMMAND_SOF) return;
|
||||
if (pHeader->version != SDK_COMMAND_VERSION) return;
|
||||
if (pHeader->length > sizeof(T_SdkProtocolHeader) &&
|
||||
pHeader->length < SDK_COMMAND_LENGTH_MIN)
|
||||
return;
|
||||
|
||||
pHeader->crc = OsdkCrc_ibmCrc16Calc(pData, SDK_COMMAND_CRCHEAD_POSITION);
|
||||
|
||||
if (pHeader->length >= SDK_COMMAND_LENGTH_MIN) {
|
||||
crc32Index = pHeader->length - SDK_COMMAND_CRCDATA_LEN;
|
||||
_SDK_U32_SET(pData + crc32Index, OsdkCrc_crc32Calc(pData, crc32Index));
|
||||
}
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkProtocol_sdkGetSessionId(void *protocolExtData,
|
||||
uint8_t *sessionId,
|
||||
uint16_t seqNum, uint8_t cmdSet,
|
||||
uint8_t cmdId) {
|
||||
int i = 0;
|
||||
T_sdkSessionCtx *sessionData = (T_sdkSessionCtx *)protocolExtData;
|
||||
for (i = 0; i < SDK_MAX_SESSION_NUM; i++) {
|
||||
if (sessionData[i].flag == SDK_SESSION_ID_IS_USE &&
|
||||
sessionData[i].seqNum == seqNum &&
|
||||
sessionData[i].cmdSet == cmdSet &&
|
||||
sessionData[i].cmdId == cmdId) {
|
||||
*sessionId = sessionData[i].sessionId;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDK_MAX_SESSION_NUM; i++) {
|
||||
if (sessionData[i].flag == SDK_SESSION_ID_IS_IDLE) {
|
||||
sessionData[i].seqNum = seqNum;
|
||||
sessionData[i].cmdSet = cmdSet;
|
||||
sessionData[i].cmdId = cmdId;
|
||||
sessionData[i].flag = SDK_SESSION_ID_IS_USE;
|
||||
*sessionId = sessionData[i].sessionId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == SDK_MAX_SESSION_NUM) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkProtocol_sdkFindSessionId(void *protocolExtData,
|
||||
uint8_t sessionId,
|
||||
uint16_t seqNum,
|
||||
uint8_t *cmdSet,
|
||||
uint8_t *cmdId) {
|
||||
int i = 0;
|
||||
T_sdkSessionCtx *sessionData = (T_sdkSessionCtx *)protocolExtData;
|
||||
|
||||
for (i = 0; i < SDK_MAX_SESSION_NUM; i++) {
|
||||
if (sessionData[i].flag == SDK_SESSION_ID_IS_USE &&
|
||||
sessionData[i].seqNum == seqNum &&
|
||||
sessionData[i].sessionId == sessionId) {
|
||||
*cmdSet = sessionData[i].cmdSet;
|
||||
*cmdId = sessionData[i].cmdId;
|
||||
sessionData[i].flag = SDK_SESSION_ID_IS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == SDK_MAX_SESSION_NUM) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_sdk.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief This is the header file for "osdk_protocol_sdk.c", defining the
|
||||
*structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_PROTOCOL_SDK_H
|
||||
#define OSDK_PROTOCOL_SDK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_protocol_common.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkProtocol_sdkInit(void **pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_sdkDeinit(void *pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_sdkPack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_sdkParse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen);
|
||||
E_OsdkStat OsdkProtocol_sdkUnpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_sdkGetLen(char *buffer, uint32_t *length);
|
||||
E_OsdkStat OsdkProtocol_setSdkKey(const char *key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_PROTOCOL_SDK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF
|
||||
* FILE******/
|
||||
@@ -1,227 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_usbmc.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_protocol_usbmc.h"
|
||||
|
||||
/* Private functions definition ---------------------------------------------*/
|
||||
static E_OsdkStat OsdkProtocol_usbmcGetCmdFromChnId(int channelId, uint8_t *cmdSet, uint8_t *cmdId);
|
||||
static E_OsdkStat OsdkProtocol_usbmcGetChnIdFromCmd(int *channelId, uint8_t cmdSet, uint8_t cmdId);
|
||||
|
||||
/* Private constants --------------------------------------------------------*/
|
||||
#define USBMC_OVFL_MAGIC (0x4F56464C)
|
||||
#define USBMC_NORMAL_MAGIC (0x55055055)
|
||||
|
||||
#define USB_BIG_DATA_MAX_BUF_SIZE (1024*512)
|
||||
|
||||
/* Private types ------------------------------------------------------------*/
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
int channelId;
|
||||
int headerLen;
|
||||
int dataLen;
|
||||
int seqNum;
|
||||
} T_UsbmcProtocolHeader;
|
||||
|
||||
typedef struct {
|
||||
int channelId;
|
||||
uint8_t cmdSet;
|
||||
uint8_t cmdId;
|
||||
} T_UsbmcMapKey;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
const static T_UsbmcMapKey mapTable[] = {{1, 0x24, 0x13},
|
||||
{81, 0x65, 0x54},
|
||||
{82, 0x65, 0x55},
|
||||
{85, 0x65, 0x56},
|
||||
{90, 0x65, 0x57},
|
||||
{322,0x00, 0x27},
|
||||
{257,0x66, 0x01}};
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcInit(void **pProtocolExtData) {
|
||||
if(!pProtocolExtData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcInit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
*pProtocolExtData =
|
||||
OsdkOsal_Malloc(sizeof(T_recvBufferCtx));
|
||||
if (*pProtocolExtData == NULL) {
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
T_recvBufferCtx *bufferCtx = *pProtocolExtData;
|
||||
bufferCtx->buffer = OsdkOsal_Malloc(USB_BIG_DATA_MAX_BUF_SIZE);
|
||||
if (bufferCtx->buffer == NULL) {
|
||||
OsdkOsal_Free(*pProtocolExtData);
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
memset(bufferCtx->buffer, 0, USB_BIG_DATA_MAX_BUF_SIZE);
|
||||
bufferCtx->bufferLen = 0;
|
||||
bufferCtx->useIdx = 0;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcDeinit(void *pProtocolExtData) {
|
||||
if(!pProtocolExtData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcInit param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
T_recvBufferCtx *bufferCtx = (T_recvBufferCtx *)pProtocolExtData;
|
||||
OsdkOsal_Free(bufferCtx->buffer);
|
||||
OsdkOsal_Free(pProtocolExtData);
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcPack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData) {
|
||||
E_OsdkStat osdkStat = OSDK_STAT_OK;
|
||||
T_UsbmcProtocolHeader *pHeader = (T_UsbmcProtocolHeader *)pFrame;
|
||||
pHeader->magic = USBMC_NORMAL_MAGIC;
|
||||
pHeader->headerLen = sizeof(T_UsbmcProtocolHeader);
|
||||
pHeader->seqNum = pInfo->seqNum;
|
||||
pHeader->dataLen = pInfo->dataLen;
|
||||
osdkStat = OsdkProtocol_usbmcGetChnIdFromCmd(&pHeader->channelId, pInfo->cmdSet, pInfo->cmdId);
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcPack failed: unknown cmd set %d, cmd id %d", pInfo->cmdSet, pInfo->cmdId);
|
||||
return osdkStat;
|
||||
}
|
||||
*len = pInfo->dataLen + pHeader->headerLen;
|
||||
memcpy(pFrame + sizeof(T_UsbmcProtocolHeader), cmdData, pInfo->dataLen);
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcGetLen(char *buffer, uint32_t *length) {
|
||||
T_UsbmcProtocolHeader *pHeader = (T_UsbmcProtocolHeader *)buffer;
|
||||
*length = pHeader->headerLen + pHeader->dataLen;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcParse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen) {
|
||||
if(!protParse || !pParseFrame || !parseLen) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_v1Parse param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
if(protParse->parseIndex == 0 && byte != 0x55) {
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
if(protParse->parseIndex == 1 && byte != 0x50) {
|
||||
protParse->parseIndex == 0;
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
protParse->parseBuff[protParse->parseIndex] = byte;
|
||||
protParse->parseIndex++;
|
||||
|
||||
if (protParse->parseIndex < sizeof(T_UsbmcProtocolHeader)) {
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
|
||||
T_UsbmcProtocolHeader *header =
|
||||
(T_UsbmcProtocolHeader *)protParse->parseBuff;
|
||||
if(header->magic != USBMC_NORMAL_MAGIC) {
|
||||
protParse->parseIndex = 0;
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
|
||||
if(protParse->parseIndex == header->headerLen + header->dataLen) {
|
||||
*pParseFrame = protParse->parseBuff;
|
||||
*parseLen = protParse->parseIndex;
|
||||
protParse->parseIndex = 0;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_usbmcUnpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData) {
|
||||
E_OsdkStat osdkStat = OSDK_STAT_OK;
|
||||
if(!pFrame || !pInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcUnpack param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
T_UsbmcProtocolHeader *pHeader = (T_UsbmcProtocolHeader *)pFrame;
|
||||
pInfo->protoType = PROTOCOL_USBMC;
|
||||
pInfo->seqNum = pHeader->seqNum;
|
||||
pInfo->dataLen = pHeader->dataLen;
|
||||
pInfo->sender = pHeader->channelId;
|
||||
pInfo->receiver = 0;
|
||||
if(pHeader->magic == USBMC_OVFL_MAGIC) {
|
||||
pInfo->cmdSet = 0;
|
||||
pInfo->cmdId = 0;
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcUnpack() recv overflow data, channel id: %d", pHeader->channelId);
|
||||
} else {
|
||||
osdkStat = OsdkProtocol_usbmcGetCmdFromChnId(pHeader->channelId, &pInfo->cmdSet, &pInfo->cmdId);
|
||||
if(osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_usbmcUnpack failed: unknown channel id %d", pHeader->channelId);
|
||||
return osdkStat;
|
||||
}
|
||||
}
|
||||
memcpy(cmdData, pFrame + pHeader->headerLen, pHeader->dataLen);
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static E_OsdkStat OsdkProtocol_usbmcGetCmdFromChnId(int channelId, uint8_t *cmdSet, uint8_t *cmdId) {
|
||||
int num = sizeof(mapTable)/sizeof(T_UsbmcMapKey);
|
||||
int i;
|
||||
for(i = 0; i < num; i++) {
|
||||
if(mapTable[i].channelId == channelId) {
|
||||
*cmdSet = mapTable[i].cmdSet;
|
||||
*cmdId = mapTable[i].cmdId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == num) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
static E_OsdkStat OsdkProtocol_usbmcGetChnIdFromCmd(int *channelId, uint8_t cmdSet, uint8_t cmdId) {
|
||||
int num = sizeof(mapTable)/sizeof(T_UsbmcMapKey);
|
||||
int i;
|
||||
for(i = 0; i < num; i++) {
|
||||
if(mapTable[i].cmdSet == cmdSet && mapTable[i].cmdId == cmdId) {
|
||||
*channelId = mapTable[i].channelId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == num) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_usbmc.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief This is the header file for "osdk_protocol_sdk.c", defining the
|
||||
*structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_PROTOCOL_USBMC_H
|
||||
#define OSDK_PROTOCOL_USBMC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_protocol_common.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkProtocol_usbmcInit(void **pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_usbmcDeinit(void *pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_usbmcPack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_usbmcParse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen);
|
||||
E_OsdkStat OsdkProtocol_usbmcUnpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_usbmcGetLen(char *buffer, uint32_t *length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_PROTOCOL_USBMC_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF
|
||||
* FILE******/
|
||||
@@ -1,268 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_v1.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_protocol_v1.h"
|
||||
#include "dji_aes.h"
|
||||
#include "osdk_crc.h"
|
||||
|
||||
/* Private constants --------------------------------------------------------*/
|
||||
|
||||
#define V1_COMMAND_DATA_LENGTH_MAX (1024 - (sizeof(T_V1ProtocolHeader) + 2))
|
||||
#define V1_COMMAND_DEVICE_ID(type, index) (((index) << 5) | (type))
|
||||
|
||||
#define V1_COMMAND_SOF 0x55
|
||||
#define V1_COMMAND_LENGTH_MIN (sizeof(T_V1ProtocolHeader) + 2)
|
||||
#define V1_COMMAND_LENGTH_MAX \
|
||||
(V1_COMMAND_DATA_LENGTH_MAX + sizeof(T_V1ProtocolHeader) + 2)
|
||||
#define V1_COMMAND_DATA_OFFSET (sizeof(T_V1ProtocolHeader))
|
||||
#define V1_COMMAND_MIN_HEADER_LEN 4
|
||||
#define V1_COMMAND_CRCDATA_LEN (sizeof(uint16_t))
|
||||
#define V1_COMMAND_CRCHEAD_LEN (sizeof(uint8_t))
|
||||
|
||||
#define V1_COMMAND_GET_FRAME_LEN(frame) \
|
||||
(((T_V1ProtocolHeader *)frame)->lenAndVer.lv.len)
|
||||
#define V1_COMMAND_GET_FRAME_CRC16(frame) \
|
||||
(((uint8_t *)frame + ((T_V1ProtocolHeader *)frame)->lenAndVer.lv.len - 2))
|
||||
#define V1_COMMAND_GET_FRAME_DATAPTR(frame) (frame + sizeof(T_V1ProtocolHeader))
|
||||
|
||||
#define V1_COMMAND_VERSION 1
|
||||
|
||||
/* Private types ------------------------------------------------------------*/
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t sof;
|
||||
union {
|
||||
struct {
|
||||
uint16_t len : 10;
|
||||
uint16_t ver : 6;
|
||||
} lv;
|
||||
uint16_t infoData;
|
||||
} lenAndVer;
|
||||
uint8_t headCheckCrc8;
|
||||
union {
|
||||
struct {
|
||||
uint8_t type : 5;
|
||||
uint8_t index : 3;
|
||||
} id;
|
||||
uint8_t infoData;
|
||||
} sender;
|
||||
union {
|
||||
struct {
|
||||
uint8_t type : 5;
|
||||
uint8_t index : 3;
|
||||
} id;
|
||||
uint8_t infoData;
|
||||
} receiver;
|
||||
uint16_t seqNum;
|
||||
union {
|
||||
struct {
|
||||
uint8_t encrypt : 4; /*!< @ref v1protocol_encrypt*/
|
||||
uint8_t reserve : 1;
|
||||
uint8_t needAck : 2; /*!< @ref v1protocol_needAck*/
|
||||
uint8_t packetType : 1; /*!< @ref v1protocol_packetType */
|
||||
} cmdType;
|
||||
uint8_t infoData;
|
||||
} cmdType;
|
||||
uint8_t cmdSet; /*!< @ref v1protocol_CmdSet */
|
||||
uint8_t cmdId;
|
||||
} T_V1ProtocolHeader;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkProtocol_v1Init(void **pProtocolExtData) {
|
||||
*pProtocolExtData = NULL;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_v1Deinit(void *pProtocolExtData) {
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
|
||||
E_OsdkStat OsdkProtocol_v1Pack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData) {
|
||||
T_V1ProtocolHeader *pHeader = (T_V1ProtocolHeader *)pFrame;
|
||||
uint32_t frameLen;
|
||||
uint32_t frameDataLen;
|
||||
|
||||
if(!pFrame || !len || !pInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_v1Pack param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
frameDataLen = pInfo->dataLen;
|
||||
frameLen = frameDataLen + V1_COMMAND_LENGTH_MIN;
|
||||
*len = frameLen;
|
||||
|
||||
pHeader->sof = V1_COMMAND_SOF;
|
||||
pHeader->lenAndVer.lv.len = (uint16_t)frameLen;
|
||||
pHeader->lenAndVer.lv.ver = V1_COMMAND_VERSION;
|
||||
pHeader->headCheckCrc8 = OsdkCrc_crc8Calc(
|
||||
pFrame, (V1_COMMAND_MIN_HEADER_LEN - V1_COMMAND_CRCHEAD_LEN));
|
||||
pHeader->cmdType.cmdType.needAck = pInfo->needAck;
|
||||
pHeader->cmdType.cmdType.packetType = pInfo->packetType;
|
||||
pHeader->cmdType.cmdType.encrypt = pInfo->encType;
|
||||
pHeader->cmdSet = pInfo->cmdSet;
|
||||
pHeader->cmdId = pInfo->cmdId;
|
||||
pHeader->seqNum = pInfo->seqNum;
|
||||
pHeader->sender.infoData = pInfo->sender;
|
||||
|
||||
pHeader->receiver.infoData = pInfo->receiver;
|
||||
|
||||
OSDK_LOG_DEBUG(
|
||||
MODULE_NAME_PROTOCOL,
|
||||
"PACK - sender:0x%02X receiver:0x%02X cmdset:0x%02X cmdid:0x%02X",
|
||||
pInfo->sender, pInfo->receiver, pInfo->cmdSet, pInfo->cmdId);
|
||||
|
||||
memcpy(&pFrame[sizeof(T_V1ProtocolHeader)], cmdData, frameDataLen);
|
||||
|
||||
uint16_t crc16 = OsdkCrc_ccittCrc16Calc(
|
||||
pFrame, (uint16_t)(pHeader->lenAndVer.lv.len - V1_COMMAND_CRCDATA_LEN));
|
||||
memcpy(&pFrame[pHeader->lenAndVer.lv.len - V1_COMMAND_CRCDATA_LEN],
|
||||
(uint8_t *)&crc16, V1_COMMAND_CRCDATA_LEN);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_v1Parse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen) {
|
||||
uint32_t frameLen;
|
||||
uint32_t frameVer;
|
||||
|
||||
if(!protParse || !pParseFrame || !parseLen) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_v1Parse param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == 0) {
|
||||
if (byte != V1_COMMAND_SOF) {
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
protParse->parseBuff[protParse->parseIndex] = byte;
|
||||
protParse->parseIndex++;
|
||||
|
||||
if (protParse->parseIndex >= 3) {
|
||||
frameLen = ((T_V1ProtocolHeader *)(protParse->parseBuff))->lenAndVer.lv.len;
|
||||
frameVer = ((T_V1ProtocolHeader *)(protParse->parseBuff))->lenAndVer.lv.ver;
|
||||
|
||||
if (frameLen < V1_COMMAND_LENGTH_MIN || frameLen > V1_COMMAND_LENGTH_MAX ||
|
||||
frameVer != V1_COMMAND_VERSION) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame length error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == V1_COMMAND_MIN_HEADER_LEN) {
|
||||
uint16_t calCrc8;
|
||||
calCrc8 =
|
||||
OsdkCrc_crc8Calc(protParse->parseBuff,
|
||||
V1_COMMAND_MIN_HEADER_LEN - V1_COMMAND_CRCHEAD_LEN);
|
||||
if (((T_V1ProtocolHeader *)(protParse->parseBuff))->headCheckCrc8 !=
|
||||
calCrc8) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame crc8 error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (protParse->parseIndex == frameLen) {
|
||||
uint32_t calCrc16;
|
||||
calCrc16 = OsdkCrc_ccittCrc16Calc(protParse->parseBuff,
|
||||
(size_t)(frameLen - V1_COMMAND_CRCDATA_LEN));
|
||||
if (*(uint16_t *)V1_COMMAND_GET_FRAME_CRC16(protParse->parseBuff) !=
|
||||
calCrc16) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame crc16 error");
|
||||
return OSDK_STAT_ERR;
|
||||
} else {
|
||||
*pParseFrame = protParse->parseBuff;
|
||||
protParse->parseIndex = 0;
|
||||
*parseLen = frameLen;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (protParse->parseIndex > frameLen) {
|
||||
protParse->parseIndex = 0;
|
||||
OSDK_LOG_WARN(MODULE_NAME_PROTOCOL, "protocol frame length error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
return OSDK_STAT_NOT_READY;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_v1Unpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData) {
|
||||
if(!pFrame || !pInfo || !cmdData) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_PROTOCOL, "OsdkProtocol_v1Unpack param check failed");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
T_V1ProtocolHeader *pHeader = (T_V1ProtocolHeader *)pFrame;
|
||||
uint32_t frameDataLen = pHeader->lenAndVer.lv.len -
|
||||
sizeof(T_V1ProtocolHeader) - V1_COMMAND_CRCDATA_LEN;
|
||||
pInfo->packetType = pHeader->cmdType.cmdType.packetType;
|
||||
pInfo->needAck = pHeader->cmdType.cmdType.needAck;
|
||||
pInfo->encType = pHeader->cmdType.cmdType.encrypt;
|
||||
pInfo->protoType = PROTOCOL_V1;
|
||||
pInfo->seqNum = pHeader->seqNum;
|
||||
|
||||
pInfo->sender = pHeader->sender.infoData;
|
||||
pInfo->receiver = pHeader->receiver.infoData;
|
||||
pInfo->cmdSet = pHeader->cmdSet;
|
||||
pInfo->cmdId = pHeader->cmdId;
|
||||
pInfo->dataLen = frameDataLen;
|
||||
pInfo->sessionId = 0xff;
|
||||
|
||||
if (frameDataLen != 0) {
|
||||
memcpy(cmdData, V1_COMMAND_GET_FRAME_DATAPTR(pFrame), pInfo->dataLen);
|
||||
}
|
||||
|
||||
OSDK_LOG_DEBUG(
|
||||
MODULE_NAME_PROTOCOL,
|
||||
"Unpack - sender:0x%02X receiver:0x%02X cmdset:0x%02X cmdid:0x%02X",
|
||||
pInfo->sender, pInfo->receiver, pInfo->cmdSet, pInfo->cmdId);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkProtocol_v1GetLen(char *buffer, uint32_t *length) {
|
||||
T_V1ProtocolHeader *pHeader = (T_V1ProtocolHeader *)buffer;
|
||||
*length = pHeader->lenAndVer.lv.len;
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_protocol_v1.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief This is the header file for "osdk_protocol_v1.c", defining the
|
||||
*structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_PROTOCOL_V1_H
|
||||
#define OSDK_PROTOCOL_V1_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_protocol_common.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkProtocol_v1Init(void **pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_v1Deinit(void *pProtocolExtData);
|
||||
E_OsdkStat OsdkProtocol_v1Pack(void *protocolExtData, uint8_t *pFrame,
|
||||
uint32_t *len, const T_CmdInfo *pInfo,
|
||||
const uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_v1Parse(T_CmdParse *protParse, uint8_t byte,
|
||||
uint8_t **pParseFrame, uint32_t *parseLen);
|
||||
E_OsdkStat OsdkProtocol_v1Unpack(void *protocolExtData, uint8_t *pFrame,
|
||||
T_CmdInfo *pInfo, uint8_t *cmdData);
|
||||
E_OsdkStat OsdkProtocol_v1GetLen(char *buffer, uint32_t *length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_PROTOCOL_V1_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF
|
||||
* FILE******/
|
||||
@@ -1,90 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_root_task.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_root_task.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
#include "osdk_osal.h"
|
||||
#include "osdk_util.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define OSDK_ROOT_TASK_FREQ_HZ (1000)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static void *OsdkCore_RootTask(void *arg);
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static T_OsdkTaskHandle s_osdkRootThread;
|
||||
static T_OsdkWork s_workList;
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_OsdkWork *OsdkCore_GetWorkInstance(void) { return &s_workList; }
|
||||
|
||||
uint16_t OsdkCore_GetRootTaskFreq(void) { return OSDK_ROOT_TASK_FREQ_HZ; }
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
E_OsdkStat OsdkCore_RootTaskInit(void) {
|
||||
E_OsdkStat osdkStat;
|
||||
s_workList.name = "root_task_list";
|
||||
osdkStat = OsdkWork_Init(&s_workList);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CORE, "osdk work list init error:%d", osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
osdkStat = OsdkOsal_TaskCreate(&s_osdkRootThread, OsdkCore_RootTask,
|
||||
OSDK_TASK_STACK_SIZE_DEFAULT, NULL);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_CORE, "core root task create error:%d",
|
||||
osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkCore_RootTaskDeInit(void) {
|
||||
return OsdkOsal_TaskDestroy(s_osdkRootThread);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||
|
||||
static void *OsdkCore_RootTask(void *arg) {
|
||||
OSDK_UTIL_UNUSED(arg);
|
||||
|
||||
while (1) {
|
||||
OsdkOsal_TaskSleepMs(1000 / OSDK_ROOT_TASK_FREQ_HZ);
|
||||
OsdkWork_CallWorkList(&s_workList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,56 +0,0 @@
|
||||
/** @file dji_aes.hpp
|
||||
* @version 3.3
|
||||
* @date April 12th, 2017
|
||||
*
|
||||
* @Copyright (c) 2016-2017 DJI
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ONBOARDSDK_AES256_H
|
||||
#define ONBOARDSDK_AES256_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct tagAES256Context {
|
||||
uint8_t key[32];
|
||||
uint8_t enckey[32];
|
||||
uint8_t deckey[32];
|
||||
} aes256_context;
|
||||
|
||||
typedef void (*ptr_aes256_codec)(aes256_context* ctx, uint8_t* buf);
|
||||
|
||||
uint8_t rj_xtime(uint8_t x);
|
||||
void aes_subBytes(uint8_t* buf);
|
||||
void aes_subBytes_inv(uint8_t* buf);
|
||||
void aes_addRoundKey(uint8_t* buf, uint8_t* key);
|
||||
void aes_addRoundKey_cpy(uint8_t* buf, uint8_t* key, uint8_t* cpk);
|
||||
void aes_shiftRows(uint8_t* buf);
|
||||
void aes_shiftRows_inv(uint8_t* buf);
|
||||
void aes_mixColumns(uint8_t* buf);
|
||||
void aes_mixColumns_inv(uint8_t* buf);
|
||||
void aes_expandEncKey(uint8_t* k, uint8_t* rc);
|
||||
void aes_expandDecKey(uint8_t* k, uint8_t* rc);
|
||||
void aes256_init(aes256_context* ctx, uint8_t* k);
|
||||
void aes256_done(aes256_context* ctx);
|
||||
void aes256_encrypt_ecb(aes256_context* ctx, uint8_t* buf);
|
||||
void aes256_decrypt_ecb(aes256_context* ctx, uint8_t* buf);
|
||||
|
||||
#endif // ONBOARDSDK_AES256_H
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_buffer.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/9/15
|
||||
* @brief This is the header file for "osdk_buffer.c", defining the structure
|
||||
*and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2017-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 OSDK_BUFFER_H
|
||||
#define OSDK_BUFFER_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_osal.h"
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
uint8_t *bufferPointer;
|
||||
uint16_t bufferSize;
|
||||
uint16_t readIndex;
|
||||
uint16_t writeIndex;
|
||||
} T_OsdkBuffer;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkBuffer_Init(T_OsdkBuffer *buffer, uint8_t *space, uint16_t size);
|
||||
E_OsdkStat OsdkBuffer_DeInit(T_OsdkBuffer *buffer);
|
||||
E_OsdkStat OsdkBuffer_PutToBack(T_OsdkBuffer *buffer, const uint8_t *data,
|
||||
uint16_t len, uint16_t *realPutLen);
|
||||
E_OsdkStat OsdkBuffer_PutToFront(T_OsdkBuffer *buffer, const uint8_t *data,
|
||||
uint16_t len, uint16_t *realPutLen);
|
||||
E_OsdkStat OsdkBuffer_GetFromFront(T_OsdkBuffer *buffer, uint8_t *data,
|
||||
uint16_t len, uint16_t *realGetLen);
|
||||
E_OsdkStat OsdkBuffer_GetUnusedSize(T_OsdkBuffer *buffer, uint16_t *unusedSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_BUFFER_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_crc.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief This is the header file for "osdk_crc.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_CRC_H
|
||||
#define OSDK_CRC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
uint8_t OsdkCrc_crc8Calc(const uint8_t* pMsg, size_t nLen);
|
||||
uint16_t OsdkCrc_ccittCrc16Calc(const uint8_t* pMsg, size_t nLen);
|
||||
uint16_t OsdkCrc_ibmCrc16Calc(const uint8_t* pMsg, size_t nLen);
|
||||
uint32_t OsdkCrc_crc32Calc(const uint8_t* pMsg, size_t nLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_CRC_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,90 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_msgq.h
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/25
|
||||
* @brief This is the header file for "osdk_msgq.c", defining the structure
|
||||
*and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_MSGQ_H
|
||||
#define OSDK_MSGQ_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_logger_internal.h"
|
||||
#include "osdk_module_name.h"
|
||||
#include "osdk_osal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define MSG_MAX_LEN 0x400
|
||||
#ifdef __linux__
|
||||
#define MSGQ_SIZE (MSG_MAX_LEN * 8)
|
||||
#elif STM32
|
||||
#define MSGQ_SIZE (MSG_MAX_LEN * 2)
|
||||
#endif
|
||||
|
||||
#define OSDK_WAIT_ONE_SECOND (uint32_t)(1000)
|
||||
#define OSDK_WAIT_POLLING (uint32_t)(0)
|
||||
#define OSDK_WAIT_FOREVER (uint32_t)(-1)
|
||||
|
||||
#define DATA_SIZE(mq) ((mq->head - mq->tail) & (mq->bufSize - 1))
|
||||
#define FREE_SIZE(mq) (mq->bufSize - 1 - DATA_SIZE(mq))
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
char *name;
|
||||
uint32_t bufSize;
|
||||
} T_msgqAttrib;
|
||||
|
||||
typedef struct {
|
||||
T_msgqAttrib attrib;
|
||||
T_OsdkMutexHandle sendMutex;
|
||||
T_OsdkMutexHandle recvMutex;
|
||||
T_OsdkSemHandle sendSem;
|
||||
T_OsdkSemHandle recvSem;
|
||||
uint32_t currentCount;
|
||||
uint32_t bufSize;
|
||||
uint32_t head;
|
||||
uint32_t tail;
|
||||
uint8_t *buffer;
|
||||
} T_msgQueue;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkMsgq_Create(T_msgqAttrib *attrib, T_msgQueue **msgq);
|
||||
E_OsdkStat OsdkMsgq_Destroy(T_msgQueue *msgq);
|
||||
E_OsdkStat OsdkMsgq_Recv(T_msgQueue *msgq, uint8_t *buffer, uint32_t *size,
|
||||
uint32_t timeout);
|
||||
E_OsdkStat OsdkMsgq_Send(T_msgQueue *msgq, void *message, uint32_t size,
|
||||
uint32_t timeout);
|
||||
E_OsdkStat OsdkMsgq_GetCount(T_msgQueue *msgq, uint32_t *count);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_MSGQ_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF
|
||||
* FILE******/
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_str.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief This is the header file for "osdk_st.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 OSDK_STR_H
|
||||
#define OSDK_STR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
uint8_t *OsdkStr_PutStrToBuf(uint8_t *pBuf, char *str, uint32_t maxStrLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_STR_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_unit.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/2
|
||||
* @brief This is the header file for "osdk_unit.c", defining the structure
|
||||
*and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2017-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 OSDK_UNIT_H
|
||||
#define OSDK_UNIT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_BYTE = 0,
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_BIT,
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_KBYTE,
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_KBIT,
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_MBYTE,
|
||||
OSDK_UNIT_DATA_LENGTH_UNIT_MBIT,
|
||||
} E_OsdkUnitDataLengthUnit;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
E_OsdkStat OsdkUnit_DataLengthUnitConversion(float inDataLength,
|
||||
E_OsdkUnitDataLengthUnit inUnit,
|
||||
float *outDataLength,
|
||||
E_OsdkUnitDataLengthUnit outUnit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_UNIT_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_util.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/2
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2017-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 OSDK_UTIL_H
|
||||
#define OSDK_UTIL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define OSDK_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define OSDK_UTIL_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define OSDK_UTIL_UNUSED(x) ((x) = (x))
|
||||
#define OSDK_UTIL_WORK_RUN(step, workfreq, taskfreq) \
|
||||
(!((step) % (uint32_t)((taskfreq) / (workfreq))))
|
||||
#define OSDK_UTIL_ARRAY_SIZE(array) \
|
||||
((uint32_t)(sizeof(array) / sizeof((array)[0])))
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSDK_UTIL_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
@@ -1,403 +0,0 @@
|
||||
/** @file AES256.cpp
|
||||
* @version 3.3
|
||||
* @date April 12th, 2017
|
||||
*
|
||||
* @Copyright (c) 2016-2017 DJI
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dji_aes.h"
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BEGIN OF AES-256
|
||||
//
|
||||
/*
|
||||
* Byte-oriented AES-256 implementation.
|
||||
* All lookup tables replaced with 'on the fly' calculations.
|
||||
*
|
||||
* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
|
||||
* Other contributors: Hal Finney
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define F(x) (((x) << 1) ^ ((((x) >> 7) & 1) * 0x1b))
|
||||
#define FD(x) (((x) >> 1) ^ (((x)&1) ? 0x8d : 0))
|
||||
|
||||
#define BACK_TO_TABLES
|
||||
#ifdef BACK_TO_TABLES
|
||||
|
||||
const uint8_t sbox[256] = {
|
||||
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
|
||||
0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
||||
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
|
||||
0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
|
||||
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
||||
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
|
||||
0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
|
||||
0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
||||
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
|
||||
0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
|
||||
0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
||||
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
|
||||
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
|
||||
0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
||||
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
|
||||
0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
|
||||
0xb0, 0x54, 0xbb, 0x16};
|
||||
const uint8_t sboxinv[256] = {
|
||||
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
|
||||
0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
||||
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
|
||||
0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
|
||||
0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
||||
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
|
||||
0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
|
||||
0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
||||
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
|
||||
0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
|
||||
0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
||||
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
|
||||
0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
|
||||
0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
||||
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
|
||||
0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
|
||||
0x55, 0x21, 0x0c, 0x7d};
|
||||
|
||||
#define rj_sbox(x) sbox[(x)]
|
||||
#define rj_sbox_inv(x) sboxinv[(x)]
|
||||
|
||||
#else /* tableless subroutines */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_alog(uint8_t x) // calculate anti-logarithm gen 3
|
||||
{
|
||||
uint8_t atb = 1, z;
|
||||
|
||||
while (x--) {
|
||||
z = atb;
|
||||
atb <<= 1;
|
||||
if (z & 0x80) atb ^= 0x1b;
|
||||
atb ^= z;
|
||||
}
|
||||
|
||||
return atb;
|
||||
} /* gf_alog */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_log(uint8_t x) // calculate logarithm gen 3
|
||||
{
|
||||
uint8_t atb = 1, i = 0, z;
|
||||
|
||||
do {
|
||||
if (atb == x) break;
|
||||
z = atb;
|
||||
atb <<= 1;
|
||||
if (z & 0x80) atb ^= 0x1b;
|
||||
atb ^= z;
|
||||
} while (++i > 0);
|
||||
|
||||
return i;
|
||||
} /* gf_log */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_mulinv(uint8_t x) // calculate multiplicative inverse
|
||||
{
|
||||
return (x) ? gf_alog(255 - gf_log(x)) : 0;
|
||||
} /* gf_mulinv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_sbox(uint8_t x) {
|
||||
uint8_t y, sb;
|
||||
|
||||
sb = y = gf_mulinv(x);
|
||||
y = (y << 1) | (y >> 7);
|
||||
sb ^= y;
|
||||
y = (y << 1) | (y >> 7);
|
||||
sb ^= y;
|
||||
y = (y << 1) | (y >> 7);
|
||||
sb ^= y;
|
||||
y = (y << 1) | (y >> 7);
|
||||
sb ^= y;
|
||||
|
||||
return (sb ^ 0x63);
|
||||
} /* rj_sbox */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_sbox_inv(uint8_t x) {
|
||||
uint8_t y, sb;
|
||||
|
||||
y = x ^ 0x63;
|
||||
sb = y = (y << 1) | (y >> 7);
|
||||
y = (y << 2) | (y >> 6);
|
||||
sb ^= y;
|
||||
y = (y << 3) | (y >> 5);
|
||||
sb ^= y;
|
||||
|
||||
return gf_mulinv(sb);
|
||||
} /* rj_sbox_inv */
|
||||
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_xtime(uint8_t x) {
|
||||
return (x & 0x80) ? ((x << 1) ^ 0x1b) : (x << 1);
|
||||
} /* rj_xtime */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_subBytes(uint8_t* buf) {
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox(buf[i]);
|
||||
} /* aes_subBytes */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_subBytes_inv(uint8_t* buf) {
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox_inv(buf[i]);
|
||||
} /* aes_subBytes_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_addRoundKey(uint8_t* buf, uint8_t* key) {
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= key[i];
|
||||
} /* aes_addRoundKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_addRoundKey_cpy(uint8_t* buf, uint8_t* key, uint8_t* cpk) {
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= (cpk[i] = key[i]), cpk[16 + i] = key[16 + i];
|
||||
} /* aes_addRoundKey_cpy */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_shiftRows(uint8_t* buf) {
|
||||
register uint8_t i, j; /* to make it potentially parallelable :) */
|
||||
|
||||
i = buf[1];
|
||||
buf[1] = buf[5];
|
||||
buf[5] = buf[9];
|
||||
buf[9] = buf[13];
|
||||
buf[13] = i;
|
||||
i = buf[10];
|
||||
buf[10] = buf[2];
|
||||
buf[2] = i;
|
||||
j = buf[3];
|
||||
buf[3] = buf[15];
|
||||
buf[15] = buf[11];
|
||||
buf[11] = buf[7];
|
||||
buf[7] = j;
|
||||
j = buf[14];
|
||||
buf[14] = buf[6];
|
||||
buf[6] = j;
|
||||
|
||||
} /* aes_shiftRows */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_shiftRows_inv(uint8_t* buf) {
|
||||
register uint8_t i, j; /* same as above :) */
|
||||
|
||||
i = buf[1];
|
||||
buf[1] = buf[13];
|
||||
buf[13] = buf[9];
|
||||
buf[9] = buf[5];
|
||||
buf[5] = i;
|
||||
i = buf[2];
|
||||
buf[2] = buf[10];
|
||||
buf[10] = i;
|
||||
j = buf[3];
|
||||
buf[3] = buf[7];
|
||||
buf[7] = buf[11];
|
||||
buf[11] = buf[15];
|
||||
buf[15] = j;
|
||||
j = buf[6];
|
||||
buf[6] = buf[14];
|
||||
buf[14] = j;
|
||||
|
||||
} /* aes_shiftRows_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_mixColumns(uint8_t* buf) {
|
||||
register uint8_t i, a, b, c, d, e;
|
||||
|
||||
for (i = 0; i < 16; i += 4) {
|
||||
a = buf[i];
|
||||
b = buf[i + 1];
|
||||
c = buf[i + 2];
|
||||
d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
buf[i] ^= e ^ rj_xtime(a ^ b);
|
||||
buf[i + 1] ^= e ^ rj_xtime(b ^ c);
|
||||
buf[i + 2] ^= e ^ rj_xtime(c ^ d);
|
||||
buf[i + 3] ^= e ^ rj_xtime(d ^ a);
|
||||
}
|
||||
} /* aes_mixColumns */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_mixColumns_inv(uint8_t* buf) {
|
||||
register uint8_t i, a, b, c, d, e, x, y, z;
|
||||
|
||||
for (i = 0; i < 16; i += 4) {
|
||||
a = buf[i];
|
||||
b = buf[i + 1];
|
||||
c = buf[i + 2];
|
||||
d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
z = rj_xtime(e);
|
||||
x = e ^ rj_xtime(rj_xtime(z ^ a ^ c));
|
||||
y = e ^ rj_xtime(rj_xtime(z ^ b ^ d));
|
||||
buf[i] ^= x ^ rj_xtime(a ^ b);
|
||||
buf[i + 1] ^= y ^ rj_xtime(b ^ c);
|
||||
buf[i + 2] ^= x ^ rj_xtime(c ^ d);
|
||||
buf[i + 3] ^= y ^ rj_xtime(d ^ a);
|
||||
}
|
||||
} /* aes_mixColumns_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_expandEncKey(uint8_t* k, uint8_t* rc) {
|
||||
register uint8_t i;
|
||||
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
*rc = F(*rc);
|
||||
|
||||
for (i = 4; i < 16; i += 4)
|
||||
k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3], k[i + 2] ^= k[i - 2],
|
||||
k[i + 3] ^= k[i - 1];
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for (i = 20; i < 32; i += 4)
|
||||
k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3], k[i + 2] ^= k[i - 2],
|
||||
k[i + 3] ^= k[i - 1];
|
||||
|
||||
} /* aes_expandEncKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_expandDecKey(uint8_t* k, uint8_t* rc) {
|
||||
uint8_t i;
|
||||
|
||||
for (i = 28; i > 16; i -= 4)
|
||||
k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3], k[i + 2] ^= k[i - 2],
|
||||
k[i + 3] ^= k[i - 1];
|
||||
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for (i = 12; i > 0; i -= 4)
|
||||
k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3], k[i + 2] ^= k[i - 2],
|
||||
k[i + 3] ^= k[i - 1];
|
||||
|
||||
*rc = FD(*rc);
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
} /* aes_expandDecKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_init(aes256_context* ctx, uint8_t* k) {
|
||||
uint8_t rcon = 1;
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++) ctx->enckey[i] = ctx->deckey[i] = k[i];
|
||||
for (i = 8; --i;) aes_expandEncKey(ctx->deckey, &rcon);
|
||||
} /* aes256_init */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_done(aes256_context* ctx) {
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++)
|
||||
ctx->key[i] = ctx->enckey[i] = ctx->deckey[i] = 0;
|
||||
} /* aes256_done */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_encrypt_ecb(aes256_context* ctx, uint8_t* buf) {
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->enckey, ctx->key);
|
||||
for (i = 1, rcon = 1; i < 14; ++i) {
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_mixColumns(buf);
|
||||
if (i & 1) {
|
||||
aes_addRoundKey(buf, &ctx->key[16]);
|
||||
} else {
|
||||
aes_expandEncKey(ctx->key, &rcon), aes_addRoundKey(buf, ctx->key);
|
||||
}
|
||||
}
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_expandEncKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, ctx->key);
|
||||
} /* aes256_encrypt */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_decrypt_ecb(aes256_context* ctx, uint8_t* buf) {
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->deckey, ctx->key);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
|
||||
for (i = 14, rcon = 0x80; --i;) //! @note exit when --i == 0;
|
||||
{
|
||||
if ((i & 1)) {
|
||||
aes_expandDecKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, &ctx->key[16]);
|
||||
} else
|
||||
aes_addRoundKey(buf, ctx->key);
|
||||
aes_mixColumns_inv(buf);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
}
|
||||
aes_addRoundKey(buf, ctx->key);
|
||||
} /* aes256_decrypt */
|
||||
|
||||
// END OF AES-256
|
||||
@@ -1,292 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_buffer.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/2
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2017-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.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
|
||||
#include "osdk_buffer.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
#include "osdk_util.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
static E_OsdkStat OsdkBuffer_CutBufferSizeToPowerOfTwo(uint16_t inSize,
|
||||
uint16_t *outSize);
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @note this function will cut size to the largest power of two that is not
|
||||
* greater than size. So, it is better that
|
||||
* size is power of two in order to not waste memory space.
|
||||
* @param buffer
|
||||
* @param space
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
E_OsdkStat OsdkBuffer_Init(T_OsdkBuffer *buffer, uint8_t *space,
|
||||
uint16_t size) {
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
if (buffer == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (space == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer space is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
buffer->readIndex = 0;
|
||||
buffer->writeIndex = 0;
|
||||
buffer->bufferPointer = space;
|
||||
osdkStat = OsdkBuffer_CutBufferSizeToPowerOfTwo(size, &buffer->bufferSize);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "cut size for buffer error: %d.",
|
||||
osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkBuffer_DeInit(T_OsdkBuffer *buffer) {
|
||||
if (buffer == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
buffer->bufferPointer = NULL;
|
||||
buffer->bufferSize = 0;
|
||||
buffer->readIndex = 0;
|
||||
buffer->writeIndex = 0;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @note this function can not promise putting all data to buffer. If unused
|
||||
* data size of buffer is less than size of
|
||||
* data to be put, this function put front data whose size is unused data size
|
||||
* of buffer to buffer.
|
||||
* @note if there exist multi-producer or multi-consumer operating a buffer,
|
||||
* please lock this buffer to protect data
|
||||
* before call this function.
|
||||
* @param buffer
|
||||
* @param data
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
E_OsdkStat OsdkBuffer_PutToBack(T_OsdkBuffer *buffer, const uint8_t *data,
|
||||
uint16_t len, uint16_t *realPutLen) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint16_t writeUpLen = 0;
|
||||
uint16_t unusedSize = 0;
|
||||
uint16_t lenToPut = 0;
|
||||
|
||||
if (realPutLen == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkBuffer_GetUnusedSize(buffer, &unusedSize);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_FLOWCONTROLLER,
|
||||
"get unused size of buffer error: %d.", osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
lenToPut = OSDK_UTIL_MIN(len, unusedSize);
|
||||
|
||||
// fill up data
|
||||
writeUpLen = OSDK_UTIL_MIN(
|
||||
lenToPut, (uint16_t)(buffer->bufferSize -
|
||||
(buffer->writeIndex & (buffer->bufferSize - 1))));
|
||||
memcpy(
|
||||
buffer->bufferPointer + (buffer->writeIndex & (buffer->bufferSize - 1)),
|
||||
data, writeUpLen);
|
||||
|
||||
// fill down data
|
||||
memcpy(buffer->bufferPointer, data + writeUpLen, lenToPut - writeUpLen);
|
||||
|
||||
buffer->writeIndex += lenToPut;
|
||||
*realPutLen = lenToPut;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @note this function can not promise putting all data to buffer. If unused
|
||||
* data size of buffer is less than size of
|
||||
* data to be put, this function put back data whose size is unused data size of
|
||||
* buffer to buffer.
|
||||
* @note if there exist multi-producer or multi-consumer operating a buffer,
|
||||
* please lock this buffer to protect data
|
||||
* before call this function.
|
||||
* @param buffer
|
||||
* @param data
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
E_OsdkStat OsdkBuffer_PutToFront(T_OsdkBuffer *buffer, const uint8_t *data,
|
||||
uint16_t len, uint16_t *realPutLen) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint16_t writeDownLen = 0;
|
||||
uint16_t unusedSize = 0;
|
||||
uint16_t lenToPut = 0;
|
||||
|
||||
if (realPutLen == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkBuffer_GetUnusedSize(buffer, &unusedSize);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_FLOWCONTROLLER,
|
||||
"get unused size of buffer error: %d.", osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
lenToPut = OSDK_UTIL_MIN(len, unusedSize);
|
||||
|
||||
// fill down data
|
||||
writeDownLen = OSDK_UTIL_MIN(
|
||||
lenToPut, (uint16_t)(buffer->readIndex & (buffer->bufferSize - 1)));
|
||||
memcpy(buffer->bufferPointer +
|
||||
(buffer->readIndex & (buffer->bufferSize - 1)) - writeDownLen,
|
||||
data + len - writeDownLen, writeDownLen);
|
||||
|
||||
// fill up data
|
||||
memcpy(buffer->bufferPointer + buffer->bufferSize - (lenToPut - writeDownLen),
|
||||
data + len - lenToPut, lenToPut - writeDownLen);
|
||||
|
||||
buffer->readIndex -= lenToPut;
|
||||
*realPutLen = lenToPut;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @note if there exist multi-producer or multi-consumer operating a buffer,
|
||||
* please lock this buffer to protect data
|
||||
* before call this function.
|
||||
* @param buffer
|
||||
* @param data
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
E_OsdkStat OsdkBuffer_GetFromFront(T_OsdkBuffer *buffer, uint8_t *data,
|
||||
uint16_t len, uint16_t *realGetLen) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint16_t readUpLen;
|
||||
uint16_t unusedSize = 0;
|
||||
uint16_t usedSize = 0;
|
||||
uint16_t lenToGet = 0;
|
||||
|
||||
if (realGetLen == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkBuffer_GetUnusedSize(buffer, &unusedSize);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_FLOWCONTROLLER,
|
||||
"get unused size of buffer error: %d.", osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
usedSize = buffer->bufferSize - unusedSize;
|
||||
lenToGet = OSDK_UTIL_MIN(len, usedSize);
|
||||
|
||||
// get up data
|
||||
readUpLen = OSDK_UTIL_MIN(
|
||||
lenToGet, (uint16_t)(buffer->bufferSize -
|
||||
(buffer->readIndex & (buffer->bufferSize - 1))));
|
||||
memcpy(data,
|
||||
buffer->bufferPointer + (buffer->readIndex & (buffer->bufferSize - 1)),
|
||||
readUpLen);
|
||||
|
||||
// get down data
|
||||
memcpy(data + readUpLen, buffer->bufferPointer, lenToGet - readUpLen);
|
||||
|
||||
buffer->readIndex += lenToGet;
|
||||
*realGetLen = lenToGet;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @note if there exist multi-producer or multi-consumer operating a buffer,
|
||||
* please lock this buffer to protect data
|
||||
* before call this function.
|
||||
* @param buffer
|
||||
* @param unusedSize
|
||||
* @return
|
||||
*/
|
||||
E_OsdkStat OsdkBuffer_GetUnusedSize(T_OsdkBuffer *buffer,
|
||||
uint16_t *unusedSize) {
|
||||
if (unusedSize == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
*unusedSize =
|
||||
(uint16_t)(buffer->bufferSize - buffer->writeIndex + buffer->readIndex);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static E_OsdkStat OsdkBuffer_CutBufferSizeToPowerOfTwo(uint16_t inSize,
|
||||
uint16_t *outSize) {
|
||||
int32_t i = 0;
|
||||
|
||||
if (outSize == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
while ((1 << (++i)) <= inSize)
|
||||
;
|
||||
*outSize = (uint16_t)(1 << (--i));
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,265 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_crc.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_crc.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define CRC8_INIT 0x77
|
||||
#define CCITT_CRC16_INIT 0x3692
|
||||
#define IBM_CRC16_INIT 0x3AA3
|
||||
#define CRC32_INIT 0x3AA3
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
//@formatter:off
|
||||
static const uint8_t s_crc8Table[256] = {
|
||||
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20,
|
||||
0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e,
|
||||
0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 0x23, 0x7d, 0x9f, 0xc1,
|
||||
0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62,
|
||||
0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e,
|
||||
0x1d, 0x43, 0xa1, 0xff, 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5,
|
||||
0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, 0xdb, 0x85, 0x67, 0x39,
|
||||
0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a,
|
||||
0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45,
|
||||
0xc6, 0x98, 0x7a, 0x24, 0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b,
|
||||
0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 0x8c, 0xd2, 0x30, 0x6e,
|
||||
0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd,
|
||||
0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31,
|
||||
0xb2, 0xec, 0x0e, 0x50, 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c,
|
||||
0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, 0x32, 0x6c, 0x8e, 0xd0,
|
||||
0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73,
|
||||
0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea,
|
||||
0x69, 0x37, 0xd5, 0x8b, 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4,
|
||||
0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 0xe9, 0xb7, 0x55, 0x0b,
|
||||
0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8,
|
||||
0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54,
|
||||
0xd7, 0x89, 0x6b, 0x35,
|
||||
};
|
||||
|
||||
static const uint16_t s_ccittCrc16Table[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48,
|
||||
0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108,
|
||||
0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb,
|
||||
0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399,
|
||||
0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e,
|
||||
0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e,
|
||||
0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd,
|
||||
0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285,
|
||||
0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44,
|
||||
0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014,
|
||||
0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5,
|
||||
0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3,
|
||||
0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862,
|
||||
0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e,
|
||||
0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1,
|
||||
0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483,
|
||||
0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50,
|
||||
0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710,
|
||||
0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7,
|
||||
0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1,
|
||||
0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72,
|
||||
0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e,
|
||||
0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf,
|
||||
0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d,
|
||||
0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c,
|
||||
0x3de3, 0x2c6a, 0x1ef1, 0x0f78};
|
||||
|
||||
static const uint32_t s_crc32Table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
|
||||
|
||||
static const uint16_t s_ibmCrc16Table[256] = {
|
||||
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601,
|
||||
0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0,
|
||||
0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81,
|
||||
0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941,
|
||||
0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01,
|
||||
0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0,
|
||||
0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081,
|
||||
0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
||||
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00,
|
||||
0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0,
|
||||
0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981,
|
||||
0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41,
|
||||
0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700,
|
||||
0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0,
|
||||
0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281,
|
||||
0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
||||
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01,
|
||||
0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1,
|
||||
0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80,
|
||||
0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541,
|
||||
0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101,
|
||||
0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0,
|
||||
0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481,
|
||||
0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
||||
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801,
|
||||
0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1,
|
||||
0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581,
|
||||
0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341,
|
||||
0x4100, 0x81c1, 0x8081, 0x4040};
|
||||
//@formatter:on
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static uint8_t OsdkCrc_crc8Update(uint8_t crc, uint8_t ch);
|
||||
static uint16_t OsdkCrc_ccittCrc16Update(uint16_t crc, uint8_t ch);
|
||||
static uint16_t OsdkCrc_ibmCrc16Update(uint16_t crc, uint8_t ch);
|
||||
static uint32_t OsdkCrc_crc32Update(uint32_t crc, uint8_t ch);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
static uint8_t OsdkCrc_crc8Update(uint8_t crc, uint8_t ch) {
|
||||
uint8_t tmp;
|
||||
|
||||
tmp = crc ^ ch;
|
||||
crc = s_crc8Table[tmp];
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint8_t OsdkCrc_crc8Calc(const uint8_t* pMsg, size_t nLen) {
|
||||
size_t i;
|
||||
uint8_t wCRC = CRC8_INIT;
|
||||
|
||||
for (i = 0; i < nLen; i++) {
|
||||
wCRC = OsdkCrc_crc8Update(wCRC, pMsg[i]);
|
||||
}
|
||||
|
||||
return wCRC;
|
||||
}
|
||||
|
||||
static uint16_t OsdkCrc_ccittCrc16Update(uint16_t crc, uint8_t ch) {
|
||||
uint16_t tmp;
|
||||
uint16_t msg;
|
||||
|
||||
msg = 0x00ff & (uint16_t)(ch);
|
||||
tmp = crc ^ msg;
|
||||
crc = (crc >> 8) ^ s_ccittCrc16Table[tmp & 0xff];
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint16_t OsdkCrc_ccittCrc16Calc(const uint8_t* pMsg, size_t nLen) {
|
||||
size_t i;
|
||||
uint16_t wCRC = CCITT_CRC16_INIT;
|
||||
|
||||
for (i = 0; i < nLen; i++) {
|
||||
wCRC = OsdkCrc_ccittCrc16Update(wCRC, pMsg[i]);
|
||||
}
|
||||
|
||||
return wCRC;
|
||||
}
|
||||
|
||||
static uint16_t OsdkCrc_ibmCrc16Update(uint16_t crc, uint8_t ch) {
|
||||
uint16_t tmp;
|
||||
uint16_t msg;
|
||||
|
||||
msg = 0x00ff & (uint16_t)(ch);
|
||||
tmp = crc ^ msg;
|
||||
crc = (crc >> 8) ^ s_ibmCrc16Table[tmp & 0xff];
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint16_t OsdkCrc_ibmCrc16Calc(const uint8_t* pMsg, size_t nLen) {
|
||||
size_t i;
|
||||
uint16_t wCRC = IBM_CRC16_INIT;
|
||||
|
||||
for (i = 0; i < nLen; i++) {
|
||||
wCRC = OsdkCrc_ibmCrc16Update(wCRC, pMsg[i]);
|
||||
}
|
||||
|
||||
return wCRC;
|
||||
}
|
||||
|
||||
static uint32_t OsdkCrc_crc32Update(uint32_t crc, uint8_t ch) {
|
||||
uint32_t tmp;
|
||||
uint32_t msg;
|
||||
|
||||
msg = 0x000000ffL & (uint32_t)(ch);
|
||||
tmp = crc ^ msg;
|
||||
crc = (crc >> 8) ^ s_crc32Table[tmp & 0xff];
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint32_t OsdkCrc_crc32Calc(const uint8_t* pMsg, size_t nLen) {
|
||||
size_t i;
|
||||
uint32_t wCRC = CRC32_INIT;
|
||||
|
||||
for (i = 0; i < nLen; i++) {
|
||||
wCRC = OsdkCrc_crc32Update(wCRC, pMsg[i]);
|
||||
}
|
||||
|
||||
return wCRC;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_list.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_list.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
static void __OsdkList_Add(T_OsdkList *node, T_OsdkList *prev,
|
||||
T_OsdkList *next);
|
||||
static void __OsdkList_Del(T_OsdkList *prev, T_OsdkList *next);
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void OsdkList_Init(T_OsdkList *list) {
|
||||
list->pNext = list;
|
||||
list->pPrev = list;
|
||||
}
|
||||
|
||||
void OsdkList_Add(T_OsdkList *node, T_OsdkList *head) {
|
||||
__OsdkList_Add(node, head, head->pPrev);
|
||||
}
|
||||
|
||||
void OsdkList_AddTail(T_OsdkList *node, T_OsdkList *head) {
|
||||
__OsdkList_Add(node, head->pPrev, head);
|
||||
}
|
||||
|
||||
void OsdkList_Del(T_OsdkList *list) {
|
||||
__OsdkList_Del(list->pPrev, list->pNext);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static void __OsdkList_Add(T_OsdkList *node, T_OsdkList *prev,
|
||||
T_OsdkList *next) {
|
||||
next->pPrev = node;
|
||||
node->pNext = next;
|
||||
node->pPrev = prev;
|
||||
prev->pNext = node;
|
||||
}
|
||||
|
||||
static void __OsdkList_Del(T_OsdkList *prev, T_OsdkList *next) {
|
||||
next->pPrev = prev;
|
||||
prev->pNext = next;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,224 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_md5.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_md5.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define ROTLEFT(a, b) ((a << b) | (a >> (32 - b)))
|
||||
|
||||
#define F(x, y, z) ((x & y) | (~x & z))
|
||||
#define G(x, y, z) ((x & z) | (y & ~z))
|
||||
#define H(x, y, z) (x ^ y ^ z)
|
||||
#define I(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
#define FF(a, b, c, d, m, s, t) \
|
||||
{ \
|
||||
a += F(b, c, d) + m + t; \
|
||||
a = b + ROTLEFT(a, s); \
|
||||
}
|
||||
#define GG(a, b, c, d, m, s, t) \
|
||||
{ \
|
||||
a += G(b, c, d) + m + t; \
|
||||
a = b + ROTLEFT(a, s); \
|
||||
}
|
||||
#define HH(a, b, c, d, m, s, t) \
|
||||
{ \
|
||||
a += H(b, c, d) + m + t; \
|
||||
a = b + ROTLEFT(a, s); \
|
||||
}
|
||||
#define II(a, b, c, d, m, s, t) \
|
||||
{ \
|
||||
a += I(b, c, d) + m + t; \
|
||||
a = b + ROTLEFT(a, s); \
|
||||
}
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void OsdkMd5_Transform(MD5_CTX *ctx, const BYTE *data) {
|
||||
WORD a, b, c, d, m[16], i, j;
|
||||
|
||||
// MD5 specifies big endian byte order, but this implementation assumes a
|
||||
// little
|
||||
// endian byte order CPU. Reverse all the bytes upon input, and re-reverse
|
||||
// them
|
||||
// on output (in md5_final()).
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4) {
|
||||
m[i] = (data[j]) + (data[j + 1] << 8) + (data[j + 2] << 16) +
|
||||
(data[j + 3] << 24);
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
|
||||
FF(a, b, c, d, m[0], 7, 0xd76aa478);
|
||||
FF(d, a, b, c, m[1], 12, 0xe8c7b756);
|
||||
FF(c, d, a, b, m[2], 17, 0x242070db);
|
||||
FF(b, c, d, a, m[3], 22, 0xc1bdceee);
|
||||
FF(a, b, c, d, m[4], 7, 0xf57c0faf);
|
||||
FF(d, a, b, c, m[5], 12, 0x4787c62a);
|
||||
FF(c, d, a, b, m[6], 17, 0xa8304613);
|
||||
FF(b, c, d, a, m[7], 22, 0xfd469501);
|
||||
FF(a, b, c, d, m[8], 7, 0x698098d8);
|
||||
FF(d, a, b, c, m[9], 12, 0x8b44f7af);
|
||||
FF(c, d, a, b, m[10], 17, 0xffff5bb1);
|
||||
FF(b, c, d, a, m[11], 22, 0x895cd7be);
|
||||
FF(a, b, c, d, m[12], 7, 0x6b901122);
|
||||
FF(d, a, b, c, m[13], 12, 0xfd987193);
|
||||
FF(c, d, a, b, m[14], 17, 0xa679438e);
|
||||
FF(b, c, d, a, m[15], 22, 0x49b40821);
|
||||
|
||||
GG(a, b, c, d, m[1], 5, 0xf61e2562);
|
||||
GG(d, a, b, c, m[6], 9, 0xc040b340);
|
||||
GG(c, d, a, b, m[11], 14, 0x265e5a51);
|
||||
GG(b, c, d, a, m[0], 20, 0xe9b6c7aa);
|
||||
GG(a, b, c, d, m[5], 5, 0xd62f105d);
|
||||
GG(d, a, b, c, m[10], 9, 0x02441453);
|
||||
GG(c, d, a, b, m[15], 14, 0xd8a1e681);
|
||||
GG(b, c, d, a, m[4], 20, 0xe7d3fbc8);
|
||||
GG(a, b, c, d, m[9], 5, 0x21e1cde6);
|
||||
GG(d, a, b, c, m[14], 9, 0xc33707d6);
|
||||
GG(c, d, a, b, m[3], 14, 0xf4d50d87);
|
||||
GG(b, c, d, a, m[8], 20, 0x455a14ed);
|
||||
GG(a, b, c, d, m[13], 5, 0xa9e3e905);
|
||||
GG(d, a, b, c, m[2], 9, 0xfcefa3f8);
|
||||
GG(c, d, a, b, m[7], 14, 0x676f02d9);
|
||||
GG(b, c, d, a, m[12], 20, 0x8d2a4c8a);
|
||||
|
||||
HH(a, b, c, d, m[5], 4, 0xfffa3942);
|
||||
HH(d, a, b, c, m[8], 11, 0x8771f681);
|
||||
HH(c, d, a, b, m[11], 16, 0x6d9d6122);
|
||||
HH(b, c, d, a, m[14], 23, 0xfde5380c);
|
||||
HH(a, b, c, d, m[1], 4, 0xa4beea44);
|
||||
HH(d, a, b, c, m[4], 11, 0x4bdecfa9);
|
||||
HH(c, d, a, b, m[7], 16, 0xf6bb4b60);
|
||||
HH(b, c, d, a, m[10], 23, 0xbebfbc70);
|
||||
HH(a, b, c, d, m[13], 4, 0x289b7ec6);
|
||||
HH(d, a, b, c, m[0], 11, 0xeaa127fa);
|
||||
HH(c, d, a, b, m[3], 16, 0xd4ef3085);
|
||||
HH(b, c, d, a, m[6], 23, 0x04881d05);
|
||||
HH(a, b, c, d, m[9], 4, 0xd9d4d039);
|
||||
HH(d, a, b, c, m[12], 11, 0xe6db99e5);
|
||||
HH(c, d, a, b, m[15], 16, 0x1fa27cf8);
|
||||
HH(b, c, d, a, m[2], 23, 0xc4ac5665);
|
||||
|
||||
II(a, b, c, d, m[0], 6, 0xf4292244);
|
||||
II(d, a, b, c, m[7], 10, 0x432aff97);
|
||||
II(c, d, a, b, m[14], 15, 0xab9423a7);
|
||||
II(b, c, d, a, m[5], 21, 0xfc93a039);
|
||||
II(a, b, c, d, m[12], 6, 0x655b59c3);
|
||||
II(d, a, b, c, m[3], 10, 0x8f0ccc92);
|
||||
II(c, d, a, b, m[10], 15, 0xffeff47d);
|
||||
II(b, c, d, a, m[1], 21, 0x85845dd1);
|
||||
II(a, b, c, d, m[8], 6, 0x6fa87e4f);
|
||||
II(d, a, b, c, m[15], 10, 0xfe2ce6e0);
|
||||
II(c, d, a, b, m[6], 15, 0xa3014314);
|
||||
II(b, c, d, a, m[13], 21, 0x4e0811a1);
|
||||
II(a, b, c, d, m[4], 6, 0xf7537e82);
|
||||
II(d, a, b, c, m[11], 10, 0xbd3af235);
|
||||
II(c, d, a, b, m[2], 15, 0x2ad7d2bb);
|
||||
II(b, c, d, a, m[9], 21, 0xeb86d391);
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
}
|
||||
|
||||
void OsdkMd5_Init(MD5_CTX *ctx) {
|
||||
ctx->datalen = 0;
|
||||
ctx->bitlen = 0;
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void OsdkMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
ctx->data[ctx->datalen] = data[i];
|
||||
ctx->datalen++;
|
||||
if (ctx->datalen == 64) {
|
||||
OsdkMd5_Transform(ctx, ctx->data);
|
||||
ctx->bitlen += 512;
|
||||
ctx->datalen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OsdkMd5_Final(MD5_CTX *ctx, BYTE *hash) {
|
||||
size_t i;
|
||||
|
||||
i = ctx->datalen;
|
||||
|
||||
// Pad whatever data is left in the buffer.
|
||||
if (ctx->datalen < 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 56) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
} else if (ctx->datalen >= 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 64) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
OsdkMd5_Transform(ctx, ctx->data);
|
||||
memset(ctx->data, 0, 56);
|
||||
}
|
||||
|
||||
// Append to the padding the total message's length in bits and transform.
|
||||
ctx->bitlen += ctx->datalen * 8;
|
||||
ctx->data[56] = ctx->bitlen;
|
||||
ctx->data[57] = ctx->bitlen >> 8;
|
||||
ctx->data[58] = ctx->bitlen >> 16;
|
||||
ctx->data[59] = ctx->bitlen >> 24;
|
||||
ctx->data[60] = ctx->bitlen >> 32;
|
||||
ctx->data[61] = ctx->bitlen >> 40;
|
||||
ctx->data[62] = ctx->bitlen >> 48;
|
||||
ctx->data[63] = ctx->bitlen >> 56;
|
||||
OsdkMd5_Transform(ctx, ctx->data);
|
||||
|
||||
// Since this implementation uses little endian byte ordering and MD uses big
|
||||
// endian,
|
||||
// reverse all the bytes when copying the final state to the output hash.
|
||||
for (i = 0; i < 4; ++i) {
|
||||
hash[i] = (ctx->state[0] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 4] = (ctx->state[1] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 8] = (ctx->state[2] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
|
||||
}
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,236 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_msgq.c
|
||||
* @version V1.0.0
|
||||
* @date 2019/09/15
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_msgq.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkMsgq_Create(T_msgqAttrib *attrib, T_msgQueue **msgq) {
|
||||
T_msgQueue *tm;
|
||||
uint32_t bufSize;
|
||||
|
||||
if (attrib == NULL || msgq == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "message queue param error");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
bufSize = 1;
|
||||
while (bufSize <= attrib->bufSize) {
|
||||
bufSize <<= 1;
|
||||
}
|
||||
tm = OsdkOsal_Malloc(sizeof(T_msgQueue) + bufSize);
|
||||
if (tm == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "msgqueue malloc error");
|
||||
return OSDK_STAT_ERR_ALLOC;
|
||||
}
|
||||
memcpy(&tm->attrib, attrib, sizeof(T_msgqAttrib));
|
||||
tm->buffer = (uint8_t *)((uint8_t *)tm + sizeof(T_msgQueue));
|
||||
tm->bufSize = bufSize;
|
||||
tm->head = tm->tail = 0;
|
||||
tm->currentCount = 0;
|
||||
|
||||
if (OsdkOsal_MutexCreate(&tm->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "send mutex create failed");
|
||||
goto err;
|
||||
}
|
||||
if (OsdkOsal_MutexCreate(&tm->recvMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "recv mutex create failed");
|
||||
goto err;
|
||||
}
|
||||
if (OsdkOsal_SemaphoreCreate(&tm->sendSem, 0) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "send semaphore create failed");
|
||||
goto err;
|
||||
}
|
||||
if (OsdkOsal_SemaphoreCreate(&tm->recvSem, 0) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "recv semaphore create failed");
|
||||
goto err;
|
||||
}
|
||||
*msgq = tm;
|
||||
return OSDK_STAT_OK;
|
||||
|
||||
err:
|
||||
OsdkOsal_Free(tm);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkMsgq_Destroy(T_msgQueue *msgq) {
|
||||
if (OsdkOsal_MutexDestroy(msgq->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "send mutex destroy failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (OsdkOsal_MutexDestroy(msgq->recvMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "recv mutex destroy failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (OsdkOsal_SemaphoreDestroy(msgq->sendSem) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "send semaphore destroy failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
if (OsdkOsal_SemaphoreDestroy(msgq->recvSem) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "recv semaphore destroy failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
OsdkOsal_Free(msgq);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkMsgq_Recv(T_msgQueue *msgq, uint8_t *buffer, uint32_t *size,
|
||||
uint32_t timeout) {
|
||||
if (msgq == NULL || buffer == NULL || size == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "msg recv param error");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
OsdkOsal_MutexLock(msgq->recvMutex);
|
||||
while (DATA_SIZE(msgq) == 0) {
|
||||
if (timeout == OSDK_WAIT_POLLING) {
|
||||
OsdkOsal_MutexUnlock(msgq->recvMutex);
|
||||
return OSDK_STAT_NOT_READY;
|
||||
} else if (timeout == OSDK_WAIT_FOREVER) {
|
||||
if (OsdkOsal_SemaphoreWait(msgq->recvSem) != OSDK_STAT_OK) {
|
||||
OsdkOsal_MutexUnlock(msgq->recvMutex);
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "semaphore wait error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
} else {
|
||||
if (OsdkOsal_SemaphoreTimedWait(msgq->recvSem, timeout) !=
|
||||
OSDK_STAT_OK) {
|
||||
OsdkOsal_MutexUnlock(msgq->recvMutex);
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "semaphore wait timeout");
|
||||
return OSDK_STAT_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t i, curSize = DATA_SIZE(msgq), tempSize = 0;
|
||||
|
||||
if (curSize > *size) {
|
||||
curSize = *size;
|
||||
} else {
|
||||
*size = curSize;
|
||||
}
|
||||
tempSize = *size;
|
||||
i = msgq->tail;
|
||||
if (i + tempSize > msgq->bufSize) {
|
||||
memcpy(buffer, &msgq->buffer[i], msgq->bufSize - i);
|
||||
buffer = (uint8_t *)(buffer + msgq->bufSize - i);
|
||||
tempSize -= msgq->bufSize - i;
|
||||
i = 0;
|
||||
}
|
||||
memcpy(buffer, &msgq->buffer[i], tempSize);
|
||||
msgq->tail = i + tempSize;
|
||||
|
||||
if (OsdkOsal_MutexUnlock(msgq->recvMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "unlock recv mutex failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (OsdkOsal_SemaphorePost(msgq->sendSem) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "send semaphore post failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
msgq->currentCount--;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkMsgq_Send(T_msgQueue *msgq, void *message, uint32_t size,
|
||||
uint32_t timeout) {
|
||||
if (msgq == NULL || message == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "msg send param error");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (OsdkOsal_MutexLock(msgq->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "lock send mutex failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
while (FREE_SIZE(msgq) < size) {
|
||||
if (timeout == OSDK_WAIT_POLLING) {
|
||||
OsdkOsal_MutexUnlock(msgq->sendMutex);
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "no enough resource");
|
||||
return OSDK_STAT_ERR;
|
||||
} else if (timeout == OSDK_WAIT_FOREVER) {
|
||||
if (OsdkOsal_SemaphoreWait(msgq->sendSem) != OSDK_STAT_OK) {
|
||||
OsdkOsal_MutexUnlock(msgq->sendMutex);
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "semaphore wait error");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
} else {
|
||||
if (OsdkOsal_SemaphoreTimedWait(msgq->sendSem, timeout) !=
|
||||
OSDK_STAT_OK) {
|
||||
OsdkOsal_MutexUnlock(msgq->sendMutex);
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "semaphore wait timeout");
|
||||
return OSDK_STAT_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t i = msgq->head;
|
||||
uint8_t *data = (uint8_t *)message;
|
||||
if (i + size > msgq->bufSize) {
|
||||
memcpy(&msgq->buffer[i], data, msgq->bufSize - i);
|
||||
data += msgq->bufSize - i;
|
||||
size -= msgq->bufSize - i;
|
||||
i = 0;
|
||||
}
|
||||
memcpy(&msgq->buffer[i], data, size);
|
||||
msgq->head = i + size;
|
||||
if (OsdkOsal_MutexUnlock(msgq->sendMutex) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "unlock send mutex failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (OsdkOsal_SemaphorePost(msgq->recvSem) != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "recv semaphore post failed");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
msgq->currentCount++;
|
||||
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkMsgq_GetCount(T_msgQueue *msgq, uint32_t *count)
|
||||
{
|
||||
*count = msgq->currentCount;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_str.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_str.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
uint8_t *OsdkStr_PutStrToBuf(uint8_t *pBuf, char *str, uint32_t maxStrLen) {
|
||||
uint32_t len;
|
||||
|
||||
if (strlen(str) > maxStrLen) {
|
||||
len = maxStrLen;
|
||||
} else {
|
||||
len = strlen(str);
|
||||
}
|
||||
|
||||
memcpy(pBuf, str, len);
|
||||
|
||||
return (pBuf + len);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_unit.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/2
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2017-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.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_unit.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define OSDK_UNIT_TIMES_OF_BYTE_BIT 8
|
||||
#define OSDK_UNIT_TIMES_OF_KBYTE_BYTE 1024
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static E_OsdkStat OsdkUnit_CalculateDataLengthUnitRelativeTimes(
|
||||
E_OsdkUnitDataLengthUnit unit, uint32_t *relativeTimes);
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkUnit_DataLengthUnitConversion(float inDataLength,
|
||||
E_OsdkUnitDataLengthUnit inUnit,
|
||||
float *outDataLength,
|
||||
E_OsdkUnitDataLengthUnit outUnit) {
|
||||
E_OsdkStat osdkStat;
|
||||
uint32_t inUnitRelativeTimes = 0; // times of unit relative to bit
|
||||
uint32_t outUnitRelativeTimes = 0; // times of unit relative to bit
|
||||
|
||||
if (outDataLength == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkUnit_CalculateDataLengthUnitRelativeTimes(
|
||||
inUnit, &inUnitRelativeTimes);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL,
|
||||
"calculate relative times of data length unit error: %d.",
|
||||
osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
osdkStat = OsdkUnit_CalculateDataLengthUnitRelativeTimes(
|
||||
outUnit, &outUnitRelativeTimes);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL,
|
||||
"calculate relative times of data length unit error: %d.",
|
||||
osdkStat);
|
||||
return OSDK_STAT_SYS_ERR;
|
||||
}
|
||||
|
||||
*outDataLength = inDataLength * inUnitRelativeTimes / outUnitRelativeTimes;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static E_OsdkStat OsdkUnit_CalculateDataLengthUnitRelativeTimes(
|
||||
E_OsdkUnitDataLengthUnit unit, uint32_t *relativeTimes) {
|
||||
if (relativeTimes == NULL) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "input pointer is null.");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
switch (unit) {
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_BYTE:
|
||||
*relativeTimes = OSDK_UNIT_TIMES_OF_BYTE_BIT;
|
||||
break;
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_BIT:
|
||||
*relativeTimes = 1;
|
||||
break;
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_KBYTE:
|
||||
*relativeTimes =
|
||||
OSDK_UNIT_TIMES_OF_BYTE_BIT * OSDK_UNIT_TIMES_OF_KBYTE_BYTE;
|
||||
break;
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_KBIT:
|
||||
*relativeTimes = OSDK_UNIT_TIMES_OF_KBYTE_BYTE;
|
||||
break;
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_MBYTE:
|
||||
*relativeTimes = OSDK_UNIT_TIMES_OF_BYTE_BIT *
|
||||
OSDK_UNIT_TIMES_OF_KBYTE_BYTE *
|
||||
OSDK_UNIT_TIMES_OF_KBYTE_BYTE;
|
||||
break;
|
||||
case OSDK_UNIT_DATA_LENGTH_UNIT_MBIT:
|
||||
*relativeTimes =
|
||||
OSDK_UNIT_TIMES_OF_KBYTE_BYTE * OSDK_UNIT_TIMES_OF_KBYTE_BYTE;
|
||||
break;
|
||||
default:
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "data length unit is incorrect: %d.",
|
||||
unit);
|
||||
return OSDK_STAT_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,148 +0,0 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osdk_work.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 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 "osdk_work.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static E_OsdkStat OsdkWork_CheckDuplicate(T_OsdkWork *work,
|
||||
T_OsdkWorkNode *node);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
E_OsdkStat OsdkWork_Init(T_OsdkWork *work) {
|
||||
OsdkList_Init(&work->head);
|
||||
work->workCnt = 0;
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkWork_DeInit(T_OsdkWork *work) {
|
||||
memset(work, 0, sizeof(T_OsdkWork));
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkWork_AddNode(T_OsdkWork *work, T_OsdkWorkNode *node) {
|
||||
E_OsdkStat osdkStat;
|
||||
|
||||
if (!node || !work) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk add node param is NULL");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (node->taskFunc == NULL || node->name == NULL) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk work new node info is NULL");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
osdkStat = OsdkWork_CheckDuplicate(work, node);
|
||||
if (osdkStat != OSDK_STAT_OK) {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "osdk work add new node error:%d",
|
||||
osdkStat);
|
||||
return osdkStat;
|
||||
}
|
||||
OsdkList_AddTail(&node->head, &work->head);
|
||||
|
||||
work->workCnt++;
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk work add new node success:%d",
|
||||
work->workCnt);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkWork_DeleteNode(T_OsdkWork *work, T_OsdkWorkNode *node) {
|
||||
if (!node || !work) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk del node param is NULL");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
OsdkList_Del(&node->head);
|
||||
|
||||
work->workCnt--;
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk work del node success:%d",
|
||||
work->workCnt);
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
E_OsdkStat OsdkWork_CallWorkList(T_OsdkWork *work) {
|
||||
T_OsdkWorkNode *pNode = NULL;
|
||||
T_OsdkWorkNode *pBackup = NULL;
|
||||
|
||||
if (!work) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk call worklist param is NULL");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &work->head, head) {
|
||||
if (pNode->taskFunc != NULL) {
|
||||
pNode->taskFunc(pNode->arg);
|
||||
} else {
|
||||
OSDK_LOG_ERROR(MODULE_NAME_UTIL, "osdk call worklist param is NULL");
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static E_OsdkStat OsdkWork_CheckDuplicate(T_OsdkWork *work,
|
||||
T_OsdkWorkNode *node) {
|
||||
T_OsdkWorkNode *pNode = NULL;
|
||||
T_OsdkWorkNode *pBackup = NULL;
|
||||
|
||||
if (!work) {
|
||||
OSDK_LOG_INFO(MODULE_NAME_UTIL, "osdk check duplicate param is NULL");
|
||||
return OSDK_STAT_ERR_PARAM;
|
||||
}
|
||||
|
||||
if (work->workCnt > 0) {
|
||||
OSDK_LIST_FOR_EACH_ENTRY_SAFE(pNode, pBackup, &work->head, head) {
|
||||
if (strcmp(node->name, pNode->name) == 0) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_UTIL,
|
||||
"osdk work reg new node duplicate name:%s", node->name);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
|
||||
if (node->taskFunc == pNode->taskFunc) {
|
||||
OSDK_LOG_WARN(MODULE_NAME_UTIL,
|
||||
"osdk work reg new node duplicate func:%s", node->name);
|
||||
return OSDK_STAT_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OSDK_STAT_OK;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@@ -1,197 +0,0 @@
|
||||
/** @file dji_internal_command.cpp
|
||||
* @version 4.0
|
||||
* @date April 2020
|
||||
*
|
||||
* @brief All DJI OSDK internal Command IDs
|
||||
*
|
||||
* @Copyright (c) 2020 DJI
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dji_internal_command.hpp"
|
||||
|
||||
/*! v1 commands */
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Gimbal::resetAngle[] = {
|
||||
V1ProtocolCMD::CMDSet::gimbal, 0x4C
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Gimbal::rotateAngle[] = {
|
||||
V1ProtocolCMD::CMDSet::gimbal, 0x0A
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Common::getVersion[] = {
|
||||
V1ProtocolCMD::CMDSet::common, 0x01
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Common::downloadFile[] = {
|
||||
V1ProtocolCMD::CMDSet::common, 0x26
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Common::downloadFileAck[] = {
|
||||
V1ProtocolCMD::CMDSet::common, 0x27
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::fc::usbFlightMode[] = {
|
||||
V1ProtocolCMD::CMDSet::fc, 0x1B
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::fc::batteryInfo[] = {
|
||||
V1ProtocolCMD::CMDSet::fc, 0x51
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::SDK::obtainDownloadRight[] = {
|
||||
V1ProtocolCMD::CMDSet::sdk, 0x20
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::PSDK::IDVerification[] = {
|
||||
V1ProtocolCMD::CMDSet::psdk, 0x37
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::PSDK::uploadPolicyFile[] = {
|
||||
V1ProtocolCMD::CMDSet::psdk, 0x40
|
||||
};
|
||||
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::HMS::hmsStatus[] = {
|
||||
V1ProtocolCMD::CMDSet::hms, 0x05
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::HMS::hmsPushData[] = {
|
||||
V1ProtocolCMD::CMDSet::hms, 0x06
|
||||
};
|
||||
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::takePhoto[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x01
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::takeVideo[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x02
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x10
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x11
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setFocusParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xc4
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setExposureMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x1e
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getExposureMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x1f
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setFocusMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x24
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getFocusMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x25
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setEvParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x2e
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getEvParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x2f
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getFocusParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xc5
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setPointZoomMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xc4
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getPointZoomMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xc5
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::pointZoomCtrl[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xc6
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setZoomParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xb8
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setIsoParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x2a
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getIsoParameter[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x2b
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setShutterSpeed[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x28
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getShutterSpeed[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x29
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setApertureSize[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x26
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getApertureSize[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x27
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setMeteringMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x22
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getMeteringMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x23
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setSpotFocusAera[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x30
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getSpotFocusAera[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x31
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::setShotMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x6a
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::getShotMode[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0x6b
|
||||
};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::Camera::controlOptizoom[] = {
|
||||
V1ProtocolCMD::CMDSet::camera, 0xb8
|
||||
};
|
||||
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointInitV2[] = {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x01};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointUploadV2[] = {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x02};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointStartStopV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x03};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointSetGlobVelocityV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x05};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetGlobVelocityV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x06};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointResumePauseV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x07};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointDownloadInitV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x08};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointDownloadPtV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x09};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetMaxPtNumV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x0d};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetWayptIdxInListV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x0E};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointBreakRestoreV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x17};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointUploadActionV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x18};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointDownloadActionV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x19};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetRemainSpaceV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x1A};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetStatePushDataV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x1B};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetEventPushDataV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x1C};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetInfoV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x1D};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetMinMaxActionIDV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x1E};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::waypointV2::waypointGetBreakInfoV2[]= {
|
||||
V1ProtocolCMD::CMDSet::waypointV2, 0x27};
|
||||
const uint8_t DJI::OSDK::V1ProtocolCMD::BatteryCmd::getBatteryDynamicInfo[]= {
|
||||
V1ProtocolCMD::CMDSet::battery, 0x02};
|
||||
@@ -1,203 +0,0 @@
|
||||
/** @file dji_linker.cpp
|
||||
* @version 3.3
|
||||
* @date April 2017
|
||||
*
|
||||
* @brief
|
||||
* Vehicle API for DJI onboardSDK library
|
||||
*
|
||||
* @Copyright (c) 2019 DJI
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dji_linker.hpp"
|
||||
#include <new>
|
||||
|
||||
using namespace DJI;
|
||||
using namespace DJI::OSDK;
|
||||
|
||||
Linker::Linker(uint8_t defaultSenderId)
|
||||
:senderId(defaultSenderId)
|
||||
{
|
||||
uartPlugged = false;
|
||||
usbPlugged = false;
|
||||
}
|
||||
|
||||
Linker::~Linker()
|
||||
{
|
||||
deinit();
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::init()
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
|
||||
errCode = OsdkCore_RootTaskInit();
|
||||
if (errCode != OSDK_STAT_OK) {
|
||||
DERROR("Root Task Init Error!, Error Code : %d\n", errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
errCode = OsdkChannel_InitInstance();
|
||||
if (errCode != OSDK_STAT_OK) {
|
||||
DERROR("Channel Task Init Error!, Error Code : %d\n", errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
errCode = OsdkCommand_InitInstance();
|
||||
if (errCode != OSDK_STAT_OK) {
|
||||
DERROR("Command Task Init Error!", errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::deinit()
|
||||
{
|
||||
OsdkCommand_DeInit(OsdkCommand_GetInstance());
|
||||
OsdkCore_RootTaskDeInit();
|
||||
OsdkChannel_DeinitInstance();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Linker::isUartPlugged() {
|
||||
return uartPlugged;
|
||||
}
|
||||
|
||||
bool Linker::isUSBPlugged() {
|
||||
return usbPlugged;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::addUartChannel(const char *device, uint32_t baudrate,
|
||||
E_ChannelIDType id)
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkChannel_InitUartChannel(device, baudrate, id);
|
||||
bool ret = ((errCode == OSDK_STAT_OK) ? true : false);
|
||||
if (id == FC_UART_CHANNEL_ID) uartPlugged = ret;
|
||||
if (id == USB_ACM_CHANNEL_ID) usbPlugged = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
bool
|
||||
Linker::addUSBBulkChannel(uint16_t pid, uint16_t vid, uint16_t num, uint16_t epIn,
|
||||
uint16_t epOut, E_ChannelIDType id)
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkChannel_InitUSBBulkChannel(pid, vid, num, epIn, epOut, id);
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
Linker::sendAsync(T_CmdInfo *cmdInfo, const uint8_t *cmdData,
|
||||
Command_SendCallback func, void *userData,
|
||||
uint32_t timeOut, uint16_t retryTimes)
|
||||
{
|
||||
return OsdkCommand_SendAsync(OsdkCommand_GetInstance(), cmdInfo, cmdData,
|
||||
func, userData, timeOut, retryTimes);
|
||||
}
|
||||
|
||||
E_OsdkStat
|
||||
Linker::sendSync(T_CmdInfo *cmdInfo, const uint8_t *cmdData,
|
||||
T_CmdInfo *ackInfo, uint8_t *ackData,
|
||||
uint32_t timeOut, uint16_t retryTimes)
|
||||
{
|
||||
return OsdkCommand_SendSync(OsdkCommand_GetInstance(), cmdInfo, cmdData,
|
||||
ackInfo, ackData, timeOut, retryTimes);
|
||||
}
|
||||
|
||||
void
|
||||
Linker::setKey(const char *key)
|
||||
{
|
||||
OsdkCommand_SetKey(key);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Linker::setSenderId(uint8_t senderId) {
|
||||
this->senderId = senderId;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
Linker::getLocalSenderId() {
|
||||
return senderId;
|
||||
}
|
||||
|
||||
E_OsdkStat
|
||||
Linker::send(T_CmdInfo *cmdInfo, const uint8_t *cmdData)
|
||||
{
|
||||
return OsdkCommand_Send(cmdInfo, cmdData);
|
||||
}
|
||||
|
||||
E_OsdkStat
|
||||
Linker::sendAck(const T_CmdInfo *ackInfo, const uint8_t *ackData, uint16_t ackDataLen)
|
||||
{
|
||||
return OsdkCommand_SendAckData(ackInfo, ackData, ackDataLen);
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::registerCmdHandler(T_RecvCmdHandle *recvCmdHandle)
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkCommand_RegRecvCmdHandler(OsdkCommand_GetInstance(), recvCmdHandle);
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::createLiveViewTask()
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkCommand_CreateLiveViewTask();
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::destroyLiveViewTask()
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkCommand_DestroyLiveViewTask();
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::createAdvancedSensingTask()
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkCommand_CreateAdvancedSensingTask();
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
bool
|
||||
Linker::destroyAdvancedSensingTask()
|
||||
{
|
||||
E_OsdkStat errCode;
|
||||
errCode = OsdkCommand_DestroyAdvancedSensingTask();
|
||||
return (errCode == OSDK_STAT_OK) ? true : false;
|
||||
}
|
||||
|
||||
Arquivo executável → Arquivo normal
+3
-9
@@ -29,7 +29,6 @@
|
||||
#ifndef DJI_INTERNAL_COMMAND_H
|
||||
#define DJI_INTERNAL_COMMAND_H
|
||||
|
||||
#include "dji_error.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace DJI
|
||||
@@ -37,7 +36,7 @@ namespace DJI
|
||||
namespace OSDK
|
||||
{
|
||||
|
||||
class V1ProtocolCMD : public ErrorCode
|
||||
class V1ProtocolCMD
|
||||
{
|
||||
public:
|
||||
const static int MAX_CMD_ARRAY_SIZE = 2;
|
||||
@@ -60,6 +59,8 @@ class V1ProtocolCMD : public ErrorCode
|
||||
const static uint8_t getPointZoomMode[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t pointZoomCtrl[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t setZoomParameter[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t setCommonZoomPara[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t getCommonZoomPara[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t setIsoParameter[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t getIsoParameter[MAX_CMD_ARRAY_SIZE];
|
||||
const static uint8_t setShutterSpeed[MAX_CMD_ARRAY_SIZE];
|
||||
@@ -148,19 +149,12 @@ class V1ProtocolCMD : public ErrorCode
|
||||
const static uint8_t camera = 2;
|
||||
const static uint8_t fc = 3;
|
||||
const static uint8_t gimbal = 4;
|
||||
const static uint8_t center = 5;
|
||||
const static uint8_t rc = 6;
|
||||
const static uint8_t wifi = 7;
|
||||
const static uint8_t dm368 = 8;
|
||||
const static uint8_t ofdm = 9;
|
||||
const static uint8_t moBinocular = 10;
|
||||
const static uint8_t battery = 13;
|
||||
const static uint8_t rtk = 15;
|
||||
const static uint8_t waypointV2 = 34;
|
||||
const static uint8_t enterprise = 25;
|
||||
const static uint8_t hms = 33;
|
||||
const static uint8_t psdk = 60;
|
||||
const static uint8_t vb = 72;
|
||||
const static uint8_t sdk = 73;
|
||||
};
|
||||
};
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <stdint.h>
|
||||
#include "osdk_command_instance.h"
|
||||
#include "osdk_channel.h"
|
||||
#include "dji_log.hpp"
|
||||
#include "osdk_root_task.h"
|
||||
#include "osdk_device_id.h"
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*************************************************************************
|
||||
> File Name: mop.h
|
||||
> Author: dafeng.xu
|
||||
> Created Time: Mon 09 Dec 2019 12:09:58 PM CST
|
||||
************************************************************************/
|
||||
|
||||
#ifndef __MOP_H__
|
||||
#define __MOP_H__
|
||||
|
||||
#include "mop_osal.h"
|
||||
|
||||
typedef void * mop_channel_handle_t;
|
||||
|
||||
#define MOP_SUCCESS (0)
|
||||
#define MOP_ERR_FAILED (-10001)
|
||||
#define MOP_ERR_CRC (-10002)
|
||||
#define MOP_ERR_PARM (-10003)
|
||||
#define MOP_ERR_NOMEM (-10004)
|
||||
#define MOP_ERR_NOTREADY (-10005)
|
||||
#define MOP_ERR_SEND (-10006)
|
||||
#define MOP_ERR_RECV (-10007)
|
||||
#define MOP_ERR_TIMEOUT (-10008)
|
||||
#define MOP_ERR_RESBUSY (-10009)
|
||||
#define MOP_ERR_RESOCCUPIED (-10010)
|
||||
#define MOP_ERR_CONNECTIONCLOSE (-10011)
|
||||
#define MOP_ERR_CONNECTING (-10012)
|
||||
#define MOP_ERR_NORESOURSE (-10013)
|
||||
#define MOP_ERR_CLOSING (-10014)
|
||||
#define MOP_ERR_NOTCONNECT (-10015)
|
||||
#define MOP_ERR_LINKDISCONNECT (-10016)
|
||||
#define MOP_ERR_CONNECTREJECT (-10017)
|
||||
#define MOP_ERR_HASBINDED (-10018)
|
||||
#define MOP_ERR_STATEWRONG (-10019)
|
||||
#define MOP_ERR_NOTIMPLEMENT (-10100)
|
||||
|
||||
|
||||
#define MOP_WAIT_FOREVER (uint32_t)(-1)
|
||||
#define MOP_WAIT_POLLING (uint32_t)(0)
|
||||
|
||||
typedef enum {
|
||||
MOP_DEVICE_ROUTER = 0,
|
||||
MOP_DEVICE_MSDK,
|
||||
MOP_DEVICE_PSDK,
|
||||
MOP_DEVICE_OSDK
|
||||
}mop_device_t;
|
||||
|
||||
typedef enum {
|
||||
MOP_TRANS_RELIABLE,
|
||||
MOP_TRANS_UNRELIABLE
|
||||
}mop_trans_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mop_create_channel(mop_channel_handle_t *chl_handle, mop_trans_t trans);
|
||||
int32_t mop_destroy_channel(mop_channel_handle_t chl_handle);
|
||||
|
||||
int32_t mop_bind_channel(mop_channel_handle_t chl_handle, uint16_t channel_id);
|
||||
|
||||
int32_t mop_connect_channel(mop_channel_handle_t chl_handle,
|
||||
mop_device_t device,
|
||||
uint8_t slot,
|
||||
uint16_t channel_id);
|
||||
int32_t mop_accept_channel(mop_channel_handle_t chl_handle,
|
||||
mop_channel_handle_t *out_chl_handle);
|
||||
|
||||
int32_t mop_read_channel(mop_channel_handle_t chl_handle,
|
||||
void *buf, uint32_t length);
|
||||
int32_t mop_write_channel(mop_channel_handle_t chl_handle,
|
||||
void *buf, uint32_t length);
|
||||
|
||||
int32_t mop_close_channel(mop_channel_handle_t chl_handle);
|
||||
|
||||
int32_t mop_set_channel_opt(mop_channel_handle_t chl_handle);
|
||||
int32_t mop_add_multicast(mop_device_t device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Arquivo executável → Arquivo normal
@@ -0,0 +1,64 @@
|
||||
/*************************************************************************
|
||||
> File Name: mop.h
|
||||
> Author: dafeng.xu
|
||||
> Created Time: Mon 09 Dec 2019 12:09:58 PM CST
|
||||
************************************************************************/
|
||||
|
||||
#ifndef __MOP_OSAL_H__
|
||||
#define __MOP_OSAL_H__
|
||||
|
||||
#include "mop_platform.h"
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
#include "assert.h"
|
||||
|
||||
typedef void *mop_osal_task_t;
|
||||
typedef void *mop_osal_msgq_t;
|
||||
typedef void *mop_osal_sema_t;
|
||||
typedef void *mop_osal_mutex_t;
|
||||
typedef void *mop_osal_timer_t;
|
||||
|
||||
#define UNUSED(x) (x = x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mop_osal_task_create(const char *name, void (*start_routine)(void *),
|
||||
void *arg, uint16_t stack_size,
|
||||
mop_osal_task_t *task);
|
||||
int32_t mop_osal_task_join(mop_osal_task_t task);
|
||||
int32_t mop_osal_task_destroy(mop_osal_task_t task);
|
||||
|
||||
int32_t mop_osal_msleep(uint32_t time_ms);
|
||||
int32_t mop_osal_get_time_ms(uint32_t *time_ms);
|
||||
|
||||
int32_t mop_osal_msgq_create(const char *name, uint32_t length, mop_osal_msgq_t *msgq);
|
||||
int32_t mop_osal_msgq_destroy(mop_osal_msgq_t msgq);
|
||||
int32_t mop_osal_msgq_send(mop_osal_msgq_t msgq, void *message,
|
||||
uint32_t size, uint32_t timeout_ms);
|
||||
int32_t mop_osal_msgq_recv(mop_osal_msgq_t msgq, void *buffer,
|
||||
uint32_t *size, uint32_t timeout_ms);
|
||||
int32_t mop_osal_msgq_get_count(mop_osal_msgq_t msgq, uint32_t *count);
|
||||
|
||||
int32_t mop_osal_sema_create(mop_osal_sema_t *sema, uint32_t init_cnt);
|
||||
int32_t mop_osal_sema_destroy(mop_osal_sema_t sema);
|
||||
int32_t mop_osal_sema_wait(mop_osal_sema_t seam, uint32_t timeout_ms);
|
||||
int32_t mop_osal_sema_post(mop_osal_sema_t seam);
|
||||
|
||||
int32_t mop_osal_mutex_create(mop_osal_mutex_t *mutex);
|
||||
int32_t mop_osal_mutex_lock(mop_osal_mutex_t mutex);
|
||||
int32_t mop_osal_mutex_unlock(mop_osal_mutex_t mutex);
|
||||
int32_t mop_osal_mutex_destroy(mop_osal_mutex_t mutex);
|
||||
|
||||
int32_t mop_osal_timer_create(void (*timer_entry)(void), uint32_t timeout_ms,
|
||||
mop_osal_timer_t *timer);
|
||||
int32_t mop_osal_timer_destroy(mop_osal_timer_t timer);
|
||||
|
||||
void *mop_osal_malloc(uint32_t size);
|
||||
void mop_osal_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,148 @@
|
||||
#ifndef __MOP_PLATFORM_H_
|
||||
#define __MOP_PLATFORM_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if PSDK_ARCH_SYS_LINUX
|
||||
|
||||
#include "logger/psdk_logger_internal.h"
|
||||
|
||||
#define MOP_LOGF(...) PSDK_LOG_ERROR(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGE(...) PSDK_LOG_ERROR(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGW(...) PSDK_LOG_WARN(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGI(...) PSDK_LOG_INFO(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGT(...) PSDK_LOG_DEBUG(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGV(...) PSDK_LOG_DEBUG(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_OSDK
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "osdk_command.h"
|
||||
#include "osdk_command_instance.h"
|
||||
#include "osdk_logger_internal.h"
|
||||
|
||||
#define MOP_LOGF(...) OSDK_LOG_ERROR(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGE(...) OSDK_LOG_ERROR(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGW(...) OSDK_LOG_WARN(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGI(...) OSDK_LOG_INFO(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGT(...) OSDK_LOG_DEBUG(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
#define MOP_LOGV(...) OSDK_LOG_DEBUG(MODULE_NAME_MOP, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_DUSS
|
||||
#include <string.h>
|
||||
#include "duml_log.h"
|
||||
#include "duml_sketch.h"
|
||||
#include "duml_hal_core.h"
|
||||
#include "duml_mb_pack.h"
|
||||
#include "usb_bulk_raw_multich_v2.h"
|
||||
|
||||
#define MOP_LOGF(...) DUSS_LOGF(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
#define MOP_LOGE(...) DUSS_LOGE(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
#define MOP_LOGW(...) DUSS_LOGW(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
#define MOP_LOGI(...) DUSS_LOGI(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
#define MOP_LOGT(...) DUSS_LOGT(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
#define MOP_LOGV(...) DUSS_LOGV(DUSS_MODULE_SYSTEM, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "stdbool.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <mach/mach_init.h>
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
|
||||
typedef enum {
|
||||
// Only debug mode can print.
|
||||
MOPLogTagTypeF,
|
||||
// Only debug and release mode can print.
|
||||
MOPLogTagTypeError,
|
||||
// Only debug mode can print.
|
||||
MOPLogTagTypeWarning,
|
||||
// Only debug mode can print.
|
||||
MOPLogTagTypeInfo,
|
||||
// Only debug mode can print.
|
||||
MOPLogTagTypeT,
|
||||
// Only debug mode can print.
|
||||
MOPLogTagTypeVerbose
|
||||
} MOPLogTagType;
|
||||
|
||||
typedef void(*DJIMOPLogCenterPrintPointer) (const char* file_path, int logline, MOPLogTagType tag, const char *fmt, ...);
|
||||
|
||||
extern DJIMOPLogCenterPrintPointer mop_log_center_print;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void set_mop_log_center_print_pointer(DJIMOPLogCenterPrintPointer pointer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MOP_LOGF(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeF, __VA_ARGS__)
|
||||
#define MOP_LOGE(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeError, __VA_ARGS__)
|
||||
#define MOP_LOGW(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeWarning, __VA_ARGS__)
|
||||
#define MOP_LOGI(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeInfo, __VA_ARGS__)
|
||||
#define MOP_LOGT(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeT, __VA_ARGS__)
|
||||
#define MOP_LOGV(...) mop_log_center_print(__FILE__, __LINE__, MOPLogTagTypeVerbose, __VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "DJI_MOP_JNI"
|
||||
|
||||
typedef void(*MopLog) (int prio, const char* tag, const char* fmt, ...);
|
||||
|
||||
extern MopLog mopLog;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void set_mop_log_handle(const MopLog mopLog);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define UNUSED(x) (x = x)
|
||||
#define MSDK_USE_LOG true
|
||||
|
||||
#if MSDK_USE_LOG
|
||||
|
||||
#define MOP_LOGF(fmt, ...) mopLog( ANDROID_LOG_FATAL, LOG_TAG, "[Fatal]-[%s:%d]" fmt, __FILE__, __LINE__ , ##__VA_ARGS__)
|
||||
#define MOP_LOGE(fmt, ...) mopLog( ANDROID_LOG_ERROR, LOG_TAG, "[Error]-[%s:%d]" fmt, __FILE__, __LINE__ ,##__VA_ARGS__)
|
||||
#define MOP_LOGW(fmt, ...) mopLog( ANDROID_LOG_WARN, LOG_TAG, "[Warn]-[%s:%d]" fmt, __FILE__, __LINE__ ,##__VA_ARGS__)
|
||||
#define MOP_LOGI(fmt, ...) mopLog( ANDROID_LOG_INFO, LOG_TAG, "[Info]-[%s:%d]" fmt, __FILE__, __LINE__ ,##__VA_ARGS__)
|
||||
#define MOP_LOGT(fmt, ...) mopLog( ANDROID_LOG_INFO, LOG_TAG, "[T]-[%s:%d]" fmt, __FILE__, __LINE__ ,##__VA_ARGS__)
|
||||
#define MOP_LOGV(fmt, ...) mopLog( ANDROID_LOG_VERBOSE, LOG_TAG, "[Verbose]-[%s:%d]" fmt, __FILE__, __LINE__ ,##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
#define MOP_LOGF(...) mopLog( ANDROID_LOG_FATAL, LOG_TAG, ##__VA_ARGS__)
|
||||
#define MOP_LOGE(...) mopLog( ANDROID_LOG_ERROR, LOG_TAG, ##__VA_ARGS__)
|
||||
#define MOP_LOGW(...) mopLog( ANDROID_LOG_WARN, LOG_TAG, ##__VA_ARGS__)
|
||||
#define MOP_LOGI(...) mopLog( ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__)
|
||||
#define MOP_LOGT(...) mopLog( ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__)
|
||||
#define MOP_LOGV(...) mopLog( ANDROID_LOG_VERBOSE, LOG_TAG, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
+2
-3
@@ -32,9 +32,8 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osdk_logger_internal.h"
|
||||
#include "osdk_protocol_sdk.h"
|
||||
#include "osdk_protocol_v1.h"
|
||||
#include "osdk_protocol_usbmc.h"
|
||||
#include "osdk_typedef.h"
|
||||
#include "osdk_protocol_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
Arquivo binário não exibido.
@@ -38,6 +38,8 @@ namespace OSDK {
|
||||
// Forward Declarations
|
||||
class Vehicle;
|
||||
|
||||
/*! @brief Class providing APIs & data structures for acting as a MOP client
|
||||
*/
|
||||
class MopClient : MopPipelineManagerBase {
|
||||
public:
|
||||
MopClient(SlotType slot);
|
||||
|
||||
@@ -37,6 +37,9 @@ using namespace DJI::OSDK::MOP;
|
||||
|
||||
namespace DJI {
|
||||
namespace OSDK {
|
||||
|
||||
/*! @brief Class providing APIs & data structures MOP pipeline operations
|
||||
*/
|
||||
class MopPipeline {
|
||||
public:
|
||||
MopPipeline(PipelineID id, PipelineType type);
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace OSDK {
|
||||
// Forward Declarations
|
||||
class Vehicle;
|
||||
|
||||
/*! @brief Class providing APIs & data structures for acting as a MOP server
|
||||
*/
|
||||
class MopServer : MopPipelineManagerBase {
|
||||
public:
|
||||
MopServer();
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "osdk_command.h"
|
||||
#include "osdk_protocol.h"
|
||||
#include "dji_internal_command.hpp"
|
||||
#include "dji_log.hpp"
|
||||
|
||||
using namespace DJI;
|
||||
using namespace DJI::OSDK;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "osdk_md5.h"
|
||||
#include "osdk_policy.hpp"
|
||||
#include "dji_internal_command.hpp"
|
||||
#include "dji_log.hpp"
|
||||
|
||||
using namespace DJI;
|
||||
using namespace DJI::OSDK;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "dji_internal_command.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <core/protocol/osdk_device_id.h>
|
||||
#include "osdk_device_id.h"
|
||||
using namespace DJI;
|
||||
using namespace DJI::OSDK;
|
||||
|
||||
|
||||
@@ -32,15 +32,64 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hal)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/osal)
|
||||
|
||||
set(OSDK_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../../../osdk-lib/${ARCH})
|
||||
set(CMAKE_MODULE_PATH ${OSDK_LIB}/../cmake-modules)
|
||||
|
||||
set(OSDK_CORE_LIB ${OSDK_LIB}/osdk-core)
|
||||
set(ADVANCED_SENSING_LIB ${OSDK_LIB}/advanced-sensing-2.0.3)
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64|x86_64")
|
||||
set(ARCH x86)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=3)
|
||||
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch"))
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH armv7)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=1)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH armv8)
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=2)
|
||||
endif()
|
||||
elseif()
|
||||
add_definitions(-DDJIOSDK_HARDWARE_TYPE=0)
|
||||
endif()
|
||||
|
||||
set(OSDK_CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../osdk-core)
|
||||
set(CMAKE_MODULE_PATH ${OSDK_CORE_PATH}/cmake-modules)
|
||||
|
||||
#set(OSDK_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../../../osdk-lib/${ARCH})
|
||||
#set(CMAKE_MODULE_PATH ${OSDK_LIB}/../cmake-modules)
|
||||
|
||||
#set(OSDK_CORE_LIB ${OSDK_LIB}/osdk-core)
|
||||
#set(ADVANCED_SENSING_LIB ${OSDK_LIB}/advanced-sensing-2.0.3)
|
||||
#set(WP2_CORE_LIB ${OSDK_LIB}/waypointv2-core-1.0.0)
|
||||
|
||||
include_directories(${OSDK_CORE_LIB}/inc)
|
||||
include_directories(${ADVANCED_SENSING_LIB}/inc)
|
||||
#include_directories(${OSDK_CORE_LIB}/inc)
|
||||
#include_directories(${ADVANCED_SENSING_LIB}/inc)
|
||||
|
||||
message("-----------OSDK_LIB_HEADERS_DIR------------")
|
||||
set(OSDK_LIB_HEADERS_DIR
|
||||
${OSDK_CORE_PATH}/api/inc
|
||||
${OSDK_CORE_PATH}/modules/inc/payload
|
||||
${OSDK_CORE_PATH}/modules/inc/flight
|
||||
${OSDK_CORE_PATH}/modules/inc/mop
|
||||
${OSDK_CORE_PATH}/platform/inc
|
||||
${OSDK_CORE_PATH}/logger/inc
|
||||
${OSDK_CORE_PATH}/utility/inc
|
||||
${OSDK_CORE_PATH}/linker/${ARCH}/inc
|
||||
${OSDK_CORE_PATH}/modules/inc/filemgr
|
||||
)
|
||||
include_directories(${OSDK_LIB_HEADERS_DIR})
|
||||
message((${OSDK_LIB_HEADERS_DIR}))
|
||||
|
||||
|
||||
message("-----------ADVANCED_SENSING_HEADERS_DIR------------")
|
||||
set(ADVANCED_SENSING_SOURCE_ROOT ${OSDK_CORE_PATH}/advanced-sensing)
|
||||
set(ADVANCED_SENSING_HEADERS_DIR
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/api/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/platform/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/protocol/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/camera_stream/src
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/protocol/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/hal/inc
|
||||
${ADVANCED_SENSING_SOURCE_ROOT}/ori-osdk-core/platform/linux/inc
|
||||
)
|
||||
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
|
||||
message((${ADVANCED_SENSING_HEADERS_DIR}))
|
||||
|
||||
find_package(LibUSB REQUIRED)
|
||||
find_package(FFMPEG REQUIRED)
|
||||
@@ -61,10 +110,11 @@ include_directories(${FFMPEG_INCLUDE_DIR})
|
||||
|
||||
#link libraries
|
||||
|
||||
link_libraries(${OSDK_CORE_LIB}/lib/libdjiosdk-core.a)
|
||||
#link_libraries(${OSDK_CORE_LIB}/lib/libdjiosdk-core.a)
|
||||
|
||||
if(ADVANCED_SENSING)
|
||||
link_libraries(${ADVANCED_SENSING_LIB}/lib/libadvanced-sensing.a)
|
||||
link_libraries(advanced-sensing)
|
||||
link_libraries(djiosdk-core)
|
||||
link_libraries(${LIBUSB_1_LIBRARIES})
|
||||
link_libraries(${FFMPEG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário