Platform Porting
The header file for cross-platform related functions is dji_platform.h
. This document describes the key information and usage of the structure and function prototypes in the dji_platform.h
file.
Catalog
Definition, Enum and Struct
E_DjiHalUartNum
E_DjiSocketMode
T_DjiUartStatus
T_DjiTime
T_DjiFileInfo
T_DjiHalUartHandler
T_DjiHalUsbBulkChannelInfo
T_DjiHalUsbBulkInfo
T_DjiHalUsbBulkDeviceInfo
T_DjiHalUsbBulkHandler
T_DjiHalNetworkHandler
T_DjiOsalHandler
T_DjiFileSystemHandler
T_DjiSocketHandler
DjiPlatform_RegHalUartHandlerFunction
DjiPlatform_RegHalUsbBulkHandler
DjiPlatform_RegHalNetworkHandler
DjiPlatform_RegOsalHandler
DjiPlatform_RegFileSystemHandler
DjiPlatform_RegSocketHandler
DjiPlatform_GetOsalHandler
DjiPlatform_GetFileSystemHandler
DjiPlatform_GetSocketHandler
Definition
typedef void *T_DjiUartHandle;
typedef void *T_DjiUsbBulkHandle;
typedef void *T_DjiNetworkHandle;
typedef void *T_DjiTaskHandle;
typedef void *T_DjiMutexHandle;
typedef void *T_DjiSemaHandle;
typedef void *T_DjiFileHandle;
typedef void *T_DjiDirHandle;
typedef void *T_DjiSocketHandle;
Enum
typedef enum E_DjiHalUartNum
typedef enum {
DJI_HAL_UART_NUM_0,
DJI_HAL_UART_NUM_1,
} E_DjiHalUartNum;
typedef enum E_DjiSocketMode
typedef enum {
DJI_SOCKET_MODE_UDP,
DJI_SOCKET_MODE_TCP,
} E_DjiSocketMode;
Struct
typedef struct T_DjiUartStatus
typedef struct {
bool isConnect;
} T_DjiUartStatus;
typedef struct T_DjiTime
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} T_DjiTime;
typedef struct T_DjiFileInfo
typedef struct {
uint32_t size;
T_DjiTime createTime;
T_DjiTime modifyTime;
char path[DJI_FILE_PATH_SIZE_MAX];
bool isDir;
} T_DjiFileInfo;
typedef struct T_DjiHalUartHandler
typedef struct {
T_DjiReturnCode (*UartInit)(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle);
T_DjiReturnCode (*UartDeInit)(T_DjiUartHandle uartHandle);
T_DjiReturnCode (*UartWriteData)(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*UartReadData)(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*UartGetStatus)(E_DjiHalUartNum uartNum, T_DjiUartStatus *status);
} T_DjiHalUartHandler;
typedef struct T_DjiHalUsbBulkChannelInfo
typedef struct {
uint16_t interfaceNum;
uint16_t endPointIn;
uint16_t endPointOut;
} T_DjiHalUsbBulkChannelInfo;
typedef struct T_DjiHalUsbBulkInfo
typedef struct {
bool isUsbHost;
// attention: if 'isUsbHost' equals false, the following parameters is not valid.
uint16_t pid;
uint16_t vid;
T_DjiHalUsbBulkChannelInfo channelInfo;
} T_DjiHalUsbBulkInfo;
typedef struct T_DjiHalUsbBulkDeviceInfo
typedef struct {
uint16_t pid;
uint16_t vid;
uint8_t bulkChannelNum;
T_DjiHalUsbBulkChannelInfo *channelInfo;
} T_DjiHalUsbBulkDeviceInfo;
typedef struct T_DjiHalUsbBulkHandler
typedef struct {
T_DjiReturnCode (*UsbBulkInit)(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle);
T_DjiReturnCode (*UsbBulkDeInit)(T_DjiUsbBulkHandle usbBulkHandle);
T_DjiReturnCode (*UsbBulkWriteData)(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf,
uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*UsbBulkReadData)(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf,
uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*UsbBulkGetDeviceInfo)(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
} T_DjiHalUsbBulkHandler;
typedef struct T_DjiHalNetworkHandler
typedef struct {
T_DjiReturnCode (*NetworkInit)(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *networkHandle);
T_DjiReturnCode (*NetworkDeInit)(T_DjiNetworkHandle networkHandle);
} T_DjiHalNetworkHandler;
typedef struct T_DjiOsalHandler
typedef struct {
T_DjiReturnCode (*TaskCreate)(const char *name, void *(*taskFunc)(void *),
uint32_t stackSize, void *arg, T_DjiTaskHandle *task);
T_DjiReturnCode (*TaskDestroy)(T_DjiTaskHandle task);
T_DjiReturnCode (*TaskSleepMs)(uint32_t timeMs);
T_DjiReturnCode (*MutexCreate)(T_DjiMutexHandle *mutex);
T_DjiReturnCode (*MutexDestroy)(T_DjiMutexHandle mutex);
T_DjiReturnCode (*MutexLock)(T_DjiMutexHandle mutex);
T_DjiReturnCode (*MutexUnlock)(T_DjiMutexHandle mutex);
T_DjiReturnCode (*SemaphoreCreate)(uint32_t initValue, T_DjiSemaHandle *semaphore);
T_DjiReturnCode (*SemaphoreDestroy)(T_DjiSemaHandle semaphore);
T_DjiReturnCode (*SemaphoreWait)(T_DjiSemaHandle semaphore);
T_DjiReturnCode (*SemaphoreTimedWait)(T_DjiSemaHandle semaphore, uint32_t waitTimeMs);
T_DjiReturnCode (*SemaphorePost)(T_DjiSemaHandle semaphore);
T_DjiReturnCode (*GetTimeMs)(uint32_t *ms);
T_DjiReturnCode (*GetTimeUs)(uint64_t *us);
void *(*Malloc)(uint32_t size);
void (*Free)(void *ptr);
} T_DjiOsalHandler;
typedef struct T_DjiFileSystemHandler
typedef struct {
T_DjiReturnCode (*FileOpen)(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj);
T_DjiReturnCode (*FileClose)(T_DjiFileHandle fileObj);
T_DjiReturnCode (*FileWrite)(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*FileRead)(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*FileSeek)(T_DjiFileHandle fileObj, uint32_t offset);
T_DjiReturnCode (*FileSync)(T_DjiFileHandle fileObj);
T_DjiReturnCode (*DirOpen)(const char *filePath, T_DjiDirHandle *dirObj);
T_DjiReturnCode (*DirClose)(T_DjiDirHandle dirObj);
T_DjiReturnCode (*DirRead)(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo);
T_DjiReturnCode (*Mkdir)(const char *filePath);
T_DjiReturnCode (*Unlink)(const char *filePath);
T_DjiReturnCode (*Rename)(const char *oldFilePath, const char *newFilePath);
T_DjiReturnCode (*Stat)(const char *filePath, T_DjiFileInfo *fileInfo);
} T_DjiFileSystemHandler;
typedef struct T_DjiSocketHandler
typedef struct {
T_DjiReturnCode (*Socket)(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle);
T_DjiReturnCode (*Close)(T_DjiSocketHandle socketHandle);
T_DjiReturnCode (*Bind)(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
T_DjiReturnCode (*UdpSendData)(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port,
const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*UdpRecvData)(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*TcpListen)(T_DjiSocketHandle socketHandle);
T_DjiReturnCode (*TcpAccept)(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
T_DjiSocketHandle *outSocketHandle);
T_DjiReturnCode (*TcpConnect)(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
T_DjiReturnCode (*TcpSendData)(T_DjiSocketHandle socketHandle,
const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode (*TcpRecvData)(T_DjiSocketHandle socketHandle,
uint8_t *buf, uint32_t len, uint32_t *realLen);
} T_DjiSocketHandler;
Function
function DjiPlatform_RegHalUartHandler
Function:Register the handler for hal uart interfaces by your platform. | product:all |
T_PsdkReturnCode DjiPlatform_RegHalUartHandler(const T_DjiHalUartHandler *halUartHandler);
halUartHandler:pointer to the handler for hal uart interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_RegHalUsbBulkHandler
Function:Register the handler for usb bulk interfaces by your platform. | product:all |
T_DjiReturnCode DjiPlatform_RegHalUsbBulkHandler(const T_DjiHalUsbBulkHandler *halUsbBulkHandler);
halUsbBulkHandler:pointer to the handler for usb bulk interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_RegHalNetworkHandler
Function:Register the handler for hal network interfaces by your platform. | product:all |
T_DjiReturnCode DjiPlatform_RegHalNetworkHandler(const T_DjiHalNetworkHandler *halNetworkHandler);
ParameterNotes:
- It should be noted that the interface in hal is written and tested well. Users need to implement all the interfaces. Otherwise, the user interface cannot be successfully registered, and then the user interface is registered through the interface. If the registration fails, it needs to be based on the return code. To judge the problem. Make sure that the feature is available after a successful registration.
- The interface needs to be called at the beginning of the application for registration, otherwise, the subsequent functions will not work properly.
halNetworkHandler:pointer to the handler for network handler interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_RegOsalHandler
Function:Register the handler for osal interfaces by your platform. | product:all |
T_DjiReturnCode DjiPlatform_RegOsalHandler(const T_DjiOsalHandler *osalHandler);
osalHandler:pointer to the handler for osal interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_RegFileSystemHandler
Function:Register the handler for file-system interfaces by your platform. | product:all |
T_DjiReturnCode DjiPlatform_RegFileSystemHandler(const T_DjiFileSystemHandler *fileSystemHandler);
fileSystemHandler:pointer to the handler for file-system interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_RegSocketHandler
Function:Register the handler for socket interfaces by your platform. | product:all |
T_DjiReturnCode DjiPlatform_RegSocketHandler(const T_DjiSocketHandler *socketHandler);
socketHandler:pointer to the handler for socket interfaces by your platform.
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_GetOsalHandler
Function:Get the handler of osal interfaces. | product:all |
T_DjiOsalHandler *DjiPlatform_GetOsalHandler(void);
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_GetFileSystemHandler
Function:Get the handler of file-system interfaces. | product:all |
T_DjiFileSystemHandler *DjiPlatform_GetFileSystemHandler(void);
Return
The details for the return code please refer to: DjiErrorCode
function DjiPlatform_GetSocketHandler
Function:Get the handler of socket interfaces. | product:all |
T_DjiSocketHandler *DjiPlatform_GetSocketHandler(void);
Return
The details for the return code please refer to: DjiErrorCode