forked from indilib/indi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccd_simulator.h
More file actions
255 lines (202 loc) · 7.58 KB
/
Copy pathccd_simulator.h
File metadata and controls
255 lines (202 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*******************************************************************************
Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
Copyright(c) 2010 Gerry Rozema. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/
#pragma once
#include <deque>
#include "indiccd.h"
#include "indifilterinterface.h"
/**
* @brief The CCDSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide chip.
*
* The CCD driver can generate star fields given that General-Star-Catalog (gsc) tool is installed on the same machine the driver is running.
*
* Many simulator parameters can be configured to generate the final star field image. In addition to support guider chip and guiding pulses (ST4),
* a filter wheel support is provided for 8 filter wheels. Cooler and temperature control is also supported.
*
* The driver can snoop the mount equatorial coords to draw the star field. It listens to EQUATORIAL_PE property and also defines it so that the user
* can set it manually.
*
* Video streaming can be enabled from the Stream property group with several encoders and recorders supported.
*
* @author Gerry Rozema
* @author Jasem Mutlaq
*/
class CCDSim : public INDI::CCD, public INDI::FilterInterface
{
public:
enum
{
SIM_XRES,
SIM_YRES,
SIM_XSIZE,
SIM_YSIZE,
SIM_MAXVAL,
SIM_SATURATION,
SIM_LIMITINGMAG,
SIM_NOISE,
SIM_SKYGLOW,
SIM_OAGOFFSET,
SIM_POLAR,
SIM_POLARDRIFT,
SIM_PE_PERIOD,
SIM_PE_MAX,
SIM_TIME_FACTOR,
SIM_ROTATION,
SIM_N
};
CCDSim();
virtual ~CCDSim() override = default;
const char *getDefaultName() override;
bool initProperties() override;
bool updateProperties() override;
void ISGetProperties(const char *dev) override;
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
virtual bool ISSnoopDevice(XMLEle *root) override;
static void *streamVideoHelper(void *context);
void *streamVideo();
protected:
bool Connect() override;
bool Disconnect() override;
bool StartExposure(float duration) override;
bool StartGuideExposure(float) override;
bool AbortExposure() override;
bool AbortGuideExposure() override;
void TimerHit() override;
int DrawCcdFrame(INDI::CCDChip *targetChip);
int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime);
int AddToPixel(INDI::CCDChip *targetChip, int, int, int);
virtual IPState GuideNorth(uint32_t) override;
virtual IPState GuideSouth(uint32_t) override;
virtual IPState GuideEast(uint32_t) override;
virtual IPState GuideWest(uint32_t) override;
virtual bool saveConfigItems(FILE *fp) override;
virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector<INDI::FITSRecord> &fitsKeyword) override;
virtual void activeDevicesUpdated() override;
virtual int SetTemperature(double temperature) override;
virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
virtual bool UpdateCCDBin(int hor, int ver) override;
virtual bool UpdateGuiderBin(int hor, int ver) override;
virtual bool SetCaptureFormat(uint8_t index) override;
virtual bool StartStreaming() override;
virtual bool StopStreaming() override;
// Filter
bool SelectFilter(int) override;
int QueryFilter() override;
protected:
float CalcTimeLeft(timeval, float);
bool watchDirectory();
bool loadNextImage();
bool setupParameters();
// Turns on/off Bayer RGB simulation.
void setBayerEnabled(bool onOff);
double flux(double magnitude) const;
double TemperatureRequest { 0 };
float ExposureRequest { 0 };
struct timeval ExpStart
{
0, 0
};
float GuideExposureRequest { 0 };
struct timeval GuideExpStart
{
0, 0
};
int testvalue { 0 };
bool ShowStarField { true };
int m_Bias { 1500 };
int m_MaxNoise { 20 };
int m_MaxVal { 65000 };
int maxpix { 0 };
int minpix { 65000 };
float m_SkyGlow { 40 };
float m_LimitingMag { 11.5 };
float m_SaturationMag { 2 };
float seeing { 3.5 };
float ImageScalex { 1.0 };
float ImageScaley { 1.0 };
// An oag is offset this much from center of scope position (arcminutes)
float m_OAGOffset { 0 };
float m_RotationCW { 0 };
float m_TimeFactor { 1 };
double m_CameraRotation { 0 };
bool m_SimulateBayer { false };
// our zero point calcs used for drawing stars
//float k { 0 };
//float z { 0 };
bool AbortGuideFrame { false };
bool AbortPrimaryFrame { false };
/// Guide rate is 7 arcseconds per second
float GuideRate { 7 };
/// PEPeriod in minutes
float m_PEPeriod { 0 };
// PE max in arcsecs
float m_PEMax { 0 };
double currentRA { 0 };
double currentDE { 0 };
bool usePE { false };
time_t RunStart;
float guideNSOffset {0};
float guideWEOffset {0};
float m_PolarError { 0 };
float m_PolarDrift { 0 };
double m_LastTemperature {0};
int streamPredicate {0};
pthread_t primary_thread;
bool terminateThread;
std::deque<std::string> m_AllFiles, m_RemainingFiles;
// And this lives in our simulator settings page
INDI::PropertyNumber SimulatorSettingsNP {16};
INDI::PropertySwitch SimulateBayerSP {2};
enum
{
INDI_ENABLED,
INDI_DISABLED
};
// We are going to snoop these from focuser
INumberVectorProperty FWHMNP;
INumber FWHMN[1];
// Focuser positions for focusing simulation
// FocuserPosition[0] is the position where the scope is in focus
// FocuserPosition[1] is the maximal position the focuser may move to (@see FOCUS_MAX in #indifocuserinterface.cpp)
// FocuserPosition[2] is the seeing (in arcsec)
// We need to have these values here, since we cannot snoop it from the focuser (the focuser does not
// publish these values)
INDI::PropertyNumber FocusSimulationNP {3};
enum
{
SIM_FOCUS_POSITION,
SIM_FOCUS_MAX,
SIM_SEEING
};
INDI::PropertyNumber EqPENP {2};
INDI::PropertySwitch CoolerSP {2};
INDI::PropertyNumber GainNP {1};
INDI::PropertyNumber OffsetNP {1};
INDI::PropertyText DirectoryTP {1};
INDI::PropertySwitch DirectorySP {2};
INDI::PropertySwitch CrashSP {1};
INDI::PropertySwitch ResolutionSP {3};
inline static const std::vector<std::pair<uint32_t, uint32_t>> Resolutions =
{
{1280, 1024},
{6000, 4000},
{0, 0} // Custom
};
static const constexpr char* SIMULATOR_TAB = "Simulator Config";
};