| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef TRKDEVICE_H
|
|---|
| 43 | #define TRKDEVICE_H
|
|---|
| 44 |
|
|---|
| 45 | #include "symbianutils_global.h"
|
|---|
| 46 | #include "callback.h"
|
|---|
| 47 |
|
|---|
| 48 | #include <QtCore/QObject>
|
|---|
| 49 | #include <QtCore/QVariant>
|
|---|
| 50 | #include <QtCore/QByteArray>
|
|---|
| 51 | #include <QtCore/QSharedPointer>
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 | class QIODevice;
|
|---|
| 55 | QT_END_NAMESPACE
|
|---|
| 56 |
|
|---|
| 57 | namespace trk {
|
|---|
| 58 |
|
|---|
| 59 | struct TrkResult;
|
|---|
| 60 | struct TrkMessage;
|
|---|
| 61 | struct TrkDevicePrivate;
|
|---|
| 62 |
|
|---|
| 63 | /* TrkDevice: Implements a Windows COM or Linux device for
|
|---|
| 64 | * Trk communications. Provides synchronous write and asynchronous
|
|---|
| 65 | * read operation.
|
|---|
| 66 | * The serialFrames property specifies whether packets are encapsulated in
|
|---|
| 67 | * "0x90 <length>" frames, which is currently the case for serial ports.
|
|---|
| 68 | * Contains a write message queue allowing
|
|---|
| 69 | * for queueing messages with a notification callback. If the message receives
|
|---|
| 70 | * an ACK, the callback is invoked.
|
|---|
| 71 | * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronization.
|
|---|
| 72 | * The respective message will not be sent, the callback is just invoked.
|
|---|
| 73 | * Note that calling open/close in quick succession can cause crashes
|
|---|
| 74 | * due to the use of queused signals. */
|
|---|
| 75 |
|
|---|
| 76 | enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
|
|---|
| 77 |
|
|---|
| 78 | typedef trk::Callback<const TrkResult &> TrkCallback;
|
|---|
| 79 |
|
|---|
| 80 | class SYMBIANUTILS_EXPORT TrkDevice : public QObject
|
|---|
| 81 | {
|
|---|
| 82 | Q_OBJECT
|
|---|
| 83 | Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)
|
|---|
| 84 | Q_PROPERTY(bool verbose READ verbose WRITE setVerbose)
|
|---|
| 85 | Q_PROPERTY(QString port READ port WRITE setPort)
|
|---|
| 86 | public:
|
|---|
| 87 | explicit TrkDevice(QObject *parent = 0);
|
|---|
| 88 | virtual ~TrkDevice();
|
|---|
| 89 |
|
|---|
| 90 | bool open(QString *errorMessage);
|
|---|
| 91 | bool isOpen() const;
|
|---|
| 92 |
|
|---|
| 93 | QString port() const;
|
|---|
| 94 | void setPort(const QString &p);
|
|---|
| 95 |
|
|---|
| 96 | QString errorString() const;
|
|---|
| 97 |
|
|---|
| 98 | bool serialFrame() const;
|
|---|
| 99 | void setSerialFrame(bool f);
|
|---|
| 100 |
|
|---|
| 101 | int verbose() const;
|
|---|
| 102 | void setVerbose(int b);
|
|---|
| 103 |
|
|---|
| 104 | // Enqueue a message with a notification callback.
|
|---|
| 105 | void sendTrkMessage(unsigned char code,
|
|---|
| 106 | TrkCallback callBack = TrkCallback(),
|
|---|
| 107 | const QByteArray &data = QByteArray(),
|
|---|
| 108 | const QVariant &cookie = QVariant());
|
|---|
| 109 |
|
|---|
| 110 | // Enqeue an initial ping
|
|---|
| 111 | void sendTrkInitialPing();
|
|---|
| 112 |
|
|---|
| 113 | // Send an Ack synchronously, bypassing the queue
|
|---|
| 114 | bool sendTrkAck(unsigned char token);
|
|---|
| 115 |
|
|---|
| 116 | public slots:
|
|---|
| 117 | void clearWriteQueue();
|
|---|
| 118 |
|
|---|
| 119 | signals:
|
|---|
| 120 | void messageReceived(const trk::TrkResult &result);
|
|---|
| 121 | // Emitted with the contents of messages enclosed in 07e, not for log output
|
|---|
| 122 | void rawDataReceived(const QByteArray &data);
|
|---|
| 123 | void error(const QString &msg);
|
|---|
| 124 | void logMessage(const QString &msg);
|
|---|
| 125 |
|
|---|
| 126 | private slots:
|
|---|
| 127 | void slotMessageReceived(const trk::TrkResult &result, const QByteArray &a);
|
|---|
| 128 |
|
|---|
| 129 | protected slots:
|
|---|
| 130 | void emitError(const QString &msg);
|
|---|
| 131 | void emitLogMessage(const QString &msg);
|
|---|
| 132 |
|
|---|
| 133 | public slots:
|
|---|
| 134 | void close();
|
|---|
| 135 |
|
|---|
| 136 | private:
|
|---|
| 137 | void readMessages();
|
|---|
| 138 | TrkDevicePrivate *d;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 | } // namespace trk
|
|---|
| 142 |
|
|---|
| 143 | #endif // TRKDEVICE_H
|
|---|