-
Notifications
You must be signed in to change notification settings - Fork 0
/
sioworker.h
executable file
·102 lines (81 loc) · 2.28 KB
/
sioworker.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
#ifndef SIOWORKER_H
#define SIOWORKER_H
#include <QThread>
#include <QMutex>
#include "serialport.h"
class SioWorker;
class SioDevice : public QObject
{
Q_OBJECT
protected:
int m_deviceNo;
QMutex mLock;
SioWorker *sio;
public:
SioDevice(SioWorker *worker);
virtual ~SioDevice();
virtual void handleCommand(quint8 command, quint16 aux) = 0;
virtual QString deviceName();
inline void lock() {mLock.lock();}
inline bool tryLock() {return mLock.tryLock();}
inline void unlock() {mLock.unlock();}
inline void setDeviceNo(int no) {emit statusChanged(m_deviceNo); m_deviceNo = no; emit statusChanged(no);}
inline int deviceNo() const {return m_deviceNo;}
signals:
void statusChanged(int deviceNo);
};
class SioWorker : public QThread
{
Q_OBJECT
private:
quint8 sioChecksum(const QByteArray &data, uint size);
QMutex *deviceMutex;
SioDevice* devices[256];
AbstractSerialPortBackend *mPort;
bool mustTerminate;
public:
AbstractSerialPortBackend* port() {return mPort;}
int maxSpeed;
SioWorker();
~SioWorker();
bool wait (unsigned long time = ULONG_MAX);
void run();
void installDevice(quint8 no, SioDevice *device);
void uninstallDevice(quint8 no);
void swapDevices(quint8 d1, quint8 d2);
SioDevice* getDevice(quint8 no);
QString deviceName(int device);
static void usleep(unsigned long time) {QThread::usleep(time);}
signals:
void statusChanged(QString status);
public slots:
void start(Priority p = InheritPriority);
};
class CassetteRecord {
public:
int baudRate;
int gapDuration;
int totalDuration;
QByteArray data;
};
class CassetteWorker : public QThread
{
Q_OBJECT
private:
QMutex mustTerminate;
AbstractSerialPortBackend *mPort;
QList<CassetteRecord> mRecords;
public:
AbstractSerialPortBackend* port() {return mPort;}
CassetteWorker();
~CassetteWorker();
bool loadCasImage(const QString &fileName);
bool wait (unsigned long time = ULONG_MAX);
void run();
int mTotalDuration;
signals:
void statusChanged(int remainingTime);
public slots:
void start(Priority p = InheritPriority);
};
#endif // SIOWORKER_H