NEW: release DJI Payload-SDK version 3.10.0

This commit is contained in:
minghuah.chen
2025-01-10 10:30:38 +08:00
parent 860751ae15
commit 292a6fcb52
104 changed files with 11506 additions and 7194764 deletions

View File

@ -0,0 +1,176 @@
/**
********************************************************************
* @file hal_i2c.c
* @brief
*
* @copyright (c) 2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs 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_i2c.h"
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
/* Private constants ---------------------------------------------------------*/
#define I2C_DEVICE_RESET_TIME_US (25 * 1000)
#define I2C_DEVICE_RESET_GPIO_NUM (4)
#define DJI_SYSTEM_CMD_STR_MAX_SIZE (64)
/* Private types -------------------------------------------------------------*/
typedef struct {
int32_t i2cFd;
} T_I2cHandleStruct;
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
static void HalI2c_ResetDevice(void);
/* Exported functions definition ---------------------------------------------*/
T_DjiReturnCode HalI2c_Init(T_DjiHalI2cConfig i2cConfig, T_DjiI2cHandle *i2cHandle)
{
T_I2cHandleStruct *i2CHandleStruct = NULL;
//attention: suggest reset the i2c device before init it.
HalI2c_ResetDevice();
i2CHandleStruct = malloc(sizeof(T_I2cHandleStruct));
if (i2CHandleStruct == NULL) {
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
i2CHandleStruct->i2cFd = open(LINUX_I2C_DEV1, O_RDWR);
if (i2CHandleStruct->i2cFd < 0) {
printf("Open i2c device failed, fd: %d\r\n", i2CHandleStruct->i2cFd);
return -1;
}
*i2cHandle = i2CHandleStruct;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalI2c_DeInit(T_DjiI2cHandle i2cHandle)
{
T_I2cHandleStruct *i2CHandleStruct = (T_I2cHandleStruct *) i2cHandle;
close(i2CHandleStruct->i2cFd);
free(i2CHandleStruct);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalI2c_WriteData(T_DjiI2cHandle i2cHandle, uint16_t devAddress, const uint8_t *buf,
uint32_t len, uint32_t *realLen)
{
struct i2c_rdwr_ioctl_data data;
struct i2c_msg messages;
int32_t ret = 0;
T_I2cHandleStruct *i2CHandleStruct = (T_I2cHandleStruct *) i2cHandle;
messages.addr = devAddress;
messages.flags = 0;
messages.len = len;
messages.buf = (uint8_t *) buf;
data.msgs = &messages;
data.nmsgs = 1;
ret = ioctl(i2CHandleStruct->i2cFd, I2C_RDWR, &data);
if (ret < 0) {
*realLen = 0;
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*realLen = ret;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_DjiReturnCode HalI2c_ReadData(T_DjiI2cHandle i2cHandle, uint16_t devAddress, uint8_t *buf,
uint32_t len, uint32_t *realLen)
{
struct i2c_rdwr_ioctl_data data;
struct i2c_msg messages;
int32_t ret = 0;
T_I2cHandleStruct *i2CHandleStruct = (T_I2cHandleStruct *) i2cHandle;
messages.addr = devAddress;
messages.flags = I2C_M_RD;
messages.len = len;
messages.buf = buf;
data.msgs = &messages;
data.nmsgs = 1;
ret = ioctl(i2CHandleStruct->i2cFd, I2C_RDWR, &data);
if (ret < 0) {
*realLen = 0;
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*realLen = ret;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
static void HalI2c_ResetDevice(void)
{
char systemCmd[DJI_SYSTEM_CMD_STR_MAX_SIZE] = {0};
int32_t ret;
sprintf(systemCmd, "echo %d > /sys/class/gpio/export", I2C_DEVICE_RESET_GPIO_NUM);
ret = system(systemCmd);
if (ret != 0) {
printf("Export reset gpio failed, %d\r\n", ret);
}
sprintf(systemCmd, "echo out > /sys/class/gpio/gpio4/direction");
ret = system(systemCmd);
if (ret != 0) {
printf("Set gpio direction failed, %d\r\n", ret);
}
sprintf(systemCmd, "echo 0 > /sys/class/gpio/gpio4/value");
ret = system(systemCmd);
if (ret != 0) {
printf("Set gpio value failed, %d\r\n", ret);
}
usleep(I2C_DEVICE_RESET_TIME_US);
sprintf(systemCmd, "echo 1 > /sys/class/gpio/gpio4/value");
ret = system(systemCmd);
if (ret != 0) {
printf("Set gpio value failed, %d\r\n", ret);
}
sprintf(systemCmd, "echo %d > /sys/class/gpio/unexport", I2C_DEVICE_RESET_GPIO_NUM);
ret = system(systemCmd);
if (ret != 0) {
printf("Unexport reset gpio failed, %d\r\n", ret);
}
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,55 @@
/**
********************************************************************
* @file hal_i2c.h
* @brief This is the header file for "hal_i2c.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs 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_I2C_H
#define HAL_I2C_H
/* Includes ------------------------------------------------------------------*/
#include "dji_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define LINUX_I2C_DEV1 "/dev/i2c-1"
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode HalI2c_Init(T_DjiHalI2cConfig i2cConfig, T_DjiI2cHandle *i2cHandle);
T_DjiReturnCode HalI2c_DeInit(T_DjiI2cHandle i2cHandle);
T_DjiReturnCode HalI2c_WriteData(T_DjiI2cHandle i2cHandle, uint16_t devAddress,
const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode HalI2c_ReadData(T_DjiI2cHandle i2cHandle, uint16_t devAddress,
uint8_t *buf, uint32_t len, uint32_t *realLen);
#ifdef __cplusplus
}
#endif
#endif // HAL_I2C_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -42,16 +42,27 @@ T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNe
{
int32_t ret;
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
int32_t routeIp[4] = {0};
int32_t genMask[4] = {0};
if (ipAddr == NULL || netMask == NULL) {
USER_LOG_ERROR("hal network config param error");
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
sscanf(ipAddr, "%d.%d.%d.%d", &routeIp[0], &routeIp[1], &routeIp[2], &routeIp[3]);
sscanf(netMask, "%d.%d.%d.%d", &genMask[0], &genMask[1], &genMask[2], &genMask[3]);
routeIp[0] &= genMask[0];
routeIp[1] &= genMask[1];
routeIp[2] &= genMask[2];
routeIp[3] &= genMask[3];
//Attention: need root permission to config ip addr and netmask.
memset(cmdStr, 0, sizeof(cmdStr));
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV);
USER_LOG_DEBUG("%s", cmdStr);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Can't open the network."
@ -61,14 +72,34 @@ T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNe
}
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask);
USER_LOG_DEBUG("%s", cmdStr);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("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.");
USER_LOG_ERROR("cmd failed: %s", cmdStr);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
osalHandler->TaskSleepMs(50);
snprintf(cmdStr, sizeof(cmdStr), "ip route flush dev %s", LINUX_NETWORK_DEV);
USER_LOG_DEBUG("%s", cmdStr);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("cmd failed: %s", cmdStr);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
snprintf(cmdStr, sizeof(cmdStr), "route add -net %d.%d.%d.%d netmask %s dev %s",
routeIp[0], routeIp[1], routeIp[2], routeIp[3], netMask, LINUX_NETWORK_DEV);
USER_LOG_DEBUG("%s", cmdStr);
ret = system(cmdStr);
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("cmd failed: %s", cmdStr);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
osalHandler->TaskSleepMs(50);
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

View File

@ -25,6 +25,7 @@
/* Includes ------------------------------------------------------------------*/
#include "hal_usb_bulk.h"
#include "dji_logger.h"
#include <errno.h>
/* Private constants ---------------------------------------------------------*/
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
@ -67,12 +68,13 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
if (handle == NULL) {
USER_LOG_ERROR("libusb open device error");
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
if (ret != LIBUSB_SUCCESS) {
printf("libusb claim interface error");
USER_LOG_ERROR("libusb claim interface error");
libusb_close(handle);
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
@ -86,22 +88,22 @@ T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHan
((T_HalUsbBulkObj *) *usbBulkHandle)->interfaceNum = usbBulkInfo.channelInfo.interfaceNum;
if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK1_INTERFACE_NUM) {
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR);
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR);
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
} else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK2_INTERFACE_NUM) {
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR);
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR);
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
@ -163,7 +165,13 @@ T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uin
*realLen = actualLen;
#endif
} else {
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
ret = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
if (ret < 0) {
USER_LOG_ERROR("write ret %d %d %s\n", ret, errno, strerror(errno));
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
*realLen = ret;
}
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
@ -194,7 +202,13 @@ T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *b
*realLen = actualLen;
#endif
} else {
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
ret = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
if (ret < 0) {
USER_LOG_ERROR("read ret %d %d %s\n", ret, errno, strerror(errno));
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
*realLen = ret;
}
}
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;

View File

@ -52,27 +52,22 @@ extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep1"
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep2"
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep1"
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep2"
#define LINUX_USB_BULK1_INTERFACE_NUM (7)
#define LINUX_USB_BULK1_END_POINT_IN (0x88)
#define LINUX_USB_BULK1_END_POINT_OUT (5)
#define LINUX_USB_BULK1_INTERFACE_NUM (0)
#define LINUX_USB_BULK1_END_POINT_IN (0x81)
#define LINUX_USB_BULK1_END_POINT_OUT (0x01)
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep1"
#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep2"
#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep1"
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep2"
#define LINUX_USB_BULK2_INTERFACE_NUM (8)
#define LINUX_USB_BULK2_END_POINT_IN (0x89)
#define LINUX_USB_BULK2_END_POINT_OUT (6)
#define LINUX_USB_BULK2_INTERFACE_NUM (1)
#define LINUX_USB_BULK2_END_POINT_IN (0x82)
#define LINUX_USB_BULK2_END_POINT_OUT (0x02)
#ifdef PLATFORM_ARCH_x86_64
#define LINUX_USB_VID (0x0B95)
#define LINUX_USB_PID (0x1790)
#else
#define LINUX_USB_VID (0x0955)
#define LINUX_USB_PID (0x7020)
#endif
#define LINUX_USB_VID (0x0955)
#define LINUX_USB_PID (0x7020)
/* Exported types ------------------------------------------------------------*/