00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ASPECT_MCUCMD_H
00013 #define ASPECT_MCUCMD_H
00014
00015
00016 #include "mcuserial.h"
00017
00018 #include <QByteArray>
00019 #include <QString>
00020
00021
00022 class Cmd
00023 {
00024 public:
00025 Cmd() { m_aCmd.clear(); };
00026 Cmd(const char *szCmd) { m_aCmd.clear(); str(szCmd); };
00027
00028 Cmd &raw(const QByteArray &aCmd);
00029 Cmd &str(const char *szCmd);
00030 Cmd &num(int nData);
00031 Cmd &byte(int nData);
00032 Cmd &word(int nData);
00033 Cmd &real(float fData);
00034
00035 QByteArray command() const { return m_aCmd; };
00036
00037 private:
00038 QByteArray m_aCmd;
00039 };
00040
00041
00042 class Ans
00043 {
00044 public:
00045 QByteArray answer() const { return m_aAns; };
00046 int byte(int nIx) const;
00047 int word(int nIx) const;
00048 float real(int nIx) const;
00049
00050 protected:
00051 QByteArray m_aAns;
00052 };
00053
00054
00055 class McuCom : public IMcuCmdAns, public Ans
00056 {
00057 public:
00058 McuCom(const char *szName, const Cmd &oCmd)
00059 : m_qsName(QString::fromUtf8(szName)), m_aCmd(oCmd.command()) {};
00060 bool send(const McuSerial &oPort, int nTimeout = 200);
00061
00062 private:
00063 QString name() const { return m_qsName; };
00064 QByteArray command() const { return m_aCmd; };
00065
00066 protected:
00067 QString m_qsName;
00068 QByteArray m_aCmd;
00069 };
00070
00071
00072 class McuAns : public IMcuAns, public Ans
00073 {
00074 public:
00075 McuAns(const char *szName, int nAnsMin, int nAnsMax)
00076 : m_qsName(QString::fromUtf8(szName)),
00077 m_nAnsMin(nAnsMin), m_nAnsMax(nAnsMax) {};
00078
00079 private:
00080 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00081 QString name() const { return m_qsName; };
00082
00083 protected:
00084 QString m_qsName;
00085 int m_nAnsMin;
00086 int m_nAnsMax;
00087 };
00088
00089
00090 class McuCmdVoid : public McuCom
00091 {
00092 public:
00093 McuCmdVoid(const char *szName, const Cmd &oCmd)
00094 : McuCom(szName, oCmd) {};
00095
00096 private:
00097 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00098 };
00099
00100
00101 class McuCmdStd : public McuCom
00102 {
00103 public:
00104 McuCmdStd(const char *szName, const Cmd &oCmd)
00105 : McuCom(szName, oCmd), m_bSuccess(true) {};
00106 bool success() const;
00107
00108 private:
00109 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00110
00111 protected:
00112 bool m_bSuccess;
00113 };
00114
00115
00116 class McuCmdBool : public McuCom
00117 {
00118 public:
00119 McuCmdBool(const char *szName, const Cmd &oCmd, char cSuccess = '0')
00120 : McuCom(szName, oCmd), m_cSuccess(cSuccess) {};
00121 bool success() const;
00122 QString errorReason() const;
00123
00124 private:
00125 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00126
00127 protected:
00128 char m_cSuccess;
00129 };
00130
00131
00132 class McuCmdString : public McuCom
00133 {
00134 public:
00135 McuCmdString(const char *szName, const Cmd &oCmd)
00136 : McuCom(szName, oCmd) {};
00137
00138 private:
00139 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00140 };
00141
00142
00143 class McuCmdFixed : public McuCom
00144 {
00145 public:
00146 McuCmdFixed(const char *szName, const Cmd &oCmd, int nAnsLen)
00147 : McuCom(szName, oCmd), m_nAnsLen(nAnsLen) {};
00148
00149 private:
00150 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00151
00152 protected:
00153 int m_nAnsLen;
00154 };
00155
00156
00157 class McuCmdQueryUnlimited : public McuCom
00158 {
00159 public:
00160 McuCmdQueryUnlimited(const char *szName, const Cmd &oCmd, int nAnsMin)
00161 : McuCom(szName, oCmd), m_nAnsMin(nAnsMin) {};
00162
00163 private:
00164 void receive(int &rnMin, int &rnMax, const QByteArray &aAnswerFragment);
00165
00166 protected:
00167 int m_nAnsMin;
00168 };
00169
00170
00171 #endif // ASPECT_MCUCMD_H
00172