添加协议显示界面,添加指令传输和json
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"comment": "Any Firmware, Any Vehicle",
|
||||
|
||||
"version": 1,
|
||||
|
||||
"CommandButton": [
|
||||
{
|
||||
"Name" : "关机",
|
||||
"row": 0,
|
||||
"column": 0,
|
||||
"param1": 1,
|
||||
"param2": 2,
|
||||
"param3": 3,
|
||||
"param4": 4,
|
||||
"param5": 5,
|
||||
"param6": 6,
|
||||
"param7": 7
|
||||
},
|
||||
{
|
||||
"Name" : "起飞",
|
||||
"row": 1,
|
||||
"column": 1,
|
||||
"param1": 7,
|
||||
"param2": 6,
|
||||
"param3": 5,
|
||||
"param4": 4,
|
||||
"param5": 3,
|
||||
"param6": 2,
|
||||
"param7": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
+168
-2
@@ -1,6 +1,28 @@
|
||||
#include "CommandUI.h"
|
||||
#include "ui_CommandUI.h"
|
||||
|
||||
|
||||
const char* CommandUI::_versionJsonKey = "version";
|
||||
const char* CommandUI::_commentJsonKey = "comment";
|
||||
const char* CommandUI::_CommandButtonJsonKey = "CommandButton";
|
||||
|
||||
const char* CommandUI::_NameJsonKey = "Name";
|
||||
const char* CommandUI::_rowJsonKey = "row";
|
||||
const char* CommandUI::_columnJsonKey = "column";
|
||||
|
||||
const char* CommandUI::_param1JsonKey = "param1";
|
||||
const char* CommandUI::_param2JsonKey = "param2";
|
||||
const char* CommandUI::_param3JsonKey = "param3";
|
||||
const char* CommandUI::_param4JsonKey = "param4";
|
||||
const char* CommandUI::_param5JsonKey = "param5";
|
||||
const char* CommandUI::_param6JsonKey = "param6";
|
||||
const char* CommandUI::_param7JsonKey = "param7";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CommandUI::CommandUI(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::CommandUI)
|
||||
@@ -16,11 +38,37 @@ CommandUI::CommandUI(QWidget *parent) :
|
||||
file.close();
|
||||
|
||||
|
||||
//load json
|
||||
|
||||
//载入json
|
||||
loadCommandJson(":/json/Command.json");
|
||||
|
||||
for(QJsonValue info: CMD_infoArray) {
|
||||
if (!info.isObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPushButton *btn = new QPushButton(ui->groupBox_Command);
|
||||
|
||||
btn->setText(info.toObject().find(_NameJsonKey).value().toString());
|
||||
|
||||
btn->setFixedSize(60,60);
|
||||
|
||||
/*
|
||||
btn->setGeometry(10 + info.toObject().find(_rowJsonKey).value().toInt() * 70,
|
||||
10 + info.toObject().find(_columnJsonKey).value().toInt() * 70,
|
||||
60,60);
|
||||
*/
|
||||
|
||||
ui->gridLayout_Command->addWidget(btn,
|
||||
info.toObject().find(_rowJsonKey).value().toInt(),
|
||||
info.toObject().find(_columnJsonKey).value().toInt());
|
||||
|
||||
|
||||
connect(btn,SIGNAL(clicked(bool)),
|
||||
this,SLOT(on_commandClicked()));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,3 +76,121 @@ CommandUI::~CommandUI()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CommandUI::loadCommandJson(const QString& jsonFilename)
|
||||
{
|
||||
if (jsonFilename.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Loading " << jsonFilename;
|
||||
|
||||
QFile jsonFile(jsonFilename);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Unable to open file" << jsonFilename << jsonFile.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray bytes = jsonFile.readAll();
|
||||
|
||||
jsonFile.close();
|
||||
QJsonParseError jsonParseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError);
|
||||
if (jsonParseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << jsonFilename << "Unable to open json document" << jsonParseError.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
int version = json.value(_versionJsonKey).toInt();
|
||||
qDebug() << "command version :" << version;
|
||||
|
||||
/*
|
||||
if (version != 1) {
|
||||
qWarning() << jsonFilename << "Invalid version" << version;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
QJsonValue jsonValue = json.value(_CommandButtonJsonKey);
|
||||
|
||||
if (!jsonValue.isArray()) {
|
||||
qWarning() << jsonFilename << "_CommandButtonJsonKey not array";
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate over MissionCommandUIInfo objects
|
||||
CMD_infoArray = jsonValue.toArray();
|
||||
|
||||
qDebug() << CMD_infoArray;
|
||||
|
||||
for(QJsonValue info: CMD_infoArray) {
|
||||
if (!info.isObject()) {
|
||||
qWarning() << jsonFilename << "mavCmdArray should contain objects";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommandUI::on_commandClicked()
|
||||
{
|
||||
//找到消息的发送者
|
||||
QPushButton *btn = qobject_cast<QPushButton *>(sender());
|
||||
|
||||
for(QJsonValue info: CMD_infoArray) {
|
||||
if (!info.isObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//找到id或者名字一样的按键,找到参数,发出去
|
||||
|
||||
QString _name = info.toObject().find(_NameJsonKey).value().toString();
|
||||
QString _text = btn->text();
|
||||
|
||||
if(_name == _text)
|
||||
{
|
||||
float param1 = info.toObject().find(_param1JsonKey).value().toDouble();
|
||||
float param2 = info.toObject().find(_param2JsonKey).value().toDouble();
|
||||
float param3 = info.toObject().find(_param3JsonKey).value().toDouble();
|
||||
float param4 = info.toObject().find(_param4JsonKey).value().toDouble();
|
||||
float param5 = info.toObject().find(_param5JsonKey).value().toDouble();
|
||||
float param6 = info.toObject().find(_param6JsonKey).value().toDouble();
|
||||
float param7 = info.toObject().find(_param7JsonKey).value().toDouble();
|
||||
|
||||
|
||||
emit cmd_long(param1,param2, param3,param4,param5,param6,param7);
|
||||
|
||||
qDebug() << tr("clicked") << btn->text()
|
||||
<< param1
|
||||
<< param2
|
||||
<< param3
|
||||
<< param4
|
||||
<< param5
|
||||
<< param6
|
||||
<< param7;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
#include "QFile"
|
||||
#include "QDebug"
|
||||
|
||||
#include "QPushButton"
|
||||
|
||||
#include "QJsonArray"
|
||||
#include "QJsonDocument"
|
||||
#include "QJsonObject"
|
||||
#include "QJsonParseError"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class CommandUI;
|
||||
}
|
||||
@@ -17,8 +25,55 @@ public:
|
||||
explicit CommandUI(QWidget *parent = nullptr);
|
||||
~CommandUI();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void cmd_int(float param1, float param2, float param3, float param4, int x, int y, float z);
|
||||
void cmd_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
|
||||
|
||||
private slots:
|
||||
|
||||
void on_commandClicked();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void loadCommandJson(const QString& jsonFilename);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static const char* _versionJsonKey;
|
||||
static const char* _commentJsonKey;
|
||||
static const char* _CommandButtonJsonKey;
|
||||
|
||||
static const char* _NameJsonKey;
|
||||
static const char* _rowJsonKey;
|
||||
static const char* _columnJsonKey;
|
||||
|
||||
static const char* _param1JsonKey;
|
||||
static const char* _param2JsonKey;
|
||||
static const char* _param3JsonKey;
|
||||
static const char* _param4JsonKey;
|
||||
static const char* _param5JsonKey;
|
||||
static const char* _param6JsonKey;
|
||||
static const char* _param7JsonKey;
|
||||
|
||||
|
||||
QJsonArray CMD_infoArray;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Ui::CommandUI *ui;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMANDUI_H
|
||||
|
||||
@@ -13,13 +13,17 @@ FORMS += \
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/CommandUI.h \
|
||||
$$PWD/commandmsg.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/CommandUI.cpp \
|
||||
$$PWD/commandmsg.cpp
|
||||
|
||||
RESOURCES += \
|
||||
$$PWD/CommandUIres.qrc
|
||||
|
||||
DISTFILES +=
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+25
-148
@@ -15,15 +15,19 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<widget class="QGroupBox" name="groupBox_Status">
|
||||
<property name="title">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3"/>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_Status"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<widget class="QGroupBox" name="groupBox_Command">
|
||||
<property name="title">
|
||||
<string>Command</string>
|
||||
</property>
|
||||
@@ -41,160 +45,33 @@
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Research</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Navigate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="pushButton_8">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Attack</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout_Command"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="minimumSize">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Manual</string>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="minimumSize">
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Destroy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="pushButton_6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="pushButton_9">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="pushButton_7">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Kill</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pushButton_10">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TakeOff</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="pushButton_11">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>BackHome</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="pushButton_12">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
<qresource prefix="/qss">
|
||||
<file>CommandUI.qss</file>
|
||||
</qresource>
|
||||
<qresource prefix="/json">
|
||||
<file>Command.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "commandmsg.h"
|
||||
|
||||
CommandMsg::CommandMsg()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString CommandMsg::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
void CommandMsg::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
emit textChanged(m_text);
|
||||
}
|
||||
|
||||
|
||||
void CommandMsg::btnclicked_int(float param1, float param2, float param3, float param4, int x, int y, float z)
|
||||
{
|
||||
emit cmd_int(param1,param2,param3,param4,x,y,z);
|
||||
}
|
||||
void CommandMsg::btnclicked_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7)
|
||||
{
|
||||
emit cmd_long(param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef COMMANDMSG_H
|
||||
#define COMMANDMSG_H
|
||||
|
||||
#include <QObject>
|
||||
#include "QDebug"
|
||||
|
||||
class CommandMsg : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
public:
|
||||
CommandMsg();
|
||||
|
||||
QString text() const;
|
||||
void setText(const QString &text);
|
||||
|
||||
public slots:
|
||||
void btnclicked_int(float param1, float param2, float param3, float param4, int x, int y, float z);
|
||||
void btnclicked_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
|
||||
|
||||
signals:
|
||||
void textChanged(QString str);
|
||||
|
||||
|
||||
void cmd_int(float param1, float param2, float param3, float param4, int x, int y, float z);
|
||||
void cmd_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
|
||||
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMANDMSG_H
|
||||
Reference in New Issue
Block a user