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/untitled5/workthread.h

77 lines
2.4 KiB
C

2 years ago
#ifndef WORKTHREAD_H
#define WORKTHREAD_H
#include <QObject>
#include <QThread>
#include <QUdpSocket>
#include <QMutexLocker>
#include <QMutex>
#include <mutex>
#include <QThread>
static QUdpSocket mSocket;
//#include <opencv.hpp>
//#include <opencv2/opencv.hpp>
//void SendMat(cv::Mat mat, quint16 port);
class WorkThread : public QThread
{
Q_OBJECT
signals:
public:
WorkThread(QObject *parent = 0) : QThread(parent)
{
}
void setID(int d)
{
port = d;
}
protected:
void run() override
{
for (int i = 5; i < 6000; ++i)
{
//_sleep(1500);
// cv::Mat mat = cv::imread("d:/1.bmp", 1);
// {
// int length = mat.rows*mat.cols * 3;
// char*data = (char*)malloc(sizeof(char)*length);
// memcpy(data, mat.data, length);
// {
// mSocket.writeDatagram(QString("Start,%1,%2").arg(QString::number(mat.cols)).arg(QString::number(mat.rows)).toUtf8(), QHostAddress("192.168.10.130"), 8880 + port);
// int currentIndex = 0;
// while (currentIndex * 10240 < length)
// {
// int len = length - currentIndex * 10240;
// len = len < 10240 ? len : 10240;
// mSocket.writeDatagram(data + currentIndex * 10240, len, QHostAddress("192.168.10.130"), 8880 + port);
// _sleep(1);
// currentIndex++;
// }
// mSocket.writeDatagram(QString("End").toUtf8(), QHostAddress("192.168.10.130"), 8880 + port);
// }
// }
mSocket.writeDatagram(QString("Time,%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
mSocket.writeDatagram(QString("Speed,10%1").arg(QString::number(i)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
if (i % 5 == 0)
mSocket.writeDatagram(QString("Ok,0%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
else
mSocket.writeDatagram(QString("Ng,0%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
mSocket.writeDatagram(QString("Total,%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
mSocket.writeDatagram(QString("Kick,%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
mSocket.writeDatagram(QString("Jd,%1").arg(QString::number(i % 35)).toUtf8(), QHostAddress("192.168.10.130"), 8080 + port);
}
}
public:
int port;
};
#endif // WORKTHREAD_H