mcuproxy.h

00001 
00002 /***************************************************************************
00003  *   This file is part of Aspect, a simple PEC tool.                       *
00004  *                                                                         *
00005  *   Copyright (C) 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_MCUPROXY_H
00013 #define ASPECT_MCUPROXY_H
00014 
00015 
00016 #include "data.h"
00017 #include "mcuserial.h"
00018 
00019 #include <QByteArray>
00020 #include <QObject>
00021 #include <QString>
00022 #include <QTime>
00023 
00024 
00025 class McuDataFirmware
00026     {
00027 public:
00028     McuDataFirmware() : m_nMajor(0), m_nMinor(0) {};
00029     void setFirmware(const QByteArray &aFirmware);
00030     void setUnknown() { m_aFirmware.clear(); };
00031     bool unknown() const { return (m_aFirmware.size() == 0); };
00032     QString firmware() const { return QString::fromLatin1(m_aFirmware); };
00033     int version() const { return m_nMajor * 100 + m_nMinor; };
00034 private:
00035     QByteArray m_aFirmware;
00036     int m_nMajor;
00037     int m_nMinor;
00038     };
00039 
00040 class McuDataKeys
00041     {
00042 public:
00043     McuDataKeys() : m_nSerial(-1), m_bKeyGoto(false), m_bKeyIntelly(false) {};
00044     void setSerial(int nSerial) { m_nSerial = nSerial; };
00045     void setKeyGoto(bool bGoto) { m_bKeyGoto = bGoto; };
00046     void setKeyIntelly(bool bIntelly) { m_bKeyIntelly = bIntelly; };
00047     int serial() const { return m_nSerial; };
00048     bool keyGoto() const { return m_bKeyGoto; };
00049     bool keyIntelly() const { return m_bKeyIntelly; };
00050 private:
00051     int m_nSerial;
00052     bool m_bKeyGoto;
00053     bool m_bKeyIntelly;
00054     };
00055 
00056 class McuDataBacklash
00057     {
00058 public:
00059     enum MethodRa { noneRa = 0, finishLeft = 1, finishRight = 2 };
00060     enum MethodDe { noneDe = 0, finishUp = 1, finishDown = 2 };
00061     void setMethodRa(MethodRa eMethod) { m_eMethodRa = eMethod; };
00062     void setValueRa(int nValue) { m_nValueRa = nValue; };
00063     void setMethodDe(MethodDe eMethod) { m_eMethodDe = eMethod; };
00064     void setValueDe(int nValue) { m_nValueDe = nValue; };
00065     MethodRa methodRa() const { return m_eMethodRa; };
00066     int valueRa() const { return m_nValueRa; };
00067     MethodDe methodDe() const { return m_eMethodDe; };
00068     int valueDe() const { return m_nValueDe; };
00069     QString backlash() const;
00070 private:
00071     MethodRa m_eMethodRa;
00072     int m_nValueRa;
00073     MethodDe m_eMethodDe;
00074     int m_nValueDe;
00075     };
00076 
00077 class McuDataGears
00078     {
00079 public:
00080     McuDataGears();
00081     McuDataGears(
00082         int nRaWormWheel, float fRaGearRatio, float fRaMotorStepAngle,
00083         int nDeWormWheel, float fDeGearRatio, float fDeMotorStepAngle);
00084 
00085     void setRaWormWheel(int nWormWheel);
00086     void setRaGearRatio(float fGearRatio);
00087     void setRaMotorStepAngle(float fMotorStepAngle);
00088     void setDeWormWheel(int nWormWheel);
00089     void setDeGearRatio(float fGearRatio);
00090     void setDeMotorStepAngle(float fMotorStepAngle);
00091     int raWormWheel() const { return m_nRaWormWheel; };
00092     float raGearRatio() const { return m_fRaGearRatio; };
00093     float raMotorStepAngle() const { return m_fRaMotorStepAngle; };
00094     int deWormWheel() const { return m_nDeWormWheel; };
00095     float deGearRatio() const { return m_fDeGearRatio; };
00096     float deMotorStepAngle() const { return m_fDeMotorStepAngle; };
00097 
00098     void setClockDivSid(int nClockDivSid) { m_nClockDivSid = nClockDivSid; };
00099     void setClockAdjSid(int nClockAdjSid) { m_nClockAdjSid = nClockAdjSid; };
00100     void setClockDivSol(int nClockDivSol) { m_nClockDivSol = nClockDivSol; };
00101     void setClockAdjSol(int nClockAdjSol) { m_nClockAdjSol = nClockAdjSol; };
00102     void setClockDivLun(int nClockDivLun) { m_nClockDivLun = nClockDivLun; };
00103     void setClockAdjLun(int nClockAdjLun) { m_nClockAdjLun = nClockAdjLun; };
00104     void setCountGotoRa(int nCountGotoRa) { m_nCountGotoRa = nCountGotoRa; };
00105     void setCountGotoDe(int nCountGotoDe) { m_nCountGotoDe = nCountGotoDe; };
00106     void setCountPec(int nCountPec) { m_nCountPec = nCountPec; };
00107     int clockDivSid() const { return m_nClockDivSid; };
00108     int clockAdjSid() const { return m_nClockAdjSid; };
00109     int clockDivSol() const { return m_nClockDivSol; };
00110     int clockAdjSol() const { return m_nClockAdjSol; };
00111     int clockDivLun() const { return m_nClockDivLun; };
00112     int clockAdjLun() const { return m_nClockAdjLun; };
00113     int countGotoRa() const { return m_nCountGotoRa; };
00114     int countGotoDe() const { return m_nCountGotoDe; };
00115     int countPec() const { return m_nCountPec; };
00116 
00117     bool operator==(const McuDataGears &oRef) const;
00118     bool operator!=(const McuDataGears &oRef) const;
00119 
00120 private:
00121     void calcInternalValues();
00122 
00123 private:
00124     int m_nRaWormWheel;
00125     float m_fRaGearRatio;
00126     float m_fRaMotorStepAngle;
00127     int m_nDeWormWheel;
00128     float m_fDeGearRatio;
00129     float m_fDeMotorStepAngle;
00130     int m_nClockDivSid;
00131     int m_nClockAdjSid;
00132     int m_nClockDivSol;
00133     int m_nClockAdjSol;
00134     int m_nClockDivLun;
00135     int m_nClockAdjLun;
00136     int m_nCountGotoRa;
00137     int m_nCountGotoDe;
00138     int m_nCountPec;
00139     };
00140 
00141 class McuDataPecState
00142     {
00143 public:
00144     McuDataPecState() : m_nPec(-1) {};
00145     void setPec(int nPec, bool bOk) { m_nPec = nPec; m_bOk = bOk; };
00146     void setWormPos(double dfWormPos) { m_dfWormPos = dfWormPos; };
00147     void setTime(const QTime &oTime) { m_oTime = oTime; };
00148     void setState(const QString &qsState) { m_qsState = qsState; };
00149     int pec() const { return m_nPec; };
00150     bool ok() const { return m_bOk; };
00151     double wormPos() const { return m_dfWormPos; };
00152     QTime time() const { return m_oTime; };
00153     QString state() const { return m_qsState; };
00154 private:
00155     int m_nPec;
00156     bool m_bOk;
00157     double m_dfWormPos;
00158     QTime m_oTime;
00159     QString m_qsState;
00160     };
00161 
00162 
00163 class McuProxy : public QObject
00164     {
00165     Q_OBJECT
00166 
00167 public:
00168     static McuProxy &proxy() { return g_oProxy; };
00169 
00170     // infrastructure
00171     bool open(const QString &qsPort, bool bRaw = false);
00172     void close();
00173 
00174     QByteArray mcuRawCommand(const QByteArray &aCommand);
00175 
00176     // static read-only properties; queried once and cached
00177     const McuDataFirmware &getFirmware() const;
00178     const McuDataKeys &getKeys() const;
00179 
00180     // cached read-write properties that need to be stored in EEPROM if changed
00181     enum Rotation { original = 0, reverse = 1 };
00182     enum Orientation { left = 0, right = 1 };
00183     enum Hemisphere { southern = 0, northern = 1 };
00184     Rotation getRotation() const;
00185     bool setRotation(Rotation eRotation);
00186     Orientation getOrientation() const;
00187     bool setOrientation(Orientation eOrientation);
00188     Hemisphere getHemisphere() const;
00189     McuDataGears &getGears();
00190     bool setGears(const McuDataGears &oGears);
00191 
00192     // dynamic properties; not cached, get and set directly from MCU
00193     enum Tracking { sidereal = 0, solar = 1, lunar = 2, off = 3 };
00194     Tracking getTrackingRate();
00195     bool setTrackingRate(Tracking eRate);
00196 
00197     McuDataPecState getPecState();
00198     bool setPec(bool bOn) const;
00199     bool getPecTable(PecData &rData, IProgress *pProgress = 0);
00200     bool putPecTable(const PecData &oData, IProgress *pProgress = 0);
00201 
00202     enum MoveDirection { north, south, east, west };
00203     enum Speed { guide_x2, move_x8, slew_x16 };
00204     enum RateSlow { rate1x33, rate1x66, rate2x };
00205     enum RateFast { rate4x, rate8x, rate16x, rate20x, rate24x,
00206         rate30x, rate40x, rate48x, rate60x, rate80x, rate120x };
00207 /*
00208     QString guideRate() const;
00209     QString paddle8Rate() const;
00210     QString paddle16Rate() const;
00211     QString gotoRate() const;
00212     int trackingRate() const;
00213     int rampSteepness() const;
00214 */
00215     bool getIntellyTrack();
00216     bool setIntellyTrack(bool bOn);
00217 
00218     void guideOff() { mcuRawCommand(QString::fromUtf8("#:Q#").toLatin1()); };
00219     void guideEast() { mcuRawCommand(QString::fromUtf8("#:Me#").toLatin1()); };
00220     void guideWest() { mcuRawCommand(QString::fromUtf8("#:Mw#").toLatin1()); };
00221 
00222 signals:
00223     void status(bool bOpen, McuSerial::Status eStatus) const;
00224     void firmware(QString qsFirmware) const;
00225     void busy(bool bBusy) const;
00226 
00227 private:
00228     McuProxy();
00229     ~McuProxy();
00230 
00231     bool mcuAck();
00232 
00233     bool mcuRecvFirmware() const;
00234     bool mcuRecvKeys();
00235     bool mcuRecvSettings();
00236     bool mcuRecvGears();
00237     bool mcuRecvPecState();
00238 
00239     bool mcuSendRotation() const;
00240     bool mcuSendOrientation() const;
00241     bool mcuSendGears() const;
00242     bool mcuSendTrackingRate(Tracking eRate) const;
00243     bool mcuSendPec(bool bOn) const;
00244     bool mcuSendPecTeaching(bool bOn) const;
00245     bool mcuSendPecFactor(int nPecFactor, int nPecAggress) const;
00246     bool mcuSendIntelly(bool bOn) const;
00247     bool mcuSendSaveToEEPROM() const;
00248 
00249     static Rotation parseRotation(const QByteArray &oAnsGetSettings);
00250 
00251     static RateSlow decodeRateSlow(int nAnswerByte, RateSlow eDefault);
00252     static RateFast decodeRateFast(int nAnswerByte, RateFast eDefault);
00253     static Tracking decodeTrackingRate(int nAnswerByte, Tracking eDefault);
00254 
00255 private:
00256     static McuProxy g_oProxy;
00257 
00258     McuSerial m_oPort;
00259 
00260     McuDataFirmware m_oFirmware;
00261     McuDataKeys m_oKeys;
00262 
00263     McuDataBacklash m_oBacklash;
00264     RateSlow m_eRateGuide;
00265     RateFast m_eRateCenter;
00266     RateFast m_eRateSlew;
00267     RateFast m_eRateGoto;
00268     Rotation m_eRotation;
00269     Orientation m_eOrientation;
00270     Hemisphere m_eHemisphere;
00271     Tracking m_eTrackingRate;
00272     int m_nRampSteepness;
00273 
00274     McuDataGears m_oGears;
00275 
00276     McuDataPecState m_oPecState;
00277     int m_nPecFactor;
00278     int m_nPecAggress;
00279     bool m_bIntellyTrack;
00280     };
00281 
00282 
00283 #endif // ASPECT_MCUPROXY_H
00284 

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