From a28c997ac8f6ddae63dee345d5c3bdbc55a0fd8a Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Mon, 3 May 2021 23:07:13 +0800 Subject: [PATCH] no message --- README.md | 28 ++++++++++++++++++++++++---- protoDebuger/NetSelect.qml | 7 +++---- protoDebuger/lua_wraper.cpp | 2 +- protoDebuger/network_controller.cpp | 10 +++++++--- protoDebuger/network_controller.h | 1 + 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 84e0ed9..940f0af 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,35 @@ - tcp服务端模式(仅支持单链接) - udp -#### 软件功能 +### 软件功能 功能示意图如下:
![image.png](https://www.testingcloud.club/sapi/api/image_download/000884f1-a057-11eb-a166-525400dc6cec.png)
-串口配置:
+#### 串口配置:
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png) +#### 网络配置 -lua脚本调试
-![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png) \ No newline at end of file +#### lua脚本调试
+![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png)
+lua代码例子: +``` +require("string") + +function OnDataReady(data) # 接收串口数据回调 + showbuffer(data) + serial_send(data) +end + +function OnNetworkData(addr,data,len) # 接收网络数据回调 + showbuffer(addr) +end + + + + +serial_send("test") # 在脚本中主动发送串口数据 + +``` \ No newline at end of file diff --git a/protoDebuger/NetSelect.qml b/protoDebuger/NetSelect.qml index 5bd8ffd..4201839 100644 --- a/protoDebuger/NetSelect.qml +++ b/protoDebuger/NetSelect.qml @@ -32,11 +32,11 @@ Item { RowLayout { spacing: 5 Row{ + Layout.topMargin: 20 Layout.leftMargin: 20 Label { id: label6 Layout.leftMargin: 20 - Layout.topMargin: 20 text: qsTr("打开端口: ") Layout.preferredHeight: 40 renderType: Text.QtRendering @@ -47,7 +47,6 @@ Item { TextEdit { id: port Layout.leftMargin: 20 - Layout.topMargin: 30 width: 80 height: 40 text: qsTr("9001") @@ -58,7 +57,6 @@ Item { RadioButton { id: isServer Layout.leftMargin: 20 - Layout.topMargin: 20 width: 138 height: 41 text: qsTr("服务端") @@ -79,12 +77,13 @@ Item { RowLayout{ spacing: 5 Row{ + Layout.topMargin: 20 Layout.leftMargin: 20 Label { id: label7 Layout.leftMargin: 20 Layout.topMargin: 20 - text: qsTr("协议选择: ") + text: qsTr("协议选择:") Layout.preferredHeight: 40 renderType: Text.QtRendering Layout.preferredWidth: 125 diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp index ac78462..ca888b8 100644 --- a/protoDebuger/lua_wraper.cpp +++ b/protoDebuger/lua_wraper.cpp @@ -83,7 +83,7 @@ LuaDelegate::LuaDelegate(): } luaL_openlibs(mVM); //打开标准库 lua_register(mVM, "showbuffer", LuaShowData); - lua_register(mVM, "resp", LuaWriteUart); + lua_register(mVM, "serial_send", LuaWriteUart); } diff --git a/protoDebuger/network_controller.cpp b/protoDebuger/network_controller.cpp index cbab364..b703efd 100644 --- a/protoDebuger/network_controller.cpp +++ b/protoDebuger/network_controller.cpp @@ -11,7 +11,8 @@ NetworkController::NetworkController(NetworkController::NetworkType type, uint16_t port):mTcp(nullptr), mUDP(nullptr), mTcpServer(nullptr), - mCnn(nullptr) + mCnn(nullptr), + mState(false) { mType = type; if(_checkType(type) == TYPE_UNKOWN){ @@ -25,10 +26,11 @@ NetworkController::NetworkController(NetworkController::NetworkType type, QObject::connect(mTcp, SIGNAL(disconnected()), this, SLOT(on_disconect())); mTcp->connectToHost(ip,port,QIODevice::ReadWrite); + if(mTcp->state() == QAbstractSocket::ConnectedState) + mState = true; } if(type == NetworkType::TYPE_TCP_SERVER){ - mTcpServer = new QTcpServer(); connect(mTcpServer,SIGNAL(newConnection()), this,SLOT(on_server_accept())); @@ -47,6 +49,7 @@ NetworkController::NetworkController(NetworkController::NetworkType type, connect(mUDP, SIGNAL(readyRead()), this, SLOT(on_ready_read())); mUDP->open(QIODevice::ReadWrite); + mState = true; } } @@ -94,6 +97,7 @@ int NetworkController::Close() if(mType == TYPE_TCP_CLIENT){ mCnn->close(); } + mState = false; return 0; } @@ -135,7 +139,7 @@ void NetworkController::on_server_accept() } mTcp = pClientConnection; mCnn = mTcp; - qDebug()<<"on_server_accept"; + mState = true; } } diff --git a/protoDebuger/network_controller.h b/protoDebuger/network_controller.h index 919bd76..c4cb7d3 100644 --- a/protoDebuger/network_controller.h +++ b/protoDebuger/network_controller.h @@ -53,6 +53,7 @@ private: QTcpServer *mTcpServer; QIODevice *mCnn; QThread mThread; + bool mState; }; #endif // NETWORK_CONTROLLER_H