add command
@@ -101,7 +101,7 @@ win32|win64 {
|
||||
src_dir ~= s,/,\\,g
|
||||
dst_dir ~= s,/,\\,g
|
||||
|
||||
#system(xcopy $$src_dir $$dst_dir /y /e)
|
||||
system(xcopy $$src_dir $$dst_dir /y /e)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,15 +16,15 @@ InspectUI::~InspectUI()
|
||||
|
||||
void InspectUI::on_MavlinkpushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->MavlinkpushButton->text());
|
||||
emit clicked(tr("Mavlink"));
|
||||
}
|
||||
|
||||
void InspectUI::on_ParampushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->ParampushButton->text());
|
||||
emit clicked(tr("Parameter"));
|
||||
}
|
||||
|
||||
void InspectUI::on_AddpushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->AddpushButton->text());
|
||||
emit clicked(tr("add component"));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<widget class="QPushButton" name="MavlinkpushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<x>170</x>
|
||||
<y>10</y>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
@@ -25,11 +25,21 @@
|
||||
<property name="text">
|
||||
<string>Mavlink</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/BlueType/images/LinkUI/plane.ico</normaloff>:/BlueType/images/LinkUI/plane.ico</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>90</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="ParampushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<x>280</x>
|
||||
<y>10</y>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
@@ -38,11 +48,21 @@
|
||||
<property name="text">
|
||||
<string>Parameter</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/BlueType/images/LinkUI/params.ico</normaloff>:/BlueType/images/LinkUI/params.ico</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>90</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="AddpushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>400</x>
|
||||
<x>390</x>
|
||||
<y>10</y>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
|
||||
@@ -6,8 +6,17 @@ LinkUI::LinkUI(QWidget *parent) :
|
||||
ui(new Ui::LinkUI)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
ui->SerialPortpushButton->setIcon(QPixmap(":/images/LinkUI/SerialPort.ico"));
|
||||
ui->UDPpushButton->setIcon(QPixmap(":/images/LinkUI/Client.ico"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LinkUI::~LinkUI()
|
||||
{
|
||||
delete ui;
|
||||
@@ -15,15 +24,15 @@ LinkUI::~LinkUI()
|
||||
|
||||
void LinkUI::on_SerialPortpushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->SerialPortpushButton->text());
|
||||
emit clicked(tr("SerialPort"));
|
||||
}
|
||||
|
||||
void LinkUI::on_UDPpushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->UDPpushButton->text());
|
||||
emit clicked(tr("UDP"));
|
||||
}
|
||||
|
||||
void LinkUI::on_AddpushButton_clicked()
|
||||
{
|
||||
emit clicked(ui->AddpushButton->text());
|
||||
emit clicked(tr("add component"));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,17 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Serial Port</string>
|
||||
<string>SerialPort</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/BlueType/images/LinkUI/SerialPort.ico</normaloff>:/BlueType/images/LinkUI/SerialPort.ico</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>90</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="UDPpushButton">
|
||||
@@ -38,6 +48,16 @@
|
||||
<property name="text">
|
||||
<string>UDP</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/BlueType/images/LinkUI/Client.ico</normaloff>:/BlueType/images/LinkUI/Client.ico</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>90</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="AddpushButton">
|
||||
<property name="geometry">
|
||||
|
||||
@@ -251,7 +251,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
|
||||
|
||||
void MainWindow::subui(QString arg)//子界面管理
|
||||
{
|
||||
if(arg == tr("Serial Port"))
|
||||
if(arg == tr("SerialPort"))
|
||||
{
|
||||
dlink_triggered();
|
||||
}
|
||||
@@ -273,14 +273,12 @@ void MainWindow::subui(QString arg)//子界面管理
|
||||
}
|
||||
else if(arg == tr("Setting"))
|
||||
{
|
||||
help->show();
|
||||
setting->show();
|
||||
}
|
||||
else if(arg == tr("Help"))
|
||||
{
|
||||
setting->show();
|
||||
help->show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +313,7 @@ void MainWindow::onTabIndexChanged(const int &index)//界面选择管理
|
||||
|
||||
if(index == 5)
|
||||
{
|
||||
qDebug() << "index:" << index;
|
||||
qDebug() << "index:" << index;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -336,7 +334,7 @@ void MainWindow::dlink_triggered()
|
||||
disconnectdialog dlg(this);
|
||||
|
||||
dlg.setWindowTitle(tr("SerialPort"));
|
||||
//dlg.setWindowIcon(ui->action_dlink->icon());
|
||||
dlg.setWindowIcon(QIcon(":/images/LinkUI/SerialPort.ico"));
|
||||
|
||||
int ret = dlg.exec();
|
||||
if (QDialog::Accepted == ret)
|
||||
@@ -349,7 +347,7 @@ void MainWindow::dlink_triggered()
|
||||
ConnectDialog dlg(this);
|
||||
|
||||
dlg.setWindowTitle(tr("SerialPort"));
|
||||
//dlg.setWindowIcon(ui->action_dlink->icon());
|
||||
dlg.setWindowIcon(QIcon(":/images/LinkUI/SerialPort.ico"));
|
||||
|
||||
dlg.baudrate = 115200;
|
||||
dlg.parity = QSerialPort::NoParity;
|
||||
@@ -367,7 +365,7 @@ void MainWindow::client_triggered()
|
||||
ClientLinkDialog dlg(this);
|
||||
|
||||
dlg.setWindowTitle(tr("ClientLink"));
|
||||
//dlg.setWindowIcon(ui->action_dlink->icon());
|
||||
dlg.setWindowIcon(QIcon(":/images/LinkUI/Client.ico"));
|
||||
|
||||
int ret = dlg.exec();
|
||||
if (QDialog::Accepted == ret)
|
||||
|
||||
@@ -42,10 +42,12 @@ DEFINES += QtMavlinkNode
|
||||
|
||||
|
||||
HEADERS += \
|
||||
commandprocess.h \
|
||||
mavlinknode.h \
|
||||
parameterprocess.h
|
||||
|
||||
SOURCES += \
|
||||
commandprocess.cpp \
|
||||
mavlinknode.cpp \
|
||||
parameterprocess.cpp
|
||||
|
||||
|
||||
@@ -14,96 +14,7 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="systemComboBox">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Component</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="componentComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearButton">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ReadButton">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>75</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>read</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
@@ -205,6 +116,95 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="systemComboBox">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Component</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="componentComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearButton">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ReadButton">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>75</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>read</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
#include "commandprocess.h"
|
||||
|
||||
|
||||
//留出一个接口给界面去注册指令
|
||||
//收到ACK后发送一个信号
|
||||
|
||||
commandprocess::commandprocess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
setRunFrq(500);
|
||||
}
|
||||
|
||||
|
||||
void commandprocess::setRunFrq(uint32_t frq)
|
||||
{
|
||||
if((frq != 0)||(frq <= 1000))
|
||||
{
|
||||
running_frq = frq;
|
||||
qDebug() << "set command thread running frquency:" <<frq <<"Hz";
|
||||
}
|
||||
}
|
||||
|
||||
void commandprocess::start()
|
||||
{
|
||||
if(thread == nullptr)
|
||||
{
|
||||
thread = new QThread();
|
||||
this->moveToThread(thread);
|
||||
connect(thread, &QThread::started, this, &commandprocess::process);
|
||||
}
|
||||
|
||||
if(!thread->isRunning())
|
||||
{
|
||||
running_flag = true;
|
||||
thread->start();
|
||||
qDebug() << "thread start" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread has started";
|
||||
}
|
||||
}
|
||||
|
||||
void commandprocess::stop()
|
||||
{
|
||||
if(thread->isRunning())
|
||||
{
|
||||
running_flag = false;
|
||||
qDebug() << "thread stop" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
}
|
||||
|
||||
void commandprocess::process()//线程函数
|
||||
{
|
||||
uint8_t count = 0;
|
||||
|
||||
while (running_flag)
|
||||
{
|
||||
count ++;
|
||||
QThread::msleep(1000/running_frq);
|
||||
|
||||
switch(status.m_Mode)
|
||||
{
|
||||
default:
|
||||
case Nop_Mode :break;
|
||||
case RecieveMode : ReadStateMachine();break;
|
||||
case TransmitMode : WriteStateMachine();break;
|
||||
}
|
||||
|
||||
}
|
||||
//退出线程
|
||||
thread->quit();
|
||||
thread->wait(200);//等待结束
|
||||
thread->deleteLater();
|
||||
thread = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void commandprocess::SendMessage(mavlink_message_t msg)
|
||||
{
|
||||
uint8_t buff[256+20];
|
||||
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
|
||||
emit SendMessageTo(0,buff, len);//使用信号和槽
|
||||
}
|
||||
|
||||
//这个函数类似中断,专门处理接收到的状态
|
||||
void commandprocess::Parse(mavlink_message_t msg)
|
||||
{
|
||||
switch (msg.msgid) {
|
||||
case MAVLINK_MSG_ID_COMMAND_INT:
|
||||
mavlink_msg_command_int_decode(&msg,&command_int);
|
||||
case MAVLINK_MSG_ID_COMMAND_LONG:
|
||||
mavlink_msg_command_long_decode(&msg,&command_long);
|
||||
case MAVLINK_MSG_ID_COMMAND_ACK:
|
||||
mavlink_msg_command_ack_decode(&msg,&command_ack);
|
||||
}
|
||||
}
|
||||
|
||||
//读状态机
|
||||
void commandprocess::ReadStateMachine(void)//没有读指令这个说法
|
||||
{
|
||||
static uint8_t step = 0;
|
||||
static uint8_t timeout_count = 0;
|
||||
static uint32_t time = 0;
|
||||
|
||||
|
||||
if(step == 0)
|
||||
{
|
||||
qDebug() << "start reading parameter";
|
||||
status.recieve.isWaitingforValue = true;
|
||||
|
||||
//request_list();
|
||||
|
||||
step++;
|
||||
time = QTime::currentTime().msecsSinceStartOfDay();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//写状态机
|
||||
void commandprocess::WriteStateMachine(void)
|
||||
{
|
||||
static uint8_t step = 0;
|
||||
static uint8_t timeout_count = 0;
|
||||
static uint32_t time = 0;
|
||||
|
||||
if(step == 0)
|
||||
{
|
||||
|
||||
status.transmit.isWaitingforACK = true;
|
||||
|
||||
//set("id",0,1);//发送一个指令
|
||||
time = QTime::currentTime().msecsSinceStartOfDay();
|
||||
step++;//下一个阶段
|
||||
}
|
||||
else if(step == 1)//等待返回
|
||||
{
|
||||
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
|
||||
{
|
||||
timeout_count ++;
|
||||
step = 0;//返回上一个步骤
|
||||
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束发送
|
||||
{
|
||||
qDebug() << "command set value fail";
|
||||
step = 0;
|
||||
status.m_Mode = Nop_Mode;
|
||||
status.transmit.isWaitingforACK = false;
|
||||
timeout_count = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//收到Value
|
||||
if(status.transmit.isWaitingforACK == false)
|
||||
{
|
||||
step = 0;
|
||||
status.m_Mode = Nop_Mode;
|
||||
status.transmit.isWaitingforACK = false;
|
||||
timeout_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*all msg
|
||||
|
||||
MAVLINK_MSG_ID_COMMAND_INT
|
||||
MAVLINK_MSG_ID_COMMAND_LONG
|
||||
MAVLINK_MSG_ID_COMMAND_ACK
|
||||
*/
|
||||
|
||||
|
||||
void commandprocess::_int(float param1,
|
||||
float param2,
|
||||
float param3,
|
||||
float param4,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
float z,
|
||||
uint16_t command,
|
||||
uint8_t frame,
|
||||
uint8_t current,
|
||||
uint8_t autocontinue)
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_command_int_t command_int;
|
||||
|
||||
command_int.target_system = sysid;
|
||||
command_int.target_component = compid;
|
||||
|
||||
|
||||
command_int.param1 = param1;
|
||||
command_int.param2 = param2;
|
||||
command_int.param3 = param3;
|
||||
command_int.param4 = param4;
|
||||
command_int.x = x;
|
||||
command_int.y = y;
|
||||
command_int.z = z;
|
||||
command_int.command = command;
|
||||
command_int.frame. = frame;
|
||||
command_int.current = current;
|
||||
command_int.autocontinue = autocontinue;
|
||||
|
||||
mavlink_msg_command_int_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,&command_int);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void commandprocess::_long(float param1,
|
||||
float param2,
|
||||
float param3,
|
||||
float param4,
|
||||
float param5,
|
||||
float param6,
|
||||
float param7,
|
||||
uint16_t command,
|
||||
uint8_t confirmation)
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_command_long_t command_long;
|
||||
|
||||
command_long.target_system = sysid;
|
||||
command_long.target_component = compid;
|
||||
|
||||
command_long.param1 = param1;
|
||||
command_long.param2 = param2;
|
||||
command_long.param3 = param3;
|
||||
command_long.param4 = param4;
|
||||
command_long.param5 = param5;
|
||||
command_long.param6 = param6;
|
||||
command_long.param7 = param7;
|
||||
command_long.command = command;
|
||||
command_long.confirmation = confirmation;
|
||||
|
||||
mavlink_msg_command_long_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,&command_long);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
MAV_RESULT_ACCEPTED=0,
|
||||
MAV_RESULT_TEMPORARILY_REJECTED=1,
|
||||
MAV_RESULT_DENIED=2,
|
||||
MAV_RESULT_UNSUPPORTED=3,
|
||||
MAV_RESULT_FAILED=4,
|
||||
MAV_RESULT_IN_PROGRESS=5,
|
||||
**/
|
||||
|
||||
|
||||
void commandprocess::ack()//地面站几乎不可能放这个函数
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
#ifndef COMMANDPROCESS_H
|
||||
#define COMMANDPROCESS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "QDebug"
|
||||
#include "QThread"
|
||||
#include "mavlink.h"
|
||||
#include "QTimer"
|
||||
#include "QTime"
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
class MAVLINKNODESHARED_EXPORT commandprocess : public QObject {
|
||||
#else
|
||||
class commandprocess : public QObject
|
||||
{
|
||||
#endif
|
||||
Q_OBJECT
|
||||
|
||||
enum _modetype {
|
||||
Nop_Mode = 0,
|
||||
RecieveMode,
|
||||
TransmitMode
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
//bool isWaitingforCount;
|
||||
bool isWaitingforValue;
|
||||
|
||||
|
||||
}_recieve;
|
||||
|
||||
typedef struct {
|
||||
bool isWaitingforACK;
|
||||
}_transmit;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
_recieve recieve;
|
||||
_transmit transmit;
|
||||
|
||||
|
||||
_modetype m_Mode;
|
||||
|
||||
}_command_;
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
explicit commandprocess(QObject *parent = nullptr);
|
||||
|
||||
_command_ status;
|
||||
|
||||
|
||||
public slots:
|
||||
//读取和写入指令
|
||||
//void ReadCmd(uint8_t m_sysid, uint8_t m_compid, uint8_t type);
|
||||
//void WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count);
|
||||
|
||||
|
||||
|
||||
//线程对外接口
|
||||
void setRunFrq(uint32_t frq);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
|
||||
void Parse(mavlink_message_t msg);
|
||||
|
||||
private slots:
|
||||
//线程私有接口
|
||||
void SendMessage(mavlink_message_t msg);
|
||||
|
||||
void process();
|
||||
|
||||
//状态机
|
||||
void ReadStateMachine(void);
|
||||
void WriteStateMachine(void);
|
||||
|
||||
|
||||
//所有相关函数
|
||||
void _int(float param1,
|
||||
float param2,
|
||||
float param3,
|
||||
float param4,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
float z, uint16_t command, uint8_t frame, uint8_t current, uint8_t autocontinue);
|
||||
void _long(float param1,
|
||||
float param2,
|
||||
float param3,
|
||||
float param4,
|
||||
float param5,
|
||||
float param6,
|
||||
float param7,
|
||||
uint16_t command,
|
||||
uint8_t confirmation);
|
||||
void ack();
|
||||
|
||||
|
||||
signals:
|
||||
void readError();
|
||||
|
||||
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
||||
|
||||
|
||||
private:
|
||||
bool running_flag = false;
|
||||
quint32 running_frq = 200;//200Hz
|
||||
QThread *thread = nullptr;
|
||||
|
||||
//目标id
|
||||
uint8_t sysid;
|
||||
uint8_t compid;
|
||||
|
||||
mavlink_command_int_t command_int;
|
||||
mavlink_command_long_t command_long;
|
||||
mavlink_command_ack_t command_ack;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMANDPROCESS_H
|
||||
@@ -1,5 +1,12 @@
|
||||
#include "mavlinknode.h"
|
||||
|
||||
/*
|
||||
* mavlink 解析相关内容请参考如下
|
||||
* https://mavlink.io/en/services/command.html
|
||||
* 包含了各个函数、参数、状态机等及其说明
|
||||
**/
|
||||
|
||||
|
||||
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//main thread
|
||||
@@ -12,24 +19,23 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
initbuff();
|
||||
|
||||
Mission = new MissionProcess();
|
||||
/*connect(Mission,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)));*/
|
||||
connect(Mission,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
|
||||
Parameter = new ParameterProcess();
|
||||
|
||||
/*
|
||||
connect(Parameter,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)));*/
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
|
||||
Commander = new commandprocess();
|
||||
connect(Commander,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
/*
|
||||
connect(Parameter,&ParameterProcess::SendMessageTo,
|
||||
this,&MavLinkNode::SendMessageTo);*/
|
||||
|
||||
|
||||
|
||||
mavlinkinspector = new MAVLinkInspector("mavlink inspector",nullptr,nullptr);
|
||||
|
||||
connect(this,SIGNAL(recievemsg(mavlink_message_t)),
|
||||
mavlinkinspector,SLOT(receiveMessage(mavlink_message_t)),Qt::DirectConnection);
|
||||
|
||||
@@ -47,6 +53,10 @@ MavLinkNode::~MavLinkNode()
|
||||
delete Parameter;
|
||||
Parameter = nullptr;
|
||||
|
||||
Commander->stop();
|
||||
delete Commander;
|
||||
Commander = nullptr;
|
||||
|
||||
if(Nodethread->isRunning())
|
||||
{
|
||||
Nodethread->quit();
|
||||
@@ -157,7 +167,7 @@ void MavLinkNode::setbuff(quint32 src,QByteArray data)
|
||||
if(client_buff.buff[client_buff.select].size() >= client_buff.max_size)
|
||||
{
|
||||
client_buff.buff[client_buff.select].clear();
|
||||
qDebug() << "client_buff.buff" << client_buff.select << "OVERFLOW";
|
||||
qDebug() << "client_buff.buff " << client_buff.select <<" OVERFLOW";
|
||||
}
|
||||
client_buff.buff[client_buff.select].append(data);
|
||||
|
||||
@@ -167,7 +177,7 @@ void MavLinkNode::setbuff(quint32 src,QByteArray data)
|
||||
if(serial_buff.buff[serial_buff.select].size() >= serial_buff.max_size)
|
||||
{
|
||||
serial_buff.buff[serial_buff.select].clear();
|
||||
qDebug() << "serial_buff.buff" << client_buff.select << "OVERFLOW";
|
||||
qDebug() << "serial_buff.buff " << serial_buff.select <<" OVERFLOW";
|
||||
}
|
||||
serial_buff.buff[serial_buff.select].append(data);
|
||||
break;
|
||||
@@ -336,7 +346,7 @@ void MavLinkNode::MAVLinkRcv_Handler(mavlink_message_t msg)
|
||||
case MAVLINK_MSG_ID_MISSION_REQUEST_PARTIAL_LIST:
|
||||
case MAVLINK_MSG_ID_MISSION_WRITE_PARTIAL_LIST:
|
||||
|
||||
Mission->MissionParse(msg);
|
||||
Mission->Parse(msg);
|
||||
break;
|
||||
|
||||
//参数
|
||||
@@ -344,12 +354,14 @@ void MavLinkNode::MAVLinkRcv_Handler(mavlink_message_t msg)
|
||||
case MAVLINK_MSG_ID_PARAM_REQUEST_READ:
|
||||
case MAVLINK_MSG_ID_PARAM_SET:
|
||||
case MAVLINK_MSG_ID_PARAM_VALUE:
|
||||
Parameter->ParameterParse(msg);
|
||||
Parameter->Parse(msg);
|
||||
break;
|
||||
|
||||
//命令
|
||||
case MAVLINK_MSG_ID_COMMAND_INT:
|
||||
case MAVLINK_MSG_ID_COMMAND_LONG:
|
||||
case MAVLINK_MSG_ID_COMMAND_ACK:
|
||||
CommandParse(msg);
|
||||
Commander->Parse(msg);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "mavlink.h"
|
||||
#include "missionprocess.h"
|
||||
#include "parameterprocess.h"
|
||||
|
||||
#include "commandprocess.h"
|
||||
|
||||
#include "MAVLinkInspector/MAVLinkInspector.h"
|
||||
|
||||
@@ -53,7 +53,7 @@ class MavLinkNode : public QObject
|
||||
mavlink_enginestate_t enginestate;
|
||||
mavlink_vfr_hud_t vfr_hud;
|
||||
|
||||
mavlink_command_int_t command_int;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public:
|
||||
_vehicle vehicle;
|
||||
MissionProcess *Mission;
|
||||
ParameterProcess *Parameter;
|
||||
commandprocess *Commander;
|
||||
|
||||
MAVLinkInspector *mavlinkinspector = nullptr;
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void MissionProcess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count
|
||||
|
||||
|
||||
//这个函数类似中断,专门处理接收到的状态
|
||||
void MissionProcess::MissionParse(mavlink_message_t msg)
|
||||
void MissionProcess::Parse(mavlink_message_t msg)
|
||||
{
|
||||
switch (msg.msgid) {
|
||||
case MAVLINK_MSG_ID_MISSION_REQUEST_LIST: {
|
||||
|
||||
@@ -61,7 +61,7 @@ public slots:
|
||||
void stop();
|
||||
|
||||
|
||||
void MissionParse(mavlink_message_t msg);
|
||||
void Parse(mavlink_message_t msg);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void ParameterProcess::setRunFrq(uint32_t frq)
|
||||
if((frq != 0)||(frq <= 1000))
|
||||
{
|
||||
running_frq = frq;
|
||||
qDebug() << "set thread running frquency:" <<frq <<"Hz";
|
||||
qDebug() << "set parameter thread running frquency:" <<frq <<"Hz";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,8 @@ void ParameterProcess::ReadCmd(uint8_t m_sysid, uint8_t m_compid,uint8_t type)
|
||||
|
||||
void ParameterProcess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count )
|
||||
{
|
||||
Q_UNUSED(count);
|
||||
|
||||
sysid = m_sysid;
|
||||
compid = m_compid;
|
||||
//mission_status.transmit.count = count;
|
||||
@@ -145,7 +147,7 @@ void ParameterProcess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t coun
|
||||
|
||||
|
||||
//这个函数类似中断,专门处理接收到的状态
|
||||
void ParameterProcess::ParameterParse(mavlink_message_t msg)
|
||||
void ParameterProcess::Parse(mavlink_message_t msg)
|
||||
{
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public slots:
|
||||
void stop();
|
||||
|
||||
|
||||
void ParameterParse(mavlink_message_t msg);
|
||||
void Parse(mavlink_message_t msg);
|
||||
|
||||
private slots:
|
||||
//线程私有接口
|
||||
@@ -111,10 +111,12 @@ signals:
|
||||
|
||||
|
||||
private:
|
||||
//线程运行参数
|
||||
bool running_flag = false;
|
||||
quint32 running_frq = 200;//200Hz
|
||||
QThread *thread = nullptr;
|
||||
|
||||
//目标id
|
||||
uint8_t sysid;
|
||||
uint8_t compid;
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<RCC>
|
||||
<qresource prefix="/BlueType">
|
||||
<file>images/dlink.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/LinkUI/Emergency.ico</file>
|
||||
<file>images/LinkUI/exit.ico</file>
|
||||
<file>images/LinkUI/Fet.ico</file>
|
||||
<file>images/LinkUI/SerialPort.ico</file>
|
||||
<file>images/LinkUI/Client.ico</file>
|
||||
<file>images/LinkUI/params.ico</file>
|
||||
<file>images/LinkUI/plane.ico</file>
|
||||
<file>images/LinkUI/Remote.ico</file>
|
||||
<file>images/LinkUI/rtk.ico</file>
|
||||
<file>images/LinkUI/WindowsQGC.ico</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 121 KiB |
@@ -9,16 +9,14 @@ DLink::DLink(QObject *parent) : QObject(parent)
|
||||
{
|
||||
qDebug() << "Dlink " << QThread::currentThreadId();
|
||||
|
||||
//采用插件导入的方式(plugin)
|
||||
|
||||
//mavlink协议节点
|
||||
mavlinknode = new MavLinkNode();//不允许带参数,因为这是单独的线程
|
||||
/*connect(mavlinknode,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SLOT(SendMessageTo(quint8,quint8*,quint16)));*/
|
||||
connect(mavlinknode,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SLOT(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);//采用直连的方式,因为是多线程
|
||||
|
||||
|
||||
connect(mavlinknode->Mission,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SLOT(SendMessageTo(quint8,quint8*,quint16)));
|
||||
|
||||
connect(mavlinknode->Parameter,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SLOT(SendMessageTo(quint8,quint8*,quint16)));
|
||||
//其他协议节点。。。
|
||||
|
||||
}
|
||||
DLink::~DLink()
|
||||
@@ -45,6 +43,8 @@ int DLink::SendMessageTo(quint8 ch, quint8 *msg, quint16 len)
|
||||
if (DLink::serialPort)
|
||||
{
|
||||
DLink::serialPort->write((const char *)msg,len);
|
||||
//qDebug() << "serialPort Send Msg" << msg;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -54,7 +54,7 @@ int DLink::SendMessageTo(quint8 ch, quint8 *msg, quint16 len)
|
||||
|
||||
void DLink::setupPort(const QString port, qint32 baudrate, QSerialPort::Parity parity)
|
||||
{
|
||||
if (serialPort)
|
||||
if (serialPort)//多串口接入
|
||||
{
|
||||
serialPort->close();
|
||||
delete serialPort;
|
||||
@@ -72,8 +72,6 @@ void DLink::setupPort(const QString port, qint32 baudrate, QSerialPort::Parity p
|
||||
|
||||
connect(serialPort, SIGNAL(readyRead()), this, SLOT(readPendingDatagramsSerialPort()));
|
||||
|
||||
|
||||
|
||||
qDebug() << "Serial Port Open Success";
|
||||
}
|
||||
else
|
||||
|
||||