no message

master
zcy 2021-05-03 02:02:25 +08:00
parent 4114dc8c70
commit 3e514bb131
9 changed files with 165 additions and 114 deletions

View File

@ -31,6 +31,8 @@ Item {
height: parent.height height: parent.height
RowLayout { RowLayout {
spacing: 5 spacing: 5
Row{
Layout.leftMargin: 20
Label { Label {
id: label6 id: label6
Layout.leftMargin: 20 Layout.leftMargin: 20
@ -45,20 +47,14 @@ Item {
TextEdit { TextEdit {
id: port id: port
Layout.leftMargin: 20 Layout.leftMargin: 20
Layout.topMargin: 20 Layout.topMargin: 30
width: 80 width: 80
height: 40 height: 40
text: qsTr("9001") text: qsTr("9001")
font.italic: false
font.bold: true
Layout.columnSpan: 2
Layout.preferredHeight: 33
Layout.preferredWidth: 50
selectionColor: "#f0f0f1" selectionColor: "#f0f0f1"
cursorVisible: true cursorVisible: true
font.pixelSize: 20 font.pixelSize: 18
} }
RadioButton { RadioButton {
id: isServer id: isServer
Layout.leftMargin: 20 Layout.leftMargin: 20
@ -79,8 +75,11 @@ Item {
} }
} }
} }
}
RowLayout{ RowLayout{
spacing: 5 spacing: 5
Row{
Layout.leftMargin: 20
Label { Label {
id: label7 id: label7
Layout.leftMargin: 20 Layout.leftMargin: 20
@ -104,6 +103,7 @@ Item {
"tcp" "tcp"
] ]
} }
RadioButton { RadioButton {
id: radioSelectWebsocket id: radioSelectWebsocket
Layout.leftMargin: 20 Layout.leftMargin: 20
@ -124,6 +124,7 @@ Item {
} }
} }
} }
}
RowLayout{ RowLayout{
spacing: 5 spacing: 5
@ -166,14 +167,6 @@ Item {
text: qsTr("打开网口") text: qsTr("打开网口")
onClicked: { onClicked: {
console.log(hostEdit.text)
// TYPE_UDP_SERVER = 0,
// TYPE_TCP_SERVER = 1,
// TYPE_UDP_CLIENT = 2,
// TYPE_TCP_CLIENT = 3,
// Q_INVOKABLE int openNetwork(QString ip,uint32_t port,bool is_ws,int type);
console.log(proto_combox.currentText)
let type_network = -1 let type_network = -1
if(proto_combox.currentText == "udp" && isServer.checked){ if(proto_combox.currentText == "udp" && isServer.checked){
type_network = 0 type_network = 0
@ -196,12 +189,11 @@ Item {
radioSelectWebsocket.checked, radioSelectWebsocket.checked,
type_network) type_network)
if(ret != 0){ if(ret != 0){
tip.text = "网络连接失败" tip.fail("网络连接失败")
tip.visible = true
return return
} }
tip.text = "网络连接成功" tip.success("网络连接成功")
tip.visible = true
} }
} }
@ -210,14 +202,31 @@ Item {
id: tip id: tip
text: qsTr("") text: qsTr("")
visible: false visible: false
font.pixelSize: 25
width: 220
contentItem: Text { contentItem: Text {
id : tip_item
text: tip.text text: tip.text
font: tip.font font: tip.font
color: "#21be2b" color: "#21be2b"
} }
background: Rectangle { background: Rectangle {
id: tip_background
border.color: "#21be2b" border.color: "#21be2b"
width: 220
height: 40
}
function success(str){
tip_item.color = "#21be2b"
tip.text = str
tip.visible = true
}
function fail(str){
tip_item.color = "#ff0000"
tip.text = str
tip.visible = true
} }
delay: 100 delay: 100
timeout: 1000 timeout: 1000

View File

@ -150,13 +150,6 @@ Item {
} }
TextEdit {
id: send_data
width: parent.width - 60
height: 30
text: qsTr("Text Edit")
font.pixelSize: 16
}
} }
} }
} }

View File

@ -201,8 +201,6 @@ Item {
uart_open = false uart_open = false
} }
} }
} }
} }
} }

View File

@ -23,13 +23,6 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// QQuickView view;
// view.setResizeMode(QQuickView::SizeRootObjectToView);
// view.setSource(QUrl("qrc:/main.qml"));
// view.setTitle ("多用途通信协议调试器,基于lua");
// view.rootContext()->setContextProperty("DataWrap",&gGlobal);
// view.show();
QQuickWidget *m_quickWidget=new QQuickWidget(); QQuickWidget *m_quickWidget=new QQuickWidget();
QUrl source("qrc:/main.qml"); QUrl source("qrc:/main.qml");
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView ); m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
@ -38,6 +31,5 @@ int main(int argc, char *argv[])
m_quickWidget->show(); m_quickWidget->show();
gGlobal.SetQuickView(m_quickWidget); gGlobal.SetQuickView(m_quickWidget);
return app.exec(); return app.exec();
} }

View File

@ -93,6 +93,13 @@ Rectangle {
color: "white" color: "white"
font.pointSize: 10 font.pointSize: 10
} }
Text {
text: qsTr("协议调试")
width: parent.width
anchors.centerIn: parent.Center
color: "white"
font.pointSize: 10
}
} }
} }
SerialSelect{ SerialSelect{

View File

@ -3,6 +3,10 @@
NetworkController::NetworkController(NetworkController::NetWorkType type, QString ip, uint16_t port) NetworkController::NetworkController(NetworkController::NetWorkType type, QString ip, uint16_t port)
{ {
mType = type;
if(_checkType(type) == TYPE_UNKOWN){
}
if(type == NetWorkType::TYPE_TCP_CLIENT){ if(type == NetWorkType::TYPE_TCP_CLIENT){
mTcp = new QTcpSocket(); mTcp = new QTcpSocket();
mCnn = mTcp; mCnn = mTcp;
@ -12,6 +16,21 @@ NetworkController::NetworkController(NetworkController::NetWorkType type, QStrin
mTcp->connectToHost(ip,port,QIODevice::ReadWrite); mTcp->connectToHost(ip,port,QIODevice::ReadWrite);
} }
if(type == NetWorkType::TYPE_TCP_SERVER){
mTcpServer = new QTcpServer();
connect(mTcpServer,SIGNAL(newConnection()),
this,SLOT(on_server_accept()));
connect(mTcpServer, SIGNAL(acceptError(QAbstractSocket::SocketError socketError)),
this, SLOT(displayError()));
if (!mTcpServer->listen(QHostAddress::Any, port))
{
qDebug() << "m_pTcpServer->listen() error";
}
}
} }
int NetworkController::SendData(int8_t *data, uint32_t len) int NetworkController::SendData(int8_t *data, uint32_t len)
@ -38,9 +57,36 @@ NetworkController::~NetworkController()
void NetworkController::on_ready_read() void NetworkController::on_ready_read()
{ {
qDebug()<<QString::fromStdString(mTcp->readAll().toStdString()); qDebug()<<QString::fromStdString(mTcp->readAll().toStdString());
emit(on_data_recv());
} }
void NetworkController::on_disconect() void NetworkController::on_disconect()
{ {
qDebug()<<"close"; qDebug()<<"close";
if(nullptr != mCnn){
emit(this->on_conection_close());
mCnn->close();
} }
}
void NetworkController::on_server_accept()
{
if(mType == TYPE_TCP_SERVER){
mTcpServer->pauseAccepting();
QTcpSocket* pClientConnection = mTcpServer->nextPendingConnection();
if(nullptr != pClientConnection){
QObject::connect(pClientConnection, SIGNAL(readyRead()), this, SLOT(on_ready_read()));
QObject::connect(pClientConnection, SIGNAL(disconnected()), this, SLOT(on_disconect()));
}
mTcp = pClientConnection;
}
}
NetworkController::NetWorkType NetworkController::_checkType(NetWorkType type){
if(type < TYPE_UNKOWN){
return type;
}else{
return TYPE_UNKOWN;
}
}

View File

@ -6,7 +6,7 @@
#include <QUdpSocket> #include <QUdpSocket>
#include <QTcpSocket> #include <QTcpSocket>
#include <QThread> #include <QThread>
#include <QTcpServer>
class NetworkController : public QObject class NetworkController : public QObject
{ {
@ -17,6 +17,7 @@ public:
TYPE_TCP_SERVER = 1, TYPE_TCP_SERVER = 1,
TYPE_UDP_CLIENT = 2, TYPE_UDP_CLIENT = 2,
TYPE_TCP_CLIENT = 3, TYPE_TCP_CLIENT = 3,
TYPE_UNKOWN = 4,
}NetWorkType; }NetWorkType;
NetworkController(NetWorkType type,QString ip,uint16_t port); NetworkController(NetWorkType type,QString ip,uint16_t port);
@ -28,16 +29,19 @@ public:
public slots: public slots:
void on_ready_read(); void on_ready_read();
void on_disconect(); void on_disconect();
void on_server_accept();
signals: signals:
void on_data_recv(); void on_data_recv();
void on_conection_ok(); void on_conection_ok();
void on_conection_close(); void on_conection_close();
void on_send_data(QByteArray); void on_send_data(QByteArray);
private: private:
NetWorkType type; NetWorkType _checkType(NetWorkType);
NetWorkType mType;
QUdpSocket *mUDP; QUdpSocket *mUDP;
QTcpSocket *mTcp; QTcpSocket *mTcp;
QTcpServer *mTcpServer;
QIODevice *mCnn; QIODevice *mCnn;
QThread mThread; QThread mThread;
}; };

View File

@ -92,7 +92,6 @@ void SerialController::GetSetting(QString baudRate, QString dataBits, QString st
mBaudrate = baudRate.toUInt(); mBaudrate = baudRate.toUInt();
mDataBits = (QSerialPort::DataBits)dataBits.toUInt(); mDataBits = (QSerialPort::DataBits)dataBits.toUInt();
mParity = QSerialPort::Parity::NoParity; mParity = QSerialPort::Parity::NoParity;
} }
void SerialController::ReadyRead() void SerialController::ReadyRead()

View File

@ -17,7 +17,6 @@ ShareData::ShareData(QObject *parent) : QObject(parent),
QTextStream in(&file); QTextStream in(&file);
m_lua_string = in.readAll(); m_lua_string = in.readAll();
qDebug()<< m_lua_string;
int ret = m_lua_.DoString(m_lua_string); int ret = m_lua_.DoString(m_lua_string);
if(ret < 0){ if(ret < 0){
qDebug()<<"默认lua脚本加载错误"; qDebug()<<"默认lua脚本加载错误";
@ -90,6 +89,11 @@ int ShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type)
if(type == NetworkController::TYPE_UDP_CLIENT){ if(type == NetworkController::TYPE_UDP_CLIENT){
} }
if(type == NetworkController::TYPE_TCP_SERVER){
m_network_ = new NetworkController(NetworkController::TYPE_TCP_SERVER,ip,port);
return 0;
}
return -1; return -1;
} }
@ -145,7 +149,6 @@ int ShareData::saveLuaScript(QString s)
} }
file.close(); file.close();
return 0; return 0;
} }
bool ShareData::luaStatus() bool ShareData::luaStatus()