You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cigarette/上海四车间3#-倾斜胶点-四相机-CPU-无延后/Cigarette/threadReceive.cpp

73 lines
1.8 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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();
}
}