no message
parent
7619a0cefc
commit
a28c997ac8
28
README.md
28
README.md
|
@ -8,15 +8,35 @@
|
||||||
- tcp服务端模式(仅支持单链接)
|
- tcp服务端模式(仅支持单链接)
|
||||||
- udp
|
- udp
|
||||||
|
|
||||||
#### 软件功能
|
### 软件功能
|
||||||
功能示意图如下:</br>
|
功能示意图如下:</br>
|
||||||
|
|
||||||
![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/000884f1-a057-11eb-a166-525400dc6cec.png)
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
串口配置:</br>
|
#### 串口配置:</br>
|
||||||
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png)
|
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png)
|
||||||
|
#### 网络配置
|
||||||
|
|
||||||
lua脚本调试</br>
|
#### lua脚本调试</br>
|
||||||
![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png)
|
![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png)</br>
|
||||||
|
lua代码例子:
|
||||||
|
```
|
||||||
|
require("string")
|
||||||
|
|
||||||
|
function OnDataReady(data) # 接收串口数据回调
|
||||||
|
showbuffer(data)
|
||||||
|
serial_send(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
function OnNetworkData(addr,data,len) # 接收网络数据回调
|
||||||
|
showbuffer(addr)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
serial_send("test") # 在脚本中主动发送串口数据
|
||||||
|
|
||||||
|
```
|
|
@ -32,11 +32,11 @@ Item {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Row{
|
Row{
|
||||||
|
Layout.topMargin: 20
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Label {
|
Label {
|
||||||
id: label6
|
id: label6
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Layout.topMargin: 20
|
|
||||||
text: qsTr("打开端口: ")
|
text: qsTr("打开端口: ")
|
||||||
Layout.preferredHeight: 40
|
Layout.preferredHeight: 40
|
||||||
renderType: Text.QtRendering
|
renderType: Text.QtRendering
|
||||||
|
@ -47,7 +47,6 @@ Item {
|
||||||
TextEdit {
|
TextEdit {
|
||||||
id: port
|
id: port
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Layout.topMargin: 30
|
|
||||||
width: 80
|
width: 80
|
||||||
height: 40
|
height: 40
|
||||||
text: qsTr("9001")
|
text: qsTr("9001")
|
||||||
|
@ -58,7 +57,6 @@ Item {
|
||||||
RadioButton {
|
RadioButton {
|
||||||
id: isServer
|
id: isServer
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Layout.topMargin: 20
|
|
||||||
width: 138
|
width: 138
|
||||||
height: 41
|
height: 41
|
||||||
text: qsTr("服务端")
|
text: qsTr("服务端")
|
||||||
|
@ -79,12 +77,13 @@ Item {
|
||||||
RowLayout{
|
RowLayout{
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Row{
|
Row{
|
||||||
|
Layout.topMargin: 20
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Label {
|
Label {
|
||||||
id: label7
|
id: label7
|
||||||
Layout.leftMargin: 20
|
Layout.leftMargin: 20
|
||||||
Layout.topMargin: 20
|
Layout.topMargin: 20
|
||||||
text: qsTr("协议选择: ")
|
text: qsTr("协议选择:")
|
||||||
Layout.preferredHeight: 40
|
Layout.preferredHeight: 40
|
||||||
renderType: Text.QtRendering
|
renderType: Text.QtRendering
|
||||||
Layout.preferredWidth: 125
|
Layout.preferredWidth: 125
|
||||||
|
|
|
@ -83,7 +83,7 @@ LuaDelegate::LuaDelegate():
|
||||||
}
|
}
|
||||||
luaL_openlibs(mVM); //打开标准库
|
luaL_openlibs(mVM); //打开标准库
|
||||||
lua_register(mVM, "showbuffer", LuaShowData);
|
lua_register(mVM, "showbuffer", LuaShowData);
|
||||||
lua_register(mVM, "resp", LuaWriteUart);
|
lua_register(mVM, "serial_send", LuaWriteUart);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ NetworkController::NetworkController(NetworkController::NetworkType type,
|
||||||
uint16_t port):mTcp(nullptr),
|
uint16_t port):mTcp(nullptr),
|
||||||
mUDP(nullptr),
|
mUDP(nullptr),
|
||||||
mTcpServer(nullptr),
|
mTcpServer(nullptr),
|
||||||
mCnn(nullptr)
|
mCnn(nullptr),
|
||||||
|
mState(false)
|
||||||
{
|
{
|
||||||
mType = type;
|
mType = type;
|
||||||
if(_checkType(type) == TYPE_UNKOWN){
|
if(_checkType(type) == TYPE_UNKOWN){
|
||||||
|
@ -25,10 +26,11 @@ 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);
|
||||||
|
if(mTcp->state() == QAbstractSocket::ConnectedState)
|
||||||
|
mState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == NetworkType::TYPE_TCP_SERVER){
|
if(type == NetworkType::TYPE_TCP_SERVER){
|
||||||
|
|
||||||
mTcpServer = new QTcpServer();
|
mTcpServer = new QTcpServer();
|
||||||
connect(mTcpServer,SIGNAL(newConnection()),
|
connect(mTcpServer,SIGNAL(newConnection()),
|
||||||
this,SLOT(on_server_accept()));
|
this,SLOT(on_server_accept()));
|
||||||
|
@ -47,6 +49,7 @@ NetworkController::NetworkController(NetworkController::NetworkType type,
|
||||||
connect(mUDP, SIGNAL(readyRead()),
|
connect(mUDP, SIGNAL(readyRead()),
|
||||||
this, SLOT(on_ready_read()));
|
this, SLOT(on_ready_read()));
|
||||||
mUDP->open(QIODevice::ReadWrite);
|
mUDP->open(QIODevice::ReadWrite);
|
||||||
|
mState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,6 +97,7 @@ int NetworkController::Close()
|
||||||
if(mType == TYPE_TCP_CLIENT){
|
if(mType == TYPE_TCP_CLIENT){
|
||||||
mCnn->close();
|
mCnn->close();
|
||||||
}
|
}
|
||||||
|
mState = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +139,7 @@ void NetworkController::on_server_accept()
|
||||||
}
|
}
|
||||||
mTcp = pClientConnection;
|
mTcp = pClientConnection;
|
||||||
mCnn = mTcp;
|
mCnn = mTcp;
|
||||||
qDebug()<<"on_server_accept";
|
mState = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
QTcpServer *mTcpServer;
|
QTcpServer *mTcpServer;
|
||||||
QIODevice *mCnn;
|
QIODevice *mCnn;
|
||||||
QThread mThread;
|
QThread mThread;
|
||||||
|
bool mState;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORK_CONTROLLER_H
|
#endif // NETWORK_CONTROLLER_H
|
||||||
|
|
Loading…
Reference in New Issue