添加tcp集群调试功能

master
zcy 2021-07-01 00:50:13 +08:00
parent fa170df052
commit e0db9e869e
7 changed files with 225 additions and 4 deletions

View File

@ -83,7 +83,7 @@ Item {
id: label7 id: label7
Layout.leftMargin: 20 Layout.leftMargin: 20
Layout.topMargin: 20 Layout.topMargin: 20
text: qsTr("协议选择:") text: "协议选择:"
Layout.preferredHeight: 40 Layout.preferredHeight: 40
renderType: Text.QtRendering renderType: Text.QtRendering
Layout.preferredWidth: 125 Layout.preferredWidth: 125

175
protoDebuger/TcpSwarm.qml Normal file
View File

@ -0,0 +1,175 @@
import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.0
Item {
objectName: "TcpSwarm"
width: 800
height: 600
property var comlist: []
visible: true
property bool uart_open: false
property var showbuf: ""
property var lua_script_text: ""
ColorAnimation {
from: "white"
to: "black"
duration: 200
}
Rectangle{
color: "#aeaeae"
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
scale: 1
transformOrigin: Item.Center
GridLayout {
width: parent.width
height: parent.height
x: 0
y: 0
rows: 3
columns: 2
Label {
id: label
text: qsTr("lua脚本:")
Layout.columnSpan: 1
font.pixelSize: 30
font.bold: true
}
Label {
id: label2
text: qsTr("输出:")
Layout.columnSpan: 1
font.pixelSize: 30
font.bold: true
}
Flickable {
id: flick
Layout.preferredHeight: parent.height - 100
Layout.preferredWidth: parent.width/2 - 20
Layout.columnSpan: 1
contentWidth: lua_script.paintedWidth
contentHeight: lua_script.paintedHeight
clip: true
Layout.leftMargin: 10
ColorAnimation {
from: "white"
to: "white"
duration: 200
}
function ensureVisible(r)
{
if (contentX >= r.x)
contentX = r.x;
else if (contentX+width <= r.x+r.width)
contentX = r.x+r.width-width;
if (contentY >= r.y)
contentY = r.y;
else if (contentY+height <= r.y+r.height)
contentY = r.y+r.height-height;
}
TextEdit {
id: lua_script
focus: true
text: lua_script_text
font.pixelSize: 20
color: "red"
selectByMouse : true
wrapMode: TextEdit.Wrap
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
}
}
TextArea {
id: text_output
Layout.preferredHeight: parent.height - 100
text: qsTr("")
font.pixelSize: 20
Layout.columnSpan: 1
Layout.preferredWidth: parent.width/2 - 20
background: Rectangle {
border.color: text_output.enabled ? "#21be2b" : "transparent"
}
Layout.leftMargin: 10
}
RowLayout{
visible: true
Layout.columnSpan: 2
Button {
id: button2
text: qsTr("保存lua脚本")
Layout.preferredHeight: 41
Layout.preferredWidth: 116
Layout.leftMargin: 15
Layout.bottomMargin: 10
onClicked: {
lua_script_text = lua_script.text
let ret = DataWrap.saveLuaScript(lua_script_text)
console.log(ret)
if(ret != 0){
tip.text = "保存lua脚本失败"
tip.visible = true
return
}
tip.text = "保存lua脚本成功"
tip.visible = true
}
}
Button {
id: button
text: qsTr("更新lua脚本")
Layout.preferredHeight: 41
Layout.preferredWidth: 116
Layout.bottomMargin: 10
onClicked: {
lua_script_text = lua_script.text
let ret = DataWrap.updateLuaScript(lua_script_text)
if(ret != 0){
tip.text = "更新lua脚本失败"
tip.visible = true
return
}
tip.text = "更新lua脚本成功"
tip.visible = true
}
}
}
}
}
ToolTip {
id: tip
text: qsTr("")
visible: false
contentItem: Text {
text: tip.text
font: tip.font
color: "#21be2b"
}
background: Rectangle {
border.color: "#21be2b"
}
delay: 100
timeout: 1000
}
function addString(str){
showbuf += str;
text_output.text = showbuf;
}
}

View File

@ -16,10 +16,11 @@
ShareData gGlobal; ShareData gGlobal;
#define test1 293
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qDebug()<<test1;
QApplication app(argc, argv); QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

View File

@ -51,6 +51,8 @@ Rectangle {
color: "white" color: "white"
font.pointSize: 10 font.pointSize: 10
anchors.top: btn_serial.bottom anchors.top: btn_serial.bottom
leftPadding: 13
} }
Button{ Button{
id: button_net id: button_net
@ -77,6 +79,8 @@ Rectangle {
color: "white" color: "white"
font.pointSize: 10 font.pointSize: 10
anchors.top: button_net.bottom anchors.top: button_net.bottom
leftPadding: 13
} }
Button{ Button{
id: button_proto id: button_proto
@ -102,6 +106,35 @@ Rectangle {
color: "white" color: "white"
font.pointSize: 10 font.pointSize: 10
anchors.top: button_proto.bottom anchors.top: button_proto.bottom
leftPadding: 13
}
Button{
id: button_tcp_swarm
width: parent.width
height:60
anchors.top: label_proto.bottom
onClicked: {
uart_choose.visible = false
net_choose.visible = false
proto_debug.visible = false
tcp_swarm.visible = true
DataWrap.getValFromQml(1)
}
background: Image {
anchors.fill: parent
source: "qrc:///res/proto.svg"
}
}
Text {
id: label_button_tcp_swarm
text: qsTr("tcp集群")
width: parent.width
color: "white"
font.pointSize: 10
anchors.top: button_tcp_swarm.bottom
leftPadding: 13
} }
Text { Text {
@ -135,6 +168,12 @@ Rectangle {
height: parent.height height: parent.height
visible: false visible: false
} }
TcpSwarm{
id: tcp_swarm
width: parent.width - 100
height: parent.height
visible: false
}
} }
} }

View File

@ -26,6 +26,7 @@ NetworkController::NetworkController(NetworkController::NetworkType type,
QObject::connect(mTcp, SIGNAL(disconnected()), this, SLOT(on_disconect())); QObject::connect(mTcp, SIGNAL(disconnected()), this, SLOT(on_disconect()));
mTcp->connectToHost(ip,port,QIODevice::ReadWrite); mTcp->connectToHost(ip,port,QIODevice::ReadWrite);
qDebug()<<mTcp->state();
if(mTcp->state() == QAbstractSocket::ConnectedState) if(mTcp->state() == QAbstractSocket::ConnectedState)
mState = true; mState = true;
} }
@ -95,7 +96,12 @@ int NetworkController::Close()
delete mCnn; delete mCnn;
} }
if(mType == TYPE_TCP_CLIENT){ if(mType == TYPE_TCP_CLIENT){
mCnn->close(); qDebug()<<(((QTcpSocket*)mTcp)->state());
qDebug()<<"disconnected"<<mTcp->bytesAvailable()<<mCnn->bytesToWrite();
((QTcpSocket*)mTcp)->disconnectFromHost();
if(((QTcpSocket*)mTcp)->waitForDisconnected(3000));
mTcp->close();
delete mTcp;
} }
mState = false; mState = false;
return 0; return 0;

View File

@ -7,5 +7,6 @@
<file>SerialSelect.qml</file> <file>SerialSelect.qml</file>
<file>NetSelect.qml</file> <file>NetSelect.qml</file>
<file>ProtoDebug.qml</file> <file>ProtoDebug.qml</file>
<file>TcpSwarm.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -33,7 +33,6 @@ public:
int SendUartData(const char *); int SendUartData(const char *);
Q_INVOKABLE void getValFromQml(int v) { Q_INVOKABLE void getValFromQml(int v) {
qDebug() << "value from qml is :" << v;
emit valueFromCpp(456); emit valueFromCpp(456);
} }