添加时间标签
This commit is contained in:
@@ -9,9 +9,6 @@ Parse::Parse(QObject *parent) : QObject(parent)
|
||||
qRegisterMetaType<QMap<quint16,QList<QByteArray>>>("QMap<quint16,QList<QByteArray>>");
|
||||
qRegisterMetaType<QMap<quint32,QMap<quint16,QList<QByteArray>>>>("QMap<quint32,QMap<quint16,QList<QByteArray>>>");
|
||||
|
||||
|
||||
|
||||
|
||||
Packer_init(&packer);
|
||||
Parser_init(&parser);
|
||||
|
||||
@@ -90,7 +87,6 @@ void Parse::run()
|
||||
frame.append((const char)parser.buff[i]);
|
||||
}
|
||||
|
||||
|
||||
if(port_data.contains(port))//包含
|
||||
{
|
||||
QList<QByteArray> frame_list = port_data.value(port);
|
||||
@@ -106,6 +102,8 @@ void Parse::run()
|
||||
|
||||
frame_data.append(frame);
|
||||
|
||||
emit frameok(ip,port,frame);
|
||||
|
||||
emit progress(all,current);
|
||||
|
||||
}
|
||||
@@ -152,8 +150,6 @@ void Parse::parseData(const QString filename)
|
||||
frame_data.clear();
|
||||
datagram.clear();
|
||||
datagram.append(file->readAll());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ signals:
|
||||
void progress(uint64_t all,uint64_t current);
|
||||
void frameList(QList<QByteArray> data);
|
||||
void frameport(QMap<quint16,QList<QByteArray>> data);
|
||||
|
||||
void frameok(quint32 ip, quint16 port, QByteArray frame);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
uint32_t cache_size = 1024 * 1024 * 100;//100M大小缓存,使用动态内存申请
|
||||
|
||||
+10
@@ -14,11 +14,21 @@ size_t Packer_pack(Packer_t *pack, uint8_t id, uint8_t pkg[], uint32_t len)
|
||||
|
||||
pack->buff[2] = id;
|
||||
|
||||
|
||||
// unsigned char *pt = (unsigned char *)&len;
|
||||
|
||||
// pack->buff[3] = pt[0];
|
||||
// pack->buff[4] = pt[1];
|
||||
// pack->buff[5] = pt[2];
|
||||
// pack->buff[6] = pt[3];
|
||||
|
||||
|
||||
pack->buff[3] = (len & 0x000000FF) >> 0;
|
||||
pack->buff[4] = (len & 0x0000FF00) >> 8;
|
||||
pack->buff[5] = (len & 0x00FF0000) >> 16;
|
||||
pack->buff[6] = (len & 0xFF000000) >> 24;
|
||||
|
||||
|
||||
sum = 0u;
|
||||
for (i=7,j=0u;j<len;++i,++j)
|
||||
{
|
||||
|
||||
+48
-14
@@ -23,6 +23,9 @@ PlayThread::~PlayThread()
|
||||
|
||||
void PlayThread::run()
|
||||
{
|
||||
QElapsedTimer elapstimer;
|
||||
elapstimer.start();
|
||||
|
||||
qDebug() << "PlayThread:" << QThread::currentThreadId();
|
||||
|
||||
union{uint8_t B[8];qint16 h[4];quint16 H[4]; qint32 i[2];quint32 I[2];qint64 q;quint64 Q;}src;
|
||||
@@ -39,6 +42,11 @@ void PlayThread::run()
|
||||
//for 不允许自加,需要后面逻辑判断增加
|
||||
for (QList<QByteArray>::iterator i = FrameData.begin(); i != FrameData.end();)
|
||||
{
|
||||
//记录一下运行到延迟之前用了多少时间,需要减掉这部分时间
|
||||
|
||||
|
||||
elapstimer.start();
|
||||
|
||||
CurrentProgress = FrameData.indexOf(*i);
|
||||
|
||||
data.clear();
|
||||
@@ -58,6 +66,9 @@ void PlayThread::run()
|
||||
|
||||
QDateTime time = QDateTime::fromMSecsSinceEpoch(time_t);
|
||||
|
||||
emit timestamp(time);
|
||||
|
||||
/*
|
||||
src.B[0] = data[index++];
|
||||
src.B[1] = data[index++];
|
||||
src.B[2] = data[index++];
|
||||
@@ -67,6 +78,8 @@ void PlayThread::run()
|
||||
src.B[6] = data[index++];
|
||||
src.B[7] = data[index++];
|
||||
qint64 save_count =src.Q;
|
||||
*/
|
||||
index += 8;//跳过某些数据
|
||||
|
||||
src.B[0] = data[index++];
|
||||
src.B[1] = data[index++];
|
||||
@@ -96,12 +109,8 @@ void PlayThread::run()
|
||||
|
||||
emit transmit(QHostAddress(ip),port,frame);
|
||||
|
||||
|
||||
|
||||
|
||||
time_tick = time.toMSecsSinceEpoch();
|
||||
|
||||
|
||||
currentTick = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
//中断播放,一般只有要播放新的文件才会出现这种情况
|
||||
@@ -153,20 +162,13 @@ void PlayThread::run()
|
||||
else
|
||||
{
|
||||
//在空闲时间里面处理好,,时间一到就发出去
|
||||
//QThread::msleep(time_gap/times);
|
||||
emit delaytime(time_gap/times,QDateTime::currentMSecsSinceEpoch() - currentTick);
|
||||
}
|
||||
time_gap = 0;
|
||||
|
||||
|
||||
//emit delaytime(time_gap/times,time_gap);
|
||||
}
|
||||
else//等于0,说明一个点内出现很多包
|
||||
{
|
||||
|
||||
emit delaytime(time_gap/times,0);
|
||||
//QThread::yieldCurrentThread();
|
||||
|
||||
}
|
||||
|
||||
if(play_state == 1)//如果是正常计时,那么就加
|
||||
@@ -216,11 +218,13 @@ void PlayThread::run()
|
||||
QDateTime time = QDateTime::fromMSecsSinceEpoch(time_t);
|
||||
time_tick = time.toMSecsSinceEpoch();
|
||||
|
||||
emit timestamp(time);
|
||||
|
||||
isChangedPos = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug() << "play time:" << elapstimer.nsecsElapsed() / 1000000.0;
|
||||
}
|
||||
play_state = 0;
|
||||
isChangedPos = false;
|
||||
@@ -232,6 +236,19 @@ void PlayThread::run()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlayThread::resetData()
|
||||
{
|
||||
port_data.clear();
|
||||
|
||||
FrameData.clear();
|
||||
|
||||
time_tick= 0;
|
||||
|
||||
play_state = 0;
|
||||
}
|
||||
|
||||
|
||||
void PlayThread::playData(QList<QByteArray> data,QMap<quint16,QList<QByteArray>> data2)
|
||||
{
|
||||
//收到数据后对数据进行分类,重新生成子线程进行解析
|
||||
@@ -251,8 +268,25 @@ void PlayThread::playData(QList<QByteArray> data,QMap<quint16,QList<QByteArray>>
|
||||
|
||||
}
|
||||
|
||||
void PlayThread::appendPlayData(QList<QByteArray> data,QMap<quint16,QList<QByteArray>> data2)
|
||||
{
|
||||
//收到数据后对数据进行分类,重新生成子线程进行解析
|
||||
|
||||
port_data.clear();
|
||||
port_data = data2;
|
||||
|
||||
|
||||
FrameData.clear();
|
||||
FrameData = data;
|
||||
|
||||
time_tick= 0;
|
||||
|
||||
play_state = 1;
|
||||
|
||||
emit progress(FrameData.size() - 1,0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +46,13 @@ public:
|
||||
|
||||
public slots:
|
||||
|
||||
void resetData();
|
||||
|
||||
void playData(QList<QByteArray> data, QMap<quint16, QList<QByteArray> > data2);
|
||||
|
||||
void appendPlayData(QList<QByteArray> data,QMap<quint16,QList<QByteArray>> data2);
|
||||
|
||||
|
||||
void setNewPos(int64_t pos)
|
||||
{
|
||||
newpos = pos;
|
||||
@@ -95,6 +100,9 @@ signals:
|
||||
|
||||
void delaytime(qint64 length,qint64 current);
|
||||
|
||||
void timestamp(QDateTime time);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
QByteArray datagram;
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
#include "SaveThread.h"
|
||||
|
||||
SaveThread::SaveThread(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
//setAutoDelete(true);
|
||||
|
||||
Packer_init(&packer);
|
||||
Parser_init(&parser);
|
||||
|
||||
save_count = 0;
|
||||
|
||||
mode = 0;
|
||||
recordstate =false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
SaveThread::~SaveThread()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//void SaveThread::run()
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
|
||||
|
||||
void SaveThread::setSave(const QHostAddress &ip, const uint16_t &port, QByteArray data)
|
||||
{
|
||||
QElapsedTimer elapstimer;
|
||||
elapstimer.start();
|
||||
|
||||
//qDebug() << "save re";
|
||||
|
||||
//qDebug() << "save" << QThread::currentThread();
|
||||
|
||||
if(mode > 0)//如果目前是播放模式,那就不记录
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!recordstate)//如果不是记录打开,那么就不记录
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray frame;
|
||||
|
||||
frame.clear();
|
||||
|
||||
union{uint8_t B[8];qint16 h[4];quint16 H[4]; qint32 i[2];quint32 I[2];qint64 q;quint64 Q;}src;
|
||||
|
||||
qint64 time_t = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
src.q = time_t;
|
||||
frame.append(src.B[0]);
|
||||
frame.append(src.B[1]);
|
||||
frame.append(src.B[2]);
|
||||
frame.append(src.B[3]);
|
||||
frame.append(src.B[4]);
|
||||
frame.append(src.B[5]);
|
||||
frame.append(src.B[6]);
|
||||
frame.append(src.B[7]);
|
||||
|
||||
save_count++;
|
||||
src.Q = save_count;
|
||||
frame.append(src.B[0]);
|
||||
frame.append(src.B[1]);
|
||||
frame.append(src.B[2]);
|
||||
frame.append(src.B[3]);
|
||||
frame.append(src.B[4]);
|
||||
frame.append(src.B[5]);
|
||||
frame.append(src.B[6]);
|
||||
frame.append(src.B[7]);
|
||||
|
||||
|
||||
src.I[0] = ip.toIPv4Address();
|
||||
frame.append(src.B[0]);
|
||||
frame.append(src.B[1]);
|
||||
frame.append(src.B[2]);
|
||||
frame.append(src.B[3]);
|
||||
|
||||
src.H[0] = port;
|
||||
frame.append(src.B[0]);
|
||||
frame.append(src.B[1]);
|
||||
|
||||
frame.append(data);
|
||||
|
||||
|
||||
//长度可能太短,需要修改打包协议
|
||||
size_t tx_len = Packer_pack(&packer, 01, (uint8_t*)frame.data(), frame.size());
|
||||
|
||||
//qDebug() << "save";
|
||||
|
||||
QFile file("./log/" + logname + ".bin");
|
||||
|
||||
if(file.open(QIODevice::Append) )
|
||||
{
|
||||
//QByteArray msg;
|
||||
|
||||
//msg.clear();
|
||||
//msg.append((const char *)packer.buff,tx_len);
|
||||
|
||||
|
||||
file.write((const char *)packer.buff,tx_len);
|
||||
|
||||
/*
|
||||
QDataStream stream(&file);
|
||||
|
||||
//stream << msg;
|
||||
|
||||
stream.writeBytes(msg.data(),msg.size());
|
||||
*/
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
qDebug() << "save time:" << elapstimer.nsecsElapsed() / 1000000.0;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef SAVETHREAD_H
|
||||
#define SAVETHREAD_H
|
||||
|
||||
#include <QObject>
|
||||
#include "QRunnable"
|
||||
#include "QDebug"
|
||||
#include "QThread"
|
||||
#include "QElapsedTimer"
|
||||
#include "QThreadPool"
|
||||
#include "QHostAddress"
|
||||
#include "ParsePack.h"
|
||||
#include "QDateTime"
|
||||
#include "QFile"
|
||||
#include "QDataStream"
|
||||
|
||||
class SaveThread : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SaveThread(QObject *parent = nullptr);
|
||||
~SaveThread();
|
||||
|
||||
//void run() override;
|
||||
|
||||
|
||||
QString logname = "00001";
|
||||
quint32 mode = 0;//0 记录模式 1 回放模式
|
||||
bool recordstate = false;
|
||||
|
||||
uint64_t save_count = 0;
|
||||
|
||||
|
||||
void setMode(quint32 value)
|
||||
{
|
||||
mode = value;
|
||||
}
|
||||
|
||||
void setRecordState(bool state)
|
||||
{
|
||||
recordstate = state;
|
||||
}
|
||||
|
||||
void setLogName(QString name)
|
||||
{
|
||||
logname = name;
|
||||
}
|
||||
|
||||
public slots:
|
||||
|
||||
void setSave(const QHostAddress &ip, const uint16_t &port, QByteArray data);
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Packer_t packer;
|
||||
Parser_t parser;
|
||||
|
||||
};
|
||||
|
||||
#endif // SAVETHREAD_H
|
||||
@@ -32,6 +32,7 @@ SOURCES += \
|
||||
Parse.cpp \
|
||||
ParsePack.c \
|
||||
PlayThread.cpp \
|
||||
SaveThread.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
@@ -39,6 +40,7 @@ HEADERS += \
|
||||
Parse.h \
|
||||
ParsePack.h \
|
||||
PlayThread.h \
|
||||
SaveThread.h \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
|
||||
+50
-60
@@ -8,13 +8,13 @@ DLink::DLink(QObject *parent) : QObject(parent)
|
||||
qDebug() << "Dlink " << QThread::currentThreadId();
|
||||
|
||||
QTimer *Timer = new QTimer(this);
|
||||
Timer->setInterval(2000);
|
||||
Timer->setInterval(1000);
|
||||
|
||||
connect(Timer,&QTimer::timeout,this,[=](){
|
||||
static qint64 last = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 time = QDateTime::currentMSecsSinceEpoch() - last;
|
||||
|
||||
if(time >= 2000)
|
||||
if(time >= 1000)
|
||||
{
|
||||
foreach(clientNode node,sockets)
|
||||
{
|
||||
@@ -80,27 +80,30 @@ DLink::~DLink()
|
||||
|
||||
void DLink::transmit(QHostAddress ip,quint16 port,QByteArray data)
|
||||
{
|
||||
QElapsedTimer time;
|
||||
|
||||
time.start();
|
||||
|
||||
foreach(clientNode node,sockets)
|
||||
{
|
||||
if((node.addr == ip) && (node.port == port))
|
||||
{
|
||||
//if(node.sock->isOpen()||node.sock->isWritable()||node.sock->isValid())
|
||||
//if(node.sock->isWritable()||node.sock->isValid())
|
||||
qint64 flag = node.sock->writeDatagram(data,node.addr, node.port);
|
||||
if(flag != -1)
|
||||
{
|
||||
qint64 flag = node.sock->writeDatagram(data,node.addr, node.port);
|
||||
if(flag != -1)
|
||||
{
|
||||
node.out.count += flag;
|
||||
node.out.frame += 1;
|
||||
sockets.replace(sockets.indexOf(node),node);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "udp Send Msg failure";
|
||||
}
|
||||
node.out.count += flag;
|
||||
node.out.frame += 1;
|
||||
sockets.replace(sockets.indexOf(node),node);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "udp Send Msg failure";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug() << "dlink transmit time:" << time.nsecsElapsed() / 1000000.0 ;
|
||||
}
|
||||
|
||||
|
||||
@@ -493,54 +496,25 @@ bool DLink::setup_multicast_transmit(const QHostAddress &ip,const quint16 &port,
|
||||
QUdpSocket *clientsock = new QUdpSocket(this);
|
||||
clientsock->setProxy(QNetworkProxy::NoProxy);//必须先设置不代理,否则连不上
|
||||
|
||||
/*
|
||||
if(clientsock->bind(QHostAddress::AnyIPv4,6000,QUdpSocket::ShareAddress))//
|
||||
{
|
||||
if (clientsock->joinMulticastGroup(QHostAddress(m_ip)))
|
||||
{
|
||||
*/
|
||||
clientsock->setSocketOption(QAbstractSocket::SendBufferSizeSocketOption,1024*1024*10);
|
||||
//clientsock->setSocketOption(QAbstractSocket::MulticastTtlOption, 10);
|
||||
//clientsock->setSocketOption(QAbstractSocket::MulticastLoopbackOption, 0);//禁止本机接收
|
||||
clientsock->setSocketOption(QAbstractSocket::SendBufferSizeSocketOption,1024*1024*10);
|
||||
//clientsock->setSocketOption(QAbstractSocket::MulticastTtlOption, 10);
|
||||
//clientsock->setSocketOption(QAbstractSocket::MulticastLoopbackOption, 0);//禁止本机接收
|
||||
|
||||
clientNode node;
|
||||
node.sock = clientsock;
|
||||
node.addr = m_ip;
|
||||
node.port = m_port;
|
||||
node.type = devtype::datalink;
|
||||
clientNode node;
|
||||
node.sock = clientsock;
|
||||
node.addr = m_ip;
|
||||
node.port = m_port;
|
||||
node.type = devtype::datalink;
|
||||
|
||||
sockets.append(node);
|
||||
qWarning() << "multicast open transmit:"
|
||||
<< node.addr
|
||||
<< node.port;
|
||||
sockets.append(node);
|
||||
qWarning() << "multicast open transmit:"
|
||||
<< node.addr
|
||||
<< node.port;
|
||||
|
||||
isSuccess = true;
|
||||
isSuccess = true;
|
||||
|
||||
|
||||
emit showMessage(tr("Bind and join the multicast group"),10000);
|
||||
/*
|
||||
}
|
||||
else
|
||||
{
|
||||
clientsock->close();
|
||||
isSuccess = false;
|
||||
qWarning() << "sock open failure" << clientsock->state();
|
||||
delete clientsock;
|
||||
clientsock = nullptr;
|
||||
emit showMessage(tr("Fail to join multicast group."),10000);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
isSuccess = false;
|
||||
clientsock->close();
|
||||
qWarning("sock is not binded.");
|
||||
delete clientsock;
|
||||
clientsock = nullptr;
|
||||
emit showMessage(tr("Fail to bind multicast socket."),10000);
|
||||
}
|
||||
*/
|
||||
emit showMessage(tr("Bind and join the multicast group"),10000);
|
||||
|
||||
return isSuccess;
|
||||
}
|
||||
@@ -584,6 +558,11 @@ bool DLink::setup_multicast_close(const QHostAddress &ip,const quint16 &port)
|
||||
|
||||
void DLink::readPendingDatagramsSerialPort(void)
|
||||
{
|
||||
//QElapsedTimer time;
|
||||
|
||||
//time.start();
|
||||
|
||||
|
||||
QObject *obj = sender();
|
||||
|
||||
if(obj)
|
||||
@@ -609,11 +588,18 @@ void DLink::readPendingDatagramsSerialPort(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug() << "dlink recieve time:" << time.nsecsElapsed() / 1000000.0 ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DLink::readPendingDatagramsClient(void)
|
||||
{
|
||||
//QElapsedTimer time;
|
||||
|
||||
//time.start();
|
||||
|
||||
QObject *obj = sender();
|
||||
|
||||
if(obj)
|
||||
@@ -630,12 +616,16 @@ void DLink::readPendingDatagramsClient(void)
|
||||
|
||||
clientsock->readDatagram(datagram.data(), datagram.size(),&address,&port);
|
||||
|
||||
emit recieve(address,port,datagram);
|
||||
|
||||
foreach (clientNode node, sockets) {
|
||||
if(node.sock)
|
||||
{
|
||||
if(node.sock == clientsock)
|
||||
{
|
||||
emit recieve(node.addr,node.port,datagram);
|
||||
|
||||
|
||||
//qDebug() << "dlink" << QThread::currentThread();
|
||||
|
||||
node.in.count += datagram.size();
|
||||
node.in.frame +=1;
|
||||
@@ -648,7 +638,7 @@ void DLink::readPendingDatagramsClient(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug() << "dlink recieve time:" << time.nsecsElapsed() / 1000000.0 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+91
-47
@@ -1,14 +1,12 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, dlink(new DLink)
|
||||
, savethread(new SaveThread)
|
||||
, playthread(new PlayThread)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -22,10 +20,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
setWindowIcon(QIcon(":/img/Dark/Logo.png"));
|
||||
|
||||
//设置表题
|
||||
bool titleflag = false;
|
||||
|
||||
QString title = Config::getSetting("title",&titleflag).toString();
|
||||
|
||||
if(titleflag == true)
|
||||
{
|
||||
setWindowTitle(title);
|
||||
@@ -40,9 +37,29 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
connect(dlink,&DLink::showMessage,this,&MainWindow::showMessage);
|
||||
|
||||
//connect(dlink,&DLink::recieve,savethread,&SaveThread::setSave);
|
||||
|
||||
|
||||
|
||||
|
||||
//dlink->moveToThread(&dlink_thread);
|
||||
//dlink_thread.start();
|
||||
|
||||
|
||||
savethread->moveToThread(&save_thread);
|
||||
|
||||
// operate 信号发射后启动线程工作
|
||||
connect(dlink,&DLink::recieve,savethread,&SaveThread::setSave);
|
||||
// 启动线程
|
||||
save_thread.start();
|
||||
|
||||
|
||||
|
||||
mode = Config::getSetting("mode").toBool();
|
||||
|
||||
savethread->setMode(mode);
|
||||
|
||||
|
||||
//上来就是记录界面
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
//读取设置
|
||||
@@ -55,11 +72,19 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
//设置IP输入校验
|
||||
//ui->lineEdit_Addr->setValidator(new QRegExpValidator(regExpIP ,ui->lineEdit_Addr));
|
||||
|
||||
//时间撮标签
|
||||
timestamplb = new QLabel(QDateTime::currentDateTimeUtc().toString("yyyy/MM/dd.hh:mm:ss.zzz"));
|
||||
|
||||
timestamplb->resize(300,80);
|
||||
|
||||
timestamplb->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
|
||||
ui->statusbar->addPermanentWidget(timestamplb);
|
||||
|
||||
timestamplb->hide();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//进度条
|
||||
progressbar = new QProgressBar(this);
|
||||
|
||||
progressbar->resize(300,80);
|
||||
@@ -75,6 +100,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
progressbar->hide();
|
||||
|
||||
|
||||
//记录按键
|
||||
recordbtn = new QPushButton(tr("StartRecord"),this);
|
||||
|
||||
recordbtn->resize(120,80);
|
||||
@@ -84,20 +110,22 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
recordbtn->hide();
|
||||
|
||||
|
||||
//开始记录-停止记录
|
||||
connect(recordbtn,&QPushButton::clicked,this,[=](){
|
||||
|
||||
if(recordstate)//正在记录
|
||||
{
|
||||
recordbtn->setText(tr("StartRecord"));
|
||||
recordstate = false;//停止记录
|
||||
savethread->setRecordState(recordstate);
|
||||
}
|
||||
else
|
||||
{
|
||||
recordbtn->setText(tr("StopRecord"));
|
||||
recordstate = true;//开始记录
|
||||
|
||||
logname = QString("raw%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
||||
savethread->setRecordState(recordstate);
|
||||
logname = QString("%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
||||
savethread->setLogName(logname);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -133,12 +161,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QString modename;
|
||||
if(mode == 0)
|
||||
{
|
||||
@@ -146,6 +168,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
progressbar->hide();
|
||||
recordbtn->show();
|
||||
combox->hide();
|
||||
timestamplb->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -153,9 +176,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
progressbar->show();
|
||||
recordbtn->hide();
|
||||
combox->show();
|
||||
timestamplb->show();
|
||||
}
|
||||
|
||||
|
||||
//模式按键初始化
|
||||
modebtn = new QPushButton(modename,this);
|
||||
|
||||
modebtn->resize(120,80);
|
||||
@@ -167,6 +191,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
mode = (mode > 0)?(0x00):(0x01);
|
||||
|
||||
savethread->setMode(mode);
|
||||
|
||||
Config::insertSetting("mode",(mode)?(true):(false));
|
||||
|
||||
QString modename;
|
||||
@@ -177,6 +203,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
progressbar->hide();
|
||||
recordbtn->show();
|
||||
combox->hide();
|
||||
timestamplb->hide();
|
||||
|
||||
if(playthread)
|
||||
{
|
||||
@@ -204,9 +231,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
progressbar->show();
|
||||
recordbtn->hide();
|
||||
combox->show();
|
||||
timestamplb->show();
|
||||
|
||||
recordbtn->setText(tr("StartRecord"));
|
||||
recordstate = false;
|
||||
savethread->setRecordState(recordstate);
|
||||
|
||||
}
|
||||
modebtn->setText(modename);
|
||||
@@ -258,13 +287,13 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//初始化打包和解析结构体
|
||||
Packer_init(&packer);
|
||||
Parser_init(&parser);
|
||||
|
||||
logname = QString("raw%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
||||
logname = QString("%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
||||
|
||||
//网络设置
|
||||
//网络列表设置
|
||||
QTableWidget *table = ui->tableWidget_Socket;
|
||||
|
||||
QStringList tabletitle;
|
||||
@@ -384,7 +413,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//列表双击
|
||||
connect(ui->tableWidget_Socket,&QTableWidget::itemDoubleClicked,this,[=](QTableWidgetItem *item)
|
||||
{
|
||||
QTableWidget *table = ui->tableWidget_Socket;
|
||||
@@ -411,9 +440,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
}
|
||||
|
||||
|
||||
qDebug() << row << column;
|
||||
|
||||
//编辑结束
|
||||
connect(line,&QLineEdit::editingFinished,[=](){
|
||||
if(line)
|
||||
{
|
||||
@@ -501,7 +528,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//添加按键按下
|
||||
connect(ui->pushButton_add,&QPushButton::clicked,this,[=](){
|
||||
//添加一组
|
||||
bool ok = false;
|
||||
@@ -573,6 +600,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
});
|
||||
|
||||
//删除按键按下
|
||||
connect(ui->pushButton_delete,&QPushButton::clicked,this,[=](){
|
||||
//删除一组
|
||||
QTableWidgetItem *item = table->currentItem();
|
||||
@@ -603,7 +631,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
|
||||
|
||||
//回放
|
||||
//回放列表
|
||||
table = ui->tableWidget_File;
|
||||
|
||||
tabletitle.clear();
|
||||
@@ -712,9 +740,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
|
||||
connect(parse,&Parse::frameport,this,[=](QMap<quint16,QList<QByteArray>> data){
|
||||
//playdata.clear();
|
||||
//playdata = data;
|
||||
|
||||
port_data.clear();
|
||||
port_data = data;
|
||||
|
||||
@@ -800,8 +825,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
flushTimer->start();
|
||||
|
||||
connect(dlink,&DLink::recieve,this,&MainWindow::setSave);
|
||||
|
||||
//connect(dlink,&DLink::recieve,this,&MainWindow::setSave);
|
||||
//显示速度
|
||||
connect(dlink,&DLink::status,this,[=](QHostAddress ip, quint16 port, qreal in_all, qreal in_rate, qreal in_frq,qreal out_all, qreal out_rate, qreal out_frq){
|
||||
|
||||
QTableWidget *table = ui->tableWidget_Socket;
|
||||
@@ -830,11 +855,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
if(in_all >= (1024*1024))
|
||||
{
|
||||
all.append(tr("total %1 MB").arg(QString::number(in_all/(1024*1024),'f',3)));
|
||||
all.append(tr("total %1 MB").arg(QString::number(in_all/(1024*1024),'f',1)));
|
||||
}
|
||||
else if(in_all >= 1024)
|
||||
{
|
||||
all.append(tr("total %1 KB").arg(QString::number(in_all/1024,'f',3)));
|
||||
all.append(tr("total %1 KB").arg(QString::number(in_all/1024,'f',1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -843,11 +868,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
if(in_rate >= (1024*1024))
|
||||
{
|
||||
rate.append(tr("rate %1 MB/s").arg(QString::number(in_rate/(1024*1024),'f',3)));
|
||||
rate.append(tr("rate %1 MB/s").arg(QString::number(in_rate/(1024*1024),'f',1)));
|
||||
}
|
||||
else if(in_rate >= 1024)
|
||||
{
|
||||
rate.append(tr("rate %1 KB/s").arg(QString::number(in_rate/1024,'f',3)));
|
||||
rate.append(tr("rate %1 KB/s").arg(QString::number(in_rate/1024,'f',1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -903,7 +928,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
});
|
||||
|
||||
|
||||
//status
|
||||
//按键样式设置
|
||||
QString last_default = QString("QPushButton{border-image: url(:/img/Dark/play_last.png);}\n");
|
||||
QString last_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_last_enter.png);}\n");
|
||||
QString last_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_last_enter.png);}\n");
|
||||
@@ -927,7 +952,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
|
||||
|
||||
playthread = new PlayThread;
|
||||
//playthread = new PlayThread;
|
||||
|
||||
//playthread->playData(playdata);
|
||||
|
||||
@@ -960,13 +985,13 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
//结束,设置按键失效
|
||||
});
|
||||
|
||||
|
||||
//显示进度条
|
||||
connect(playthread,&PlayThread::delaytime,this,[=](qint64 length,qint64 current){
|
||||
progressbar->setRange(0,length);
|
||||
progressbar->setValue(current);
|
||||
});
|
||||
|
||||
|
||||
//设置游标位置
|
||||
connect(this,&MainWindow::changedframe,this,[=](int64_t pos){
|
||||
if(playthread)
|
||||
{
|
||||
@@ -974,6 +999,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
});
|
||||
|
||||
//设置播放状态
|
||||
connect(this,&MainWindow::changedPlayState,this,[=](uint8_t state){
|
||||
if(playthread)
|
||||
{
|
||||
@@ -981,9 +1007,16 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
});
|
||||
|
||||
//时间撮显示
|
||||
connect(playthread,&PlayThread::timestamp,this,[=](QDateTime time){
|
||||
timestamplb->setText(time.toString("yyyy/MM/dd.hh:mm:ss.zzz"));
|
||||
});
|
||||
|
||||
//发给dlink发出去
|
||||
connect(playthread,&PlayThread::transmit,dlink,&DLink::transmit);
|
||||
|
||||
|
||||
//回放发送设置界面(这个想办法用其他办法,这个有点浪费时间)
|
||||
connect(playthread,&PlayThread::transmit,this,[=](QHostAddress p_ip,quint16 p_port,QByteArray data){
|
||||
|
||||
Q_UNUSED(data)
|
||||
@@ -996,14 +1029,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
QTableWidget *table = ui->tableWidget_Socket;
|
||||
|
||||
|
||||
|
||||
table->setRowCount(table->rowCount() + 1);
|
||||
int idx = table->rowCount()-1;
|
||||
|
||||
QLabel *logo = new QLabel();
|
||||
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
||||
logo->setAlignment(Qt::AlignHCenter);
|
||||
logo->setAlignment(Qt::AlignCenter);
|
||||
|
||||
table->removeCellWidget(idx,0);
|
||||
table->setCellWidget(idx,0,logo);
|
||||
@@ -1056,7 +1087,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
});
|
||||
|
||||
|
||||
|
||||
//关闭程序的时候线程线程处理
|
||||
connect(this,&MainWindow::destroyed,this,[=](){
|
||||
if(playthread)
|
||||
{
|
||||
@@ -1073,6 +1104,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//游标移动设置
|
||||
connect(ui->horizontalSlider,&QSlider::sliderMoved,this,[=](int value){
|
||||
if(playthread)
|
||||
{
|
||||
@@ -1096,6 +1129,19 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
save_thread.quit();
|
||||
save_thread.wait();
|
||||
|
||||
play_thread.quit();
|
||||
play_thread.wait();
|
||||
|
||||
decode_thread.quit();
|
||||
decode_thread.wait();
|
||||
|
||||
dlink_thread.quit();
|
||||
dlink_thread.wait();
|
||||
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@@ -1191,8 +1237,6 @@ void MainWindow::setSave(const QHostAddress &ip, const uint16_t &port, QByteArra
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,9 +21,15 @@
|
||||
#include "QStyle"
|
||||
|
||||
#include "QPushButton"
|
||||
#include "QLabel"
|
||||
#include "QComboBox"
|
||||
|
||||
#include <QTextStream>
|
||||
#include "QThread"
|
||||
|
||||
#include "SaveThread.h"
|
||||
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
@@ -38,6 +44,11 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
|
||||
QThread save_thread;
|
||||
QThread play_thread;
|
||||
QThread decode_thread;
|
||||
QThread dlink_thread;
|
||||
|
||||
public slots:
|
||||
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
@@ -73,6 +84,9 @@ private:
|
||||
|
||||
DLink *dlink = nullptr;
|
||||
|
||||
SaveThread *savethread = nullptr;
|
||||
|
||||
|
||||
QList<QMap<QVariant,QVariant>> sockets;
|
||||
|
||||
|
||||
@@ -110,6 +124,8 @@ private:
|
||||
QProgressBar *progressbar = nullptr;
|
||||
QComboBox *combox = nullptr;
|
||||
|
||||
QLabel *timestamplb = nullptr;
|
||||
|
||||
|
||||
|
||||
bool recordstate = false;
|
||||
|
||||
Reference in New Issue
Block a user