第一次提交
203
Source/M300/PSDK_Qt/Config/ConfigParser_M300RTK.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
#include "ConfigParser_M300RTK.h"
|
||||
|
||||
ZZ_ConfigParser_M300RTK::ZZ_ConfigParser_M300RTK(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_bInit = false;
|
||||
//return 0;
|
||||
}
|
||||
|
||||
ZZ_ConfigParser_M300RTK::~ZZ_ConfigParser_M300RTK()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ZZ_ConfigParser_M300RTK::GetParams(AppRegInfo& struAppRegInfo, HardwareInfo& struHardwareInfo,UIConfig& struUIConfig)
|
||||
{
|
||||
Initialize("/home/DJI/Settings/");
|
||||
LoadParams();
|
||||
struAppRegInfo = m_struAppRegInfo;
|
||||
struHardwareInfo = m_struHardwareInfo;
|
||||
struUIConfig = m_struUIConfig;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_ConfigParser_M300RTK::UpdateUIConfig(UIConfig struUIConfig)
|
||||
{
|
||||
m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/CaptureMode"), struUIConfig.sCaptureMode);
|
||||
|
||||
m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/SamplingRate"), struUIConfig.sSamplingRate);
|
||||
|
||||
m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/DecisionHeight"), struUIConfig.sDecisionHeight);
|
||||
}
|
||||
|
||||
int ZZ_ConfigParser_M300RTK::Initialize(QString qstrConfigFolderPath)
|
||||
{
|
||||
if (m_bInit)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
QDir qdConfigFiles(qstrConfigFolderPath);
|
||||
if (!qdConfigFiles.exists())
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300: Func Initialize. Dir not exists";
|
||||
return 1;
|
||||
}
|
||||
|
||||
qdConfigFiles.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
qdConfigFiles.setSorting(QDir::DirsFirst);
|
||||
|
||||
QFileInfoList qfList = qdConfigFiles.entryInfoList();
|
||||
if (qfList.size() < 1)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func Initialize. Empty folder";
|
||||
return 2;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
do
|
||||
{
|
||||
QFileInfo qfInfo = qfList.at(i);
|
||||
bool bisDir = qfInfo.isDir();
|
||||
if (bisDir)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (qfInfo.fileName() == "AppInfoConfig.ini")
|
||||
{
|
||||
//QSettings qsTemp(qfInfo.filePath(), QSettings::Format::IniFormat);
|
||||
m_pqfM300ConfigFiles[0] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat);
|
||||
qDebug() << qfInfo.filePath();
|
||||
j++;
|
||||
}
|
||||
if (qfInfo.fileName() == "HardwareSettings.ini")
|
||||
{
|
||||
//m_qfM300ConfigFiles[1].setUserIniPath(qfInfo.filePath());
|
||||
m_pqfM300ConfigFiles[1] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat);
|
||||
qDebug() << qfInfo.filePath();
|
||||
j++;
|
||||
}
|
||||
if (qfInfo.fileName() == "SystemSettings.ini")
|
||||
{
|
||||
m_pqfM300ConfigFiles[2] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat);
|
||||
//m_qfM300ConfigFiles[2].setUserIniPath(qfInfo.filePath());
|
||||
qDebug() << qfInfo.filePath();
|
||||
j++;
|
||||
}
|
||||
//qDebug() << qfInfo.filePath() << ":" << qfInfo.fileName();
|
||||
}
|
||||
++i;
|
||||
} while (i < qfList.size());
|
||||
|
||||
if (j != 3)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func Initialize. File count not match";
|
||||
return 3;
|
||||
}
|
||||
|
||||
m_bInit = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_ConfigParser_M300RTK::LoadParams()
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QString qstrUSER_APP_NAME = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_NAME"),"Error").toString();
|
||||
qDebug() << qstrUSER_APP_NAME;
|
||||
if (qstrUSER_APP_NAME=="Error")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_NAME not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString qstrUSER_APP_ID = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_ID"), "Error").toString();
|
||||
qDebug() << qstrUSER_APP_ID;
|
||||
if (qstrUSER_APP_ID == "Error")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_ID not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString qstrUSER_APP_KEY = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_KEY"), "Error").toString();
|
||||
qDebug() << qstrUSER_APP_KEY;
|
||||
if (qstrUSER_APP_KEY == "Error")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString qstrUSER_APP_LICENSE = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_LICENSE"), "Error").toString();
|
||||
qDebug() << qstrUSER_APP_LICENSE;
|
||||
if (qstrUSER_APP_LICENSE == "Error")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString qstrUSER_DEVELOPER_ACCOUNT = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_DEVELOPER_ACCOUNT"), "Error").toString();
|
||||
qDebug() << qstrUSER_DEVELOPER_ACCOUNT;
|
||||
if (qstrUSER_DEVELOPER_ACCOUNT == "Error")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
m_struAppRegInfo.qstrUserAppAcc = qstrUSER_DEVELOPER_ACCOUNT;
|
||||
m_struAppRegInfo.qstrUserAppID = qstrUSER_APP_ID;
|
||||
m_struAppRegInfo.qstrUserAppKey = qstrUSER_APP_KEY;
|
||||
m_struAppRegInfo.qstrUserAppLic = qstrUSER_APP_LICENSE;
|
||||
m_struAppRegInfo.qstrUserAppName = qstrUSER_APP_NAME;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QString qstrUSER_BAUD_RATE = m_pqfM300ConfigFiles[1]->value(QString("COMPORT/USER_BAUD_RATE"),"NULL").toString();
|
||||
qDebug() << qstrUSER_BAUD_RATE;
|
||||
if (qstrUSER_BAUD_RATE == "NULL")
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_BAUD_RATE not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
int iCONFIG_HARDWARE_CONNECTION = m_pqfM300ConfigFiles[1]->value(QString("ADV MODE/CONFIG_HARDWARE_CONNECTION"),10000).toInt();
|
||||
qDebug() << iCONFIG_HARDWARE_CONNECTION;
|
||||
if (iCONFIG_HARDWARE_CONNECTION == 10000)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.CONFIG_HARDWARE_CONNECTION not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
m_struHardwareInfo.enumHCM = HardwareConnectionMode(iCONFIG_HARDWARE_CONNECTION);
|
||||
m_struHardwareInfo.qstrBaudRate = qstrUSER_BAUD_RATE;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int iCaptureMode = m_pqfM300ConfigFiles[2]->value(QString("PSDK/CaptureMode"), -1).toInt();
|
||||
qDebug() << iCaptureMode;
|
||||
if (iCaptureMode == -1)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.CaptureMode not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
m_struUIConfig.sCaptureMode = (short)iCaptureMode;
|
||||
|
||||
int iSamplingRate = m_pqfM300ConfigFiles[2]->value(QString("PSDK/SamplingRate"), -1).toInt();
|
||||
qDebug() << iSamplingRate;
|
||||
if (iSamplingRate == -1)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.SamplingRate not load";
|
||||
return 1;
|
||||
}
|
||||
m_struUIConfig.sSamplingRate = (short)iSamplingRate;
|
||||
|
||||
int iDecisionHeight = m_pqfM300ConfigFiles[2]->value(QString("PSDK/DecisionHeight"), -1).toInt();
|
||||
qDebug() << iDecisionHeight;
|
||||
if (iDecisionHeight == -1)
|
||||
{
|
||||
qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.DecisionHeight not load";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
26
Source/M300/PSDK_Qt/Config/ConfigParser_M300RTK.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "ZZ_Types_M300.h"
|
||||
using namespace ZZ::Device::DJI::M300RTK;
|
||||
|
||||
class ZZ_ConfigParser_M300RTK :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ZZ_ConfigParser_M300RTK(QObject* parent = nullptr);
|
||||
virtual ~ZZ_ConfigParser_M300RTK();
|
||||
public:
|
||||
private:
|
||||
bool m_bInit;
|
||||
QSettings *m_pqfM300ConfigFiles[3];
|
||||
|
||||
AppRegInfo m_struAppRegInfo;
|
||||
HardwareInfo m_struHardwareInfo;
|
||||
UIConfig m_struUIConfig;
|
||||
public:
|
||||
int GetParams(AppRegInfo &struAppRegInfo, HardwareInfo &struHardwareInfo, UIConfig& struUIConfig);
|
||||
int UpdateUIConfig(UIConfig struUIConfig);
|
||||
private:
|
||||
int Initialize(QString qstrConfigFolderPath);
|
||||
int LoadParams();
|
||||
};
|
||||
@ -0,0 +1,6 @@
|
||||
[DJI]
|
||||
USER_APP_NAME=Project_Grixis
|
||||
USER_APP_ID=126401
|
||||
USER_APP_KEY=a313e3617b16c56a11502bd91a61d6f
|
||||
USER_APP_LICENSE=BNrpsD+UJ2lj8kmVgN4GnXg+AZiQwaxSuf/WvA072DFdLy2h+NCQizf+nR+WcjEEKeTknSzPbfqlvAc/WSJwrtqV/gYXSVPtSlK0AaV61SeKBvZQpogoyaZy07fWNCZrha3OAQsHj18TtU5RjOn6gYapzGDAPQVG6Q/At/H/9GSPQr5uwxI20fVWUTOkymYLM/04CNQGsToPD+fZwixExjjjHjdD9K7R0D4EgyvbqMpMLlkspBLR/9h6/oVxefOyaHJIi+pk+IdLFFC3omnrh7U3/4b95LA3t22J1GJvqvO2cyphjrSXsaDdctvtj6EjE8WhEXQCvmYm0VIHWz/0Qw==
|
||||
USER_DEVELOPER_ACCOUNT=1033584732@qq.com
|
||||
@ -0,0 +1,4 @@
|
||||
[COMPORT]
|
||||
USER_BAUD_RATE=230400
|
||||
[ADV MODE]
|
||||
CONFIG_HARDWARE_CONNECTION=1
|
||||
@ -0,0 +1,4 @@
|
||||
[PSDK]
|
||||
SamplingRate=1
|
||||
CaptureMode=0
|
||||
DecisionHeight=10
|
||||
741
Source/M300/PSDK_Qt/Main/VehicleController.cpp
Normal file
@ -0,0 +1,741 @@
|
||||
#include "VehicleController.h"
|
||||
|
||||
#include <dji_platform.h>
|
||||
#include <dji_logger.h>
|
||||
#include <dji_core.h>
|
||||
#include <dji_aircraft_info.h>
|
||||
#include <dji_fc_subscription.h>
|
||||
|
||||
#include "osal.h"
|
||||
#include "osal_fs.h"
|
||||
#include "osal_socket.h"
|
||||
#include "hal_usb_bulk.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_network.h"
|
||||
|
||||
#include "time.h"
|
||||
#include "ZZ_Types_M300.h"
|
||||
|
||||
#define ZZ_UNUSED(x) ((x) = (x))
|
||||
#define ZZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define ZZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
int VehicleController::m_siFlagIsPumpWorking = 0;
|
||||
int VehicleController::m_siFlagIsStartCaptureSignalEmitted = 0;
|
||||
VehicleController* VehicleController::spCaller = NULL;
|
||||
char VehicleController::m_scCaptureMode = 0;
|
||||
|
||||
VehicleController::VehicleController(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_iFlagIsVehicleTakeoff = 0;
|
||||
m_iFlagIsVehicleCapturing = 0;
|
||||
m_iFlagIsCaptureModeInited = 0;
|
||||
|
||||
//m_cCaptureMode = 0;
|
||||
|
||||
}
|
||||
VehicleController::~VehicleController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
T_DjiReturnCode VehicleController::DjiTest_FcSubscriptionReceiveFlightStatusCallback(const uint8_t* ccData, uint16_t sDataSize, const T_DjiDataTimestamp* tDjiTimestamp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
T_DjiReturnCode VehicleController::DjiTest_FcSubscriptionReceiveHeightCallback(const uint8_t* data, uint16_t dataSize, const T_DjiDataTimestamp* timestamp)
|
||||
{
|
||||
float fHeight = *((T_DjiFcSubscriptionHeightFusion*)data);
|
||||
//qDebug() <<"[Fused Height]:"<< fHeight;
|
||||
|
||||
///Pump need to be added
|
||||
if (m_siFlagIsPumpWorking==0&& fHeight>10)
|
||||
{
|
||||
//system("sudo gpio mode 7 out");
|
||||
m_siFlagIsPumpWorking = 1;
|
||||
system("sudo gpio write 7 1");
|
||||
qDebug() << "[Fused Height]:" << fHeight;
|
||||
}
|
||||
if (m_siFlagIsPumpWorking == 1 && fHeight < 10)
|
||||
{
|
||||
//system("sudo gpio mode 7 out");
|
||||
m_siFlagIsPumpWorking = 0;
|
||||
system("sudo gpio write 7 0");
|
||||
qDebug() << "[Fused Height]:" << fHeight;
|
||||
}
|
||||
|
||||
//T_DjiOsalHandler* osalHandler = DjiPlatform_GetOsalHandler();
|
||||
//osalHandler->TaskSleepMs(2000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
T_DjiReturnCode VehicleController::ZZ_DjiWaypointV2EventCallback(T_DjiWaypointV2MissionEventPush eventData)
|
||||
{
|
||||
if (spCaller==NULL)
|
||||
{
|
||||
qDebug() << "ZZ_DjiWaypointV2EventCallback Fatal Error.spCaller Undefined";
|
||||
return -1;
|
||||
}
|
||||
if (eventData.event == 0x10)
|
||||
{
|
||||
if (eventData.data.waypointIndex==0 && m_siFlagIsStartCaptureSignalEmitted==0)
|
||||
{
|
||||
if (m_scCaptureMode==0)
|
||||
{
|
||||
m_siFlagIsStartCaptureSignalEmitted++;
|
||||
spCaller->emit Signal_StartCapture();
|
||||
}
|
||||
// emit Signal_StartCapture();
|
||||
|
||||
}
|
||||
}
|
||||
if (eventData.event == 0x11)
|
||||
{
|
||||
qDebug() << "eventData.event" << m_siFlagIsStartCaptureSignalEmitted;
|
||||
if (m_siFlagIsStartCaptureSignalEmitted > 0)
|
||||
{
|
||||
m_siFlagIsStartCaptureSignalEmitted = 0;
|
||||
spCaller->emit Signal_StopCapture();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::Initialize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::SetupEnvironment_M300RTK()
|
||||
{
|
||||
using namespace ZZ::Device::DJI::M300RTK;
|
||||
|
||||
spCaller = this;
|
||||
|
||||
//for test
|
||||
//ZZ_ConfigParser_M300RTK clsConfigParser;
|
||||
//clsConfigParser.GetParams(m_struAppRegInfo, m_struHardwareInfo, m_struUIConfig);
|
||||
//
|
||||
//for use
|
||||
m_clsConfigParser.GetParams(m_struAppRegInfo, m_struHardwareInfo, m_struUIConfig);
|
||||
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiOsalHandler osalHandler;
|
||||
T_DjiHalUartHandler uartHandler;
|
||||
T_DjiHalUsbBulkHandler usbBulkHandler;
|
||||
T_DjiLoggerConsole printConsole;
|
||||
T_DjiLoggerConsole localRecordConsole;
|
||||
T_DjiFileSystemHandler fileSystemHandler;
|
||||
T_DjiSocketHandler socketHandler;
|
||||
T_DjiHalNetworkHandler networkHandler;
|
||||
|
||||
networkHandler.NetworkInit = HalNetWork_Init;
|
||||
networkHandler.NetworkDeInit = HalNetWork_DeInit;
|
||||
networkHandler.NetworkGetDeviceInfo = HalNetWork_GetDeviceInfo;
|
||||
|
||||
socketHandler.Socket = Osal_Socket;
|
||||
socketHandler.Bind = Osal_Bind;
|
||||
socketHandler.Close = Osal_Close;
|
||||
socketHandler.UdpSendData = Osal_UdpSendData;
|
||||
socketHandler.UdpRecvData = Osal_UdpRecvData;
|
||||
socketHandler.TcpListen = Osal_TcpListen;
|
||||
socketHandler.TcpAccept = Osal_TcpAccept;
|
||||
socketHandler.TcpConnect = Osal_TcpConnect;
|
||||
socketHandler.TcpSendData = Osal_TcpSendData;
|
||||
socketHandler.TcpRecvData = Osal_TcpRecvData;
|
||||
|
||||
osalHandler.TaskCreate = Osal_TaskCreate;
|
||||
osalHandler.TaskDestroy = Osal_TaskDestroy;
|
||||
osalHandler.TaskSleepMs = Osal_TaskSleepMs;
|
||||
osalHandler.MutexCreate = Osal_MutexCreate;
|
||||
osalHandler.MutexDestroy = Osal_MutexDestroy;
|
||||
osalHandler.MutexLock = Osal_MutexLock;
|
||||
osalHandler.MutexUnlock = Osal_MutexUnlock;
|
||||
osalHandler.SemaphoreCreate = Osal_SemaphoreCreate;
|
||||
osalHandler.SemaphoreDestroy = Osal_SemaphoreDestroy;
|
||||
osalHandler.SemaphoreWait = Osal_SemaphoreWait;
|
||||
osalHandler.SemaphoreTimedWait = Osal_SemaphoreTimedWait;
|
||||
osalHandler.SemaphorePost = Osal_SemaphorePost;
|
||||
osalHandler.Malloc = Osal_Malloc;
|
||||
osalHandler.Free = Osal_Free;
|
||||
osalHandler.GetTimeMs = Osal_GetTimeMs;
|
||||
osalHandler.GetTimeUs = Osal_GetTimeUs;
|
||||
|
||||
uartHandler.UartInit = HalUart_Init;
|
||||
uartHandler.UartDeInit = HalUart_DeInit;
|
||||
uartHandler.UartWriteData = HalUart_WriteData;
|
||||
uartHandler.UartReadData = HalUart_ReadData;
|
||||
uartHandler.UartGetStatus = HalUart_GetStatus;
|
||||
|
||||
usbBulkHandler.UsbBulkInit = HalUsbBulk_Init;
|
||||
usbBulkHandler.UsbBulkDeInit = HalUsbBulk_DeInit;
|
||||
usbBulkHandler.UsbBulkWriteData = HalUsbBulk_WriteData;
|
||||
usbBulkHandler.UsbBulkReadData = HalUsbBulk_ReadData;
|
||||
usbBulkHandler.UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo;
|
||||
|
||||
fileSystemHandler.FileOpen = Osal_FileOpen;
|
||||
fileSystemHandler.FileClose = Osal_FileClose;
|
||||
fileSystemHandler.FileWrite = Osal_FileWrite;
|
||||
fileSystemHandler.FileRead = Osal_FileRead;
|
||||
fileSystemHandler.FileSync = Osal_FileSync;
|
||||
fileSystemHandler.FileSeek = Osal_FileSeek;
|
||||
fileSystemHandler.DirOpen = Osal_DirOpen;
|
||||
fileSystemHandler.DirClose = Osal_DirClose;
|
||||
fileSystemHandler.DirRead = Osal_DirRead;
|
||||
fileSystemHandler.Mkdir = Osal_Mkdir;
|
||||
fileSystemHandler.Unlink = Osal_Unlink;
|
||||
fileSystemHandler.Rename = Osal_Rename;
|
||||
fileSystemHandler.Stat = Osal_Stat;
|
||||
|
||||
printConsole.func = DjiUser_PrintMessage;
|
||||
printConsole.consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_INFO;
|
||||
printConsole.isSupportColor = false;
|
||||
|
||||
returnCode = DjiPlatform_RegOsalHandler(&osalHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegOsalHandler. Register osal handler error";
|
||||
throw std::runtime_error("Register osal handler error.");
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegHalUartHandler(&uartHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegHalUartHandler. Register hal uart handler error";
|
||||
throw std::runtime_error("Register hal uart handler error.");
|
||||
}
|
||||
|
||||
if (m_struHardwareInfo.enumHCM== HardwareConnectionMode::UartAndNetwork)
|
||||
{
|
||||
returnCode = DjiPlatform_RegHalNetworkHandler(&networkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegHalNetworkHandler. Register hal network handler error";
|
||||
throw std::runtime_error("Register hal network handler error");
|
||||
}
|
||||
}
|
||||
else if(m_struHardwareInfo.enumHCM == HardwareConnectionMode::UartAndUSBBulk)
|
||||
{
|
||||
returnCode = DjiPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegHalUsbBulkHandler. Register hal usb bulk handler error";
|
||||
throw std::runtime_error("Register hal usb bulk handler error.");
|
||||
}
|
||||
}
|
||||
else if (m_struHardwareInfo.enumHCM == HardwareConnectionMode::UartOnly)
|
||||
{
|
||||
returnCode = DjiPlatform_RegSocketHandler(&socketHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegSocketHandler. Register osal socket handler error";
|
||||
throw std::runtime_error("register osal socket handler error");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegSocketHandler. Register osal socket handler error";
|
||||
throw std::runtime_error("hardware connection configuration error");
|
||||
}
|
||||
|
||||
returnCode = DjiPlatform_RegFileSystemHandler(&fileSystemHandler);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegFileSystemHandler. Register osal filesystem handler error";
|
||||
throw std::runtime_error("Register osal filesystem handler error.");
|
||||
}
|
||||
|
||||
returnCode = DjiLogger_AddConsole(&printConsole);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "VehicleController: Func DjiPlatform_RegFileSystemHandler. Register osal filesystem handler error";
|
||||
throw std::runtime_error("Add printf console error.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if (DjiUser_LocalWriteFsInit(DJI_LOG_PATH) != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
// throw std::runtime_error("File system init error.");
|
||||
// }
|
||||
//
|
||||
// returnCode = DjiLogger_AddConsole(&printConsole);
|
||||
// if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
// throw std::runtime_error("Add printf console error.");
|
||||
// }
|
||||
//
|
||||
// returnCode = DjiLogger_AddConsole(&localRecordConsole);
|
||||
// if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
// throw std::runtime_error("Add printf console error.");
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::StartupPSDK_M300RTK()
|
||||
{
|
||||
T_DjiUserInfo userInfo;
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
|
||||
T_DjiOsalHandler* osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
returnCode = LoadUserAppInfo(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Fill user info error, please check user info config.");
|
||||
}
|
||||
|
||||
returnCode = DjiCore_Init(&userInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Core init error.");
|
||||
}
|
||||
|
||||
returnCode = DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Get aircraft base info error.");
|
||||
}
|
||||
|
||||
// if (aircraftInfoBaseInfo.mountPosition != DJI_MOUNT_POSITION_EXTENSION_PORT)
|
||||
// {
|
||||
// throw std::runtime_error("Please run this sample on extension port.");
|
||||
// }
|
||||
|
||||
returnCode = DjiCore_SetAlias("PSDK_APPALIAS");
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Set alias error.");
|
||||
}
|
||||
|
||||
returnCode = DjiCore_ApplicationStart();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Start sdk application error.");
|
||||
}
|
||||
|
||||
//osalHandler->TaskSleepMs(5000);
|
||||
SetupWidget();
|
||||
//osalHandler->TaskSleepMs(5000);
|
||||
SetupMessagePipe();
|
||||
SetupWaypointStatusCallback();
|
||||
InitSystemDateTime();
|
||||
SetupSubscriptions();
|
||||
|
||||
|
||||
qDebug()<<"M300RTK PSDK Channel Started.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::UpdateUIConfig()
|
||||
{
|
||||
m_clsWidget.GetSettings(m_struUIConfig);
|
||||
m_clsConfigParser.UpdateUIConfig(m_struUIConfig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::GetOneDataFrame(M300RTKDataFrame& M300RTKDataFrame)
|
||||
{
|
||||
T_DjiReturnCode tDjiReturnCode;
|
||||
T_DjiFcSubscriptionVelocity tDjiVelocity = { 0 };
|
||||
T_DjiFcSubscriptionQuaternion tDjiQuaternion = { 0 };
|
||||
T_DjiFcSubscriptionGpsPosition tDjiGpsPosition = { 0 };
|
||||
T_DjiDataTimestamp tDjiTimestamp = { 0 };
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,(uint8_t*)&tDjiVelocity,sizeof(T_DjiFcSubscriptionVelocity),&tDjiTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic error.DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY";
|
||||
//return 1;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, (uint8_t*)&tDjiGpsPosition, sizeof(T_DjiFcSubscriptionGpsPosition), &tDjiTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic error.DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY";
|
||||
//return 2;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION, (uint8_t*)&tDjiQuaternion, sizeof(T_DjiFcSubscriptionQuaternion), &tDjiTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic error.DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION";
|
||||
//return 3;
|
||||
}
|
||||
|
||||
M300RTKDataFrame.stVelocity.x = tDjiVelocity.data.x;
|
||||
M300RTKDataFrame.stVelocity.y = tDjiVelocity.data.y;
|
||||
M300RTKDataFrame.stVelocity.z = tDjiVelocity.data.z;
|
||||
|
||||
M300RTKDataFrame.stQuaternion.w_q0 = tDjiQuaternion.q0;
|
||||
M300RTKDataFrame.stQuaternion.x_q1 = tDjiQuaternion.q1;
|
||||
M300RTKDataFrame.stQuaternion.y_q2 = tDjiQuaternion.q2;
|
||||
M300RTKDataFrame.stQuaternion.z_q3 = tDjiQuaternion.q3;
|
||||
|
||||
M300RTKDataFrame.stGPSPosition.x = tDjiGpsPosition.x;
|
||||
M300RTKDataFrame.stGPSPosition.y = tDjiGpsPosition.y;
|
||||
M300RTKDataFrame.stGPSPosition.z = tDjiGpsPosition.z;
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << tDjiVelocity.data.x << tDjiVelocity.data.y << tDjiVelocity.data.z << tDjiGpsPosition.x << tDjiGpsPosition.y << tDjiGpsPosition.z;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::SetupSubscriptions()
|
||||
{
|
||||
T_DjiReturnCode tDjiReturnCode;
|
||||
|
||||
// tDjiReturnCode = DjiFcSubscription_Init();
|
||||
// if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
// {
|
||||
// qDebug() << "init data subscription module error.";
|
||||
// return 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qDebug() << "init data subscription module finished.";
|
||||
// }
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_HEIGHT_FUSION, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, DjiTest_FcSubscriptionReceiveHeightCallback);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_HEIGHT_FUSION error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY, DJI_DATA_SUBSCRIPTION_TOPIC_5_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, DJI_DATA_SUBSCRIPTION_TOPIC_5_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION, DJI_DATA_SUBSCRIPTION_TOPIC_5_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_BAROMETER, DJI_DATA_SUBSCRIPTION_TOPIC_5_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_BAROMETER error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::SetupWaypointStatusCallback()
|
||||
{
|
||||
T_DjiReturnCode returnCode;
|
||||
|
||||
returnCode = DjiWaypointV2_Init();
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug()<<"Init waypoint V2 module error, error code:"<< returnCode;
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
returnCode = DjiWaypointV2_RegisterMissionEventCallback(ZZ_DjiWaypointV2EventCallback);
|
||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() <<"Register waypoint V2 event failed, error code:" << returnCode;
|
||||
return returnCode;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// int VehicleController::TransSignal_StartCapture(VehicleController* pCaller)
|
||||
// {
|
||||
// pCaller->emit Signal_StartCapture();
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
int VehicleController::LoadUserAppInfo(T_DjiUserInfo* struDjiUserInfo)
|
||||
{
|
||||
using namespace ZZ::Device::DJI::M300RTK;
|
||||
|
||||
memset(struDjiUserInfo->appName, 0, sizeof(struDjiUserInfo->appName));
|
||||
memset(struDjiUserInfo->appId, 0, sizeof(struDjiUserInfo->appId));
|
||||
memset(struDjiUserInfo->appKey, 0, sizeof(struDjiUserInfo->appKey));
|
||||
memset(struDjiUserInfo->appLicense, 0, sizeof(struDjiUserInfo->appLicense));
|
||||
memset(struDjiUserInfo->developerAccount, 0, sizeof(struDjiUserInfo->developerAccount));
|
||||
memset(struDjiUserInfo->baudRate, 0, sizeof(struDjiUserInfo->baudRate));
|
||||
|
||||
if (m_struAppRegInfo.qstrUserAppName.length() >= sizeof(struDjiUserInfo->appName) ||
|
||||
m_struAppRegInfo.qstrUserAppID.length() > sizeof(struDjiUserInfo->appId) ||
|
||||
m_struAppRegInfo.qstrUserAppKey.length() > sizeof(struDjiUserInfo->appKey) ||
|
||||
m_struAppRegInfo.qstrUserAppLic.length() > sizeof(struDjiUserInfo->appLicense) ||
|
||||
m_struAppRegInfo.qstrUserAppAcc.length() >= sizeof(struDjiUserInfo->developerAccount) ||
|
||||
m_struHardwareInfo.qstrBaudRate.length() > sizeof(struDjiUserInfo->baudRate))
|
||||
{
|
||||
qDebug()<<"VehicleController:LoadUserAppInfo.Length of user information string is beyond limit,Please check";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
strncpy(struDjiUserInfo->appName, m_struAppRegInfo.qstrUserAppName.toLatin1().data(), m_struAppRegInfo.qstrUserAppName.length());
|
||||
memcpy(struDjiUserInfo->appId, m_struAppRegInfo.qstrUserAppID.toLatin1().data(), ZZ_MIN(sizeof(struDjiUserInfo->appId), m_struAppRegInfo.qstrUserAppID.length()));
|
||||
memcpy(struDjiUserInfo->appKey, m_struAppRegInfo.qstrUserAppKey.toLatin1().data(), ZZ_MIN(sizeof(struDjiUserInfo->appKey), m_struAppRegInfo.qstrUserAppKey.length()));
|
||||
memcpy(struDjiUserInfo->appLicense, m_struAppRegInfo.qstrUserAppLic.toLatin1().data(),
|
||||
ZZ_MIN(sizeof(struDjiUserInfo->appLicense), m_struAppRegInfo.qstrUserAppLic.length()));
|
||||
memcpy(struDjiUserInfo->baudRate, m_struHardwareInfo.qstrBaudRate.toLatin1().data(), ZZ_MIN(sizeof(struDjiUserInfo->baudRate), m_struHardwareInfo.qstrBaudRate.length()));
|
||||
strncpy(struDjiUserInfo->developerAccount, m_struAppRegInfo.qstrUserAppAcc.toLatin1().data(), sizeof(struDjiUserInfo->developerAccount) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
T_DjiReturnCode VehicleController::DjiUser_PrintMessage(const uint8_t* data, uint16_t dataLen)
|
||||
{
|
||||
QString qstrMessage((char*)data);
|
||||
qDebug() << qstrMessage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::SetupMessagePipe()
|
||||
{
|
||||
connect(&m_clsWidget, &ZZ_Widget_M300RTK::Signal_UpdateCaptureMode, this, &VehicleController::Slot_OnChangeCaptureMode);
|
||||
connect(&m_clsWidget, &ZZ_Widget_M300RTK::Signal_StartCapture, this, &VehicleController::Signal_StartCapture);
|
||||
connect(&m_clsWidget, &ZZ_Widget_M300RTK::Signal_StopCapture, this, &VehicleController::Signal_StopCapture);
|
||||
connect(this, &VehicleController::Signal_UpdateVehicleMessage, &m_clsWidget, &ZZ_Widget_M300RTK::Slot_UpdatePSDKFloatMessage);
|
||||
/// for test
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
connect(this, &VehicleController::Signal_StartCapture, this, &VehicleController::Slot_TestStartCapture);
|
||||
connect(this, &VehicleController::Signal_StopCapture, this, &VehicleController::Slot_TestStopCapture);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::SetupWidget()
|
||||
{
|
||||
m_clsWidget.SetUIFilePath("/home/DJI/Widget",100);
|
||||
m_clsWidget.SetSettings(m_struUIConfig);
|
||||
m_clsWidget.PreparteEnvironment();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::InitSystemDateTime()
|
||||
{
|
||||
T_DjiReturnCode tDjiReturnCode;
|
||||
|
||||
///Init
|
||||
tDjiReturnCode = DjiFcSubscription_Init();
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "init data subscription module error.";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "InitSystemDateTime finished.";
|
||||
}
|
||||
|
||||
///SubscribeTopic
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_TIME, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_GPS_TIME error.";
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
///Make sure Gps avalible
|
||||
T_DjiOsalHandler* osalHandler = DjiPlatform_GetOsalHandler();
|
||||
bool bStop = false;
|
||||
/////for test
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
|
||||
bStop = 1;
|
||||
#endif
|
||||
|
||||
|
||||
T_DjiFcSubscriptionGpsSignalLevel tDjiGpsSignalLevel = { 0 };
|
||||
T_DjiDataTimestamp tTimestamp = { 0 };
|
||||
|
||||
osalHandler->TaskSleepMs(5000);
|
||||
QTime qtStart = QTime::currentTime();
|
||||
|
||||
int iRetryTime = 0;
|
||||
|
||||
while (!bStop)
|
||||
{
|
||||
if (iRetryTime>10)
|
||||
{
|
||||
bStop = 1;
|
||||
}
|
||||
osalHandler->TaskSleepMs(2000);
|
||||
DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL, (uint8_t*)&tDjiGpsSignalLevel, sizeof(T_DjiFcSubscriptionGpsSignalLevel), &tTimestamp);
|
||||
qDebug() << "DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL" << tDjiGpsSignalLevel;
|
||||
QTime qtElapsed = QTime::currentTime();
|
||||
if (tDjiGpsSignalLevel>1)
|
||||
{
|
||||
bStop = 1;
|
||||
//emit Signal_UpdatePSDKFloatMessage("");
|
||||
}
|
||||
else
|
||||
{
|
||||
QString qstrInfo = QString("Warning:Weak GPS signal, Waiting....GPS_SIGNAL_LEVEL:%1, Elapsed time:%2").arg(tDjiGpsSignalLevel).arg(qtStart.msecsTo(qtElapsed));
|
||||
emit Signal_UpdateVehicleMessage(qstrInfo);
|
||||
}
|
||||
|
||||
iRetryTime++;
|
||||
}
|
||||
|
||||
///Get GPS Datetime
|
||||
T_DjiFcSubscriptionGpsDate tGpsDate = { 0 };
|
||||
T_DjiFcSubscriptionGpsTime tGpsTime = { 0 };
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE, (uint8_t*)&tGpsDate, sizeof(T_DjiFcSubscriptionGpsDate), &tTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_TIME, (uint8_t*)&tGpsTime, sizeof(T_DjiFcSubscriptionGpsTime), &tTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE.";
|
||||
return -2;
|
||||
}
|
||||
|
||||
//qDebug() << "Date" << tGpsDate << "Time" << tGpsTime;
|
||||
|
||||
QDateTime qdtDateTime;
|
||||
QString qstrDate, qstrTime,qstrDateTime;
|
||||
qstrDate = QString::number(tGpsDate);
|
||||
qstrTime = QString::number(tGpsTime);
|
||||
if (qstrTime.length()==5)
|
||||
{
|
||||
qstrTime = "0" + qstrTime/*+"000"*/;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// qstrTime= qstrTime + "000";
|
||||
// }
|
||||
// QDate qd;
|
||||
// qd = QDate::fromString("20121022", "yyyyMMdd");
|
||||
// QTime qt;
|
||||
// qt.fromString(qstrTime,"hhmmsszzz");
|
||||
qstrDateTime = qstrDate + qstrTime;
|
||||
qdtDateTime = QDateTime::fromString(qstrDateTime, "yyyyMMddhhmmss");
|
||||
time_t stdTime = qdtDateTime.toTime_t();
|
||||
|
||||
if (qdtDateTime.isValid())
|
||||
{
|
||||
stime(&stdTime);
|
||||
}
|
||||
#ifndef ZZ_FLAG_TEST
|
||||
//stime(&stdTime);
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
// qDebug() << qstrDate;
|
||||
// qDebug() << qstrTime;
|
||||
// qDebug() << qd.isValid();
|
||||
// qDebug() << qd.toString("yyyyMMdd");
|
||||
// qDebug() << qt.isValid();
|
||||
// qDebug() << qt;
|
||||
qDebug() <<"[GPS Time Check]" << qdtDateTime.isValid();
|
||||
qDebug() <<"[GPS Time:]" << qstrDateTime << "####" << qdtDateTime.toString("yyyyMMddhhmmsszzz");
|
||||
|
||||
///UnSubscribeTopic
|
||||
tDjiReturnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_UnSubscribeTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_GPS_SIGNAL_LEVEL.";
|
||||
return -11;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_UnSubscribeTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_GPS_DATE.";
|
||||
return -12;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_TIME);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_UnSubscribeTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_GPS_TIME.";
|
||||
return -13;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::Slot_OnChangeCaptureMode(char cMode)
|
||||
{
|
||||
//ZZ_Widget_M300RTK* test = qobject_cast<ZZ_Widget_M300RTK*>(sender());
|
||||
//if (test== &m_clsWidget)
|
||||
//{
|
||||
// qDebug() << "from ZZ_Widget_M300RTK";
|
||||
//}
|
||||
|
||||
///0:Auto 1:Manual
|
||||
switch (cMode)
|
||||
{
|
||||
case 0:
|
||||
//m_clsWidget.SetUIFilePath("/home/DJI/Widget_Auto/", 100);
|
||||
//m_clsWidget.PreparteEnvironment();
|
||||
//m_clsWidget.UpdateCaptureStatus(0);
|
||||
m_scCaptureMode = 0;
|
||||
break;
|
||||
case 1:
|
||||
//m_clsWidget.SetUIFilePath("/home/DJI/Widget_Manual/", 100);
|
||||
//m_clsWidget.PreparteEnvironment();
|
||||
//m_clsWidget.UpdateCaptureStatus(1);
|
||||
m_scCaptureMode = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::Slot_TestStartCapture()
|
||||
{
|
||||
qDebug() << "VehicleController Test Cap Started";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::Slot_TestStopCapture()
|
||||
{
|
||||
qDebug() << "VehicleController Test Cap Stopped";
|
||||
return 0;
|
||||
}
|
||||
|
||||
92
Source/M300/PSDK_Qt/Main/VehicleController.h
Normal file
@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "dji_typedef.h"
|
||||
#include "dji_core.h"
|
||||
#include "dji_waypoint_v2.h"
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "ConfigParser_M300RTK.h"
|
||||
#include "Widget_M300RTK.h"
|
||||
#include "ZZ_Types.h"
|
||||
using namespace std;
|
||||
using namespace ZZ_DATA_DEF::M300RTK;
|
||||
using namespace ZZ_DATA_DEF::MainConfig;
|
||||
|
||||
class VehicleController :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VehicleController(QObject* parent = nullptr);
|
||||
virtual ~VehicleController();
|
||||
|
||||
public:
|
||||
static int m_siFlagIsPumpWorking;
|
||||
static int m_siFlagIsStartCaptureSignalEmitted;
|
||||
static VehicleController* spCaller;
|
||||
static char m_scCaptureMode;
|
||||
private:
|
||||
///////////Config need modify
|
||||
ZZ_ConfigParser_M300RTK m_clsConfigParser;
|
||||
ZZ_Widget_M300RTK m_clsWidget;
|
||||
|
||||
M300RTKSettings m_struM300RTKSs;
|
||||
AppRegInfo m_struAppRegInfo;
|
||||
HardwareInfo m_struHardwareInfo;
|
||||
UIConfig m_struUIConfig;
|
||||
|
||||
int m_iFlagIsVehicleTakeoff;
|
||||
int m_iFlagIsVehicleCapturing;
|
||||
int m_iFlagIsCaptureModeInited;
|
||||
|
||||
public:
|
||||
/// test func Do Not Call
|
||||
static T_DjiReturnCode DjiTest_FcSubscriptionReceiveFlightStatusCallback(const uint8_t* ccData, uint16_t sDataSize,const T_DjiDataTimestamp* tDjiTimestamp);
|
||||
static T_DjiReturnCode DjiTest_FcSubscriptionReceiveHeightCallback(const uint8_t* data, uint16_t dataSize,const T_DjiDataTimestamp* timestamp);
|
||||
|
||||
/// callback func to monitor flight status
|
||||
static T_DjiReturnCode ZZ_DjiWaypointV2EventCallback(T_DjiWaypointV2MissionEventPush eventData);
|
||||
public:
|
||||
/// call First
|
||||
int Initialize();
|
||||
int SetupEnvironment_M300RTK();
|
||||
/// call Seconde
|
||||
int StartupPSDK_M300RTK();
|
||||
|
||||
///call to save Settings
|
||||
int UpdateUIConfig();
|
||||
|
||||
/// data call
|
||||
int GetOneDataFrame(M300RTKDataFrame &M300RTKDataFrame);
|
||||
private:
|
||||
///
|
||||
int SetupMessagePipe();
|
||||
///
|
||||
int SetupWidget();
|
||||
///
|
||||
public:///for test
|
||||
int InitSystemDateTime();
|
||||
int SetupSubscriptions();
|
||||
///
|
||||
public:///for test
|
||||
int SetupWaypointStatusCallback();
|
||||
///
|
||||
|
||||
///
|
||||
int LoadUserAppInfo(T_DjiUserInfo* struDjiUserInfo);
|
||||
static T_DjiReturnCode DjiUser_PrintMessage(const uint8_t* data, uint16_t dataLen);
|
||||
signals:
|
||||
int Signal_StartCapture();
|
||||
int Signal_StopCapture();
|
||||
|
||||
void Signal_UpdateVehicleMessage(QString qstrMessage);
|
||||
public slots:
|
||||
int Slot_OnChangeCaptureMode(char cMode);
|
||||
///for test
|
||||
int Slot_TestStartCapture();
|
||||
int Slot_TestStopCapture();
|
||||
};
|
||||
|
||||
234
Source/M300/PSDK_Qt/Widget/Widget_M300RTK.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
#include "Widget_M300RTK.h"
|
||||
|
||||
int32_t ZZ_Widget_M300RTK::m_siDjiWidgetValueBtn = 0;
|
||||
int32_t ZZ_Widget_M300RTK::m_siDjiWidgetValueList_CaptureMode = 1;
|
||||
int32_t ZZ_Widget_M300RTK::m_siDjiWidgetValueList_DecisionHeight = 1;
|
||||
int32_t ZZ_Widget_M300RTK::m_siDjiWidgetValueList_SamplingRate = 0;
|
||||
|
||||
ZZ_Widget_M300RTK::ZZ_Widget_M300RTK(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_iFlagIsVehicleCapturing = 0;
|
||||
|
||||
connect(this,&ZZ_Widget_M300RTK::Signal_UpdatePSDKFloatMessage,this,&ZZ_Widget_M300RTK::Slot_UpdatePSDKFloatMessage);
|
||||
}
|
||||
|
||||
ZZ_Widget_M300RTK::~ZZ_Widget_M300RTK()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::InitParam()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::SetUIFilePath(char* pcUIFilePath, uint16_t uiLength)
|
||||
{
|
||||
if (uiLength>=256)
|
||||
{
|
||||
qDebug() << "ZZ_Widget_M300RTK: Func SetUIFilePath. File path is too long";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QByteArray qbaTemp(pcUIFilePath);
|
||||
m_qstrFilePath = qbaTemp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ZZ_Widget_M300RTK::UpdateCaptureStatus(int iStatus)
|
||||
{
|
||||
m_iFlagIsVehicleCapturing = iStatus;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::GetSettings(UIConfig &struUIConfig)
|
||||
{
|
||||
struUIConfig.sDecisionHeight = m_siDjiWidgetValueList_DecisionHeight;
|
||||
struUIConfig.sCaptureMode = m_siDjiWidgetValueList_CaptureMode;
|
||||
struUIConfig.sSamplingRate = m_siDjiWidgetValueList_SamplingRate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::SetSettings(UIConfig struUIConfig)
|
||||
{
|
||||
m_struUIConfig = struUIConfig;
|
||||
m_siDjiWidgetValueList_CaptureMode = struUIConfig.sCaptureMode;
|
||||
m_siDjiWidgetValueList_DecisionHeight = struUIConfig.sDecisionHeight;
|
||||
m_siDjiWidgetValueList_SamplingRate = struUIConfig.sSamplingRate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::PreparteEnvironment()
|
||||
{
|
||||
|
||||
|
||||
T_DjiReturnCode djiStat;
|
||||
|
||||
static const T_DjiWidgetHandlerListItem s_DjiWidgetHandlerList[] =
|
||||
{
|
||||
{0, DJI_WIDGET_TYPE_SWITCH, ZZ_Widget_M300RTK::OnUpdateWidgetValue, ZZ_Widget_M300RTK::OnLoadWidgetValue, this},
|
||||
{1, DJI_WIDGET_TYPE_LIST, ZZ_Widget_M300RTK::OnUpdateWidgetValue, ZZ_Widget_M300RTK::OnLoadWidgetValue, this},
|
||||
{2, DJI_WIDGET_TYPE_LIST, ZZ_Widget_M300RTK::OnUpdateWidgetValue, ZZ_Widget_M300RTK::OnLoadWidgetValue, this},
|
||||
{3, DJI_WIDGET_TYPE_LIST, ZZ_Widget_M300RTK::OnUpdateWidgetValue, ZZ_Widget_M300RTK::OnLoadWidgetValue, this}
|
||||
};
|
||||
|
||||
djiStat = DjiWidget_Init();
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "ZZ_Widget_M300RTK: Func DjiWidget_Init. Dji widget init error"<< djiStat;
|
||||
//return djiStat;
|
||||
}
|
||||
|
||||
djiStat = DjiWidget_RegDefaultUiConfigByDirPath(m_qstrFilePath.toLatin1());
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << m_qstrFilePath.toLatin1();
|
||||
qDebug() << "ZZ_Widget_M300RTK: Func DjiWidget_RegDefaultUiConfigByDirPath.Add default widget ui config error";
|
||||
return djiStat;
|
||||
}
|
||||
|
||||
djiStat = DjiWidget_RegHandlerList(s_DjiWidgetHandlerList, sizeof(s_DjiWidgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem));
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() <<"ZZ_Widget_M300RTK: Func DjiWidget_RegHandlerList.Set widget handler list error";
|
||||
return djiStat;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::UploadResources()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::test_UpdatePSDKFloatMessage(QString qstrMessage)
|
||||
{
|
||||
T_DjiReturnCode djiStat;
|
||||
|
||||
djiStat = DjiWidgetFloatingWindow_ShowMessage(qstrMessage.toLatin1());
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "ZZ_Widget_M300RTK: Func test_UpdatePSDKFloatMessage.Floating window show message error";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
T_DjiReturnCode ZZ_Widget_M300RTK::OnUpdateWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t value, void* userData)
|
||||
{
|
||||
ZZ_Widget_M300RTK* pCaller = (ZZ_Widget_M300RTK*)userData;
|
||||
|
||||
if (pCaller->m_iFlagIsVehicleCapturing)
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (widgetType == DJI_WIDGET_TYPE_SWITCH )
|
||||
{
|
||||
if (ZZ_Widget_M300RTK::m_siDjiWidgetValueList_CaptureMode==0)
|
||||
{
|
||||
pCaller->emit Signal_UpdatePSDKFloatMessage("Automatic capture mode.Please don't use this function");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value==1)
|
||||
{
|
||||
pCaller->emit Signal_UpdatePSDKFloatMessage("start capture");
|
||||
pCaller->emit Signal_StartCapture();
|
||||
}
|
||||
else
|
||||
{
|
||||
pCaller->emit Signal_UpdatePSDKFloatMessage("capture stopped");
|
||||
pCaller->emit Signal_StopCapture();
|
||||
}
|
||||
|
||||
}
|
||||
ZZ_Widget_M300RTK::m_siDjiWidgetValueBtn = value;
|
||||
|
||||
///for test
|
||||
QString qstrTest;
|
||||
qDebug() << "OnUpdateWidgetValue " << "widgetType " << widgetType << "index " << index << "value " << value;
|
||||
qstrTest = QString("index:%1,value:%2").arg(index, value);
|
||||
//pCaller->test_UpdatePSDKFloatMessage(qstrTest);
|
||||
//qstrTest = "12345";
|
||||
//pCaller->emit Signal_UpdatePSDKFloatMessage(qstrTest);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (widgetType == DJI_WIDGET_TYPE_LIST )
|
||||
{
|
||||
if (index==1)
|
||||
{
|
||||
pCaller->emit Signal_UpdateCaptureMode((char)value);
|
||||
ZZ_Widget_M300RTK::m_siDjiWidgetValueList_CaptureMode = value;
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
ZZ_Widget_M300RTK::m_siDjiWidgetValueList_DecisionHeight = value;
|
||||
}
|
||||
else if (index == 3)
|
||||
{
|
||||
ZZ_Widget_M300RTK::m_siDjiWidgetValueList_SamplingRate = value;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "OnUpdateWidgetValue " << "widgetType " << widgetType << "index " << index << "value " << value;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode ZZ_Widget_M300RTK::OnLoadWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t* value, void* userData)
|
||||
{
|
||||
|
||||
if (widgetType == DJI_WIDGET_TYPE_SWITCH)
|
||||
{
|
||||
//qDebug() << "OnLoadWidgetValue " << "widgetType " << widgetType << "index " << index << "value " << value;
|
||||
|
||||
*value= ZZ_Widget_M300RTK::m_siDjiWidgetValueBtn;
|
||||
}
|
||||
|
||||
if (widgetType == DJI_WIDGET_TYPE_LIST)
|
||||
{
|
||||
//qDebug() << "OnLoadWidgetValue " << "widgetType " << widgetType << "index " << index << "value " << value;
|
||||
if (index == 1)
|
||||
{
|
||||
*value = ZZ_Widget_M300RTK::m_siDjiWidgetValueList_CaptureMode;
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
*value = ZZ_Widget_M300RTK::m_siDjiWidgetValueList_DecisionHeight;
|
||||
}
|
||||
else if (index == 3)
|
||||
{
|
||||
*value = ZZ_Widget_M300RTK::m_siDjiWidgetValueList_SamplingRate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int ZZ_Widget_M300RTK::Slot_UpdatePSDKFloatMessage(QString qstrMessage)
|
||||
{
|
||||
T_DjiReturnCode djiStat;
|
||||
|
||||
djiStat = DjiWidgetFloatingWindow_ShowMessage(qstrMessage.toLatin1());
|
||||
if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "ZZ_Widget_M300RTK: Func test_UpdatePSDKFloatMessage.Floating window show message error";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
50
Source/M300/PSDK_Qt/Widget/Widget_M300RTK.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "dji_typedef.h"
|
||||
#include "dji_core.h"
|
||||
#include "pch.h"
|
||||
#include "dji_widget.h"
|
||||
#include "ConfigParser_M300RTK.h"
|
||||
using namespace std;
|
||||
|
||||
class ZZ_Widget_M300RTK :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ZZ_Widget_M300RTK(QObject* parent = nullptr);
|
||||
virtual ~ZZ_Widget_M300RTK();
|
||||
public:
|
||||
|
||||
private:
|
||||
int m_iFlagIsVehicleCapturing;
|
||||
UIConfig m_struUIConfig;
|
||||
short m_sFlagCaptureMode;
|
||||
QString m_qstrFilePath;
|
||||
static int32_t m_siDjiWidgetValueBtn, m_siDjiWidgetValueList_CaptureMode, m_siDjiWidgetValueList_SamplingRate, m_siDjiWidgetValueList_DecisionHeight;
|
||||
public:
|
||||
int PreparteEnvironment();
|
||||
int SetUIFilePath(char* pcUIFilePath, uint16_t uiLength);
|
||||
int UpdateCaptureStatus(int iStatus);
|
||||
|
||||
int GetSettings(UIConfig &struUIConfig);
|
||||
int SetSettings(UIConfig struUIConfig);
|
||||
//int UpdateCaptureStatus(int iStatus);
|
||||
private:
|
||||
int InitParam();
|
||||
int UploadResources();
|
||||
int test_UpdatePSDKFloatMessage(QString qstrMessage);
|
||||
|
||||
public:
|
||||
static T_DjiReturnCode OnUpdateWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t value,void* userData);
|
||||
static T_DjiReturnCode OnLoadWidgetValue (E_DjiWidgetType widgetType, uint32_t index, int32_t* value,void* userData);
|
||||
public slots:
|
||||
int Slot_UpdatePSDKFloatMessage(QString qstrMessage);
|
||||
signals:
|
||||
void Signal_UpdatePSDKFloatMessage(QString qstrMessage);
|
||||
///0:Auto 1:Manual
|
||||
void Signal_UpdateCaptureMode(char cMode);
|
||||
|
||||
void Signal_StartCapture();
|
||||
void Signal_StopCapture();
|
||||
};
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,52 @@
|
||||
{
|
||||
"version":
|
||||
{
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"main_interface": {
|
||||
"floating_window": {
|
||||
"is_enable": true
|
||||
},
|
||||
"speaker": {
|
||||
"is_enable_tts": false,
|
||||
"is_enable_voice": false
|
||||
},
|
||||
"widget_list": [
|
||||
{
|
||||
|
||||
}
|
||||
]
|
||||
},
|
||||
"config_interface":
|
||||
{
|
||||
"widget_list":
|
||||
[
|
||||
{
|
||||
"widget_index": 1,
|
||||
"widget_type": "list",
|
||||
"widget_name": "采集模式",
|
||||
"list_item": [
|
||||
{
|
||||
"item_name": "自动航线采集",
|
||||
"icon_file_set": {
|
||||
"icon_file_name_selected": "",
|
||||
"icon_file_name_unselected": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"item_name": "手动航线采集",
|
||||
"icon_file_set": {
|
||||
"icon_file_name_selected": "",
|
||||
"icon_file_name_unselected": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"customize_rc_buttons_config": {
|
||||
"is_enable": true,
|
||||
"mapping_config_display_order": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,109 @@
|
||||
{
|
||||
"version":
|
||||
{
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"main_interface": {
|
||||
"floating_window": {
|
||||
"is_enable": true
|
||||
},
|
||||
"speaker": {
|
||||
"is_enable_tts": false,
|
||||
"is_enable_voice": false
|
||||
},
|
||||
"widget_list": [
|
||||
{
|
||||
"widget_index": 0,
|
||||
"widget_type": "switch",
|
||||
"widget_name": "采集",
|
||||
"icon_file_set": {
|
||||
"icon_file_name_selected": "icon_button_zz_stop.png",
|
||||
"icon_file_name_unselected": "icon_button_zz_start.png"
|
||||
},
|
||||
"customize_rc_buttons_config": {
|
||||
"is_enable": true,
|
||||
"mapping_config_display_order": 3,
|
||||
"button_value_step_length": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"config_interface":
|
||||
{
|
||||
"widget_list":
|
||||
[
|
||||
{
|
||||
"widget_index": 1,
|
||||
"widget_type": "list",
|
||||
"widget_name": "采集模式",
|
||||
"list_item": [
|
||||
{
|
||||
"item_name": "自动航线采集",
|
||||
"icon_file_set": {
|
||||
"icon_file_name_selected": "",
|
||||
"icon_file_name_unselected": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"item_name": "手动航线采集",
|
||||
"icon_file_set": {
|
||||
"icon_file_name_selected": "",
|
||||
"icon_file_name_unselected": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"customize_rc_buttons_config": {
|
||||
"is_enable": true,
|
||||
"mapping_config_display_order": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"widget_index": 2,
|
||||
"widget_type": "list",
|
||||
"widget_name": "决断高度",
|
||||
"list_item": [
|
||||
{
|
||||
"item_name": "0m"
|
||||
},
|
||||
{
|
||||
"item_name": "10m"
|
||||
},
|
||||
{
|
||||
"item_name": "20m"
|
||||
},
|
||||
{
|
||||
"item_name": "∞"
|
||||
}
|
||||
],
|
||||
"customize_rc_buttons_config": {
|
||||
"is_enable": true,
|
||||
"mapping_config_display_order": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"widget_index": 3,
|
||||
"widget_type": "list",
|
||||
"widget_name": "采样频率",
|
||||
"list_item": [
|
||||
{
|
||||
"item_name": "1Hz"
|
||||
},
|
||||
{
|
||||
"item_name": "2Hz"
|
||||
},
|
||||
{
|
||||
"item_name": "5Hz"
|
||||
},
|
||||
{
|
||||
"item_name": "10Hz"
|
||||
}
|
||||
],
|
||||
"customize_rc_buttons_config": {
|
||||
"is_enable": true,
|
||||
"mapping_config_display_order": 3
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
46
Source/M300/PSDK_Qt/ZZ_Types_M300.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "dji_typedef.h"
|
||||
namespace ZZ
|
||||
{
|
||||
namespace Device
|
||||
{
|
||||
namespace DJI
|
||||
{
|
||||
namespace M300RTK
|
||||
{
|
||||
enum HardwareConnectionMode
|
||||
{
|
||||
UartOnly = 0,
|
||||
UartAndUSBBulk,
|
||||
UartAndNetwork
|
||||
};
|
||||
|
||||
typedef struct tagAppRegInfo
|
||||
{
|
||||
QString qstrUserAppName;
|
||||
QString qstrUserAppID;
|
||||
QString qstrUserAppKey;
|
||||
QString qstrUserAppLic;
|
||||
QString qstrUserAppAcc;
|
||||
}AppRegInfo;
|
||||
|
||||
typedef struct tagHardwareInfo
|
||||
{
|
||||
HardwareConnectionMode enumHCM;
|
||||
QString qstrBaudRate;
|
||||
}HardwareInfo;
|
||||
|
||||
typedef struct tagUIConfig
|
||||
{
|
||||
short sCaptureMode=0;
|
||||
short sSamplingRate=0;
|
||||
short sDecisionHeight=1;
|
||||
}UIConfig;
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
92
Source/M300/PSDK_Qt/hal/hal_network.c
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.c
|
||||
* @version V2.0.0
|
||||
* @date 3/27/20
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "hal_network.h"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj)
|
||||
{
|
||||
int32_t ret;
|
||||
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
|
||||
|
||||
if (ipAddr == NULL || netMask == NULL) {
|
||||
USER_LOG_ERROR("hal network config param error");
|
||||
return DJI_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 %s up", LINUX_NETWORK_DEV);
|
||||
ret = system(cmdStr);
|
||||
if (ret != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||
USER_LOG_ERROR("Can't open the network."
|
||||
"Probably the program not execute with root permission."
|
||||
"Please use the root permission to execute the program.");
|
||||
return DJI_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 != 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.");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj)
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalNetWork_GetDeviceInfo(T_DjiHalNetworkDeviceInfo *deviceInfo)
|
||||
{
|
||||
deviceInfo->usbNetAdapter.vid = USB_NET_ADAPTER_VID;
|
||||
deviceInfo->usbNetAdapter.pid = USB_NET_ADAPTER_PID;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
73
Source/M300/PSDK_Qt/hal/hal_network.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_network.h
|
||||
* @brief This is the header file for "hal_network.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_NETWORK_H
|
||||
#define HAL_NETWORK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/** @attention User can config network card name here, if your device is not MF2C/G, please comment below and add your
|
||||
* NIC name micro define as #define 'LINUX_NETWORK_DEV "your NIC name"'.
|
||||
*/
|
||||
#ifdef PLATFORM_ARCH_x86_64
|
||||
#define LINUX_NETWORK_DEV "enx000ec6688213"
|
||||
#else
|
||||
#define LINUX_NETWORK_DEV "l4tbr0"
|
||||
#endif
|
||||
/**
|
||||
* @attention
|
||||
*/
|
||||
|
||||
#ifdef PLATFORM_ARCH_x86_64
|
||||
#define USB_NET_ADAPTER_VID (0x0B95)
|
||||
#define USB_NET_ADAPTER_PID (0x1790)
|
||||
#else
|
||||
#define USB_NET_ADAPTER_VID (0x0955)
|
||||
#define USB_NET_ADAPTER_PID (0x7020)
|
||||
#endif
|
||||
|
||||
#define LINUX_CMD_STR_MAX_SIZE (128)
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_DjiNetworkHandle *halObj);
|
||||
T_DjiReturnCode HalNetWork_DeInit(T_DjiNetworkHandle halObj);
|
||||
T_DjiReturnCode HalNetWork_GetDeviceInfo(T_DjiHalNetworkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_NETWORK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
280
Source/M300/PSDK_Qt/hal/hal_uart.c
Normal file
@ -0,0 +1,280 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_uart.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_logger.h>
|
||||
#include "hal_uart.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define UART_DEV_NAME_STR_SIZE (128)
|
||||
#define DJI_SYSTEM_CMD_STR_MAX_SIZE (64)
|
||||
#define DJI_SYSTEM_RESULT_STR_MAX_SIZE (128)
|
||||
|
||||
//Global
|
||||
char gvpcM300RTK_UART1[128] = "/dev/ttyUSB0";
|
||||
char gvpcM300RTK_UART2[128] = "/dev/ttyUSB0";
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int uartFd;
|
||||
} T_UartHandleStruct;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle)
|
||||
{
|
||||
T_UartHandleStruct *uartHandleStruct;
|
||||
struct termios options;
|
||||
struct flock lock;
|
||||
T_DjiReturnCode returnCode = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
char uartName[UART_DEV_NAME_STR_SIZE];
|
||||
char systemCmd[DJI_SYSTEM_CMD_STR_MAX_SIZE];
|
||||
char *ret = NULL;
|
||||
char lineBuf[DJI_SYSTEM_RESULT_STR_MAX_SIZE] = {0};
|
||||
FILE *fp;
|
||||
|
||||
uartHandleStruct = malloc(sizeof(T_UartHandleStruct));
|
||||
if (uartHandleStruct == NULL)
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////edit by zz
|
||||
/*if (uartNum == DJI_HAL_UART_NUM_0) {
|
||||
strcpy(uartName, LINUX_UART_DEV1);
|
||||
} else if (uartNum == DJI_HAL_UART_NUM_1) {
|
||||
strcpy(uartName, LINUX_UART_DEV2);
|
||||
} else {
|
||||
goto free_uart_handle;
|
||||
}*/
|
||||
|
||||
if (uartNum == DJI_HAL_UART_NUM_0)
|
||||
{
|
||||
strcpy(uartName, gvpcM300RTK_UART1);
|
||||
}
|
||||
else if (uartNum == DJI_HAL_UART_NUM_1)
|
||||
{
|
||||
strcpy(uartName, gvpcM300RTK_UART2);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto free_uart_handle;
|
||||
}
|
||||
|
||||
#ifdef USE_CLION_DEBUG
|
||||
sprintf(systemCmd, "ls -l %s", uartName);
|
||||
fp = popen(systemCmd, "r");
|
||||
if (fp == NULL) {
|
||||
goto free_uart_handle;
|
||||
}
|
||||
|
||||
ret = fgets(lineBuf, sizeof(lineBuf), fp);
|
||||
if (ret == NULL) {
|
||||
goto close_fp;
|
||||
}
|
||||
|
||||
if (strstr(lineBuf, "crwxrwxrwx") == NULL) {
|
||||
USER_LOG_ERROR("Can't operation the device. "
|
||||
"Probably the device has not operation permission. "
|
||||
"Please execute command 'sudo chmod 777 %s' to add permission. ", uartName);
|
||||
goto close_fp;
|
||||
}
|
||||
#else
|
||||
sprintf(systemCmd, "chmod 777 %s", uartName);
|
||||
fp = popen(systemCmd, "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
uartHandleStruct->uartFd = open(uartName, (unsigned) O_RDWR | (unsigned) O_NOCTTY | (unsigned) O_NDELAY);
|
||||
if (uartHandleStruct->uartFd == -1) {
|
||||
goto close_fp;
|
||||
}
|
||||
|
||||
// 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(uartHandleStruct->uartFd, F_GETLK, &lock) < 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
if (lock.l_type != F_UNLCK) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_pid = getpid();
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
if (fcntl(uartHandleStruct->uartFd, F_SETLKW, &lock) < 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
if (tcgetattr(uartHandleStruct->uartFd, &options) != 0) {
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
switch (baudRate) {
|
||||
case 115200:
|
||||
cfsetispeed(&options, B115200);
|
||||
cfsetospeed(&options, B115200);
|
||||
break;
|
||||
case 230400:
|
||||
cfsetispeed(&options, B230400);
|
||||
cfsetospeed(&options, B230400);
|
||||
break;
|
||||
case 460800:
|
||||
cfsetispeed(&options, B460800);
|
||||
cfsetospeed(&options, B460800);
|
||||
break;
|
||||
case 921600:
|
||||
cfsetispeed(&options, B921600);
|
||||
cfsetospeed(&options, B921600);
|
||||
break;
|
||||
case 1000000:
|
||||
cfsetispeed(&options, B1000000);
|
||||
cfsetospeed(&options, B1000000);
|
||||
break;
|
||||
default:
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
options.c_cflag |= (unsigned) CLOCAL;
|
||||
options.c_cflag |= (unsigned) CREAD;
|
||||
options.c_cflag &= ~(unsigned) CRTSCTS;
|
||||
options.c_cflag &= ~(unsigned) CSIZE;
|
||||
options.c_cflag |= (unsigned) CS8;
|
||||
options.c_cflag &= ~(unsigned) PARENB;
|
||||
options.c_iflag &= ~(unsigned) INPCK;
|
||||
options.c_cflag &= ~(unsigned) CSTOPB;
|
||||
options.c_oflag &= ~(unsigned) OPOST;
|
||||
options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG);
|
||||
options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON);
|
||||
options.c_cc[VTIME] = 0;
|
||||
options.c_cc[VMIN] = 0;
|
||||
|
||||
tcflush(uartHandleStruct->uartFd, TCIFLUSH);
|
||||
|
||||
if (tcsetattr(uartHandleStruct->uartFd, TCSANOW, &options) != 0)
|
||||
{
|
||||
goto close_uart_fd;
|
||||
}
|
||||
|
||||
*uartHandle = uartHandleStruct;
|
||||
pclose(fp);
|
||||
|
||||
return returnCode;
|
||||
|
||||
close_uart_fd:
|
||||
close(uartHandleStruct->uartFd);
|
||||
|
||||
close_fp:
|
||||
pclose(fp);
|
||||
|
||||
free_uart_handle:
|
||||
free(uartHandleStruct);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
ret = close(uartHandleStruct->uartFd);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(uartHandleStruct);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = write(uartHandleStruct->uartFd, buf, len);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
|
||||
|
||||
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = read(uartHandleStruct->uartFd, buf, len);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status)
|
||||
{
|
||||
if (uartNum == DJI_HAL_UART_NUM_0) {
|
||||
status->isConnect = true;
|
||||
} else if (uartNum == DJI_HAL_UART_NUM_1) {
|
||||
status->isConnect = true;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
68
Source/M300/PSDK_Qt/hal/hal_uart.h
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_uart.h
|
||||
* @brief This is the header file for "hal_uart.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_UART_H
|
||||
#define HAL_UART_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//global
|
||||
extern char gvpcM300RTK_UART1[128];
|
||||
extern char gvpcM300RTK_UART2[128];
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
//User can config dev based on there environmental conditions
|
||||
#define LINUX_UART_DEV1 "/dev/ttyS1"
|
||||
#define LINUX_UART_DEV2 "/dev/ttyACM0"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle);
|
||||
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle);
|
||||
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_UART_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
224
Source/M300/PSDK_Qt/hal/hal_usb_bulk.c
Normal file
@ -0,0 +1,224 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hal_usb_bulk.h"
|
||||
#include "dji_logger.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
|
||||
#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
libusb_device_handle *handle;
|
||||
#else
|
||||
void *handle;
|
||||
#endif
|
||||
int32_t ep1;
|
||||
int32_t ep2;
|
||||
uint32_t interfaceNum;
|
||||
T_DjiHalUsbBulkInfo usbBulkInfo;
|
||||
} T_HalUsbBulkObj;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
*usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj));
|
||||
if (*usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_init(NULL);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
|
||||
if (handle == NULL) {
|
||||
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");
|
||||
libusb_close(handle);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
|
||||
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
|
||||
#endif
|
||||
} else {
|
||||
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
|
||||
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
|
||||
((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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle)
|
||||
{
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
|
||||
osalHandler->TaskSleepMs(100);
|
||||
libusb_exit(NULL);
|
||||
#endif
|
||||
} else {
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1);
|
||||
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2);
|
||||
}
|
||||
|
||||
free(usbBulkHandle);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t actualLen;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut,
|
||||
(uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
#endif
|
||||
} else {
|
||||
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
struct libusb_device_handle *handle = NULL;
|
||||
int32_t actualLen;
|
||||
|
||||
if (usbBulkHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
|
||||
|
||||
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn,
|
||||
buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER);
|
||||
if (ret < 0) {
|
||||
USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*realLen = actualLen;
|
||||
#endif
|
||||
} else {
|
||||
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo)
|
||||
{
|
||||
//attention: this interface only be called in usb device mode.
|
||||
deviceInfo->vid = LINUX_USB_VID;
|
||||
deviceInfo->pid = LINUX_USB_PID;
|
||||
|
||||
// This bulk channel is used to obtain DJI camera video stream and push 3rd-party camera video stream.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT;
|
||||
|
||||
// This bulk channel is used to obtain DJI perception image and download camera media file.
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN;
|
||||
deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
91
Source/M300/PSDK_Qt/hal/hal_usb_bulk.h
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file hal_usb_bulk.h
|
||||
* @brief This is the header file for "hal_usb_bulk.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef HAL_USB_BULK_H
|
||||
#define HAL_USB_BULK_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef LIBUSB_INSTALLED
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
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_INTERFACE_NUM (2)
|
||||
#define LINUX_USB_BULK1_END_POINT_IN (0x83)
|
||||
#define LINUX_USB_BULK1_END_POINT_OUT (2)
|
||||
|
||||
#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_INTERFACE_NUM (3)
|
||||
#define LINUX_USB_BULK2_END_POINT_IN (0x84)
|
||||
#define LINUX_USB_BULK2_END_POINT_OUT (3)
|
||||
|
||||
#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
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode HalUsbBulk_Init(T_DjiHalUsbBulkInfo usbBulkInfo, T_DjiUsbBulkHandle *usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_DeInit(T_DjiUsbBulkHandle usbBulkHandle);
|
||||
T_DjiReturnCode HalUsbBulk_WriteData(T_DjiUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
|
||||
uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_ReadData(T_DjiUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAL_USB_BULK_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
324
Source/M300/PSDK_Qt/osal/osal.c
Normal file
@ -0,0 +1,324 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal.h"
|
||||
#include "dji_typedef.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
static uint32_t s_localTimeMsOffset = 0;
|
||||
static uint64_t s_localTimeUsOffset = 0;
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *), uint32_t stackSize, void *arg,
|
||||
T_DjiTaskHandle *task)
|
||||
{
|
||||
int result;
|
||||
char nameDealed[16] = {0};
|
||||
|
||||
*task = malloc(sizeof(pthread_t));
|
||||
if (*task == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_create(*task, NULL, taskFunc, arg);
|
||||
if (result != 0) {
|
||||
return DJI_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 DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task)
|
||||
{
|
||||
pthread_cancel(*(pthread_t *) task);
|
||||
free(task);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs)
|
||||
{
|
||||
usleep(1000 * timeMs);
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
*mutex = malloc(sizeof(pthread_mutex_t));
|
||||
if (*mutex == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = pthread_mutex_init(*mutex, NULL);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = pthread_mutex_destroy(mutex);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
free(mutex);
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_lock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex)
|
||||
{
|
||||
int result = pthread_mutex_unlock(mutex);
|
||||
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
*semaphore = malloc(sizeof(sem_t));
|
||||
if (*semaphore == NULL) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
result = sem_init(*semaphore, 0, (unsigned int) initValue);
|
||||
if (result != 0) {
|
||||
return
|
||||
DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return
|
||||
DJI_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_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_destroy((sem_t *) semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
free(semaphore);
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_wait(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle 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 DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_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_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = sem_post(semaphore);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the system time for ms.
|
||||
* @return an uint32 that the time of system, uint:ms
|
||||
*/
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*ms = (time.tv_sec * 1000 + time.tv_usec / 1000);
|
||||
|
||||
if (s_localTimeMsOffset == 0) {
|
||||
s_localTimeMsOffset = *ms;
|
||||
} else {
|
||||
*ms = *ms - s_localTimeMsOffset;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, NULL);
|
||||
*us = (time.tv_sec * 1000000 + time.tv_usec);
|
||||
|
||||
if (s_localTimeUsOffset == 0) {
|
||||
s_localTimeUsOffset = *us;
|
||||
} else {
|
||||
*us = *us - s_localTimeMsOffset;
|
||||
}
|
||||
|
||||
return DJI_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
Source/M300/PSDK_Qt/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) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef 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 "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_TaskCreate(const char *name, void *(*taskFunc)(void *),
|
||||
uint32_t stackSize, void *arg, T_DjiTaskHandle *task);
|
||||
T_DjiReturnCode Osal_TaskDestroy(T_DjiTaskHandle task);
|
||||
T_DjiReturnCode Osal_TaskSleepMs(uint32_t timeMs);
|
||||
|
||||
T_DjiReturnCode Osal_MutexCreate(T_DjiMutexHandle *mutex);
|
||||
T_DjiReturnCode Osal_MutexDestroy(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexLock(T_DjiMutexHandle mutex);
|
||||
T_DjiReturnCode Osal_MutexUnlock(T_DjiMutexHandle mutex);
|
||||
|
||||
T_DjiReturnCode Osal_SemaphoreCreate(uint32_t initValue, T_DjiSemaHandle *semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreDestroy(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreWait(T_DjiSemaHandle semaphore);
|
||||
T_DjiReturnCode Osal_SemaphoreTimedWait(T_DjiSemaHandle semaphore, uint32_t waitTime);
|
||||
T_DjiReturnCode Osal_SemaphorePost(T_DjiSemaHandle semaphore);
|
||||
|
||||
T_DjiReturnCode Osal_GetTimeMs(uint32_t *ms);
|
||||
T_DjiReturnCode Osal_GetTimeUs(uint64_t *us);
|
||||
|
||||
void *Osal_Malloc(uint32_t size);
|
||||
void Osal_Free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
293
Source/M300/PSDK_Qt/osal/osal_fs.c
Normal file
@ -0,0 +1,293 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal_fs.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "time.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj)
|
||||
{
|
||||
if (fileName == NULL || fileMode == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*fileObj = malloc(sizeof(FILE));
|
||||
if (*fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
*fileObj = fopen(fileName, fileMode);
|
||||
if (*fileObj == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
free(*fileObj);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fclose(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fwrite(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fread(buf, 1, len, fileObj);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fseek(fileObj, offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = fflush(fileObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj)
|
||||
{
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*dirObj = opendir(filePath);
|
||||
if (*dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (dirObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = closedir((DIR *) dirObj);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct dirent *dirent;
|
||||
|
||||
if (dirObj == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dirent = readdir((DIR *) dirObj);
|
||||
if (!dirent) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
if (dirent->d_type == DT_DIR) {
|
||||
fileInfo->isDir = true;
|
||||
} else {
|
||||
fileInfo->isDir = false;
|
||||
}
|
||||
strcpy(fileInfo->path, dirent->d_name);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = mkdir(filePath, S_IRWXU);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (filePath[strlen(filePath) - 1] == '/') {
|
||||
ret = rmdir(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = unlink(filePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (oldFilePath == NULL || newFilePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = rename(oldFilePath, newFilePath);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo)
|
||||
{
|
||||
struct stat st;
|
||||
int32_t ret;
|
||||
struct tm *fileTm;
|
||||
|
||||
if (filePath == NULL || fileInfo == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = stat(filePath, &st);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileTm = localtime(&(st.st_ctime));
|
||||
if (fileTm == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileInfo->size = st.st_size;
|
||||
|
||||
fileInfo->createTime.year = fileTm->tm_year + 1900 - 1980;
|
||||
fileInfo->createTime.month = fileTm->tm_mon;
|
||||
fileInfo->createTime.day = fileTm->tm_mday;
|
||||
fileInfo->createTime.hour = fileTm->tm_hour;
|
||||
fileInfo->createTime.minute = fileTm->tm_min;
|
||||
fileInfo->createTime.second = fileTm->tm_sec;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
73
Source/M300/PSDK_Qt/osal/osal_fs.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_fs.h
|
||||
* @brief This is the header file for "osal_fs.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_FS_H
|
||||
#define OSAL_FS_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_FileOpen(const char *fileName, const char *fileMode, T_DjiFileHandle *fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileClose(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_FileWrite(T_DjiFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileRead(T_DjiFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_FileSeek(T_DjiFileHandle fileObj, uint32_t offset);
|
||||
|
||||
T_DjiReturnCode Osal_FileSync(T_DjiFileHandle fileObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirOpen(const char *filePath, T_DjiDirHandle *dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirClose(T_DjiDirHandle dirObj);
|
||||
|
||||
T_DjiReturnCode Osal_DirRead(T_DjiDirHandle dirObj, T_DjiFileInfo *fileInfo);
|
||||
|
||||
T_DjiReturnCode Osal_Mkdir(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Unlink(const char *filePath);
|
||||
|
||||
T_DjiReturnCode Osal_Rename(const char *oldFilePath, const char *newFilePath);
|
||||
|
||||
T_DjiReturnCode Osal_Stat(const char *filePath, T_DjiFileInfo *fileInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_FS_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
272
Source/M300/PSDK_Qt/osal/osal_socket.c
Normal file
@ -0,0 +1,272 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_socket.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "osal_socket.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int socketFd;
|
||||
} T_SocketHandleStruct;
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_Socket(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct;
|
||||
|
||||
if (socketHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
socketHandleStruct = malloc(sizeof(T_SocketHandleStruct));
|
||||
if (socketHandleStruct == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
if (mode == DJI_SOCKET_MODE_UDP) {
|
||||
socketHandleStruct->socketFd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
} else if (mode == DJI_SOCKET_MODE_TCP) {
|
||||
socketHandleStruct->socketFd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*socketHandle = socketHandleStruct;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Close(T_DjiSocketHandle socketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandleStruct->socketFd <= 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = close(socketHandleStruct->socketFd);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_Bind(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
struct sockaddr_in addr;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = bind(socketHandleStruct->socketFd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_UdpSendData(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle <= 0 || ipAddr == NULL || port == 0 || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = sendto(socketHandleStruct->socketFd, buf, len, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_UdpRecvData(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
uint32_t addrLen = 0;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0 || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = recvfrom(socketHandleStruct->socketFd, buf, len, 0, (struct sockaddr *) &addr, &addrLen);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
strcpy(ipAddr, inet_ntoa(addr.sin_addr));
|
||||
*port = ntohs(addr.sin_port);
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpListen(T_DjiSocketHandle socketHandle)
|
||||
{
|
||||
int32_t ret;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
|
||||
if (socketHandle == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = listen(socketHandleStruct->socketFd, 5);
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpAccept(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
T_DjiSocketHandle *outSocketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
T_SocketHandleStruct *outSocketHandleStruct;
|
||||
struct sockaddr_in addr;
|
||||
uint32_t addrLen = 0;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
outSocketHandleStruct = malloc(sizeof(T_SocketHandleStruct));
|
||||
if (outSocketHandleStruct == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
outSocketHandleStruct->socketFd = accept(socketHandleStruct->socketFd, (struct sockaddr *) &addr, &addrLen);
|
||||
if (outSocketHandleStruct->socketFd < 0) {
|
||||
free(outSocketHandleStruct);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*port = ntohs(addr.sin_port);
|
||||
*outSocketHandle = outSocketHandleStruct;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpConnect(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || ipAddr == NULL || port == 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(ipAddr);
|
||||
|
||||
ret = connect(socketHandleStruct->socketFd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpSendData(T_DjiSocketHandle socketHandle,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = send(socketHandleStruct->socketFd, buf, len, 0);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_TcpRecvData(T_DjiSocketHandle socketHandle,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct = (T_SocketHandleStruct *) socketHandle;
|
||||
int32_t ret;
|
||||
|
||||
if (socketHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = recv(socketHandleStruct->socketFd, buf, len, 0);
|
||||
if (ret >= 0) {
|
||||
*realLen = ret;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
72
Source/M300/PSDK_Qt/osal/osal_socket.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file osal_socket.h
|
||||
* @brief This is the header file for "osal_socket.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef OSAL_SOCKET_H
|
||||
#define OSAL_SOCKET_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode Osal_Socket(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_Close(T_DjiSocketHandle socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_Bind(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
|
||||
|
||||
T_DjiReturnCode Osal_UdpSendData(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_UdpRecvData(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_TcpListen(T_DjiSocketHandle socketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_TcpAccept(T_DjiSocketHandle socketHandle, char *ipAddr, uint32_t *port,
|
||||
T_DjiSocketHandle *outSocketHandle);
|
||||
|
||||
T_DjiReturnCode Osal_TcpConnect(T_DjiSocketHandle socketHandle, const char *ipAddr, uint32_t port);
|
||||
|
||||
T_DjiReturnCode Osal_TcpSendData(T_DjiSocketHandle socketHandle,
|
||||
const uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
T_DjiReturnCode Osal_TcpRecvData(T_DjiSocketHandle socketHandle,
|
||||
uint8_t *buf, uint32_t len, uint32_t *realLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_SOCKET_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
127
Source/M300/PSDK_Qt/util_buffer.c
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file util_buffer.c
|
||||
* @brief The file defines buffer related functions, including initialize, put data to buffer,
|
||||
* get data from buffer and get unused count of bytes of buffer.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "util_buffer.h"
|
||||
#include <string.h>
|
||||
#include "util_misc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Cut buffer size to power of 2, in order to increase the convenience of get and put operating of buffer.
|
||||
* @param bufSize Original buffer size.
|
||||
* @return Buffer size after handling.
|
||||
*/
|
||||
static uint16_t UtilBuffer_CutBufSizeToPowOfTwo(uint16_t bufSize)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
while ((1 << (++i)) <= bufSize);
|
||||
return (uint16_t) (1 << (--i));
|
||||
}
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Buffer initialization.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pBuf Pointer to data buffer.
|
||||
* @param bufSize Size of data buffer.
|
||||
* @return None.
|
||||
*/
|
||||
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize)
|
||||
{
|
||||
pthis->readIndex = 0;
|
||||
pthis->writeIndex = 0;
|
||||
pthis->bufferPtr = pBuf;
|
||||
pthis->bufferSize = UtilBuffer_CutBufSizeToPowOfTwo(bufSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put a block of data into buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pData Pointer to data to be stored.
|
||||
* @param dataLen Length of data to be stored.
|
||||
* @return Length of data to be stored.
|
||||
*/
|
||||
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen)
|
||||
{
|
||||
uint16_t writeUpLen;
|
||||
|
||||
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex));
|
||||
|
||||
//fill up data
|
||||
writeUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->writeIndex & (pthis->bufferSize - 1))));
|
||||
memcpy(pthis->bufferPtr + (pthis->writeIndex & (pthis->bufferSize - 1)), pData, writeUpLen);
|
||||
|
||||
//fill begin data
|
||||
memcpy(pthis->bufferPtr, pData + writeUpLen, dataLen - writeUpLen);
|
||||
|
||||
pthis->writeIndex += dataLen;
|
||||
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a block of data from buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @param pData Pointer to data to be read.
|
||||
* @param dataLen Length of data to be read.
|
||||
* @return Length of data to be read.
|
||||
*/
|
||||
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen)
|
||||
{
|
||||
uint16_t readUpLen;
|
||||
|
||||
dataLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->writeIndex - pthis->readIndex));
|
||||
|
||||
//get up data
|
||||
readUpLen = USER_UTIL_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->readIndex & (pthis->bufferSize - 1))));
|
||||
memcpy(pData, pthis->bufferPtr + (pthis->readIndex & (pthis->bufferSize - 1)), readUpLen);
|
||||
|
||||
//get begin data
|
||||
memcpy(pData + readUpLen, pthis->bufferPtr, dataLen - readUpLen);
|
||||
|
||||
pthis->readIndex += dataLen;
|
||||
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get unused size of buffer.
|
||||
* @param pthis Pointer to buffer structure.
|
||||
* @return Unused size of buffer.
|
||||
*/
|
||||
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis)
|
||||
{
|
||||
return (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex);
|
||||
}
|
||||
59
Source/M300/PSDK_Qt/util_buffer.h
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file util_buffer.h
|
||||
* @brief This is the header file for "util_buffer.c".
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _DJI_UTIL_BUFFER_H_
|
||||
#define _DJI_UTIL_BUFFER_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
//Note: not need lock for just one producer / one consumer
|
||||
//need mutex to protect for multi-producer / multi-consumer
|
||||
typedef struct {
|
||||
uint8_t *bufferPtr;
|
||||
uint16_t bufferSize;
|
||||
uint16_t readIndex;
|
||||
uint16_t writeIndex;
|
||||
} T_UtilBuffer;
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
void UtilBuffer_Init(T_UtilBuffer *pthis, uint8_t *pBuf, uint16_t bufSize);
|
||||
uint16_t UtilBuffer_Put(T_UtilBuffer *pthis, const uint8_t *pData, uint16_t dataLen);
|
||||
uint16_t UtilBuffer_Get(T_UtilBuffer *pthis, uint8_t *pData, uint16_t dataLen);
|
||||
uint16_t UtilBuffer_GetUnusedSize(T_UtilBuffer *pthis);
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
207
Source/M300/PSDK_Qt/util_file.c
Normal file
@ -0,0 +1,207 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_file.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include "util_file.h"
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime)
|
||||
{
|
||||
struct stat st;
|
||||
struct tm *fileTm;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (stat(filePath, &st) != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
fileTm = localtime(&(st.st_ctime));
|
||||
if (fileTm == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
createTime->year = fileTm->tm_year + 1900 - 1980;
|
||||
createTime->month = fileTm->tm_mon;
|
||||
createTime->day = fileTm->tm_mday;
|
||||
createTime->hour = fileTm->tm_hour;
|
||||
createTime->minute = fileTm->tm_min;
|
||||
createTime->second = fileTm->tm_sec;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (stat(filePath, &st) != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
*fileSize = st.st_size;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint16_t len,
|
||||
uint8_t *data, uint16_t *realLen)
|
||||
{
|
||||
FILE *pF;
|
||||
T_DjiReturnCode psdkStat;
|
||||
uint32_t readRtn;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
pF = fopen(filePath, "rb+");
|
||||
if (pF == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (fseek(pF, offset, SEEK_SET) != 0) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
readRtn = fread(data, 1, len, pF);
|
||||
if (readRtn == 0 || readRtn > len) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*realLen = readRtn;
|
||||
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
fclose(pF);
|
||||
|
||||
return psdkStat;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_Delete(const char *filePath)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (filePath == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ret = unlink(filePath);
|
||||
|
||||
if (ret != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
} else {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (file == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
long int curSeek = ftell(file);
|
||||
|
||||
result = fseek(file, 0L, SEEK_END);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
*fileSize = ftell(file);
|
||||
|
||||
if (curSeek < 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
result = fseek(file, curSeek, SEEK_SET);
|
||||
if (result != 0) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||
}
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen)
|
||||
{
|
||||
T_DjiReturnCode psdkStat;
|
||||
uint32_t readRtn;
|
||||
|
||||
if (file == NULL) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fseek(file, offset, SEEK_SET) != 0) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
readRtn = fread(data, 1, len, file);
|
||||
if (readRtn == 0 || readRtn > len) {
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*realLen = readRtn;
|
||||
|
||||
psdkStat = DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
return psdkStat;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
70
Source/M300/PSDK_Qt/util_file.h
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_file.h
|
||||
* @brief This is the header file for "util_file.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_FILE_H
|
||||
#define UTIL_FILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <dji_typedef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
uint32_t second: 5;
|
||||
uint32_t minute: 6;
|
||||
uint32_t hour: 5;
|
||||
uint32_t day: 5;
|
||||
uint32_t month: 4;
|
||||
uint32_t year: 7;
|
||||
} T_UtilFileCreateTime;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode UtilFile_GetCreateTime(const char *filePath, T_UtilFileCreateTime *createTime);
|
||||
T_DjiReturnCode UtilFile_GetFileSizeByPath(const char *filePath, uint32_t *fileSize);
|
||||
T_DjiReturnCode UtilFile_GetFileDataByPath(const char *filePath, uint32_t offset, uint16_t len,
|
||||
uint8_t *data, uint16_t *realLen);
|
||||
T_DjiReturnCode DjiFile_Delete(const char *filePath);
|
||||
|
||||
T_DjiReturnCode UtilFile_GetFileSize(FILE *file, uint32_t *fileSize);
|
||||
T_DjiReturnCode UtilFile_GetFileData(FILE *file, uint32_t offset, uint16_t len, uint8_t *data, uint16_t *realLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // UTIL_FILE_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
238
Source/M300/PSDK_Qt/util_md5.c
Normal file
@ -0,0 +1,238 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_md5.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* crypto-algorithms
|
||||
* =================
|
||||
*
|
||||
* About
|
||||
* ---
|
||||
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
|
||||
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
|
||||
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
|
||||
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
|
||||
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
|
||||
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
|
||||
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
|
||||
* author.
|
||||
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
|
||||
* and should not be used in contexts that need cryptographically secure implementations.
|
||||
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
|
||||
* basic optimization techniques have been employed.
|
||||
* Building
|
||||
* ---
|
||||
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
|
||||
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
|
||||
* matters. Compiling them should be as easy as adding the relevent source code to the project.
|
||||
*
|
||||
* @statement DJI has modified some symbols' name.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "util_md5.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
#define ROTLEFT(a, b) ((a << b) | (a >> (32-b)))
|
||||
|
||||
#define F(x, y, z) ((x & y) | (~x & z))
|
||||
#define G(x, y, z) ((x & z) | (y & ~z))
|
||||
#define H(x, y, z) (x ^ y ^ z)
|
||||
#define I(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
#define FF(a, b, c, d, m, s, t) { a += F(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define GG(a, b, c, d, m, s, t) { a += G(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define HH(a, b, c, d, m, s, t) { a += H(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
#define II(a, b, c, d, m, s, t) { a += I(b,c,d) + m + t; \
|
||||
a = b + ROTLEFT(a,s); }
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
void UtilMd5_Transform(MD5_CTX *ctx, const BYTE *data)
|
||||
{
|
||||
WORD a, b, c, d, m[16], i, j;
|
||||
|
||||
// MD5 specifies big endian byte order, but this implementation assumes a little
|
||||
// endian byte order CPU. Reverse all the bytes upon input, and re-reverse them
|
||||
// on output (in md5_final()).
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4) {
|
||||
m[i] = (data[j]) + (data[j + 1] << 8) + (data[j + 2] << 16) + (data[j + 3] << 24);
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
|
||||
FF(a, b, c, d, m[0], 7, 0xd76aa478);
|
||||
FF(d, a, b, c, m[1], 12, 0xe8c7b756);
|
||||
FF(c, d, a, b, m[2], 17, 0x242070db);
|
||||
FF(b, c, d, a, m[3], 22, 0xc1bdceee);
|
||||
FF(a, b, c, d, m[4], 7, 0xf57c0faf);
|
||||
FF(d, a, b, c, m[5], 12, 0x4787c62a);
|
||||
FF(c, d, a, b, m[6], 17, 0xa8304613);
|
||||
FF(b, c, d, a, m[7], 22, 0xfd469501);
|
||||
FF(a, b, c, d, m[8], 7, 0x698098d8);
|
||||
FF(d, a, b, c, m[9], 12, 0x8b44f7af);
|
||||
FF(c, d, a, b, m[10], 17, 0xffff5bb1);
|
||||
FF(b, c, d, a, m[11], 22, 0x895cd7be);
|
||||
FF(a, b, c, d, m[12], 7, 0x6b901122);
|
||||
FF(d, a, b, c, m[13], 12, 0xfd987193);
|
||||
FF(c, d, a, b, m[14], 17, 0xa679438e);
|
||||
FF(b, c, d, a, m[15], 22, 0x49b40821);
|
||||
|
||||
GG(a, b, c, d, m[1], 5, 0xf61e2562);
|
||||
GG(d, a, b, c, m[6], 9, 0xc040b340);
|
||||
GG(c, d, a, b, m[11], 14, 0x265e5a51);
|
||||
GG(b, c, d, a, m[0], 20, 0xe9b6c7aa);
|
||||
GG(a, b, c, d, m[5], 5, 0xd62f105d);
|
||||
GG(d, a, b, c, m[10], 9, 0x02441453);
|
||||
GG(c, d, a, b, m[15], 14, 0xd8a1e681);
|
||||
GG(b, c, d, a, m[4], 20, 0xe7d3fbc8);
|
||||
GG(a, b, c, d, m[9], 5, 0x21e1cde6);
|
||||
GG(d, a, b, c, m[14], 9, 0xc33707d6);
|
||||
GG(c, d, a, b, m[3], 14, 0xf4d50d87);
|
||||
GG(b, c, d, a, m[8], 20, 0x455a14ed);
|
||||
GG(a, b, c, d, m[13], 5, 0xa9e3e905);
|
||||
GG(d, a, b, c, m[2], 9, 0xfcefa3f8);
|
||||
GG(c, d, a, b, m[7], 14, 0x676f02d9);
|
||||
GG(b, c, d, a, m[12], 20, 0x8d2a4c8a);
|
||||
|
||||
HH(a, b, c, d, m[5], 4, 0xfffa3942);
|
||||
HH(d, a, b, c, m[8], 11, 0x8771f681);
|
||||
HH(c, d, a, b, m[11], 16, 0x6d9d6122);
|
||||
HH(b, c, d, a, m[14], 23, 0xfde5380c);
|
||||
HH(a, b, c, d, m[1], 4, 0xa4beea44);
|
||||
HH(d, a, b, c, m[4], 11, 0x4bdecfa9);
|
||||
HH(c, d, a, b, m[7], 16, 0xf6bb4b60);
|
||||
HH(b, c, d, a, m[10], 23, 0xbebfbc70);
|
||||
HH(a, b, c, d, m[13], 4, 0x289b7ec6);
|
||||
HH(d, a, b, c, m[0], 11, 0xeaa127fa);
|
||||
HH(c, d, a, b, m[3], 16, 0xd4ef3085);
|
||||
HH(b, c, d, a, m[6], 23, 0x04881d05);
|
||||
HH(a, b, c, d, m[9], 4, 0xd9d4d039);
|
||||
HH(d, a, b, c, m[12], 11, 0xe6db99e5);
|
||||
HH(c, d, a, b, m[15], 16, 0x1fa27cf8);
|
||||
HH(b, c, d, a, m[2], 23, 0xc4ac5665);
|
||||
|
||||
II(a, b, c, d, m[0], 6, 0xf4292244);
|
||||
II(d, a, b, c, m[7], 10, 0x432aff97);
|
||||
II(c, d, a, b, m[14], 15, 0xab9423a7);
|
||||
II(b, c, d, a, m[5], 21, 0xfc93a039);
|
||||
II(a, b, c, d, m[12], 6, 0x655b59c3);
|
||||
II(d, a, b, c, m[3], 10, 0x8f0ccc92);
|
||||
II(c, d, a, b, m[10], 15, 0xffeff47d);
|
||||
II(b, c, d, a, m[1], 21, 0x85845dd1);
|
||||
II(a, b, c, d, m[8], 6, 0x6fa87e4f);
|
||||
II(d, a, b, c, m[15], 10, 0xfe2ce6e0);
|
||||
II(c, d, a, b, m[6], 15, 0xa3014314);
|
||||
II(b, c, d, a, m[13], 21, 0x4e0811a1);
|
||||
II(a, b, c, d, m[4], 6, 0xf7537e82);
|
||||
II(d, a, b, c, m[11], 10, 0xbd3af235);
|
||||
II(c, d, a, b, m[2], 15, 0x2ad7d2bb);
|
||||
II(b, c, d, a, m[9], 21, 0xeb86d391);
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
}
|
||||
|
||||
void UtilMd5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->datalen = 0;
|
||||
ctx->bitlen = 0;
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
ctx->data[ctx->datalen] = data[i];
|
||||
ctx->datalen++;
|
||||
if (ctx->datalen == 64) {
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
ctx->bitlen += 512;
|
||||
ctx->datalen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = ctx->datalen;
|
||||
|
||||
// Pad whatever data is left in the buffer.
|
||||
if (ctx->datalen < 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 56) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
} else if (ctx->datalen >= 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 64) {
|
||||
ctx->data[i++] = 0x00;
|
||||
}
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
memset(ctx->data, 0, 56);
|
||||
}
|
||||
|
||||
// Append to the padding the total message's length in bits and transform.
|
||||
ctx->bitlen += ctx->datalen * 8;
|
||||
ctx->data[56] = ctx->bitlen;
|
||||
ctx->data[57] = ctx->bitlen >> 8;
|
||||
ctx->data[58] = ctx->bitlen >> 16;
|
||||
ctx->data[59] = ctx->bitlen >> 24;
|
||||
ctx->data[60] = ctx->bitlen >> 32;
|
||||
ctx->data[61] = ctx->bitlen >> 40;
|
||||
ctx->data[62] = ctx->bitlen >> 48;
|
||||
ctx->data[63] = ctx->bitlen >> 56;
|
||||
UtilMd5_Transform(ctx, ctx->data);
|
||||
|
||||
// Since this implementation uses little endian byte ordering and MD uses big endian,
|
||||
// reverse all the bytes when copying the final state to the output hash.
|
||||
for (i = 0; i < 4; ++i) {
|
||||
hash[i] = (ctx->state[0] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 4] = (ctx->state[1] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 8] = (ctx->state[2] >> (i * 8)) & 0x000000ff;
|
||||
hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
|
||||
}
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
88
Source/M300/PSDK_Qt/util_md5.h
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_md5.h
|
||||
* @brief This is the header file for "util_md5.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
* crypto-algorithms
|
||||
* =================
|
||||
*
|
||||
* About
|
||||
* ---
|
||||
* These are basic implementations of standard cryptography algorithms, written by Brad Conte (brad@bradconte.com) from
|
||||
* scratch and without any cross-licensing. They exist to provide publically accessible, restriction-free implementations
|
||||
* of popular cryptographic algorithms, like AES and SHA-1. These are primarily intended for educational and pragmatic
|
||||
* purposes (such as comparing a specification to actual implementation code, or for building an internal application
|
||||
* that computes test vectors for a product). The algorithms have been tested against standard test vectors.
|
||||
* This code is released into the public domain free of any restrictions. The author requests acknowledgement if the code
|
||||
* is used, but does not require it. This code is provided free of any liability and without any quality claims by the
|
||||
* author.
|
||||
* Note that these are *not* cryptographically secure implementations. They have no resistence to side-channel attacks
|
||||
* and should not be used in contexts that need cryptographically secure implementations.
|
||||
* These algorithms are not optimized for speed or space. They are primarily designed to be easy to read, although some
|
||||
* basic optimization techniques have been employed.
|
||||
* Building
|
||||
* ---
|
||||
* The source code for each algorithm will come in a pair of a source code file and a header file. There should be no
|
||||
* inter-header file dependencies, no additional libraries, no platform-specific header files, or any other complicating
|
||||
* matters. Compiling them should be as easy as adding the relevent source code to the project.
|
||||
*
|
||||
* @statement DJI has modified some symbols' name.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_MD5_H
|
||||
#define UTIL_MD5_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef unsigned char BYTE; // 8-bit byte
|
||||
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
|
||||
|
||||
typedef struct {
|
||||
BYTE data[64];
|
||||
WORD datalen;
|
||||
unsigned long long bitlen;
|
||||
WORD state[4];
|
||||
} MD5_CTX;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
void UtilMd5_Init(MD5_CTX *ctx);
|
||||
void UtilMd5_Update(MD5_CTX *ctx, const BYTE *data, size_t len);
|
||||
void UtilMd5_Final(MD5_CTX *ctx, BYTE *hash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MD5_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
103
Source/M300/PSDK_Qt/util_misc.c
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_misc.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
#define SYSTEM_ARCH_LINUX
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include <stdio.h>
|
||||
#include "util_misc.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
const char *baseStr = "[>>>>>>>>>>>>>---------------------------------------------------------------------------------------] 13%";
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath)
|
||||
{
|
||||
uint32_t i = strlen(filePath) - 1;
|
||||
uint32_t dirPathLen;
|
||||
|
||||
while (filePath[i] != '/') {
|
||||
i--;
|
||||
}
|
||||
|
||||
dirPathLen = i + 1;
|
||||
|
||||
if (dirPathLen + 1 > pathBufferSize) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
memcpy(dirPath, filePath, dirPathLen);
|
||||
dirPath[dirPathLen] = 0;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = popen(systemCmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData)
|
||||
{
|
||||
for (int j = 0; j < strlen(baseStr) + strlen(userData) + 4; ++j) {
|
||||
printf("\b");
|
||||
}
|
||||
|
||||
printf("[");
|
||||
for (int j = 0; j < totalProgress; ++j) {
|
||||
if (j < currentProgress) {
|
||||
printf("%c", '>');
|
||||
} else {
|
||||
printf("-");
|
||||
}
|
||||
}
|
||||
|
||||
printf("] ");
|
||||
printf("%3d%%", currentProgress);
|
||||
printf("%s", userData);
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
58
Source/M300/PSDK_Qt/util_misc.h
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_misc.h
|
||||
* @brief This is the header file for "util_misc.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef UTIL_MISC_H
|
||||
#define UTIL_MISC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "dji_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define USER_UTIL_UNUSED(x) ((x) = (x))
|
||||
#define USER_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define USER_UTIL_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define USER_UTIL_IS_WORK_TURN(step, workfreq, taskfreq) (!((step) % (uint32_t) ((taskfreq) / (workfreq))))
|
||||
#define UTIL_OFFSETOF(type, member) ((size_t) & ((type *)0 )-> member)
|
||||
#define UTIL_ARRAY_SIZE(array) ((unsigned int) (sizeof(array) / sizeof((array)[0])))
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath);
|
||||
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData);
|
||||
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTIL_MISC_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
62
Source/M300/PSDK_Qt/util_time.c
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_time.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include "util_time.h"
|
||||
#include <sys/resource.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void)
|
||||
{
|
||||
T_DjiRunTimeStamps timeStamps;
|
||||
struct rusage rusage;
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
timeStamps.realUsec = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
|
||||
|
||||
getrusage(RUSAGE_SELF, &rusage);
|
||||
timeStamps.userUsec =
|
||||
(rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
|
||||
timeStamps.sysUsec =
|
||||
(rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
|
||||
|
||||
return timeStamps;
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
60
Source/M300/PSDK_Qt/util_time.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_time.h
|
||||
* @brief This is the header file for "util_time.c", defining the structure and
|
||||
* (exported) function prototypes.
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DJI_UTIL_TIME_H
|
||||
#define DJI_UTIL_TIME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
uint64_t realUsec;
|
||||
uint64_t userUsec;
|
||||
uint64_t sysUsec;
|
||||
} T_DjiRunTimeStamps;
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
T_DjiRunTimeStamps DjiUtilTime_GetRunTimeStamps(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // DJI_DP_UTILS_H
|
||||
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||