no message

master
zcy 2021-05-01 23:41:40 +08:00
parent 70c898e74a
commit 4114dc8c70
7 changed files with 98 additions and 42 deletions

View File

@ -1,15 +1,14 @@
import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.0
import QtQml 2.3
Item {
id: element
// width: parent.width - 80
// height: parent.height
width: 800
height: 600
property alias textEditFontfamily: textEdit.font.family
visible: true
ColorAnimation {
@ -30,10 +29,8 @@ Item {
spacing: 6
width: parent.width
height: parent.height
RowLayout{
RowLayout {
spacing: 5
Label {
id: label6
Layout.leftMargin: 20
@ -46,7 +43,7 @@ Item {
font.pointSize: 20
}
TextEdit {
id: textEdit
id: port
Layout.leftMargin: 20
Layout.topMargin: 20
width: 80
@ -63,30 +60,27 @@ Item {
}
RadioButton {
id: radioButton
id: isServer
Layout.leftMargin: 20
Layout.topMargin: 20
width: 138
height: 41
text: qsTr("服务端")
checkable: true
checked: true
onClicked:{
if(radioButton.checked == true){
radioButton.checked = false
if(isServer.checked == true){
isServer.checked = false
isServer.checkable = false
}else{
radioButton.checked = true
isServer.checked = true
isServer.checkable = true
}
}
}
}
RowLayout{
spacing: 5
Label {
id: label7
Layout.leftMargin: 20
@ -98,9 +92,8 @@ Item {
wrapMode: Text.NoWrap
font.pointSize: 20
}
ComboBox {
id: comboBox1
id: proto_combox
Layout.leftMargin: 20
Layout.topMargin: 20
width: 143
@ -120,19 +113,21 @@ Item {
text: qsTr("websocket")
checkable: true
checked: true
onCheckableChanged: {
checked = ~checked
}
onClicked:{
radioSelectWebsocket.checked = ~radioSelectWebsocket.checked
if(radioSelectWebsocket.checked == true){
radioSelectWebsocket.checked = false
radioSelectWebsocket.checkable = false
}else{
radioSelectWebsocket.checked = true
radioSelectWebsocket.checkable = true
}
}
}
}
RowLayout{
spacing: 5
Label {
id: label8
Layout.leftMargin: 20
@ -143,7 +138,6 @@ Item {
wrapMode: Text.NoWrap
font.pointSize: 20
}
TextEdit {
id: hostEdit
Layout.leftMargin: 20
@ -172,14 +166,62 @@ Item {
text: qsTr("打开网口")
onClicked: {
let ret = DataWrap.openNetwork()
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
if(proto_combox.currentText == "udp" && isServer.checked){
type_network = 0
}
if(proto_combox.currentText == "udp" && !isServer.checked){
type_network = 2
}
if(proto_combox.currentText == "tcp" && isServer.checked){
type_network = 1
}
if(proto_combox.currentText == "tcp" && !isServer.checked){
type_network = 3
}
console.log(hostEdit.text,
port.text,
radioSelectWebsocket.checked,
type_network)
let ret = DataWrap.openNetwork(hostEdit.text,
Number(port.text),
radioSelectWebsocket.checked,
type_network)
if(ret != 0){
tip.text = "网络连接失败"
tip.visible = true
return
}
tip.text = "网络连接成功"
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
}
}
}
}

View File

@ -6,10 +6,9 @@ import QtQuick.Controls.Material 2.12
Item {
objectName: "ProtoDebug"
// width: parent.width - 80
// height: parent.height
width: 800
height: 600
property var comlist: []
visible: true
property bool uart_open: false

View File

@ -20,8 +20,8 @@ ShareData gGlobal;
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// QQuickView view;
// view.setResizeMode(QQuickView::SizeRootObjectToView);

View File

@ -16,20 +16,31 @@ NetworkController::NetworkController(NetworkController::NetWorkType type, QStrin
int NetworkController::SendData(int8_t *data, uint32_t len)
{
return mTcp->write((const char *)data,len);
if(nullptr == data)
return -1;
return mCnn->write((const char *)data,len);
}
int NetworkController::ReadData(int8_t *data)
{
if(nullptr != data){
return -1;
}
memcpy(data,mCnn->readAll().data(),mCnn->size());
}
NetworkController::~NetworkController()
{
delete mTcp;
}
void NetworkController::on_ready_read()
{
qDebug()<<QString::fromStdString(mTcp->readAll().toStdString());
}
void NetworkController::on_disconect()
{
qDebug()<<"close";
}

View File

@ -14,13 +14,15 @@ class NetworkController : public QObject
public:
typedef enum{
TYPE_UDP_SERVER = 0,
TYPE_TCP_SERVER,
TYPE_UDP_CLIENT,
TYPE_TCP_CLIENT,
TYPE_TCP_SERVER = 1,
TYPE_UDP_CLIENT = 2,
TYPE_TCP_CLIENT = 3,
}NetWorkType;
NetworkController(NetWorkType type,QString ip,uint16_t port);
int SendData(int8_t *data,uint32_t len);
int ReadData(int8_t *data);
~NetworkController();
public slots:

View File

@ -81,14 +81,16 @@ int ShareData::openUart(QString port, QString baudRate, QString dataBits, QStrin
return -1;
}
int ShareData::openNetwork(QString ip, uint32_t port, bool is_ws,int type)
int ShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type)
{
if(type == NetworkController::TYPE_TCP_CLIENT){
m_network_ = new NetworkController(NetworkController::TYPE_TCP_CLIENT,ip,port);
return 0;
}
if(type == NetworkController::TYPE_UDP_CLIENT){
m_network_ = new NetworkController(NetworkController::TYPE_TCP_CLIENT,ip,port);
}
return -1;
}
int ShareData::closeSerial()

View File

@ -39,7 +39,7 @@ public:
Q_INVOKABLE int openUart(QString port,QString baudRate,QString dataBits,QString stopBits,
QString flow);
Q_INVOKABLE int openNetwork(QString ip,uint32_t port,bool is_ws,int type);
Q_INVOKABLE int openNetwork(QString ip,unsigned int port,bool is_ws,int type);
Q_INVOKABLE int closeSerial();
Q_INVOKABLE int TestLua();
Q_INVOKABLE int TestShowData();