This commit is contained in:
hm
2021-07-03 11:31:09 +08:00
parent e054ecf094
commit 5f5795ab2d
7 changed files with 48 additions and 330 deletions
+1 -12
View File
@@ -252,18 +252,7 @@ void StateWidget::setValue(QString s)
bool flag = false; bool flag = false;
double value = s.toDouble(&flag); double value = s.toDouble(&flag);
#ifdef unix value = (qIsNaN(value))?(0):(value);
#else
#ifdef __MINGW32__
#else
if(isnan(value))
{
return;
}
#endif
#endif
if(bar) if(bar)
{ {
+22 -265
View File
@@ -276,21 +276,7 @@ void Cockpit::wheelEvent(QWheelEvent *e)
void Cockpit::setPitch(double Pitch) void Cockpit::setPitch(double Pitch)
{ {
#ifdef unix Pitch = (qIsNaN(Pitch))?(0):(Pitch);
#else
#ifdef __MINGW32__
#else
if(isnan(Pitch))
{
return;
}
#endif
#endif
//if(Pitch > 360) Pitch = 360;
//else if(Pitch < -360) Pitch = -360;
int n = Pitch/360; int n = Pitch/360;
Pitch = Pitch - n*360; Pitch = Pitch - n*360;
@@ -308,21 +294,7 @@ void Cockpit::setPitch(double Pitch)
void Cockpit::setPitchTarget(double Pitch) void Cockpit::setPitchTarget(double Pitch)
{ {
#ifdef unix Pitch = (qIsNaN(Pitch))?(0):(Pitch);
#else
#ifdef __MINGW32__
#else
if(isnan(Pitch))
{
return;
}
#endif
#endif
//if(Pitch > 360) Pitch = 360;
//else if(Pitch < -360) Pitch = -360;
int n = Pitch/360; int n = Pitch/360;
Pitch = Pitch - n*360; Pitch = Pitch - n*360;
@@ -341,20 +313,7 @@ void Cockpit::setPitchTarget(double Pitch)
void Cockpit::setRoll(double Roll) void Cockpit::setRoll(double Roll)
{ {
#ifdef unix Roll = (qIsNaN(Roll))?(0):(Roll);
#else
#ifdef __MINGW32__
#else
if(isnan(Roll))
{
return;
}
#endif
#endif
//if(Roll > 360) Roll = 360;
//else if(Roll < -360) Roll = -360;
int n = Roll/360; int n = Roll/360;
Roll = Roll - n*360; Roll = Roll - n*360;
@@ -372,20 +331,7 @@ void Cockpit::setRoll(double Roll)
void Cockpit::setRollTarget(double Roll) void Cockpit::setRollTarget(double Roll)
{ {
#ifdef unix Roll = (qIsNaN(Roll))?(0):(Roll);
#else
#ifdef __MINGW32__
#else
if(isnan(Roll))
{
return;
}
#endif
#endif
//if(Roll > 360) Roll = 360;
//else if(Roll < -360) Roll = -360;
int n = Roll/360; int n = Roll/360;
Roll = Roll - n*360; Roll = Roll - n*360;
@@ -405,18 +351,7 @@ void Cockpit::setRollTarget(double Roll)
void Cockpit::setYaw(double Yaw) void Cockpit::setYaw(double Yaw)
{ {
#ifdef unix Yaw = (qIsNaN(Yaw))?(0):(Yaw);
#else
#ifdef __MINGW32__
#else
if(isnan(Yaw))
{
return;
}
#endif
#endif
if(Yaw < 0) Yaw += 360; if(Yaw < 0) Yaw += 360;
else if(Yaw > 360) Yaw -= 360; else if(Yaw > 360) Yaw -= 360;
@@ -431,19 +366,8 @@ void Cockpit::setYaw(double Yaw)
void Cockpit::setYawTarget(double Yaw) void Cockpit::setYawTarget(double Yaw)
{ {
#ifdef unix Yaw = (qIsNaN(Yaw))?(0):(Yaw);
#else
#ifdef __MINGW32__
#else
if(isnan(Yaw))
{
return;
}
#endif
#endif
if(Yaw < 0) Yaw += 360; if(Yaw < 0) Yaw += 360;
else if(Yaw > 360) Yaw -= 360; else if(Yaw > 360) Yaw -= 360;
@@ -473,50 +397,18 @@ void Cockpit::setAttitudeTarget(double Pitch,double Roll,double Yaw)
void Cockpit::setAttitudeSpeed(double PitchSpeed,double RollSpeed,double YawSpeed) void Cockpit::setAttitudeSpeed(double PitchSpeed,double RollSpeed,double YawSpeed)
{ {
#ifdef unix
#else
#ifdef __MINGW32__
#else m_State.gy = (qIsNaN(PitchSpeed))?(0):(PitchSpeed);
if(isnan(PitchSpeed)) m_State.gx = (qIsNaN(RollSpeed))?(0):(RollSpeed);
{ m_State.gz = (qIsNaN(YawSpeed))?(0):(YawSpeed);
return;
}
if(isnan(RollSpeed))
{
return;
}
if(isnan(YawSpeed))
{
return;
}
#endif
#endif
m_State.gy = PitchSpeed;
m_State.gx = RollSpeed;
m_State.gz = YawSpeed;
m_State.isUpdate = true; m_State.isUpdate = true;
} }
void Cockpit::setAltitude(double Altitude) void Cockpit::setAltitude(double Altitude)
{ {
#ifdef unix Altitude = (qIsNaN(Altitude))?(0):(Altitude);
#else
#ifdef __MINGW32__
#else
if(isnan(Altitude))
{
return;
}
#endif
#endif
if(Altitude > 99999) Altitude = 99999; if(Altitude > 99999) Altitude = 99999;
else if(Altitude < (-9999)) Altitude = -9999; else if(Altitude < (-9999)) Altitude = -9999;
@@ -527,18 +419,7 @@ void Cockpit::setAltitude(double Altitude)
void Cockpit::setHeight(double Altitude) void Cockpit::setHeight(double Altitude)
{ {
#ifdef unix Altitude = (qIsNaN(Altitude))?(0):(Altitude);
#else
#ifdef __MINGW32__
#else
if(isnan(Altitude))
{
return;
}
#endif
#endif
if(Altitude > 99999) Altitude = 99999; if(Altitude > 99999) Altitude = 99999;
else if(Altitude < (-9999)) Altitude = -9999; else if(Altitude < (-9999)) Altitude = -9999;
@@ -549,18 +430,7 @@ void Cockpit::setHeight(double Altitude)
void Cockpit::setAltitudeTarget(double Altitude) void Cockpit::setAltitudeTarget(double Altitude)
{ {
#ifdef unix Altitude = (qIsNaN(Altitude))?(0):(Altitude);
#else
#ifdef __MINGW32__
#else
if(isnan(Altitude))
{
return;
}
#endif
#endif
if(Altitude > 99999) Altitude = 99999; if(Altitude > 99999) Altitude = 99999;
else if(Altitude < (-9999)) Altitude = -9999; else if(Altitude < (-9999)) Altitude = -9999;
@@ -572,41 +442,17 @@ void Cockpit::setAltitudeTarget(double Altitude)
void Cockpit::setSpeed(double speed,uint8_t flag) void Cockpit::setSpeed(double speed,uint8_t flag)
{ {
#ifdef unix
#else
#ifdef __MINGW32__
#else
if(isnan(speed))
{
return;
}
#endif
#endif
m_State.AirspeedFlag = flag; m_State.AirspeedFlag = flag;
m_State.speed = speed; m_State.speed = (qIsNaN(speed))?(0):(speed);;
m_State.isUpdate = true; m_State.isUpdate = true;
} }
void Cockpit::setAirSpeed(double speed,uint8_t flag) void Cockpit::setAirSpeed(double speed,uint8_t flag)
{ {
#ifdef unix speed = (qIsNaN(speed))?(0):(speed);
#else
#ifdef __MINGW32__
#else
if(isnan(speed))
{
return;
}
#endif
#endif
if(speed < 0) speed = 0; if(speed < 0) speed = 0;
else if(speed > 9999) speed = 9999; else if(speed > 9999) speed = 9999;
@@ -618,19 +464,7 @@ void Cockpit::setAirSpeedTarget(double speed, uint8_t flag)
{ {
Q_UNUSED(flag) Q_UNUSED(flag)
#ifdef unix speed = (qIsNaN(speed))?(0):(speed);
#else
#ifdef __MINGW32__
#else
if(isnan(speed))
{
return;
}
#endif
#endif
if(speed < 0) speed = 0; if(speed < 0) speed = 0;
else if(speed > 9999) speed = 999; else if(speed > 9999) speed = 999;
@@ -647,18 +481,7 @@ void Cockpit::setAirSpeedFlag(quint8 flag)
void Cockpit::setVerticalSpeed(double speed) void Cockpit::setVerticalSpeed(double speed)
{ {
#ifdef unix speed = (qIsNaN(speed))?(0):(speed);
#else
#ifdef __MINGW32__
#else
if(isnan(speed))
{
return;
}
#endif
#endif
m_State.verticalspeed_t = speed; m_State.verticalspeed_t = speed;
m_State.isUpdate = true; m_State.isUpdate = true;
@@ -666,18 +489,7 @@ void Cockpit::setVerticalSpeed(double speed)
void Cockpit::setVerticalSpeedTarget(double speed) void Cockpit::setVerticalSpeedTarget(double speed)
{ {
#ifdef unix speed = (qIsNaN(speed))?(0):(speed);
#else
#ifdef __MINGW32__
#else
if(isnan(speed))
{
return;
}
#endif
#endif
m_Target.verticalspeed = speed; m_Target.verticalspeed = speed;
m_Target.isUpdate = true; m_Target.isUpdate = true;
@@ -685,18 +497,7 @@ void Cockpit::setVerticalSpeedTarget(double speed)
void Cockpit::setXTrack(double value)//飞机在航线右边为正 void Cockpit::setXTrack(double value)//飞机在航线右边为正
{ {
#ifdef unix value = (qIsNaN(value))?(0):(value);
#else
#ifdef __MINGW32__
#else
if(isnan(value))
{
return;
}
#endif
#endif
if(value > 9999) value = 9999; if(value > 9999) value = 9999;
else if(value < (-9999)) value = -9999; else if(value < (-9999)) value = -9999;
@@ -707,18 +508,7 @@ void Cockpit::setXTrack(double value)//飞机在航线右边为正
void Cockpit::setWP_dist(double value) void Cockpit::setWP_dist(double value)
{ {
#ifdef unix value = (qIsNaN(value))?(0):(value);
#else
#ifdef __MINGW32__
#else
if(isnan(value))
{
return;
}
#endif
#endif
if(value > 9999) value = 9999; if(value > 9999) value = 9999;
else if(value < (-9999)) value = -9999; else if(value < (-9999)) value = -9999;
@@ -729,18 +519,7 @@ void Cockpit::setWP_dist(double value)
void Cockpit::setAlt_err(double value)//飞机在航线下面为正 void Cockpit::setAlt_err(double value)//飞机在航线下面为正
{ {
#ifdef unix value = (qIsNaN(value))?(0):(value);
#else
#ifdef __MINGW32__
#else
if(isnan(value))
{
return;
}
#endif
#endif
if(value > 9999) value = 9999; if(value > 9999) value = 9999;
else if(value < (-9999)) value = -9999; else if(value < (-9999)) value = -9999;
@@ -770,18 +549,7 @@ void Cockpit::setState(QString str)
void Cockpit::setAOA(qreal Value) void Cockpit::setAOA(qreal Value)
{ {
#ifdef unix Value = (qIsNaN(Value))?(0):(Value);
#else
#ifdef __MINGW32__
#else
if(isnan(Value))
{
return;
}
#endif
#endif
m_State.AOA = Value; m_State.AOA = Value;
m_Target.isUpdate = true; m_Target.isUpdate = true;
@@ -789,18 +557,7 @@ void Cockpit::setAOA(qreal Value)
void Cockpit::setOL(qreal Value) void Cockpit::setOL(qreal Value)
{ {
#ifdef unix Value = (qIsNaN(Value))?(0):(Value);
#else
#ifdef __MINGW32__
#else
if(isnan(Value))
{
return;
}
#endif
#endif
m_State.OL = Value; m_State.OL = Value;
m_Target.isUpdate = true; m_Target.isUpdate = true;
+12 -45
View File
@@ -3,16 +3,18 @@
ThreadTemplet::ThreadTemplet(QObject *parent) : QObject(parent) ThreadTemplet::ThreadTemplet(QObject *parent) : QObject(parent)
{ {
running_flag = false; running_flag = false;
thread = new QThread(); moveToThread(this);
this->moveToThread(thread); //connect(this, &ThreadTemplet::started, this, &ThreadTemplet::process);
connect(thread, &QThread::started, this, &ThreadTemplet::process); //setRunFrq(50);//default frq = 50
setRunFrq(50);//default frq = 50
start();
} }
ThreadTemplet::~ThreadTemplet() ThreadTemplet::~ThreadTemplet()
{ {
stop(); quit();
wait();
} }
void ThreadTemplet::setRunFrq(uint32_t frq) void ThreadTemplet::setRunFrq(uint32_t frq)
@@ -24,45 +26,6 @@ void ThreadTemplet::setRunFrq(uint32_t frq)
} }
} }
void ThreadTemplet::start()
{
if(!thread->isRunning())
{
running_flag = true;
thread->start();
qDebug() << "thread start" << running_flag;
}
else
{
qDebug() << "thread has started";
}
}
void ThreadTemplet::stop()
{
if(thread)
{
if(!thread->isFinished())
{
running_flag = false;
disconnect(thread, nullptr, nullptr, nullptr);
thread->quit();
thread->deleteLater();
thread = nullptr;
}
else
{
qDebug() << "thread is not running";
}
}
}
void ThreadTemplet::process()//线程函数 void ThreadTemplet::process()//线程函数
{ {
@@ -75,7 +38,11 @@ void ThreadTemplet::process()//线程函数
} }
} }
void ThreadTemplet::run(void)
{
exec();
}
+3 -2
View File
@@ -9,9 +9,9 @@
#ifdef QtMavlinkNode #ifdef QtMavlinkNode
#include <mavlinknodeglobal.h> #include <mavlinknodeglobal.h>
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QObject { class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QThread {
#else #else
class ThreadTemplet : public QObject class ThreadTemplet : public QThread
{ {
#endif #endif
Q_OBJECT Q_OBJECT
@@ -38,6 +38,7 @@ public slots:
virtual void setRunFrq(uint32_t frq); virtual void setRunFrq(uint32_t frq);
virtual void start(); virtual void start();
virtual void stop(); virtual void stop();
virtual void run();
virtual bool isActive(void) virtual bool isActive(void)
{ {
return running_flag; return running_flag;
+7 -1
View File
@@ -132,8 +132,12 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
RC = new rcprocess(); RC = new rcprocess();
RC->setGCSID(Current_sysID,Current_CompID); RC->setGCSID(Current_sysID,Current_CompID);
connect(RC,SIGNAL(SendMessageTo(quint8,quint8*,quint16)), /* connect(RC,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection); this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
*/
connect(RC,&rcprocess::SendMessageTo,
this,&MavLinkNode::SendMessageTo);
connect(this,SIGNAL(setCurrentID(int,int)), connect(this,SIGNAL(setCurrentID(int,int)),
@@ -325,6 +329,8 @@ void MavLinkNode::start()
{ {
qDebug() << "MavLinkNode thread has started"; qDebug() << "MavLinkNode thread has started";
} }
} }
+2 -5
View File
@@ -1,5 +1,6 @@
#include "rcprocess.h" #include "rcprocess.h"
rcprocess::rcprocess(QObject *parent) : QObject(parent) rcprocess::rcprocess(QObject *parent) : QObject(parent)
{ {
//初始化ID //初始化ID
@@ -98,6 +99,7 @@ void rcprocess::stop()
thread->quit(); thread->quit();
thread->wait();
thread->deleteLater(); thread->deleteLater();
thread = nullptr; thread = nullptr;
@@ -107,12 +109,7 @@ void rcprocess::stop()
{ {
qDebug() << "thread is not running"; qDebug() << "thread is not running";
} }
qDebug() << "thread ";
} }
} }
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息 //这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
+1
View File
@@ -12,6 +12,7 @@ rtkprocess::rtkprocess(QObject *parent) : ThreadTemplet(parent)
rtkprocess::~rtkprocess() rtkprocess::~rtkprocess()
{ {
stop(); stop();
} }
void rtkprocess::setID(int m_sysid,int m_compid) void rtkprocess::setID(int m_sysid,int m_compid)