1 /*
2 * guidinglog.h
3 * PHD Guiding
4 *
5 * Created by Bret McKee
6 * Copyright (c) 2012-2013 Bret McKee
7 * All rights reserved.
8 *
9 * This source code is distributed under the following "BSD" license
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * Neither the name of Bret McKee, Dad Dog Development,
18 * Craig Stark, Stark Labs nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36 #ifndef GUIDINGLOG_INCLUDED
37 #define GUIDINGLOG_INCLUDED
38
39 #include "logger.h"
40
41 class Mount;
42 class Guider;
43 struct LockPosShiftParams;
44
45 struct CalibrationStepInfo
46 {
47 Mount *mount;
48 wxString direction;
49 int stepNumber;
50 double dx;
51 double dy;
52 PHD_Point pos;
53 double dist;
54 wxString msg;
55
56 CalibrationStepInfo(Mount *mount_, const wxString& dir_, int stepNumber_, double dx_,
57 double dy_, const PHD_Point& pos_, double dist_, const wxString& msg_ = wxEmptyString)
mountCalibrationStepInfo58 : mount(mount_), direction(dir_), stepNumber(stepNumber_), dx(dx_), dy(dy_), pos(pos_),
59 dist(dist_), msg(msg_) { }
60 };
61
62 struct GuideStepInfo
63 {
64 Mount *mount;
65 unsigned int moveOptions;
66 int frameNumber;
67 double time;
68 PHD_Point cameraOffset;
69 PHD_Point mountOffset;
70 double guideDistanceRA;
71 double guideDistanceDec;
72 int durationRA;
73 int durationDec;
74 bool raLimited;
75 bool decLimited;
76 // TODO: the following two members are GUIDE_DIRECTION, but we have circular
77 // dependencies in our header files so cannot use GUIDE_DIRECTION here
78 int directionRA;
79 int directionDec;
80 wxPoint aoPos;
81 double starMass;
82 double starSNR;
83 double starHFD;
84 double avgDist;
85 int starError;
86 };
87
88 struct FrameDroppedInfo
89 {
90 int frameNumber;
91 double time;
92 double starMass;
93 double starSNR;
94 double starHFD;
95 double avgDist;
96 int starError;
97 wxString status;
98 };
99
100 struct GuideLogSummaryInfo
101 {
102 bool valid;
103 unsigned int cal_cnt;
104 unsigned int guide_cnt;
105 double guide_dur;
106 unsigned int ga_cnt;
107
ClearGuideLogSummaryInfo108 void Clear()
109 {
110 valid = false;
111 cal_cnt = 0;
112 guide_cnt = 0;
113 guide_dur = 0.;
114 ga_cnt = 0;
115 }
GuideLogSummaryInfoGuideLogSummaryInfo116 GuideLogSummaryInfo() { Clear(); }
117 void LoadSummaryInfo(wxFFile& guidelog);
118 };
119
120 class GuidingLog : public Logger
121 {
122 bool m_enabled;
123 wxFFile m_file;
124 wxString m_fileName;
125 bool m_keepFile;
126 bool m_isGuiding;
127 GuideLogSummaryInfo m_summary;
128
129 void EnableLogging();
130 void DisableLogging();
131
132 public:
133 GuidingLog();
134 ~GuidingLog();
135
136 void EnableLogging(bool enabled);
137 bool IsEnabled() const;
138 bool Flush();
139 void CloseGuideLog();
140
141 wxFFile& File();
142
143 void StartCalibration(const Mount *pCalibrationMount);
144 void CalibrationFailed(const Mount *pCalibrationMount, const wxString& msg);
145 void CalibrationStep(const CalibrationStepInfo& info);
146 void CalibrationDirectComplete(const Mount *pCalibrationMount, const wxString& direction,
147 double angle, double rate, int parity);
148 void CalibrationComplete(const Mount *pCalibrationMount);
149
150 void GuidingStarted();
151 void GuidingStopped();
152 void GuideStep(const GuideStepInfo& info);
153 void FrameDropped(const FrameDroppedInfo& info);
154 void CalibrationFrameDropped(const FrameDroppedInfo& info);
155
156 void ServerCommand(Guider *guider, const wxString& cmd);
157 void NotifyGuidingDithered(Guider *guider, double dx, double dy);
158 void NotifySetLockPosition(Guider *guider);
159 void NotifyLockShiftParams(const LockPosShiftParams& shiftParams, const PHD_Point& cameraRate);
160 void NotifySettlingStateChange(const wxString& msg);
161 void NotifyGACompleted();
162 void NotifyGAResult(const wxString& msg);
163 void NotifyManualGuide(const Mount *whichMount, int direction, int duration);
164
165 void SetGuidingParam(const wxString& name, double val);
166 void SetGuidingParam(const wxString& name, int val);
167 void SetGuidingParam(const wxString& name, bool val);
168 void SetGuidingParam(const wxString& name, const wxString& val);
169 void SetGuidingParam(const wxString& name, const wxString& val, bool AlwaysLog);
170
171 bool ChangeDirLog(const wxString& newdir);
172 void RemoveOldFiles();
173 };
174
IsEnabled()175 inline bool GuidingLog::IsEnabled() const
176 {
177 return m_enabled;
178 }
179
File()180 inline wxFFile& GuidingLog::File()
181 {
182 return m_file;
183 }
184
185 extern GuidingLog GuideLog;
186
187 #endif
188