|
|
#include "threadReceive.h"
|
|
|
#include "cigarette.h"
|
|
|
#include "basecamera.h"
|
|
|
void threadReceive::start_work()
|
|
|
{
|
|
|
//start(HighestPriority);
|
|
|
start();
|
|
|
}
|
|
|
|
|
|
void threadReceive::stop()
|
|
|
{
|
|
|
isLoop = false;
|
|
|
BOOL bDontLinger = FALSE;
|
|
|
mSocket->abort();
|
|
|
filemSocket->abort();
|
|
|
// wait();
|
|
|
}
|
|
|
|
|
|
void threadReceive::init(std::string IP,int port)
|
|
|
{
|
|
|
ip = QString::fromStdString(IP);
|
|
|
|
|
|
mSocket = new QUdpSocket(this);
|
|
|
mSocket->bind(port + NumberOfSupportedCameras*2+1, QUdpSocket::ShareAddress);
|
|
|
connect(mSocket, &QUdpSocket::readyRead, this, &threadReceive::processPendingDatagram);
|
|
|
|
|
|
filemSocket = new QUdpSocket(this);
|
|
|
filemSocket->bind(port + NumberOfSupportedCameras*2+2, QUdpSocket::ShareAddress);
|
|
|
connect(filemSocket, &QUdpSocket::readyRead, this, &threadReceive::fileprocessPendingDatagram);
|
|
|
}
|
|
|
|
|
|
void threadReceive::processPendingDatagram()
|
|
|
{
|
|
|
// 拥有等待的数据报
|
|
|
while (mSocket->hasPendingDatagrams())
|
|
|
{
|
|
|
QByteArray datagram;
|
|
|
|
|
|
// 让datagram的大小为等待处理的数据报的大小,这样才能接收到完整的数据
|
|
|
datagram.resize(mSocket->pendingDatagramSize());
|
|
|
|
|
|
// 接收数据报,将其存放到datagram中
|
|
|
mSocket->readDatagram(datagram.data(), datagram.size());
|
|
|
QString data = datagram;
|
|
|
|
|
|
emit sendMsgToCigratte(data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void threadReceive::fileprocessPendingDatagram()
|
|
|
{
|
|
|
// 拥有等待的数据报
|
|
|
while (filemSocket->hasPendingDatagrams())
|
|
|
{
|
|
|
QByteArray datagram;
|
|
|
|
|
|
// 让datagram的大小为等待处理的数据报的大小,这样才能接收到完整的数据
|
|
|
datagram.resize(filemSocket->pendingDatagramSize());
|
|
|
|
|
|
// 接收数据报,将其存放到datagram中
|
|
|
filemSocket->readDatagram(datagram.data(), datagram.size());
|
|
|
QString data = datagram;
|
|
|
|
|
|
std::fstream cfg_file;
|
|
|
cfg_file.open("../conf/conf.txt",std::ios::out | std::ios::trunc);
|
|
|
if (cfg_file.is_open())
|
|
|
{
|
|
|
cfg_file.write(data.toStdString().c_str(),datagram.size());
|
|
|
}
|
|
|
cfg_file.close();
|
|
|
|
|
|
}
|
|
|
} |