调通遥控器,但是dlink进入死锁

This commit is contained in:
hm
2021-01-13 21:51:51 +08:00
parent f56f004774
commit 222df390c6
21 changed files with 233 additions and 83 deletions
+32 -25
View File
@@ -262,11 +262,15 @@ void RemoteControl::PowerSwitchUpdate(uint16_t value)
{
if(value <= 1300)
{
isActive = true;
isActive = 0;
}
else if(value <= 1600)
{
isActive = 1;
}
else
{
isActive = false;
isActive = 2;
}
//qDebug() << isActive << value;
}
@@ -290,7 +294,7 @@ void RemoteControl::stateChanged(void)
rc.append(channel[9]);
if(isActive)
if(isActive == 2)
{
emit RemoteControlUpdate(rc);
}
@@ -358,31 +362,34 @@ void RemoteControl::setMode(uint8_t value)
void RemoteControl::setChannelOveride(QList<uint16_t> rc)
{
if(mode == RightHand)//右手油门
if(isActive == 1)
{
joystick_right->setValue(0,rc.at(1));
joystick_right->setValue(1,rc.at(3));
joystick_left->setValue(0,rc.at(4));
joystick_left->setValue(1,rc.at(2));
}
else if(mode == LeftHand)
{
joystick_left->setValue(0,rc.at(1));
joystick_left->setValue(1,rc.at(3));
joystick_right->setValue(0,rc.at(4));
joystick_right->setValue(1,rc.at(2));
}
if(mode == RightHand)//右手油门
{
joystick_right->setValue(0,rc.at(1));
joystick_right->setValue(1,rc.at(3));
joystick_left->setValue(0,rc.at(4));
joystick_left->setValue(1,rc.at(2));
}
else if(mode == LeftHand)
{
joystick_left->setValue(0,rc.at(1));
joystick_left->setValue(1,rc.at(3));
joystick_right->setValue(0,rc.at(4));
joystick_right->setValue(1,rc.at(2));
}
AUX5Switch->setValue(rc.at(5));
AUX6Switch->setValue(rc.at(6));
AUX7Switch->setValue(rc.at(7));
AUX8Switch->setValue(rc.at(8));
AUX5Switch->setValue(rc.at(5));
AUX6Switch->setValue(rc.at(6));
AUX7Switch->setValue(rc.at(7));
AUX8Switch->setValue(rc.at(8));
remotelabel->raise();
remotelabel->setText(QString("%1:%2:%3:%4:%5:%6:%7:%8:%9:%10")\
.arg(rc[0],5).arg(rc[1],4).arg(rc[2],4)\
.arg(rc[3],4).arg(rc[4],4).arg(rc[5],4)\
.arg(rc[6],4).arg(rc[7],4).arg(rc[8],4).arg(rc[9],4));
remotelabel->raise();
remotelabel->setText(QString("%1:%2:%3:%4:%5:%6:%7:%8:%9:%10")\
.arg(rc[0],5).arg(rc[1],4).arg(rc[2],4)\
.arg(rc[3],4).arg(rc[4],4).arg(rc[5],4)\
.arg(rc[6],4).arg(rc[7],4).arg(rc[8],4).arg(rc[9],4));
}
}
+5 -3
View File
@@ -28,13 +28,15 @@ public:
//void setDirection(uint16_t Channel,uint16_t Value);
void setFixed(bool value);
void setMode(uint8_t value);
void setChannelOveride(QList<uint16_t> rc);
signals:
void RemoteControlUpdate(QList<uint16_t>);
public slots:
void setChannelOveride(QList<uint16_t> rc);
void Left_stickUpdate(uint16_t channel0, uint16_t channel1);
void Right_stickUpdate(uint16_t channel0, uint16_t channel1);
@@ -81,10 +83,10 @@ private:
1100,1100,1100,1100,1100,1100,1100,1100,1100,1100,1100};
//遥控配置
uint8_t mode = 0;//右手0 左手1
uint8_t mode = 1;//右手0 左手1
//开关
bool isActive= false;
uint32_t isActive= 0;
};
+3
View File
@@ -286,6 +286,9 @@ MainWindow::MainWindow(QWidget *parent)
toolsui->index2,SLOT(ReplayComplete()),Qt::DirectConnection);
connect(dlink->mavlinknode,SIGNAL(new_remote_ctrl(QList<uint16_t>)),
toolsui->remotecontrol,SLOT(setChannelOveride(QList<uint16_t>)));
//dlink --- toolui-index3
connect(dlink->mavlinknode->Terminal,SIGNAL(Recieve(QString)),
toolsui->index3,SLOT(Recieve(QString)),Qt::DirectConnection);
+2
View File
@@ -59,6 +59,7 @@ HEADERS += \
missionprocess.h \
mavlinknodeglobal.h \
replay.h \
sbusparser.h \
statusprocess.h
SOURCES += \
@@ -68,6 +69,7 @@ SOURCES += \
parameterprocess.cpp \
missionprocess.cpp \
replay.cpp \
sbusparser.cpp \
statusprocess.cpp
INCLUDEPATH += $$PWD/../thirdpart/include
+5 -2
View File
@@ -86,8 +86,11 @@ void terminal::setID(int m_sysid,int m_compid)
void terminal::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
+1
View File
@@ -8,6 +8,7 @@
#include "mavlink.h"
#include "QTimer"
#include "QTime"
#include <QtEndian>
#ifdef QtMavlinkNode
+5 -2
View File
@@ -93,8 +93,11 @@ void commandprocess::setID(int m_sysid,int m_compid)
void commandprocess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
+1
View File
@@ -8,6 +8,7 @@
#include "mavlink.h"
#include "QTimer"
#include "QTime"
#include <QtEndian>
#ifdef QtMavlinkNode
#include <mavlinknodeglobal.h>
+120
View File
@@ -173,7 +173,15 @@ void MavLinkNode::setGCSID(int id)
}
}
void MavLinkNode::SendMessage(mavlink_message_t msg)
{
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
void MavLinkNode::setRunFrq(uint32_t frq)
{
@@ -218,6 +226,13 @@ void MavLinkNode::start()
logTimer->start();
gdt_timer = new QTimer(this);
gdt_timer->setInterval(66);
connect(gdt_timer, &QTimer::timeout,
this, &MavLinkNode::update15Hz,Qt::DirectConnection);
gdt_timer->start();
//初始化buff
initbuff();
@@ -1358,6 +1373,111 @@ void MavLinkNode::setLogfile(QString file)
}
}
void MavLinkNode::update15Hz(void)
{
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
mavlink_message_t msg;
if (rtkrawdata.size() >= 180)
{
mavlink_gps_rtcm_data_t rtcm;
rtcm.flags = 0;
rtcm.len = 180;
for (uint i=0u;i<180u;++i)
{
rtcm.data[i] = rtkrawdata[i];
}
mavlink_msg_gps_rtcm_data_encode(0,0,&msg,&rtcm);
SendMessage(msg);
rtkrawdata = rtkrawdata.mid(180);
}
else if (rcin_update)
{
if (!remote_enabled || rcin_cnt > 0)
{
rcin_cnt--;
mavlink_rc_channels_override_t command;
command.chan1_raw = rcin[0];
command.chan2_raw = rcin[1];
command.chan3_raw = rcin[2];
command.chan4_raw = rcin[3];
command.chan5_raw = rcin[4];
command.chan6_raw = rcin[5];
command.chan7_raw = rcin[6];
command.chan8_raw = rcin[7];
command.chan9_raw = rcin[8];
command.chan10_raw = rcin[9];
command.chan11_raw = rcin[10];
command.chan12_raw = rcin[11];
command.chan13_raw = rcin[12];
command.chan14_raw = rcin[13];
command.chan15_raw = rcin[14];
command.chan16_raw = rcin[15];
command.chan17_raw = rcin[16];
command.chan18_raw = rcin[17];
command.target_component = 2;
command.target_system = 0;
mavlink_msg_rc_channels_override_encode(0,0,&msg,&command);
SendMessage(msg);
}
}
}
void MavLinkNode::readRTK(QByteArray datagram)
{
bool rtk_sending = true;
if (rtk_sending)
{
/*
rtkrawdata.append(datagram);
if (rtkrawdata.size() > 2048)
{
rtkrawdata.mid(2048);
}
*/
}
}
void MavLinkNode::readRemote(QByteArray datagram)
{
bool remote_enabled = true;
if (remote_enabled)
{
for (QByteArray::const_iterator i = datagram.cbegin(); i != datagram.cend(); ++i)
{
if (sbus.parse_char(*i))
{
/*
for (int i=0; i<18; ++i)
{
rcin[i] = sbus.Channel[i+1];
}
rcin_cnt = 10;
*/
QList<uint16_t> list;
for (int i=0; i<13; ++i)
{
list.append(sbus.Channel[i]);
}
emit new_remote_ctrl(list);
}
}
}
}
/*
void MavLinkNode::saveExcel(QString filepath)
{
+17 -4
View File
@@ -13,7 +13,7 @@
#include "commandprocess.h"
#include "statusprocess.h"
#include "Terminal.h"
#include "sbusparser.h"
//#include "QAxObject"
@@ -106,6 +106,15 @@ public:
float rssi = 100;
uint16_t rcin[20];
int rcin_cnt = 0;
bool rcin_update = true;
bool remote_enabled;
QByteArray rtkrawdata;
QByteArray csvData;
QByteArray autopilot_version_csv;
@@ -169,7 +178,7 @@ signals:
void signal_servo_output_raw(mavlink_servo_output_raw_t servo);
void new_remote_ctrl(QList<uint16_t>);
void updateDlink(float rssi,uint64_t byte);
void CommuniationLost(bool);
@@ -217,9 +226,13 @@ public slots:
void setGCSID(int id);
void update15Hz(void);
void readRemote(QByteArray datagram);
void readRTK(QByteArray datagram);
private slots:
//线程私有接口
void SendMessage(mavlink_message_t msg);
void process();
//缓存私有接口
@@ -266,9 +279,9 @@ protected:
QThread *Parameterthread;
SBusParser sbus;
QTimer *gdt_timer = nullptr;
QTimer *timer = nullptr;
+5 -2
View File
@@ -98,8 +98,11 @@ void MissionProcess::setID(int m_sysid,int m_compid)
void MissionProcess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
+1
View File
@@ -13,6 +13,7 @@
#include "mavlink.h"
#include "QTimer"
#include "QTime"
#ifdef QtMavlinkNode
#include <mavlinknodeglobal.h>
class MAVLINKNODESHARED_EXPORT MissionProcess : public QObject {
+5 -2
View File
@@ -91,8 +91,11 @@ void ParameterProcess::setID(int m_sysid,int m_compid)
void ParameterProcess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
+1
View File
@@ -8,6 +8,7 @@
#include "mavlink.h"
#include "QTimer"
#include "QTime"
#include <QtEndian>
//#include "ParameterInspector/ParameterInspector.h"
+5 -2
View File
@@ -103,8 +103,11 @@ void statusprocess::setID(int m_sysid,int m_compid)
void statusprocess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
qToBigEndian(currentTimestamp, buff);
uint16_t len = mavlink_msg_to_send_buffer(buff+ sizeof(quint64), &msg);
emit SendMessageTo(0,buff, len);//使用信号和槽
}
+1
View File
@@ -8,6 +8,7 @@
#include "mavlink.h"
#include "QTimer"
#include "QTime"
#include <QtEndian>
#ifdef QtMavlinkNode
+16 -30
View File
@@ -15,7 +15,7 @@ DLink::DLink(QObject *parent) : QObject(parent)
//在当前线程运行
connect(mavlinknode,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
this,SLOT(SendMessageTo(quint8,quint8*,quint16)),Qt::BlockingQueuedConnection);//采用直连的方式,因为是多线程
this,SLOT(SendMessageTo(quint8,quint8*,quint16)),Qt::QueuedConnection);//BlockingQueuedConnection);//采用直连的方式,因为是多线程
//在当前线程运行
connect(mavlinknode,SIGNAL(showMessage(QString,int)),
@@ -25,6 +25,14 @@ DLink::DLink(QObject *parent) : QObject(parent)
connect(this,SIGNAL(recieveMessage(quint32,QByteArray)),
mavlinknode,SLOT(setbuff(quint32,QByteArray)),Qt::DirectConnection);
connect(this,SIGNAL(getRTK(QByteArray)),
mavlinknode,SLOT(readRTK(QByteArray)),Qt::DirectConnection);
connect(this,SIGNAL(getRemote(QByteArray)),
mavlinknode,SLOT(readRemote(QByteArray)),Qt::DirectConnection);
mavlinknode->start();
//其他协议节点。。。
}
@@ -491,28 +499,23 @@ void DLink::processPendingMulticastDatagrams(void)
void DLink::readRTKPendingDatagrams(void)
{
bool rtk_sending = true;
QObject *obj = sender();
QSerialPort *serialport = qobject_cast<QSerialPort *>(obj);
if(serialport)
{
QByteArray datagram = serialport->readAll();
if (rtk_sending)
if(datagram.size() > 0)
{
rtkrawdata.append(datagram);
if (rtkrawdata.size() > 2048)
{
rtkrawdata.mid(2048);
}
emit getRTK(datagram);
}
}
}
void DLink::readRemotePendingDatagrams(void)
{
bool remote_enabled = true;
QObject *obj = sender();
QSerialPort *serialport = qobject_cast<QSerialPort *>(obj);
@@ -520,30 +523,13 @@ void DLink::readRemotePendingDatagrams(void)
{
QByteArray datagram = serialport->readAll();
if (remote_enabled)
if(datagram.size() > 0)
{
for (QByteArray::const_iterator i = datagram.cbegin(); i != datagram.cend(); ++i)
{
if (sbus.parse_char(*i))
{
for (int i=0; i<18; ++i)
{
rcin[i] = sbus.Channel[i+1];
}
rcin_cnt = 10;
QList<uint16_t> list;
for (int i=0; i<10; ++i)
{
list.append(sbus.Channel[i]);
}
//emit new_remote_ctrl(list);
}
}
emit getRemote(datagram);
}
}
}
+6 -7
View File
@@ -7,7 +7,7 @@
#include <QUdpSocket>
#include "QDebug"
#include "mavlinknode.h"
#include "sbusparser.h"
QT_BEGIN_NAMESPACE
@@ -70,7 +70,8 @@ signals:
QVariant m_Param3,QVariant m_Param4,
QVariant m_Param5);
void getRemote(QByteArray);
void getRTK(QByteArray);
public slots:
@@ -110,10 +111,8 @@ protected:
};
SBusParser sbus;
uint16_t rcin[20];
int rcin_cnt = 0;
bool rcin_update = true;
QMap<uint32_t,unsigned> cnts_in;
QMap<uint32_t,unsigned> cnts_out;
@@ -134,7 +133,7 @@ protected:
qint32 multicast_transmit_port;
QByteArray rtkrawdata;
QMap<quint8,QIODevice *> Device;
+2 -4
View File
@@ -45,12 +45,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
HEADERS += \
$$PWD/dlink.h \
$$PWD/dlinkglobal.h \
sbusparser.h
$$PWD/dlinkglobal.h
SOURCES += \
$$PWD/dlink.cpp \
sbusparser.cpp
$$PWD/dlink.cpp
#加入第三方库
INCLUDEPATH += $$PWD/../thirdpart/include