-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.cpp
executable file
·175 lines (138 loc) · 5.22 KB
/
mainwindow.cpp
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
#include <QMetaType>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "console.h"
#include "canboot_library/canboot.h"
#include "filedialog/filedialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
can_console(new Console),
cboot(new CANBoot)
{
ui->setupUi(this);
ui->upd_progressBar->setValue(0);
/* Нажатие на кнопку Find Devices */
connect(ui->find_pushButton, SIGNAL (clicked(bool)),
this, SLOT (slotInitButtonClicked()));
/* Отправка сообщения в консольное окно */
connect(cboot, SIGNAL(signalConsolePrint(const QString&)),
can_console, SLOT (putData(const QString&)));
/* Найдены доступные устройства */
connect(cboot, SIGNAL(signalDeviceActive(const bool)),
this, SLOT(slotChannelsActive(const bool)));
/* Найден свободный канал */
connect(cboot, SIGNAL(signalFreeChannelFound(int)),
this, SLOT(slotAddFreeChannelToCombo(int)));
/* Найден занятой канал */
connect(cboot, SIGNAL(signalBusyChannelFound(int)),
this, SLOT(slotAddBusyChannelToCombo(int)));
/* Выбран свободный канал */
connect(ui->channel_comboBox, SIGNAL(currentIndexChanged(int)),
cboot, SLOT(slotSetActiveChannel(int)));
/* Выбрана скорость подключения */
connect(ui->speed_comboBox, SIGNAL(activated(int)),
this, SLOT(slotSendSignalCurrentBaud(int)));
connect(this, SIGNAL(signalPassBaud(int)),
cboot, SLOT(slotSetActiveBaud(int)));
/* Нажатие на кнопку Сonnect */
connect(ui->connect_pushButton, SIGNAL (toggled(bool)),
cboot, SLOT (slotConnectButtonPressed(bool)));
connect(ui->connect_pushButton, SIGNAL (toggled(bool)),
this, SLOT (slotConnectButtonPressed(bool)));
/* Нажатие на кнопку Upload */
connect(ui->upd_pushButton, SIGNAL (clicked(bool)),
cboot, SLOT (slotUploadButtonPressed()));
/* Обновление ProgressBar */
connect(cboot, SIGNAL (signalProgressBarUpdate(int)),
ui->upd_progressBar, SLOT (setValue(int)));
/* Connection failed */
connect(cboot, SIGNAL (signalConnectionFailed(void)),
this, SLOT (slotConnectionFailed(void)));
/* File Dialog */
connect(ui->open_pushButton, SIGNAL(clicked(bool)),
cboot, SLOT(slotFDOpenFileDialog(void)));
connect(cboot, SIGNAL(signalBFSetProgressBarMaxValue(int)),
this, SLOT(slotSetProgressBarMaxValue(int)));
/* Add console window to UI */
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(can_console);
ui->console_groupBox->setLayout(vbox);
cboot->lib_init();
}
MainWindow::~MainWindow()
{
CiStop(this->cboot->getActiveChannel());
CiClose(this->cboot->getActiveChannel());
delete ui;
}
/* START SLOTS */
void MainWindow::slotInitButtonClicked ()
{
ui->channel_comboBox->clear();
cboot->device_init();
}
void MainWindow::slotChannelsActive(const bool setVar)
{
ui->channel_comboBox->setEnabled(setVar);
ui->speed_comboBox->setEnabled(setVar);
}
void MainWindow::slotAddFreeChannelToCombo(int ch)
{
QString new_channel = QString("%1-free").arg(ch);
ui->channel_comboBox->addItem(new_channel);
}
void MainWindow::slotAddBusyChannelToCombo(int ch)
{
QString new_channel = QString("%1-busy").arg(ch);
ui->channel_comboBox->addItem(new_channel);
}
void MainWindow::slotSendSignalCurrentBaud(int)
{
QString ch_baud = ui->speed_comboBox->itemText(ui->speed_comboBox->currentIndex());
int cur_baud = ch_baud.toInt();
ui->connect_pushButton->setEnabled(1);
emit signalPassBaud(cur_baud);
}
void MainWindow::slotConnectButtonPressed(bool checked)
{
if ((checked == 1) and (cboot->getConnectedFlag() == 1))
{
ui->find_pushButton->setEnabled(0);
ui->channel_comboBox->setEnabled(0);
ui->speed_comboBox->setEnabled(0);
ui->upd_pushButton->setEnabled(1);
ui->upd_progressBar->setEnabled(1);
ui->connect_pushButton->setText("DISCONNECT");
}
else
{
ui->find_pushButton->setEnabled(1);
ui->channel_comboBox->setEnabled(1);
ui->speed_comboBox->setEnabled(1);
ui->upd_pushButton->setEnabled(0);
ui->upd_progressBar->setEnabled(0);
ui->upd_progressBar->setValue(0);
ui->connect_pushButton->setEnabled(0);
ui->connect_pushButton->setText("CONNECT");
}
}
void MainWindow::slotConnectionFailed(void)
{
ui->find_pushButton->setEnabled(1);
ui->channel_comboBox->setEnabled(1);
ui->speed_comboBox->setEnabled(1);
ui->connect_pushButton->setEnabled(1);
ui->connect_pushButton->setChecked(0);
ui->connect_pushButton->setText("CONNECT");
ui->upd_pushButton->setEnabled(0);
ui->upd_progressBar->setEnabled(0);
CiStop(this->cboot->getActiveChannel());
CiClose(this->cboot->getActiveChannel());
this->cboot->setConnectedFlag(0);
}
void MainWindow::slotSetProgressBarMaxValue(int val)
{
ui->upd_progressBar->setMaximum(val);
}
/* END SLOTS */