代码拉取完成,页面将自动刷新
#include "osdtcp.h"
OSDTcp::OSDTcp()
{
m_DataDictionary = DataDictionary::GetInstance();
OSDIp = m_DataDictionary->GetSystemData(SYS_CAMERA_IP1);
OSDPort = m_DataDictionary->GetSystemData(SYS_OSD_PORT).toShort();
m_TcpSocke = new QTcpSocket;
AllowSend = true;
gbk = QTextCodec::codecForName("gbk");
connect(m_TcpSocke, &QTcpSocket::connected, this, &OSDTcp::connected);
connect(m_TcpSocke,SIGNAL(bytesWritten(qint64)),this,SLOT(bytesWritten(qint64)));
connect(m_TcpSocke,SIGNAL(error(QAbstractSocket::SocketError)),this,
SLOT(error(QAbstractSocket::SocketError)));
connect(m_DataDictionary,SIGNAL(SystemDataChange(SystemDataIndex_t)),
this,SLOT(SystemDataChangeProcess(SystemDataIndex_t)));
}
OSDTcp::~OSDTcp()
{
delete m_TcpSocke;
}
void OSDTcp::OSDWWAPackBuild(bool s,QStringList data,int x,int y)
{
memset(&m_WWAOsd,0x0,sizeof (WWAOsd_t));
m_WWAOsd.Head.Cmd1 = 0x11;
m_WWAOsd.Head.Cmd2 = 0xa8;
m_WWAOsd.Head.LenH = 0x01;
m_WWAOsd.Head.LenL = 0xa4;
if(s)
m_WWAOsd.DataHead.bFlag = 1;
else
m_WWAOsd.DataHead.bFlag = 0;
m_WWAOsd.DataHead.bMaxNum = data.count();
m_WWAOsd.DataHead.bMaxNum = 64;
m_WWAOsd.DataHead.bFont = 2;
m_WWAOsd.DataHead.bSave = 0;
m_WWAOsd.DataHead.bChange = 1;
m_WWAOsd.DataHead.bDispLinePerTxet = 1;
m_WWAOsd.DataHead.bDispMode = 0;
for (int i = 0;i < data.count();i++) {
m_WWAOsd.Data[i].bFlag = 2;
if(i == 0){
m_WWAOsd.Data[i].bYPos = y;
m_WWAOsd.Data[i].bXPos = x;
}
m_WWAOsd.Data[i].bColor = 0;
QByteArray gb_bytes= gbk->fromUnicode(data[i]);
memcpy(m_WWAOsd.Data[i].text,gb_bytes.data(),gb_bytes.size());
}
}
void OSDTcp::OSDSend()
{
if(m_TcpSocke->state() == QTcpSocket::ConnectedState)
{
m_TcpSocke->write((char*)&m_WWAOsd,sizeof (WWAOsd_t));
AllowSend = true;
}
else if(m_TcpSocke->state() == QTcpSocket::UnconnectedState){
m_TcpSocke->connectToHost(OSDIp, OSDPort);
}
}
void OSDTcp::OSDDataSend(QStringList data)
{
if(!AllowSend)
{
OSDDisableDataSend(data);
return;
}
OSDWWAPackBuild(true,data,m_DataDictionary->GetSystemData(SYS_OSD_X_POS).toInt(),
m_DataDictionary->GetSystemData(SYS_OSD_Y_POS).toInt());
OSDSend();
}
void OSDTcp::OSDDisableDataSend(QStringList data)
{
AllowSend = false;
OSDWWAPackBuild(false,data,m_DataDictionary->GetSystemData(SYS_OSD_X_POS).toInt(),
m_DataDictionary->GetSystemData(SYS_OSD_Y_POS).toInt());
OSDSend();
}
void OSDTcp::connected()
{
m_TcpSocke->write((char*)&m_WWAOsd,sizeof (WWAOsd_t));
AllowSend = true;
}
void OSDTcp::bytesWritten(qint64 byte)
{
//m_TcpSocke->disconnect();
}
void OSDTcp::error(QAbstractSocket::SocketError socketError)
{
m_TcpSocke->disconnect();
qDebug() << "OSD network error:" + OSDIp + ":" + QString::number(OSDPort) + ":"+m_TcpSocke->errorString();
//QMessageBox msgBox;
//msgBox.setText(OSDIp + ":" + QString::number(OSDPort) + ":"+m_TcpSocke->errorString());
//msgBox.exec();
}
void OSDTcp::SystemDataChangeProcess(SystemDataIndex_t Index)
{
switch (Index) {
case SYS_CAMERA_IP1:
OSDIp = m_DataDictionary->GetSystemData(SYS_CAMERA_IP1);
m_TcpSocke->disconnect();
break;
case SYS_OSD_PORT:
OSDPort = m_DataDictionary->GetSystemData(SYS_OSD_PORT).toUShort();
m_TcpSocke->disconnect();
break;
case SYS_OSD_X_POS:
case SYS_OSD_Y_POS:
OSDDisableDataSend(QStringList());
break;
default:
break;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。