mcuserial.h

00001 
00002 /***************************************************************************
00003  *   This file is part of Aspect, a simple PEC tool.                       *
00004  *                                                                         *
00005  *   Copyright (C) 2006-2007 by Wolfgang Hoffmann <woho@woho.de>           *
00006  *                                                                         *
00007  *   This program is free software, licensed under the GPL v2.             *
00008  *   See the file COPYING for more details.                                *
00009  ***************************************************************************/
00010 
00011 
00012 #ifndef ASPECT_MCUSERIAL_H
00013 #define ASPECT_MCUSERIAL_H
00014 
00015 
00016 #include <QObject>
00017 
00018 
00019 class QextSerialPort;
00020 class QString;
00021 
00022 
00023 class IMcuCmd
00024     {
00025 public:
00026     virtual ~IMcuCmd() {};
00027 private:
00028     virtual QByteArray command() const = 0;
00029     virtual QString name() const = 0;
00030 friend class McuSerial;
00031     };
00032 
00033 class IMcuAns
00034     {
00035 public:
00036     virtual ~IMcuAns() {};
00037 private:
00038     virtual void receive(int &rnMin, int &rnMax,
00039         const QByteArray &aAnswerFragment) = 0;
00040     virtual QString name() const = 0;
00041 friend class McuSerial;
00042     };
00043 
00044 class IMcuCmdAns: public IMcuCmd, public IMcuAns
00045     {
00046 public:
00047     virtual ~IMcuCmdAns() {};
00048     };
00049 
00050 
00051 class McuSerial : public QObject
00052     {
00053     Q_OBJECT
00054 
00055 public:
00056     enum Status { unknown, error, cmd_ok, ans_ok };
00057 
00058     McuSerial();
00059     virtual ~McuSerial();
00060 
00061     bool open(const QString &qsPort);
00062     void close();
00063 
00064     bool send(IMcuCmd *pCmd);
00065     bool recv(IMcuAns *pAns, int nTimeout = 200);
00066     void flush();
00067 
00068     static void msleep(int nMsecs);
00069 
00070 signals:
00071     void status(bool bOpen, McuSerial::Status eStatus);
00072 
00073 private:
00074     static QString hex(const QByteArray &aData);
00075 
00076 private:
00077     QextSerialPort *m_pSerPort;
00078     bool m_bOpen;
00079     Status m_eStatus;
00080     QString m_qsLastCmd;
00081     };
00082 
00083 
00084 #endif // ASPECT_MCUSERIAL_H
00085 

Generated on Sun Jun 3 16:45:46 2007 for Aspect by  doxygen 1.5.1