File indexing completed on 2024-04-28 07:33:03
0001 /* mock ekos modules 0002 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef MOCKMODULES_H 0008 #define MOCKMODULES_H 0009 0010 #include <QString> 0011 #include <QList> 0012 #include <QStringList> 0013 #include <QtDBus/QtDBus> 0014 #include "ekos/ekos.h" 0015 #include "indi/indimount.h" 0016 0017 // These classes mock Ekos modules for use in testing the scheduler 0018 // in test_ekos_scheduler_ops.cpp. They perform minimal functions 0019 // and are only partially implemented--that is, they only have methods 0020 // that are actually called by the scheduler. If scheduler functionality 0021 // is added, then more mock methods may need to be created, or methods extended. 0022 // They communicate with the scheduler with the same dbus calls as the real modules. 0023 // 0024 // Note that MockEkos uses a different path and interface than the actual 0025 // scheduler (to avoid name conflicts with the adaptor class) so it use it 0026 // the scheduler contstructor that takes path and interface needs to be used. 0027 // Scheduler scheduler("/MockKStars/MockEkos", "org.kde.mockkstars.MockEkos"); 0028 0029 namespace Ekos 0030 { 0031 0032 // MockFocus returns status of either FOCUS_PROGRESS or FOCUS_IDLE 0033 // or whatever is passed to setStatus(). It is commanded by the status call. 0034 // It signals newStatus() if the status is changed. 0035 // Status can be changed via start(), abort(), or setStatus(status). 0036 class MockFocus : public QObject 0037 { 0038 Q_OBJECT 0039 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos.MockFocus") 0040 Q_PROPERTY(Ekos::FocusState status READ status NOTIFY newStatus) 0041 public: 0042 MockFocus(); 0043 0044 Q_SCRIPTABLE Q_NOREPLY void start() 0045 { 0046 fprintf(stderr, "MockFocus::start called\n"); 0047 setStatus(Ekos::FOCUS_PROGRESS); 0048 } 0049 Q_SCRIPTABLE Q_NOREPLY void abort() 0050 { 0051 fprintf(stderr, "MockFocus::abort called\n"); 0052 setStatus(Ekos::FOCUS_IDLE); 0053 } 0054 Q_SCRIPTABLE Q_NOREPLY bool canAutoFocus() 0055 { 0056 fprintf(stderr, "MockFocus::canAutoFocus called\n"); 0057 return true; 0058 } 0059 0060 // Seems like the calibrationAutoStar is the one that's used! 0061 Q_SCRIPTABLE Q_NOREPLY void setAutoStarEnabled(bool enable) 0062 { 0063 Q_UNUSED(enable); 0064 fprintf(stderr, "MockFocus::setAutoStarEnabled called\n"); 0065 } 0066 0067 Q_SCRIPTABLE Q_NOREPLY void resetFrame() 0068 { 0069 fprintf(stderr, "MockFocus::ResetFrame called\n"); 0070 isReset = true; 0071 } 0072 0073 bool isReset = false; 0074 0075 Q_SCRIPTABLE Ekos::FocusState status() 0076 { 0077 return m_Status; 0078 } 0079 0080 void setStatus(Ekos::FocusState status) 0081 { 0082 m_Status = status; 0083 emit newStatus(m_Status); 0084 } 0085 0086 static const QString mockPath; 0087 0088 public slots: 0089 0090 signals: 0091 void newStatus(Ekos::FocusState state); 0092 private: 0093 Ekos::FocusState m_Status = Ekos::FOCUS_IDLE; 0094 }; 0095 0096 // MockMount returns status() of either MOUNT_SLEWING, MOUNT_IDLE 0097 // or whatever is passed to setStatus(). 0098 // They are commanded by slew(), abort() & setStatus() and signaled by newStatus(). 0099 // It also returns parkStatus() of either PARK_PARKED or PARK_UNPARKED 0100 // or whatever is passed to setParkStatus(). 0101 // Commanded by park(), unpark(), setParkStatus() & signaled by newParkStatus(). 0102 // It can also signal ready() when sendRead() is called. 0103 class MockMount : public QObject 0104 { 0105 Q_OBJECT 0106 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos.MockMount") 0107 Q_PROPERTY(ISD::Mount::Status status READ status NOTIFY newStatus) 0108 Q_PROPERTY(ISD::ParkStatus parkStatus READ parkStatus NOTIFY newParkStatus) 0109 Q_PROPERTY(bool canPark READ canPark) 0110 public: 0111 MockMount(); 0112 0113 ISD::Mount::Status status() const 0114 { 0115 return m_Status; 0116 } 0117 Q_INVOKABLE Q_SCRIPTABLE ISD::ParkStatus parkStatus() const 0118 { 0119 return m_ParkStatus; 0120 } 0121 Q_INVOKABLE Q_SCRIPTABLE bool slew(double RaHours, double DecDegrees) 0122 { 0123 fprintf(stderr, "%d @@@MockMount::slew(%f,%f)\n", __LINE__, RaHours, DecDegrees); 0124 setStatus(ISD::Mount::MOUNT_SLEWING); 0125 lastRaHoursSlew = RaHours; 0126 lastDecDegreesSlew = DecDegrees; 0127 return true; 0128 } 0129 Q_INVOKABLE Q_SCRIPTABLE bool abort() 0130 { 0131 fprintf(stderr, "%d @@@MockMount::abort()\n", __LINE__); 0132 setStatus(ISD::Mount::MOUNT_IDLE); 0133 return true; 0134 } 0135 Q_INVOKABLE Q_SCRIPTABLE bool resetModel() 0136 { 0137 return true; 0138 } 0139 Q_INVOKABLE Q_SCRIPTABLE bool canPark() 0140 { 0141 return true; 0142 } 0143 Q_INVOKABLE Q_SCRIPTABLE bool park() 0144 { 0145 fprintf(stderr, "%d @@@MockMount::park\n", __LINE__); 0146 setParkStatus(ISD::PARK_PARKED); 0147 return true; 0148 } 0149 Q_INVOKABLE Q_SCRIPTABLE bool unpark() 0150 { 0151 fprintf(stderr, "%d @@@MockMount::park\n", __LINE__); 0152 setParkStatus(ISD::PARK_UNPARKED); 0153 return true; 0154 } 0155 0156 void sendReady() 0157 { 0158 emit ready(); 0159 } 0160 void setStatus(ISD::Mount::Status status) 0161 { 0162 m_Status = status; 0163 emit newStatus(m_Status); 0164 } 0165 void setParkStatus(ISD::ParkStatus parkStatus) 0166 { 0167 m_ParkStatus = parkStatus; 0168 emit newParkStatus(parkStatus); 0169 } 0170 0171 double lastRaHoursSlew = 0; 0172 double lastDecDegreesSlew = 0; 0173 static const QString mockPath; 0174 0175 signals: 0176 void newStatus(ISD::Mount::Status status); 0177 void ready(); 0178 void newParkStatus(ISD::ParkStatus status); 0179 0180 public slots: 0181 void setMeridianFlipValues(bool activate, double hours) 0182 { 0183 Q_UNUSED(activate); 0184 Q_UNUSED(hours); 0185 } 0186 private: 0187 ISD::Mount::Status m_Status = ISD::Mount::MOUNT_IDLE; 0188 ISD::ParkStatus m_ParkStatus = ISD::PARK_UNPARKED; 0189 }; 0190 0191 // MockCapture returns status() of CAPTURE_CAPTURING, CAPTURE_ABORTED, CAPTURE_IDLE 0192 // or whatever is passed to setStatus(). 0193 // They are commanded by start(), abort() & setStatus() and signaled by newStatus(). 0194 // It also has a coolerControl and targetName property. 0195 class MockCapture : public QObject 0196 { 0197 Q_OBJECT 0198 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos.MockCapture") 0199 Q_PROPERTY(Ekos::CaptureState status READ status NOTIFY newStatus) 0200 Q_PROPERTY(QString targetName MEMBER m_TargetName) 0201 Q_PROPERTY(bool coolerControl READ hasCoolerControl WRITE setCoolerControl) 0202 0203 0204 public: 0205 MockCapture(); 0206 Q_SCRIPTABLE Q_NOREPLY void clearAutoFocusHFR() {} 0207 Q_SCRIPTABLE bool loadSequenceQueue(const QString &fileURL, QString targetName = "") 0208 { 0209 Q_UNUSED(targetName) 0210 fprintf(stderr, "%d @@@MockCapture::loadSequenceQueue(%s)\n", __LINE__, fileURL.toLatin1().data()); 0211 m_fileURL = fileURL; 0212 return true; 0213 } 0214 Q_SCRIPTABLE Q_NOREPLY void setCapturedFramesMap(const QString &signature, int count) 0215 { 0216 Q_UNUSED(signature); 0217 Q_UNUSED(count); 0218 fprintf(stderr, "%d @@@MockCapture::setCapturedFramesMap(%s,%d)\n", __LINE__, signature.toLatin1().data(), count); 0219 } 0220 Q_SCRIPTABLE Ekos::CaptureState status() 0221 { 0222 return m_Status; 0223 } 0224 0225 Q_SCRIPTABLE bool hasCoolerControl() 0226 { 0227 return m_CoolerControl; 0228 } 0229 Q_SCRIPTABLE bool setCoolerControl(bool value) 0230 { 0231 m_CoolerControl = value; 0232 return true; 0233 } 0234 0235 void sendReady() 0236 { 0237 emit ready(); 0238 } 0239 void setStatus(Ekos::CaptureState status) 0240 { 0241 m_Status = status; 0242 emit newStatus(m_Status); 0243 } 0244 QString m_fileURL; 0245 0246 static const QString mockPath; 0247 0248 public slots: 0249 0250 Q_SCRIPTABLE Q_NOREPLY void abort() 0251 { 0252 fprintf(stderr, "%d @@@MockCapture::abort()\n", __LINE__); 0253 setStatus(CAPTURE_ABORTED); 0254 } 0255 Q_SCRIPTABLE Q_NOREPLY void start() 0256 { 0257 fprintf(stderr, "%d @@@MockCapture::start()\n", __LINE__); 0258 setStatus(CAPTURE_CAPTURING); 0259 } 0260 0261 signals: 0262 Q_SCRIPTABLE void newStatus(Ekos::CaptureState status); 0263 void ready(); 0264 0265 private: 0266 QString m_TargetName; 0267 Ekos::CaptureState m_Status { CAPTURE_IDLE }; 0268 bool m_CoolerControl { false }; 0269 }; 0270 0271 // MockAlign returns status() of ALIGN_PROGRESS or whatever is passed to setStatus(). 0272 // They are commanded by captureAndSolve(), loadAndSlew(), abort() & setStatus(). 0273 // It is signaled by newStatus(). 0274 class MockAlign : public QObject 0275 { 0276 Q_OBJECT 0277 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos.MockAlign") 0278 Q_PROPERTY(Ekos::AlignState status READ status NOTIFY newStatus) 0279 0280 public: 0281 MockAlign(); 0282 0283 Q_SCRIPTABLE Ekos::AlignState status() 0284 { 0285 return m_Status; 0286 } 0287 Q_SCRIPTABLE Q_NOREPLY void setSolverAction(int action) 0288 { 0289 fprintf(stderr, "%d @@@MockAlign::setSolverAction(%d)\n", __LINE__, action); 0290 } 0291 void setStatus(Ekos::AlignState status) 0292 { 0293 m_Status = status; 0294 emit newStatus(m_Status); 0295 } 0296 0297 static const QString mockPath; 0298 0299 public slots: 0300 Q_SCRIPTABLE Q_NOREPLY void abort() 0301 { 0302 fprintf(stderr, "%d @@@MockAlign::abort()\n", __LINE__); 0303 setStatus(ALIGN_IDLE); 0304 } 0305 Q_SCRIPTABLE bool captureAndSolve() 0306 { 0307 fprintf(stderr, "%d @@@MockAlign::captureAndSolve()\n", __LINE__); 0308 setStatus(ALIGN_PROGRESS); 0309 return true; 0310 } 0311 Q_SCRIPTABLE bool loadAndSlew(QString fileURL = QString()) 0312 { 0313 Q_UNUSED(fileURL); 0314 fprintf(stderr, "%d @@@MockAlign::loadAndSlew(fileURL)\n", __LINE__); 0315 setStatus(ALIGN_PROGRESS); 0316 return true; 0317 } 0318 Q_SCRIPTABLE Q_NOREPLY void setTargetCoords(double ra, double dec) 0319 { 0320 fprintf(stderr, "%d @@@MockAlign::setTargetCoords(%f,%f)\n", __LINE__, ra, dec); 0321 targetRa = ra; 0322 targetDec = dec; 0323 } 0324 Q_SCRIPTABLE Q_NOREPLY void setTargetPositionAngle(double rotation) 0325 { 0326 fprintf(stderr, "%d @@@MockAlign::setTargetPositionAngle(%f)\n", __LINE__, rotation); 0327 targetPositionAngle = rotation; 0328 Q_UNUSED(rotation); 0329 } 0330 bool loadAndSlew(const QByteArray &image, const QString &extension) 0331 { 0332 Q_UNUSED(image); 0333 Q_UNUSED(extension); 0334 fprintf(stderr, "%d @@@MockAlign::loadAndSlew(image,extension)\n", __LINE__); 0335 setStatus(ALIGN_PROGRESS); 0336 return true; 0337 } 0338 0339 signals: 0340 void newStatus(Ekos::AlignState state); 0341 0342 private: 0343 Ekos::AlignState m_Status {ALIGN_IDLE}; 0344 int action { 0 }; 0345 double targetRa { 0 }; 0346 double targetDec { 0 }; 0347 double targetPositionAngle { 0 }; 0348 }; 0349 0350 // MockGuide returns status() of GUIDE_GUIDING, GUIDE_ABORTED, or GUIDE_IDLE 0351 // or whatever is passed to setStatus(). 0352 // They are commanded by guide(), abort() & setStatus() and signaled by newStatus(). 0353 class MockGuide : public QObject 0354 { 0355 Q_OBJECT 0356 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos.MockGuide") 0357 Q_PROPERTY(Ekos::GuideState status READ status NOTIFY newStatus) 0358 0359 public: 0360 MockGuide(); 0361 0362 Q_SCRIPTABLE bool connectGuider() 0363 { 0364 fprintf(stderr, "%d @@@MockGuide::connectGuider()\n", __LINE__); 0365 connected = true; 0366 return true; 0367 } 0368 Q_SCRIPTABLE Q_NOREPLY void setCalibrationAutoStar(bool enable) 0369 { 0370 fprintf(stderr, "%d @@@MockGuide::setCalibrationAutoStar()\n", __LINE__); 0371 calAutoStar = enable; 0372 Q_UNUSED(enable); 0373 } 0374 Q_SCRIPTABLE Ekos::GuideState status() 0375 { 0376 return m_Status; 0377 } 0378 void setStatus(Ekos::GuideState status) 0379 { 0380 m_Status = status; 0381 emit newStatus(m_Status); 0382 } 0383 bool connected { false }; 0384 0385 // I believe this is really autoStar in general! 0386 bool calAutoStar { false }; 0387 0388 static const QString mockPath; 0389 0390 public slots: 0391 Q_SCRIPTABLE Q_NOREPLY void clearCalibration() {} 0392 Q_SCRIPTABLE bool guide() 0393 { 0394 fprintf(stderr, "%d @@@MockGuide::guide()\n", __LINE__); 0395 setStatus(Ekos::GUIDE_GUIDING); 0396 return true; 0397 } 0398 Q_SCRIPTABLE bool abort() 0399 { 0400 setStatus(Ekos::GUIDE_ABORTED); 0401 return true; 0402 } 0403 0404 signals: 0405 void newStatus(Ekos::GuideState status); 0406 0407 private: 0408 Ekos::GuideState m_Status {GUIDE_IDLE}; 0409 }; 0410 0411 // MockEkos has 2 different statuses. 0412 // ekosStatus is commanded by start() --> Success, and stop() --> Idle and 0413 // setEkosStatus(). It signals ekosStatusChanged. 0414 // indiStatus is commanded by connectDevices() --> Success, and 0415 // disconnectDevives() --> Idle and setIndiStatus(). 0416 // It signals indiStatusChanged. 0417 // It also has an addModule() method which signals newModule(). 0418 // A scheduler using this mock should be constructed as: 0419 // Scheduler scheduler("/MockKStars/MockEkos", "org.kde.mockkstars.MockEkos"); 0420 class MockEkos : public QObject 0421 { 0422 Q_OBJECT 0423 Q_CLASSINFO("D-Bus Interface", "org.kde.mockkstars.MockEkos") 0424 Q_PROPERTY(Ekos::CommunicationStatus indiStatus READ indiStatus NOTIFY indiStatusChanged) 0425 Q_PROPERTY(Ekos::CommunicationStatus ekosStatus READ ekosStatus NOTIFY ekosStatusChanged) 0426 0427 public: 0428 MockEkos(); 0429 Q_SCRIPTABLE void start() 0430 { 0431 fprintf(stderr, "%d @@@MockEkos::start()\n", __LINE__); 0432 setEkosStatus(Ekos::Success); 0433 } 0434 Q_SCRIPTABLE void stop() 0435 { 0436 fprintf(stderr, "%d @@@MockEkos::stop()\n", __LINE__); 0437 setEkosStatus(Ekos::Idle); 0438 } 0439 Q_SCRIPTABLE QStringList getProfiles() 0440 { 0441 fprintf(stderr, "%d @@@MockEkos::getProfiles()\n", __LINE__); 0442 return QStringList(); 0443 } 0444 Q_SCRIPTABLE bool setProfile(const QString &profileName) 0445 { 0446 Q_UNUSED(profileName); 0447 fprintf(stderr, "%d @@@MockEkos::setProfile()\n", __LINE__); 0448 return true; 0449 } 0450 Q_SCRIPTABLE CommunicationStatus indiStatus() 0451 { 0452 fprintf(stderr, "%d @@@MockEkos::indiStatus\n", __LINE__); 0453 return m_INDIStatus; 0454 } 0455 Q_SCRIPTABLE CommunicationStatus ekosStatus() 0456 { 0457 fprintf(stderr, "%d @@@MockEkos::ekosStatus\n", __LINE__); 0458 return m_EkosStatus; 0459 } 0460 void setEkosStatus(Ekos::CommunicationStatus status) 0461 { 0462 m_EkosStatus = status; 0463 emit ekosStatusChanged(status); 0464 } 0465 void setIndiStatus(Ekos::CommunicationStatus status) 0466 { 0467 m_INDIStatus = status; 0468 emit indiStatusChanged(status); 0469 } 0470 void addModule(const QString &name) 0471 { 0472 emit newModule(name); 0473 } 0474 0475 static const QString mockPath; 0476 0477 signals: 0478 void ekosStatusChanged(Ekos::CommunicationStatus status); 0479 void indiStatusChanged(Ekos::CommunicationStatus status); 0480 void newModule(const QString &name); 0481 0482 protected: 0483 public slots: 0484 Q_SCRIPTABLE Q_NOREPLY void connectDevices() 0485 { 0486 fprintf(stderr, "%d @@@MockEkos::connectDevices\n", __LINE__); 0487 setIndiStatus(Ekos::Success); 0488 } 0489 Q_SCRIPTABLE Q_NOREPLY void disconnectDevices() 0490 { 0491 fprintf(stderr, "%d @@@MockEkos::disconnectDevices\n", __LINE__); 0492 setIndiStatus(Ekos::Idle); 0493 } 0494 private slots: 0495 private: 0496 Ekos::CommunicationStatus m_EkosStatus {Ekos::Idle}; 0497 Ekos::CommunicationStatus m_INDIStatus {Ekos::Idle}; 0498 }; 0499 0500 } // namespace Ekos 0501 0502 #endif // MOCKMODULES_H