propellermanager.h
1 #pragma once
2 
3 #include <QTimer>
4 #include <QStringList>
5 #include <QHash>
6 
7 #include "../device/propellerdevice.h"
8 #include "../session/propellersession.h"
9 #include "../session/readbuffer.h"
10 
83 class PropellerSession;
84 
85 
86 class PropellerManager : public QObject
87 {
88  Q_OBJECT
89 
90 private:
91  QTimer portMonitor;
92  QStringList _ports;
93  QHash<QString, PropellerDevice *> _devices;
94  QHash<PropellerDevice *, quint32> _active_sessions;
95  QHash<PropellerDevice *, PropellerSession *> _busy;
96  QHash<PropellerSession *, PropellerSession *> _paused;
97  QHash<PropellerSession *, PropellerSession *> _sessions;
98 
99  QHash<PropellerSession *, PropellerDevice *> _connections;
100  QHash<PropellerSession *, PropellerDevice *> _saved_connections;
101 
102  QHash<PropellerSession *, ReadBuffer *> _buffers;
103 
104  void attach(PropellerSession * session, PropellerDevice * device);
105  void attachByName(PropellerSession * session, const QString & port);
106  void detach(PropellerSession * session, PropellerDevice * device);
107  bool portIsBusy(PropellerSession * session, const QString & name);
108 
109  PropellerDevice * getDevice(const QString & port, bool open = true);
110  void deleteDevice(const QString & port);
111 
112 private slots:
113  void readyBuffer();
114  void checkPorts();
115 
116 public:
117  PropellerManager(QObject *parent = 0);
119 
120  const QStringList & listPorts();
121  void enablePortMonitor(bool enabled);
122 
124 
125  bool beginSession(PropellerSession * session);
126  void endSession(PropellerSession * session);
127 
128  bool isOpen(PropellerSession * session, const QString & port);
129  bool clear(PropellerSession * session, const QString & port);
130 
131  bool setBaudRate(PropellerSession * session, const QString & port, quint32 baudRate);
132 
133  qint64 bytesToWrite(PropellerSession * session, const QString & port);
134  qint64 bytesAvailable(PropellerSession * session, const QString & port);
135 
136  QByteArray read(PropellerSession * session, const QString & port, qint64 maxSize);
137  QByteArray readAll(PropellerSession * session, const QString & port);
138 
139  bool putChar(PropellerSession * session, const QString & port, char c);
140  qint64 write(PropellerSession * session, const QString & port, const QByteArray & byteArray);
141  QString errorString(PropellerSession * session, const QString & port);
142  int error(PropellerSession * session, const QString & port);
143 
144  quint32 minimumTimeout(PropellerSession * session, const QString & port);
145  void setMinimumTimeout(PropellerSession * session, const QString & port, quint32 milliseconds);
146  quint32 calculateTimeout(PropellerSession * session, const QString & port, quint32 bytes);
147  void useReset(PropellerSession * session, const QString & port, const QString & name, int pin);
148  void useDefaultReset(PropellerSession * session, const QString & port);
149  bool reset(PropellerSession * session, const QString & port);
150  quint32 resetPeriod(PropellerSession * session, const QString & port);
151 
152  bool reserve(PropellerSession * session, const QString & port);
153  bool isReserved(PropellerSession * session, const QString & port);
154  void release(PropellerSession * session, const QString & port);
155 
156  void pause(PropellerSession * session);
157  bool isPaused(PropellerSession * session);
158  void unpause(PropellerSession * session);
159 
161 
162 signals:
163  void portListChanged();
164 };
const QStringList & listPorts()
Definition: propellermanager.cpp:160
void enablePortMonitor(bool enabled)
Definition: propellermanager.cpp:165
~PropellerManager()
Definition: propellermanager.cpp:14
The PropellerManager class provides an abstraction layer between PropellerSession and PropellerDevice...
Definition: propellermanager.h:86
The PropellerSession class provides a persistent interface to Propeller hardware via PropellerManager...
Definition: propellersession.h:43
The PropellerDevice class provides access to serial Propeller devices.
Definition: propellerdevice.h:17
void portListChanged()
PropellerManager(QObject *parent=0)
Definition: propellermanager.cpp:8