first commit
This commit is contained in:
2688
PSDK/samples/sample_c/module_sample/utils/cJSON.c
Normal file
2688
PSDK/samples/sample_c/module_sample/utils/cJSON.c
Normal file
File diff suppressed because it is too large
Load Diff
290
PSDK/samples/sample_c/module_sample/utils/cJSON.h
Normal file
290
PSDK/samples/sample_c/module_sample/utils/cJSON.h
Normal file
@ -0,0 +1,290 @@
|
||||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 12
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON {
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks {
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*)cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_ParseByJsonData(const uint8_t *json_data, uint16_t data_len);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_ParseWithOpts(const char *value, const char **return_parse_end,
|
||||
cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *)cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *)cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *)cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_GetObjectItem(const cJSON *const object, const char *const string);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *)cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check if the item is a string and return its valuestring */
|
||||
CJSON_PUBLIC(char *)cJSON_GetStringValue(cJSON *item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_CreateStringArray(const char **strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *)cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(void)
|
||||
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
|
||||
CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
|
||||
CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *)cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable adress area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddNullToObject(cJSON *const object, const char *const name);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddTrueToObject(cJSON *const object, const char *const name);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddFalseToObject(cJSON *const object, const char *const name);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddObjectToObject(cJSON *const object, const char *const name);
|
||||
CJSON_PUBLIC(cJSON*)cJSON_AddArrayToObject(cJSON *const object, const char *const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *)cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
339
PSDK/samples/sample_c/module_sample/utils/dji_config_manager.c
Normal file
339
PSDK/samples/sample_c/module_sample/utils/dji_config_manager.c
Normal file
@ -0,0 +1,339 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_config_manager.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <utils/util_misc.h>
|
||||
#include <dji_logger.h>
|
||||
#include <utils/util_file.h>
|
||||
#include <dji_aircraft_info.h>
|
||||
#include "dji_config_manager.h"
|
||||
#include "utils/cJSON.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static T_DjiUserInfo s_configManagerUserInfo = {0};
|
||||
static T_DjiUserLinkConfig s_configManagerLinkInfo = {0};
|
||||
static bool s_configManagerIsEnable = false;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static T_DjiReturnCode DjiUserConfigManager_GetAppInfoInner(const char *path, T_DjiUserInfo *userInfo);
|
||||
static T_DjiReturnCode DjiUserConfigManager_GetLinkConfigInner(const char *path, T_DjiUserLinkConfig *linkConfig);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserConfigManager_LoadConfiguration(const char *path)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
if (path == NULL) {
|
||||
perror("Config file path is null.\n");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
printf("Load configuration start, config file path is: %s\r\n", path);
|
||||
|
||||
returnCode = DjiUserConfigManager_GetAppInfoInner(path, &s_configManagerUserInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
perror("Get app info failed.\n");
|
||||
}
|
||||
|
||||
returnCode = DjiUserConfigManager_GetLinkConfigInner(path, &s_configManagerLinkInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
perror("Get link info failed.\n");
|
||||
}
|
||||
|
||||
printf("\r\nLoad configuration successfully.\r\n");
|
||||
|
||||
s_configManagerIsEnable = true;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void DjiUserConfigManager_GetAppInfo(T_DjiUserInfo *userInfo)
|
||||
{
|
||||
memcpy(userInfo, &s_configManagerUserInfo, sizeof(T_DjiUserInfo));
|
||||
}
|
||||
|
||||
void DjiUserConfigManager_GetLinkConfig(T_DjiUserLinkConfig *linkConfig)
|
||||
{
|
||||
memcpy(linkConfig, &s_configManagerLinkInfo, sizeof(T_DjiUserLinkConfig));
|
||||
}
|
||||
|
||||
bool DjiUserConfigManager_IsEnable(void)
|
||||
{
|
||||
return s_configManagerIsEnable;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_DjiReturnCode DjiUserConfigManager_GetAppInfoInner(const char *path, T_DjiUserInfo *userInfo)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
uint32_t fileSize = 0;
|
||||
uint32_t readRealSize = 0;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
uint8_t *jsonData = NULL;
|
||||
cJSON *jsonRoot = NULL;
|
||||
cJSON *jsonItem = NULL;
|
||||
cJSON *jsonValue = NULL;
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
returnCode = UtilFile_GetFileSizeByPath(path, &fileSize);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Get file size by path failed, stat = 0x%08llX", returnCode);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
USER_LOG_DEBUG("Get config json file size is %d", fileSize);
|
||||
|
||||
jsonData = osalHandler->Malloc(fileSize + 1);
|
||||
if (jsonData == NULL) {
|
||||
USER_LOG_ERROR("Malloc failed.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
memset(jsonData, 0, fileSize);
|
||||
|
||||
UtilFile_GetFileDataByPath(path, 0, fileSize, jsonData, &readRealSize);
|
||||
|
||||
jsonData[readRealSize] = '\0';
|
||||
|
||||
jsonRoot = cJSON_Parse((char *) jsonData);
|
||||
if (jsonRoot == NULL) {
|
||||
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
goto jsonDataFree;
|
||||
}
|
||||
|
||||
jsonItem = cJSON_GetObjectItem(jsonRoot, "dji_sdk_app_info");
|
||||
if (jsonItem != NULL) {
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_name");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->appName, jsonValue->valuestring);
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_id");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->appId, jsonValue->valuestring);
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_key");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->appKey, jsonValue->valuestring);
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_app_license");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->appLicense, jsonValue->valuestring);
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_develop_account");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->developerAccount, jsonValue->valuestring);
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "user_baud_rate");
|
||||
if (jsonValue != NULL) {
|
||||
strcpy(userInfo->baudRate, jsonValue->valuestring);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(userInfo->appName) >= sizeof(userInfo->appName) ||
|
||||
strlen(userInfo->appId) > sizeof(userInfo->appId) ||
|
||||
strlen(userInfo->appKey) > sizeof(userInfo->appKey) ||
|
||||
strlen(userInfo->appLicense) > sizeof(userInfo->appLicense) ||
|
||||
strlen(userInfo->developerAccount) >= sizeof(userInfo->developerAccount) ||
|
||||
strlen(userInfo->baudRate) > sizeof(userInfo->baudRate)) {
|
||||
USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
|
||||
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
goto jsonDataFree;
|
||||
}
|
||||
|
||||
if (!strcmp(userInfo->appName, "your_app_name") ||
|
||||
!strcmp(userInfo->appId, "your_app_id") ||
|
||||
!strcmp(userInfo->appKey, "your_app_key") ||
|
||||
!strcmp(userInfo->appLicense, "your_app_license") ||
|
||||
!strcmp(userInfo->developerAccount, "your_developer_account") ||
|
||||
!strcmp(userInfo->baudRate, "your_baud_rate")) {
|
||||
USER_LOG_ERROR(
|
||||
"Please fill in correct user information to 'samples/sample_c++/platform/linux/manifold2/application/dji_sdk_config.json' file.");
|
||||
returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
goto jsonDataFree;
|
||||
}
|
||||
|
||||
jsonDataFree:
|
||||
osalHandler->Free(jsonData);
|
||||
#endif
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_DjiReturnCode DjiUserConfigManager_GetLinkConfigInner(const char *path, T_DjiUserLinkConfig *linkConfig)
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
uint32_t fileSize = 0;
|
||||
uint32_t readRealSize = 0;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
uint8_t *jsonData = NULL;
|
||||
cJSON *jsonRoot = NULL;
|
||||
cJSON *jsonItem = NULL;
|
||||
cJSON *jsonValue = NULL;
|
||||
cJSON *jsonConfig = NULL;
|
||||
int32_t configValue;
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
returnCode = UtilFile_GetFileSizeByPath(path, &fileSize);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Get file size by path failed, stat = 0x%08llX", returnCode);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
USER_LOG_DEBUG("Get config json file size is %d", fileSize);
|
||||
|
||||
jsonData = osalHandler->Malloc(fileSize + 1);
|
||||
if (jsonData == NULL) {
|
||||
USER_LOG_ERROR("Malloc failed.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
memset(jsonData, 0, fileSize);
|
||||
|
||||
UtilFile_GetFileDataByPath(path, 0, fileSize, jsonData, &readRealSize);
|
||||
|
||||
jsonData[readRealSize] = '\0';
|
||||
|
||||
jsonRoot = cJSON_Parse((char *) jsonData);
|
||||
if (jsonRoot == NULL) {
|
||||
goto jsonDataFree;
|
||||
}
|
||||
|
||||
jsonItem = cJSON_GetObjectItem(jsonRoot, "dji_sdk_link_config");
|
||||
if (jsonItem != NULL) {
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "link_select");
|
||||
if (jsonValue != NULL) {
|
||||
printf("\r\nSelect link type: %s\r\n", jsonValue->valuestring);
|
||||
if (strcmp(jsonValue->valuestring, "use_only_uart") == 0) {
|
||||
linkConfig->type = DJI_USER_LINK_CONFIG_USE_ONLY_UART;
|
||||
} else if (strcmp(jsonValue->valuestring, "use_uart_and_network_device") == 0) {
|
||||
linkConfig->type = DJI_USER_LINK_CONFIG_USE_UART_AND_NETWORK_DEVICE;
|
||||
} else if (strcmp(jsonValue->valuestring, "use_uart_and_usb_bulk_device") == 0) {
|
||||
linkConfig->type = DJI_USER_LINK_CONFIG_USE_UART_AND_USB_BULK_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "uart_config");
|
||||
if (jsonValue != NULL) {
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart1_device_name");
|
||||
printf("\r\nConfig uart1 device name: %s\r\n", jsonConfig->valuestring);
|
||||
strcpy(linkConfig->uartConfig.uart1DeviceName, jsonConfig->valuestring);
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart2_device_name");
|
||||
printf("Config uart2 device name: %s\r\n", jsonConfig->valuestring);
|
||||
strcpy(linkConfig->uartConfig.uart2DeviceName, jsonConfig->valuestring);
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "uart2_device_enable");
|
||||
printf("Config uart2 device enable: %s\r\n", jsonConfig->valuestring);
|
||||
if (strcmp(jsonConfig->valuestring, "true") == 0) {
|
||||
linkConfig->uartConfig.uart2DeviceEnable = true;
|
||||
} else {
|
||||
linkConfig->uartConfig.uart2DeviceEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "network_config");
|
||||
if (jsonValue != NULL) {
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_device_name");
|
||||
printf("\r\nConfig network device name: %s\r\n", jsonConfig->valuestring);
|
||||
strcpy(linkConfig->networkConfig.networkDeviceName, jsonConfig->valuestring);
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_usb_adapter_vid");
|
||||
printf("Config network usb adapter vid: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->networkConfig.networkUsbAdapterVid = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "network_usb_adapter_pid");
|
||||
printf("Config network usb adapter vid: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->networkConfig.networkUsbAdapterPid = configValue;
|
||||
}
|
||||
|
||||
jsonValue = cJSON_GetObjectItem(jsonItem, "usb_bulk_config");
|
||||
if (jsonValue != NULL) {
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_device_vid");
|
||||
printf("\r\nConfig usb device vid: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbDeviceVid = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_device_pid");
|
||||
printf("Config usb device pid: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbDevicePid = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_device_name");
|
||||
printf("Config usb bulk1 device name: %s\r\n", jsonConfig->valuestring);
|
||||
strcpy(linkConfig->usbBulkConfig.usbBulk1DeviceName, jsonConfig->valuestring);
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_interface_num");
|
||||
printf("Config usb bulk1 interface num: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbBulk1InterfaceNum = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_endpoint_in");
|
||||
printf("Config usb bulk1 endpoint in: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbBulk1EndpointIn = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk1_endpoint_out");
|
||||
printf("Config usb bulk1 endpoint out: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbBulk1EndpointOut = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_device_name");
|
||||
printf("Config usb bulk2 device name: %s\r\n", jsonConfig->valuestring);
|
||||
strcpy(linkConfig->usbBulkConfig.usbBulk2DeviceName, jsonConfig->valuestring);
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_interface_num");
|
||||
printf("Config usb bulk2 interface num: %s\r\n", jsonConfig->valuestring);
|
||||
sscanf(jsonConfig->valuestring, "%X", &configValue);
|
||||
linkConfig->usbBulkConfig.usbBulk2InterfaceNum = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_endpoint_in");
|
||||
printf("Config usb bulk2 endpoint in: %s\r\n", jsonConfig->valuestring);
|
||||
linkConfig->usbBulkConfig.usbBulk2EndpointIn = configValue;
|
||||
|
||||
jsonConfig = cJSON_GetObjectItem(jsonValue, "usb_bulk2_endpoint_out");
|
||||
printf("Config usb bulk2 endpoint out: %s\r\n", jsonConfig->valuestring);
|
||||
linkConfig->usbBulkConfig.usbBulk2EndpointOut = configValue;
|
||||
}
|
||||
}
|
||||
|
||||
jsonDataFree:
|
||||
osalHandler->Free(jsonData);
|
||||
#endif
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
@ -0,0 +1,88 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file dji_config_manager.h
|
||||
* @brief This is the header file for "dji_config_manager.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_CONFIG_MANAGER_H
|
||||
#define DJI_CONFIG_MANAGER_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
#include "dji_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define USER_DEVICE_NAME_STR_MAX_SIZE (64)
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
DJI_USER_LINK_CONFIG_USE_ONLY_UART,
|
||||
DJI_USER_LINK_CONFIG_USE_UART_AND_NETWORK_DEVICE,
|
||||
DJI_USER_LINK_CONFIG_USE_UART_AND_USB_BULK_DEVICE,
|
||||
} E_DjiUserLinkConfigType;
|
||||
|
||||
typedef struct {
|
||||
E_DjiUserLinkConfigType type;
|
||||
struct {
|
||||
char uart1DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
|
||||
bool uart2DeviceEnable;
|
||||
char uart2DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
|
||||
} uartConfig;
|
||||
struct {
|
||||
char networkDeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
|
||||
// M300/M350 RTK payload port no need
|
||||
uint16_t networkUsbAdapterVid;
|
||||
uint16_t networkUsbAdapterPid;
|
||||
} networkConfig;
|
||||
struct {
|
||||
uint16_t usbDeviceVid;
|
||||
uint16_t usbDevicePid;
|
||||
|
||||
char usbBulk1DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
|
||||
uint8_t usbBulk1InterfaceNum;
|
||||
uint8_t usbBulk1EndpointIn;
|
||||
uint8_t usbBulk1EndpointOut;
|
||||
|
||||
char usbBulk2DeviceName[USER_DEVICE_NAME_STR_MAX_SIZE];
|
||||
uint8_t usbBulk2InterfaceNum;
|
||||
uint8_t usbBulk2EndpointIn;
|
||||
uint8_t usbBulk2EndpointOut;
|
||||
} usbBulkConfig;
|
||||
} T_DjiUserLinkConfig;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserConfigManager_LoadConfiguration(const char *path);
|
||||
void DjiUserConfigManager_GetAppInfo(T_DjiUserInfo *userInfo);
|
||||
void DjiUserConfigManager_GetLinkConfig(T_DjiUserLinkConfig *linkConfig);
|
||||
bool DjiUserConfigManager_IsEnable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DJI_CONFIG_MANAGER_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
127
PSDK/samples/sample_c/module_sample/utils/util_buffer.c
Normal file
127
PSDK/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
PSDK/samples/sample_c/module_sample/utils/util_buffer.h
Normal file
59
PSDK/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
PSDK/samples/sample_c/module_sample/utils/util_file.c
Normal file
207
PSDK/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, uint32_t len,
|
||||
uint8_t *data, uint32_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
PSDK/samples/sample_c/module_sample/utils/util_file.h
Normal file
70
PSDK/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, uint32_t len,
|
||||
uint8_t *data, uint32_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******/
|
||||
218
PSDK/samples/sample_c/module_sample/utils/util_link_list.c
Normal file
218
PSDK/samples/sample_c/module_sample/utils/util_link_list.c
Normal file
@ -0,0 +1,218 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_link_list.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.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
#define UTIL_LINK_LIST_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "util_link_list.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void DjiUserUtil_ListNodeDeleteDataOnly( T_UtilListNode *node )
|
||||
{
|
||||
if ( NULL == node) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( NULL != node->data ) {
|
||||
UTIL_OSAL_MEMRY_FREE( node->data );
|
||||
node->data = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void DjiUserUtil_ListNodeDeleteNodeSelf( T_UtilListNode *node )
|
||||
{
|
||||
if ( NULL == node) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
UTIL_OSAL_MEMRY_FREE( node );
|
||||
return;
|
||||
}
|
||||
|
||||
void DjiUserUtil_InitListNode( T_UtilListNode *node, void *data )
|
||||
{
|
||||
if ( NULL == node ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
node->data = data;
|
||||
return;
|
||||
}
|
||||
|
||||
T_UtilListNode *DjiUserUtil_NewListNode( void *data )
|
||||
{
|
||||
T_UtilListNode *node = NULL;
|
||||
|
||||
node = (T_UtilListNode *)UTIL_OSAL_MEMRY_ALLOC( sizeof(T_UtilListNode) );
|
||||
if ( NULL == node ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DjiUserUtil_InitListNode( node, data );
|
||||
return node;
|
||||
}
|
||||
|
||||
void DjiUserUtil_LinkListDestory( T_UtilLinkList *linkList )
|
||||
{
|
||||
T_UtilListNode *node = NULL;
|
||||
T_UtilListNode *next = NULL;
|
||||
|
||||
if ( NULL == linkList ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
for ( node = linkList->first; NULL != node ; node = next ) {
|
||||
next = node->next;
|
||||
DjiUserUtil_ListNodeDeleteDataOnly( node );
|
||||
DjiUserUtil_ListNodeDeleteNodeSelf( node );
|
||||
}
|
||||
}
|
||||
void DjiUserUtil_LinkListAddNodeFirst( T_UtilLinkList *linkList, T_UtilListNode *node )
|
||||
{
|
||||
if ( ( NULL == linkList ) || ( NULL == node ) ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( UTIL_LINKLIST_IS_EMPTY( *linkList ) ) {
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
linkList->first = node;
|
||||
linkList->last = node;
|
||||
} else {
|
||||
node->prev = NULL;
|
||||
node->next = linkList->first;
|
||||
linkList->first = node;
|
||||
node->next->prev = node;
|
||||
}
|
||||
linkList->count ++;
|
||||
return;
|
||||
}
|
||||
|
||||
void DjiUserUtil_LinkListAddNodeLast( T_UtilLinkList *linkList, T_UtilListNode *node )
|
||||
{
|
||||
if ( ( NULL == linkList ) || ( NULL == node ) ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( UTIL_LINKLIST_IS_EMPTY( *linkList ) ) {
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
linkList->first = node;
|
||||
linkList->last = node;
|
||||
} else {
|
||||
node->next = NULL;
|
||||
node->prev = linkList->last;
|
||||
linkList->last = node;
|
||||
node->prev->next = node;
|
||||
}
|
||||
linkList->count ++;
|
||||
return;
|
||||
}
|
||||
|
||||
void DjiUserUtil_InitLinkList( T_UtilLinkList *linkList )
|
||||
{
|
||||
if ( NULL == linkList ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
linkList->first = NULL;
|
||||
linkList->last = NULL;
|
||||
linkList->count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
T_UtilLinkList *DjiUserUtil_NewLinkList( void )
|
||||
{
|
||||
T_UtilLinkList *linkList = NULL;
|
||||
|
||||
linkList = (T_UtilLinkList *)UTIL_OSAL_MEMRY_ALLOC( sizeof( T_UtilLinkList ) );
|
||||
if ( NULL == linkList ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DjiUserUtil_InitLinkList( linkList );
|
||||
return linkList;
|
||||
}
|
||||
|
||||
void DjiUserUtil_LinkListRemoveNodeOnly( T_UtilLinkList *linkList, T_UtilListNode *node )
|
||||
{
|
||||
if ( ( NULL == linkList ) || ( NULL == node ) ) {
|
||||
UTIL_REPORT_ERROR( "null pointer" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( node == linkList->first ) {
|
||||
linkList->first = linkList->first->next;
|
||||
}
|
||||
|
||||
if ( node == linkList->last ) {
|
||||
linkList->last = linkList->last->prev;
|
||||
}
|
||||
|
||||
if ( NULL != node->next ) {
|
||||
node->next->prev = node->prev;
|
||||
}
|
||||
|
||||
if ( NULL != node->prev ) {
|
||||
node->prev->next = node->next;
|
||||
}
|
||||
|
||||
if ( 0 != linkList->count ) {
|
||||
linkList->count --;
|
||||
}
|
||||
|
||||
DjiUserUtil_ListNodeDeleteNodeSelf( node );
|
||||
return;
|
||||
}
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
94
PSDK/samples/sample_c/module_sample/utils/util_link_list.h
Normal file
94
PSDK/samples/sample_c/module_sample/utils/util_link_list.h
Normal file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file link_list.h
|
||||
* @brief This is the header file for "link_list.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_LINK_LIST_H
|
||||
#define UTIL_LINK_LIST_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef UTIL_LINK_LIST_C
|
||||
#define UTIL_LINK_LIST_EXT
|
||||
#else
|
||||
#define UTIL_LINK_LIST_EXT extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define UTIL_REPORT_ERROR( exp... )
|
||||
|
||||
#define UTIL_OSAL_MEMRY_ALLOC(size) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); osalHandler->Malloc( size ); } )
|
||||
#define UTIL_OSAL_MEMRY_FREE(ptr) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); osalHandler->Free( ptr ); } )
|
||||
|
||||
#define UTIL_OSAL_SEM_FREE_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreDestroy( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_SEM_INIT_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreCreate( 0, sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_SEM_POST_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphorePost( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_SEM_WAIT_MAY_RETURN(sem) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreWait( sem ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_SEM_WAIT_FOR(sem,ms) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->SemaphoreTimedWait( sem, ms ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
|
||||
#define UTIL_OSAL_MUTEX_FREE_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexDestroy( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_MUTEX_INIT_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexCreate( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_MUTEX_LOCK_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexLock( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
#define UTIL_OSAL_MUTEX_UNLOCK_MAY_RETURN(mutex) ( { T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); if( DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS != osalHandler->MutexUnlock( mutex ) ) { return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } } )
|
||||
|
||||
#define UTIL_LINKLIST_IS_EMPTY(l) ( ((l).first == NULL) ? true : false )
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct tagT_UtilListNode {
|
||||
struct tagT_UtilListNode *next;
|
||||
struct tagT_UtilListNode *prev;
|
||||
void *data;
|
||||
} T_UtilListNode;
|
||||
|
||||
typedef struct tagT_UtilLinkList {
|
||||
T_UtilListNode *first;
|
||||
T_UtilListNode *last;
|
||||
uint32_t count;
|
||||
} T_UtilLinkList;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_ListNodeDeleteDataOnly( T_UtilListNode *node );
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_ListNodeDeleteNodeSelf( T_UtilListNode *node );
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_InitListNode( T_UtilListNode *node, void *data );
|
||||
UTIL_LINK_LIST_EXT T_UtilListNode *DjiUserUtil_NewListNode( void *data );
|
||||
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListDestory( T_UtilLinkList *linkList );
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListAddNodeFirst( T_UtilLinkList *linkList, T_UtilListNode *node );
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListAddNodeLast( T_UtilLinkList *linkList, T_UtilListNode *node );
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_InitLinkList( T_UtilLinkList *linkList );
|
||||
UTIL_LINK_LIST_EXT T_UtilLinkList *DjiUserUtil_NewLinkList( void );
|
||||
|
||||
UTIL_LINK_LIST_EXT void DjiUserUtil_LinkListRemoveNodeOnly( T_UtilLinkList *linkList, T_UtilListNode *node );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_LINK_LIST_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
238
PSDK/samples/sample_c/module_sample/utils/util_md5.c
Normal file
238
PSDK/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
PSDK/samples/sample_c/module_sample/utils/util_md5.h
Normal file
88
PSDK/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
PSDK/samples/sample_c/module_sample/utils/util_misc.c
Normal file
102
PSDK/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****/
|
||||
58
PSDK/samples/sample_c/module_sample/utils/util_misc.h
Normal file
58
PSDK/samples/sample_c/module_sample/utils/util_misc.h
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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);
|
||||
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MISC_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
62
PSDK/samples/sample_c/module_sample/utils/util_time.c
Normal file
62
PSDK/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
PSDK/samples/sample_c/module_sample/utils/util_time.h
Normal file
60
PSDK/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