1、操作遥控器按钮,psdk进程通过socket发送命令给相机进程 来控制高光谱采集系统;
2、通过FFmpeg采集摄像头视频流并编码为h264,利用psdk推流到遥控器;
This commit is contained in:
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 "eth0"//enx00e04c360a7d
|
||||
#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"///dev/dji_serial_port
|
||||
|
||||
/* 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******/
|
Reference in New Issue
Block a user