Instrument Neutral Distributed Interface INDI 2.2.5
guide_simulator.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3 Copyright(c) 2010 Gerry Rozema. All rights reserved.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7 .
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 .
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#pragma once
20
21#include <indiccd.h>
22#include "sky_renderer.h"
23#include "simulator_clock.h"
24#include "indipropertyswitch.h"
25#include "fitskeyword.h"
26
43class GuideSim : public INDI::CCD
44{
45 public:
46
47 GuideSim();
48 virtual ~GuideSim() override = default;
49
50 const char *getDefaultName() override;
51
52 bool initProperties() override;
53 bool updateProperties() override;
54
55 void ISGetProperties(const char *dev) override;
56
57 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
58 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
59 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
60 virtual bool ISSnoopDevice(XMLEle *root) override;
61
62 static void *streamVideoHelper(void *context);
63 void *streamVideo();
64
65 protected:
66
67 bool Connect() override;
68 bool Disconnect() override;
69
70 bool StartExposure(float duration) override;
71
72 bool AbortExposure() override;
73
74 void TimerHit() override;
75
76 int DrawCcdFrame(INDI::CCDChip *targetChip);
77
78 virtual IPState GuideNorth(uint32_t) override;
79 virtual IPState GuideSouth(uint32_t) override;
80 virtual IPState GuideEast(uint32_t) override;
81 virtual IPState GuideWest(uint32_t) override;
82
83 virtual bool saveConfigItems(FILE *fp) override;
84 virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector<INDI::FITSRecord> &fitsKeywords) override;
85 virtual void activeDevicesUpdated() override;
86 virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
87 virtual bool UpdateCCDBin(int hor, int ver) override;
88
89 virtual bool StartStreaming() override;
90 virtual bool StopStreaming() override;
91
92 protected:
93
94 bool SetupParms();
95
96 private:
97
98 // Turns on/off Bayer RGB simulation.
99 void setRGB(bool onOff);
100
101 float CalcTimeLeft(timeval start, float req);
102
103 SkyRenderer m_Renderer;
104
105 // Follows the client's TIME_UTC, so the rendered sky agrees with the telescope simulator's
106 SimulatorClock m_Clock;
107
108 // ADU ceiling and magnitude calibration -- updated from INDI properties.
109 int m_MaxVal {65000};
110 float m_LimitingMag {11.5f};
111 float m_SaturationMag {2.0f};
112 float m_Seeing {3.5f};
113
114 double m_TemperatureRequest { 0 };
115
116 float m_ExposureRequest { 0 };
117 struct timeval m_ExpStart
118 {
119 0, 0
120 };
121
122
123 int m_TestValue { 0 };
124 bool m_ShowStarField { true };
125 int m_Bias { 1500 };
126 int m_MaxNoise { 20 };
127 float m_SkyGlow { 40 };
128 // An oag is offset this much from center of scope position (arcminutes)
129 float m_OAGoffset { 0 };
130 float m_TimeFactor { 1 };
131 // With a rotator device "RotatorAngle" is snooped and defined, so the
132 // resulting camera rotation is the addition of offset and rotator angle.
133 // Without a rotator device ("Manual Rotator") the rotator angle is
134 // considered fixed to 0° and the camera rotation is equal to offset
135 float m_RotationOffset { 0 };
136
137 bool m_SimulateRGB { false };
138
139 bool m_AbortPrimaryFrame { false };
140
141 protected:
142 float m_GuideRate { 7 };
145 double m_CurrentRA { 0 };
146 double m_CurrentDEC { 0 };
147
148 private:
149 float m_PEPeriod { 8 * 60 };
150 float m_PEMax { 11 };
151
152 // Random values added to ra and dec
153 float m_RaRand { 0 };
154 float m_DecRand { 0 };
155
156 // linear drift (multiplied by seconds since start) in arcsec/sec.
157 float m_RaTimeDrift { 0 };
158 float m_DecTimeDrift { 0 };
159
160 bool m_UsePE { false };
161#ifdef USE_EQUATORIAL_PE
162 double raPE { 0 };
163 double decPE { 0 };
164#endif
165 time_t m_RunStart;
166 time_t m_LastSim;
167 bool m_RunStartInitialized { false };
168
169 float m_PolarError { 0 };
170 float m_PolarDrift { 0 };
171 float m_KingGamma = { 0 };
172 float m_KingTheta = { 0 };
173
174 int m_StreamPredicate;
175 pthread_t m_PrimaryThread;
176 bool m_TerminateThread;
177
178 // And this lives in our simulator settings page
179
180 enum
181 {
182 SIM_XRES = 0,
183 SIM_YRES,
184 SIM_XSIZE,
185 SIM_YSIZE,
186 SIM_MAXVAL,
187 SIM_BIAS,
188 SIM_SATURATION,
189 SIM_LIMITINGMAG,
190 SIM_NOISE,
191 SIM_SKYGLOW,
192 SIM_OAGOFFSET,
193 SIM_POLAR,
194 SIM_POLARDRIFT,
195 SIM_ROTATION,
196 SIM_KING_GAMMA,
197 SIM_KING_THETA,
198 SIM_TIME_FACTOR,
199 SIM_SEEING,
200 SIM_RA_DRIFT,
201 SIM_DEC_DRIFT,
202 SIM_RA_RAND,
203 SIM_DEC_RAND,
204 SIM_PE_PERIOD,
205 SIM_PE_MAX,
206 SIM_TEMPERATURE,
207 SIM_NUM_PROPERTIES
208 };
209 INDI::PropertyNumber SimulatorSettingsNP {SIM_NUM_PROPERTIES};
210
211
212 INDI::PropertySwitch SimTestsSP {3};
213 enum
214 {
215 SIM_TESTS_RGB,
216 SIM_TESTS_CRASH,
217 SIM_TESTS_TIMEOUT
218 };
219
220 INDI::PropertyNumber EqPENP {2};
221 enum
222 {
223 RA_PE,
224 DEC_PE
225 };
226
227 INDI::PropertyNumber GainNP {1};
228
229 bool m_SimulateTimeout { false };
230
231 static constexpr const char *SIMULATOR_TAB {"Simulator Settings"};
232};
The GuideSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
double m_CurrentDEC
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
virtual bool UpdateCCDFrame(int x, int y, int w, int h) override
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
float m_GuideRate
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
float m_GuideNSOffset
virtual ~GuideSim() override=default
virtual bool UpdateCCDBin(int hor, int ver) override
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
int DrawCcdFrame(INDI::CCDChip *targetChip)
double m_CurrentRA
virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector< INDI::FITSRecord > &fitsKeywords) override
Generate FITS keywords that will be added to FIST/XISF file.
const char * getDefaultName() override
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
bool Disconnect() override
Disconnect from device.
float m_GuideWEOffset
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
bool AbortExposure() override
Abort ongoing exposure.
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
virtual bool StopStreaming() override
StopStreaming Stop live video streaming.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void * streamVideo()
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
static void * streamVideoHelper(void *context)
bool StartExposure(float duration) override
Start exposing primary CCD chip.
virtual void activeDevicesUpdated() override
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
bool SetupParms()
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition indiccdchip.h:39
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition indiccd.h:108
The SimulatorClock class is the clock of a camera simulator: the system clock, shifted to the time th...
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158