2018-05-26 14:49:18 +08:00
|
|
|
|
#include "cedianudpprotocol.h"
|
2018-01-27 22:14:00 +08:00
|
|
|
|
|
2018-05-26 14:49:18 +08:00
|
|
|
|
CedianUdpProtocol::CedianUdpProtocol ( QObject* parent ) : QQtProtocol ( parent )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-26 14:49:18 +08:00
|
|
|
|
bool CedianUdpProtocol::dispatcher ( const QByteArray& dg )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
2018-05-26 14:49:18 +08:00
|
|
|
|
QByteArray data = dg;
|
|
|
|
|
mMsg.parser ( data );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
emit msgIncoming();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*依赖已经初始化好的端口*/
|
2018-05-26 14:49:18 +08:00
|
|
|
|
CedianUdpProtocol* cedianUdpServer ( QObject* parent )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
|
|
|
|
static CedianUdpServer* s0[9] = {NULL};
|
|
|
|
|
static CedianUdpProtocol* p0 = NULL;
|
2018-05-26 14:49:18 +08:00
|
|
|
|
if ( !s0[0] && !p0 )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
2018-05-26 14:49:18 +08:00
|
|
|
|
p0 = new CedianUdpProtocol ( parent );
|
|
|
|
|
for ( int i = 0; i < 9; i++ )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
2018-05-26 14:49:18 +08:00
|
|
|
|
int port = cedianUdpPort ( i + 1 );
|
|
|
|
|
pline() << i + 1 << port;
|
2018-01-27 22:14:00 +08:00
|
|
|
|
|
2018-05-26 14:49:18 +08:00
|
|
|
|
s0[i] = new CedianUdpServer ( parent );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
/*通讯端口:绑定本地端口*/
|
2018-05-26 14:49:18 +08:00
|
|
|
|
s0[i]->bind ( port );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
/*通讯端口:给测点协议*/
|
2018-05-26 14:49:18 +08:00
|
|
|
|
//s0[i]->installProtocol ( p0 );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return p0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 这里最好添加一个针对测点的本地监听Port列表设置函数,给mainwindow调用。
|
|
|
|
|
* 初始化第一次调用,需要把port列表传进去。
|
|
|
|
|
* 以后只需要获取即可,这个端口列表,重启生效。
|
|
|
|
|
* 不要少于9个,不要越界。
|
|
|
|
|
* 1-9
|
|
|
|
|
*/
|
2018-05-26 14:49:18 +08:00
|
|
|
|
qint32 cedianUdpPort ( int siteID, qint32* portList )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
2018-05-26 14:49:18 +08:00
|
|
|
|
if ( siteID < 1 || siteID > 9 )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
static qint32 sPort[9] = {0};
|
2018-05-26 14:49:18 +08:00
|
|
|
|
if ( portList )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
2018-05-26 14:49:18 +08:00
|
|
|
|
for ( int i = 0; i < 9; i++ )
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
|
|
|
|
sPort[i] = portList[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-26 14:49:18 +08:00
|
|
|
|
return sPort[siteID - 1];
|
2018-01-27 22:14:00 +08:00
|
|
|
|
}
|