forked from LazyT/rrcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.h
498 lines (429 loc) · 13.3 KB
/
mainwindow.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#define APPNAME "RoboRock Control Center"
#define APPVERS "0.8.8"
#define APPDATE "25.01.2020"
#define FW_NAME_G1 "v11_00????.fullos.pkg"
#define FW_NAME_G2 "v11_00????.fullos.pkg"
#define FW_NAME_G3 "t6_????.fullos.pkg"
#define FW_DIR_G1 "updpkg"
#define FW_DIR_G2 "rubys/updpkg"
#define FW_DIR_G3 "tanos/updpkg"
#define FW_VER_G1 3468
#define FW_VER_G2 1768
#define FW_VER_G3 412
#include <QApplication>
#include <QMainWindow>
#include <QScreen>
#include <QTranslator>
#include <QLibraryInfo>
#include <QSettings>
#include <QMessageBox>
#include <QCloseEvent>
#include <QCryptographicHash>
#include <QUdpSocket>
#include <QTcpServer>
#include <QTcpSocket>
#include <QWebSocket>
#include <QThread>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDateTime>
#include <QTimer>
#include <QNetworkInterface>
#include <QNetworkAccessManager>
#include <QAuthenticator>
#include <QNetworkReply>
#include <QFileDialog>
#include <QStandardPaths>
#include <QClipboard>
#include <QDesktopServices>
#include <QGraphicsPixmapItem>
#include <QScrollBar>
#include <QToolTip>
#include <QDebug>
#include "ccryptlib.h"
#include "qaesencryption.h"
#include "qarchive.h"
#include "qsshsocket.h"
#include "ui_mainwindow.h"
#include "logger.h"
#include "setup.h"
#include "history.h"
#include "timer.h"
#include "upload.h"
#include "update.h"
#include "packager.h"
#include "unpackager.h"
#include "converter.h"
#include "about.h"
#include "zones.h"
#include "installer.h"
#include "uninstaller.h"
#include "download.h"
#include "search.h"
#include "onlineupd.h"
#define CFG_H QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.rrcc/rrcc.cfg"
#define CFG_P QCoreApplication::applicationDirPath() + "/rrcc.cfg"
#define LOG QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/rrcc.log"
#define TGZ QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/rrcc.tgz"
#define PKG QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/rrcc.pkg"
#define PKG_KEY "r0ckrobo#23456"
#define TIMEOUT 2500
#define MAPSIZE 51200 // 51200 x 51200
#define MAPFACTOR 12.5 // MAPSIZE : 4096
#define WORKTIME_MAINBRUSH 1080000 // 300h
#define WORKTIME_SIDEBRUSH 720000 // 200h
#define WORKTIME_FILTER 540000 // 150h
#define WORKTIME_SENSOR 108000 // 30h
#define MIIO_HELLO "21310020ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
#define MIIO_FIND_ME "{'id':%1,'method':'find_me'}"
#define MIIO_APP_START "{'id':%1,'method':'app_start'}"
#define MIIO_APP_STOP "{'id':%1,'method':'app_stop'}"
#define MIIO_APP_PAUSE "{'id':%1,'method':'app_pause'}"
#define MIIO_APP_CHARGE "{'id':%1,'method':'app_charge'}"
#define MIIO_APP_SPOT "{'id':%1,'method':'app_spot'}"
#define MIIO_APP_ZONED_CLEAN "{'id':%6,'method':'app_zoned_clean','params':[[%1,%2,%3,%4,%5]]}"
#define MIIO_GET_SERIAL_NUMBER "{'id':%1,'method':'get_serial_number'}"
#define MIIO_GET_CONSUMABLE "{'id':%1,'method':'get_consumable'}"
#define MIIO_RESET_CONSUMABLE "{'id':%2,'method':'reset_consumable','params':['%1']}"
#define MIIO_GET_STATUS "{'id':%1,'method':'get_status'}"
#define MIIO_GET_CLEAN_SUMMARY "{'id':%1,'method':'get_clean_summary'}"
#define MIIO_GET_CLEAN_RECORD "{'id':%2,'method':'get_clean_record','params':[%1]}"
#define MIIO_SET_CUSTOM_MODE "{'id':%2,'method':'set_custom_mode','params':[%1]}"
#define MIIO_GET_TIMER "{'id':%1,'method':'get_timer'}"
#define MIIO_SET_TIMER "{'id':%4,'method':'set_timer','params':[['%1',['%2',['start_clean',%3]]]]}"
#define MIIO_UPD_TIMER "{'id':%3,'method':'upd_timer','params':['%1','%2']}"
#define MIIO_DEL_TIMER "{'id':%2,'method':'del_timer','params':['%1']}"
#define MIIO_GET_DND_TIMER "{'id':%1,'method':'get_dnd_timer'}"
#define MIIO_SET_DND_TIMER "{'id':%2,'method':'set_dnd_timer','params':[%1]}"
#define MIIO_CLOSE_DND_TIMER "{'id':%1,'method':'close_dnd_timer'}"
#define MIIO_GET_SOUND_VOLUME "{'id':%1,'method':'get_sound_volume'}"
#define MIIO_CHANGE_SOUND_VOLUME "{'id':%2,'method':'change_sound_volume','params':[%1]}"
#define MIIO_TEST_SOUND_VOLUME "{'id':%1,'method':'test_sound_volume'}"
#define MIIO_GET_CURRENT_SOUND "{'id':%1,'method':'get_current_sound'}"
#define MIIO_DNLD_INSTALL_SOUND "{'id':%4,'method':'dnld_install_sound','params':{'url':'%1','md5':'%2','sid':%3}}"
#define MIIO_GET_SOUND_PROGRESS "{'id':%1,'method':'get_sound_progress'}"
#define MIIO_GET_CARPET_MODE "{'id':%1,'method':'get_carpet_mode'}"
#define MIIO_SET_CARPET_MODE "{'id':%6,'method':'set_carpet_mode','params':[{'enable':%1,'current_integral':%2,'current_high':%3,'current_low':%4,'stall_time':%5}]}"
#define MIIO_APP_GOTO_TARGET "{'id':%3,'method':'app_goto_target','params':[%1,%2]}"
#define MIIO_SET_LAB_STATUS "{'id':%2,'method':'set_lab_status','params':[%1]}"
#define MIIO_SAVE_MAP "{'id':%2,'method':'save_map','params':[%1]}"
#define MIIO_CONFIG_ROUTER "{'id':%3,'method':'miIO.config_router','params':{'ssid':'%1','passwd':'%2','uid':null}}"
#define MIIO_OTA "{'id':%3,'method':'miIO.ota','params':{'mode':'normal','install':'1','app_url':'%1','file_md5':'%2','proc':'dnld install'}}"
#define MIIO_GET_OTA_STATE "{'id':%1,'method':'miIO.get_ota_state'}"
#define MIIO_GET_OTA_PROGRESS "{'id':%1,'method':'miIO.get_ota_progress'}"
#define SSH_GET_FIRMWARE_VERSION "egrep RO[BC][OK]RO[CB][KO]_VERSION /etc/os-release"
#define SSH_GET_VALETUDO_VERSION "fgrep -a -m1 -A1 '\"name\": \"valetudo' /usr/local/bin/valetudo"
enum {MIIO_ID_HELLO, MIIO_ID_APP_START, MIIO_ID_APP_STOP, MIIO_ID_APP_PAUSE, MIIO_ID_APP_CHARGE, MIIO_ID_APP_SPOT, MIIO_ID_APP_ZONED_CLEAN, MIIO_ID_FIND_ME, MIIO_ID_GET_SERIAL_NUMBER, MIIO_ID_GET_CONSUMABLE, MIIO_ID_RESET_CONSUMABLE, MIIO_ID_GET_STATUS, MIIO_ID_GET_CLEAN_SUMMARY, MIIO_ID_GET_CLEAN_RECORD, MIIO_ID_SET_CUTOM_MODE, MIIO_ID_GET_TIMER, MIIO_ID_SET_TIMER, MIIO_ID_UPD_TIMER, MIIO_ID_DEL_TIMER, MIIO_ID_GET_DND_TIMER, MIIO_ID_SET_DND_TIMER, MIIO_ID_CLOSE_DND_TIMER, MIIO_ID_GET_SOUND_VOLUME, MIIO_ID_CHANGE_SOUND_VOLUME, MIIO_ID_TEST_SOUND_VOLUME, MIIO_ID_GET_CURRENT_SOUND, MIIO_ID_DNLD_INSTALL_SOUND, MIIO_ID_GET_SOUND_PROGRESS, MIIO_ID_GET_CARPET_MODE, MIIO_ID_SET_CARPET_MODE, MIIO_ID_APP_GOTO_TARGET, MIIO_ID_SET_LAB_STATUS, MIIO_ID_SAVE_MAP, MIIO_ID_CONFIG_ROUTER, MIIO_ID_OTA, MIIO_ID_GET_OTA_STATE, MIIO_ID_GET_OTA_PROGRESS};
enum {AES_ENCRYPT, AES_DECRYPT};
enum {FANSPEED_QUIET = 38, FANSPEED_BALANCED = 60, FANSPEED_TURBO = 77, FANSPEED_MAXIMUM = 90};
struct TIMER
{
QString id;
QString state;
QString crontab;
QString command;
int fanspeed;
};
struct CLEANZONE
{
QString label;
int x1;
int y1;
int x2;
int y2;
int times;
};
struct NOGOZONE
{
int x1;
int y1;
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
};
struct VIRTWALL
{
int x1;
int y1;
int x2;
int y2;
};
struct GOTO
{
QString label;
int x;
int y;
};
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
bool sendUDP(QString);
void parseJSON(int, QByteArray);
void drawFlags(bool, bool);
QMenu *menu_map_zones, *menu_map_gotos;
QByteArray did, cnt;
uint timediff;
QString src_ip;
QByteArray AESPayload(bool, QByteArray);
bool provisioning = false;
bool forceclose = false;
QGraphicsScene *scene;
QPointF pos_flag;
QRect zone_preview_rect = {0, 0, 0, 0};
QGraphicsRectItem *zone_preview_item = nullptr;
QStringList qarchive_error_strings
{
tr("No error"),
tr("Archive has bad data"),
tr("Archive does not exist or no permission"),
tr("Unknown error"),
tr("Fatal error"),
tr("Wrong password for archive"),
tr("Empty password for archive"),
tr("Cannot create archive"),
tr("Cannot open added file"),
tr("Cannot read added file"),
tr("Cannot find extraction destination"),
tr("File does not exists"),
tr("Extraction destination invalid"),
tr("Memory allocation failed"),
tr("Cannot open existing file")
};
QStringList ssh_error_strings
{
"SocketError",
"SessionCreationError",
"ChannelCreationError",
"ScpChannelCreationError",
"ScpPullRequestError",
"ScpPushRequestError",
"ScpFileNotCreatedError",
"ScpReadError",
"ScpWriteError",
"PasswordAuthenticationFailedError",
"KeyAuthenticationFailedError"
};
struct CONFIG
{
QString ip;
QString token;
qlonglong msgid;
bool map;
bool websocket;
bool update;
QString ssh_user;
QString ssh_pass;
QString ssh_pkey;
QString ssh_pkpp;
QString ssh_auth;
QString valetudo_user;
QString valetudo_pass;
bool flip_h;
bool flip_v;
bool swap_x;
bool swap_y;
int rotate;
QVector<CLEANZONE> zones;
QVector<GOTO> gotos;
}cfg;
struct ROBO
{
QString serial_number;
struct CONSUMABLE
{
int main_brush_work_time;
int side_brush_work_time;
int filter_work_time;
int sensor_dirty_time;
}consumable;
struct STATUS
{
int msg_ver;
int msg_seq;
int state;
int battery;
int clean_time;
int clean_area;
int error_code;
int map_present;
int in_cleaning;
int in_returning;
int in_fresh_state;
int lab_status;
int fan_power;
int dnd_enabled;
}status;
struct CLEANSUMMARY
{
int time;
int area;
int count;
QVector<int> id;
}cleansummary;
struct CLEANRECORD
{
int begin;
int finish;
int duration;
int area;
int error;
int complete;
}cleanrecord;
QVector<TIMER> timers;
struct DND
{
int enabled;
int start_hour;
int start_minute;
int end_hour;
int end_minute;
}dnd;
struct CARPETMODE
{
int enable;
int current_integral;
int current_high;
int current_low;
int stall_time;
}carpetmode;
int volume;
struct CURRENTSOUND
{
QString bom;
QString language;
QString location;
int msg_ver;
int sid_in_progress;
int sid_in_use;
int sid_version;
}currentsound;
struct SOUNDPROGRESS
{
int error;
int progress;
int sid_in_progress;
int state;
}soundprogress;
struct OTA
{
QString state;
int progress;
}ota;
QVector<VIRTWALL> virtwalls;
QVector<NOGOZONE> nogozones;
}robo = {};
private:
QStringList state_strings
{
tr("Starting"),
tr("Charger disconnected"),
tr("Idle"),
tr("Remote control active"),
tr("Cleaning"),
tr("Returning home"),
tr("Manual mode"),
tr("Charging"),
tr("Charging problem"),
tr("Paused"),
tr("Spot cleaning"),
tr("Error"),
tr("Shutting down"),
tr("Updating"),
tr("Docking"),
tr("Going to target"),
tr("Zoned cleaning")
};
QTranslator baseTranslator, helpTranslator, appTranslator;
QCommandLineParser cmd;
QDialog *logger;
QDialog *upddlg = nullptr;
QTimer timerMap, timerFanspeed;
QNetworkAccessManager *netmgr;
QWebSocket *websocket;
QPoint drag_pos, rubber_pos;
QGraphicsPixmapItem *png_flag = nullptr, *png_flag_lt = nullptr, *png_flag_rt = nullptr, *png_flag_lb = nullptr, *png_flag_rb = nullptr;
QPointF pos_flag_lt, pos_flag_rt, pos_flag_lb, pos_flag_rb;
QMenu *menu_map, *menu_map_rotation, *menu_map_flipping, *menu_map_swapping;
QMenu *menu_map_delete;
QActionGroup *group_map;
QRubberBand *rubberBand;
qreal scale;
QSshSocket *ssh;
QString ssh_cmd;
void getConfig();
void setConfig();
void findIP();
void getStatus();
void drawMapFromJson(QByteArray);
void drawMapFromJsonOld(QByteArray);
void getScale();
void setMatrix();
public slots:
void hoveredGoto(QAction*);
void hoveredZone(QAction*);
void aboutToHideGoto();
void aboutToHideZone();
private slots:
void on_actionExit_triggered();
void on_actionRefresh_triggered();
void on_actionMap_toggled(bool);
void on_actionSetup_triggered();
void on_actionLogger_triggered();
void on_actionTimer_triggered();
void on_actionHistory_triggered();
void on_actionEditor_triggered();
void on_actionValetudoVersion_triggered();
void on_actionValetudoInstall_triggered();
void on_actionValetudoUninstall_triggered();
void on_actionCheckFirmware_triggered();
void on_actionSearchFirmware_triggered();
void on_actionDownloadFirmware_triggered();
void on_actionUpdateFirmware_triggered();
void on_actionHelp_triggered();
void on_actionAbout_triggered();
void on_actionOnlineUpdate_triggered();
void on_toolButton_Dock_clicked();
void on_toolButton_Start_clicked();
void on_toolButton_Spot_clicked();
void on_toolButton_Pause_clicked();
void on_toolButton_Stop_clicked();
void on_toolButton_Find_clicked();
void on_toolButton_Fanspeed1_clicked();
void on_toolButton_Fanspeed2_clicked();
void on_toolButton_Fanspeed3_clicked();
void on_toolButton_Fanspeed4_clicked();
void on_toolButton_Mainbrush_clicked();
void on_toolButton_Sidebrush_clicked();
void on_toolButton_Filter_clicked();
void on_toolButton_Sensors_clicked();
void on_dial_valueChanged(int);
void on_doubleSpinBox_Zoom_valueChanged(double);
void timer_refreshMap();
void timer_setFanspeed();
void httpAuthenticationRequired(QNetworkReply*, QAuthenticator*);
void httpFinished(QNetworkReply*);
void websocketTextMessageReceived(QString);
void websocketError(QAbstractSocket::SocketError);
void ssh_connected();
void ssh_disconnected();
void ssh_error(QSshSocket::SshError);
void ssh_loginSuccessful();
void ssh_commandExecuted(QString, QString);
void resizeEvent(QResizeEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void wheelEvent(QWheelEvent*);
void contextMenuEvent(QContextMenuEvent*);
void keyPressEvent(QKeyEvent*);
void closeEvent(QCloseEvent*);
};
#endif // MAINWINDOW_H