1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

add qqt network example and creator

This commit is contained in:
tianduanrui 2018-04-19 23:03:39 +08:00
parent f7f1d61b34
commit cf2b1a5b0e
56 changed files with 4109 additions and 105 deletions

View File

@ -45,6 +45,7 @@ SUBDIRS += examples/qqtaudioexample
#SUBDIRS += examples/qrcodeexample
#
SUBDIRS += examples/qqtnetworkexample
SUBDIRS += demo/QQtNetworkCreator
#greaterThan(QT_VERSION, 4.6.0):SUBDIRS += test/voicetest
#mac:lessThan(QT_MAJOR_VERSION , 5):SUBDIRS -= test/voicetest

View File

@ -0,0 +1,27 @@
#include "qqtuserprotocol.h"
QDebug& operator << ( QDebug& dbg, const QQtUserMessage& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
QQtUserProtocol* QQtUserConnectionInstance ( QObject* parent )
{
static QQtUserProtocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtUserProtocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef QQTUSERPROTOCOL_H
#define QQTUSERPROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class QQtUserMessage : public QQtMessage
{
Q_OBJECT
public:
explicit QQtUserMessage ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~QQtUserMessage() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const QQtUserMessage& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class QQtUserProtocol : public QQtProtocol
{
Q_OBJECT
public:
explicit QQtUserProtocol ( QObject* parent = nullptr ) {
}
~QQtUserProtocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const QQtUserMessage& msg ) {
//what do you want to do?
}
void recvCommand2 ( const QQtUserMessage& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
QQtUserMessage qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
QQtUserProtocol* QQtUserConnectionInstance ( QObject* parent = 0 );
#endif // QQTUSERPROTOCOL_H

View File

@ -0,0 +1,50 @@
#-------------------------------------------------
#
# Project created by QtCreator 2018-04-19T20:04:17
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QQtNetworkCreator
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
#测试这个模板是不是正确的
AppRoot/templete/qqtuserprotocol.cpp
HEADERS += \
mainwindow.h \
AppRoot/templete/qqtuserprotocol.h
FORMS += \
mainwindow.ui
CONFIG += mobility
MOBILITY =
#促使qqt_deploy_config配置执行没有这个变量不执行
APP_CONFIG_PWD = $${PWD}/AppRoot
equals(QMAKE_HOST.os, Windows) {
APP_CONFIG_PWD ~=s,/,\\,g
}
#促使编译源代码qmake pri配置里面的QMAKE_XX_LINK命令就会执行
system("touch main.cpp")
include(../../src/app_base_manager.pri)

View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,77 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QKeyEvent>
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),
ui ( new Ui::MainWindow )
{
ui->setupUi ( this );
QFile file ( "templete/qqtuserprotocol.h" );
file.open ( QFile::ReadOnly );
headerFileBytes = file.readAll();
file.close();
file.setFileName ( "templete/qqtuserprotocol.cpp" );
file.open ( QFile::ReadOnly );
sourceFileBytes = file.readAll();
file.close();
ui->lineEdit->installEventFilter ( this );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
if ( ui->lineEdit->text().isEmpty() )
return;
QByteArray className = ui->lineEdit->text().toLocal8Bit();
QByteArray HongName = className.toUpper();
QByteArray fileName = className.toLower();
QByteArray headerFileBytes = this->headerFileBytes;
QByteArray sourceFileBytes = this->sourceFileBytes;
headerFileBytes.replace ( "QQtUser", className );
headerFileBytes.replace ( "QQTUSER", HongName );
sourceFileBytes.replace ( "QQtUser", className );
sourceFileBytes.replace ( "qqtuser", fileName );
QFile headerFile ( QString ( "%1protocol.h" ).arg ( QString ( fileName ) ) );
QFile sourceFile ( QString ( "%1protocol.cpp" ).arg ( QString ( fileName ) ) );
headerFile.open ( QFile::Truncate | QFile::WriteOnly );
headerFile.write ( headerFileBytes );
headerFile.close();
sourceFile.open ( QFile::Truncate | QFile::WriteOnly );
sourceFile.write ( sourceFileBytes );
sourceFile.close();
}
bool MainWindow::eventFilter ( QObject* watched, QEvent* event )
{
if ( watched == ui->lineEdit )
{
if ( event->type() == QEvent::KeyPress )
{
QKeyEvent* e = ( QKeyEvent* ) event;
if ( e->key() == Qt::Key_Enter
|| e->key() == Qt::Key_Return )
{
on_pushButton_clicked();
}
}
}
}

View File

@ -0,0 +1,32 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow ( QWidget* parent = 0 );
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow* ui;
QByteArray headerFileBytes;
QByteArray sourceFileBytes;
// QObject interface
public:
virtual bool eventFilter ( QObject* watched, QEvent* event ) override;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>326</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>370</x>
<y>240</y>
<width>111</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Create</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>60</x>
<y>40</y>
<width>271</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Protocol Class Name:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>140</x>
<y>100</y>
<width>281</width>
<height>31</height>
</rect>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -1,6 +1,5 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qqtuserserialprotocol.h"
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),

View File

@ -1,104 +1,177 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-10-17T21:33:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qqtnetworkexample
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
qqtcloudprotocol.cpp \
qqtlanprotocol.cpp \
qqtnetworkmessage.cpp \
qqtserialmessage.cpp \
qqtuserserialprotocol.cpp \
qqtsubprotocoltest.cpp
HEADERS += \
mainwindow.h \
qqtcloudprotocol.h \
qqtlanprotocol.h \
qqtnetworkmessage.h \
qqtserialmessage.h \
qqtuserserialprotocol.h \
qqtsubprotocoltest.h
FORMS += \
mainwindow.ui
#qmake_pre/post_link will work after source changed but not pro pri changed.
system("touch main.cpp")
#-------------------------------------------------
#link qqt library
#if you link a library to your app, on android you must select the running kit to the app, not LibQQt e.g.
#user can modify any infomation under this annotation
#-------------------------------------------------
include(../../src/app_base_manager.pri)
contains (DEFINES, __BLUETOOTH__){
SOURCES += \
quserbluetoothprotocol.cpp
HEADERS += \
quserbluetoothprotocol.h
}
#-------------------------------------------------
#user app may use these these settings prefertly
#-------------------------------------------------
#-------------------------------------------------
#install app
#-------------------------------------------------
#CONFIG += can_install
can_install:equals(QKIT_PRIVATE, EMBEDDED) {
target.path = /Application
INSTALLS += target
} else: unix {
equals(QKIT_PRIVATE, macOS) {
target.path = /Applications
INSTALLS += target
}
}
############
##config defination
############
equals(QKIT_PRIVATE, macOS) {
CONFIG += app_bundle
}
contains(QKIT_PRIVATE, ANDROID|ANDROIDX86) {
CONFIG += mobility
MOBILITY =
DISTFILES += \
android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
}
#-------------------------------------------------
##project environ
#-------------------------------------------------
#default
message ($${TARGET} config $${CONFIG})
message ($${TARGET} define $${DEFINES})
#-------------------------------------------------
#
# Project created by QtCreator 2017-10-17T21:33:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qqtnetworkexample
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
qqtcloudprotocol.cpp \
qqtlanprotocol.cpp \
qqtnetworkmessage.cpp \
qqtserialmessage.cpp \
qqtuserserialprotocol.cpp \
qqtsubprotocoltest.cpp \
qqtuserprotocol1.cpp \
qqtuserprotocol2.cpp \
qqtuserprotocol3.cpp \
main.cpp \
mainwindow.cpp \
qqtcloudprotocol.cpp \
qqtlanprotocol.cpp \
qqtnetworkmessage.cpp \
qqtserialmessage.cpp \
qqtsubprotocoltest.cpp \
qqtuserprotocol1.cpp \
qqtuserprotocol2.cpp \
qqtuserprotocol3.cpp \
qqtuserserialprotocol.cpp \
quserbluetoothprotocol.cpp \
usernode0protocol.cpp \
usernode1protocol.cpp \
usernode2protocol.cpp \
usernode3protocol.cpp \
usernode4protocol.cpp \
usernode5protocol.cpp \
usernode6protocol.cpp \
usernode7protocol.cpp \
usernode8protocol.cpp \
usernode9protocol.cpp \
usertest0protocol.cpp \
usertest1protocol.cpp \
usertest2protocol.cpp \
usertest3protocol.cpp \
usertest4protocol.cpp \
usertest5protocol.cpp \
usertest6protocol.cpp \
usertest7protocol.cpp \
usertest8protocol.cpp \
usertest9protocol.cpp
HEADERS += \
mainwindow.h \
qqtcloudprotocol.h \
qqtlanprotocol.h \
qqtnetworkmessage.h \
qqtserialmessage.h \
qqtuserserialprotocol.h \
qqtsubprotocoltest.h \
qqtuserprotocol1.h \
qqtuserprotocol2.h \
qqtuserprotocol3.h \
mainwindow.h \
qqtcloudprotocol.h \
qqtlanprotocol.h \
qqtnetworkmessage.h \
qqtserialmessage.h \
qqtsubprotocoltest.h \
qqtuserprotocol1.h \
qqtuserprotocol2.h \
qqtuserprotocol3.h \
qqtuserserialprotocol.h \
quserbluetoothprotocol.h \
usernode0protocol.h \
usernode1protocol.h \
usernode2protocol.h \
usernode3protocol.h \
usernode4protocol.h \
usernode5protocol.h \
usernode6protocol.h \
usernode7protocol.h \
usernode8protocol.h \
usernode9protocol.h \
usertest0protocol.h \
usertest1protocol.h \
usertest2protocol.h \
usertest3protocol.h \
usertest4protocol.h \
usertest5protocol.h \
usertest6protocol.h \
usertest7protocol.h \
usertest8protocol.h \
usertest9protocol.h
FORMS += \
mainwindow.ui \
mainwindow.ui
#qmake_pre/post_link will work after source changed but not pro pri changed.
system("touch main.cpp")
#-------------------------------------------------
#link qqt library
#if you link a library to your app, on android you must select the running kit to the app, not LibQQt e.g.
#user can modify any infomation under this annotation
#-------------------------------------------------
include(../../src/app_base_manager.pri)
contains (DEFINES, __BLUETOOTH__){
SOURCES += \
quserbluetoothprotocol.cpp
HEADERS += \
quserbluetoothprotocol.h
}
#-------------------------------------------------
#user app may use these these settings prefertly
#-------------------------------------------------
#-------------------------------------------------
#install app
#-------------------------------------------------
#CONFIG += can_install
can_install:equals(QKIT_PRIVATE, EMBEDDED) {
target.path = /Application
INSTALLS += target
} else: unix {
equals(QKIT_PRIVATE, macOS) {
target.path = /Applications
INSTALLS += target
}
}
############
##config defination
############
equals(QKIT_PRIVATE, macOS) {
CONFIG += app_bundle
}
contains(QKIT_PRIVATE, ANDROID|ANDROIDX86) {
CONFIG += mobility
MOBILITY =
DISTFILES += \
android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
}
#-------------------------------------------------
##project environ
#-------------------------------------------------
#default
message ($${TARGET} config $${CONFIG})
message ($${TARGET} define $${DEFINES})
SUBDIRS += \
qqtnetworkexample.pro

View File

@ -0,0 +1,27 @@
#include "qqtuserprotocol1.h"
QDebug& operator << ( QDebug& dbg, const QQtUserMessage1& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
QQtUserProtocol1* QQtUserConnectionInstance1 ( QObject* parent )
{
static QQtUserProtocol1* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtUserProtocol1 ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef QQTUSERPROTOCOL1_H
#define QQTUSERPROTOCOL1_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class QQtUserMessage1 : public QQtMessage
{
Q_OBJECT
public:
explicit QQtUserMessage1 ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~QQtUserMessage1() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const QQtUserMessage1& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class QQtUserProtocol1 : public QQtProtocol
{
Q_OBJECT
public:
explicit QQtUserProtocol1 ( QObject* parent = nullptr ) {
}
~QQtUserProtocol1() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const QQtUserMessage1& msg ) {
//what do you want to do?
}
void recvCommand2 ( const QQtUserMessage1& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
QQtUserMessage1 qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
QQtUserProtocol1* QQtUserConnectionInstance1 ( QObject* parent = 0 );
#endif // QQTUSERPROTOCOL1_H

View File

@ -0,0 +1,26 @@
#include "qqtuserprotocol2.h"
QDebug& operator << ( QDebug& dbg, const QQtUserMessage2& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
QQtUserProtocol2* QQtUserConnectionInstance2 ( QObject* parent )
{
static QQtUserProtocol2* p0 = NULL;
static QQtSocketTcpClient* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtUserProtocol2 ( parent );
s0 = new QQtSocketTcpClient ( parent );
s0->installProtocol ( p0 );
s0->connectToHost ( QHostAddress ( "192.168.0.100" ), 8000 );
}
return p0;
}

View File

@ -0,0 +1,129 @@
#ifndef QQTUSERPROTOCOL2_H
#define QQTUSERPROTOCOL2_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpclient.h>
#include <QHostAddress>
class QQtUserMessage2 : public QQtMessage
{
Q_OBJECT
public:
explicit QQtUserMessage2 ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~QQtUserMessage2() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const QQtUserMessage2& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class QQtUserProtocol2 : public QQtProtocol
{
Q_OBJECT
public:
explicit QQtUserProtocol2 ( QObject* parent = nullptr ) {
}
~QQtUserProtocol2() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const QQtUserMessage2& msg ) {
//what do you want to do?
}
void recvCommand2 ( const QQtUserMessage2& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
QQtUserMessage2 qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
QQtUserProtocol2* QQtUserConnectionInstance2 ( QObject* parent = 0 );
#endif // QQTUSERPROTOCOL2_H

View File

@ -0,0 +1,33 @@
#include "qqtuserprotocol3.h"
QDebug& operator << ( QDebug& dbg, const QQtUserMessage3& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
QQtUserProtocol3* QQtUserConnectionInstance3 ( QObject* parent )
{
static QQtUserProtocol3* p0 = NULL;
static QQtSerialPort* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtUserProtocol3 ( parent );
s0 = new QQtSerialPort ( parent );
s0->setPortName ( "/dev/ttyUSB0" );
s0->setBaudRate ( QQtSerialPort::Baud57600 );
s0->setDataBits ( QQtSerialPort::Data8 );
s0->setParity ( QQtSerialPort::NoParity );
s0->setStopBits ( QQtSerialPort::OneStop );
s0->setFlowControl ( QQtSerialPort::NoFlowControl );
s0->open ( QQtSerialPort::ReadWrite );
s0->installProtocol ( p0 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef QQTUSERPROTOCOL3_H
#define QQTUSERPROTOCOL3_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtserialport.h>
class QQtUserMessage3 : public QQtMessage
{
Q_OBJECT
public:
explicit QQtUserMessage3 ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~QQtUserMessage3() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const QQtUserMessage3& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class QQtUserProtocol3 : public QQtProtocol
{
Q_OBJECT
public:
explicit QQtUserProtocol3 ( QObject* parent = nullptr ) {
}
~QQtUserProtocol3() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const QQtUserMessage3& msg ) {
//what do you want to do?
}
void recvCommand2 ( const QQtUserMessage3& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
QQtUserMessage3 qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
QQtUserProtocol3* QQtUserConnectionInstance3 ( QObject* parent = 0 );
#endif // QQTUSERPROTOCOL3_H

View File

@ -0,0 +1,27 @@
#include "usernode0protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode0Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode0Protocol* UserNode0ConnectionInstance ( QObject* parent )
{
static UserNode0Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode0Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE0PROTOCOL_H
#define USERNODE0PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode0Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode0Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode0Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode0Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode0Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode0Protocol ( QObject* parent = nullptr ) {
}
~UserNode0Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode0Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode0Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode0Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode0Protocol* UserNode0ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE0PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode1protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode1Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode1Protocol* UserNode1ConnectionInstance ( QObject* parent )
{
static UserNode1Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode1Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE1PROTOCOL_H
#define USERNODE1PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode1Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode1Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode1Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode1Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode1Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode1Protocol ( QObject* parent = nullptr ) {
}
~UserNode1Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode1Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode1Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode1Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode1Protocol* UserNode1ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE1PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode2protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode2Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode2Protocol* UserNode2ConnectionInstance ( QObject* parent )
{
static UserNode2Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode2Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE2PROTOCOL_H
#define USERNODE2PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode2Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode2Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode2Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode2Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode2Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode2Protocol ( QObject* parent = nullptr ) {
}
~UserNode2Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode2Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode2Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode2Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode2Protocol* UserNode2ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE2PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode3protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode3Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode3Protocol* UserNode3ConnectionInstance ( QObject* parent )
{
static UserNode3Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode3Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE3PROTOCOL_H
#define USERNODE3PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode3Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode3Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode3Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode3Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode3Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode3Protocol ( QObject* parent = nullptr ) {
}
~UserNode3Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode3Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode3Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode3Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode3Protocol* UserNode3ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE3PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode4protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode4Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode4Protocol* UserNode4ConnectionInstance ( QObject* parent )
{
static UserNode4Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode4Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE4PROTOCOL_H
#define USERNODE4PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode4Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode4Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode4Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode4Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode4Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode4Protocol ( QObject* parent = nullptr ) {
}
~UserNode4Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode4Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode4Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode4Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode4Protocol* UserNode4ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE4PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode5protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode5Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode5Protocol* UserNode5ConnectionInstance ( QObject* parent )
{
static UserNode5Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode5Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE5PROTOCOL_H
#define USERNODE5PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode5Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode5Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode5Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode5Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode5Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode5Protocol ( QObject* parent = nullptr ) {
}
~UserNode5Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode5Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode5Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode5Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode5Protocol* UserNode5ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE5PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode6protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode6Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode6Protocol* UserNode6ConnectionInstance ( QObject* parent )
{
static UserNode6Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode6Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE6PROTOCOL_H
#define USERNODE6PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode6Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode6Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode6Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode6Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode6Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode6Protocol ( QObject* parent = nullptr ) {
}
~UserNode6Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode6Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode6Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode6Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode6Protocol* UserNode6ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE6PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode7protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode7Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode7Protocol* UserNode7ConnectionInstance ( QObject* parent )
{
static UserNode7Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode7Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE7PROTOCOL_H
#define USERNODE7PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode7Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode7Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode7Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode7Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode7Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode7Protocol ( QObject* parent = nullptr ) {
}
~UserNode7Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode7Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode7Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode7Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode7Protocol* UserNode7ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE7PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode8protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode8Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode8Protocol* UserNode8ConnectionInstance ( QObject* parent )
{
static UserNode8Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode8Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE8PROTOCOL_H
#define USERNODE8PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode8Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode8Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode8Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode8Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode8Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode8Protocol ( QObject* parent = nullptr ) {
}
~UserNode8Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode8Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode8Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode8Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode8Protocol* UserNode8ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE8PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usernode9protocol.h"
QDebug& operator << ( QDebug& dbg, const UserNode9Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserNode9Protocol* UserNode9ConnectionInstance ( QObject* parent )
{
static UserNode9Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserNode9Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERNODE9PROTOCOL_H
#define USERNODE9PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserNode9Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserNode9Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserNode9Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserNode9Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserNode9Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserNode9Protocol ( QObject* parent = nullptr ) {
}
~UserNode9Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserNode9Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserNode9Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserNode9Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserNode9Protocol* UserNode9ConnectionInstance ( QObject* parent = 0 );
#endif // USERNODE9PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest0protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest0Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest0Protocol* UserTest0ConnectionInstance ( QObject* parent )
{
static UserTest0Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest0Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST0PROTOCOL_H
#define USERTEST0PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest0Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest0Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest0Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest0Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest0Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest0Protocol ( QObject* parent = nullptr ) {
}
~UserTest0Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest0Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest0Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest0Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest0Protocol* UserTest0ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST0PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest1protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest1Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest1Protocol* UserTest1ConnectionInstance ( QObject* parent )
{
static UserTest1Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest1Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST1PROTOCOL_H
#define USERTEST1PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest1Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest1Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest1Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest1Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest1Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest1Protocol ( QObject* parent = nullptr ) {
}
~UserTest1Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest1Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest1Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest1Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest1Protocol* UserTest1ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST1PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest2protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest2Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest2Protocol* UserTest2ConnectionInstance ( QObject* parent )
{
static UserTest2Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest2Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST2PROTOCOL_H
#define USERTEST2PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest2Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest2Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest2Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest2Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest2Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest2Protocol ( QObject* parent = nullptr ) {
}
~UserTest2Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest2Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest2Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest2Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest2Protocol* UserTest2ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST2PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest3protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest3Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest3Protocol* UserTest3ConnectionInstance ( QObject* parent )
{
static UserTest3Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest3Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST3PROTOCOL_H
#define USERTEST3PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest3Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest3Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest3Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest3Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest3Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest3Protocol ( QObject* parent = nullptr ) {
}
~UserTest3Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest3Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest3Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest3Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest3Protocol* UserTest3ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST3PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest4protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest4Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest4Protocol* UserTest4ConnectionInstance ( QObject* parent )
{
static UserTest4Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest4Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST4PROTOCOL_H
#define USERTEST4PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest4Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest4Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest4Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest4Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest4Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest4Protocol ( QObject* parent = nullptr ) {
}
~UserTest4Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest4Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest4Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest4Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest4Protocol* UserTest4ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST4PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest5protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest5Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest5Protocol* UserTest5ConnectionInstance ( QObject* parent )
{
static UserTest5Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest5Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST5PROTOCOL_H
#define USERTEST5PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest5Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest5Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest5Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest5Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest5Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest5Protocol ( QObject* parent = nullptr ) {
}
~UserTest5Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest5Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest5Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest5Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest5Protocol* UserTest5ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST5PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest6protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest6Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest6Protocol* UserTest6ConnectionInstance ( QObject* parent )
{
static UserTest6Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest6Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST6PROTOCOL_H
#define USERTEST6PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest6Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest6Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest6Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest6Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest6Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest6Protocol ( QObject* parent = nullptr ) {
}
~UserTest6Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest6Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest6Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest6Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest6Protocol* UserTest6ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST6PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest7protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest7Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest7Protocol* UserTest7ConnectionInstance ( QObject* parent )
{
static UserTest7Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest7Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST7PROTOCOL_H
#define USERTEST7PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest7Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest7Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest7Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest7Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest7Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest7Protocol ( QObject* parent = nullptr ) {
}
~UserTest7Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest7Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest7Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest7Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest7Protocol* UserTest7ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST7PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest8protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest8Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest8Protocol* UserTest8ConnectionInstance ( QObject* parent )
{
static UserTest8Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest8Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST8PROTOCOL_H
#define USERTEST8PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest8Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest8Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest8Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest8Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest8Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest8Protocol ( QObject* parent = nullptr ) {
}
~UserTest8Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest8Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest8Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest8Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest8Protocol* UserTest8ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST8PROTOCOL_H

View File

@ -0,0 +1,27 @@
#include "usertest9protocol.h"
QDebug& operator << ( QDebug& dbg, const UserTest9Message& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.size() << "}";
return dbg.space();
}
UserTest9Protocol* UserTest9ConnectionInstance ( QObject* parent )
{
static UserTest9Protocol* p0 = NULL;
static QQtSocketTcpServer* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new UserTest9Protocol ( parent );
s0 = new QQtSocketTcpServer ( parent );
s0->installProtocol ( p0 );
s0->listen ( QHostAddress::Any, 8000 );
}
return p0;
}

View File

@ -0,0 +1,127 @@
#ifndef USERTEST9PROTOCOL_H
#define USERTEST9PROTOCOL_H
#include <qqtmessage.h>
#include <qqtprotocol.h>
#include <qqtsockettcpserver.h>
class UserTest9Message : public QQtMessage
{
Q_OBJECT
public:
explicit UserTest9Message ( QObject* parent = nullptr ) {
mSize = 0x03;//报文定长
}
~UserTest9Message() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
quint8& cmd() { return mCmd; }
const quint8& cmd() const { return mCmd; }
quint8& data() { return mData; }
const quint8& data() const { return mData; }
private:
//格式
//|quint8 size|quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
//把报文这条流解析出字段
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
//把报文字段组装成流
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
QDebug& operator << ( QDebug&, const UserTest9Message& msg );
//业务层总是用这个协议工作,读来到的,写出去的。
class UserTest9Protocol : public QQtProtocol
{
Q_OBJECT
public:
explicit UserTest9Protocol ( QObject* parent = nullptr ) {
}
~UserTest9Protocol() {
}
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
void recvCommand1 ( const UserTest9Message& msg ) {
//what do you want to do?
}
void recvCommand2 ( const UserTest9Message& msg ) {
//what do you want to do?
}
signals:
//给业务层发的信号
void signalSendtoLogicLevelCode();
public slots:
// QQtProtocol interface
protected:
//报文的最小长度
virtual quint16 minlength() override {
return 0x0a;
}
//报文的最大长度
virtual quint16 maxlength() override {
return 0x07FF;
}
//报文现在在流里第一个字节就是size读出来通过返回值告诉QQtProtocol
virtual quint16 splitter ( const QByteArray& l ) override { //stream
QByteArray s0 = l.left ( 1 );
quint8 size = 0;
s0 >> size;
return size;
}
//报文现在被切开发了进来第二个字节是cmd解析出来在函数里处理处理数据告诉业务层拿到数据了干点什么。
virtual bool dispatcher ( const QByteArray& m ) override { //message
bool ret = true;
UserTest9Message qMsg;
qMsg.parser ( m );
pline() << qMsg;
switch ( qMsg.cmd() ) {
case 0x0a://protocol command 1
recvCommand1 ( qMsg );
break;
case 0x0b://protocol command 2
recvCommand2 ( qMsg );
break;
default:
ret = false;
pline() << "receive unknown command:" << hex << qMsg.cmd();
break;
}
return ret;
}
};
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
UserTest9Protocol* UserTest9ConnectionInstance ( QObject* parent = 0 );
#endif // USERTEST9PROTOCOL_H