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

60 lines
1.5 KiB
C++
Raw Normal View History

2018-05-26 14:49:18 +08:00
#include "cedianudpprotocol.h"
2018-05-26 14:49:18 +08:00
CedianUdpProtocol::CedianUdpProtocol ( QObject* parent ) : QQtProtocol ( parent )
{
}
2018-05-26 14:49:18 +08:00
bool CedianUdpProtocol::dispatcher ( const QByteArray& dg )
{
2018-05-26 14:49:18 +08:00
QByteArray data = dg;
mMsg.parser ( data );
emit msgIncoming();
}
/*依赖已经初始化好的端口*/
2018-05-26 14:49:18 +08:00
CedianUdpProtocol* cedianUdpServer ( QObject* parent )
{
static CedianUdpServer* s0[9] = {NULL};
static CedianUdpProtocol* p0 = NULL;
2018-05-26 14:49:18 +08:00
if ( !s0[0] && !p0 )
{
2018-05-26 14:49:18 +08:00
p0 = new CedianUdpProtocol ( parent );
for ( int i = 0; i < 9; i++ )
{
2018-05-26 14:49:18 +08:00
int port = cedianUdpPort ( i + 1 );
pline() << i + 1 << port;
2018-05-26 14:49:18 +08:00
s0[i] = new CedianUdpServer ( parent );
/*通讯端口:绑定本地端口*/
2018-05-26 14:49:18 +08:00
s0[i]->bind ( port );
/*通讯端口:给测点协议*/
2018-05-26 14:49:18 +08:00
//s0[i]->installProtocol ( p0 );
}
}
return p0;
}
/*
* Port列表设置函数mainwindow调用
* port列表传进去
*
* 9
* 1-9
*/
2018-05-26 14:49:18 +08:00
qint32 cedianUdpPort ( int siteID, qint32* portList )
{
2018-05-26 14:49:18 +08:00
if ( siteID < 1 || siteID > 9 )
return 0;
static qint32 sPort[9] = {0};
2018-05-26 14:49:18 +08:00
if ( portList )
{
2018-05-26 14:49:18 +08:00
for ( int i = 0; i < 9; i++ )
{
sPort[i] = portList[i];
}
}
2018-05-26 14:49:18 +08:00
return sPort[siteID - 1];
}