NEW: sync the code of DJI Payload-SDK version 2.2.1 released on January 20 2021.
Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
This commit is contained in:
484
sample/platform/linux/common/monitor/sys_monitor.c
Normal file
484
sample/platform/linux/common/monitor/sys_monitor.c
Normal file
@ -0,0 +1,484 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file sys_monitor.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/11/10
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include "sys_monitor.h"
|
||||
#include "psdk_logger.h"
|
||||
#include "utils/util_misc.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define MONITOR_VMRSS_LINE 15
|
||||
#define MONITOR_PROCESS_ITEM 14
|
||||
#define MONITOR_CMD_BUF_SIZE 512
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static const char *Monitor_GetItems(const char *buffer, int ie);
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
int Monitor_GetPhyMem(pid_t p)
|
||||
{
|
||||
int i;
|
||||
char file[64] = {0};
|
||||
FILE *fd;
|
||||
char lineBuf[256] = {0};
|
||||
char name[32];
|
||||
int vmrss = 0; //memory peak
|
||||
char *ret = NULL;
|
||||
|
||||
sprintf(file, "/proc/%d/status", (int) p);
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogError("open file fail.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < MONITOR_VMRSS_LINE - 1; i++) {
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
USER_UTIL_UNUSED(ret);
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
sscanf(lineBuf, "%31s %d", name, &vmrss);
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
|
||||
return vmrss;
|
||||
}
|
||||
|
||||
int Monitor_GetTotalMem(void)
|
||||
{
|
||||
char *file = "/proc/meminfo";
|
||||
FILE *fd;
|
||||
char lineBuf[256] = {0};
|
||||
char name[32];
|
||||
int memtotal = 0;
|
||||
char *ret = NULL;
|
||||
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogError("open file fail.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
sscanf(lineBuf, "%31s %d", name, &memtotal);
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
|
||||
return memtotal;
|
||||
}
|
||||
|
||||
float Monitor_GetPmem(pid_t p)
|
||||
{
|
||||
int phy = Monitor_GetPhyMem(p);
|
||||
int total = Monitor_GetTotalMem();
|
||||
float occupy = (float) ((phy * 1.0) / (total * 1.0));
|
||||
|
||||
return occupy;
|
||||
}
|
||||
|
||||
unsigned int Monitor_GetCpuOccupyOfProcess(pid_t pid)
|
||||
{
|
||||
char file[64] = {0};
|
||||
T_MonitorProcessCpuOccupy t = {0};
|
||||
FILE *fd;
|
||||
char lineBuf[1024] = {0};
|
||||
char *q = NULL;
|
||||
char *ret = NULL;
|
||||
|
||||
sprintf(file, "/proc/%d/stat", (int) pid);
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogError("open file fail.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
sscanf(lineBuf, "%u", (unsigned int *) &t.pid);
|
||||
q = (char *) Monitor_GetItems(lineBuf, MONITOR_PROCESS_ITEM);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sscanf(q, "%u %u %u %u", &t.utime, &t.stime, &t.cutime, &t.cstime);
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
|
||||
return (t.utime + t.stime + t.cutime + t.cstime);
|
||||
}
|
||||
|
||||
unsigned int Monitor_GetCpuOccupyOfThread(pid_t pid, pid_t tid)
|
||||
{
|
||||
char file[64] = {0};
|
||||
T_MonitorProcessCpuOccupy t = {0};
|
||||
FILE *fd;
|
||||
char lineBuf[1024] = {0};
|
||||
char *q = NULL;
|
||||
char *ret = NULL;
|
||||
|
||||
sprintf(file, "/proc/%d/task/%d/stat", (int) pid, (int) tid);
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogError("open file fail.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
sscanf(lineBuf, "%u", (unsigned int *) &t.pid);
|
||||
q = (char *) Monitor_GetItems(lineBuf, MONITOR_PROCESS_ITEM);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sscanf(q, "%u %u %u %u", &t.utime, &t.stime, &t.cutime, &t.cstime);
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
|
||||
return (t.utime + t.stime + t.cutime + t.cstime);
|
||||
}
|
||||
|
||||
unsigned int Monitor_GetCpuTotalOccupy(void)
|
||||
{
|
||||
FILE *fd;
|
||||
char buff[1024] = {0};
|
||||
T_MonitorTotalCpuOccupy t = {0};
|
||||
char name[16];
|
||||
char *ret = NULL;
|
||||
|
||||
fd = fopen("/proc/stat", "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogError("open file fail.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fgets(buff, sizeof(buff), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
sscanf(buff, "%15s %u %u %u %u", name, &t.user, &t.nice, &t.system, &t.idle);
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
|
||||
return (t.user + t.nice + t.system + t.idle);
|
||||
}
|
||||
|
||||
float Monitor_GetPcpuOfThread(pid_t pid, pid_t tid)
|
||||
{
|
||||
FILE *fp;
|
||||
char cmdStr[MONITOR_CMD_BUF_SIZE];
|
||||
char lineBuf[256] = {0};
|
||||
pid_t tidInCommandLine = 0;
|
||||
float pcpuInCommandLine = 0.0f;
|
||||
int ret;
|
||||
char *q = NULL;
|
||||
|
||||
snprintf(cmdStr, MONITOR_CMD_BUF_SIZE, "ps -mp %d -o tid,pcpu", (int) pid);
|
||||
fp = popen(cmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
PsdkLogger_UserLogError("fp is null.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(lineBuf, sizeof(lineBuf), fp) != NULL) {
|
||||
q = (char *) Monitor_GetItems(lineBuf, 1);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sscanf(q, "%u", (unsigned int *) &tidInCommandLine);
|
||||
|
||||
if (tidInCommandLine == tid) {
|
||||
q = (char *) Monitor_GetItems(lineBuf, 2);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = sscanf(q, "%f", &pcpuInCommandLine);
|
||||
if (ret <= 0) {
|
||||
PsdkLogger_UserLogError("get pcpu error.");
|
||||
pcpuInCommandLine = 0;
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
PsdkLogger_UserLogDebug("not found thread.");
|
||||
|
||||
out:
|
||||
pclose(fp);
|
||||
|
||||
return pcpuInCommandLine;
|
||||
}
|
||||
|
||||
unsigned int Monitor_GetThreadCountOfProcess(pid_t pid)
|
||||
{
|
||||
FILE *fp;
|
||||
char cmdStr[MONITOR_CMD_BUF_SIZE];
|
||||
unsigned int count;
|
||||
int ret;
|
||||
|
||||
snprintf(cmdStr, MONITOR_CMD_BUF_SIZE, "ps -T -p %d | wc -l", (int) pid);
|
||||
fp = popen(cmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
PsdkLogger_UserLogError("fp is null.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fscanf(fp, "%u", &count);
|
||||
if (ret <= 0) {
|
||||
PsdkLogger_UserLogError("get count error.");
|
||||
count = 0;
|
||||
goto out;
|
||||
}
|
||||
count--;
|
||||
|
||||
out:
|
||||
pclose(fp);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void Monitor_GetTidListOfProcess(pid_t pid, pid_t *tidList, unsigned int size)
|
||||
{
|
||||
int i = 0;
|
||||
FILE *fp;
|
||||
char cmdStr[MONITOR_CMD_BUF_SIZE];
|
||||
char lineBuf[256] = {0};
|
||||
int ret = 0;
|
||||
|
||||
if (Monitor_GetThreadCountOfProcess(pid) > size) {
|
||||
PsdkLogger_UserLogError("size is too small.");
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(cmdStr, MONITOR_CMD_BUF_SIZE, "ps -mp %d -o tid", (int) pid);
|
||||
fp = popen(cmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
PsdkLogger_UserLogError("fp is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(lineBuf, sizeof(lineBuf), fp) != NULL && i <= size) {
|
||||
ret = sscanf(lineBuf, "%u", (unsigned int *) &tidList[i]);
|
||||
if (ret > 0)
|
||||
i++;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
}
|
||||
|
||||
void Monitor_GetNameOfThread(pid_t pid, pid_t tid, char *name, unsigned int size)
|
||||
{
|
||||
char file[64] = {0};
|
||||
FILE *fd;
|
||||
char lineBuf[32] = {0};
|
||||
char *ret = NULL;
|
||||
|
||||
memset(name, 0, size);
|
||||
|
||||
sprintf(file, "/proc/%d/task/%d/comm", (int) pid, (int) tid);
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
PsdkLogger_UserLogDebug("open file fail.");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fd);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
if (lineBuf[strlen(lineBuf) - 1] == '\n')
|
||||
lineBuf[strlen(lineBuf) - 1] = '\0';
|
||||
strncpy(name, lineBuf, USER_UTIL_MIN(size - 1, sizeof(lineBuf)));
|
||||
|
||||
out:
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param pid
|
||||
* @return Unit: B.
|
||||
*/
|
||||
unsigned int Monitor_GetHeapUsed(pid_t pid)
|
||||
{
|
||||
FILE *fp;
|
||||
char cmdStr[MONITOR_CMD_BUF_SIZE];
|
||||
char lineBuf[256] = {0};
|
||||
int ret = 0;
|
||||
unsigned int heapUsed = 0;
|
||||
char *q = NULL;
|
||||
char *rett = NULL;
|
||||
|
||||
snprintf(cmdStr, MONITOR_CMD_BUF_SIZE, "cat /proc/%d/smaps | grep -A 18 heap | grep Private_Dirty", (int) pid);
|
||||
fp = popen(cmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
PsdkLogger_UserLogError("fp is null.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rett = fgets(lineBuf, sizeof(lineBuf), fp);
|
||||
if (rett == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
q = (char *) Monitor_GetItems(lineBuf, 2);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = sscanf(q, "%u", &heapUsed);
|
||||
if (ret <= 0) {
|
||||
PsdkLogger_UserLogError("can not find heapUsed.");
|
||||
heapUsed = 0;
|
||||
goto out;
|
||||
}
|
||||
heapUsed *= 1024;
|
||||
|
||||
out:
|
||||
pclose(fp);
|
||||
|
||||
return heapUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param pid
|
||||
* @return Unit: B.
|
||||
*/
|
||||
unsigned int Monitor_GetStackUsed(pid_t pid)
|
||||
{
|
||||
FILE *fp;
|
||||
char cmdStr[MONITOR_CMD_BUF_SIZE];
|
||||
char lineBuf[256] = {0};
|
||||
int ret = 0;
|
||||
unsigned int stackUsed = 0;
|
||||
char *q = NULL;
|
||||
char *rett = NULL;
|
||||
|
||||
snprintf(cmdStr, MONITOR_CMD_BUF_SIZE, "cat /proc/%d/smaps | grep -A 18 stack | grep Private_Dirty", (int) pid);
|
||||
fp = popen(cmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
PsdkLogger_UserLogError("fp is null.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rett = fgets(lineBuf, sizeof(lineBuf), fp);
|
||||
if (rett == NULL)
|
||||
goto out;
|
||||
|
||||
q = (char *) Monitor_GetItems(lineBuf, 2);
|
||||
if (q == NULL) {
|
||||
PsdkLogger_UserLogError("get item fail.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = sscanf(q, "%u", &stackUsed);
|
||||
if (ret <= 0) {
|
||||
PsdkLogger_UserLogError("can not find stackUsed.");
|
||||
stackUsed = 0;
|
||||
goto out;
|
||||
}
|
||||
stackUsed *= 1024;
|
||||
|
||||
out:
|
||||
pclose(fp);
|
||||
|
||||
return stackUsed;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static const char *Monitor_GetItems(const char *buffer, int ie)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
char *p = (char *) buffer;
|
||||
int len = (int) strlen(buffer);
|
||||
int count = 0;
|
||||
|
||||
if (1 == ie || ie < 1) {
|
||||
return p;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
for (i = j; i < len; i++) {
|
||||
if (*(buffer + i) != ' ') {
|
||||
count++;
|
||||
|
||||
if (count == ie)
|
||||
return buffer + i;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = i; j < len; ++j) {
|
||||
if (*(buffer + j) == ' ')
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == len || j == len)
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
78
sample/platform/linux/common/monitor/sys_monitor.h
Normal file
78
sample/platform/linux/common/monitor/sys_monitor.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file sys_monitor.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/11/10
|
||||
* @brief This is the header file for "sys_monitor.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef SYS_MONITOR_H
|
||||
#define SYS_MONITOR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "psdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
unsigned int user;
|
||||
unsigned int nice;
|
||||
unsigned int system;
|
||||
unsigned int idle;
|
||||
} T_MonitorTotalCpuOccupy;
|
||||
|
||||
typedef struct {
|
||||
pid_t pid;
|
||||
unsigned int utime;
|
||||
unsigned int stime;
|
||||
unsigned int cutime;
|
||||
unsigned int cstime;
|
||||
} T_MonitorProcessCpuOccupy;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
int Monitor_GetPhyMem(pid_t p);
|
||||
int Monitor_GetTotalMem();
|
||||
unsigned int Monitor_GetCpuTotalOccupy();
|
||||
unsigned int Monitor_GetCpuOccupyOfProcess(pid_t pid);
|
||||
unsigned int Monitor_GetCpuOccupyOfThread(pid_t pid, pid_t tid);
|
||||
float Monitor_GetPcpuOfThread(pid_t pid, pid_t tid);
|
||||
float Monitor_GetPmem(pid_t p);
|
||||
unsigned int Monitor_GetThreadCountOfProcess(pid_t pid);
|
||||
void Monitor_GetTidListOfProcess(pid_t pid, pid_t *tidList, unsigned int size);
|
||||
void Monitor_GetNameOfThread(pid_t pid, pid_t tid, char *name, unsigned int size);
|
||||
unsigned int Monitor_GetHeapUsed(pid_t pid);
|
||||
unsigned int Monitor_GetStackUsed(pid_t pid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //SYS_MONITOR_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
294
sample/platform/linux/common/osal/osal.c
Normal file
294
sample/platform/linux/common/osal/osal.c
Normal file
@ -0,0 +1,294 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file psdk_osal.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal.h"
|
||||
#include "utils/util_misc.h"
|
||||
#include "psdk_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
T_PsdkReturnCode
|
||||
Osal_TaskCreate(T_PsdkTaskHandle *task, void *(*taskFunc)(void *), const char *name, uint32_t stackSize, void *arg)
|
||||
{
|
||||
int result;
|
||||
char nameDealed[16] = {0};
|
||||
|
||||
USER_UTIL_UNUSED(stackSize);
|
||||
|
||||
*task = malloc(sizeof(pthread_t));
|
||||
if (*task == NULL) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_create(*task, NULL, taskFunc, arg);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (name != NULL)
|
||||
strncpy(nameDealed, name, sizeof(nameDealed) - 1);
|
||||
result = pthread_setname_np(*(pthread_t * ) * task, nameDealed);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode Osal_TaskDestroy(T_PsdkTaskHandle task)
|
||||
{
|
||||
pthread_cancel(*(pthread_t *) task);
|
||||
free(task);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode Osal_TaskSleepMs(uint32_t timeMs)
|
||||
{
|
||||
usleep(1000 * timeMs);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the mutex container, initialize the mutex, and
|
||||
* create mutex ID.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_MutexCreate(T_PsdkMutexHandle *mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
*mutex = malloc(sizeof(pthread_mutex_t));
|
||||
if (*mutex == NULL) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_mutex_init(*mutex, NULL);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created mutex.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_MutexDestroy(T_PsdkMutexHandle mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = pthread_mutex_destroy(mutex);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
free(mutex);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquire and lock the mutex when peripheral access is required
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_MutexLock(T_PsdkMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_lock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock and release the mutex, when done with the peripheral access.
|
||||
* @param mutex: pointer to the created mutex ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_MutexUnlock(T_PsdkMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_unlock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare the semaphore container, initialize the semaphore, and
|
||||
* create semaphore ID.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param initValue: initial value of semaphore.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_SemaphoreCreate(T_PsdkSemHandle *semaphore, uint32_t initValue)
|
||||
{
|
||||
int result;
|
||||
|
||||
*semaphore = malloc(sizeof(sem_t));
|
||||
if (*semaphore == NULL) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = sem_init(*semaphore, 0, (unsigned int) initValue);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete the created semaphore.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_SemaphoreDestroy(T_PsdkSemHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_destroy((sem_t *) semaphore);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(semaphore);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_SemaphoreWait(T_PsdkSemHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_wait(semaphore);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait the semaphore until token becomes available.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @param waitTime: timeout value of waiting semaphore, unit: millisecond.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_SemaphoreTimedWait(T_PsdkSemHandle semaphore, uint32_t waitTime)
|
||||
{
|
||||
int result;
|
||||
struct timespec semaphoreWaitTime;
|
||||
struct timeval systemTime;
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
|
||||
systemTime.tv_usec += waitTime * 1000;
|
||||
if (systemTime.tv_usec >= 1000000) {
|
||||
systemTime.tv_sec += systemTime.tv_usec / 1000000;
|
||||
systemTime.tv_usec %= 1000000;
|
||||
}
|
||||
|
||||
semaphoreWaitTime.tv_sec = systemTime.tv_sec;
|
||||
semaphoreWaitTime.tv_nsec = systemTime.tv_usec * 1000;
|
||||
|
||||
result = sem_timedwait(semaphore, &semaphoreWaitTime);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the semaphore token.
|
||||
* @param semaphore: pointer to the created semaphore ID.
|
||||
* @return an enum that represents a status of PSDK
|
||||
*/
|
||||
T_PsdkReturnCode Osal_SemaphorePost(T_PsdkSemHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_post(semaphore);
|
||||
if (result != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for ms.
|
||||
* @return an uint32 that the time of system, uint:ms
|
||||
*/
|
||||
T_PsdkReturnCode Osal_GetTimeMs(uint32_t *ms)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*ms = (time.tv_sec * 1000 + time.tv_usec / 1000);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void *Osal_Malloc(uint32_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void Osal_Free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
77
sample/platform/linux/common/osal/osal.h
Normal file
77
sample/platform/linux/common/osal/osal.h
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/28
|
||||
* @brief This is the header file for "osal.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_H
|
||||
#define OSAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include "psdk_typedef.h"
|
||||
|
||||
#include "psdk_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_PsdkReturnCode
|
||||
Osal_TaskCreate(T_PsdkTaskHandle *task, void *(*taskFunc)(void *), const char *name, uint32_t stackSize, void *arg);
|
||||
T_PsdkReturnCode Osal_TaskDestroy(T_PsdkTaskHandle task);
|
||||
T_PsdkReturnCode Osal_TaskSleepMs(uint32_t timeMs);
|
||||
|
||||
T_PsdkReturnCode Osal_MutexCreate(T_PsdkMutexHandle *mutex);
|
||||
T_PsdkReturnCode Osal_MutexDestroy(T_PsdkMutexHandle mutex);
|
||||
T_PsdkReturnCode Osal_MutexLock(T_PsdkMutexHandle mutex);
|
||||
T_PsdkReturnCode Osal_MutexUnlock(T_PsdkMutexHandle mutex);
|
||||
|
||||
T_PsdkReturnCode Osal_SemaphoreCreate(T_PsdkSemHandle *semaphore, uint32_t initValue);
|
||||
T_PsdkReturnCode Osal_SemaphoreDestroy(T_PsdkSemHandle semaphore);
|
||||
T_PsdkReturnCode Osal_SemaphoreWait(T_PsdkSemHandle semaphore);
|
||||
T_PsdkReturnCode Osal_SemaphoreTimedWait(T_PsdkSemHandle semaphore, uint32_t waitTime);
|
||||
T_PsdkReturnCode Osal_SemaphorePost(T_PsdkSemHandle semaphore);
|
||||
|
||||
T_PsdkReturnCode Osal_GetTimeMs(uint32_t *ms);
|
||||
void *Osal_Malloc(uint32_t size);
|
||||
void Osal_Free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
@ -0,0 +1,219 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file upgrade_platform_opt_linux.c
|
||||
* @version V2.0.0
|
||||
* @date 3/25/20
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "upgrade_platform_opt_linux.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <psdk_logger.h>
|
||||
#include <psdk_upgrade.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define PSDK_TEST_CMD_CALL_MAX_LEN (PSDK_FILE_PATH_SIZE_MAX + 256)
|
||||
#define PSDK_REBOOT_STATE_FILE_NAME "reboot_state"
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static FILE *s_upgradeProgramFile = NULL;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static T_PsdkReturnCode PsdkTest_RunSystemCmd(char *systemCmdStr);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_RebootSystem(void)
|
||||
{
|
||||
// attention: you need su permission to reboot system
|
||||
return PsdkTest_RunSystemCmd("reboot -h now");
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea(void)
|
||||
{
|
||||
char cmdBuffer[PSDK_TEST_CMD_CALL_MAX_LEN];
|
||||
|
||||
snprintf(cmdBuffer, PSDK_TEST_CMD_CALL_MAX_LEN, "rm -rf %s*", PSDK_TEST_UPGRADE_FILE_DIR);
|
||||
|
||||
return PsdkTest_RunSystemCmd(cmdBuffer);
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_ReplaceOldProgram(void)
|
||||
{
|
||||
char cmdBuffer[PSDK_TEST_CMD_CALL_MAX_LEN];
|
||||
|
||||
snprintf(cmdBuffer, PSDK_TEST_CMD_CALL_MAX_LEN, "cp -f %s*_V*.*.*.bin %s", PSDK_TEST_UPGRADE_FILE_DIR,
|
||||
PSDK_TEST_UPGRADE_OLD_FIRMWARE_PATH);
|
||||
|
||||
return PsdkTest_RunSystemCmd(cmdBuffer);
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo)
|
||||
{
|
||||
FILE *rebootStateFile;
|
||||
size_t res;
|
||||
T_PsdkReturnCode returnCode;
|
||||
|
||||
rebootStateFile = fopen(PSDK_REBOOT_STATE_FILE_NAME, "w+");
|
||||
if (rebootStateFile == NULL) {
|
||||
PsdkLogger_UserLogError("Create reboot state file error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
res = fwrite((uint8_t *) upgradeEndInfo, 1, sizeof(T_PsdkUpgradeEndInfo), rebootStateFile);
|
||||
if (res != sizeof(T_PsdkUpgradeEndInfo)) {
|
||||
PsdkLogger_UserLogError("Write data len is not equal");
|
||||
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
fclose(rebootStateFile);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_GetUpgradeRebootState(bool *isUpgradeReboot,
|
||||
T_PsdkUpgradeEndInfo *upgradeEndInfo)
|
||||
{
|
||||
FILE *rebootStateFile;
|
||||
size_t res;
|
||||
|
||||
rebootStateFile = fopen(PSDK_REBOOT_STATE_FILE_NAME, "r");
|
||||
if (rebootStateFile == NULL) {
|
||||
*isUpgradeReboot = false;
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
res = fread(upgradeEndInfo, 1, sizeof(T_PsdkUpgradeEndInfo), rebootStateFile);
|
||||
if (res != sizeof(T_PsdkUpgradeEndInfo)) {
|
||||
PsdkLogger_UserLogError("Read data len is not equal");
|
||||
*isUpgradeReboot = false;
|
||||
goto out;
|
||||
}
|
||||
*isUpgradeReboot = true;
|
||||
|
||||
out:
|
||||
fclose(rebootStateFile);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CleanUpgradeRebootState(void)
|
||||
{
|
||||
return PsdkTest_RunSystemCmd("rm -f "PSDK_REBOOT_STATE_FILE_NAME);
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo)
|
||||
{
|
||||
char filePath[PSDK_FILE_PATH_SIZE_MAX];
|
||||
|
||||
s_upgradeProgramFile = NULL;
|
||||
snprintf(filePath, PSDK_FILE_PATH_SIZE_MAX, "%s%s", PSDK_TEST_UPGRADE_FILE_DIR, fileInfo->fileName);
|
||||
s_upgradeProgramFile = fopen(filePath, "w+");
|
||||
if (s_upgradeProgramFile == NULL) {
|
||||
PsdkLogger_UserLogError("Upgrade program file can't create");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode
|
||||
PsdkUpgradePlatformLinux_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
size_t writeLen;
|
||||
|
||||
if (s_upgradeProgramFile == NULL) {
|
||||
PsdkLogger_UserLogError("upgrade program file can't be NULL");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (fseek(s_upgradeProgramFile, offset, SEEK_SET) != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
writeLen = fwrite(data, 1, dataLen, s_upgradeProgramFile);
|
||||
if (writeLen != dataLen) {
|
||||
PsdkLogger_UserLogError("Write upgrade program file error, writeLen = %d, dataLen = %d", writeLen);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
|
||||
uint16_t *realLen)
|
||||
{
|
||||
uint32_t readRtn;
|
||||
|
||||
if (s_upgradeProgramFile == NULL) {
|
||||
PsdkLogger_UserLogError("upgrade program file can't be NULL");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (fseek(s_upgradeProgramFile, offset, SEEK_SET) != 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
readRtn = fread(data, 1, readDataLen, s_upgradeProgramFile);
|
||||
if (readRtn == 0 || readRtn > readDataLen) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
*realLen = readRtn;
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CloseUpgradeProgramFile(void)
|
||||
{
|
||||
if (s_upgradeProgramFile == NULL) {
|
||||
PsdkLogger_UserLogError("upgrade program file can't be NULL");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
fclose(s_upgradeProgramFile);
|
||||
s_upgradeProgramFile = NULL;
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_PsdkReturnCode PsdkTest_RunSystemCmd(char *systemCmdStr)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = system(systemCmdStr);
|
||||
if (status == -1 || WIFEXITED(status) == false) {
|
||||
PsdkLogger_UserLogError("Call %s error, status = %d", systemCmdStr, status);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (WEXITSTATUS(status) == 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
PsdkLogger_UserLogError("Exit status is = %d", WEXITSTATUS(status));
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
@ -0,0 +1,71 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file upgrade_platform_opt_linux.h
|
||||
* @version V2.0.0
|
||||
* @date 3/25/20
|
||||
* @brief This is the header file for "upgrade_platform_opt_linux.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UPGRADE_PLATFORM_OPT_LINUX_H
|
||||
#define UPGRADE_PLATFORM_OPT_LINUX_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include <psdk_typedef.h>
|
||||
#include <psdk_upgrade.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define PSDK_TEST_UPGRADE_OLD_FIRMWARE_PATH "/usr/local/bin/psdk_demo"
|
||||
#define PSDK_TEST_UPGRADE_FILE_DIR "/upgrade/"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_RebootSystem(void);
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea(void);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data,
|
||||
uint16_t dataLen);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
|
||||
uint16_t *realLen);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CloseUpgradeProgramFile(void);
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_ReplaceOldProgram(void);
|
||||
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_GetUpgradeRebootState(bool *isUpgradeReboot,
|
||||
T_PsdkUpgradeEndInfo *upgradeEndInfo);
|
||||
T_PsdkReturnCode PsdkUpgradePlatformLinux_CleanUpgradeRebootState(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UPGRADE_PLATFORM_OPT_LINUX_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
38
sample/platform/linux/manifold2/README.txt
Normal file
38
sample/platform/linux/manifold2/README.txt
Normal file
@ -0,0 +1,38 @@
|
||||
Payload SDK Linux Sample.
|
||||
|
||||
Test Environment:
|
||||
Hardware: Manifold2-C/G
|
||||
Serial: USB-to-Serial Controller CP210x
|
||||
C Compiler: GCC version 5.4.0 20160609
|
||||
CMake Version: Cmake version 3.5.1
|
||||
IDE: CLion 2020.3.1
|
||||
|
||||
Communication Serial Configuration:
|
||||
Baud Rate: 460800
|
||||
|
||||
Network Port Configuration:
|
||||
IP Address: Auto Config (Need root permission)
|
||||
Network Port: Auto Config
|
||||
NetMask: Auto Config
|
||||
Gateway: Auto Config
|
||||
|
||||
====== The steps to run the Payload SDK linux sample ======
|
||||
Step 1 : modify related device information, such as device name of network or uart, uart baud rate.
|
||||
|
||||
Step 2 : fill in your app info to file with path 'sample/platform/linux/manifold2/application/app_info.h'.
|
||||
This info can be obtained by logging in to the developer website https://developer.dji.com/payload-sdk.
|
||||
|
||||
Step 3 : build source file, use following cmd:
|
||||
cd source_code_dir/project
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
|
||||
Step 4 : Manifold should connect to Skyport 2.0/XPort via usb-to-serial controller and network cable, make sure the
|
||||
serial pins are connected properly.
|
||||
|
||||
Step 5 : use the root permission to execute this program, use following cmd:
|
||||
sudo ./psdk_demo
|
||||
|
||||
Step 6: open DJI Pilot APP/MSDK APP to use the payload demo functions.
|
57
sample/platform/linux/manifold2/application/app_info.h
Normal file
57
sample/platform/linux/manifold2/application/app_info.h
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file app_info.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief This is the header file for "app_info.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef APP_INFO_H
|
||||
#define APP_INFO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
// ATTENTION: User must goto developer.dji.com to create your own payload sdk application, get payload sdk application
|
||||
// information then fill in the application information here.
|
||||
#define USER_APP_NAME "your_app_name"
|
||||
#define USER_APP_ID "your_app_id"
|
||||
#define USER_APP_KEY "your_app_key"
|
||||
#define USER_DEVELOPER_ACCOUNT "your_developer_account"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //APP_INFO_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
506
sample/platform/linux/manifold2/application/main.c
Normal file
506
sample/platform/linux/manifold2/application/main.c
Normal file
@ -0,0 +1,506 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file main.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "errno.h"
|
||||
#include <signal.h>
|
||||
|
||||
#include "psdk_logger.h"
|
||||
#include "psdk_core.h"
|
||||
#include "psdk_platform.h"
|
||||
|
||||
#include "osal/osal.h"
|
||||
#include "utils/util_misc.h"
|
||||
#include "hal/hal_uart.h"
|
||||
#include "hal/hal_network.h"
|
||||
#include "psdk_config.h"
|
||||
#include "app_info.h"
|
||||
#include "psdk_aircraft_info.h"
|
||||
#include "camera_emu/test_payload_cam_emu.h"
|
||||
#include "data_transmission/test_data_transmission.h"
|
||||
#include "data_subscription/test_data_subscription.h"
|
||||
#include "payload_collaboration/test_payload_collaboration.h"
|
||||
#include "camera_media_emu/test_payload_cam_media.h"
|
||||
#include "widget/test_widget.h"
|
||||
#include "gimbal_emu/test_payload_gimbal_emu.h"
|
||||
#include "psdk_data_channel.h"
|
||||
#include "data_channel/test_data_channel.h"
|
||||
#include "power_management/test_power_management.h"
|
||||
#include "xport/test_xport.h"
|
||||
#include "monitor/sys_monitor.h"
|
||||
#include "psdk_product_info.h"
|
||||
#include "mop_channel/test_mop_channel.h"
|
||||
#include "upgrade/test_upgrade.h"
|
||||
#include "upgrade_platform_opt/upgrade_platform_opt_linux.h"
|
||||
#include <psdk_payload_camera.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define PSDK_LOG_PATH "Logs/psdk_local"
|
||||
#define PSDK_LOG_INDEX_FILE_NAME "Logs/latest"
|
||||
#define PSDK_LOG_FOLDER_NAME "Logs"
|
||||
#define PSDK_LOG_PATH_MAX_SIZE (128)
|
||||
#define PSDK_LOG_FOLDER_NAME_MAX_SIZE (32)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
pid_t tid;
|
||||
char name[16];
|
||||
float pcpu;
|
||||
} T_ThreadAttribute;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
static T_PsdkReturnCode PsdkUser_FillInUserInfo(T_PsdkUserInfo *userInfo);
|
||||
static T_PsdkReturnCode PsdkUser_Console(const uint8_t *data, uint16_t dataLen);
|
||||
static T_PsdkReturnCode PsdkUser_LocalWrite(const uint8_t *data, uint16_t dataLen);
|
||||
static T_PsdkReturnCode PsdkUser_FileSystemInit(const char *path);
|
||||
static void *PsdkUser_MonitorTask(void *argument);
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
static FILE *s_psdkLogFile;
|
||||
static FILE *s_psdkLogFileCnt;
|
||||
static pthread_t s_monitorThread = 0;
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
static T_PsdkReturnCode PsdkUser_FillInUserInfo(T_PsdkUserInfo *userInfo)
|
||||
{
|
||||
memset(userInfo->appName, 0, sizeof(userInfo->appName));
|
||||
memset(userInfo->appId, 0, sizeof(userInfo->appId));
|
||||
memset(userInfo->appKey, 0, sizeof(userInfo->appKey));
|
||||
memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount));
|
||||
|
||||
if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) ||
|
||||
strlen(USER_APP_ID) > sizeof(userInfo->appId) ||
|
||||
strlen(USER_APP_KEY) > sizeof(userInfo->appKey) ||
|
||||
strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount)) {
|
||||
PsdkLogger_UserLogError("Length of user information string is beyond limit. Please check.");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (!strcmp(USER_APP_NAME, "your_app_name") ||
|
||||
!strcmp(USER_APP_ID, "your_app_id") ||
|
||||
!strcmp(USER_APP_KEY, "your_app_key") ||
|
||||
!strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account")) {
|
||||
PsdkLogger_UserLogError("Please fill in correct user information to psdk_app_info.h file.");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1);
|
||||
memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID)));
|
||||
memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY)));
|
||||
strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_PsdkReturnCode PsdkUser_Console(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
USER_UTIL_UNUSED(dataLen);
|
||||
|
||||
/*
|
||||
* Warning: printf() is a blocking interface. If print speed is too low, PSDK will be blocked and many abnormal
|
||||
* situations occur, such as initialization failure and payload disconnection. Users can raise corresponding
|
||||
* console level to INFO or even higher to solve this problem.
|
||||
*/
|
||||
printf("%s", data);
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static T_PsdkReturnCode PsdkUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
|
||||
{
|
||||
int32_t realLen;
|
||||
|
||||
if (s_psdkLogFile == NULL) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
realLen = fwrite(data, 1, dataLen, s_psdkLogFile);
|
||||
fflush(s_psdkLogFile);
|
||||
if (realLen == dataLen) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static T_PsdkReturnCode PsdkUser_FileSystemInit(const char *path)
|
||||
{
|
||||
T_PsdkReturnCode psdkStat = PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
char filePath[PSDK_LOG_PATH_MAX_SIZE];
|
||||
char folderName[PSDK_LOG_FOLDER_NAME_MAX_SIZE];
|
||||
time_t currentTime = time(NULL);
|
||||
struct tm *localTime = localtime(¤tTime);
|
||||
uint16_t logFileIndex = 0;
|
||||
uint16_t currentLogFileIndex = 0;
|
||||
uint8_t ret = 0;
|
||||
|
||||
if (localTime == NULL) {
|
||||
printf("Get local time error.\r\n");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (access(PSDK_LOG_FOLDER_NAME, F_OK) != 0) {
|
||||
printf("Log file is not existed, need create new.\r\n");
|
||||
sprintf(folderName, "mkdir %s", PSDK_LOG_FOLDER_NAME);
|
||||
ret = system(folderName);
|
||||
if (ret != 0) {
|
||||
printf("Create new log folder error, ret:%d.\r\n", ret);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
s_psdkLogFileCnt = fopen(PSDK_LOG_INDEX_FILE_NAME, "rb+");
|
||||
if (s_psdkLogFileCnt == NULL) {
|
||||
s_psdkLogFileCnt = fopen(PSDK_LOG_INDEX_FILE_NAME, "wb+");
|
||||
if (s_psdkLogFileCnt == NULL) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
} else {
|
||||
ret = fseek(s_psdkLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_psdkLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Read log file index error.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Get current log index: %d\r\n", logFileIndex);
|
||||
currentLogFileIndex = logFileIndex;
|
||||
logFileIndex++;
|
||||
|
||||
ret = fseek(s_psdkLogFileCnt, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_psdkLogFileCnt);
|
||||
if (ret != sizeof(uint16_t)) {
|
||||
printf("Write log file index error.\r\n");
|
||||
fclose(s_psdkLogFileCnt);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fclose(s_psdkLogFileCnt);
|
||||
|
||||
sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex,
|
||||
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
|
||||
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
|
||||
|
||||
s_psdkLogFile = fopen(filePath, "wb+");
|
||||
if (s_psdkLogFile == NULL) {
|
||||
PsdkLogger_UserLogWarn("Open filepath time error.");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return psdkStat;
|
||||
}
|
||||
|
||||
static void PsdkUser_NormalExitHandler(int signalNum)
|
||||
{
|
||||
USER_UTIL_UNUSED(signalNum);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
|
||||
#pragma GCC diagnostic ignored "-Wreturn-type"
|
||||
|
||||
static void *PsdkUser_MonitorTask(void *argument)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int threadCount = 0;
|
||||
pid_t *tidList = NULL;
|
||||
T_ThreadAttribute *threadAttribute = NULL;
|
||||
|
||||
USER_UTIL_UNUSED(argument);
|
||||
|
||||
while (1) {
|
||||
threadCount = Monitor_GetThreadCountOfProcess(getpid());
|
||||
tidList = PsdkOsal_Malloc(threadCount * sizeof(pid_t));
|
||||
if (tidList == NULL) {
|
||||
PsdkLogger_UserLogError("malloc fail.");
|
||||
goto delay;
|
||||
}
|
||||
Monitor_GetTidListOfProcess(getpid(), tidList, threadCount);
|
||||
|
||||
threadAttribute = PsdkOsal_Malloc(threadCount * sizeof(T_ThreadAttribute));
|
||||
if (threadAttribute == NULL) {
|
||||
PsdkLogger_UserLogError("malloc fail.");
|
||||
goto freeTidList;
|
||||
}
|
||||
for (i = 0; i < threadCount; ++i) {
|
||||
threadAttribute[i].tid = tidList[i];
|
||||
}
|
||||
|
||||
PsdkLogger_UserLogDebug("thread pcpu:");
|
||||
PsdkLogger_UserLogDebug("tid\tname\tpcpu");
|
||||
for (i = 0; i < threadCount; ++i) {
|
||||
threadAttribute[i].pcpu = Monitor_GetPcpuOfThread(getpid(), tidList[i]);
|
||||
Monitor_GetNameOfThread(getpid(), tidList[i], threadAttribute[i].name, sizeof(threadAttribute[i].name));
|
||||
PsdkLogger_UserLogDebug("%d\t%15s\t%f %%.", threadAttribute[i].tid, threadAttribute[i].name,
|
||||
threadAttribute[i].pcpu);
|
||||
}
|
||||
|
||||
PsdkLogger_UserLogDebug("heap used: %d B.", Monitor_GetHeapUsed(getpid()));
|
||||
PsdkLogger_UserLogDebug("stack used: %d B.", Monitor_GetStackUsed(getpid()));
|
||||
|
||||
PsdkOsal_Free(threadAttribute);
|
||||
freeTidList:
|
||||
PsdkOsal_Free(tidList);
|
||||
|
||||
delay:
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
|
||||
#pragma GCC diagnostic ignored "-Wreturn-type"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
T_PsdkUserInfo userInfo;
|
||||
const T_PsdkDataChannelBandwidthProportionOfHighspeedChannel bandwidthProportionOfHighspeedChannel =
|
||||
{10, 60, 30};
|
||||
T_PsdkLoggerConsole printConsole = {
|
||||
.consoleLevel = PSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO,
|
||||
.func = PsdkUser_Console,
|
||||
};
|
||||
|
||||
T_PsdkLoggerConsole localRecordConsole = {
|
||||
.consoleLevel = PSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO,
|
||||
.func = PsdkUser_LocalWrite,
|
||||
};
|
||||
|
||||
T_PsdkHalUartHandler halUartHandler = {
|
||||
.UartInit = Hal_UartInit,
|
||||
.UartReadData = Hal_UartReadData,
|
||||
.UartWriteData = Hal_UartSendData,
|
||||
};
|
||||
|
||||
T_PsdkHalNetWorkHandler halNetWorkHandler = {
|
||||
.NetWorkConfig = HalNetWork_Config,
|
||||
};
|
||||
|
||||
T_PsdkOsalHandler osalHandler = {
|
||||
.Malloc = Osal_Malloc,
|
||||
.Free = Osal_Free,
|
||||
.TaskCreate = Osal_TaskCreate,
|
||||
.TaskDestroy = Osal_TaskDestroy,
|
||||
.TaskSleepMs = Osal_TaskSleepMs,
|
||||
.MutexCreate = Osal_MutexCreate,
|
||||
.MutexDestroy = Osal_MutexDestroy,
|
||||
.MutexLock = Osal_MutexLock,
|
||||
.MutexUnlock = Osal_MutexUnlock,
|
||||
.SemaphoreCreate = Osal_SemaphoreCreate,
|
||||
.SemaphoreDestroy = Osal_SemaphoreDestroy,
|
||||
.SemaphoreWait = Osal_SemaphoreWait,
|
||||
.SemaphorePost = Osal_SemaphorePost,
|
||||
.SemaphoreTimedWait = Osal_SemaphoreTimedWait,
|
||||
.GetTimeMs = Osal_GetTimeMs,
|
||||
};
|
||||
|
||||
T_PsdkAircraftInfoBaseInfo aircraftBaseInfo = {0};
|
||||
|
||||
if (PsdkPlatform_RegHalUartHandler(&halUartHandler) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk register hal uart handler error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkPlatform_RegHalNetworkHandler(&halNetWorkHandler) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk register hal network handler error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkPlatform_RegOsalHandler(&osalHandler) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk register osal handler error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkLogger_AddConsole(&printConsole) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk add console print error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkUser_FileSystemInit(PSDK_LOG_PATH) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk file system init error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkLogger_AddConsole(&localRecordConsole) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk add console record error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkUser_FillInUserInfo(&userInfo) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
printf("psdk fill in user info error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkCore_Init(&userInfo) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk instance init error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkProductInfo_SetAlias("PSDK_APPALIAS") != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("set product alias error.");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PsdkAircraftInfo_GetBaseInfo(&aircraftBaseInfo) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("get aircraft information error.");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
#ifdef PSDK_USING_POWER_MANAGEMENT
|
||||
if (PsdkTest_PowerManagementInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("power management init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_CAMERA_EMU
|
||||
if (PsdkTest_CameraInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk camera init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_CAMERA_MEDIA_EMU
|
||||
#if PSDK_ARCH_SYS_LINUX
|
||||
if (PsdkTest_CameraMediaInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk camera media init error");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_DATA_TRANSMISSION
|
||||
if (PsdkTest_DataTransmissionInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk data transmission init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_DATA_CHANNEL
|
||||
if (PsdkTest_DataChannelSetBandwidthProportionForHighspeedChannel(
|
||||
bandwidthProportionOfHighspeedChannel) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("set bandwidth distribution for high-speed channel error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_DATA_SUBSCRIPTION
|
||||
if (PsdkTest_DataSubscriptionInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk data subscription init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_PAYLOAD_COLLABORATION
|
||||
if (((aircraftBaseInfo.aircraftType == PSDK_AIRCRAFT_INFO_TYPE_M200_V2 ||
|
||||
aircraftBaseInfo.aircraftType == PSDK_AIRCRAFT_INFO_TYPE_M210_V2 ||
|
||||
aircraftBaseInfo.aircraftType == PSDK_AIRCRAFT_INFO_TYPE_M210RTK_V2) &&
|
||||
aircraftBaseInfo.payloadMountPosition == PSDK_AIRCRAFT_INFO_PAYLOAD_MOUNT_POSITION_NO2) ||
|
||||
aircraftBaseInfo.aircraftType == PSDK_AIRCRAFT_INFO_TYPE_M300_RTK) {
|
||||
if (PsdkTest_PayloadCollaborationInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk payload collaboration init error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_WIDGET
|
||||
if (PsdkTest_WidgetInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk widget init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_GIMBAL_EMU
|
||||
if (aircraftBaseInfo.psdkAdapterType == PSDK_AIRCRAFT_INFO_PSDK_ADAPTER_TYPE_SKYPORT_V2) {
|
||||
if (PsdkTest_GimbalInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk gimbal init error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_XPORT
|
||||
if (aircraftBaseInfo.psdkAdapterType == PSDK_AIRCRAFT_INFO_PSDK_ADAPTER_TYPE_XPORT) {
|
||||
if (PsdkTest_XPortInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk XPort init error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_UPGRADE
|
||||
T_PsdkTestUpgradePlatformOpt linuxUpgradePlatformOpt = {
|
||||
.rebootSystem = PsdkUpgradePlatformLinux_RebootSystem,
|
||||
.cleanUpgradeProgramFileStoreArea = PsdkUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea,
|
||||
.createUpgradeProgramFile = PsdkUpgradePlatformLinux_CreateUpgradeProgramFile,
|
||||
.writeUpgradeProgramFile = PsdkUpgradePlatformLinux_WriteUpgradeProgramFile,
|
||||
.readUpgradeProgramFile = PsdkUpgradePlatformLinux_ReadUpgradeProgramFile,
|
||||
.closeUpgradeProgramFile = PsdkUpgradePlatformLinux_CloseUpgradeProgramFile,
|
||||
.replaceOldProgram = PsdkUpgradePlatformLinux_ReplaceOldProgram,
|
||||
.setUpgradeRebootState = PsdkUpgradePlatformLinux_SetUpgradeRebootState,
|
||||
.getUpgradeRebootState = PsdkUpgradePlatformLinux_GetUpgradeRebootState,
|
||||
.cleanUpgradeRebootState = PsdkUpgradePlatformLinux_CleanUpgradeRebootState,
|
||||
};
|
||||
if (PsdkTest_UpgradeInit(&linuxUpgradePlatformOpt) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk upgrade init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PSDK_USING_MOP_CHANNEL
|
||||
if (PsdkTest_MopChannelInit() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk mop channel init error");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pthread_create(&s_monitorThread, NULL, PsdkUser_MonitorTask, NULL) != 0) {
|
||||
PsdkLogger_UserLogError("create monitor task fail.");
|
||||
}
|
||||
|
||||
if (pthread_setname_np(s_monitorThread, "monitor task") != 0) {
|
||||
PsdkLogger_UserLogError("set name for monitor task fail.");
|
||||
}
|
||||
|
||||
if (PsdkCore_ApplicationStart() != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("psdk application start error");
|
||||
}
|
||||
|
||||
signal(SIGTERM, PsdkUser_NormalExitHandler);
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
75
sample/platform/linux/manifold2/application/psdk_config.h
Normal file
75
sample/platform/linux/manifold2/application/psdk_config.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file psdk_config.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/9/11
|
||||
* @brief This is the header file for "psdk_config.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef PSDK_CONFIG_H
|
||||
#define PSDK_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define PSDK_USING_POWER_MANAGEMENT
|
||||
|
||||
#define PSDK_USING_CAMERA_EMU
|
||||
|
||||
#define PSDK_USING_CAMERA_MEDIA_EMU
|
||||
|
||||
#define PSDK_USING_DATA_TRANSMISSION
|
||||
|
||||
#define PSDK_USING_DATA_CHANNEL
|
||||
|
||||
#define PSDK_USING_DATA_SUBSCRIPTION
|
||||
|
||||
#define PSDK_USING_PAYLOAD_COLLABORATION
|
||||
|
||||
#define PSDK_USING_WIDGET
|
||||
|
||||
#define PSDK_USING_GIMBAL_EMU
|
||||
|
||||
#define PSDK_USING_XPORT
|
||||
|
||||
#define PSDK_USING_UPGRADE
|
||||
|
||||
/*!< Attention: This function needs to be used together with OSDK/MSDK mop sample.
|
||||
* */
|
||||
//#define PSDK_USING_MOP_CHANNEL
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PSDK_CONFIG_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
90
sample/platform/linux/manifold2/hal/hal_network.c
Normal file
90
sample/platform/linux/manifold2/hal/hal_network.c
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.c
|
||||
* @version V2.0.0
|
||||
* @date 3/27/20
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "hal_network.h"
|
||||
#include "psdk_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LINUX_NETWORK_DEV "enp0s31f6"
|
||||
#define LINUX_CMD_STR_MAX_SIZE (128)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_PsdkReturnCode HalNetWork_Config(const char *ipAddr, const char *netMask)
|
||||
{
|
||||
int32_t ret;
|
||||
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
|
||||
|
||||
if (ipAddr == NULL || netMask == NULL) {
|
||||
PsdkLogger_UserLogError("hal network config param error");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//Attention: need root permission to config ip addr and netmask.
|
||||
memset(cmdStr, 0, sizeof(cmdStr));
|
||||
|
||||
snprintf(cmdStr, sizeof(cmdStr), "ifconfig | grep %s", LINUX_NETWORK_DEV);
|
||||
ret = system(cmdStr);
|
||||
if (ret != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("Can't find the network device. "
|
||||
"Probably the name of network device is not match or device is not properly initialized. "
|
||||
"Please check the name or status of network device. ");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV);
|
||||
ret = system(cmdStr);
|
||||
if (ret != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("Can't open the network. "
|
||||
"Probably the program not execute with root permission. "
|
||||
"Please use the root permission to execute the program. ");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask);
|
||||
ret = system(cmdStr);
|
||||
if (ret != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
PsdkLogger_UserLogError("Can't config the ip address of network. "
|
||||
"Probably the program not execute with root permission. "
|
||||
"Please use the root permission to execute the program. ");
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
52
sample/platform/linux/manifold2/hal/hal_network.h
Normal file
52
sample/platform/linux/manifold2/hal/hal_network.h
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.h
|
||||
* @version V2.0.0
|
||||
* @date 3/27/20
|
||||
* @brief This is the header file for "hal_network.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_NETWORK_H
|
||||
#define HAL_NETWORK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "psdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_PsdkReturnCode HalNetWork_Config(const char *ipAddr, const char *netMask);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_NETWORK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
139
sample/platform/linux/manifold2/hal/hal_uart.c
Normal file
139
sample/platform/linux/manifold2/hal/hal_uart.c
Normal file
@ -0,0 +1,139 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file psdk_hal.c
|
||||
* @version V2.0.0
|
||||
* @date 2019/07/01
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hal_uart.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LINUX_UART_DEV "/dev/ttyUSB0"
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
static int s_psdkUartFd = -1;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_PsdkReturnCode Hal_UartInit(void)
|
||||
{
|
||||
struct termios options;
|
||||
struct flock lock;
|
||||
T_PsdkReturnCode returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
s_psdkUartFd = open(LINUX_UART_DEV, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (s_psdkUartFd == -1) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
// Forbid multiple psdk programs to access the serial port
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_pid = getpid();
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
|
||||
if (fcntl(s_psdkUartFd, F_GETLK, &lock) < 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
if (lock.l_type != F_UNLCK) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_pid = getpid();
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
if (fcntl(s_psdkUartFd, F_SETLKW, &lock) < 0) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (tcgetattr(s_psdkUartFd, &options) != 0) {
|
||||
close(s_psdkUartFd);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
cfsetispeed(&options, B460800);
|
||||
cfsetospeed(&options, B460800);
|
||||
|
||||
options.c_cflag |= CLOCAL;
|
||||
options.c_cflag |= CREAD;
|
||||
options.c_cflag &= ~CRTSCTS;
|
||||
options.c_cflag &= ~CSIZE;
|
||||
options.c_cflag |= CS8;
|
||||
options.c_cflag &= ~PARENB;
|
||||
options.c_iflag &= ~INPCK;
|
||||
options.c_cflag &= ~CSTOPB;
|
||||
options.c_oflag &= ~OPOST;
|
||||
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
options.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
options.c_cc[VTIME] = 0;
|
||||
options.c_cc[VMIN] = 0;
|
||||
|
||||
tcflush(s_psdkUartFd, TCIFLUSH);
|
||||
|
||||
if (tcsetattr(s_psdkUartFd, TCSANOW, &options) != 0) {
|
||||
close(s_psdkUartFd);
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
T_PsdkReturnCode Hal_UartSendData(const uint8_t *pBuf, uint16_t bufLen)
|
||||
{
|
||||
int32_t realLen;
|
||||
|
||||
if (s_psdkUartFd == -1) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
realLen = write(s_psdkUartFd, pBuf, bufLen);
|
||||
if (realLen == bufLen) {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
T_PsdkReturnCode Hal_UartReadData(uint8_t *pBuf, uint16_t bufLen, uint16_t *realBufLen)
|
||||
{
|
||||
int result;
|
||||
T_PsdkReturnCode returnCode;
|
||||
|
||||
result = read(s_psdkUartFd, pBuf, bufLen);
|
||||
if (result >= 0) {
|
||||
*realBufLen = result;
|
||||
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
} else {
|
||||
*realBufLen = 0;
|
||||
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
62
sample/platform/linux/manifold2/hal/hal_uart.h
Normal file
62
sample/platform/linux/manifold2/hal/hal_uart.h
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal.h
|
||||
* @version V2.0.0
|
||||
* @date 2019/8/28
|
||||
* @brief This is the header file for "hal.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2018-2019 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_H
|
||||
#define HAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "psdk_platform.h"
|
||||
#include "psdk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_PsdkReturnCode Hal_UartInit(void);
|
||||
T_PsdkReturnCode Hal_UartSendData(const uint8_t *pBuf, uint16_t bufLen);
|
||||
T_PsdkReturnCode Hal_UartReadData(uint8_t *pBuf, uint16_t bufLen, uint16_t *realBufLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
58
sample/platform/linux/manifold2/project/CMakeLists.txt
Normal file
58
sample/platform/linux/manifold2/project/CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(psdk_demo C)
|
||||
|
||||
### Set toolchain flags
|
||||
set(CMAKE_C_FLAGS "-D_REENTRANT -std=gnu99")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-pthread -lpthread")
|
||||
|
||||
set(CMAKE_C_COMPILER "gcc")
|
||||
set(CMAKE_CXX_COMPILER "g++")
|
||||
|
||||
set(PSDK_ARCH_SYS linux)
|
||||
|
||||
include_directories(..)
|
||||
include_directories(../../common)
|
||||
include_directories(../../../../api_sample)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/api_headers)
|
||||
|
||||
## Srcs
|
||||
file(GLOB_RECURSE APP_SRC ../../manifold2/application/*.c
|
||||
../../manifold2/hal/*.c)
|
||||
file(GLOB_RECURSE COMMON_SRC ../../common/*.c)
|
||||
file(GLOB_RECURSE SAMPLE_SRC ../../../../api_sample/*.c)
|
||||
|
||||
## "uname -m" to auto distinguish Manifold2-G or Manifold2-C
|
||||
execute_process(COMMAND uname -m
|
||||
OUTPUT_VARIABLE DEVICE_SYSTEM_ID)
|
||||
|
||||
if (NOT PSDK_ARCH_SYS)
|
||||
message(FATAL_ERROR
|
||||
"to use psdk inc src cmake ,
|
||||
you must set <PSDK_ARCH_SYS> value to indicate your system arch!
|
||||
This value can be linux, baremetal or rtos_xxxx (xxxx is the specific name of rtos."
|
||||
)
|
||||
endif ()
|
||||
|
||||
string(TOUPPER ${PSDK_ARCH_SYS} PSDK_ARCH_SYS_DEF)
|
||||
add_definitions(-DPSDK_ARCH_SYS_${PSDK_ARCH_SYS_DEF}=1)
|
||||
add_definitions(-D_GNU_SOURCE)
|
||||
|
||||
## Include directories and library
|
||||
if (DEVICE_SYSTEM_ID MATCHES x86_64)
|
||||
link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/x86_64-linux-gnu-gcc)
|
||||
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/x86_64-linux-gnu-gcc/libpayloadsdk.a)
|
||||
elseif (DEVICE_SYSTEM_ID MATCHES aarch64)
|
||||
link_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/aarch64-linux-gnu-gcc)
|
||||
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/aarch64-linux-gnu-gcc/libpayloadsdk.a)
|
||||
endif ()
|
||||
|
||||
## Outputs
|
||||
add_executable(${CMAKE_PROJECT_NAME}
|
||||
${APP_SRC}
|
||||
${COMMON_SRC}
|
||||
${SAMPLE_SRC}
|
||||
)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} m)
|
||||
|
||||
|
Reference in New Issue
Block a user