File indexing completed on 2024-05-12 15:23:42
0001 /* 0002 SPDX-FileCopyrightText: 2020 Hy Murveit <hy@murveit.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QElapsedTimer> 0010 #include <QFile> 0011 0012 #include "indi/indicommon.h" 0013 #include "indi/indimount.h" 0014 0015 // This class will help write guide log files, using the PHD2 guide log format. 0016 0017 class GuideLog 0018 { 0019 public: 0020 class GuideInfo 0021 { 0022 public: 0023 double pixelScale = 0; // arcseconds/pixel 0024 int binning = 1; 0025 double focalLength = 0; // millimeters 0026 // Recent mount position. 0027 double ra = 0, dec = 0, azimuth = 0, altitude = 0; // degrees 0028 ISD::Mount::PierSide pierSide = ISD::Mount::PierSide::PIER_UNKNOWN; 0029 double xangle = 0.0, yangle = 0.0; // degrees, x,y axis vs ra,dec. 0030 double xrate = 1.0, yrate = 1.0; // pixels/second of pulsing. 0031 }; 0032 0033 class GuideData 0034 { 0035 public: 0036 enum GuideDataType { MOUNT, DROP }; 0037 GuideDataType type = MOUNT; 0038 double dx = 0, dy = 0; // Should be in units of pixels. 0039 double raDistance = 0, decDistance = 0; // Should be in units of arcseconds. 0040 double raGuideDistance = 0, decGuideDistance = 0; // Should be in units of arcseconds. 0041 int raDuration = 0, decDuration = 0; // Should be in units of milliseconds. 0042 GuideDirection raDirection, decDirection = NO_DIR; 0043 double mass = 0; 0044 double snr = 0; 0045 // From https://openphdguiding.org/PHD2_User_Guide.pdf and logs 0046 enum ErrorCode 0047 { 0048 NO_ERRORS = 0, 0049 STAR_SATURATED = 1, 0050 LOW_SNR = 2, 0051 STAR_LOST_LOW_MASS = 3, 0052 EDGE_OF_FRAME = 4, 0053 STAR_MASS_CHANGED = 5, 0054 STAR_LOST_MASS_CHANGED = 6, 0055 NO_STAR_FOUND = 7 0056 }; 0057 ErrorCode code = NO_ERRORS; 0058 }; 0059 0060 GuideLog(); 0061 ~GuideLog(); 0062 0063 // Won't log unless enable() is called. 0064 void enable() 0065 { 0066 enabled = true; 0067 } 0068 void disable() 0069 { 0070 enabled = false; 0071 } 0072 0073 // These are called for each guiding session. 0074 void startGuiding(const GuideInfo &info); 0075 void addGuideData(const GuideData &data); 0076 void endGuiding(); 0077 0078 // These are called for each calibration session. 0079 void startCalibration(const GuideInfo &info); 0080 void addCalibrationData(GuideDirection direction, double x, double y, double xOrigin, double yOrigin); 0081 void endCalibrationSection(GuideDirection direction, double degrees); 0082 void endCalibration(double raSpeed, double decSpeed); 0083 0084 // INFO messages 0085 void ditherInfo(double dx, double dy, double x, double y); 0086 void pauseInfo(); 0087 void resumeInfo(); 0088 void settleStartedInfo(); 0089 void settleCompletedInfo(); 0090 0091 // Deal with suspend, resume, dither, ... 0092 private: 0093 // Write the file header and footer. 0094 void startLog(); 0095 void endLog(); 0096 void appendToLog(const QString &lines); 0097 0098 // Log file info. 0099 QFile logFile; 0100 QString logFileName; 0101 0102 // Message indeces and timers. 0103 int guideIndex = 1; 0104 int calibrationIndex = 1; 0105 QElapsedTimer timer; 0106 0107 // Used to write and end-of-guiding message on exit, if this was not called. 0108 bool isGuiding = false; 0109 0110 // Variable used to detect calibration change of direction. 0111 GuideDirection lastCalibrationDirection = NO_DIR; 0112 0113 // If false, no logging will occur. 0114 bool enabled = false; 0115 0116 // True means the filename was created and the log's header has been written. 0117 bool initialized = false; 0118 };