-
Notifications
You must be signed in to change notification settings - Fork 6
/
sessionmanager.h
150 lines (118 loc) · 3.12 KB
/
sessionmanager.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
/**
* \file
* <!--
* Copyright 2015 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \brief SessionManager class header
*
* \author Aurelien Rainone <aurelien@develer.com>
*/
#ifndef SESSIONMANAGER_H
#define SESSIONMANAGER_H
#include "connectdialog.h"
#include "filetransfer.h"
#include <QObject>
#include <QSerialPort>
class FileTransfer;
/**
* \brief manage serial port session
*/
class SessionManager : public QObject
{
Q_OBJECT
public:
/**
* \brief file transfer protocols and variants
*/
enum Protocol
{
XMODEM = 1,
YMODEM = 10,
ZMODEM = 100
};
private:
/// serial port instance
QSerialPort *serial;
/// current session configuration
QHash<QString, QString> curr_cfg;
/// indicate that a connection has been initiated or is in progress
bool in_progress;
/// file transfer implementation
FileTransfer *file_transfer;
public:
explicit SessionManager(QObject *parent = 0);
~SessionManager();
/**
* \brief open a serial port session
* \param port_cfg serial port settings
*/
void openSession(const QHash<QString, QString> &port_cfg);
/**
* \brief close current serial port session
*/
void closeSession();
/**
* \brief return true if the session is active
*/
bool isSessionOpen() const;
/**
* \brief send data to serial port
* \param data byte array data
*/
void sendToSerial(const QByteArray &data);
/**
* \brief init a file transfer thread
* \param filename file to transfer
* \param type protocol to use
*/
void transferFile(const QString &filename, Protocol type);
/**
* \brief handle file transfer cancelation signal
*/
void handleTransferCancelledByUser();
private:
/**
* \brief read data from serial port
*/
void readData();
/**
* \brief save given data to configured dump file
*/
void saveToFile(const QByteArray &data);
/**
* \brief handle serial port error
*/
void handleError(QSerialPort::SerialPortError serialPortError);
/**
* \brief handle FileTransfer::transferEnded signal
* \param error transfer end error code
*/
void handleFileTransferEnded(FileTransfer::TransferError error);
signals:
/**
* \brief signal emitted when a new session is opened
*/
void sessionOpened();
/**
* \brief signal emitted when current has been closed
*/
void sessionClosed();
/**
* \brief signal emitted when new data has been received from the serial port
* \param data byte array data
*/
void dataReceived(const QByteArray &data);
/**
* \brief signal emitted when file transfer has ended
* \param error transfer end error code
*/
void fileTransferEnded(FileTransfer::TransferError error);
/**
* \brief signal emitted each time the file transfer progresses
* (minimum amount to emit is 1% progress)
* \percent percentage of file transfered
*/
void fileTransferProgressed(int percent);
};
#endif // SESSIONMANAGER_H