EtherCAT Graphical User Interface Code 0.0.1
EtherCAT GUI that uses different communication protocols with EtherCAT Master server.
Loading...
Searching...
No Matches
ec_gui_start.h
1#ifndef EC_GUI_START_H
2#define EC_GUI_START_H
3
4#include <QtUiTools>
5#include <QWidget>
6#include <QMainWindow>
7
8#include "cmn_utils.h"
9#include "utils/ec_utils.h"
10
11#include "ec_gui_net.h"
12#include "ec_gui_wrapper.h"
13#include "ec_gui_terminal.h"
14
15class EcGuiFirmware : public QWizard
16{
17 Q_OBJECT
18public:
19
20 EcGuiFirmware(QWidget * parent = 0){
21
22 _firmware_files_tree = new QTreeWidget();
23 _firmware_files_tree->setColumnCount(2);
24 _firmware_files_tree->setHeaderLabels({"Firmware files",""});
25 _firmware_files_tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
26 _firmware_files_tree->header()->setMinimumSectionSize(0);
27 _firmware_files_tree->header()->resizeSection(1,0);
28 _firmware_files_tree->header()->setStretchLastSection(false); // QTreeWidget problem for resizing added another column!!
29
30
31 auto firmware_manager = new QDialogButtonBox(QDialogButtonBox::RestoreDefaults |
32 QDialogButtonBox::Ignore |
33 QDialogButtonBox::Retry |
34 QDialogButtonBox::Save );
35
36
37 auto select_files = firmware_manager->button(QDialogButtonBox::RestoreDefaults);
38 select_files->setText("Select all bin or config files");
39 connect(select_files, &QPushButton::released,this, &EcGuiFirmware::onSelectFilesReleased);
40
41 auto copy_files_btn = firmware_manager->button(QDialogButtonBox::Ignore);
42 copy_files_btn->setText("Copy files to embedded PC");
43 _firmware_update_btns.push_back(copy_files_btn);
44
45 auto open_config_btn = firmware_manager->button(QDialogButtonBox::Retry);
46 open_config_btn->setText("Open firmware configuration file");
47 _firmware_update_btns.push_back(open_config_btn);
48
49 auto start_update_btn = firmware_manager->button(QDialogButtonBox::Save);
50 start_update_btn->setText("Start firmware update");
51 _firmware_update_btns.push_back(start_update_btn);
52
53 QVBoxLayout *layout = new QVBoxLayout;
54 layout->addWidget(_firmware_files_tree);
55 layout->addWidget(firmware_manager);
56 QHBoxLayout *layout_page = new QHBoxLayout;
57 QLabel *firmware_image=new QLabel;
58 QPixmap firmware_logo_pic;
59 firmware_logo_pic.load(":/icon/firmware.png");
60 firmware_image->setPixmap(firmware_logo_pic);
61 layout_page->addWidget(firmware_image);
62 layout_page->addLayout(layout);
63
64 QWizardPage *firmware_wizard_page = new QWizardPage();
65 firmware_wizard_page->setTitle("Firmware update wizard");
66 firmware_wizard_page->setLayout(layout_page);
67 this->addPage(firmware_wizard_page);
68 this->setFixedSize(layout_page->geometry().width(),layout_page->geometry().height());
69 this->setWindowFlags(Qt::Window);
70 this->setAttribute(Qt::WA_QuitOnClose,false);
71 };
72
74 };
75
76 std::vector<QPushButton *> get_firmware_update_btns(){
77 return _firmware_update_btns;
78 }
79
80 QStringList get_files_list(){
81 return _files_list;
82 }
83
84 void run_wizard(){
85 if(!this->isVisible()){
86 _firmware_files_tree->clear();
87 _files_list.clear();
88 }
89 this->close();
90 this->setWindowState(Qt::WindowActive);
91 this->show();
92 };
93
94private slots:
95 void onSelectFilesReleased(){
96
97 QStringList fileNames = QFileDialog::getOpenFileNames(
98 this,
99 "Select one or more files",
100 QDir::homePath(),
101 "Bin files (*.bin);;Config files (*.csv)");
102 for(const auto& file_path:fileNames){
103 if(!file_listed(file_path)){
104 QTreeWidgetItem * file_item = new QTreeWidgetItem();
105 file_item->setText(0,file_path);
106 _firmware_files_tree->addTopLevelItem(file_item);
107 _files_list.append(file_path);
108 }
109 }
110 };
111
112private:
113 QTreeWidget *_firmware_files_tree;
114 QStringList _files_list;
115 std::vector<QPushButton *> _firmware_update_btns;
116 bool file_listed(const QString &file_name){
117 for(int i=0;i<_firmware_files_tree->topLevelItemCount();i++){
118 auto topLevel =_firmware_files_tree->topLevelItem(i);
119 if(topLevel->text(0)==file_name){
120 return true;
121 }
122 }
123 return false;
124 };
125};
126
127class EcGuiStart : public QMainWindow
128{
129 Q_OBJECT
130
131public:
132
133 explicit EcGuiStart(QWidget *parent = nullptr);
134
135 ~EcGuiStart();
136
137private slots:
138 void onEcMasterProcessChanged(int index);
139 void onStartEtherCATSystem();
140 void onStopEtherCATSystem();
141 void onScanDeviceReleased();
142 void ExpertUserPassChanged();
143 void onFirmwareUpdateReleased();
144 void onFirmwareUpdateCopyFiles();
145 void onFirmwareUpdateOpenConfig();
146 void onFirmwareUpdateStart();
147 void onFirmwarewizardClosed(int ret);
148
149private:
150
151 EcGuiWrapper::ec_wrapper_info_t _ec_wrapper_info;
152 EcGuiWrapper::Ptr _ec_gui_wrapper;
153 EcGuiNet::Ptr _ec_gui_net;
154 QPushButton *_ec_sys_start,*_ec_sys_stop,*_firmware_update_btn;
155 QLabel *_ec_system_status;
156 bool _ec_sys_started;
157
158 QTreeWidget * _net_tree_wid;
159 QLineEdit *_expert_user;
160 EcGuiFirmware *_firmware_update_wizard;
161 QComboBox *_master_process_type;
162
163 void error_on_scannig();
164 void restart_gui();
165 void add_device();
166 void scan_device();
167 void read_sdo_info(const int32_t device_id,
168 const std::vector<std::string> sdo_name,
169 std::vector<float> &sdo_info);
170 void setup_motor_device(int32_t device_id,int32_t device_type);
171 void clear_device();
172 void clear_gui();
173 bool create_ec_iface();
174 void stopping_ec_sys();
175 void disable_ec_system();
176 void enable_ec_system();
177};
178
179#endif // EC_GUI_START_H
Definition ec_gui_start.h:16
Definition ec_gui_start.h:128
void setup_motor_device(int32_t device_id, int32_t device_type)
Definition ec_gui_start.cpp:391
Definition ec_gui_wrapper.h:22