NEW: release DJI Payload-SDK version 3.0
Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
This commit is contained in:
127
samples/sample_c/module_sample/utils/util_buffer.c
Normal file
127
samples/sample_c/module_sample/utils/util_buffer.c
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file util_buffer.c
|
||||
* @brief The file defines buffer related functions, including initialize, put data to buffer,
|
||||
* get data from buffer and get unused count of bytes of buffer.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "util_buffer.h"
|
||||
#include <string.h>
|
||||
#include "util_misc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Cut buffer size to power of 2, in order to increase the convenience of get and put operating of buffer.
|
||||
* @param bufSize Original buffer size.
|
||||
* @return Buffer size after handling.
|
||||
*/
|
||||
static uint16_t UtilBuffer_CutBufSizeToPowOfTwo(uint16_t bufSize)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
while ((1 << (++i)) <= bufSize);
|
||||
return (uint16_t) (1 << (--i));
|
||||
}
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Buffer initialization.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pBuf Pointer to data buffer.
|
||||
* @param bufSize Size of data buffer.
|
||||
* @return None.
|
||||
*/
|
||||
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize)
|
||||
{
|
||||
pthis->readIndex = 0;
|
||||
pthis->writeIndex = 0;
|
||||
pthis->bufferPtr = pBuf;
|
||||
pthis->bufferSize = UtilBuffer_CutBufSizeToPowOfTwo(bufSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put a block of data into buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pData Pointer to data to be stored.
|
||||
* @param dataLen Length of data to be stored.
|
||||
* @return Length of data to be stored.
|
||||
*/
|
||||
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen)
|
||||
{
|
||||
uint16_t writeUpLen;
|
||||
|
||||
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex));
|
||||
|
||||
//fill up data
|
||||
writeUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->writeIndex & (pthis->bufferSize - 1))));
|
||||
memcpy(pthis->bufferPtr + (pthis->writeIndex & (pthis->bufferSize - 1)), pData, writeUpLen);
|
||||
|
||||
//fill begin data
|
||||
memcpy(pthis->bufferPtr, pData + writeUpLen, dataLen - writeUpLen);
|
||||
|
||||
pthis->writeIndex += dataLen;
|
||||
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a block of data from buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pData Pointer to data to be read.
|
||||
* @param dataLen Length of data to be read.
|
||||
* @return Length of data to be read.
|
||||
*/
|
||||
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen)
|
||||
{
|
||||
uint16_t readUpLen;
|
||||
|
||||
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->writeIndex - pthis->readIndex));
|
||||
|
||||
//get up data
|
||||
readUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->readIndex & (pthis->bufferSize - 1))));
|
||||
memcpy(pData, pthis->bufferPtr + (pthis->readIndex & (pthis->bufferSize - 1)), readUpLen);
|
||||
|
||||
//get begin data
|
||||
memcpy(pData + readUpLen, pthis->bufferPtr, dataLen - readUpLen);
|
||||
|
||||
pthis->readIndex += dataLen;
|
||||
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get unused size of buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @return Unused size of buffer.
|
||||
*/
|
||||
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis)
|
||||
{
|
||||
return (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex);
|
||||
}
|
59
samples/sample_c/module_sample/utils/util_buffer.h
Normal file
59
samples/sample_c/module_sample/utils/util_buffer.h
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file util_buffer.h
|
||||
* @brief This is the header file for "util_buffer.c".
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _DJI_UTIL_BUFFER_H_
|
||||
#define _DJI_UTIL_BUFFER_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
//Note: not need lock for just one producer / one consumer
|
||||
//need mutex to protect for multi-producer / multi-consumer
|
||||
typedef struct {
|
||||
uint8_t *bufferPtr;
|
||||
uint16_t bufferSize;
|
||||
uint16_t readIndex;
|
||||
uint16_t writeIndex;
|
||||
} T_UtilBuffer;
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize);
|
||||
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen);
|
||||
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen);
|
||||
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis);
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
#endif
|
207
samples/sample_c/module_sample/utils/util_file.c
Normal file
207
samples/sample_c/module_sample/utils/util_file.c
Normal file
@ -0,0 +1,207 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_file.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include "util_file.h"
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime)
|
||||
{
|
||||
struct stat st;
|
||||
struct tm *fileTm;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (stat(filePath, &st) != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileTm = localtime(&(st.st_ctime));
|
||||
if (fileTm == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
createTime->year = fileTm->tm_year + 1900 - 1980;
|
||||
createTime->month = fileTm->tm_mon;
|
||||
createTime->day = fileTm->tm_mday;
|
||||
createTime->hour = fileTm->tm_hour;
|
||||
createTime->minute = fileTm->tm_min;
|
||||
createTime->second = fileTm->tm_sec;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (stat(filePath, &st) != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*fileSize = st.st_size;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint16_t len,
|
||||
uint8_t *data, uint16_t *realLen)
|
||||
{
|
||||
FILE *pF;
|
||||
T_DjiReturnCode psdkStat;
|
||||
uint32_t readRtn;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
pF = fopen(filePath, "rb+");
|
||||
if (pF == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (fseek(pF, offset, SEEK_SET) != 0) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
readRtn = fread(data, 1, len, pF);
|
||||
if (readRtn == 0 || readRtn > len) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*realLen = readRtn;
|
||||
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
fclose(pF);
|
||||
|
||||
return psdkStat;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_Delete(const char *filePath)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = unlink(filePath);
|
||||
|
||||
if (ret != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (file == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
long int curSeek = ftell(file);
|
||||
|
||||
result = fseek(file, 0L, SEEK_END);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
*fileSize = ftell(file);
|
||||
|
||||
if (curSeek < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
result = fseek(file, curSeek, SEEK_SET);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen)
|
||||
{
|
||||
T_DjiReturnCode psdkStat;
|
||||
uint32_t readRtn;
|
||||
|
||||
if (file == NULL) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fseek(file, offset, SEEK_SET) != 0) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
readRtn = fread(data, 1, len, file);
|
||||
if (readRtn == 0 || readRtn > len) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*realLen = readRtn;
|
||||
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
return psdkStat;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
70
samples/sample_c/module_sample/utils/util_file.h
Normal file
70
samples/sample_c/module_sample/utils/util_file.h
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_file.h
|
||||
* @brief This is the header file for "util_file.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_FILE_H
|
||||
#define UTIL_FILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_typedef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
uint32_t second: 5;
|
||||
uint32_t minute: 6;
|
||||
uint32_t hour: 5;
|
||||
uint32_t day: 5;
|
||||
uint32_t month: 4;
|
||||
uint32_t year: 7;
|
||||
} T_UtilFileCreateTime;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime);
|
||||
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize);
|
||||
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint16_t len,
|
||||
uint8_t *data, uint16_t *realLen);
|
||||
T_DjiReturnCode DjiFile_Delete(const char *filePath);
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize);
|
||||
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // UTIL_FILE_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
238
samples/sample_c/module_sample/utils/util_md5.c
Normal file
238
samples/sample_c/module_sample/utils/util_md5.c
Normal file
@ -0,0 +1,238 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_md5.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* crypto-algorithms
|
||||
* =================
|
||||
*
|
||||
* About
|
||||
* ---
|
||||
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
|
||||
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
|
||||
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
|
||||
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
|
||||
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
|
||||
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
|
||||
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
|
||||
* author.
|
||||
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
|
||||
* and should not be used in contexts that need cryptographically secure implementations.
|
||||
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
|
||||
* basic optimization techniques have been employed.
|
||||
* Building
|
||||
* ---
|
||||
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
|
||||
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
|
||||
* matters. Compiling them should be as easy as adding the relevent source code to the project.
|
||||
*
|
||||
* @statement DJI has modified some symbols' name.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "util_md5.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define ROTLEFT(a, b) ((a << b) | (a >> (32-b)))
|
||||
|
||||
#define F(x, y, z) ((x & y) | (~x & z))
|
||||
#define G(x, y, z) ((x & z) | (y & ~z))
|
||||
#define H(x, y, z) (x ^ y ^ z)
|
||||
#define I(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
#define FF(a, b, c, d, m, s, t) { a += F(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define GG(a, b, c, d, m, s, t) { a += G(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define HH(a, b, c, d, m, s, t) { a += H(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define II(a, b, c, d, m, s, t) { a += I(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void UtilMd5_Transform(MD5_CTX *ctx, const BYTE *data)
|
||||
{
|
||||
WORD a, b, c, d, m[16], i, j;
|
||||
|
||||
// MD5 specifies big endian byte order, but this implementation assumes a little
|
||||
// endian byte order CPU. Reverse all the bytes upon input, and re-reverse them
|
||||
// on output (in md5_final()).
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4) {
|
||||
m[i] = (data[j]) + (data[j + 1] << 8) + (data[j + 2] << 16) + (data[j + 3] << 24);
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
|
||||
FF(a, b, c, d, m[0], 7, 0xd76aa478);
|
||||
FF(d, a, b, c, m[1], 12, 0xe8c7b756);
|
||||
FF(c, d, a, b, m[2], 17, 0x242070db);
|
||||
FF(b, c, d, a, m[3], 22, 0xc1bdceee);
|
||||
FF(a, b, c, d, m[4], 7, 0xf57c0faf);
|
||||
FF(d, a, b, c, m[5], 12, 0x4787c62a);
|
||||
FF(c, d, a, b, m[6], 17, 0xa8304613);
|
||||
FF(b, c, d, a, m[7], 22, 0xfd469501);
|
||||
FF(a, b, c, d, m[8], 7, 0x698098d8);
|
||||
FF(d, a, b, c, m[9], 12, 0x8b44f7af);
|
||||
FF(c, d, a, b, m[10], 17, 0xffff5bb1);
|
||||
FF(b, c, d, a, m[11], 22, 0x895cd7be);
|
||||
FF(a, b, c, d, m[12], 7, 0x6b901122);
|
||||
FF(d, a, b, c, m[13], 12, 0xfd987193);
|
||||
FF(c, d, a, b, m[14], 17, 0xa679438e);
|
||||
FF(b, c, d, a, m[15], 22, 0x49b40821);
|
||||
|
||||
GG(a, b, c, d, m[1], 5, 0xf61e2562);
|
||||
GG(d, a, b, c, m[6], 9, 0xc040b340);
|
||||
GG(c, d, a, b, m[11], 14, 0x265e5a51);
|
||||
GG(b, c, d, a, m[0], 20, 0xe9b6c7aa);
|
||||
GG(a, b, c, d, m[5], 5, 0xd62f105d);
|
||||
GG(d, a, b, c, m[10], 9, 0x02441453);
|
||||
GG(c, d, a, b, m[15], 14, 0xd8a1e681);
|
||||
GG(b, c, d, a, m[4], 20, 0xe7d3fbc8);
|
||||
GG(a, b, c, d, m[9], 5, 0x21e1cde6);
|
||||
GG(d, a, b, c, m[14], 9, 0xc33707d6);
|
||||
GG(c, d, a, b, m[3], 14, 0xf4d50d87);
|
||||
GG(b, c, d, a, m[8], 20, 0x455a14ed);
|
||||
GG(a, b, c, d, m[13], 5, 0xa9e3e905);
|
||||
GG(d, a, b, c, m[2], 9, 0xfcefa3f8);
|
||||
GG(c, d, a, b, m[7], 14, 0x676f02d9);
|
||||
GG(b, c, d, a, m[12], 20, 0x8d2a4c8a);
|
||||
|
||||
HH(a, b, c, d, m[5], 4, 0xfffa3942);
|
||||
HH(d, a, b, c, m[8], 11, 0x8771f681);
|
||||
HH(c, d, a, b, m[11], 16, 0x6d9d6122);
|
||||
HH(b, c, d, a, m[14], 23, 0xfde5380c);
|
||||
HH(a, b, c, d, m[1], 4, 0xa4beea44);
|
||||
HH(d, a, b, c, m[4], 11, 0x4bdecfa9);
|
||||
HH(c, d, a, b, m[7], 16, 0xf6bb4b60);
|
||||
HH(b, c, d, a, m[10], 23, 0xbebfbc70);
|
||||
HH(a, b, c, d, m[13], 4, 0x289b7ec6);
|
||||
HH(d, a, b, c, m[0], 11, 0xeaa127fa);
|
||||
HH(c, d, a, b, m[3], 16, 0xd4ef3085);
|
||||
HH(b, c, d, a, m[6], 23, 0x04881d05);
|
||||
HH(a, b, c, d, m[9], 4, 0xd9d4d039);
|
||||
HH(d, a, b, c, m[12], 11, 0xe6db99e5);
|
||||
HH(c, d, a, b, m[15], 16, 0x1fa27cf8);
|
||||
HH(b, c, d, a, m[2], 23, 0xc4ac5665);
|
||||
|
||||
II(a, b, c, d, m[0], 6, 0xf4292244);
|
||||
II(d, a, b, c, m[7], 10, 0x432aff97);
|
||||
II(c, d, a, b, m[14], 15, 0xab9423a7);
|
||||
II(b, c, d, a, m[5], 21, 0xfc93a039);
|
||||
II(a, b, c, d, m[12], 6, 0x655b59c3);
|
||||
II(d, a, b, c, m[3], 10, 0x8f0ccc92);
|
||||
II(c, d, a, b, m[10], 15, 0xffeff47d);
|
||||
II(b, c, d, a, m[1], 21, 0x85845dd1);
|
||||
II(a, b, c, d, m[8], 6, 0x6fa87e4f);
|
||||
II(d, a, b, c, m[15], 10, 0xfe2ce6e0);
|
||||
II(c, d, a, b, m[6], 15, 0xa3014314);
|
||||
II(b, c, d, a, m[13], 21, 0x4e0811a1);
|
||||
II(a, b, c, d, m[4], 6, 0xf7537e82);
|
||||
II(d, a, b, c, m[11], 10, 0xbd3af235);
|
||||
II(c, d, a, b, m[2], 15, 0x2ad7d2bb);
|
||||
II(b, c, d, a, m[9], 21, 0xeb86d391);
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
}
|
||||
|
||||
void UtilMd5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->datalen = 0;
|
||||
ctx->bitlen = 0;
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
ctx->data[ctx->datalen] = data[i];
|
||||
ctx->datalen++;
|
||||
if (ctx->datalen == 64) {
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
ctx->bitlen += 512;
|
||||
ctx->datalen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = ctx->datalen;
|
||||
|
||||
// Pad whatever data is left in the buffer.
|
||||
if (ctx->datalen < 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 56) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
} else if (ctx->datalen >= 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 64) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
memset(ctx->data, 0, 56);
|
||||
}
|
||||
|
||||
// Append to the padding the total message's length in bits and transform.
|
||||
ctx->bitlen += ctx->datalen * 8;
|
||||
ctx->data[56] = ctx->bitlen;
|
||||
ctx->data[57] = ctx->bitlen >> 8;
|
||||
ctx->data[58] = ctx->bitlen >> 16;
|
||||
ctx->data[59] = ctx->bitlen >> 24;
|
||||
ctx->data[60] = ctx->bitlen >> 32;
|
||||
ctx->data[61] = ctx->bitlen >> 40;
|
||||
ctx->data[62] = ctx->bitlen >> 48;
|
||||
ctx->data[63] = ctx->bitlen >> 56;
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
|
||||
// Since this implementation uses little endian byte ordering and MD uses big endian,
|
||||
// reverse all the bytes when copying the final state to the output hash.
|
||||
for (i = 0; i < 4; ++i) {
|
||||
hash[i] = (ctx->state[0] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 4] = (ctx->state[1] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 8] = (ctx->state[2] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
|
||||
}
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
88
samples/sample_c/module_sample/utils/util_md5.h
Normal file
88
samples/sample_c/module_sample/utils/util_md5.h
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_md5.h
|
||||
* @brief This is the header file for "util_md5.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* crypto-algorithms
|
||||
* =================
|
||||
*
|
||||
* About
|
||||
* ---
|
||||
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
|
||||
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
|
||||
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
|
||||
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
|
||||
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
|
||||
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
|
||||
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
|
||||
* author.
|
||||
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
|
||||
* and should not be used in contexts that need cryptographically secure implementations.
|
||||
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
|
||||
* basic optimization techniques have been employed.
|
||||
* Building
|
||||
* ---
|
||||
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
|
||||
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
|
||||
* matters. Compiling them should be as easy as adding the relevent source code to the project.
|
||||
*
|
||||
* @statement DJI has modified some symbols' name.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_MD5_H
|
||||
#define UTIL_MD5_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef unsigned char BYTE; // 8-bit byte
|
||||
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
|
||||
|
||||
typedef struct {
|
||||
BYTE data[64];
|
||||
WORD datalen;
|
||||
unsigned long long bitlen;
|
||||
WORD state[4];
|
||||
} MD5_CTX;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
void UtilMd5_Init(MD5_CTX *ctx);
|
||||
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len);
|
||||
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MD5_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
102
samples/sample_c/module_sample/utils/util_misc.c
Normal file
102
samples/sample_c/module_sample/utils/util_misc.c
Normal file
@ -0,0 +1,102 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_misc.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include <stdio.h>
|
||||
#include "util_misc.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
const char *baseStr = "[>>>>>>>>>>>>>---------------------------------------------------------------------------------------] 13%";
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath)
|
||||
{
|
||||
uint32_t i = strlen(filePath) - 1;
|
||||
uint32_t dirPathLen;
|
||||
|
||||
while (filePath[i] != '/') {
|
||||
i--;
|
||||
}
|
||||
|
||||
dirPathLen = i + 1;
|
||||
|
||||
if (dirPathLen + 1 > pathBufferSize) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
memcpy(dirPath, filePath, dirPathLen);
|
||||
dirPath[dirPathLen] = 0;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = popen(systemCmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData)
|
||||
{
|
||||
for (int j = 0; j < strlen(baseStr) + strlen(userData) + 4; ++j) {
|
||||
printf("\b");
|
||||
}
|
||||
|
||||
printf("[");
|
||||
for (int j = 0; j < totalProgress; ++j) {
|
||||
if (j < currentProgress) {
|
||||
printf("%c", '>');
|
||||
} else {
|
||||
printf("-");
|
||||
}
|
||||
}
|
||||
|
||||
printf("] ");
|
||||
printf("%3d%%", currentProgress);
|
||||
printf("%s", userData);
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
57
samples/sample_c/module_sample/utils/util_misc.h
Normal file
57
samples/sample_c/module_sample/utils/util_misc.h
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_misc.h
|
||||
* @brief This is the header file for "util_misc.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_MISC_H
|
||||
#define UTIL_MISC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define USER_UTIL_UNUSED(x) ((x) = (x))
|
||||
#define USER_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define USER_UTIL_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define USER_UTIL_IS_WORK_TURN(step, workfreq, taskfreq) (!((step) % (uint32_t) ((taskfreq) / (workfreq))))
|
||||
#define UTIL_OFFSETOF(type, member) ((size_t) & ((type *)0 )-> member)
|
||||
#define UTIL_ARRAY_SIZE(array) ((unsigned int) (sizeof(array) / sizeof((array)[0])))
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath);
|
||||
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MISC_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
62
samples/sample_c/module_sample/utils/util_time.c
Normal file
62
samples/sample_c/module_sample/utils/util_time.c
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_time.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include "util_time.h"
|
||||
#include <sys/resource.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void)
|
||||
{
|
||||
T_DjiRunTimeStamps timeStamps;
|
||||
struct rusage rusage;
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
timeStamps.realUsec = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
|
||||
|
||||
getrusage(RUSAGE_SELF, &rusage);
|
||||
timeStamps.userUsec =
|
||||
(rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
|
||||
timeStamps.sysUsec =
|
||||
(rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
|
||||
|
||||
return timeStamps;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
60
samples/sample_c/module_sample/utils/util_time.h
Normal file
60
samples/sample_c/module_sample/utils/util_time.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_time.h
|
||||
* @brief This is the header file for "util_time.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_UTIL_TIME_H
|
||||
#define DJI_UTIL_TIME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
uint64_t realUsec;
|
||||
uint64_t userUsec;
|
||||
uint64_t sysUsec;
|
||||
} T_DjiRunTimeStamps;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // DJI_DP_UTILS_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
Reference in New Issue
Block a user