no message
parent
7619a0cefc
commit
a28c997ac8
28
README.md
28
README.md
|
@ -8,15 +8,35 @@
|
|||
- tcp服务端模式(仅支持单链接)
|
||||
- udp
|
||||
|
||||
#### 软件功能
|
||||
### 软件功能
|
||||
功能示意图如下:</br>
|
||||
|
||||
![image.png](https://www.testingcloud.club/sapi/api/image_download/000884f1-a057-11eb-a166-525400dc6cec.png)
|
||||
|
||||
</br>
|
||||
|
||||
串口配置:</br>
|
||||
#### 串口配置:</br>
|
||||
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png)
|
||||
#### 网络配置
|
||||
|
||||
lua脚本调试</br>
|
||||
![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png)
|
||||
#### lua脚本调试</br>
|
||||
![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 {
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ private:
|
|||
QTcpServer *mTcpServer;
|
||||
QIODevice *mCnn;
|
||||
QThread mThread;
|
||||
bool mState;
|
||||
};
|
||||
|
||||
#endif // NETWORK_CONTROLLER_H
|
||||
|
|
Loading…
Reference in New Issue