张卓写的代码
1
Source/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.vs
|
||||
117
Source/DataFileManager.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
#include "DataFileManager.h"
|
||||
|
||||
DataFileManager::DataFileManager(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_pqfData = NULL;
|
||||
m_qstrFilePath = "/home/data/Data/";
|
||||
}
|
||||
|
||||
DataFileManager::~DataFileManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DataFileManager::GenerateFilePath()
|
||||
{
|
||||
m_qdtTime = QDateTime::currentDateTime();
|
||||
// QTimeZone curZone;
|
||||
// m_qdtTime.toTimeZone();
|
||||
QString qstrAddYMD = m_qdtTime.toString("/yyyy_MM_dd");
|
||||
m_qdtTime = m_qdtTime.addSecs(3600 * 8);
|
||||
QString qstrAddHMS = m_qdtTime.toString("hh_mm_ss");
|
||||
|
||||
|
||||
m_qstrFullFileName = m_qstrFilePath + qstrAddYMD;
|
||||
QString qstrTemp = m_qstrFullFileName;
|
||||
|
||||
m_qstrFullFileName = m_qstrFullFileName + "/" + qstrAddHMS + ".csv";
|
||||
|
||||
QDir qdirPathTemp(m_qstrFilePath);
|
||||
if (!qdirPathTemp.exists())
|
||||
{
|
||||
bool bRes = qdirPathTemp.mkdir(m_qstrFilePath);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "DataFileProcessor mkdir Failed.";
|
||||
//printf("DataFileProcessor mkdir Failed");
|
||||
}
|
||||
}
|
||||
|
||||
QDir qdirPathTempA(qstrTemp);
|
||||
if (!qdirPathTempA.exists())
|
||||
{
|
||||
bool bRes = qdirPathTempA.mkdir(qstrTemp);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "DataFileProcessor mkdir Failed.";
|
||||
//printf("DataFileProcessor mkdir Failed");
|
||||
}
|
||||
}
|
||||
//return 0;
|
||||
}
|
||||
|
||||
int DataFileManager::GenerateFile()
|
||||
{
|
||||
m_pqfData = new QFile(m_qstrFullFileName);
|
||||
bool bRes = m_pqfData->open(QFile::WriteOnly | QFile::Text | QIODevice::Append);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "GenerateFile Failed.";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataFileManager::WriteData(M300RTKDataFrame struM300RTKDataFrame, GSDataFrame struGSDataFrame, UASDataFrame struUASDataFrame)
|
||||
{
|
||||
// QFile qfData(m_qstrFullFileName);
|
||||
// bool bRes = qfData.open(QFile::WriteOnly | QFile::Text | QIODevice::Append);
|
||||
// if (!bRes)
|
||||
// {
|
||||
// qDebug() << "WriteData open Failed.";
|
||||
// return 0;
|
||||
// }
|
||||
//////////////////////////////////////////////////////////////////////////add datetime 20230408
|
||||
QString qStrDate = QDate::currentDate().toString("yyyy/MM/dd,");
|
||||
QString qStrTime = QTime::currentTime().toString("hh:mm:ss,");
|
||||
|
||||
qint64 qRes = m_pqfData->write(qStrDate.toLatin1());
|
||||
qRes = m_pqfData->write(qStrTime.toLatin1());
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QString qstrTemp;
|
||||
qstrTemp = QString("%1,%2,%3,%4,").arg(struM300RTKDataFrame.stGPSPosition.x).arg(struM300RTKDataFrame.stGPSPosition.y).arg(struM300RTKDataFrame.stGPSPosition.z).arg(struM300RTKDataFrame.fAltitudeFused);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
//qDebug() << qstrTemp;
|
||||
//qDebug() << qRes;
|
||||
|
||||
qstrTemp= QString("%1,%2,%3,").arg(struM300RTKDataFrame.stVelocity.x).arg(struM300RTKDataFrame.stVelocity.y).arg(struM300RTKDataFrame.stVelocity.z);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
//qDebug() << qRes;
|
||||
//qDebug() << qstrTemp;
|
||||
|
||||
qstrTemp= QString("%1,%2,%3,%4,").arg(struM300RTKDataFrame.stQuaternion.w_q0).arg(struM300RTKDataFrame.stQuaternion.x_q1).arg(struM300RTKDataFrame.stQuaternion.y_q2).arg(struM300RTKDataFrame.stQuaternion.z_q3);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////20230428 add EulerAngle
|
||||
qstrTemp = QString("%1,%2,%3,").arg(struM300RTKDataFrame.stEulerAngle.pitch).arg(struM300RTKDataFrame.stEulerAngle.roll).arg(struM300RTKDataFrame.stEulerAngle.yaw);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
qstrTemp = QString("%1,%2,%3,%4,%5,").arg(struGSDataFrame.ulCO2).arg(struGSDataFrame.ulH2O).arg(struGSDataFrame.fTemp).arg(struGSDataFrame.fPP).arg(struGSDataFrame.fPB);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
|
||||
qstrTemp = QString("%1,%2,%3,%4,%5").arg(struUASDataFrame.fFixedWindDirection).arg(struUASDataFrame.fFixedWindSpeed).arg(struUASDataFrame.fWindDirection).arg(struUASDataFrame.fWindSpeed).arg(struUASDataFrame.fWindTemperature);
|
||||
qRes = m_pqfData->write(qstrTemp.toLatin1());
|
||||
|
||||
m_pqfData->write("\n");
|
||||
|
||||
m_pqfData->flush();
|
||||
//QString qstrTemp;
|
||||
}
|
||||
|
||||
int DataFileManager::CloseData()
|
||||
{
|
||||
m_pqfData->flush();
|
||||
m_pqfData->close();
|
||||
}
|
||||
|
||||
35
Source/DataFileManager.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "ZZ_Types.h"
|
||||
|
||||
using namespace ZZ_DATA_DEF::M300RTK;
|
||||
using namespace ZZ_DATA_DEF::CO2_GAS_SENSOR;
|
||||
using namespace ZZ_DATA_DEF::UA_SENSOR;
|
||||
|
||||
class DataFileManager :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataFileManager(QObject* parent = nullptr);
|
||||
virtual ~DataFileManager();
|
||||
public:
|
||||
public:
|
||||
void GenerateFilePath();
|
||||
int GenerateFile();
|
||||
int WriteData(M300RTKDataFrame struM300RTKDataFrame,GSDataFrame struGSDataFrame,UASDataFrame struUASDataFrame);
|
||||
int CloseData();
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
private:
|
||||
QString m_qstrFullFileName;
|
||||
QString m_qstrFileName;
|
||||
QString m_qstrFilePath;
|
||||
QDateTime m_qdtTime;
|
||||
|
||||
QFile *m_pqfData;
|
||||
|
||||
};
|
||||
259
Source/EGM96/EGM96.c
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (c) 2006 D.Ineiev <ineiev@yahoo.co.uk>
|
||||
* Copyright (c) 2020 Emeric Grange <emeric.grange@gmail.com>
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program is designed for the calculation of a geoid undulation at a point
|
||||
* whose latitude and longitude is specified.
|
||||
*
|
||||
* This program is designed to be used with the constants of EGM96 and those of
|
||||
* the WGS84(g873) system. The undulation will refer to the WGS84 ellipsoid.
|
||||
*
|
||||
* It's designed to use the potential coefficient model EGM96 and a set of
|
||||
* spherical harmonic coefficients of a correction term.
|
||||
* The correction term is composed of several different components, the primary
|
||||
* one being the conversion of a height anomaly to a geoid undulation.
|
||||
* The principles of this procedure were initially described in the paper:
|
||||
* - use of potential coefficient models for geoid undulation determination using
|
||||
* a spherical harmonic representation of the height anomaly/geoid undulation
|
||||
* difference by R.H. Rapp, Journal of Geodesy, 1996.
|
||||
*
|
||||
* This program is a modification of the program described in the following report:
|
||||
* - a fortran program for the computation of gravimetric quantities from high
|
||||
* degree spherical harmonic expansions, Richard H. Rapp, report 334, Department
|
||||
* of Geodetic Science and Surveying, the Ohio State University, Columbus, 1982
|
||||
*/
|
||||
|
||||
#include "EGM96.h"
|
||||
#include "EGM96_data.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
#define _coeffs (65341) //!< Size of correction and harmonic coefficients arrays (361*181)
|
||||
#define _nmax (360) //!< Maximum degree and orders of harmonic coefficients.
|
||||
#define _361 (361)
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
double hundu(double p[_coeffs+1],
|
||||
double sinml[_361+1], double cosml[_361+1],
|
||||
double gr, double re)
|
||||
{
|
||||
// WGS 84 gravitational constant in m³/s² (mass of Earth’s atmosphere included)
|
||||
const double GM = 0.3986004418e15;
|
||||
// WGS 84 datum surface equatorial radius
|
||||
const double ae = 6378137.0;
|
||||
|
||||
double ar = ae/re;
|
||||
double arn = ar;
|
||||
double ac = 0;
|
||||
double a = 0;
|
||||
|
||||
unsigned k = 3;
|
||||
for (unsigned n = 2; n <= _nmax; n++)
|
||||
{
|
||||
arn *= ar;
|
||||
k++;
|
||||
double sum = p[k]*egm96_data[k][2];
|
||||
double sumc = p[k]*egm96_data[k][0];
|
||||
|
||||
for (unsigned m = 1; m <= n; m++)
|
||||
{
|
||||
k++;
|
||||
double tempc = egm96_data[k][0]*cosml[m] + egm96_data[k][1]*sinml[m];
|
||||
double temp = egm96_data[k][2]*cosml[m] + egm96_data[k][3]*sinml[m];
|
||||
sumc += p[k]*tempc;
|
||||
sum += p[k]*temp;
|
||||
}
|
||||
ac += sumc;
|
||||
a += sum*arn;
|
||||
}
|
||||
ac += egm96_data[1][0] + (p[2]*egm96_data[2][0]) + (p[3] * (egm96_data[3][0]*cosml[1] + egm96_data[3][1]*sinml[1]));
|
||||
|
||||
// Add haco = ac/100 to convert height anomaly on the ellipsoid to the undulation
|
||||
// Add -0.53m to make undulation refer to the WGS84 ellipsoid
|
||||
|
||||
return ((a * GM) / (gr * re)) + (ac / 100.0) - 0.53;
|
||||
}
|
||||
|
||||
void dscml(double rlon, double sinml[_361+1], double cosml[_361+1])
|
||||
{
|
||||
double a = sin(rlon);
|
||||
double b = cos(rlon);
|
||||
|
||||
sinml[1] = a;
|
||||
cosml[1] = b;
|
||||
sinml[2] = 2*b*a;
|
||||
cosml[2] = 2*b*b - 1;
|
||||
|
||||
for (unsigned m = 3; m <= _nmax; m++)
|
||||
{
|
||||
sinml[m] = 2*b*sinml[m-1] - sinml[m-2];
|
||||
cosml[m] = 2*b*cosml[m-1] - cosml[m-2];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \param m: order.
|
||||
* \param theta: Colatitude (radians).
|
||||
* \param rleg: Normalized legendre function.
|
||||
*
|
||||
* This subroutine computes all normalized legendre function in 'rleg'.
|
||||
* The dimensions of array 'rleg' must be at least equal to nmax+1.
|
||||
* All calculations are in double precision.
|
||||
*
|
||||
* Original programmer: Oscar L. Colombo, Dept. of Geodetic Science the Ohio State University, August 1980.
|
||||
* ineiev: I removed the derivatives, for they are never computed here.
|
||||
*/
|
||||
void legfdn(unsigned m, double theta, double rleg[_361+1])
|
||||
{
|
||||
static double drts[1301], dirt[1301], cothet, sithet, rlnn[_361+1];
|
||||
static int ir; // TODO 'ir' must be set to zero before the first call to this sub.
|
||||
|
||||
unsigned nmax1 = _nmax + 1;
|
||||
unsigned nmax2p = (2 * _nmax) + 1;
|
||||
unsigned m1 = m + 1;
|
||||
unsigned m2 = m + 2;
|
||||
unsigned m3 = m + 3;
|
||||
unsigned n, n1, n2;
|
||||
|
||||
if (!ir)
|
||||
{
|
||||
ir = 1;
|
||||
for (n = 1; n <= nmax2p; n++)
|
||||
{
|
||||
drts[n] = sqrt(n);
|
||||
dirt[n] = 1 / drts[n];
|
||||
}
|
||||
}
|
||||
|
||||
cothet = cos(theta);
|
||||
sithet = sin(theta);
|
||||
|
||||
// compute the legendre functions
|
||||
rlnn[1] = 1;
|
||||
rlnn[2] = sithet * drts[3];
|
||||
for (n1 = 3; n1 <= m1; n1++)
|
||||
{
|
||||
n = n1 - 1;
|
||||
n2 = 2 * n;
|
||||
rlnn[n1] = drts[n2 + 1] * dirt[n2] * sithet * rlnn[n];
|
||||
}
|
||||
|
||||
switch (m)
|
||||
{
|
||||
case 1:
|
||||
rleg[2] = rlnn[2];
|
||||
rleg[3] = drts[5] * cothet * rleg[2];
|
||||
break;
|
||||
case 0:
|
||||
rleg[1] = 1;
|
||||
rleg[2] = cothet * drts[3];
|
||||
break;
|
||||
}
|
||||
rleg[m1] = rlnn[m1];
|
||||
|
||||
if (m2 <= nmax1)
|
||||
{
|
||||
rleg[m2] = drts[m1*2 + 1] * cothet * rleg[m1];
|
||||
if (m3 <= nmax1)
|
||||
{
|
||||
for (n1 = m3; n1 <= nmax1; n1++)
|
||||
{
|
||||
n = n1 - 1;
|
||||
if ((!m && n < 2) || (m == 1 && n < 3)) continue;
|
||||
n2 = 2 * n;
|
||||
rleg[n1] = drts[n2+1] * dirt[n+m] * dirt[n-m] * (drts[n2-1] * cothet * rleg[n1-1] - drts[n+m-1] * drts[n-m-1] * dirt[n2-3] * rleg[n1-2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \param lat: Latitude in radians.
|
||||
* \param lon: Longitude in radians.
|
||||
* \param re: Geocentric radius.
|
||||
* \param rlat: Geocentric latitude.
|
||||
* \param gr: Normal gravity (m/sec²).
|
||||
*
|
||||
* This subroutine computes geocentric distance to the point, the geocentric
|
||||
* latitude, and an approximate value of normal gravity at the point based the
|
||||
* constants of the WGS84(g873) system are used.
|
||||
*/
|
||||
void radgra(double lat, double lon, double *rlat, double *gr, double *re)
|
||||
{
|
||||
const double a = 6378137.0;
|
||||
const double e2 = 0.00669437999013;
|
||||
const double geqt = 9.7803253359;
|
||||
const double k = 0.00193185265246;
|
||||
double t1 = sin(lat) * sin(lat);
|
||||
double n = a / sqrt(1.0 - (e2 * t1));
|
||||
double t2 = n * cos(lat);
|
||||
double x = t2 * cos(lon);
|
||||
double y = t2 * sin(lon);
|
||||
double z = (n * (1 - e2)) * sin(lat);
|
||||
|
||||
*re = sqrt((x * x) + (y * y) + (z * z)); // compute the geocentric radius
|
||||
*rlat = atan(z / sqrt((x * x) + (y * y))); // compute the geocentric latitude
|
||||
*gr = geqt * (1 + (k * t1)) / sqrt(1 - (e2 * t1)); // compute normal gravity (m/sec²)
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compute the geoid undulation from the EGM96 potential coefficient model, for a given latitude and longitude.
|
||||
* \param lat: Latitude in radians.
|
||||
* \param lon: Longitude in radians.
|
||||
* \return The geoid undulation / altitude offset (in meters).
|
||||
*/
|
||||
double undulation(double lat, double lon)
|
||||
{
|
||||
double p[_coeffs+1], sinml[_361+1], cosml[_361+1], rleg[_361+1];
|
||||
|
||||
double rlat, gr, re;
|
||||
unsigned nmax1 = _nmax + 1;
|
||||
|
||||
// compute the geocentric latitude, geocentric radius, normal gravity
|
||||
radgra(lat, lon, &rlat, &gr, &re);
|
||||
rlat = (M_PI / 2) - rlat;
|
||||
|
||||
for (unsigned j = 1; j <= nmax1; j++)
|
||||
{
|
||||
unsigned m = j - 1;
|
||||
legfdn(m, rlat, rleg);
|
||||
for (unsigned i = j ; i <= nmax1; i++)
|
||||
{
|
||||
p[(((i - 1) * i) / 2) + m + 1] = rleg[i];
|
||||
}
|
||||
}
|
||||
dscml(lon, sinml, cosml);
|
||||
|
||||
return hundu(p, sinml, cosml, gr, re);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
double egm96_compute_altitude_offset(double lat, double lon)
|
||||
{
|
||||
const double rad = (180.0 / M_PI);
|
||||
return undulation(lat/rad, lon/rad);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
39
Source/EGM96/EGM96.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006 D.Ineiev <ineiev@yahoo.co.uk>
|
||||
* Copyright (c) 2020 Emeric Grange <emeric.grange@gmail.com>
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef EGM96_H
|
||||
#define EGM96_H
|
||||
/* ************************************************************************** */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*!
|
||||
* \brief Compute the geoid undulation from the EGM96 potential coefficient model, for a given latitude and longitude.
|
||||
* \param latitude: Latitude (in degrees).
|
||||
* \param longitude: Longitude (in degrees).
|
||||
* \return The geoid undulation / altitude offset (in meters).
|
||||
*/
|
||||
double egm96_compute_altitude_offset(double latitude, double longitude);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* ************************************************************************** */
|
||||
#endif // EGM96_H
|
||||
65372
Source/EGM96/EGM96_data.h
Normal file
287
Source/IrisSensor_Gas_P0.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
#include "pch.h"
|
||||
#include "IrisSensor_Gas_P0.h"
|
||||
|
||||
IrisSensor_Gas_P0::IrisSensor_Gas_P0()
|
||||
{
|
||||
m_pSerialPort = new QSerialPort;
|
||||
m_iBaudRate = 115200;
|
||||
}
|
||||
|
||||
IrisSensor_Gas_P0::~IrisSensor_Gas_P0()
|
||||
{
|
||||
delete m_pSerialPort;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::SendData_Chk(std::string sSend)
|
||||
{
|
||||
QByteArray qbaSend(sSend.c_str(), (int)sSend.length());
|
||||
qint64 qi64Write = m_pSerialPort->write(qbaSend);
|
||||
m_pSerialPort->waitForBytesWritten(200);
|
||||
if (qi64Write != qbaSend.size())
|
||||
{
|
||||
qDebug() << "Err:Sensor_Gas write Failed.Exit Code:1" << qi64Write;
|
||||
return qi64Write;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::RecvData_Chk(/*std::string sRecv*/)
|
||||
{
|
||||
QByteArray qbData;
|
||||
qbData.clear();
|
||||
qbData = m_pSerialPort->readAll();
|
||||
|
||||
int iCounter = 0;
|
||||
while (qbData.size() < 3)
|
||||
{
|
||||
m_pSerialPort->waitForReadyRead(100);
|
||||
QByteArray qbTemp = m_pSerialPort->readAll();
|
||||
qbData.append(qbTemp);
|
||||
|
||||
if (iCounter > 3)
|
||||
{
|
||||
qDebug() << "Err:Sensor_Gas RecvData Failed,Not Enough Data.Exit Code:1" << qbData.size();
|
||||
return 1;
|
||||
}
|
||||
iCounter++;
|
||||
}
|
||||
|
||||
iCounter = 0;
|
||||
if (qbData[0]==(char)0x06)
|
||||
{
|
||||
int iLength = qbData[2] + 3 + 1;
|
||||
while (qbData.size()< iLength)
|
||||
{
|
||||
m_pSerialPort->waitForReadyRead(100);
|
||||
qbData.append(m_pSerialPort->readAll());
|
||||
iCounter++;
|
||||
if (iCounter > 3)
|
||||
{
|
||||
qDebug() << "Err:Sensor_Gas RecvData Failed,Incomplete Data.Exit Code:2" << qbData.size();
|
||||
return 3;
|
||||
}
|
||||
//return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Err:Sensor_Gas RecvData wrong header.Exit Code:2" << qbData.size();
|
||||
}
|
||||
|
||||
m_sRecv.clear();
|
||||
m_sRecv.resize(qbData.size());
|
||||
|
||||
for (int i=0;i< qbData.size();i++)
|
||||
{
|
||||
m_sRecv[i] = (unsigned char)qbData[i];
|
||||
}
|
||||
|
||||
//QString qstrTest = m_sRecv.c_str();
|
||||
//QString qstrTemp;
|
||||
// qstrTemp.resize((int)m_sRecv.size());
|
||||
// for (int i = 0; i < m_sRecv.size(); i++)
|
||||
// {
|
||||
// qstrTemp[i] = m_sRecv[i];
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::ParseMeasuredData_Chk()
|
||||
{
|
||||
if (m_sRecv.size()!=0x1f+4)
|
||||
{
|
||||
qDebug() << "Err:Sensor_Gas ParseData Failed,Incorrect Data Length.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char uc12, uc13, uc14, uc15, uc16,uc17,uc18,uc19,uc28,uc29,uc30,uc31,uc32, uc33;
|
||||
|
||||
uc32 = m_sRecv[32];
|
||||
uc33 = m_sRecv[33];
|
||||
m_fTPTemperature = (uc32 * 256 + uc33) / 100;
|
||||
|
||||
uc30 = m_sRecv[30];
|
||||
uc31 = m_sRecv[31];
|
||||
m_fPB = (uc30 * 256 + uc31) / 10;
|
||||
|
||||
uc28 = m_sRecv[28];
|
||||
uc29 = m_sRecv[29];
|
||||
m_fPB = (uc28 * 256 + uc29) / 10;
|
||||
|
||||
uc16 = m_sRecv[16];
|
||||
uc17 = m_sRecv[17];
|
||||
uc18 = m_sRecv[18];
|
||||
uc19 = m_sRecv[19];
|
||||
m_ulCO2 = uc16*256*256*256 + uc17*256*256 + uc18*256 + uc19;
|
||||
|
||||
uc12 = m_sRecv[12];
|
||||
uc13 = m_sRecv[13];
|
||||
uc14 = m_sRecv[14];
|
||||
uc15 = m_sRecv[15];
|
||||
m_ulH2O = uc12 * 256 * 256 * 256 + uc13 * 256 * 256 + uc14 * 256 + uc15;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::Initialize(std::string ucPortNumber)
|
||||
{
|
||||
QString qstrPortName = QString::fromStdString(ucPortNumber);
|
||||
|
||||
m_pSerialPort->setPortName(qstrPortName);
|
||||
m_pSerialPort->setReadBufferSize(512);
|
||||
|
||||
bool bRes = m_pSerialPort->setBaudRate(m_iBaudRate);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "Err:setBaudRate Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bRes = m_pSerialPort->open(QIODevice::ReadWrite);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "Err:open Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::GetVersion()
|
||||
{
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x01);
|
||||
qbSend.append(0x09);
|
||||
qbSend.append((unsigned char)0xf4);
|
||||
|
||||
SendData_Chk(qbSend.toStdString());
|
||||
|
||||
return 0;
|
||||
}// 02 01 09 F4
|
||||
|
||||
int IrisSensor_Gas_P0::GetMeasuredData(unsigned long &ulCO2, unsigned long &ulH2O, float &fTPTemperature, float &fPP, float &fPB)
|
||||
{
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x04);
|
||||
qbSend.append(0x01);
|
||||
qbSend.append(0x01);
|
||||
qbSend.append(0x05);
|
||||
qbSend.append((const char) 0x00);
|
||||
qbSend.append((unsigned char)0xf3); //chksum
|
||||
|
||||
SendData_Chk(qbSend.toStdString());
|
||||
|
||||
RecvData_Chk();
|
||||
|
||||
ParseMeasuredData_Chk();
|
||||
|
||||
ulCO2 = m_ulCO2;
|
||||
ulH2O = m_ulH2O;
|
||||
fTPTemperature = m_fTPTemperature;
|
||||
fPP = m_fPP;
|
||||
fPB = m_fPB;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::ZeroCalibration_N2()
|
||||
{
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x02);
|
||||
qbSend.append((const char) 0x00);
|
||||
qbSend.append((unsigned char)0xfa); //chksum
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::ZeroCalibration_Air()
|
||||
{
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x02);
|
||||
qbSend.append((const char) 0x01);
|
||||
qbSend.append((unsigned char)0xf9); //chksum
|
||||
|
||||
SendData_Chk(qbSend.toStdString());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::SpanCalibration(char cChannel,unsigned int uiPPM)
|
||||
{
|
||||
unsigned char ucChksum=0x0;
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x06);
|
||||
qbSend.append(0x03);
|
||||
qbSend.append(cChannel);
|
||||
|
||||
unsigned char *pResult = new unsigned char[4];
|
||||
pResult[0] = (unsigned char)((uiPPM >> 24) & 0xFF);
|
||||
pResult[1] = (unsigned char)((uiPPM >> 16) & 0xFF);
|
||||
pResult[2] = (unsigned char)((uiPPM >> 8) & 0xFF);
|
||||
pResult[3] = (unsigned char)(uiPPM & 0xFF);
|
||||
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
qbSend.append(pResult[i]);
|
||||
}
|
||||
|
||||
for (int i=0;i<qbSend.size();i++)
|
||||
{
|
||||
ucChksum += qbSend[i];
|
||||
}
|
||||
ucChksum = ~ucChksum + 1;
|
||||
|
||||
qbSend.append(ucChksum); //chksum
|
||||
|
||||
delete[] pResult;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::ResetCalibration(char cChannel)
|
||||
{
|
||||
unsigned char ucChksum = 0x0;
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x04);
|
||||
qbSend.append(cChannel);
|
||||
|
||||
for (int i = 0; i < qbSend.size(); i++)
|
||||
{
|
||||
ucChksum += qbSend[i];
|
||||
}
|
||||
ucChksum = ~ucChksum + 1;
|
||||
|
||||
qbSend.append(ucChksum);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_Gas_P0::StopAutoSending()
|
||||
{
|
||||
QByteArray qbSend;
|
||||
qbSend.append(0x02);
|
||||
qbSend.append(0x04);
|
||||
qbSend.append(0x01);
|
||||
qbSend.append((const char)0x00);
|
||||
qbSend.append(0x05);
|
||||
qbSend.append((const char)0x00);
|
||||
qbSend.append((unsigned char)0xf4); //chksum
|
||||
|
||||
int iRes = SendData_Chk(qbSend.toStdString());
|
||||
return 0;
|
||||
}
|
||||
35
Source/IrisSensor_Gas_P0.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
class IrisSensor_Gas_P0
|
||||
{
|
||||
public:
|
||||
IrisSensor_Gas_P0();
|
||||
~IrisSensor_Gas_P0();
|
||||
|
||||
private:
|
||||
int m_iBaudRate;
|
||||
QSerialPort *m_pSerialPort;
|
||||
std::string m_sRecv;
|
||||
|
||||
float m_fTPTemperature;
|
||||
float m_fPP, m_fPB;
|
||||
unsigned long m_ulCO2, m_ulH2O;
|
||||
|
||||
unsigned int uiSoftwareVersion, uiHardwareVersion;
|
||||
public:
|
||||
|
||||
private:
|
||||
int SendData_Chk(std::string sSend);
|
||||
int RecvData_Chk(/*std::string sRecv*/);
|
||||
int ParseMeasuredData_Chk();
|
||||
public:
|
||||
int Initialize(std::string ucPortNumber);
|
||||
int GetVersion();
|
||||
int GetMeasuredData(unsigned long &ulCO2, unsigned long &ulH2O,float &fTPTemperature,float &fPP, float &fPB);
|
||||
int ZeroCalibration_N2();
|
||||
int ZeroCalibration_Air();
|
||||
int SpanCalibration(char cChannel, unsigned int uiPPM);
|
||||
int ResetCalibration(char cChannel);//FF means all channel
|
||||
int StopAutoSending();
|
||||
};
|
||||
|
||||
178
Source/IrisSensor_WDA_P0.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
#include "pch.h"
|
||||
#include "IrisSensor_WDA_P0.h"
|
||||
|
||||
IrisSensor_WDA_P0::IrisSensor_WDA_P0()
|
||||
{
|
||||
m_pSerialPort = new QSerialPort;
|
||||
m_iBaudRate = 9600;
|
||||
return;
|
||||
}
|
||||
|
||||
IrisSensor_WDA_P0::~IrisSensor_WDA_P0()
|
||||
{
|
||||
delete m_pSerialPort;
|
||||
return;
|
||||
}
|
||||
|
||||
int IrisSensor_WDA_P0::SendData_NChk(std::string sSend)
|
||||
{
|
||||
//std::string sSendLinux = sSend;
|
||||
//std::replace(sSendLinux.begin(), sSendLinux.end(), '\r', '\n');
|
||||
|
||||
QByteArray qbaSend(sSend.c_str(), (int)sSend.length());
|
||||
qint64 qi64Write = m_pSerialPort->write(qbaSend);
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
// int a1 = qbaSend[10];
|
||||
// int a2 = qbaSend[11];
|
||||
// qDebug() << qbaSend[0]<< qbaSend[1]<<qbaSend[2] << qbaSend[3] << qbaSend[4] << qbaSend[5] << qbaSend[6] << qbaSend[7] << qbaSend[8] << qbaSend[9] /*<< qbaSend[10] << (char)qbaSend[11] */;
|
||||
// qDebug() << a1 << a2;
|
||||
#endif
|
||||
m_pSerialPort->waitForBytesWritten(50);
|
||||
if (qi64Write != qbaSend.size())
|
||||
{
|
||||
qDebug() << "Err:Sensor_WDA write Failed.Exit Code:1" << qi64Write;
|
||||
return qi64Write;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_WDA_P0::RecvData_NChk(/*std::string sRecv*/)
|
||||
{
|
||||
QByteArray qbData;
|
||||
qbData.clear();
|
||||
qbData = m_pSerialPort->readAll();
|
||||
|
||||
int iCounter = 0;
|
||||
while (qbData.size()<8)
|
||||
{
|
||||
m_pSerialPort->waitForReadyRead(50);
|
||||
QByteArray qbTemp = m_pSerialPort->readAll();
|
||||
qbData.append(qbTemp);
|
||||
|
||||
if (iCounter > 3)
|
||||
{
|
||||
qDebug() << "Err:Sensor_WDA RecvData Failed,Not Enough Data.Exit Code:1" << qbData.size();
|
||||
return 1;
|
||||
}
|
||||
iCounter++;
|
||||
}
|
||||
|
||||
iCounter = 0;
|
||||
while ((char)(qbData[qbData.size()-2]) != 0x0D && (char)(qbData[qbData.size() - 2]) != 0x0A)
|
||||
{
|
||||
m_pSerialPort->waitForReadyRead(50);
|
||||
qbData.append(m_pSerialPort->readAll());
|
||||
iCounter++;
|
||||
if (iCounter > 3)
|
||||
{
|
||||
qDebug() << "Err:Sensor_WDA RecvData Failed,Incomplete Data.Exit Code:2" << qbData.size();
|
||||
return 3;
|
||||
}
|
||||
//return 0;
|
||||
}
|
||||
|
||||
//m_sRecv.clear();
|
||||
//m_sRecv.assign(qbData.constData());
|
||||
|
||||
m_sRecv.clear();
|
||||
m_sRecv.resize(qbData.size());
|
||||
for (int i = 0; i < qbData.size(); i++)
|
||||
{
|
||||
m_sRecv[i] = (unsigned char)qbData[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_WDA_P0::ParseData_NChk()
|
||||
{
|
||||
//QString qstrTemp(m_sRecv.c_str());
|
||||
///////////////////////
|
||||
QString qstrTemp;
|
||||
qstrTemp.resize((int)m_sRecv.size());
|
||||
for (int i=0;i< m_sRecv.size();i++)
|
||||
{
|
||||
qstrTemp[i] = m_sRecv[i];
|
||||
}
|
||||
///////////////////////
|
||||
/*int iPos = qstrTemp.indexOf("=");
|
||||
int iPos1 = qstrTemp.lastIndexOf(",");
|
||||
qstrTemp = qstrTemp.left(iPos1);
|
||||
qstrTemp = qstrTemp.mid(iPos+1);
|
||||
|
||||
QString qstrSpeed, qstrDirection;
|
||||
iPos = qstrTemp.indexOf(",");
|
||||
qstrSpeed = qstrTemp.left(iPos);
|
||||
qstrDirection = qstrTemp.mid(iPos+1);
|
||||
|
||||
m_fWindSpeed = qstrSpeed.toFloat();
|
||||
m_fWindDirection = qstrDirection.toFloat();*/
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int iEqualSignIndex = qstrTemp.indexOf('=');
|
||||
if (iEqualSignIndex != -1)
|
||||
{
|
||||
QString dataPart = qstrTemp.mid(iEqualSignIndex + 1);
|
||||
QStringList dataList = dataPart.split(',');
|
||||
|
||||
m_fWindSpeed = dataList[0].toFloat();
|
||||
m_fWindDirection = dataList[1].toInt();
|
||||
m_fWindTemp = dataList[5].toFloat();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
qDebug() << m_fWindSpeed;
|
||||
qDebug() << m_fWindDirection;
|
||||
qDebug() << m_fWindTemp;
|
||||
/*for (int i=0;i<dataList.size();i++)
|
||||
{
|
||||
qDebug() << dataList[i];
|
||||
}*/
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_WDA_P0::Initialize(std::string ucPortNumber)
|
||||
{
|
||||
QString qstrPortName = QString::fromStdString(ucPortNumber);
|
||||
|
||||
m_pSerialPort->setPortName(qstrPortName);
|
||||
m_pSerialPort->setReadBufferSize(512);
|
||||
|
||||
bool bRes = m_pSerialPort->setBaudRate(m_iBaudRate);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "Err:setBaudRate Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bRes = m_pSerialPort->open(QIODevice::ReadWrite);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "Err:open Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IrisSensor_WDA_P0::GetSA_NChk(float &fSpeed, float &fAngle,float& fTemp)
|
||||
{
|
||||
if (SendData_NChk("$01,WV?*//\r\n")!=0)
|
||||
{
|
||||
qDebug() << "Err:GetSA_NChk - SendData_NChk.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (RecvData_NChk() != 0)
|
||||
{
|
||||
qDebug() << "Err:RecvData_NChk - SendData_NChk.Exit Code:1";
|
||||
return 2;
|
||||
}
|
||||
|
||||
ParseData_NChk();
|
||||
|
||||
fSpeed = m_fWindSpeed;
|
||||
fAngle = m_fWindDirection;
|
||||
fTemp = m_fWindTemp;
|
||||
return 0;
|
||||
}
|
||||
27
Source/IrisSensor_WDA_P0.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
class IrisSensor_WDA_P0
|
||||
{
|
||||
public:
|
||||
IrisSensor_WDA_P0();
|
||||
~IrisSensor_WDA_P0();
|
||||
|
||||
private:
|
||||
int m_iBaudRate;
|
||||
QSerialPort *m_pSerialPort;
|
||||
|
||||
std::string m_sRecv;
|
||||
|
||||
float m_fWindSpeed,m_fWindDirection,m_fWindTemp;
|
||||
public:
|
||||
|
||||
private:
|
||||
int SendData_NChk(std::string sSend);
|
||||
int RecvData_NChk(/*std::string sRecv*/);
|
||||
int ParseData_NChk();
|
||||
public:
|
||||
int Initialize(std::string sPortNumber);
|
||||
int GetSA_NChk(float &fSpeed,float &fAngle,float& fTemp);
|
||||
|
||||
};
|
||||
|
||||
90
Source/Logger.h
Normal file
@ -0,0 +1,90 @@
|
||||
//
|
||||
// Created by xin on 2021/8/17.
|
||||
//edit by zz.
|
||||
//fixed code page problem;added a new initialize function; --20211101
|
||||
#pragma once
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
#include "qmutex.h"
|
||||
#include "QtMsgHandler"
|
||||
|
||||
namespace QT_LOG
|
||||
{
|
||||
static int m_LogLevel = 1;
|
||||
static QString m_LogFile = QString("%1.log").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmss"));
|
||||
QMutex m_LogMutex;
|
||||
|
||||
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
if (type < m_LogLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString log_info;
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
log_info = QString("%1:%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"),msg);
|
||||
break;
|
||||
|
||||
case QtWarningMsg:
|
||||
log_info = QString("%1[Warning]:%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"),msg);
|
||||
break;
|
||||
|
||||
case QtCriticalMsg:
|
||||
log_info = QString("%1[Critical]:%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"),msg);
|
||||
break;
|
||||
|
||||
case QtFatalMsg:
|
||||
log_info = QString("%1[Fatal]:%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"),msg);
|
||||
abort();
|
||||
}
|
||||
|
||||
m_LogMutex.lock();
|
||||
|
||||
QFile outFile(m_LogFile);
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
|
||||
QTextStream ts(&outFile);
|
||||
ts << log_info << endl;
|
||||
outFile.close();
|
||||
|
||||
m_LogMutex.unlock();
|
||||
}
|
||||
void logInit(QString logFile = "",int logLevel = 0)
|
||||
{
|
||||
|
||||
#ifndef DEBUG
|
||||
if ((logLevel < 0) || (logLevel > 3))
|
||||
{
|
||||
m_LogLevel = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LogLevel = logLevel;
|
||||
}
|
||||
|
||||
if (!logFile.isEmpty())
|
||||
{
|
||||
m_LogFile = logFile+"/"+m_LogFile;
|
||||
}
|
||||
|
||||
qInstallMessageHandler(customMessageHandler);
|
||||
//qInstallMsgHandler(customMessageHandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
//added by IRIS_ZZ initialize from main
|
||||
void ZZ_InitLogger(QString qstrDir)
|
||||
{
|
||||
QDir qdLogFolder;
|
||||
qdLogFolder.mkdir(qstrDir);
|
||||
qDebug() << QT_LOG::m_LogFile;
|
||||
QT_LOG::logInit(qstrDir);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
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
|
||||
838
Source/M300/PSDK_Qt/Main/VehicleController.cpp
Normal file
@ -0,0 +1,838 @@
|
||||
#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 <csignal>
|
||||
#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_fHeightOfHomePoint_BM = -1;
|
||||
//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_DjiFcSubscriptionAltitudeFused*)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 = { 0 };
|
||||
T_DjiHalUartHandler uartHandler = { 0 };
|
||||
T_DjiHalUsbBulkHandler usbBulkHandler = { 0 };
|
||||
T_DjiLoggerConsole printConsole;
|
||||
T_DjiLoggerConsole localRecordConsole;
|
||||
T_DjiFileSystemHandler fileSystemHandler = { 0 };
|
||||
T_DjiSocketHandler socketHandler{ 0 };
|
||||
T_DjiHalNetworkHandler networkHandler = { 0 };
|
||||
|
||||
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;
|
||||
osalHandler.GetRandomNum = Osal_GetRandomNum;
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VehicleController::StartupPSDK_M300RTK()
|
||||
{
|
||||
T_DjiUserInfo userInfo;
|
||||
T_DjiReturnCode returnCode;
|
||||
T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;
|
||||
T_DjiOsalHandler* osalHandler = DjiPlatform_GetOsalHandler();
|
||||
|
||||
//signal(SIGTERM, DjiUser_NormalExitHandler);
|
||||
|
||||
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();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><DFBC>л<EFBFBD>
|
||||
//osalHandler->TaskSleepMs(5000);
|
||||
SetupMessagePipe();//widget<65><74>vehicle
|
||||
SetupWaypointStatusCallback();
|
||||
InitSystemParams();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>ϵͳʱ<CDB3>䣬Ȼ<E4A3AC><C8BB>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>Ϊ<EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
SetupSubscriptions();//ʵ<><CAB5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ķ<EFBFBD><C4B6>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
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 };
|
||||
T_DjiFcSubscriptionAltitudeFused tDjiAltFused = { 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_BAROMETER, (uint8_t*)&tDjiAltFused, sizeof(T_DjiFcSubscriptionAltitudeFused), &tDjiTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic error.DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_BAROMETER";
|
||||
//return 4;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
M300RTKDataFrame.fAltitudeFused = tDjiAltFused;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////Calc Euler From Quaternion 20230428
|
||||
M300RTKDataFrame.stEulerAngle.pitch = (dji_f64_t)asinf(-2 * tDjiQuaternion.q1 * tDjiQuaternion.q3 + 2 * tDjiQuaternion.q0 * tDjiQuaternion.q2) * 57.3;
|
||||
|
||||
M300RTKDataFrame.stEulerAngle.roll = (dji_f64_t)atan2f(2 * tDjiQuaternion.q2 * tDjiQuaternion.q3 + 2 * tDjiQuaternion.q0 * tDjiQuaternion.q1,
|
||||
-2 * tDjiQuaternion.q1 * tDjiQuaternion.q1 - 2 * tDjiQuaternion.q2 * tDjiQuaternion.q2 + 1) * 57.3;
|
||||
|
||||
M300RTKDataFrame.stEulerAngle.yaw = (dji_f64_t)atan2f(2 * tDjiQuaternion.q1 * tDjiQuaternion.q2 + 2 * tDjiQuaternion.q0 * tDjiQuaternion.q3,
|
||||
-2 * tDjiQuaternion.q2 * tDjiQuaternion.q2 - 2 * tDjiQuaternion.q3 * tDjiQuaternion.q3 + 1) * 57.3;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#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_1_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::InitSystemParams()
|
||||
{
|
||||
T_DjiReturnCode tDjiReturnCode;
|
||||
QString qstrWBackPath("/home/data/Settings/MainSettings.ini");
|
||||
|
||||
|
||||
///Init
|
||||
tDjiReturnCode = DjiFcSubscription_Init();
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "init data subscription module error.";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "InitSystemDateTime started.";
|
||||
}
|
||||
|
||||
///SubscribeTopic GPS_SIGNAL_LEVEL
|
||||
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 -1;
|
||||
}
|
||||
|
||||
///SubscribeTopic GPS_DATE
|
||||
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 -2;
|
||||
}
|
||||
|
||||
///SubscribeTopic GPS_TIME
|
||||
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 -3;
|
||||
}
|
||||
|
||||
///SubscribeTopic ALTITUDE_OF_HOMEPOINT
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT error.";
|
||||
return -4;
|
||||
}
|
||||
|
||||
///SubscribeTopic DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION
|
||||
tDjiReturnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ, NULL);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "Subscribe topic DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION error.";
|
||||
return -5;
|
||||
}
|
||||
|
||||
///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>60)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
//osalHandler->TaskSleepMs(2000);
|
||||
|
||||
///Get GPS Datetime
|
||||
T_DjiFcSubscriptionGpsDate tGpsDate = { 0 };
|
||||
T_DjiFcSubscriptionGpsTime tGpsTime = { 0 };
|
||||
///Get Other
|
||||
T_DjiFcSubscriptionAltitudeOfHomePoint tAltOfHP = { 0 };
|
||||
T_DjiFcSubscriptionGpsPosition tDjiGpsPosition = { 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;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT, (uint8_t*)&tAltOfHP, sizeof(T_DjiFcSubscriptionAltitudeOfHomePoint), &tTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT.";
|
||||
return -3;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION, (uint8_t*)&tDjiGpsPosition, sizeof(T_DjiFcSubscriptionGpsPosition), &tTimestamp);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_GetLatestValueOfTopic error.DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY";
|
||||
return -4;
|
||||
}
|
||||
|
||||
m_fHeightOfHomePoint_BM = tAltOfHP;
|
||||
float fHeightOfHomePoint_GPS= tDjiGpsPosition.z;
|
||||
QString qstrHeightOfHomePoint_BM = QString("%1").arg(m_fHeightOfHomePoint_BM);
|
||||
QString qstrHeightOfHomePoint_GPS = QString("%1").arg(tDjiGpsPosition.z);
|
||||
//////////////////////////////////////////////////////////////////////////write back AOHP
|
||||
QSettings qsMainSettings(qstrWBackPath, QSettings::Format::IniFormat);
|
||||
qsMainSettings.setValue(QString("WBACK/HeightOfHomePoint_BM"), qstrHeightOfHomePoint_BM);
|
||||
qsMainSettings.setValue(QString("WBACK/HeightOfHomePoint_GPS"), qstrHeightOfHomePoint_GPS);
|
||||
qDebug() << qstrHeightOfHomePoint_BM << m_fHeightOfHomePoint_BM;
|
||||
qDebug() << qstrHeightOfHomePoint_GPS << tDjiGpsPosition.z;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//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_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;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_UnSubscribeTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT.";
|
||||
return -14;
|
||||
}
|
||||
|
||||
tDjiReturnCode = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION);
|
||||
if (tDjiReturnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
||||
{
|
||||
qDebug() << "DjiFcSubscription_UnSubscribeTopic module error,DJI_FC_SUBSCRIPTION_TOPIC_ALTITUDE_OF_HOMEPOINT.";
|
||||
return -15;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
93
Source/M300/PSDK_Qt/Main/VehicleController.h
Normal file
@ -0,0 +1,93 @@
|
||||
#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;
|
||||
|
||||
float m_fHeightOfHomePoint_BM;
|
||||
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 InitSystemParams();
|
||||
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 "enxf8e43b7bbc2c"
|
||||
#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******/
|
||||
263
Source/M300/PSDK_Qt/hal/hal_uart.c
Normal file
@ -0,0 +1,263 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#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****/
|
||||
70
Source/M300/PSDK_Qt/hal/hal_uart.h
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
//User can config dev based on there environmental conditions
|
||||
#define LINUX_UART_DEV1 "/dev/ttyUSB0"
|
||||
#define LINUX_UART_DEV2 "/dev/ttyACM0"
|
||||
|
||||
//global
|
||||
extern char gvpcM300RTK_UART1[128];
|
||||
extern char gvpcM300RTK_UART2[128];
|
||||
|
||||
|
||||
/* 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******/
|
||||
230
Source/M300/PSDK_Qt/hal/hal_usb_bulk.c
Normal file
@ -0,0 +1,230 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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) {
|
||||
USER_LOG_ERROR("init usb bulk failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
|
||||
if(handle == NULL) {
|
||||
USER_LOG_ERROR("open usb device failed");
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
|
||||
if (ret != LIBUSB_SUCCESS) {
|
||||
USER_LOG_ERROR("libusb claim interface failed, errno = %d", ret);
|
||||
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();
|
||||
int32_t ret;
|
||||
|
||||
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_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
|
||||
if(ret != 0) {
|
||||
USER_LOG_ERROR("release usb bulk interface failed, errno = %d", ret);
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
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****/
|
||||
92
Source/M300/PSDK_Qt/hal/hal_usb_bulk.h
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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******/
|
||||
347
Source/M300/PSDK_Qt/osal/osal.c
Normal file
@ -0,0 +1,347 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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;
|
||||
|
||||
if (!mutex) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*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 = 0;
|
||||
|
||||
if (!mutex) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
|
||||
if (!mutex) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
|
||||
if (!mutex) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
T_DjiReturnCode Osal_GetRandomNum(uint16_t *randomNum)
|
||||
{
|
||||
srand(time(NULL));
|
||||
*randomNum = random() % 65535;
|
||||
|
||||
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****/
|
||||
78
Source/M300/PSDK_Qt/osal/osal.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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);
|
||||
T_DjiReturnCode Osal_GetRandomNum(uint16_t *randomNum);
|
||||
|
||||
void *Osal_Malloc(uint32_t size);
|
||||
void Osal_Free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OSAL_H
|
||||
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
|
||||
288
Source/M300/PSDK_Qt/osal/osal_fs.c
Normal file
@ -0,0 +1,288 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 || fileObj == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*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******/
|
||||
299
Source/M300/PSDK_Qt/osal/osal_socket.c
Normal file
@ -0,0 +1,299 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @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 ---------------------------------------------------------*/
|
||||
#define SOCKET_RECV_BUF_MAX_SIZE (1000 * 1000 * 10)
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int socketFd;
|
||||
} T_SocketHandleStruct;
|
||||
|
||||
/* Private values -------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode Osal_Socket(E_DjiSocketMode mode, T_DjiSocketHandle *socketHandle)
|
||||
{
|
||||
T_SocketHandleStruct *socketHandleStruct;
|
||||
socklen_t optlen = sizeof(int);
|
||||
int rcvBufSize = SOCKET_RECV_BUF_MAX_SIZE;
|
||||
int opt = 1;
|
||||
|
||||
/*! set the socket default read buffer to 20MByte */
|
||||
system("echo 20000000 > /proc/sys/net/core/rmem_default");
|
||||
|
||||
/*! set the socket max read buffer to 50MByte */
|
||||
system("echo 50000000 > /proc/sys/net/core/rmem_max");
|
||||
|
||||
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);
|
||||
|
||||
if (setsockopt(socketHandleStruct->socketFd, SOL_SOCKET, SO_REUSEADDR, &opt, optlen) < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (setsockopt(socketHandleStruct->socketFd, SOL_SOCKET, SO_RCVBUF, &rcvBufSize, optlen) < 0)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
} else if (mode == DJI_SOCKET_MODE_TCP) {
|
||||
socketHandleStruct->socketFd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
} else {
|
||||
goto out;
|
||||
}
|
||||
|
||||
*socketHandle = socketHandleStruct;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
|
||||
out:
|
||||
close(socketHandleStruct->socketFd);
|
||||
free(socketHandleStruct);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
free(socketHandle);
|
||||
|
||||
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******/
|
||||
102
Source/M300/PSDK_Qt/util_misc.c
Normal file
@ -0,0 +1,102 @@
|
||||
/**
|
||||
********************************************************************
|
||||
* @file util_misc.c
|
||||
* @brief
|
||||
*
|
||||
* @copyright (c) 2021 DJI. All rights reserved.
|
||||
*
|
||||
* All information contained herein is, and remains, the property of DJI.
|
||||
* The intellectual and technical concepts contained herein are proprietary
|
||||
* to DJI and may be covered by U.S. and foreign patents, patents in process,
|
||||
* and protected by trade secret or copyright law. Dissemination of this
|
||||
* information, including but not limited to data and other proprietary
|
||||
* material(s) incorporated within the information, in any form, is strictly
|
||||
* prohibited without the express written consent of DJI.
|
||||
*
|
||||
* If you receive this source code without DJI’s authorization, you may not
|
||||
* further disseminate the information, and you must immediately remove the
|
||||
* source code and notify DJI of its removal. DJI reserves the right to pursue
|
||||
* legal actions against you for any loss(es) or damage(s) caused by your
|
||||
* failure to do so.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifdef SYSTEM_ARCH_LINUX
|
||||
|
||||
#include <stdio.h>
|
||||
#include "util_misc.h"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
const char *baseStr = "[>>>>>>>>>>>>>---------------------------------------------------------------------------------------] 13%";
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
|
||||
/* Private values ------------------------------------------------------------*/
|
||||
|
||||
/* Private functions declaration ---------------------------------------------*/
|
||||
|
||||
/* Exported functions definition ---------------------------------------------*/
|
||||
T_DjiReturnCode DjiUserUtil_GetCurrentFileDirPath(const char *filePath, uint32_t pathBufferSize, char *dirPath)
|
||||
{
|
||||
uint32_t i = strlen(filePath) - 1;
|
||||
uint32_t dirPathLen;
|
||||
|
||||
while (filePath[i] != '/') {
|
||||
i--;
|
||||
}
|
||||
|
||||
dirPathLen = i + 1;
|
||||
|
||||
if (dirPathLen + 1 > pathBufferSize) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
memcpy(dirPath, filePath, dirPathLen);
|
||||
dirPath[dirPathLen] = 0;
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
T_DjiReturnCode DjiUserUtil_RunSystemCmd(const char *systemCmdStr)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = popen(systemCmdStr, "r");
|
||||
if (fp == NULL) {
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
|
||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void DjiUserUtil_PrintProgressBar(uint16_t currentProgress, uint16_t totalProgress, char *userData)
|
||||
{
|
||||
for (int j = 0; j < strlen(baseStr) + strlen(userData) + 4; ++j) {
|
||||
printf("\b");
|
||||
}
|
||||
|
||||
printf("[");
|
||||
for (int j = 0; j < totalProgress; ++j) {
|
||||
if (j < currentProgress) {
|
||||
printf("%c", '>');
|
||||
} else {
|
||||
printf("-");
|
||||
}
|
||||
}
|
||||
|
||||
printf("] ");
|
||||
printf("%3d%%", currentProgress);
|
||||
printf("%s", userData);
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Private functions definition-----------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/
|
||||
58
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******/
|
||||
281
Source/MainAcqThread.cpp
Normal file
@ -0,0 +1,281 @@
|
||||
#include "MainAcqThread.h"
|
||||
#include "unistd.h"
|
||||
#include <cmath>
|
||||
#include "hal_uart.h"
|
||||
|
||||
CMainAcqThread::CMainAcqThread(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_iFlagCaptureStatus = 0;
|
||||
iFlagIsPathGenerated = false;
|
||||
|
||||
m_clsCapTimer.setTimerType(Qt::PreciseTimer);
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
//connect(&m_clsCapTimer, &QTimer::timeout, this, &CMainAcqThread::OnTestTimer);
|
||||
#endif
|
||||
|
||||
|
||||
//m_clsCapTimer.start()
|
||||
|
||||
}
|
||||
|
||||
CMainAcqThread::~CMainAcqThread()
|
||||
{
|
||||
}
|
||||
|
||||
int CMainAcqThread::SetupContext()
|
||||
{
|
||||
m_ctrlConfigParser.SetFilePath("/home/data/Settings/MainSettings.ini");
|
||||
m_ctrlConfigParser.GetParams(m_struMiscCtrls,m_struM300RTKSs,m_struSensorPort);
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << m_struSensorPort.qstrGasSensorPort;
|
||||
qDebug() << m_struSensorPort.qstrWindSensorPort;
|
||||
qDebug() << m_struMiscCtrls.iPumpGPIOPort;
|
||||
qDebug() << m_struM300RTKSs.qstrM300RTKSettingsFilePath;
|
||||
qDebug() << m_struM300RTKSs.qstrM300RTKWidgetFilePath;
|
||||
#endif
|
||||
|
||||
m_ctrlVehicle.SetupEnvironment_M300RTK();
|
||||
SetupMessagePipe();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::StartUp()
|
||||
{
|
||||
///pump control
|
||||
system("sudo gpio mode 7 out");
|
||||
|
||||
m_ctrlVehicle.StartupPSDK_M300RTK();
|
||||
|
||||
QString qstrMessage = "Initializing sensors,Please wait...";
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
|
||||
int iRes = m_ctrlGasSensor.Initialize(m_struSensorPort.qstrGasSensorPort.toStdString());
|
||||
if (iRes!=0)
|
||||
{
|
||||
qstrMessage.clear();
|
||||
qstrMessage.append("Fatal Error!!! Gas sensor not connected.Please check.");
|
||||
//qstrMessage = "Fatal Error!!! Gas sensor not connected.Please check.";
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
qDebug() << qstrMessage;
|
||||
//return 1;
|
||||
}
|
||||
|
||||
iRes = m_ctrlWindSensor.Initialize(m_struSensorPort.qstrWindSensorPort.toStdString());
|
||||
if (iRes != 0)
|
||||
{
|
||||
qstrMessage.append("Fatal Error!!! Wind sensor not connected.Please check.");
|
||||
//qstrMessage = "Fatal Error!!! Wind sensor not connected.Please check.";
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
qDebug() << qstrMessage;
|
||||
//return 2;
|
||||
}
|
||||
|
||||
qstrMessage.append("System ready.Waiting for signals");
|
||||
//qstrMessage = "System ready.Waiting for signals";
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::SetupMessagePipe()
|
||||
{
|
||||
connect(&m_ctrlVehicle, &VehicleController::Signal_StartCapture, this, &CMainAcqThread::Slot_StartCapture);
|
||||
connect(&m_ctrlVehicle, &VehicleController::Signal_StopCapture, this, &CMainAcqThread::Slot_StopCapture);
|
||||
|
||||
connect(this, &CMainAcqThread::Signal_UpdateVehicleMessage, &m_ctrlVehicle, &VehicleController::Signal_UpdateVehicleMessage);
|
||||
|
||||
connect(&m_clsCapTimer, &QTimer::timeout, this, &CMainAcqThread::OnTimerCapture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CMainAcqThread::WindSensorCorrection()
|
||||
{
|
||||
QuaternionToRotationMatrix();
|
||||
ConvertWindData();
|
||||
RotateWindVec();
|
||||
FormFixedWindData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::QuaternionToRotationMatrix()
|
||||
{
|
||||
m_dRotationMatrix[0] = 1.0 - 2.0 * (m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.y_q2 + m_struM300RTKDataFrame.stQuaternion.z_q3 * m_struM300RTKDataFrame.stQuaternion.z_q3);
|
||||
m_dRotationMatrix[1] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.y_q2 - m_struM300RTKDataFrame.stQuaternion.z_q3 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[2] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.z_q3 + m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[3] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.y_q2 + m_struM300RTKDataFrame.stQuaternion.z_q3 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[4] = 1.0 - 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.x_q1 + m_struM300RTKDataFrame.stQuaternion.z_q3 * m_struM300RTKDataFrame.stQuaternion.z_q3);
|
||||
m_dRotationMatrix[5] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.z_q3 - m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[6] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.z_q3 - m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[7] = 2.0 * (m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.z_q3 + m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.w_q0);
|
||||
m_dRotationMatrix[8] = 1.0 - 2.0 * (m_struM300RTKDataFrame.stQuaternion.x_q1 * m_struM300RTKDataFrame.stQuaternion.x_q1 + m_struM300RTKDataFrame.stQuaternion.y_q2 * m_struM300RTKDataFrame.stQuaternion.y_q2);
|
||||
// R[0] = r11; R[1] = r12; R[2] = r13;
|
||||
// R[3] = r21; R[4] = r22; R[5] = r23;
|
||||
// R[6] = r31; R[7] = r32; R[8] = r33;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::ConvertWindData()
|
||||
{
|
||||
m_fTempWindVecX = m_struUASDataFrame.fWindSpeed * cos(m_struUASDataFrame.fWindDirection / 180 * 3.14159);
|
||||
m_fTempWindVecY = m_struUASDataFrame.fWindSpeed * sin(m_struUASDataFrame.fWindDirection / 180 * 3.14159);
|
||||
m_fTempWindVecZ = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::RotateWindVec()
|
||||
{
|
||||
m_fTempFixedWindVecX = m_dRotationMatrix[0] * m_fTempWindVecX + m_dRotationMatrix[1] * m_fTempWindVecY /*+ m_dRotationMatrix[2] * m_fTempWindVecZ*/;
|
||||
m_fTempFixedWindVecY = m_dRotationMatrix[3] * m_fTempWindVecX + m_dRotationMatrix[4] * m_fTempWindVecY /*+ m_dRotationMatrix[5] * m_fTempWindVecZ*/;
|
||||
m_fTempFixedWindVecZ = m_dRotationMatrix[6] * m_fTempWindVecX + m_dRotationMatrix[7] * m_fTempWindVecY /*+ m_dRotationMatrix[8] * m_fTempWindVecZ*/;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CMainAcqThread::FormFixedWindData()
|
||||
{
|
||||
m_fTempFixedWindVecX = m_fTempFixedWindVecX-m_struM300RTKDataFrame.stVelocity.x;
|
||||
m_fTempFixedWindVecY = m_fTempFixedWindVecY - m_struM300RTKDataFrame.stVelocity.y;
|
||||
m_fTempFixedWindVecZ = m_fTempFixedWindVecZ - m_struM300RTKDataFrame.stVelocity.z;
|
||||
|
||||
double dDotProduct = m_fTempFixedWindVecX; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double dVectorLength = sqrt(m_fTempFixedWindVecX * m_fTempFixedWindVecX + m_fTempFixedWindVecY * m_fTempFixedWindVecY + m_fTempFixedWindVecZ * m_fTempFixedWindVecZ); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
double dAngleInRadians = acos(dDotProduct / dVectorLength); // <20><><EFBFBD><EFBFBD><EFBFBD>нǵĻ<C7B5><C4BB><EFBFBD>ֵ
|
||||
double angleInDegrees = dAngleInRadians * (180.0 / M_PI); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
|
||||
m_struUASDataFrame.fFixedWindDirection = angleInDegrees;
|
||||
m_struUASDataFrame.fFixedWindSpeed = dVectorLength;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMainAcqThread::OnTestTimer()
|
||||
{
|
||||
qDebug() << "entering time:"<< QTime::currentTime();
|
||||
QTime currentTime;
|
||||
int elapsed = 0;
|
||||
if (lastTime == QTime())
|
||||
{
|
||||
lastTime = QTime::currentTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTime = QTime::currentTime();
|
||||
elapsed = lastTime.msecsTo(currentTime);
|
||||
lastTime = QTime:: currentTime();
|
||||
}
|
||||
|
||||
qDebug() << "Run.elapsed =" << elapsed << "ms";
|
||||
|
||||
for (int i=0;i< 99999999;i++)
|
||||
{
|
||||
int b = i + 1;
|
||||
if (b%2==0)
|
||||
{
|
||||
b = b + 2;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "leave time:" << QTime::currentTime();
|
||||
}
|
||||
|
||||
int CMainAcqThread::GetData()
|
||||
{
|
||||
unsigned long ulCO2=0, ulH2O=0;
|
||||
float fGasTemp=-1,fPP=-1,fPB=-1;
|
||||
m_ctrlGasSensor.GetMeasuredData(ulCO2, ulH2O, fGasTemp, fPP, fPB);
|
||||
m_struGSDataFrame.ulCO2 = ulCO2;
|
||||
m_struGSDataFrame.ulH2O = ulH2O;
|
||||
m_struGSDataFrame.fTemp = fGasTemp;
|
||||
m_struGSDataFrame.fPP = fPP;
|
||||
m_struGSDataFrame.fPB = fPB;
|
||||
|
||||
float fSpeed=-1, fAngle=-1,fWindTemp=-1;
|
||||
m_ctrlWindSensor.GetSA_NChk(fSpeed,fAngle, fWindTemp);
|
||||
m_struUASDataFrame.fWindDirection = fAngle;
|
||||
m_struUASDataFrame.fWindSpeed = fSpeed;
|
||||
m_struUASDataFrame.fWindTemperature = fWindTemp;
|
||||
|
||||
m_ctrlVehicle.GetOneDataFrame(m_struM300RTKDataFrame);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
int CMainAcqThread::OnTimerCapture()
|
||||
{
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "OnTimerCapture entering time:" << QTime::currentTime();
|
||||
#endif
|
||||
|
||||
//m_ctrlGasSensor.GetMeasuredData();
|
||||
//m_ctrlWindSensor.GetSA_NChk();
|
||||
//m_ctrlVehicle.GetOneDataFrame(m_struM300RTKDataFrame);
|
||||
GetData();
|
||||
WindSensorCorrection();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////update message to controller
|
||||
//m_struGSDataFrame.ulH2O = 223;
|
||||
//m_struGSDataFrame.ulCO2 = 530;
|
||||
QString qstrMessage;
|
||||
qstrMessage = QString("CO2: %1ppm, H20: %2ppm\r\nFixed Wind Speed: %3m/s\r\nFixed Wind Direction: %4deg").arg(m_struGSDataFrame.ulCO2).arg(m_struGSDataFrame.ulH2O)
|
||||
.arg(m_struUASDataFrame.fFixedWindSpeed).arg(m_struUASDataFrame.fFixedWindDirection);
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << m_struM300RTKDataFrame.stGPSPosition.x << m_struM300RTKDataFrame.stGPSPosition.y << m_struM300RTKDataFrame.stGPSPosition.z
|
||||
<< m_struM300RTKDataFrame.stVelocity.x << m_struM300RTKDataFrame.stVelocity.y << m_struM300RTKDataFrame.stVelocity.z;
|
||||
#endif
|
||||
|
||||
m_ctrlData.WriteData(m_struM300RTKDataFrame, m_struGSDataFrame, m_struUASDataFrame);
|
||||
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "OnTimerCapture leave time:" << QTime::currentTime();
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::Slot_StartCapture()
|
||||
{
|
||||
// ground test
|
||||
system("sudo gpio write 7 1");
|
||||
|
||||
iFlagIsPathGenerated = true;
|
||||
|
||||
m_ctrlVehicle.UpdateUIConfig();
|
||||
|
||||
m_ctrlData.GenerateFilePath();
|
||||
|
||||
m_ctrlData.GenerateFile();
|
||||
|
||||
m_clsCapTimer.start(1000);
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "CMainAcqThread Test Cap Started";
|
||||
#endif // ZZ_FLAG_TEST
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainAcqThread::Slot_StopCapture()
|
||||
{
|
||||
// ground test
|
||||
system("sudo gpio write 7 0");
|
||||
|
||||
iFlagIsPathGenerated = false;
|
||||
|
||||
m_clsCapTimer.stop();
|
||||
|
||||
m_ctrlData.CloseData();
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "CMainAcqThread Test Cap Stopped";
|
||||
#endif // ZZ_FLAG_TEST
|
||||
|
||||
QString qstrMessage = QString("Capture Stopped.");
|
||||
emit Signal_UpdateVehicleMessage(qstrMessage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
74
Source/MainAcqThread.h
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <atomic>
|
||||
#include "dji_typedef.h"
|
||||
#include "dji_core.h"
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "VehicleController.h"
|
||||
#include "IrisSensor_WDA_P0.h"
|
||||
#include "IrisSensor_Gas_P0.h"
|
||||
#include "DataFileManager.h"
|
||||
#include "MainConfigParser.h"
|
||||
|
||||
using namespace ZZ_DATA_DEF::M300RTK;
|
||||
using namespace ZZ_DATA_DEF::CO2_GAS_SENSOR;
|
||||
using namespace ZZ_DATA_DEF::UA_SENSOR;
|
||||
using namespace ZZ_DATA_DEF::MainConfig;
|
||||
|
||||
class CMainAcqThread :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CMainAcqThread(QObject* parent = nullptr);
|
||||
~CMainAcqThread();
|
||||
|
||||
private:
|
||||
QTime lastTime;
|
||||
QTimer m_clsCapTimer;
|
||||
|
||||
int iFlagIsPathGenerated;
|
||||
|
||||
MiscControls m_struMiscCtrls;
|
||||
M300RTKSettings m_struM300RTKSs;
|
||||
SensorPort m_struSensorPort;
|
||||
|
||||
M300RTKDataFrame m_struM300RTKDataFrame;
|
||||
GSDataFrame m_struGSDataFrame;
|
||||
UASDataFrame m_struUASDataFrame;
|
||||
|
||||
double m_dRotationMatrix[9];
|
||||
float m_fTempWindVecX, m_fTempWindVecY, m_fTempWindVecZ;
|
||||
float m_fTempFixedWindVecX, m_fTempFixedWindVecY, m_fTempFixedWindVecZ;
|
||||
public:
|
||||
atomic<int> m_iFlagCaptureStatus;
|
||||
private:
|
||||
MainConfigParser m_ctrlConfigParser;
|
||||
|
||||
VehicleController m_ctrlVehicle;
|
||||
|
||||
DataFileManager m_ctrlData;
|
||||
|
||||
IrisSensor_Gas_P0 m_ctrlGasSensor;
|
||||
IrisSensor_WDA_P0 m_ctrlWindSensor;
|
||||
public:
|
||||
int SetupContext();
|
||||
int StartUp();
|
||||
private:
|
||||
int SetupMessagePipe();
|
||||
int GetData();
|
||||
int WindSensorCorrection();
|
||||
int QuaternionToRotationMatrix();
|
||||
int ConvertWindData();
|
||||
int RotateWindVec();
|
||||
int FormFixedWindData();
|
||||
signals:
|
||||
void Signal_UpdateVehicleMessage(QString qstrMessage);
|
||||
public slots:
|
||||
void OnTestTimer();
|
||||
int OnTimerCapture();
|
||||
int Slot_StartCapture();
|
||||
int Slot_StopCapture();
|
||||
};
|
||||
121
Source/MainSettings/MainConfigParser.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include "MainConfigParser.h"
|
||||
|
||||
MainConfigParser::MainConfigParser(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_bIsInit = false;
|
||||
}
|
||||
|
||||
MainConfigParser::~MainConfigParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int MainConfigParser::SetFilePath(QString qstrFullFilePath)
|
||||
{
|
||||
m_qstrFullFilePath = qstrFullFilePath;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainConfigParser::GetParams(MiscControls& struMiscCtrls, M300RTKSettings& struM300RTKSs, SensorPort& struSensorPort)
|
||||
{
|
||||
if (!m_bIsInit)
|
||||
{
|
||||
Initialize(m_qstrFullFilePath);
|
||||
}
|
||||
|
||||
struSensorPort.qstrGasSensorPort = m_struSensorPort.qstrGasSensorPort;
|
||||
struSensorPort.qstrWindSensorPort = m_struSensorPort.qstrWindSensorPort;
|
||||
|
||||
struMiscCtrls.iPumpGPIOPort = m_struMiscCtrls.iPumpGPIOPort;
|
||||
|
||||
struM300RTKSs.qstrM300RTKUDEV1 = m_struM300RTKSs.qstrM300RTKUDEV1;
|
||||
struM300RTKSs.qstrM300RTKUDEV2 = m_struM300RTKSs.qstrM300RTKUDEV2;
|
||||
struM300RTKSs.qstrM300RTKWidgetFilePath = m_struM300RTKSs.qstrM300RTKWidgetFilePath;
|
||||
struM300RTKSs.qstrM300RTKSettingsFilePath = m_struM300RTKSs.qstrM300RTKSettingsFilePath;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainConfigParser::Initialize(QString qstrPath)
|
||||
{
|
||||
QFileInfo qfiSettings(qstrPath);
|
||||
if (!qfiSettings.exists())
|
||||
{
|
||||
qDebug() << "Fatal Error.Main config file not found.!!!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QSettings qsMainSettings(qfiSettings.filePath(), QSettings::Format::IniFormat);
|
||||
|
||||
QString qstrWindSensorPort = qsMainSettings.value(QString("SENSOR/WindSensorPort"), "Error").toString();
|
||||
qDebug() << "qstrWindSensorPort:" << qstrWindSensorPort;
|
||||
if (qstrWindSensorPort == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.WindSensorPort not load";
|
||||
return 2;
|
||||
}
|
||||
m_struSensorPort.qstrWindSensorPort = qstrWindSensorPort;
|
||||
|
||||
QString qstrGasSensorPort = qsMainSettings.value(QString("SENSOR/GasSensorPort"), "Error").toString();
|
||||
qDebug() << "qstrGasSensorPort:" << qstrGasSensorPort;
|
||||
if (qstrGasSensorPort == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.GasSensorPort not load";
|
||||
return 3;
|
||||
}
|
||||
m_struSensorPort.qstrGasSensorPort = qstrGasSensorPort;
|
||||
|
||||
int iPumpGPIO = qsMainSettings.value(QString("GPIO/PortNumber"), "-1").toInt();
|
||||
qDebug() << "iPumpGPIO:" << iPumpGPIO;
|
||||
if (iPumpGPIO == -1)
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.iPumpGPIO not load";
|
||||
return 4;
|
||||
}
|
||||
m_struMiscCtrls.iPumpGPIOPort = iPumpGPIO;
|
||||
|
||||
QString qstrUART1= qsMainSettings.value(QString("M300RTK/UART1"), "Error").toString();
|
||||
if (qstrUART1 == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.M300 UART1 not load";
|
||||
return 5;
|
||||
}
|
||||
m_struM300RTKSs.qstrM300RTKUDEV1= qstrUART1;
|
||||
strcpy(gvpcM300RTK_UART1, qstrUART1.toLatin1().data());
|
||||
|
||||
QString qstrUART2 = qsMainSettings.value(QString("M300RTK/UART2"), "Error").toString();
|
||||
if (qstrUART2 == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.M300 UART2 not load";
|
||||
return 6;
|
||||
}
|
||||
m_struM300RTKSs.qstrM300RTKUDEV2 = qstrUART2;
|
||||
strcpy(gvpcM300RTK_UART2, qstrUART2.toLatin1().data());
|
||||
|
||||
QString qstrSettingsFilePath = qsMainSettings.value(QString("M300RTK/SettingsFilePath"), "Error").toString();
|
||||
if (qstrSettingsFilePath == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.M300 SettingsFilePath not load";
|
||||
return 7;
|
||||
}
|
||||
m_struM300RTKSs.qstrM300RTKSettingsFilePath = qstrSettingsFilePath;
|
||||
|
||||
QString qstrWidgetFilePath = qsMainSettings.value(QString("M300RTK/WidgetFilePath"), "Error").toString();
|
||||
if (qstrWidgetFilePath == "Error")
|
||||
{
|
||||
qDebug() << "MainConfigParser:Func Initialize.M300 WidgetFilePath not load";
|
||||
return 8;
|
||||
}
|
||||
m_struM300RTKSs.qstrM300RTKWidgetFilePath = qstrWidgetFilePath;
|
||||
|
||||
#ifdef ZZ_FLAG_TEST
|
||||
qDebug() << "UART 1" << gvpcM300RTK_UART1;
|
||||
qDebug() << "UART 2" << gvpcM300RTK_UART2;
|
||||
qDebug() << "WidgetFilePath" << qstrWidgetFilePath;
|
||||
qDebug() << "SettingsFilePath" << qstrSettingsFilePath;
|
||||
#endif
|
||||
|
||||
m_bIsInit = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
29
Source/MainSettings/MainConfigParser.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "ZZ_Types.h"
|
||||
#include "hal_uart.h"
|
||||
using namespace ZZ_DATA_DEF::MainConfig;
|
||||
class MainConfigParser:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainConfigParser(QObject* parent = nullptr);
|
||||
virtual ~MainConfigParser();
|
||||
private:
|
||||
QString m_qstrFullFilePath;
|
||||
|
||||
MiscControls m_struMiscCtrls;
|
||||
M300RTKSettings m_struM300RTKSs;
|
||||
SensorPort m_struSensorPort;
|
||||
|
||||
bool m_bIsInit;
|
||||
public:
|
||||
int SetFilePath(QString qstrFullFilePath);
|
||||
int GetParams(MiscControls &struMiscCtrls,M300RTKSettings& struM300RTKSs,SensorPort& struSensorPort);
|
||||
private:
|
||||
int Initialize(QString qstrPath);
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
10
Source/MainSettings/SettingsFile/MainSettings.ini
Normal file
@ -0,0 +1,10 @@
|
||||
[SENSOR]
|
||||
WindSensorPort=/dev/ttyS2
|
||||
GasSensorPort=/dev/ttyS1
|
||||
[M300RTK]
|
||||
UART1=/dev/ttyUSB0
|
||||
UART2=/dev/ttyACM0
|
||||
WidgetFilePath=/home/data/DJI/Settings
|
||||
SettingsFilePath=/home/data/DJI/Widget
|
||||
[GPIO]
|
||||
PortNumber=7
|
||||
101
Source/ZZ_Types.h
Normal file
@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
namespace ZZ_DATA_DEF
|
||||
{
|
||||
namespace M300RTK
|
||||
{
|
||||
typedef struct tagVector3f
|
||||
{
|
||||
float x; /*!< Specifies float value of x for vector. */
|
||||
float y; /*!< Specifies float value of y for vector. */
|
||||
float z; /*!< Specifies float value of z for vector. */
|
||||
}ZZVector3f;
|
||||
|
||||
|
||||
typedef struct tagVector3d {
|
||||
int32_t x; /*!< Specifies int32 value of x for vector. */
|
||||
int32_t y; /*!< Specifies int32 value of y for vector. */
|
||||
int32_t z; /*!< Specifies int32 value of z for vector. */
|
||||
} ZZVector3d;
|
||||
|
||||
typedef struct tagDegOrientation
|
||||
{
|
||||
float roll;
|
||||
float pitch;
|
||||
float yaw;
|
||||
}ZZDegOrientation;
|
||||
|
||||
typedef struct tagQuaternion
|
||||
{
|
||||
float w_q0;
|
||||
float x_q1;
|
||||
float y_q2;
|
||||
float z_q3;
|
||||
}ZZQuaternion;
|
||||
|
||||
typedef struct tagM300RTKDataFrame
|
||||
{
|
||||
// ZZ_U32 usExposureTimeInMS;
|
||||
// ZZ_S32 lData[4096];
|
||||
// float fTemperature = 0;
|
||||
// double dTimes = 0;
|
||||
ZZVector3d stGPSPosition = { 0 };
|
||||
ZZVector3f stVelocity = { 0 };
|
||||
ZZQuaternion stQuaternion = { 0 };
|
||||
float fAltitudeFused;
|
||||
ZZDegOrientation stEulerAngle = { 0 };
|
||||
}M300RTKDataFrame;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
namespace CO2_GAS_SENSOR
|
||||
{
|
||||
typedef struct tagGSDataFrame
|
||||
{
|
||||
unsigned long ulCO2;
|
||||
unsigned long ulH2O;
|
||||
float fTemp;
|
||||
float fPB;
|
||||
float fPP;
|
||||
}GSDataFrame;
|
||||
};
|
||||
|
||||
namespace UA_SENSOR
|
||||
{
|
||||
typedef struct tagUASDataFrame
|
||||
{
|
||||
float fWindSpeed;
|
||||
float fWindDirection;
|
||||
float fFixedWindSpeed;
|
||||
float fFixedWindDirection;
|
||||
float fWindTemperature;
|
||||
}UASDataFrame;
|
||||
};
|
||||
|
||||
namespace MainConfig
|
||||
{
|
||||
typedef struct tagMiscControls
|
||||
{
|
||||
int iPumpGPIOPort;
|
||||
}MiscControls;
|
||||
|
||||
typedef struct tagM300RTKSettings
|
||||
{
|
||||
QString qstrM300RTKUDEV1;
|
||||
QString qstrM300RTKUDEV2;
|
||||
QString qstrM300RTKSettingsFilePath;
|
||||
QString qstrM300RTKWidgetFilePath;
|
||||
}M300RTKSettings;
|
||||
|
||||
typedef struct tagSensorPort
|
||||
{
|
||||
QString qstrWindSensorPort;
|
||||
QString qstrGasSensorPort;
|
||||
}SensorPort;
|
||||
};
|
||||
|
||||
};
|
||||
35
Source/pch.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
////////////////////////////setings
|
||||
#include <QSettings>
|
||||
#include <QMetaEnum>
|
||||
////////////////////////////Basic
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
#include <QtEndian>
|
||||
////////////////////////////Thread
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
////////////////////////////json
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonParseError>
|
||||
////////////////////////////time
|
||||
#include <QtCore/QTime>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
////////////////////////////Serial I/O
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
////////////////////////////NetWork
|
||||
#include "QNetworkRequest"
|
||||
#include "QNetworkAccessManager"
|
||||
#include "QNetworkReply"
|
||||