-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerGUI.h
176 lines (138 loc) · 4.43 KB
/
PlayerGUI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Created by user on 15.11.2020.
//
#ifndef FOCUSIPCCTRL_PLAYERGUI_H
#define FOCUSIPCCTRL_PLAYERGUI_H
#include <QMainWindow>
#include <QThread>
#include <QCheckBox>
#include <memory>
#include <thread>
#include <CanController.h>
#include <QHBoxLayout>
#include <QtWidgets>
#include "utils.h"
using ElmPlayerUtils::Packet;
namespace Ui {
class Form;
}
class PlayerThread : public QThread
{
Q_OBJECT
void run() override {
do {
for (const auto &packet : CAP) {
if (isInterruptionRequested())
return;
if (blackList.find(packet.ID) != blackList.end()) {
continue;
}
std::vector<uint8_t> data(reinterpret_cast<const uint8_t *>(packet.data),
reinterpret_cast<const uint8_t *>(packet.data) + sizeof(Packet::data));
emit signalLog(QString(packet.str().c_str()));
m_controller->transaction(packet.ID, data);
}
} while (loopPlay);
}
std::vector<Packet> CAP;
std::set<int> blackList;
std::unique_ptr<CanController> m_controller;
std::atomic<bool> loopPlay = false;
public:
explicit PlayerThread(std::unique_ptr<CanController> controller) : m_controller(std::move(controller)) {};
void play(const std::vector<Packet> &captured_data, const std::set<int> &_blackList) {
if(!isRunning()) {
CAP=captured_data;
blackList=_blackList;
start();
}
}
void setProtocol(CAN_PROTO proto) {
m_controller->set_protocol(proto);
};
void setLoopPlay(bool f) {
loopPlay = f;
};
CanController * controller() { return m_controller.get(); }
signals:
void signalLog(QString str);
};
class PlayerGUI : public QMainWindow {
Q_OBJECT
private slots:
void slotLog(const QString &str);
void playFinished();
public:
explicit PlayerGUI(std::unique_ptr<CanController> controller, QWidget *parent = nullptr);
private:
enum enPeriodicCols {
COL_CAN_ID = 0,
COL_CAN_DATA,
COL_EN,
COL_COUNT
};
static constexpr int PERIODIC_MSG_COUNT = 10;
void resizeEvent(QResizeEvent *event) override;
PlayerThread player;
Ui::Form *ui;
std::vector<Packet> m_captured_data;
};
class CheckboxCell : public QWidget {
Q_OBJECT
QCheckBox *m_checkBox;
public:
CheckboxCell() {
m_checkBox = new QCheckBox();
auto layoutCheckBox = new QHBoxLayout(this);
layoutCheckBox->addWidget(m_checkBox);
layoutCheckBox->setAlignment(Qt::AlignCenter);
layoutCheckBox->setContentsMargins(0,0,0,0);
}
void mousePressEvent(QMouseEvent *event) override {
if (event->button() == Qt::MouseButton::LeftButton) {
m_checkBox->setChecked(!m_checkBox->isChecked());
}
QWidget::mousePressEvent(event);
}
[[nodiscard]] bool isChecked() const {
return m_checkBox->isChecked();
}
};
class DelegateColCanID : public QItemDelegate
{
public:
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem & option,
const QModelIndex & index) const override
{
auto lineEdit = new QLineEdit(parent);
connect(lineEdit, &QLineEdit::textEdited, [lineEdit](const QString &text) {
lineEdit->setText(text.toUpper());
});
auto validator = new QRegExpValidator(QRegExp("[0-9a-fA-F]{3}"), lineEdit);
lineEdit->setValidator(validator);
lineEdit->setPlaceholderText("XXX");
return lineEdit;
}
};
class DelegateColCanData : public QItemDelegate
{
public:
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem & option,
const QModelIndex & index) const override
{
auto lineEdit = new QLineEdit(parent);
lineEdit->setMaxLength(23);
connect(lineEdit, &QLineEdit::textEdited, [lineEdit](const QString &text) {
if(!((text.size()+1) % 3)) {
lineEdit->setText(text.toUpper() + " ");
} else {
lineEdit->setText(text.toUpper());
}
});
lineEdit->setPlaceholderText("XX XX XX XX XX XX XX XX");
auto validator = new QRegExpValidator(QRegExp("([0-9a-fA-F]{2} ){7}[0-9a-fA-F]{2}|"), lineEdit);
lineEdit->setValidator(validator);
return lineEdit;
}
};
#endif //FOCUSIPCCTRL_PLAYERGUI_H