forked from LazyT/rrcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.h
413 lines (354 loc) · 11.2 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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#define APPNAME "RoboRock Control Center"
#define APPVERS "0.8.2"
#define APPDATE "31.10.2018"
#include <QApplication>
#include <QMainWindow>
#include <QDesktopWidget>
#include <QTranslator>
#include <QLibraryInfo>
#include <QSettings>
#include <QMessageBox>
#include <QCloseEvent>
#include <QCryptographicHash>
#include <QUdpSocket>
#include <QTcpServer>
#include <QTcpSocket>
#include <QThread>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDateTime>
#include <QTimer>
#include <QNetworkInterface>
#include <QNetworkAccessManager>
#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"
#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_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'}"
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_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;
};
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
QMenu *menu_map_zones;
QByteArray did, cnt;
uint timediff;
QString src_ip;
QByteArray AESPayload(bool, QByteArray);
bool sendUDP(QString);
void parseJSON(int, QByteArray);
bool provisioning = false;
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;
QString ssh_user;
QString ssh_pass;
QString ssh_pkey;
QString ssh_pkpp;
QString ssh_auth;
bool flip_h;
bool flip_v;
bool swap_y;
int rotate;
QVector<CLEANZONE> zones;
}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 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;
}robo = {};
private:
QTranslator baseTranslator, helpTranslator, appTranslator;
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")
};
void getConfig();
void setConfig();
void findIP();
void getStatus();
void drawMapFromJson(QByteArray);
void getScale();
void setMatrix();
QDialog *logger;
QTimer timerMap, timerFanspeed;
QNetworkAccessManager *netmgr;
QGraphicsScene *scene;
QPoint drag_pos, rubber_pos;
QRect zone_preview_rect = {0, 0, 0, 0};
QGraphicsRectItem *zone_preview_item = NULL;
QMenu *menu_map, *menu_map_rotation, *menu_map_flipping;
QActionGroup *group_map;
QRubberBand *rubberBand;
qreal scale;
QSshSocket *ssh;
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_actionZones_triggered();
void on_actionValetudoInstall_triggered();
void on_actionValetudoUninstall_triggered();
void on_actionCheckFirmware_triggered();
void on_actionUpdateFirmware_triggered();
void on_actionHelp_triggered();
void on_actionAbout_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 timer_refreshMap();
void timer_setFanspeed();
void httpFinished(QNetworkReply*);
void hovered(QAction*);
void aboutToHide();
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