-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflasher.h
69 lines (54 loc) · 1.5 KB
/
flasher.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
#ifndef FLASHER_H
#define FLASHER_H
#include <QObject>
#include <QFile>
#include <QSerialPort>
#include <stdint.h>
#include "config.h"
// simplify the bytes to words translation
typedef union {
uint16_t w;
uint8_t b[2];
}W2B;
class Flasher : public QObject
{
Q_OBJECT
public:
enum PROTOCOLS {
CAN_STYLE_PROTO, OLD_PROTO
};
enum BOOT_MODE {
NORMAL_MODE, BRIDGE_MODE
};
explicit Flasher(QObject *parent = 0);
QSerialPort *serial;
void setPortName(QString port_name);
void setProtocol(PROTOCOLS proto);
void setBootMode(BOOT_MODE boot_mode);
qint64 getReadedBytes();
public slots:
bool go_boot();
bool leave_boot();
QString get_status(bool open_serial = true);
void send_flash_from_file(QString hexFilePath, int page_size);
signals:
void changeProgress(int percent);
void finished();
void infoCritical(QString title, QString info);
void infoWarning(QString title, QString info);
void infoInfo(QString title, QString info);
void infoDebug(QString info);
private:
QString port_name;
PROTOCOLS protocol_type;
BOOT_MODE boot_mode;
qint64 readed;
bool send_address(uint16_t addressW);
bool erase_chip();
bool send_checksumm(uint16_t ck1, uint16_t ck2);
bool openSerialPort(QString port_name);
void closeSerialPort();
};
Q_DECLARE_METATYPE(Flasher::PROTOCOLS)
Q_DECLARE_METATYPE(Flasher::BOOT_MODE)
#endif // FLASHER_H