NEW: release DJI Payload-SDK version 3.0
Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
This commit is contained in:
309
samples/sample_c/platform/linux/common/osal/osal.c
Normal file
309
samples/sample_c/platform/linux/common/osal/osal.c
Normal file
@ -0,0 +1,309 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal.h"
|
||||
#include "dji_typedef.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *), uint32_t stackSize, void *arg,
|
||||
T_DjiTaskHandle *task)
|
||||
{
|
||||
int result;
|
||||
char nameDealed[16] = {0};
|
||||
|
||||
*task = malloc(sizeof(pthread_t));
|
||||
if (*task == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_create(*task, NULL, taskFunc, arg);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (name != NULL)
|
||||
strncpy(nameDealed, name, sizeof(nameDealed) - 1);
|
||||
result = pthread_setname_np(*(pthread_t *) *task, nameDealed);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task)
|
||||
{
|
||||
pthread_cancel(*(pthread_t *) task);
|
||||
free(task);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs)
|
||||
{
|
||||
usleep(1000 * timeMs);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the mutex container, initialize the mutex, and
|
||||
* create mutex ID.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
*mutex = malloc(sizeof(pthread_mutex_t));
|
||||
if (*mutex == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_mutex_init(*mutex, NULL);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created mutex.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = pthread_mutex_destroy(mutex);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
free(mutex);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquire and lock the mutex when peripheral access is required
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_lock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock and release the mutex, when done with the peripheral access.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_unlock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the semaphore container, initialize the semaphore, and
|
||||
* create semaphore ID.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param initValue: initial value of semaphore.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
*semaphore = malloc(sizeof(sem_t));
|
||||
if (*semaphore == NULL) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = sem_init(*semaphore, 0, (unsigned int) initValue);
|
||||
if (result != 0) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created semaphore.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_destroy((sem_t *) semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(semaphore);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_wait(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param waitTime: timeout value of waiting semaphore, unit: millisecond.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime)
|
||||
{
|
||||
int result;
|
||||
struct timespec semaphoreWaitTime;
|
||||
struct timeval systemTime;
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
|
||||
systemTime.tv_usec += waitTime * 1000;
|
||||
if (systemTime.tv_usec >= 1000000) {
|
||||
systemTime.tv_sec += systemTime.tv_usec / 1000000;
|
||||
systemTime.tv_usec %= 1000000;
|
||||
}
|
||||
|
||||
semaphoreWaitTime.tv_sec = systemTime.tv_sec;
|
||||
semaphoreWaitTime.tv_nsec = systemTime.tv_usec * 1000;
|
||||
|
||||
result = sem_timedwait(semaphore, &semaphoreWaitTime);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the semaphore token.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_post(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for ms.
|
||||
* @return an uint32 that the time of system, uint:ms
|
||||
*/
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*ms = (time.tv_sec * 1000 + time.tv_usec / 1000);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*us = (time.tv_sec * 1000000 + time.tv_usec);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void *Osal_Malloc(uint32_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void Osal_Free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
75
samples/sample_c/platform/linux/common/osal/osal.h
Normal file
75
samples/sample_c/platform/linux/common/osal/osal.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal.h
|
||||
* @brief This is the header file for "osal.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_H
|
||||
#define OSAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *),
|
||||
uint32_t stackSize, void *arg, T_DjiTaskHandle *task);
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task);
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs);
|
||||
|
||||
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex);
|
||||
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex);
|
||||
|
||||
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime);
|
||||
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore);
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms);
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us);
|
||||
|
||||
void *Osal_Malloc(uint32_t size);
|
||||
void Osal_Free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
293
samples/sample_c/platform/linux/common/osal/osal_fs.c
Normal file
293
samples/sample_c/platform/linux/common/osal/osal_fs.c
Normal file
@ -0,0 +1,293 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal_fs.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "time.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj)
|
||||
{
|
||||
if (fileName == NULL || fileMode == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*fileObj = malloc(sizeof(FILE));
|
||||
if (*fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
*fileObj = fopen(fileName, fileMode);
|
||||
if (*fileObj == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
free(*fileObj);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fclose(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fwrite(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fread(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fseek(fileObj, offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fflush(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj)
|
||||
{
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*dirObj = opendir(filePath);
|
||||
if (*dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = closedir((DIR *) dirObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct dirent *dirent;
|
||||
|
||||
if (dirObj == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dirent = readdir((DIR *) dirObj);
|
||||
if (!dirent) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (dirent->d_type == DT_DIR) {
|
||||
fileInfo->isDir = true;
|
||||
} else {
|
||||
fileInfo->isDir = false;
|
||||
}
|
||||
strcpy(fileInfo->path, dirent->d_name);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = mkdir(filePath, S_IRWXU);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (filePath[strlen(filePath) - 1] == '/') {
|
||||
ret = rmdir(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = unlink(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (oldFilePath == NULL || newFilePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = rename(oldFilePath, newFilePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct stat st;
|
||||
int32_t ret;
|
||||
struct tm *fileTm;
|
||||
|
||||
if (filePath == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = stat(filePath, &st);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileTm = localtime(&(st.st_ctime));
|
||||
if (fileTm == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileInfo->size = st.st_size;
|
||||
|
||||
fileInfo->createTime.year = fileTm->tm_year + 1900 - 1980;
|
||||
fileInfo->createTime.month = fileTm->tm_mon;
|
||||
fileInfo->createTime.day = fileTm->tm_mday;
|
||||
fileInfo->createTime.hour = fileTm->tm_hour;
|
||||
fileInfo->createTime.minute = fileTm->tm_min;
|
||||
fileInfo->createTime.second = fileTm->tm_sec;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
73
samples/sample_c/platform/linux/common/osal/osal_fs.h
Normal file
73
samples/sample_c/platform/linux/common/osal/osal_fs.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.h
|
||||
* @brief This is the header file for "osal_fs.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_FS_H
|
||||
#define OSAL_FS_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset);
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo);
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath);
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_FS_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
272
samples/sample_c/platform/linux/common/osal/osal_socket.c
Normal file
272
samples/sample_c/platform/linux/common/osal/osal_socket.c
Normal file
@ -0,0 +1,272 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_socket.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal_socket.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int socketFd;
|
||||
} T_SocketHandleStruct;
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_Socket(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct;
|
||||
|
||||
if (socketHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
socketHandleStruct = malloc(sizeof(T_SocketHandleStruct));
|
||||
if (socketHandleStruct == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
if (mode == DJI_SOCKET_MODE_UDP) {
|
||||
socketHandleStruct->socketFd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
} else if (mode == DJI_SOCKET_MODE_TCP) {
|
||||
socketHandleStruct->socketFd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*socketHandle = socketHandleStruct;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Close(T_DjiSocketHandle socketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandleStruct->socketFd <= 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = close(socketHandleStruct->socketFd);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Bind(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
struct sockaddr_in addr;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = bind(socketHandleStruct->socketFd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_UdpSendData(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle <= 0 || ipAddr == NULL || port == 0 || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = sendto(socketHandleStruct->socketFd, buf, len, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_UdpRecvData(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
uint32_t addrLen = 0;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0 || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = recvfrom(socketHandleStruct->socketFd, buf, len, 0, (struct sockaddr *) &addr, &addrLen);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
strcpy(ipAddr, inet_ntoa(addr.sin_addr));
|
||||
*port = ntohs(addr.sin_port);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpListen(T_DjiSocketHandle socketHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
|
||||
if (socketHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = listen(socketHandleStruct->socketFd, 5);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpAccept(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
T_DjiSocketHandle *outSocketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
T_SocketHandleStruct *outSocketHandleStruct;
|
||||
struct sockaddr_in addr;
|
||||
uint32_t addrLen = 0;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
outSocketHandleStruct = malloc(sizeof(T_SocketHandleStruct));
|
||||
if (outSocketHandleStruct == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
outSocketHandleStruct->socketFd = accept(socketHandleStruct->socketFd, (struct sockaddr *) &addr, &addrLen);
|
||||
if (outSocketHandleStruct->socketFd < 0) {
|
||||
free(outSocketHandleStruct);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*port = ntohs(addr.sin_port);
|
||||
*outSocketHandle = outSocketHandleStruct;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpConnect(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = connect(socketHandleStruct->socketFd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpSendData(T_DjiSocketHandle socketHandle,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = send(socketHandleStruct->socketFd, buf, len, 0);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpRecvData(T_DjiSocketHandle socketHandle,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = recv(socketHandleStruct->socketFd, buf, len, 0);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
72
samples/sample_c/platform/linux/common/osal/osal_socket.h
Normal file
72
samples/sample_c/platform/linux/common/osal/osal_socket.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_socket.h
|
||||
* @brief This is the header file for "osal_socket.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_SOCKET_H
|
||||
#define OSAL_SOCKET_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_Socket(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_Close(T_DjiSocketHandle socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_Bind(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
|
||||
|
||||
T_DjiReturnCode Osal_UdpSendData(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_UdpRecvData(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_TcpListen(T_DjiSocketHandle socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_TcpAccept(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
T_DjiSocketHandle *outSocketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_TcpConnect(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
|
||||
|
||||
T_DjiReturnCode Osal_TcpSendData(T_DjiSocketHandle socketHandle,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_TcpRecvData(T_DjiSocketHandle socketHandle,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_SOCKET_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
Reference in New Issue
Block a user